]> granicus.if.org Git - clang/commitdiff
Push nested-name-specifier source location information into namespace
authorDouglas Gregor <dgregor@apple.com>
Fri, 25 Feb 2011 17:08:07 +0000 (17:08 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 25 Feb 2011 17:08:07 +0000 (17:08 +0000)
aliases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126496 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclCXX.h
lib/AST/DeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp
test/Index/annotate-nested-name-specifier.cpp
tools/libclang/CIndex.cpp

index c231e4703bc88557d2ae57014961b6977da39339..1656a7e9737c980d4bde329d859a892b2d5f879f 100644 (file)
@@ -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<NamespaceAliasDecl>(Namespace))
@@ -1910,8 +1898,7 @@ public:
                                     SourceLocation NamespaceLoc, 
                                     SourceLocation AliasLoc,
                                     IdentifierInfo *Alias,
-                                    SourceRange QualifierRange,
-                                    NestedNameSpecifier *Qualifier,
+                                    NestedNameSpecifierLoc QualifierLoc,
                                     SourceLocation IdentLoc,
                                     NamedDecl *Namespace);
 
index aafe480e80c0b55bad9643767e6f8e01aaab2412..46768c12d87940e845c2e675a4b133cef80cf7bf 100644 (file)
@@ -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<NamespaceDecl>(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 {
index fb65dd822b0aabcfda14705e6ba49b45797ff98b..f483262a8cf589fb13ae30f2b2d66bbabaeac3df 100644 (file)
@@ -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);
index 1d75da71f59715777673c854ae0f1e9d4c7966e2..3a40b6fd77a78ecb9820d2a285bf8e90cd232258 100644 (file)
@@ -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);
index f7c8e17a340ac17724c36624035e3000beb926eb..493ccbad8618a2c6446080683557281e052d78ff 100644 (file)
@@ -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<NamedDecl>(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:
index 43eff0997f123e210cfa372e61e9cdc58bda8012..12d1226be94ebe3f5a0577e70b18297d3c0bf9a0 100644 (file)
@@ -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;
 }
index cc8e8eedf347d5cf02927112efecda2764e85eba..216fc4ec9c7df2c091d6807f519b1355d2858eb0 100644 (file)
@@ -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]
+
index ccaeaa69aff495e2c42190d426f9448e32d8df9a..a09a7371251259d1d5e032a957510adb4f719e69 100644 (file)
@@ -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(),