[cfe-commits] r106831 - in /cfe/trunk: include/clang/AST/ExprCXX.h include/clang/Basic/StmtNodes.td include/clang/Frontend/PCHBitCodes.h lib/AST/ExprCXX.cpp lib/Frontend/PCHReaderStmt.cpp lib/Frontend/PCHWriterStmt.cpp test/PCH/cxx-templates.h
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Jun 25 02:03:26 PDT 2010
Author: akirtzidis
Date: Fri Jun 25 04:03:26 2010
New Revision: 106831
URL: http://llvm.org/viewvc/llvm-project?rev=106831&view=rev
Log:
Support UnresolvedMemberExpr for PCH.
Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/Basic/StmtNodes.td
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-templates.h
Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=106831&r1=106830&r2=106831&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Fri Jun 25 04:03:26 2010
@@ -1369,16 +1369,20 @@
/// The location of the name.
SourceLocation NameLoc;
+protected:
/// True if the name was a template-id.
bool HasExplicitTemplateArgs;
-protected:
OverloadExpr(StmtClass K, ASTContext &C, QualType T, bool Dependent,
NestedNameSpecifier *Qualifier, SourceRange QRange,
DeclarationName Name, SourceLocation NameLoc,
bool HasTemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+ OverloadExpr(StmtClass K, EmptyShell Empty)
+ : Expr(K, Empty), Results(0), NumResults(0),
+ Qualifier(0), HasExplicitTemplateArgs(false) { }
+
public:
/// Computes whether an unresolved lookup on the given declarations
/// and optional template arguments is type- and value-dependent.
@@ -1409,6 +1413,9 @@
decls_iterator decls_end() const {
return UnresolvedSetIterator(Results + NumResults);
}
+
+ void initializeResults(ASTContext &C,
+ UnresolvedSetIterator Begin,UnresolvedSetIterator End);
/// Gets the number of declarations in the unresolved set.
unsigned getNumDecls() const { return NumResults; }
@@ -1423,9 +1430,11 @@
/// Fetches the nested-name qualifier, if one was given.
NestedNameSpecifier *getQualifier() const { return Qualifier; }
+ void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
/// Fetches the range of the nested-name qualifier.
SourceRange getQualifierRange() const { return QualifierRange; }
+ void setQualifierRange(SourceRange R) { QualifierRange = R; }
/// \brief Determines whether this expression had an explicit
/// template argument list, e.g. f<int>.
@@ -2161,6 +2170,10 @@
SourceLocation MemberLoc,
const TemplateArgumentListInfo *TemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+
+ UnresolvedMemberExpr(EmptyShell Empty)
+ : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
+ HasUnresolvedUsing(false), Base(0) { }
public:
static UnresolvedMemberExpr *
@@ -2174,6 +2187,9 @@
const TemplateArgumentListInfo *TemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+ static UnresolvedMemberExpr *
+ CreateEmpty(ASTContext &C, unsigned NumTemplateArgs);
+
/// \brief True if this is an implicit access, i.e. one in which the
/// member being accessed was not written in the source. The source
/// location of the operator is invalid in this case.
@@ -2192,6 +2208,12 @@
void setBase(Expr *E) { Base = E; }
QualType getBaseType() const { return BaseType; }
+ void setBaseType(QualType T) { BaseType = T; }
+
+ /// \brief Determine whether the lookup results contain an unresolved using
+ /// declaration.
+ bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
+ void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; }
/// \brief Determine whether this member expression used the '->'
/// operator; otherwise, it used the '.' operator.
Modified: cfe/trunk/include/clang/Basic/StmtNodes.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/StmtNodes.td?rev=106831&r1=106830&r2=106831&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/StmtNodes.td (original)
+++ cfe/trunk/include/clang/Basic/StmtNodes.td Fri Jun 25 04:03:26 2010
@@ -99,7 +99,6 @@
def CXXNewExpr : DStmt<Expr>;
def CXXDeleteExpr : DStmt<Expr>;
def CXXPseudoDestructorExpr : DStmt<Expr>;
-def UnresolvedLookupExpr : DStmt<Expr>;
def UnaryTypeTraitExpr : DStmt<Expr>;
def DependentScopeDeclRefExpr : DStmt<Expr>;
def CXXConstructExpr : DStmt<Expr>;
@@ -109,7 +108,9 @@
def CXXTemporaryObjectExpr : DStmt<CXXConstructExpr>;
def CXXUnresolvedConstructExpr : DStmt<Expr>;
def CXXDependentScopeMemberExpr : DStmt<Expr>;
-def UnresolvedMemberExpr : DStmt<Expr>;
+def OverloadExpr : DStmt<Expr, 1>;
+def UnresolvedLookupExpr : DStmt<OverloadExpr>;
+def UnresolvedMemberExpr : DStmt<OverloadExpr>;
// Obj-C Expressions.
def ObjCStringLiteral : DStmt<Expr>;
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=106831&r1=106830&r2=106831&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Fri Jun 25 04:03:26 2010
@@ -770,7 +770,8 @@
EXPR_CXX_EXPR_WITH_TEMPORARIES, // CXXExprWithTemporaries
EXPR_CXX_DEPENDENT_SCOPE_MEMBER, // CXXDependentScopeMemberExpr
- EXPR_CXX_UNRESOLVED_CONSTRUCT // CXXUnresolvedConstructExpr
+ EXPR_CXX_UNRESOLVED_CONSTRUCT, // CXXUnresolvedConstructExpr
+ EXPR_CXX_UNRESOLVED_MEMBER // UnresolvedMemberExpr
};
/// \brief The kinds of designators that can occur in a
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=106831&r1=106830&r2=106831&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Fri Jun 25 04:03:26 2010
@@ -197,19 +197,28 @@
UnresolvedSetIterator Begin,
UnresolvedSetIterator End)
: Expr(K, T, Dependent, Dependent),
- Results(0), NumResults(End - Begin), Name(Name), Qualifier(Qualifier),
+ Results(0), NumResults(0), Name(Name), Qualifier(Qualifier),
QualifierRange(QRange), NameLoc(NameLoc),
HasExplicitTemplateArgs(HasTemplateArgs)
{
+ initializeResults(C, Begin, End);
+}
+
+void OverloadExpr::initializeResults(ASTContext &C,
+ UnresolvedSetIterator Begin,
+ UnresolvedSetIterator End) {
+ assert(Results == 0 && "Results already initialized!");
+ NumResults = End - Begin;
if (NumResults) {
Results = static_cast<DeclAccessPair *>(
C.Allocate(sizeof(DeclAccessPair) * NumResults,
llvm::alignof<DeclAccessPair>()));
memcpy(Results, &*Begin.getIterator(),
- (End - Begin) * sizeof(DeclAccessPair));
+ NumResults * sizeof(DeclAccessPair));
}
}
+
bool OverloadExpr::ComputeDependence(UnresolvedSetIterator Begin,
UnresolvedSetIterator End,
const TemplateArgumentListInfo *Args) {
@@ -801,6 +810,18 @@
Member, MemberLoc, TemplateArgs, Begin, End);
}
+UnresolvedMemberExpr *
+UnresolvedMemberExpr::CreateEmpty(ASTContext &C, unsigned NumTemplateArgs) {
+ std::size_t size = sizeof(UnresolvedMemberExpr);
+ if (NumTemplateArgs != 0)
+ size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
+
+ void *Mem = C.Allocate(size, llvm::alignof<UnresolvedMemberExpr>());
+ UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell());
+ E->HasExplicitTemplateArgs = NumTemplateArgs != 0;
+ return E;
+}
+
CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const {
// Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
Modified: cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderStmt.cpp?rev=106831&r1=106830&r2=106831&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Fri Jun 25 04:03:26 2010
@@ -140,6 +140,9 @@
unsigned VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
unsigned VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
+
+ unsigned VisitOverloadExpr(OverloadExpr *E);
+ unsigned VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
};
}
@@ -1161,6 +1164,47 @@
return E->arg_size();
}
+unsigned PCHStmtReader::VisitOverloadExpr(OverloadExpr *E) {
+ VisitExpr(E);
+
+ unsigned NumTemplateArgs = Record[Idx++];
+ assert((NumTemplateArgs != 0) == E->hasExplicitTemplateArgs() &&
+ "Read wrong record during creation ?");
+ if (E->hasExplicitTemplateArgs()) {
+ TemplateArgumentListInfo ArgInfo;
+ ArgInfo.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
+ ArgInfo.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
+ for (unsigned i = 0; i != NumTemplateArgs; ++i)
+ ArgInfo.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
+ E->getExplicitTemplateArgs().initializeFrom(ArgInfo);
+ }
+
+ unsigned NumDecls = Record[Idx++];
+ UnresolvedSet<8> Decls;
+ for (unsigned i = 0; i != NumDecls; ++i) {
+ NamedDecl *D = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
+ AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
+ Decls.addDecl(D, AS);
+ }
+ E->initializeResults(*Reader.getContext(), Decls.begin(), Decls.end());
+
+ E->setName(Reader.ReadDeclarationName(Record, Idx));
+ E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
+ E->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
+ E->setNameLoc(Reader.ReadSourceLocation(Record, Idx));
+ return 0;
+}
+
+unsigned PCHStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
+ VisitOverloadExpr(E);
+ E->setArrow(Record[Idx++]);
+ E->setHasUnresolvedUsing(Record[Idx++]);
+ E->setBase(cast_or_null<Expr>(StmtStack.back()));
+ E->setBaseType(Reader.GetType(Record[Idx++]));
+ E->setOperatorLoc(Reader.ReadSourceLocation(Record, Idx));
+ return 1;
+}
+
// Within the bitstream, expressions are stored in Reverse Polish
// Notation, with each of the subexpressions preceding the
@@ -1546,12 +1590,17 @@
case pch::EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
S = CXXDependentScopeMemberExpr::CreateEmpty(*Context,
- Record[PCHStmtReader::NumExprFields]);
+ /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]);
break;
case pch::EXPR_CXX_UNRESOLVED_CONSTRUCT:
S = CXXUnresolvedConstructExpr::CreateEmpty(*Context,
- Record[PCHStmtReader::NumExprFields]);
+ /*NumArgs=*/Record[PCHStmtReader::NumExprFields]);
+ break;
+
+ case pch::EXPR_CXX_UNRESOLVED_MEMBER:
+ S = UnresolvedMemberExpr::CreateEmpty(*Context,
+ /*NumTemplateArgs=*/Record[PCHStmtReader::NumExprFields]);
break;
}
Modified: cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterStmt.cpp?rev=106831&r1=106830&r2=106831&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterStmt.cpp Fri Jun 25 04:03:26 2010
@@ -135,6 +135,9 @@
void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
void VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
void VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
+
+ void VisitOverloadExpr(OverloadExpr *E);
+ void VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
};
}
@@ -1066,6 +1069,45 @@
Code = pch::EXPR_CXX_UNRESOLVED_CONSTRUCT;
}
+void PCHStmtWriter::VisitOverloadExpr(OverloadExpr *E) {
+ VisitExpr(E);
+
+ if (E->hasExplicitTemplateArgs()) {
+ const ExplicitTemplateArgumentList &Args = E->getExplicitTemplateArgs();
+ assert(Args.NumTemplateArgs &&
+ "Num of template args was zero! PCH reading will mess up!");
+ Record.push_back(Args.NumTemplateArgs);
+ Writer.AddSourceLocation(Args.LAngleLoc, Record);
+ Writer.AddSourceLocation(Args.RAngleLoc, Record);
+ for (unsigned i=0; i != Args.NumTemplateArgs; ++i)
+ Writer.AddTemplateArgumentLoc(Args.getTemplateArgs()[i], Record);
+ } else {
+ Record.push_back(0);
+ }
+
+ Record.push_back(E->getNumDecls());
+ for (OverloadExpr::decls_iterator
+ OvI = E->decls_begin(), OvE = E->decls_end(); OvI != OvE; ++OvI) {
+ Writer.AddDeclRef(OvI.getDecl(), Record);
+ Record.push_back(OvI.getAccess());
+ }
+
+ Writer.AddDeclarationName(E->getName(), Record);
+ Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
+ Writer.AddSourceRange(E->getQualifierRange(), Record);
+ Writer.AddSourceLocation(E->getNameLoc(), Record);
+}
+
+void PCHStmtWriter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
+ VisitOverloadExpr(E);
+ Record.push_back(E->isArrow());
+ Record.push_back(E->hasUnresolvedUsing());
+ Writer.WriteSubStmt(!E->isImplicitAccess() ? E->getBase() : 0);
+ Writer.AddTypeRef(E->getBaseType(), Record);
+ Writer.AddSourceLocation(E->getOperatorLoc(), Record);
+ Code = pch::EXPR_CXX_UNRESOLVED_MEMBER;
+}
+
//===----------------------------------------------------------------------===//
// PCHWriter Implementation
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/test/PCH/cxx-templates.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-templates.h?rev=106831&r1=106830&r2=106831&view=diff
==============================================================================
--- cfe/trunk/test/PCH/cxx-templates.h (original)
+++ cfe/trunk/test/PCH/cxx-templates.h Fri Jun 25 04:03:26 2010
@@ -27,7 +27,11 @@
Ty x = Ty();
T::my_f();
int y = T::template my_templf<int>(0);
+ ovl(y);
}
+
+ void ovl(int);
+ void ovl(float);
};
template<typename T, typename A1>
More information about the cfe-commits
mailing list