[cfe-commits] r67795 - in /cfe/trunk: include/clang/AST/DeclCXX.h include/clang/Basic/Diagnostic.h lib/AST/DeclCXX.cpp lib/Sema/SemaDeclCXX.cpp

Anders Carlsson andersca at mac.com
Thu Mar 26 16:46:54 PDT 2009


Author: andersca
Date: Thu Mar 26 18:46:50 2009
New Revision: 67795

URL: http://llvm.org/viewvc/llvm-project?rev=67795&view=rev
Log:
Add

const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                    AccessSpecifier AS);
   
so we can easily add access specifiers to diagnostics.


Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Mar 26 18:46:50 2009
@@ -980,6 +980,11 @@
   }
   static bool classof(StaticAssertDecl *D) { return true; }
 };
+
+/// Insertion operator for diagnostics.  This allows sending AccessSpecifier's
+/// into a diagnostic with <<.
+const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+                                    AccessSpecifier AS);
   
 } // end namespace clang
 

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

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Mar 26 18:46:50 2009
@@ -144,7 +144,8 @@
     ak_identifierinfo,  // IdentifierInfo
     ak_qualtype,        // QualType
     ak_declarationname, // DeclarationName
-    ak_nameddecl        // NamedDecl *
+    ak_nameddecl,       // NamedDecl *
+    ak_accessspecifier  // AccessSpecifier
   };
 
 private:  

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

==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Thu Mar 26 18:46:50 2009
@@ -377,3 +377,24 @@
 StaticAssertDecl::~StaticAssertDecl() {
 }
 
+static const char *getAccessName(AccessSpecifier AS) {
+  switch (AS) {
+    default:
+    case AS_none:
+      assert("Invalid access specifier!");
+      return 0;
+    case AS_public:
+      return "public";
+    case AS_private:
+      return "private";
+    case AS_protected:
+      return "protected";
+  }
+}
+
+const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
+                                           AccessSpecifier AS) {
+  return DB << getAccessName(AS);
+}
+
+

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Mar 26 18:46:50 2009
@@ -2530,21 +2530,6 @@
   Fn->setDeleted();
 }
 
-static const char *getAccessName(AccessSpecifier AS) {
-  switch (AS) {
-    default:
-    case AS_none:
-      assert("Invalid access specifier!");
-      return 0;
-    case AS_public:
-      return "public";
-    case AS_private:
-      return "private";
-    case AS_protected:
-      return "protected";
-  }
-}
-
 bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, 
                                     NamedDecl *PrevMemberDecl,
                                     AccessSpecifier LexicalAS) {
@@ -2559,9 +2544,9 @@
   if (LexicalAS != AS_none && LexicalAS != PrevMemberDecl->getAccess()) {
     Diag(MemberDecl->getLocation(), 
          diag::err_class_redeclared_with_different_access) 
-      << MemberDecl << getAccessName(LexicalAS);
+      << MemberDecl << LexicalAS;
     Diag(PrevMemberDecl->getLocation(), diag::note_previous_access_declaration)
-      << PrevMemberDecl << getAccessName(PrevMemberDecl->getAccess());
+      << PrevMemberDecl << PrevMemberDecl->getAccess();
     return true;
   }
   





More information about the cfe-commits mailing list