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); }
/// 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;
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];
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); }
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
/// 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());
}
// \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();
/// \brief Emit a source range.
void AddSourceRange(SourceRange Range, RecordData &Record);
-
+
/// \brief Emit an integral value.
void AddAPInt(const llvm::APInt &Value, RecordData &Record);
/// \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);
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,
}
CXXExprWithTemporaries::~CXXExprWithTemporaries() {
+ // FIXME: This is a memory leak in disable free mode.
delete[] Temps;
}
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);
}
unsigned VisitCXXThisExpr(CXXThisExpr *E);
unsigned VisitCXXThrowExpr(CXXThrowExpr *E);
unsigned VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
+ unsigned VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+
+ unsigned VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
};
}
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;
}
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.
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()) {
void VisitCXXThisExpr(CXXThisExpr *E);
void VisitCXXThrowExpr(CXXThrowExpr *E);
void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
+ void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+
+ void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
};
}
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
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() &&
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;
typedef __typeof__(typeid(int))* typeid_result1;
typedef __typeof__(typeid(2))* typeid_result2;
+Derived foo();
+
void Derived::g() {
// CXXThisExpr
f(2); // Implicit
// CXXDefaultArgExpr
f();
+
+ const Derived &X = foo();
+
+
+ // FIXME: CXXBindReferenceExpr ?
}
\ No newline at end of file