[cfe-commits] r103390 - in /cfe/trunk: include/clang/AST/ExprCXX.h include/clang/Frontend/PCHBitCodes.h lib/AST/ExprCXX.cpp lib/Frontend/PCHReaderStmt.cpp lib/Frontend/PCHWriterStmt.cpp test/PCH/cxx_exprs.h
Chris Lattner
sabre at nondot.org
Sun May 9 18:22:27 PDT 2010
Author: lattner
Date: Sun May 9 20:22:27 2010
New Revision: 103390
URL: http://llvm.org/viewvc/llvm-project?rev=103390&view=rev
Log:
pch'ify CXXNewExpr and CXXZeroInitValueExpr
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
cfe/trunk/test/PCH/cxx_exprs.h
Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=103390&r1=103389&r2=103390&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sun May 9 20:22:27 2010
@@ -882,10 +882,15 @@
SourceLocation rParenLoc ) :
Expr(CXXZeroInitValueExprClass, ty, false, false),
TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
+ explicit CXXZeroInitValueExpr(EmptyShell Shell)
+ : Expr(CXXZeroInitValueExprClass, Shell) { }
SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
SourceLocation getRParenLoc() const { return RParenLoc; }
+ void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
+ void setRParenLoc(SourceLocation L) { RParenLoc = L; }
+
/// @brief Whether this initialization expression was
/// implicitly-generated.
bool isImplicit() const {
@@ -946,6 +951,11 @@
Expr **constructorArgs, unsigned numConsArgs,
FunctionDecl *operatorDelete, QualType ty,
SourceLocation startLoc, SourceLocation endLoc);
+ explicit CXXNewExpr(EmptyShell Shell)
+ : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
+
+ void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
+ unsigned numConsArgs);
virtual void DoDestroy(ASTContext &C);
@@ -955,8 +965,11 @@
}
FunctionDecl *getOperatorNew() const { return OperatorNew; }
+ void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
+ void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
CXXConstructorDecl *getConstructor() const { return Constructor; }
+ void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
bool isArray() const { return Array; }
Expr *getArraySize() {
@@ -977,8 +990,11 @@
}
bool isGlobalNew() const { return GlobalNew; }
+ void setGlobalNew(bool V) { GlobalNew = V; }
bool isParenTypeId() const { return ParenTypeId; }
+ void setParenTypeId(bool V) { ParenTypeId = V; }
bool hasInitializer() const { return Initializer; }
+ void setHasInitializer(bool V) { Initializer = V; }
unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
Expr *getConstructorArg(unsigned i) {
@@ -1018,7 +1034,21 @@
const_arg_iterator constructor_arg_end() const {
return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
}
+
+ typedef Stmt **raw_arg_iterator;
+ raw_arg_iterator raw_arg_begin() { return SubExprs; }
+ raw_arg_iterator raw_arg_end() {
+ return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
+ }
+ const_arg_iterator raw_arg_begin() const { return SubExprs; }
+ const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
+
+ SourceLocation getStartLoc() const { return StartLoc; }
+ void setStartLoc(SourceLocation L) { StartLoc = L; }
+ SourceLocation getEndLoc() const { return EndLoc; }
+ void setEndLoc(SourceLocation L) { EndLoc = L; }
+
virtual SourceRange getSourceRange() const {
return SourceRange(StartLoc, EndLoc);
}
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=103390&r1=103389&r2=103390&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Sun May 9 20:22:27 2010
@@ -753,6 +753,9 @@
EXPR_CXX_THROW, // CXXThrowExpr
EXPR_CXX_DEFAULT_ARG, // CXXDefaultArgExpr
EXPR_CXX_BIND_TEMPORARY, // CXXBindTemporaryExpr
+ //
+ EXPR_CXX_ZERO_INIT_VALUE, // CXXZeroInitValueExpr
+ EXPR_CXX_NEW, // CXXNewExpr
EXPR_CXX_EXPR_WITH_TEMPORARIES // CXXExprWithTemporaries
};
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=103390&r1=103389&r2=103390&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Sun May 9 20:22:27 2010
@@ -92,12 +92,11 @@
SourceLocation startLoc, SourceLocation endLoc)
: Expr(CXXNewExprClass, ty, ty->isDependentType(), ty->isDependentType()),
GlobalNew(globalNew), ParenTypeId(parenTypeId),
- Initializer(initializer), Array(arraySize), NumPlacementArgs(numPlaceArgs),
- NumConstructorArgs(numConsArgs), OperatorNew(operatorNew),
+ Initializer(initializer), SubExprs(0), OperatorNew(operatorNew),
OperatorDelete(operatorDelete), Constructor(constructor),
StartLoc(startLoc), EndLoc(endLoc) {
- unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs;
- SubExprs = new (C) Stmt*[TotalSize];
+
+ AllocateArgsArray(C, arraySize != 0, numPlaceArgs, numConsArgs);
unsigned i = 0;
if (Array)
SubExprs[i++] = arraySize;
@@ -105,9 +104,20 @@
SubExprs[i++] = placementArgs[j];
for (unsigned j = 0; j < NumConstructorArgs; ++j)
SubExprs[i++] = constructorArgs[j];
- assert(i == TotalSize);
}
+void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
+ unsigned numPlaceArgs, unsigned numConsArgs){
+ assert(SubExprs == 0 && "SubExprs already allocated");
+ Array = isArray;
+ NumPlacementArgs = numPlaceArgs;
+ NumConstructorArgs = numConsArgs;
+
+ unsigned TotalSize = Array + NumPlacementArgs + NumConstructorArgs;
+ SubExprs = new (C) Stmt*[TotalSize];
+}
+
+
void CXXNewExpr::DoDestroy(ASTContext &C) {
DestroyChildren(C);
if (SubExprs)
Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=103390&r1=103389&r2=103390&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Sun May 9 20:22:27 2010
@@ -132,6 +132,9 @@
unsigned VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
unsigned VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+ unsigned VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
+ unsigned VisitCXXNewExpr(CXXNewExpr *E);
+
unsigned VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
};
}
@@ -1041,6 +1044,42 @@
return 1;
}
+unsigned PCHStmtReader::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+ VisitExpr(E);
+ E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ return 0;
+}
+
+unsigned PCHStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
+ VisitExpr(E);
+ E->setGlobalNew(Record[Idx++]);
+ E->setParenTypeId(Record[Idx++]);
+ E->setHasInitializer(Record[Idx++]);
+ bool isArray = Record[Idx++];
+ unsigned NumPlacementArgs = Record[Idx++];
+ unsigned NumCtorArgs = Record[Idx++];
+ E->setOperatorNew(cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
+ E->setOperatorDelete(
+ cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
+ E->setConstructor(
+ cast_or_null<CXXConstructorDecl>(Reader.GetDecl(Record[Idx++])));
+ E->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ E->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+
+ E->AllocateArgsArray(*Reader.getContext(), isArray, NumPlacementArgs,
+ NumCtorArgs);
+
+ // Install all the subexpressions.
+ unsigned TotalSubExprs = E->raw_arg_end()-E->raw_arg_begin();
+ unsigned SSIdx = StmtStack.size()-TotalSubExprs;
+ for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),e = E->raw_arg_end();
+ I != e; ++I)
+ *I = StmtStack[SSIdx++];
+
+ return TotalSubExprs;
+}
+
unsigned PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
VisitExpr(E);
@@ -1422,6 +1461,14 @@
case pch::EXPR_CXX_BIND_TEMPORARY:
S = new (Context) CXXBindTemporaryExpr(Empty);
break;
+
+ case pch::EXPR_CXX_ZERO_INIT_VALUE:
+ S = new (Context) CXXZeroInitValueExpr(Empty);
+ break;
+ case pch::EXPR_CXX_NEW:
+ S = new (Context) CXXNewExpr(Empty);
+ break;
+
case pch::EXPR_CXX_EXPR_WITH_TEMPORARIES:
S = new (Context) CXXExprWithTemporaries(Empty);
Modified: cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterStmt.cpp?rev=103390&r1=103389&r2=103390&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterStmt.cpp Sun May 9 20:22:27 2010
@@ -128,6 +128,9 @@
void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+ void VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
+ void VisitCXXNewExpr(CXXNewExpr *E);
+
void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
};
}
@@ -964,6 +967,34 @@
Code = pch::EXPR_CXX_BIND_TEMPORARY;
}
+void PCHStmtWriter::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+ VisitExpr(E);
+ Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
+ Writer.AddSourceLocation(E->getRParenLoc(), Record);
+ Code = pch::EXPR_CXX_ZERO_INIT_VALUE;
+}
+
+void PCHStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
+ VisitExpr(E);
+ Record.push_back(E->isGlobalNew());
+ Record.push_back(E->isParenTypeId());
+ Record.push_back(E->hasInitializer());
+ Record.push_back(E->isArray());
+ Record.push_back(E->getNumPlacementArgs());
+ Record.push_back(E->getNumConstructorArgs());
+ Writer.AddDeclRef(E->getOperatorNew(), Record);
+ Writer.AddDeclRef(E->getOperatorDelete(), Record);
+ Writer.AddDeclRef(E->getConstructor(), Record);
+ Writer.AddSourceLocation(E->getStartLoc(), Record);
+ Writer.AddSourceLocation(E->getEndLoc(), Record);
+ for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
+ I != e; ++I)
+ Writer.WriteSubStmt(*I);
+
+ Code = pch::EXPR_CXX_NEW;
+}
+
+
void PCHStmtWriter::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
VisitExpr(E);
Record.push_back(E->getNumTemporaries());
@@ -1019,8 +1050,13 @@
Writer.Code = pch::STMT_NULL_PTR;
Writer.Visit(S);
- assert(Writer.Code != pch::STMT_NULL_PTR &&
- "Unhandled expression writing PCH file");
+
+#ifndef NDEBUG
+ if (Writer.Code == pch::STMT_NULL_PTR) {
+ S->dump();
+ assert(0 && "Unhandled sub statement writing PCH file");
+ }
+#endif
Stream.EmitRecord(Writer.Code, Record);
}
Modified: cfe/trunk/test/PCH/cxx_exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx_exprs.h?rev=103390&r1=103389&r2=103390&view=diff
==============================================================================
--- cfe/trunk/test/PCH/cxx_exprs.h (original)
+++ cfe/trunk/test/PCH/cxx_exprs.h Sun May 9 20:22:27 2010
@@ -5,8 +5,8 @@
typedef __typeof__(static_cast<void *>(0)) static_cast_result;
// CXXDynamicCastExpr
-struct Base { virtual void f(int x = 492); ~Base(); };
-struct Derived : Base { void g(); };
+struct Base { Base(int); virtual void f(int x = 492); ~Base(); };
+struct Derived : Base { Derived(); void g(); };
Base *base_ptr;
typedef __typeof__(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result;
@@ -46,6 +46,9 @@
Derived foo();
+Derived::Derived() : Base(4) {
+}
+
void Derived::g() {
// CXXThisExpr
f(2); // Implicit
@@ -60,6 +63,21 @@
const Derived &X = foo();
+ // FIXME: How do I make a CXXBindReferenceExpr, CXXConstructExpr?
+
+ int A = int(0.5); // CXXFunctionalCastExpr
+ A = int(); // CXXZeroInitValueExpr
+
+ new Base(4); // CXXNewExpr
- // FIXME: CXXBindReferenceExpr ?
-}
\ No newline at end of file
+}
+
+
+// FIXME: The comment on CXXTemporaryObjectExpr is broken, this doesn't make
+// one.
+struct CtorStruct { CtorStruct(int, float); };
+
+CtorStruct create_CtorStruct() {
+ return CtorStruct(1, 3.14f); // CXXTemporaryObjectExpr
+};
+
More information about the cfe-commits
mailing list