[cfe-commits] r112681 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp test/Index/load-namespaces.cpp

Douglas Gregor dgregor at apple.com
Tue Aug 31 17:08:19 PDT 2010


Author: dgregor
Date: Tue Aug 31 19:08:19 2010
New Revision: 112681

URL: http://llvm.org/viewvc/llvm-project?rev=112681&view=rev
Log:
Improve location information in the representation of namespace
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.

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

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=112681&r1=112680&r2=112681&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Tue Aug 31 19:08:19 2010
@@ -1829,7 +1829,8 @@
 /// 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 @@
   /// 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 @@
 
   /// 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; }

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=112681&r1=112680&r2=112681&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Tue Aug 31 19:08:19 2010
@@ -622,12 +622,11 @@
 
 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) {

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=112681&r1=112680&r2=112681&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Tue Aug 31 19:08:19 2010
@@ -614,7 +614,7 @@
 
 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);

Modified: cfe/trunk/test/Index/load-namespaces.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-namespaces.cpp?rev=112681&r1=112680&r2=112681&view=diff
==============================================================================
--- cfe/trunk/test/Index/load-namespaces.cpp (original)
+++ cfe/trunk/test/Index/load-namespaces.cpp Tue Aug 31 19:08:19 2010
@@ -21,8 +21,7 @@
 // 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]





More information about the cfe-commits mailing list