[cfe-commits] r103376 - in /cfe/trunk: include/clang/AST/ExprCXX.h include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReaderStmt.cpp lib/Frontend/PCHWriterDecl.cpp lib/Frontend/PCHWriterStmt.cpp test/PCH/cxx_exprs.h
Chris Lattner
sabre at nondot.org
Sat May 8 23:40:09 PDT 2010
Author: lattner
Date: Sun May 9 01:40:08 2010
New Revision: 103376
URL: http://llvm.org/viewvc/llvm-project?rev=103376&view=rev
Log:
pch'ify default argument definitions and uses.
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
cfe/trunk/lib/Frontend/PCHWriterDecl.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=103376&r1=103375&r2=103376&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sun May 9 01:40:08 2010
@@ -351,6 +351,11 @@
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; }
@@ -471,8 +476,7 @@
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;
}
@@ -480,6 +484,9 @@
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,
@@ -498,6 +505,9 @@
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())
@@ -509,10 +519,16 @@
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
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=103376&r1=103375&r2=103376&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Sun May 9 01:40:08 2010
@@ -750,7 +750,8 @@
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
Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=103376&r1=103375&r2=103376&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Sun May 9 01:40:08 2010
@@ -129,6 +129,7 @@
unsigned VisitCXXTypeidExpr(CXXTypeidExpr *E);
unsigned VisitCXXThisExpr(CXXThisExpr *E);
unsigned VisitCXXThrowExpr(CXXThrowExpr *E);
+ unsigned VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
};
}
@@ -532,7 +533,6 @@
VisitExpr(E);
E->setSubExpr(cast<Expr>(StmtStack.back()));
E->setCastKind((CastExpr::CastKind)Record[Idx++]);
-
return 1;
}
@@ -1004,6 +1004,7 @@
}
// typeid(42+2)
+ E->setExprOperand(cast<Expr>(StmtStack.back()));
return 1;
}
@@ -1017,9 +1018,20 @@
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
@@ -1381,6 +1393,9 @@
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.
Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=103376&r1=103375&r2=103376&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Sun May 9 01:40:08 2010
@@ -416,7 +416,7 @@
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;
@@ -445,7 +445,8 @@
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
@@ -456,7 +457,6 @@
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) {
Modified: cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterStmt.cpp?rev=103376&r1=103375&r2=103376&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterStmt.cpp Sun May 9 01:40:08 2010
@@ -125,6 +125,7 @@
void VisitCXXTypeidExpr(CXXTypeidExpr *E);
void VisitCXXThisExpr(CXXThisExpr *E);
void VisitCXXThrowExpr(CXXThrowExpr *E);
+ void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
};
}
@@ -934,11 +935,25 @@
}
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
Modified: cfe/trunk/test/PCH/cxx_exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx_exprs.h?rev=103376&r1=103375&r2=103376&view=diff
==============================================================================
--- cfe/trunk/test/PCH/cxx_exprs.h (original)
+++ cfe/trunk/test/PCH/cxx_exprs.h Sun May 9 01:40:08 2010
@@ -5,7 +5,7 @@
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;
@@ -31,7 +31,7 @@
void foo(Derived *P) {
// CXXMemberCallExpr
- P->f();
+ P->f(12);
}
@@ -46,10 +46,13 @@
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
More information about the cfe-commits
mailing list