Push nested-name-specifier source location information into

DependentScopeDeclRefExpr. Plus, give NestedNameSpecifierLoc == and !=
operators, since we're going to need 'em elsewhere.

llvm-svn: 126508
This commit is contained in:
Douglas Gregor 2011-02-25 20:49:16 +00:00
parent e167360a45
commit 3a43fd645d
10 changed files with 64 additions and 58 deletions

View File

@ -1873,30 +1873,26 @@ public:
/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
/// declaration can be found.
class DependentScopeDeclRefExpr : public Expr {
/// The name of the entity we will be referencing.
DeclarationNameInfo NameInfo;
/// QualifierRange - The source range that covers the
/// nested-name-specifier.
SourceRange QualifierRange;
/// \brief The nested-name-specifier that qualifies this unresolved
/// declaration name.
NestedNameSpecifier *Qualifier;
NestedNameSpecifierLoc QualifierLoc;
/// The name of the entity we will be referencing.
DeclarationNameInfo NameInfo;
/// \brief Whether the name includes explicit template arguments.
bool HasExplicitTemplateArgs;
DependentScopeDeclRefExpr(QualType T,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NestedNameSpecifierLoc QualifierLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *Args);
friend class ASTStmtReader;
public:
static DependentScopeDeclRefExpr *Create(ASTContext &C,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NestedNameSpecifierLoc QualifierLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs = 0);
@ -1906,24 +1902,23 @@ public:
/// \brief Retrieve the name that this expression refers to.
const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; }
/// \brief Retrieve the name that this expression refers to.
DeclarationName getDeclName() const { return NameInfo.getName(); }
void setDeclName(DeclarationName N) { NameInfo.setName(N); }
/// \brief Retrieve the location of the name within the expression.
SourceLocation getLocation() const { return NameInfo.getLoc(); }
void setLocation(SourceLocation L) { NameInfo.setLoc(L); }
/// \brief Retrieve the source range of the nested-name-specifier.
SourceRange getQualifierRange() const { return QualifierRange; }
void setQualifierRange(SourceRange R) { QualifierRange = R; }
/// \brief Retrieve the nested-name-specifier that qualifies the
/// name, with source location information.
NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
/// \brief Retrieve the nested-name-specifier that qualifies this
/// declaration.
NestedNameSpecifier *getQualifier() const { return Qualifier; }
void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
NestedNameSpecifier *getQualifier() const {
return QualifierLoc.getNestedNameSpecifier();
}
/// Determines whether this lookup had explicit template arguments.
bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
@ -1974,7 +1969,7 @@ public:
}
SourceRange getSourceRange() const {
SourceRange Range(QualifierRange.getBegin(), getLocation());
SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
if (hasExplicitTemplateArgs())
Range.setEnd(getRAngleLoc());
return Range;

View File

@ -300,6 +300,16 @@ public:
/// \brief Determines the data length for the entire
/// nested-name-specifier.
unsigned getDataLength() const { return getDataLength(Qualifier); }
friend bool operator==(NestedNameSpecifierLoc X,
NestedNameSpecifierLoc Y) {
return X.Qualifier == Y.Qualifier && X.Data == Y.Data;
}
friend bool operator!=(NestedNameSpecifierLoc X,
NestedNameSpecifierLoc Y) {
return !(X == Y);
}
};
/// Insertion operator for diagnostics. This allows sending NestedNameSpecifiers

View File

@ -1692,20 +1692,18 @@ DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
})
DEF_TRAVERSE_STMT(DeclRefExpr, {
TRY_TO(TraverseNestedNameSpecifier(S->getQualifier()));
TRY_TO(TraverseTemplateArgumentLocsHelper(
S->getTemplateArgs(), S->getNumTemplateArgs()));
// FIXME: Should we be recursing on the qualifier?
TRY_TO(TraverseNestedNameSpecifier(S->getQualifier()));
})
DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
// FIXME: Should we be recursing on these two things?
TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
if (S->hasExplicitTemplateArgs()) {
TRY_TO(TraverseTemplateArgumentLocsHelper(
S->getExplicitTemplateArgs().getTemplateArgs(),
S->getNumTemplateArgs()));
}
TRY_TO(TraverseNestedNameSpecifier(S->getQualifier()));
})
DEF_TRAVERSE_STMT(MemberExpr, {

View File

@ -283,15 +283,16 @@ CXXRecordDecl *OverloadExpr::getNamingClass() const {
// DependentScopeDeclRefExpr
DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NestedNameSpecifierLoc QualifierLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *Args)
: Expr(DependentScopeDeclRefExprClass, T, VK_LValue, OK_Ordinary,
true, true,
(NameInfo.containsUnexpandedParameterPack() ||
(Qualifier && Qualifier->containsUnexpandedParameterPack()))),
NameInfo(NameInfo), QualifierRange(QualifierRange), Qualifier(Qualifier),
(QualifierLoc &&
QualifierLoc.getNestedNameSpecifier()
->containsUnexpandedParameterPack()))),
QualifierLoc(QualifierLoc), NameInfo(NameInfo),
HasExplicitTemplateArgs(Args != 0)
{
if (Args) {
@ -307,16 +308,14 @@ DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(QualType T,
DependentScopeDeclRefExpr *
DependentScopeDeclRefExpr::Create(ASTContext &C,
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NestedNameSpecifierLoc QualifierLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *Args) {
std::size_t size = sizeof(DependentScopeDeclRefExpr);
if (Args)
size += ExplicitTemplateArgumentList::sizeFor(*Args);
void *Mem = C.Allocate(size);
return new (Mem) DependentScopeDeclRefExpr(C.DependentTy,
Qualifier, QualifierRange,
return new (Mem) DependentScopeDeclRefExpr(C.DependentTy, QualifierLoc,
NameInfo, Args);
}
@ -329,7 +328,7 @@ DependentScopeDeclRefExpr::CreateEmpty(ASTContext &C,
size += ExplicitTemplateArgumentList::sizeFor(NumTemplateArgs);
void *Mem = C.Allocate(size);
DependentScopeDeclRefExpr *E
= new (Mem) DependentScopeDeclRefExpr(QualType(), 0, SourceRange(),
= new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(),
DeclarationNameInfo(), 0);
E->HasExplicitTemplateArgs = HasExplicitTemplateArgs;
return E;

View File

@ -400,8 +400,7 @@ Sema::BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs) {
return Owned(DependentScopeDeclRefExpr::Create(Context,
static_cast<NestedNameSpecifier*>(SS.getScopeRep()),
SS.getRange(),
SS.getWithLocInContext(Context),
NameInfo,
TemplateArgs));
}
@ -2332,9 +2331,13 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param,
DeclarationNameInfo NameInfo(DTN->getIdentifier(),
Arg.getTemplateNameLoc());
// FIXME: TemplateArgumentLoc should store a NestedNameSpecifierLoc
// for the template name.
CXXScopeSpec SS;
SS.MakeTrivial(Context, DTN->getQualifier(),
Arg.getTemplateQualifierRange());
Expr *E = DependentScopeDeclRefExpr::Create(Context,
DTN->getQualifier(),
Arg.getTemplateQualifierRange(),
SS.getWithLocInContext(Context),
NameInfo);
// If we parsed the template argument as a pack expansion, create a

View File

@ -1887,12 +1887,12 @@ public:
///
/// By default, performs semantic analysis to build the new expression.
/// Subclasses may override this routine to provide different behavior.
ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
SourceRange QualifierRange,
ExprResult RebuildDependentScopeDeclRefExpr(
NestedNameSpecifierLoc QualifierLoc,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs) {
CXXScopeSpec SS;
SS.MakeTrivial(SemaRef.Context, NNS, QualifierRange);
SS.Adopt(QualifierLoc);
if (TemplateArgs)
return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
@ -6787,10 +6787,9 @@ template<typename Derived>
ExprResult
TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
DependentScopeDeclRefExpr *E) {
NestedNameSpecifier *NNS
= getDerived().TransformNestedNameSpecifier(E->getQualifier(),
E->getQualifierRange());
if (!NNS)
NestedNameSpecifierLoc QualifierLoc
= getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
if (!QualifierLoc)
return ExprError();
// TODO: If this is a conversion-function-id, verify that the
@ -6804,14 +6803,13 @@ TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
if (!E->hasExplicitTemplateArgs()) {
if (!getDerived().AlwaysRebuild() &&
NNS == E->getQualifier() &&
QualifierLoc == E->getQualifierLoc() &&
// Note: it is sufficient to compare the Name component of NameInfo:
// if name has not changed, DNLoc has not changed either.
NameInfo.getName() == E->getDeclName())
return SemaRef.Owned(E);
return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
E->getQualifierRange(),
return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
NameInfo,
/*TemplateArgs*/ 0);
}
@ -6822,8 +6820,7 @@ TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
TransArgs))
return ExprError();
return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
E->getQualifierRange(),
return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
NameInfo,
&TransArgs);
}

View File

@ -1219,10 +1219,9 @@ ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
if (Record[Idx++])
ReadExplicitTemplateArgumentList(E->getExplicitTemplateArgs(),
Record[Idx++]);
E->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx);
ReadDeclarationNameInfo(E->NameInfo, Record, Idx);
E->setQualifierRange(ReadSourceRange(Record, Idx));
E->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
}
void

View File

@ -1216,9 +1216,8 @@ ASTStmtWriter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
AddExplicitTemplateArgumentList(Args);
}
Writer.AddNestedNameSpecifierLoc(E->getQualifierLoc(), Record);
Writer.AddDeclarationNameInfo(E->NameInfo, Record);
Writer.AddSourceRange(E->getQualifierRange(), Record);
Writer.AddNestedNameSpecifier(E->getQualifier(), Record);
Code = serialization::EXPR_CXX_DEPENDENT_SCOPE_DECL_REF;
}

View File

@ -61,3 +61,10 @@ void PseudoDestructorExprCheck(
PseudoDestructorExprTester<HasInnerTemplate, float> tester) {
tester.f(0); // expected-note{{in instantiation of member function}}
}
template<typename T>
struct DependentScopedDeclRefExpr {
void f() {
outer_alias::inner::X0<T>::value = 17;
}
};

View File

@ -1864,8 +1864,7 @@ void EnqueueVisitor::VisitDeclRefExpr(DeclRefExpr *DR) {
void EnqueueVisitor::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
AddExplicitTemplateArgs(E->getOptionalExplicitTemplateArgs());
AddDeclarationNameInfo(E);
if (NestedNameSpecifier *Qualifier = E->getQualifier())
AddNestedNameSpecifier(Qualifier, E->getQualifierRange());
AddNestedNameSpecifierLoc(E->getQualifierLoc());
}
void EnqueueVisitor::VisitDeclStmt(DeclStmt *S) {
unsigned size = WL.size();