[cfe-commits] r59916 - in /cfe/trunk: include/clang/AST/DeclarationName.h include/clang/AST/Type.h include/clang/Analysis/PathSensitive/BugReporter.h include/clang/Basic/Diagnostic.h include/clang/Basic/DiagnosticKinds.def lib/Basic/Diagnostic.cpp lib/Sema/Sema.cpp lib/Sema/SemaDecl.cpp test/SemaCXX/nested-name-spec.cpp

Chris Lattner sabre at nondot.org
Sun Nov 23 12:28:16 PST 2008


Author: lattner
Date: Sun Nov 23 14:28:15 2008
New Revision: 59916

URL: http://llvm.org/viewvc/llvm-project?rev=59916&view=rev
Log:
add support for inserting a DeclarationName into a diagnostic directly
without calling getAsString().  This implicitly puts quotes around the
name, so diagnostics need to be tweaked to accommodate this.

Modified:
    cfe/trunk/include/clang/AST/DeclarationName.h
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/nested-name-spec.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclarationName.h (original)
+++ cfe/trunk/include/clang/AST/DeclarationName.h Sun Nov 23 14:28:15 2008
@@ -22,11 +22,11 @@
 }
 
 namespace clang {
-  class CXXSpecialName;       // a private class used by DeclarationName
-  class CXXOperatorIdName;    // a private class used by DeclarationName
-  class DeclarationNameExtra; // a private class used by DeclarationName
+  class CXXSpecialName;
+  class CXXOperatorIdName;
+  class DeclarationNameExtra;
   class IdentifierInfo;
-  class MultiKeywordSelector; // a private class used by Selector and DeclarationName
+  class MultiKeywordSelector;
 
 /// DeclarationName - The name of a declaration. In the common case,
 /// this just stores an IdentifierInfo pointer to a normal
@@ -198,6 +198,12 @@
   /// name as an opaque integer.
   uintptr_t getAsOpaqueInteger() const { return Ptr; }
 
+  static DeclarationName getFromOpaqueInteger(uintptr_t P) {
+    DeclarationName N;
+    N.Ptr = P;
+    return N;
+  }
+  
   /// getCXXNameType - If this name is one of the C++ names (of a
   /// constructor, destructor, or conversion function), return the
   /// type associated with that name.
@@ -314,6 +320,16 @@
   DeclarationName getCXXOperatorName(OverloadedOperatorKind Op);
 };  
 
+/// Insertion operator for diagnostics.  This allows sending DeclarationName's
+/// into a diagnostic with <<.
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+                                           DeclarationName N) {
+  DB.AddTaggedVal(N.getAsOpaqueInteger(),
+                  Diagnostic::ak_declarationname);
+  return DB;
+}
+  
+  
 }  // end namespace clang
 
 namespace llvm {

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Nov 23 14:28:15 2008
@@ -1494,7 +1494,6 @@
                   Diagnostic::ak_qualtype);
   return DB;
 }
-  
 
 }  // end namespace clang
 

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h?rev=59916&r1=59915&r2=59916&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Sun Nov 23 14:28:15 2008
@@ -335,7 +335,8 @@
       case Diagnostic::ak_identifierinfo:
         R.addString(Info.getArgIdentifier(i)->getName());
         break;
-      case Diagnostic::ak_qualtype: {
+      case Diagnostic::ak_qualtype:
+      case Diagnostic::ak_declarationname: {
         llvm::SmallString<64> Str;
         Info.getDiags()->ConvertArgToString(Info.getArgKind(i),
                                             Info.getRawArg(i), 0, 0, 0, 0, Str);

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=59916&r1=59915&r2=59916&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Sun Nov 23 14:28:15 2008
@@ -68,7 +68,8 @@
     ak_sint,           // int
     ak_uint,           // unsigned
     ak_identifierinfo, // IdentifierInfo
-    ak_qualtype        // QualType
+    ak_qualtype,       // QualType
+    ak_declarationname // DeclarationName
   };
   
 private:  

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=59916&r1=59915&r2=59916&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sun Nov 23 14:28:15 2008
@@ -1218,9 +1218,9 @@
 DIAG(err_expected_class_or_namespace, ERROR,
      "expected a class or namespace")
 DIAG(err_invalid_declarator_scope, ERROR,
-     "definition or redeclaration for '%0' not in a namespace enclosing '%1'")
+     "definition or redeclaration of '%0' not in a namespace enclosing '%1'")
 DIAG(err_invalid_declarator_in_function, ERROR,
-     "definition or redeclaration for '%0' not allowed inside a function")
+     "definition or redeclaration of %0 not allowed inside a function")
 DIAG(err_not_tag_in_scope, ERROR,
      "'%0' does not name a tag member in the specified scope")
 

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=59916&r1=59915&r2=59916&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Sun Nov 23 14:28:15 2008
@@ -536,6 +536,7 @@
       break;
     }
     case Diagnostic::ak_qualtype:
+    case Diagnostic::ak_declarationname:
       OutStr.push_back('\'');
       getDiags()->ConvertArgToString(getArgKind(ArgNo), getRawArg(ArgNo),
                                      Modifier, ModifierLen,

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=59916&r1=59915&r2=59916&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sun Nov 23 14:28:15 2008
@@ -22,17 +22,24 @@
 
 /// ConvertQualTypeToStringFn - This function is used to pretty print the 
 /// specified QualType as a string in diagnostics.
-static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t QT,
+static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val,
                                       const char *Modifier, unsigned ML,
                                       const char *Argument, unsigned ArgLen,
                                       llvm::SmallVectorImpl<char> &Output) {
   assert(ML == 0 && ArgLen == 0 && "Invalid modifier for QualType argument");
-  assert(Kind == Diagnostic::ak_qualtype);
   
-  QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast<void*>(QT)));
-  
-  // FIXME: Playing with std::string is really slow.
-  std::string S = Ty.getAsString();
+  std::string S;
+  if (Kind == Diagnostic::ak_qualtype) {
+    QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast<void*>(Val)));
+  
+    // FIXME: Playing with std::string is really slow.
+    S = Ty.getAsString();
+  } else {
+    assert(Kind == Diagnostic::ak_declarationname);
+   
+    DeclarationName N = DeclarationName::getFromOpaqueInteger(Val);
+    S = N.getAsString();
+  }
   Output.append(S.begin(), S.end());
 }
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=59916&r1=59915&r2=59916&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Nov 23 14:28:15 2008
@@ -856,10 +856,9 @@
       SourceLocation L = D.getIdentifierLoc();
       SourceRange R = D.getCXXScopeSpec().getRange();
       if (isa<FunctionDecl>(CurContext)) {
-        Diag(L, diag::err_invalid_declarator_in_function)
-          << Name.getAsString() << R;
+        Diag(L, diag::err_invalid_declarator_in_function) << Name << R;
       } else {
-      Diag(L, diag::err_invalid_declarator_scope)
+        Diag(L, diag::err_invalid_declarator_scope)
           << Name.getAsString() << cast<NamedDecl>(DC)->getName() << R;
       }
     }

Modified: cfe/trunk/test/SemaCXX/nested-name-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nested-name-spec.cpp?rev=59916&r1=59915&r2=59916&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/nested-name-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/nested-name-spec.cpp Sun Nov 23 14:28:15 2008
@@ -21,11 +21,11 @@
 }
 
 namespace B {
-  void ::A::Af() {} // expected-error {{definition or redeclaration for 'Af' not in a namespace enclosing 'A'}}
+  void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
 }
 
 void f1() {
-  void A::Af(); // expected-error {{definition or redeclaration for 'Af' not allowed inside a function}}  
+  void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}  
 }
 
 void f2() {





More information about the cfe-commits mailing list