From: Douglas Gregor Date: Fri, 25 Feb 2011 17:08:07 +0000 (+0000) Subject: Push nested-name-specifier source location information into namespace X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0cfaf6a270ecd0f5c7e541a8047c87948317548b;p=clang Push nested-name-specifier source location information into namespace aliases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126496 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index c231e4703b..1656a7e973 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -1837,49 +1837,37 @@ class NamespaceAliasDecl : public NamedDecl { /// \brief The location of the "namespace" keyword. SourceLocation NamespaceLoc; - /// \brief The source range that covers the nested-name-specifier - /// preceding the namespace name. - SourceRange QualifierRange; - - /// \brief The nested-name-specifier that precedes the namespace - /// name, if any. - NestedNameSpecifier *Qualifier; - /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc. SourceLocation IdentLoc; - + + /// \brief The nested-name-specifier that precedes the namespace. + NestedNameSpecifierLoc QualifierLoc; + /// Namespace - The Decl that this alias points to. Can either be a /// NamespaceDecl or a NamespaceAliasDecl. NamedDecl *Namespace; NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, - SourceRange QualifierRange, - NestedNameSpecifier *Qualifier, + NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Namespace) : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), - NamespaceLoc(NamespaceLoc), QualifierRange(QualifierRange), - Qualifier(Qualifier), IdentLoc(IdentLoc), Namespace(Namespace) { } + NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), + QualifierLoc(QualifierLoc), Namespace(Namespace) { } friend class ASTDeclReader; public: - /// \brief Retrieve the source range of the nested-name-specifier - /// that qualifiers the namespace name. - SourceRange getQualifierRange() const { return QualifierRange; } - - /// \brief Set the source range of the nested-name-specifier that qualifies - /// the namespace name. - void setQualifierRange(SourceRange R) { QualifierRange = R; } - + /// \brief Retrieve the nested-name-specifier that qualifies the + /// name of the namespace, with source-location information. + NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } + /// \brief Retrieve the nested-name-specifier that qualifies the /// name of the namespace. - NestedNameSpecifier *getQualifier() const { return Qualifier; } - - /// \brief Set the nested-name-specifier that qualifies the name of the - /// namespace. - void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; } - + NestedNameSpecifier *getQualifier() const { + return QualifierLoc.getNestedNameSpecifier(); + } + /// \brief Retrieve the namespace declaration aliased by this directive. NamespaceDecl *getNamespace() { if (NamespaceAliasDecl *AD = dyn_cast(Namespace)) @@ -1910,8 +1898,7 @@ public: SourceLocation NamespaceLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, - SourceRange QualifierRange, - NestedNameSpecifier *Qualifier, + NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Namespace); diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index aafe480e80..46768c12d8 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -1288,14 +1288,13 @@ NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, - SourceRange QualifierRange, - NestedNameSpecifier *Qualifier, + NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Namespace) { if (NamespaceDecl *NS = dyn_cast_or_null(Namespace)) Namespace = NS->getOriginalNamespace(); - return new (C) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias, QualifierRange, - Qualifier, IdentLoc, Namespace); + return new (C) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias, + QualifierLoc, IdentLoc, Namespace); } UsingDecl *UsingShadowDecl::getUsingDecl() const { diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index fb65dd822b..f483262a8c 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -4542,8 +4542,7 @@ Decl *Sema::ActOnNamespaceAliasDef(Scope *S, NamespaceAliasDecl *AliasDecl = NamespaceAliasDecl::Create(Context, CurContext, NamespaceLoc, AliasLoc, - Alias, SS.getRange(), - (NestedNameSpecifier *)SS.getScopeRep(), + Alias, SS.getWithLocInContext(Context), IdentLoc, R.getFoundDecl()); PushOnScopeChains(AliasDecl, S); diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 1d75da71f5..3a40b6fd77 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -120,9 +120,8 @@ TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { = NamespaceAliasDecl::Create(SemaRef.Context, Owner, D->getNamespaceLoc(), D->getAliasLoc(), - D->getNamespace()->getIdentifier(), - D->getQualifierRange(), - D->getQualifier(), + D->getIdentifier(), + D->getQualifierLoc(), D->getTargetNameLoc(), D->getNamespace()); Owner->addDecl(Inst); diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index f7c8e17a34..493ccbad86 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -744,9 +744,8 @@ void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { VisitNamedDecl(D); D->NamespaceLoc = ReadSourceLocation(Record, Idx); - D->setQualifierRange(ReadSourceRange(Record, Idx)); - D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx)); D->IdentLoc = ReadSourceLocation(Record, Idx); + D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); D->Namespace = cast(Reader.GetDecl(Record[Idx++])); } @@ -1428,7 +1427,8 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) { break; case DECL_NAMESPACE_ALIAS: D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(), - SourceLocation(), 0, SourceRange(), 0, + SourceLocation(), 0, + NestedNameSpecifierLoc(), SourceLocation(), 0); break; case DECL_USING: diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 43eff0997f..12d1226be9 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -697,9 +697,8 @@ void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { VisitNamedDecl(D); Writer.AddSourceLocation(D->getNamespaceLoc(), Record); - Writer.AddSourceRange(D->getQualifierRange(), Record); - Writer.AddNestedNameSpecifier(D->getQualifier(), Record); Writer.AddSourceLocation(D->getTargetNameLoc(), Record); + Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record); Writer.AddDeclRef(D->getNamespace(), Record); Code = serialization::DECL_NAMESPACE_ALIAS; } diff --git a/test/Index/annotate-nested-name-specifier.cpp b/test/Index/annotate-nested-name-specifier.cpp index cc8e8eedf3..216fc4ec9c 100644 --- a/test/Index/annotate-nested-name-specifier.cpp +++ b/test/Index/annotate-nested-name-specifier.cpp @@ -49,8 +49,9 @@ namespace outer { } using namespace outer_alias::inner::secret; +namespace super_secret = outer_alias::inner::secret; -// RUN: c-index-test -test-annotate-tokens=%s:13:1:52:1 %s | FileCheck %s +// RUN: c-index-test -test-annotate-tokens=%s:13:1:53:1 %s | FileCheck %s // CHECK: Keyword: "using" [14:1 - 14:6] UsingDeclaration=vector[4:12] // CHECK: Identifier: "outer_alias" [14:7 - 14:18] NamespaceRef=outer_alias:10:11 @@ -107,3 +108,15 @@ using namespace outer_alias::inner::secret; // CHECK: Identifier: "inner" [51:30 - 51:35] NamespaceRef=inner:45:13 // CHECK: Punctuation: "::" [51:35 - 51:37] UsingDirective=:51:37 // CHECK: Identifier: "secret" [51:37 - 51:43] NamespaceRef=secret:46:15 + +// Namespace alias +// CHECK: Keyword: "namespace" [52:1 - 52:10] NamespaceAlias=super_secret:52:11 +// CHECK: Identifier: "super_secret" [52:11 - 52:23] NamespaceAlias=super_secret:52:11 +// CHECK: Punctuation: "=" [52:24 - 52:25] NamespaceAlias=super_secret:52:11 +// CHECK: Identifier: "outer_alias" [52:26 - 52:37] NamespaceRef=outer_alias:10:11 +// CHECK: Punctuation: "::" [52:37 - 52:39] NamespaceAlias=super_secret:52:11 +// CHECK: Identifier: "inner" [52:39 - 52:44] NamespaceRef=inner:45:13 +// CHECK: Punctuation: "::" [52:44 - 52:46] NamespaceAlias=super_secret:52:11 +// CHECK: Identifier: "secret" [52:46 - 52:52] NamespaceRef=secret:46:15 +// CHECK: Punctuation: ";" [52:52 - 52:53] + diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index ccaeaa69af..a09a737125 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1080,8 +1080,8 @@ bool CursorVisitor::VisitNamespaceDecl(NamespaceDecl *D) { bool CursorVisitor::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { // Visit nested-name-specifier. - if (NestedNameSpecifier *Qualifier = D->getQualifier()) - if (VisitNestedNameSpecifier(Qualifier, D->getQualifierRange())) + if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) + if (VisitNestedNameSpecifierLoc(QualifierLoc)) return true; return Visit(MakeCursorNamespaceRef(D->getAliasedNamespace(),