[cfe-commits] r69240 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Frontend/PCHBitCodes.h lib/AST/Expr.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/exprs.c test/PCH/exprs.h
Douglas Gregor
dgregor at apple.com
Wed Apr 15 16:02:49 PDT 2009
Author: dgregor
Date: Wed Apr 15 18:02:49 2009
New Revision: 69240
URL: http://llvm.org/viewvc/llvm-project?rev=69240&view=rev
Log:
PCH support for ExtVectorElementExpr and VAArgExpr.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/test/PCH/exprs.c
cfe/trunk/test/PCH/exprs.h
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=69240&r1=69239&r2=69240&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Apr 15 18:02:49 2009
@@ -1844,8 +1844,19 @@
BuiltinLoc(BLoc),
RParenLoc(RPLoc) { }
+ /// \brief Create an empty __builtin_va_start expression.
+ explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
+
const Expr *getSubExpr() const { return cast<Expr>(Val); }
Expr *getSubExpr() { return cast<Expr>(Val); }
+ void setSubExpr(Expr *E) { Val = E; }
+
+ SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
+ void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
+
+ SourceLocation getRParenLoc() const { return RParenLoc; }
+ void setRParenLoc(SourceLocation L) { RParenLoc = L; }
+
virtual SourceRange getSourceRange() const {
return SourceRange(BuiltinLoc, RParenLoc);
}
@@ -2306,19 +2317,28 @@
///
class ExtVectorElementExpr : public Expr {
Stmt *Base;
- IdentifierInfo &Accessor;
+ IdentifierInfo *Accessor;
SourceLocation AccessorLoc;
public:
ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
SourceLocation loc)
: Expr(ExtVectorElementExprClass, ty),
- Base(base), Accessor(accessor), AccessorLoc(loc) {}
+ Base(base), Accessor(&accessor), AccessorLoc(loc) {}
+ /// \brief Build an empty vector element expression.
+ explicit ExtVectorElementExpr(EmptyShell Empty)
+ : Expr(ExtVectorElementExprClass, Empty) { }
+
const Expr *getBase() const { return cast<Expr>(Base); }
Expr *getBase() { return cast<Expr>(Base); }
-
- IdentifierInfo &getAccessor() const { return Accessor; }
-
+ void setBase(Expr *E) { Base = E; }
+
+ IdentifierInfo &getAccessor() const { return *Accessor; }
+ void setAccessor(IdentifierInfo *II) { Accessor = II; }
+
+ SourceLocation getAccessorLoc() const { return AccessorLoc; }
+ void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
+
/// getNumElements - Get the number of components being selected.
unsigned getNumElements() const;
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69240&r1=69239&r2=69240&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 15 18:02:49 2009
@@ -418,7 +418,15 @@
/// \brief An ImplicitCastExpr record.
EXPR_IMPLICIT_CAST,
/// \brief A CStyleCastExpr record.
- EXPR_CSTYLE_CAST
+ EXPR_CSTYLE_CAST,
+ /// FIXME: CompoundLiteralExpr
+ /// \brief An ExtVectorElementExpr record.
+ EXPR_EXT_VECTOR_ELEMENT,
+ /// FIXME: InitListExpr
+ /// FIXME: DesignatedInitExpr
+ /// FIXME: ImplicitValueInitExpr
+ /// \brief A VAArgExpr record.
+ EXPR_VA_ARG
};
/// @}
}
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=69240&r1=69239&r2=69240&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Apr 15 18:02:49 2009
@@ -1372,8 +1372,8 @@
/// containsDuplicateElements - Return true if any element access is repeated.
bool ExtVectorElementExpr::containsDuplicateElements() const {
- const char *compStr = Accessor.getName();
- unsigned length = Accessor.getLength();
+ const char *compStr = Accessor->getName();
+ unsigned length = Accessor->getLength();
// Halving swizzles do not contain duplicate elements.
if (!strcmp(compStr, "hi") || !strcmp(compStr, "lo") ||
@@ -1398,7 +1398,7 @@
/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
void ExtVectorElementExpr::getEncodedElementAccess(
llvm::SmallVectorImpl<unsigned> &Elts) const {
- const char *compStr = Accessor.getName();
+ const char *compStr = Accessor->getName();
if (*compStr == 's')
compStr++;
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69240&r1=69239&r2=69240&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 15 18:02:49 2009
@@ -257,6 +257,8 @@
unsigned VisitImplicitCastExpr(ImplicitCastExpr *E);
unsigned VisitExplicitCastExpr(ExplicitCastExpr *E);
unsigned VisitCStyleCastExpr(CStyleCastExpr *E);
+ unsigned VisitExtVectorElementExpr(ExtVectorElementExpr *E);
+ unsigned VisitVAArgExpr(VAArgExpr *E);
};
}
@@ -437,6 +439,23 @@
return 1;
}
+unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
+ VisitExpr(E);
+ E->setBase(ExprStack.back());
+ E->setAccessor(Reader.GetIdentifierInfo(Record, Idx));
+ E->setAccessorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ return 1;
+}
+
+unsigned PCHStmtReader::VisitVAArgExpr(VAArgExpr *E) {
+ VisitExpr(E);
+ E->setSubExpr(ExprStack.back());
+ E->setBuiltinLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ return 1;
+}
+
+
// FIXME: use the diagnostics machinery
static bool Error(const char *Str) {
std::fprintf(stderr, "%s\n", Str);
@@ -1949,6 +1968,15 @@
case pch::EXPR_CSTYLE_CAST:
E = new (Context) CStyleCastExpr(Empty);
break;
+
+ case pch::EXPR_EXT_VECTOR_ELEMENT:
+ E = new (Context) ExtVectorElementExpr(Empty);
+ break;
+
+ case pch::EXPR_VA_ARG:
+ // FIXME: untested; we need function bodies first
+ E = new (Context) VAArgExpr(Empty);
+ break;
}
// We hit an EXPR_STOP, so we're done with this expression.
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69240&r1=69239&r2=69240&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 15 18:02:49 2009
@@ -464,6 +464,8 @@
void VisitImplicitCastExpr(ImplicitCastExpr *E);
void VisitExplicitCastExpr(ExplicitCastExpr *E);
void VisitCStyleCastExpr(CStyleCastExpr *E);
+ void VisitExtVectorElementExpr(ExtVectorElementExpr *E);
+ void VisitVAArgExpr(VAArgExpr *E);
};
}
@@ -637,6 +639,22 @@
Code = pch::EXPR_CSTYLE_CAST;
}
+void PCHStmtWriter::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
+ VisitExpr(E);
+ Writer.WriteSubExpr(E->getBase());
+ Writer.AddIdentifierRef(&E->getAccessor(), Record);
+ Writer.AddSourceLocation(E->getAccessorLoc(), Record);
+ Code = pch::EXPR_EXT_VECTOR_ELEMENT;
+}
+
+void PCHStmtWriter::VisitVAArgExpr(VAArgExpr *E) {
+ VisitExpr(E);
+ Writer.WriteSubExpr(E->getSubExpr());
+ Writer.AddSourceLocation(E->getBuiltinLoc(), Record);
+ Writer.AddSourceLocation(E->getRParenLoc(), Record);
+ Code = pch::EXPR_VA_ARG;
+}
+
//===----------------------------------------------------------------------===//
// PCHWriter Implementation
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/test/PCH/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.c?rev=69240&r1=69239&r2=69240&view=diff
==============================================================================
--- cfe/trunk/test/PCH/exprs.c (original)
+++ cfe/trunk/test/PCH/exprs.c Wed Apr 15 18:02:49 2009
@@ -60,3 +60,6 @@
// CStyleCastExpr
void_ptr vp1 = &integer;
+
+// ExtVectorElementExpr
+ext_vector_element *double_ptr5 = &floating;
Modified: cfe/trunk/test/PCH/exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.h?rev=69240&r1=69239&r2=69240&view=diff
==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Wed Apr 15 18:02:49 2009
@@ -56,3 +56,7 @@
// CStyleCastExpr
typedef typeof((void *)0) void_ptr;
+// ExtVectorElementExpr
+typedef __attribute__(( ext_vector_type(2) )) double double2;
+double2 vec2;
+typedef typeof(vec2.x) ext_vector_element;
More information about the cfe-commits
mailing list