[cfe-commits] r103387 - in /cfe/trunk: include/clang/AST/ExprCXX.h include/clang/Frontend/PCHBitCodes.h include/clang/Frontend/PCHReader.h include/clang/Frontend/PCHWriter.h lib/AST/ExprCXX.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHReaderStmt.cpp lib/Frontend/PCHWriter.cpp lib/Frontend/PCHWriterStmt.cpp test/PCH/cxx_exprs.h
Chris Lattner
sabre at nondot.org
Sun May 9 17:25:06 PDT 2010
Author: lattner
Date: Sun May 9 19:25:06 2010
New Revision: 103387
URL: http://llvm.org/viewvc/llvm-project?rev=103387&view=rev
Log:
pchify CXXTemporary, CXXBindTemporaryExpr, and
CXXExprWithTemporaries.
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/include/clang/Frontend/PCHReader.h
cfe/trunk/include/clang/Frontend/PCHWriter.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
cfe/trunk/lib/Frontend/PCHWriter.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=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sun May 9 19:25:06 2010
@@ -580,11 +580,15 @@
virtual void DoDestroy(ASTContext &C);
public:
+ CXXBindTemporaryExpr(EmptyShell Empty)
+ : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
+
static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
Expr* SubExpr);
CXXTemporary *getTemporary() { return Temp; }
const CXXTemporary *getTemporary() const { return Temp; }
+ void setTemporary(CXXTemporary *T) { Temp = T; }
const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
Expr *getSubExpr() { return cast<Expr>(SubExpr); }
@@ -611,8 +615,8 @@
/// const int &i = 10;
///
/// a bind reference expression is inserted to indicate that 10 is bound to
-/// a reference. (Ans also that a temporary needs to be created to hold the
-/// value).
+/// a reference, and that a temporary needs to be created to hold the
+/// value.
class CXXBindReferenceExpr : public Expr {
// SubExpr - The expression being bound.
Stmt *SubExpr;
@@ -1658,11 +1662,17 @@
virtual void DoDestroy(ASTContext &C);
public:
+ CXXExprWithTemporaries(EmptyShell Empty)
+ : Expr(CXXExprWithTemporariesClass, Empty),
+ SubExpr(0), Temps(0), NumTemps(0) {}
+
static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
CXXTemporary **Temps,
unsigned NumTemps);
unsigned getNumTemporaries() const { return NumTemps; }
+ void setNumTemporaries(unsigned N);
+
CXXTemporary *getTemporary(unsigned i) {
assert(i < NumTemps && "Index out of range");
return Temps[i];
@@ -1670,6 +1680,10 @@
const CXXTemporary *getTemporary(unsigned i) const {
return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
}
+ void setTemporary(unsigned i, CXXTemporary *T) {
+ assert(i < NumTemps && "Index out of range");
+ Temps[i] = T;
+ }
Expr *getSubExpr() { return cast<Expr>(SubExpr); }
const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Sun May 9 19:25:06 2010
@@ -751,7 +751,10 @@
EXPR_CXX_TYPEID_TYPE, // CXXTypeidExpr (of type).
EXPR_CXX_THIS, // CXXThisExpr
EXPR_CXX_THROW, // CXXThrowExpr
- EXPR_CXX_DEFAULT_ARG // CXXDefaultArgExpr
+ EXPR_CXX_DEFAULT_ARG, // CXXDefaultArgExpr
+ EXPR_CXX_BIND_TEMPORARY, // CXXBindTemporaryExpr
+
+ EXPR_CXX_EXPR_WITH_TEMPORARIES // CXXExprWithTemporaries
};
/// \brief The kinds of designators that can occur in a
Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Sun May 9 19:25:06 2010
@@ -652,8 +652,8 @@
/// declarations with this name are visible from translation unit scope, their
/// declarations will be deserialized and introduced into the declaration
/// chain of the identifier.
- virtual IdentifierInfo* get(const char *NameStart, const char *NameEnd);
- IdentifierInfo* get(llvm::StringRef Name) {
+ virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
+ IdentifierInfo *get(llvm::StringRef Name) {
return get(Name.begin(), Name.end());
}
@@ -724,6 +724,8 @@
// \brief Read a string
std::string ReadString(const RecordData &Record, unsigned &Idx);
+ CXXTemporary *ReadCXXTemporary(const RecordData &Record, unsigned &Idx);
+
/// \brief Reads attributes from the current stream position.
Attr *ReadAttributes();
Modified: cfe/trunk/include/clang/Frontend/PCHWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHWriter.h?rev=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHWriter.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHWriter.h Sun May 9 19:25:06 2010
@@ -256,7 +256,7 @@
/// \brief Emit a source range.
void AddSourceRange(SourceRange Range, RecordData &Record);
-
+
/// \brief Emit an integral value.
void AddAPInt(const llvm::APInt &Value, RecordData &Record);
@@ -266,12 +266,15 @@
/// \brief Emit a floating-point value.
void AddAPFloat(const llvm::APFloat &Value, RecordData &Record);
- /// \brief Emit a reference to an identifier
+ /// \brief Emit a reference to an identifier.
void AddIdentifierRef(const IdentifierInfo *II, RecordData &Record);
- /// \brief Emit a Selector (which is a smart pointer reference)
- void AddSelectorRef(const Selector, RecordData &Record);
+ /// \brief Emit a Selector (which is a smart pointer reference).
+ void AddSelectorRef(Selector, RecordData &Record);
+ /// \brief Emit a CXXTemporary.
+ void AddCXXTemporary(const CXXTemporary *Temp, RecordData &Record);
+
/// \brief Get the unique number used to refer to the given
/// identifier.
pch::IdentID getIdentifierRef(const IdentifierInfo *II);
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Sun May 9 19:25:06 2010
@@ -520,16 +520,24 @@
CXXExprWithTemporaries::CXXExprWithTemporaries(Expr *subexpr,
CXXTemporary **temps,
unsigned numtemps)
-: Expr(CXXExprWithTemporariesClass, subexpr->getType(),
+ : Expr(CXXExprWithTemporariesClass, subexpr->getType(),
subexpr->isTypeDependent(), subexpr->isValueDependent()),
- SubExpr(subexpr), Temps(0), NumTemps(numtemps) {
- if (NumTemps > 0) {
- Temps = new CXXTemporary*[NumTemps];
- for (unsigned i = 0; i < NumTemps; ++i)
+ SubExpr(subexpr), Temps(0), NumTemps(0) {
+ if (NumTemps) {
+ setNumTemporaries(numtemps);
+ for (unsigned i = 0; i != numtemps; ++i)
Temps[i] = temps[i];
}
}
+void CXXExprWithTemporaries::setNumTemporaries(unsigned N) {
+ assert(Temps == 0 && "Cannot resize with this");
+ // FIXME: This is a memory leak in disable free mode.
+ Temps = new CXXTemporary*[NumTemps];
+ NumTemps = N;
+}
+
+
CXXExprWithTemporaries *CXXExprWithTemporaries::Create(ASTContext &C,
Expr *SubExpr,
CXXTemporary **Temps,
@@ -544,6 +552,7 @@
}
CXXExprWithTemporaries::~CXXExprWithTemporaries() {
+ // FIXME: This is a memory leak in disable free mode.
delete[] Temps;
}
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Sun May 9 19:25:06 2010
@@ -2974,6 +2974,12 @@
return Result;
}
+CXXTemporary *PCHReader::ReadCXXTemporary(const RecordData &Record,
+ unsigned &Idx) {
+ CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++]));
+ return CXXTemporary::Create(*Context, Decl);
+}
+
DiagnosticBuilder PCHReader::Diag(unsigned DiagID) {
return Diag(SourceLocation(), DiagID);
}
Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Sun May 9 19:25:06 2010
@@ -130,6 +130,9 @@
unsigned VisitCXXThisExpr(CXXThisExpr *E);
unsigned VisitCXXThrowExpr(CXXThrowExpr *E);
unsigned VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
+ unsigned VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+
+ unsigned VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
};
}
@@ -1028,7 +1031,27 @@
bool HasStoredExpr = Record[Idx++];
if (!HasStoredExpr) return 0;
E->setExpr(cast<Expr>(StmtStack.back()));
- return 1; // Read it.
+ return 1;
+}
+
+unsigned PCHStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+ VisitExpr(E);
+ E->setTemporary(Reader.ReadCXXTemporary(Record, Idx));
+ E->setSubExpr(cast<Expr>(StmtStack.back()));
+ return 1;
+}
+
+
+unsigned PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
+ VisitExpr(E);
+ unsigned NumTemps = Record[Idx++];
+ if (NumTemps) {
+ E->setNumTemporaries(NumTemps);
+ for (unsigned i = 0; i != NumTemps; ++i)
+ E->setTemporary(i, Reader.ReadCXXTemporary(Record, Idx));
+ }
+ E->setSubExpr(cast<Expr>(StmtStack.back()));
+ return 1;
}
@@ -1396,6 +1419,13 @@
case pch::EXPR_CXX_DEFAULT_ARG:
S = new (Context) CXXDefaultArgExpr(Empty);
break;
+ case pch::EXPR_CXX_BIND_TEMPORARY:
+ S = new (Context) CXXBindTemporaryExpr(Empty);
+ break;
+
+ case pch::EXPR_CXX_EXPR_WITH_TEMPORARIES:
+ S = new (Context) CXXExprWithTemporaries(Empty);
+ break;
}
// We hit a STMT_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=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Sun May 9 19:25:06 2010
@@ -2241,6 +2241,10 @@
Record.push_back(SID);
}
+void PCHWriter::AddCXXTemporary(const CXXTemporary *Temp, RecordData &Record) {
+ AddDeclRef(Temp->getDestructor(), Record);
+}
+
void PCHWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg,
RecordData &Record) {
switch (Arg.getArgument().getKind()) {
Modified: cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterStmt.cpp?rev=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterStmt.cpp Sun May 9 19:25:06 2010
@@ -126,6 +126,9 @@
void VisitCXXThisExpr(CXXThisExpr *E);
void VisitCXXThrowExpr(CXXThrowExpr *E);
void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
+ void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+
+ void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
};
}
@@ -954,6 +957,23 @@
Code = pch::EXPR_CXX_DEFAULT_ARG;
}
+void PCHStmtWriter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
+ VisitExpr(E);
+ Writer.AddCXXTemporary(E->getTemporary(), Record);
+ Writer.WriteSubStmt(E->getSubExpr());
+ Code = pch::EXPR_CXX_BIND_TEMPORARY;
+}
+
+void PCHStmtWriter::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
+ VisitExpr(E);
+ Record.push_back(E->getNumTemporaries());
+ for (unsigned i = 0, e = E->getNumTemporaries(); i != e; ++i)
+ Writer.AddCXXTemporary(E->getTemporary(i), Record);
+
+ Writer.WriteSubStmt(E->getSubExpr());
+ Code = pch::EXPR_CXX_EXPR_WITH_TEMPORARIES;
+}
+
//===----------------------------------------------------------------------===//
// PCHWriter Implementation
@@ -1021,8 +1041,12 @@
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 expression writing PCH file");
+ }
+#endif
Stream.EmitRecord(Writer.Code, Record);
assert(N == StmtsToEmit.size() &&
Modified: cfe/trunk/test/PCH/cxx_exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx_exprs.h?rev=103387&r1=103386&r2=103387&view=diff
==============================================================================
--- cfe/trunk/test/PCH/cxx_exprs.h (original)
+++ cfe/trunk/test/PCH/cxx_exprs.h Sun May 9 19:25:06 2010
@@ -5,7 +5,7 @@
typedef __typeof__(static_cast<void *>(0)) static_cast_result;
// CXXDynamicCastExpr
-struct Base { virtual void f(int x = 492); };
+struct Base { virtual void f(int x = 492); ~Base(); };
struct Derived : Base { void g(); };
Base *base_ptr;
typedef __typeof__(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result;
@@ -44,6 +44,8 @@
typedef __typeof__(typeid(int))* typeid_result1;
typedef __typeof__(typeid(2))* typeid_result2;
+Derived foo();
+
void Derived::g() {
// CXXThisExpr
f(2); // Implicit
@@ -55,4 +57,9 @@
// CXXDefaultArgExpr
f();
+
+ const Derived &X = foo();
+
+
+ // FIXME: CXXBindReferenceExpr ?
}
\ No newline at end of file
More information about the cfe-commits
mailing list