[cfe-commits] r67284 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Type.cpp test/SemaCXX/elaborated-type-specifier.cpp test/SemaCXX/enum.cpp test/SemaCXX/qualified-names-diag.cpp test/SemaTemplate/class-template-id-2.cpp test/SemaTemplate/qualified-names-diag.cpp

Douglas Gregor dgregor at apple.com
Wed Mar 18 21:25:59 PDT 2009


Author: dgregor
Date: Wed Mar 18 23:25:59 2009
New Revision: 67284

URL: http://llvm.org/viewvc/llvm-project?rev=67284&view=rev
Log:
Print the context of tag types as part of pretty-printing, e.g.,

  struct N::M::foo


Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp
    cfe/trunk/test/SemaCXX/enum.cpp
    cfe/trunk/test/SemaCXX/qualified-names-diag.cpp
    cfe/trunk/test/SemaTemplate/class-template-id-2.cpp
    cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=67284&r1=67283&r2=67284&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Mar 18 23:25:59 2009
@@ -860,6 +860,7 @@
   friend class TagDecl;
   friend class TemplateTypeParmDecl;
   friend class ClassTemplateSpecializationDecl;
+  friend class TagType;
 
 protected:
   TypeDecl(Kind DK, DeclContext *DC, SourceLocation L,

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=67284&r1=67283&r2=67284&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Wed Mar 18 23:25:59 2009
@@ -1526,8 +1526,35 @@
     InnerString = TemplateArgs + InnerString;
   }
 
-  if (Kind)
-    InnerString = std::string(Kind) + " " + ID + InnerString;
-  else
+  if (Kind) {
+    // Compute the full nested-name-specifier for this type. In C,
+    // this will always be empty.
+    std::string ContextStr;
+    for (DeclContext *DC = getDecl()->getDeclContext(); 
+         !DC->isTranslationUnit(); DC = DC->getParent()) {
+      std::string MyPart;
+      if (NamespaceDecl *NS = dyn_cast<NamespaceDecl>(DC)) {
+        if (NS->getIdentifier())
+          MyPart = NS->getNameAsString();
+      } else if (ClassTemplateSpecializationDecl *Spec 
+                   = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
+        std::string TemplateArgs 
+          = ClassTemplateSpecializationType::PrintTemplateArgumentList(
+                                                  Spec->getTemplateArgs(),
+                                                  Spec->getNumTemplateArgs());
+        MyPart = Spec->getIdentifier()->getName() + TemplateArgs;
+      } else if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
+        if (TypedefDecl *Typedef = Tag->getTypedefForAnonDecl())
+          MyPart = Typedef->getIdentifier()->getName();
+        else if (Tag->getIdentifier())
+          MyPart = Tag->getIdentifier()->getName();
+      }
+
+      if (!MyPart.empty())
+        ContextStr = MyPart + "::" + ContextStr;
+    }
+
+    InnerString = std::string(Kind) + " " + ContextStr + ID + InnerString;
+  } else
     InnerString = ID + InnerString;
 }

Modified: cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp?rev=67284&r1=67283&r2=67284&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp (original)
+++ cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp Wed Mar 18 23:25:59 2009
@@ -27,7 +27,7 @@
 
 void test_X_elab(NS::X x) {
   struct S4 *s4 = 0;
-  x.test_elab2(s4); // expected-error{{incompatible type passing 'struct S4 *', expected 'struct S4 *'}}
+  x.test_elab2(s4); // expected-error{{incompatible type passing 'struct S4 *', expected 'struct NS::S4 *'}}
 }
 
 namespace NS {

Modified: cfe/trunk/test/SemaCXX/enum.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum.cpp?rev=67284&r1=67283&r2=67284&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/enum.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum.cpp Wed Mar 18 23:25:59 2009
@@ -32,9 +32,7 @@
 enum e1 { YES, NO };
 
 static enum e1 badfunc(struct s1 *q) {
-  // FIXME: the message below should probably give context information
-  // in those types.
-  return q->bar(); // expected-error{{incompatible type returning 'enum e1', expected 'enum e1'}}
+  return q->bar(); // expected-error{{incompatible type returning 'enum s1::e1', expected 'enum e1'}}
 }
 
 enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}

Modified: cfe/trunk/test/SemaCXX/qualified-names-diag.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/qualified-names-diag.cpp?rev=67284&r1=67283&r2=67284&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/qualified-names-diag.cpp (original)
+++ cfe/trunk/test/SemaCXX/qualified-names-diag.cpp Wed Mar 18 23:25:59 2009
@@ -16,17 +16,17 @@
 namespace bar {
   typedef int y;
 
-  struct incomplete; // expected-note{{forward declaration of 'struct incomplete'}}
+  struct incomplete; // expected-note{{forward declaration of 'struct bar::incomplete'}}
 }
 void test() {
   foo::wibble::x a;
   ::bar::y b;
-  a + b; // expected-error{{invalid operands to binary expression ('foo::wibble::x' (aka 'struct x') and '::bar::y' (aka 'int'))}}
+  a + b; // expected-error{{invalid operands to binary expression ('foo::wibble::x' (aka 'struct foo::wibble::x') and '::bar::y' (aka 'int'))}}
 
   ::foo::wibble::bar::wonka::x::y c;
-  c + b; // expected-error{{invalid operands to binary expression ('::foo::wibble::bar::wonka::x::y' (aka 'struct y') and '::bar::y' (aka 'int'))}}
+  c + b; // expected-error{{invalid operands to binary expression ('::foo::wibble::bar::wonka::x::y' (aka 'struct foo::wibble::bar::wonka::x::y') and '::bar::y' (aka 'int'))}}
 
-  (void)sizeof(bar::incomplete); // expected-error{{invalid application of 'sizeof' to an incomplete type 'bar::incomplete' (aka 'struct incomplete')}}
+  (void)sizeof(bar::incomplete); // expected-error{{invalid application of 'sizeof' to an incomplete type 'bar::incomplete' (aka 'struct bar::incomplete')}}
 }
 
 int ::foo::wibble::bar::wonka::x::y::* ptrmem;

Modified: cfe/trunk/test/SemaTemplate/class-template-id-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/class-template-id-2.cpp?rev=67284&r1=67283&r2=67284&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/class-template-id-2.cpp (original)
+++ cfe/trunk/test/SemaTemplate/class-template-id-2.cpp Wed Mar 18 23:25:59 2009
@@ -4,7 +4,7 @@
 
   template<> class A<int> { };
 
-  template<> class A<float>; // expected-note{{forward declaration of 'class A<float>'}}
+  template<> class A<float>; // expected-note{{forward declaration of 'class N::A<float>'}}
 
   class B : public A<int> { };
 }

Modified: cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp?rev=67284&r1=67283&r2=67284&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp (original)
+++ cfe/trunk/test/SemaTemplate/qualified-names-diag.cpp Wed Mar 18 23:25:59 2009
@@ -12,5 +12,5 @@
 
   std::vector<INT> v1;
   vector<Real> v2;
-  v1 = v2; // expected-error{{incompatible type assigning 'vector<Real>' (aka 'class vector<float>'), expected 'std::vector<INT>' (aka 'class vector<int>')}}
+  v1 = v2; // expected-error{{incompatible type assigning 'vector<Real>' (aka 'class std::vector<float>'), expected 'std::vector<INT>' (aka 'class std::vector<int>')}}
 }





More information about the cfe-commits mailing list