From: Anders Carlsson Date: Thu, 26 Mar 2009 23:46:50 +0000 (+0000) Subject: Add X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05bf2c79770927c66ca725e9bb589048ed3f069e;p=clang Add const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, AccessSpecifier AS); so we can easily add access specifiers to diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67795 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index e1f1095d3d..940d95ca43 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -980,6 +980,11 @@ public: } 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 diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index a9f87107ab..c6c9e394f5 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -144,7 +144,8 @@ public: ak_identifierinfo, // IdentifierInfo ak_qualtype, // QualType ak_declarationname, // DeclarationName - ak_nameddecl // NamedDecl * + ak_nameddecl, // NamedDecl * + ak_accessspecifier // AccessSpecifier }; private: diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 98d7d8f487..7c5dbced31 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -377,3 +377,24 @@ void StaticAssertDecl::Destroy(ASTContext& C) { 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); +} + + diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 11ab071c58..cb44cfc186 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2530,21 +2530,6 @@ void Sema::SetDeclDeleted(DeclTy *dcl, SourceLocation DelLoc) { 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 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, 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; }