[cfe-commits] r69186 - 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 10:44:05 PDT 2009
Author: dgregor
Date: Wed Apr 15 12:43:59 2009
New Revision: 69186
URL: http://llvm.org/viewvc/llvm-project?rev=69186&view=rev
Log:
PCH support for MemberExpr and CallExpr.
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=69186&r1=69185&r2=69186&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Apr 15 12:43:59 2009
@@ -970,6 +970,9 @@
CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
SourceLocation rparenloc);
+ /// \brief Build an empty call expression.
+ CallExpr(ASTContext &C, EmptyShell Empty);
+
~CallExpr() {}
void Destroy(ASTContext& C);
@@ -992,18 +995,12 @@
return cast<Expr>(SubExprs[Arg+ARGS_START]);
}
- // FIXME: Why is this needed? Why not just create the CallExpr with the
- // corect number of arguments? It makes the ASTs less brittle.
/// setArg - Set the specified argument.
void setArg(unsigned Arg, Expr *ArgExpr) {
assert(Arg < NumArgs && "Arg access out of range!");
SubExprs[Arg+ARGS_START] = ArgExpr;
}
- // FIXME: It would be great to just get rid of this. There is only one
- // callee of this method, and it probably could be refactored to not use
- // this method and instead just create a CallExpr with the right number of
- // arguments.
/// setNumArgs - This changes the number of arguments present in this call.
/// Any orphaned expressions are deleted by this, and any new operands are set
/// to null.
@@ -1026,6 +1023,7 @@
unsigned isBuiltinCall(ASTContext &Context) const;
SourceLocation getRParenLoc() const { return RParenLoc; }
+ void setRParenLoc(SourceLocation L) { RParenLoc = L; }
virtual SourceRange getSourceRange() const {
return SourceRange(getCallee()->getLocStart(), RParenLoc);
@@ -1071,6 +1069,9 @@
: Expr(MemberExprClass, ty),
Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
+ /// \brief Build an empty member reference expression.
+ explicit MemberExpr(EmptyShell Empty) : Expr(MemberExprClass, Empty) { }
+
void setBase(Expr *E) { Base = E; }
Expr *getBase() const { return cast<Expr>(Base); }
@@ -1080,11 +1081,14 @@
/// a CXXMethodDecl.
NamedDecl *getMemberDecl() const { return MemberDecl; }
void setMemberDecl(NamedDecl *D) { MemberDecl = D; }
+
bool isArrow() const { return IsArrow; }
-
+ void setArrow(bool A) { IsArrow = A; }
+
/// getMemberLoc - Return the location of the "member", in X->F, it is the
/// location of 'F'.
SourceLocation getMemberLoc() const { return MemberLoc; }
+ void setMemberLoc(SourceLocation L) { MemberLoc = L; }
virtual SourceRange getSourceRange() const {
return SourceRange(getBase()->getLocStart(), MemberLoc);
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69186&r1=69185&r2=69186&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 15 12:43:59 2009
@@ -391,6 +391,10 @@
EXPR_UNARY_OPERATOR,
/// \brief A SizefAlignOfExpr record.
EXPR_SIZEOF_ALIGN_OF,
+ /// \brief A CallExpr record.
+ EXPR_CALL,
+ /// \brief A MemberExpr record.
+ EXPR_MEMBER,
/// \brief A BinaryOperator record.
EXPR_BINARY_OPERATOR,
/// \brief An ImplicitCastExpr record.
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=69186&r1=69185&r2=69186&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Apr 15 12:43:59 2009
@@ -186,6 +186,11 @@
RParenLoc = rparenloc;
}
+CallExpr::CallExpr(ASTContext &C, EmptyShell Empty)
+ : Expr(CallExprClass, Empty), SubExprs(0), NumArgs(0) {
+ SubExprs = new (C) Stmt*[1];
+}
+
void CallExpr::Destroy(ASTContext& C) {
DestroyChildren(C);
if (SubExprs) C.Deallocate(SubExprs);
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69186&r1=69185&r2=69186&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 15 12:43:59 2009
@@ -245,6 +245,8 @@
unsigned VisitParenExpr(ParenExpr *E);
unsigned VisitUnaryOperator(UnaryOperator *E);
unsigned VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
+ unsigned VisitCallExpr(CallExpr *E);
+ unsigned VisitMemberExpr(MemberExpr *E);
unsigned VisitCastExpr(CastExpr *E);
unsigned VisitBinaryOperator(BinaryOperator *E);
unsigned VisitImplicitCastExpr(ImplicitCastExpr *E);
@@ -348,6 +350,25 @@
return E->isArgumentType()? 0 : 1;
}
+unsigned PCHStmtReader::VisitCallExpr(CallExpr *E) {
+ VisitExpr(E);
+ E->setNumArgs(Reader.getContext(), Record[Idx++]);
+ E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ E->setCallee(ExprStack[ExprStack.size() - E->getNumArgs() - 1]);
+ for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
+ E->setArg(I, ExprStack[ExprStack.size() - N + I]);
+ return E->getNumArgs() + 1;
+}
+
+unsigned PCHStmtReader::VisitMemberExpr(MemberExpr *E) {
+ VisitExpr(E);
+ E->setBase(ExprStack.back());
+ E->setMemberDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
+ E->setMemberLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ E->setArrow(Record[Idx++]);
+ return 1;
+}
+
unsigned PCHStmtReader::VisitCastExpr(CastExpr *E) {
VisitExpr(E);
E->setSubExpr(ExprStack.back());
@@ -1703,6 +1724,14 @@
E = new (Context) SizeOfAlignOfExpr(Empty);
break;
+ case pch::EXPR_CALL:
+ E = new (Context) CallExpr(Context, Empty);
+ break;
+
+ case pch::EXPR_MEMBER:
+ E = new (Context) MemberExpr(Empty);
+ break;
+
case pch::EXPR_BINARY_OPERATOR:
E = new (Context) BinaryOperator(Empty);
break;
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69186&r1=69185&r2=69186&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 15 12:43:59 2009
@@ -453,6 +453,8 @@
void VisitParenExpr(ParenExpr *E);
void VisitUnaryOperator(UnaryOperator *E);
void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
+ void VisitCallExpr(CallExpr *E);
+ void VisitMemberExpr(MemberExpr *E);
void VisitCastExpr(CastExpr *E);
void VisitBinaryOperator(BinaryOperator *E);
void VisitImplicitCastExpr(ImplicitCastExpr *E);
@@ -550,6 +552,26 @@
Code = pch::EXPR_SIZEOF_ALIGN_OF;
}
+void PCHStmtWriter::VisitCallExpr(CallExpr *E) {
+ VisitExpr(E);
+ Record.push_back(E->getNumArgs());
+ Writer.AddSourceLocation(E->getRParenLoc(), Record);
+ Writer.WriteSubExpr(E->getCallee());
+ for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
+ Arg != ArgEnd; ++Arg)
+ Writer.WriteSubExpr(*Arg);
+ Code = pch::EXPR_CALL;
+}
+
+void PCHStmtWriter::VisitMemberExpr(MemberExpr *E) {
+ VisitExpr(E);
+ Writer.WriteSubExpr(E->getBase());
+ Writer.AddDeclRef(E->getMemberDecl(), Record);
+ Writer.AddSourceLocation(E->getMemberLoc(), Record);
+ Record.push_back(E->isArrow());
+ Code = pch::EXPR_MEMBER;
+}
+
void PCHStmtWriter::VisitCastExpr(CastExpr *E) {
VisitExpr(E);
Writer.WriteSubExpr(E->getSubExpr());
Modified: cfe/trunk/test/PCH/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.c?rev=69186&r1=69185&r2=69186&view=diff
==============================================================================
--- cfe/trunk/test/PCH/exprs.c (original)
+++ cfe/trunk/test/PCH/exprs.c Wed Apr 15 12:43:59 2009
@@ -36,6 +36,12 @@
typeof_sizeof *size_t_ptr = &size_t_value;
typeof_sizeof2 *size_t_ptr2 = &size_t_value;
+// CallExpr
+call_returning_double *double_ptr2 = &floating;
+
+// MemberExpr
+member_ref_double *double_ptr3 = &floating;
+
// BinaryOperator
add_result *int_ptr5 = &integer;
Modified: cfe/trunk/test/PCH/exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.h?rev=69186&r1=69185&r2=69186&view=diff
==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Wed Apr 15 12:43:59 2009
@@ -26,6 +26,17 @@
typedef typeof(sizeof(int)) typeof_sizeof;
typedef typeof(sizeof(Enumerator)) typeof_sizeof2;
+// CallExpr
+double dplus(double x, double y);
+double d0, d1;
+typedef typeof((&dplus)(d0, d1)) call_returning_double;
+
+// MemberExpr
+struct S {
+ double x;
+};
+typedef typeof(((struct S*)0)->x) member_ref_double;
+
// BinaryOperator
typedef typeof(i + Enumerator) add_result;
More information about the cfe-commits
mailing list