return static_cast<Expr*>(Operand.get<Stmt *>());
}
+ void setExprOperand(Expr *E) {
+ assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
+ Operand = E;
+ }
+
virtual SourceRange getSourceRange() const { return Range; }
void setSourceRange(SourceRange R) { Range = R; }
CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
Expr *SubExpr)
- : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc)
- {
+ : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc) {
*reinterpret_cast<Expr **>(this + 1) = SubExpr;
}
virtual void DoDestroy(ASTContext &C);
public:
+ CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
+
+
// Param is the parameter whose default argument is used by this
// expression.
static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
const ParmVarDecl *getParam() const { return Param.getPointer(); }
ParmVarDecl *getParam() { return Param.getPointer(); }
+ /// isExprStored - Return true if this expression owns the expression.
+ bool isExprStored() const { return Param.getInt(); }
+
// Retrieve the actual argument to the function call.
const Expr *getExpr() const {
if (Param.getInt())
return *reinterpret_cast<Expr **> (this + 1);
return getParam()->getDefaultArg();
}
+
+ void setExpr(Expr *E) {
+ Param.setInt(true);
+ Param.setPointer((ParmVarDecl*)E);
+ }
/// \brief Retrieve the location where this default argument was actually
/// used.
SourceLocation getUsedLocation() const { return Loc; }
+ void setUsedLocation(SourceLocation L) { Loc = L; }
virtual SourceRange getSourceRange() const {
// Default argument expressions have no representation in the
EXPR_CXX_TYPEID_EXPR, // CXXTypeidExpr (of expr).
EXPR_CXX_TYPEID_TYPE, // CXXTypeidExpr (of type).
EXPR_CXX_THIS, // CXXThisExpr
- EXPR_CXX_THROW // CXXThrowExpr
+ EXPR_CXX_THROW, // CXXThrowExpr
+ EXPR_CXX_DEFAULT_ARG // CXXDefaultArgExpr
};
/// \brief The kinds of designators that can occur in a
unsigned VisitCXXTypeidExpr(CXXTypeidExpr *E);
unsigned VisitCXXThisExpr(CXXThisExpr *E);
unsigned VisitCXXThrowExpr(CXXThrowExpr *E);
+ unsigned VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
};
}
VisitExpr(E);
E->setSubExpr(cast<Expr>(StmtStack.back()));
E->setCastKind((CastExpr::CastKind)Record[Idx++]);
-
return 1;
}
}
// typeid(42+2)
+ E->setExprOperand(cast<Expr>(StmtStack.back()));
return 1;
}
unsigned PCHStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
VisitExpr(E);
E->setThrowLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ E->setSubExpr(cast<Expr>(StmtStack.back()));
return 1;
}
+unsigned PCHStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
+ VisitExpr(E);
+ E->setUsedLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
+ bool HasStoredExpr = Record[Idx++];
+ if (!HasStoredExpr) return 0;
+ E->setExpr(cast<Expr>(StmtStack.back()));
+ return 1; // Read it.
+}
+
+
// Within the bitstream, expressions are stored in Reverse Polish
// Notation, with each of the subexpressions preceding the
// expression they are stored in. To evaluate expressions, we
case pch::EXPR_CXX_THROW:
S = new (Context) CXXThrowExpr(Empty);
break;
+ case pch::EXPR_CXX_DEFAULT_ARG:
+ S = new (Context) CXXDefaultArgExpr(Empty);
+ break;
}
// We hit a STMT_STOP, so we're done with this expression.
Record.push_back(D->isDeclaredInCondition());
Record.push_back(D->isExceptionVariable());
Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
- Record.push_back(D->getInit()? 1 : 0);
+ Record.push_back(D->getInit() ? 1 : 0);
if (D->getInit())
Writer.AddStmt(D->getInit());
Code = pch::DECL_VAR;
D->getStorageClass() == 0 &&
!D->hasCXXDirectInitializer() && // Can params have this ever?
D->getObjCDeclQualifier() == 0 &&
- !D->hasInheritedDefaultArg())
+ !D->hasInheritedDefaultArg() &&
+ D->getInit() == 0) // No default expr.
AbbrevToUse = Writer.getParmVarDeclAbbrev();
// Check things we know are true of *every* PARM_VAR_DECL, which is more than
assert(!D->isDeclaredInCondition() && "PARM_VAR_DECL can't be in condition");
assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
assert(D->getPreviousDeclaration() == 0 && "PARM_VAR_DECL can't be redecl");
- assert(D->getInit() == 0 && "PARM_VAR_DECL never has init");
}
void PCHDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
void VisitCXXTypeidExpr(CXXTypeidExpr *E);
void VisitCXXThisExpr(CXXThisExpr *E);
void VisitCXXThrowExpr(CXXThrowExpr *E);
+ void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
};
}
}
void PCHStmtWriter::VisitCXXThrowExpr(CXXThrowExpr *E) {
+ VisitExpr(E);
Writer.AddSourceLocation(E->getThrowLoc(), Record);
Writer.WriteSubStmt(E->getSubExpr());
Code = pch::EXPR_CXX_THROW;
}
+void PCHStmtWriter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
+ VisitExpr(E);
+ Writer.AddSourceLocation(E->getUsedLocation(), Record);
+ if (E->isExprStored()) {
+ Record.push_back(1);
+ Writer.WriteSubStmt(E->getExpr());
+ } else {
+ Record.push_back(0);
+ }
+
+ Code = pch::EXPR_CXX_DEFAULT_ARG;
+}
+
//===----------------------------------------------------------------------===//
// PCHWriter Implementation
typedef __typeof__(static_cast<void *>(0)) static_cast_result;
// CXXDynamicCastExpr
-struct Base { virtual void f(); };
+struct Base { virtual void f(int x = 492); };
struct Derived : Base { void g(); };
Base *base_ptr;
typedef __typeof__(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result;
void foo(Derived *P) {
// CXXMemberCallExpr
- P->f();
+ P->f(12);
}
void Derived::g() {
// CXXThisExpr
- f(); // Implicit
- this->f(); // Explicit
+ f(2); // Implicit
+ this->f(1); // Explicit
// CXXThrowExpr
throw;
throw 42;
+
+ // CXXDefaultArgExpr
+ f();
}
\ No newline at end of file