]> granicus.if.org Git - clang/commitdiff
Improve location information in the representation of namespace
authorDouglas Gregor <dgregor@apple.com>
Wed, 1 Sep 2010 00:08:19 +0000 (00:08 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 1 Sep 2010 00:08:19 +0000 (00:08 +0000)
aliases. Previously, the location of the alias was at the "namespace"
keyword. Now, it's on the identifier being declared (as is the custom
for Clang), and we keep a separate source location for the "namespace"
keyword.

Also, added a getSourceRange() member function to NamespaceAliasDecl
to correctly compute the source range.

Finally, removed a bunch of setters from NamespaceAliasDecl and gave
ASTReaderDecl friendship so that it could set the corresponding fields
directly.

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

include/clang/AST/DeclCXX.h
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp
test/Index/load-namespaces.cpp

index b529cf0346ec3c6c8a514da4574fd381046f145e..e259ccb6d218cf60aecefad9fb60776e9e4af998 100644 (file)
@@ -1829,7 +1829,8 @@ public:
 /// namespace Foo = Bar;
 /// @endcode
 class NamespaceAliasDecl : public NamedDecl {
-  SourceLocation AliasLoc;
+  /// \brief The location of the "namespace" keyword.
+  SourceLocation NamespaceLoc;
 
   /// \brief The source range that covers the nested-name-specifier
   /// preceding the namespace name.
@@ -1846,15 +1847,17 @@ class NamespaceAliasDecl : public NamedDecl {
   /// NamespaceDecl or a NamespaceAliasDecl.
   NamedDecl *Namespace;
 
-  NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
+  NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
                      SourceLocation AliasLoc, IdentifierInfo *Alias,
                      SourceRange QualifierRange,
                      NestedNameSpecifier *Qualifier,
                      SourceLocation IdentLoc, NamedDecl *Namespace)
-    : NamedDecl(NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
-      QualifierRange(QualifierRange), Qualifier(Qualifier),
-      IdentLoc(IdentLoc), Namespace(Namespace) { }
+    : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), 
+      NamespaceLoc(NamespaceLoc), QualifierRange(QualifierRange), 
+      Qualifier(Qualifier), IdentLoc(IdentLoc), Namespace(Namespace) { }
 
+  friend class ASTDeclReader;
+  
 public:
   /// \brief Retrieve the source range of the nested-name-specifier
   /// that qualifiers the namespace name.
@@ -1886,41 +1889,31 @@ public:
 
   /// Returns the location of the alias name, i.e. 'foo' in
   /// "namespace foo = ns::bar;".
-  SourceLocation getAliasLoc() const { return AliasLoc; }
-
-  /// Set the location o;f the alias name, e.e., 'foo' in
-  /// "namespace foo = ns::bar;".
-  void setAliasLoc(SourceLocation L) { AliasLoc = L; }
+  SourceLocation getAliasLoc() const { return getLocation(); }
 
   /// Returns the location of the 'namespace' keyword.
-  SourceLocation getNamespaceLoc() const { return getLocation(); }
+  SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
 
   /// Returns the location of the identifier in the named namespace.
   SourceLocation getTargetNameLoc() const { return IdentLoc; }
 
-  /// Set the location of the identifier in the named namespace.
-  void setTargetNameLoc(SourceLocation L) { IdentLoc = L; }
-
   /// \brief Retrieve the namespace that this alias refers to, which
   /// may either be a NamespaceDecl or a NamespaceAliasDecl.
   NamedDecl *getAliasedNamespace() const { return Namespace; }
 
-  /// \brief Set the namespace or namespace alias pointed to by this
-  /// alias decl.
-  void setAliasedNamespace(NamedDecl *ND) {
-    assert((isa<NamespaceAliasDecl>(ND) || isa<NamespaceDecl>(ND)) &&
-      "expecting namespace or namespace alias decl");
-      Namespace = ND;
-  }
-
   static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
-                                    SourceLocation L, SourceLocation AliasLoc,
+                                    SourceLocation NamespaceLoc, 
+                                    SourceLocation AliasLoc,
                                     IdentifierInfo *Alias,
                                     SourceRange QualifierRange,
                                     NestedNameSpecifier *Qualifier,
                                     SourceLocation IdentLoc,
                                     NamedDecl *Namespace);
 
+  virtual SourceRange getSourceRange() const {
+    return SourceRange(NamespaceLoc, IdentLoc);
+  }
+  
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const NamespaceAliasDecl *D) { return true; }
   static bool classofKind(Kind K) { return K == NamespaceAlias; }
index 053b91acb7a81e3c0f1dd542b9d453f887ae20ae..9795bd085d4530fd174ef123e14b26c7f781a1ff 100644 (file)
@@ -622,12 +622,11 @@ void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
 
 void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
   VisitNamedDecl(D);
-
-  D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
+  D->NamespaceLoc = Reader.ReadSourceLocation(Record, Idx);
   D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
   D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
-  D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
-  D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
+  D->IdentLoc = Reader.ReadSourceLocation(Record, Idx);
+  D->Namespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
 }
 
 void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
index 413f544f4c1a9c371e81d6debba704f7d71c62db..9ac12fb56e93448e70dfb0e3843cf7fd0dd46b75 100644 (file)
@@ -614,7 +614,7 @@ void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
 
 void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
   VisitNamedDecl(D);
-  Writer.AddSourceLocation(D->getAliasLoc(), Record);
+  Writer.AddSourceLocation(D->getNamespaceLoc(), Record);
   Writer.AddSourceRange(D->getQualifierRange(), Record);
   Writer.AddNestedNameSpecifier(D->getQualifier(), Record);
   Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
index cf94546a2474cb43f1bbd4d9df9527322f152983..e614f7ca98db3c08e84e13eba56852c88caafc9e 100644 (file)
@@ -21,8 +21,7 @@ namespace std0x = std98;
 // CHECK: load-namespaces.cpp:5:10: FunctionDecl=f:5:10 Extent=[5:10 - 5:13]
 // CHECK: load-namespaces.cpp:9:11: Namespace=std:9:11 (Definition) Extent=[9:11 - 11:2]
 // CHECK: load-namespaces.cpp:10:8: FunctionDecl=g:10:8 Extent=[10:8 - 10:11]
-// CHECK: load-namespaces.cpp:13:1: NamespaceAlias=std98:13:1 Extent=[13:1 - 13:10]
+// CHECK: load-namespaces.cpp:13:11: NamespaceAlias=std98:13:11 Extent=[13:1 - 13:22]
 // CHECK: load-namespaces.cpp:13:19: NamespaceRef=std:3:11 Extent=[13:19 - 13:22]
-// CHECK: load-namespaces.cpp:14:1: NamespaceAlias=std0x:14:1 Extent=[14:1 - 14:10]
-// CHECK: load-namespaces.cpp:14:19: NamespaceRef=std98:13:1 Extent=[14:19 - 14:24]
-
+// CHECK: load-namespaces.cpp:14:11: NamespaceAlias=std0x:14:11 Extent=[14:1 - 14:24]
+// CHECK: load-namespaces.cpp:14:19: NamespaceRef=std98:13:11 Extent=[14:19 - 14:24]