diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-11-23 20:28:15 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-11-23 20:28:15 +0000 |
| commit | f7e69d5a77b21fd98e29df84411506527faa62b3 (patch) | |
| tree | f28788136092895a6e81591f405c074886096112 /clang | |
| parent | d125393d24b006d67774497d9d284d1e0fee118e (diff) | |
| download | bcm5719-llvm-f7e69d5a77b21fd98e29df84411506527faa62b3.tar.gz bcm5719-llvm-f7e69d5a77b21fd98e29df84411506527faa62b3.zip | |
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.
llvm-svn: 59916
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/DeclarationName.h | 24 | ||||
| -rw-r--r-- | clang/include/clang/AST/Type.h | 1 | ||||
| -rw-r--r-- | clang/include/clang/Analysis/PathSensitive/BugReporter.h | 3 | ||||
| -rw-r--r-- | clang/include/clang/Basic/Diagnostic.h | 3 | ||||
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticKinds.def | 4 | ||||
| -rw-r--r-- | clang/lib/Basic/Diagnostic.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Sema/Sema.cpp | 17 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 5 | ||||
| -rw-r--r-- | clang/test/SemaCXX/nested-name-spec.cpp | 4 |
9 files changed, 43 insertions, 19 deletions
diff --git a/clang/include/clang/AST/DeclarationName.h b/clang/include/clang/AST/DeclarationName.h index 4c7a17096ee..f387d699866 100644 --- a/clang/include/clang/AST/DeclarationName.h +++ b/clang/include/clang/AST/DeclarationName.h @@ -22,11 +22,11 @@ namespace llvm { } 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 @@ public: /// 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 @@ public: 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 { diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index ed1e33752df..a8e1bcbd1ec 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -1494,7 +1494,6 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, Diagnostic::ak_qualtype); return DB; } - } // end namespace clang diff --git a/clang/include/clang/Analysis/PathSensitive/BugReporter.h b/clang/include/clang/Analysis/PathSensitive/BugReporter.h index 945cca3ed0e..d62fe61f712 100644 --- a/clang/include/clang/Analysis/PathSensitive/BugReporter.h +++ b/clang/include/clang/Analysis/PathSensitive/BugReporter.h @@ -335,7 +335,8 @@ public: 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); diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h index 144095f1295..430e0c4266a 100644 --- a/clang/include/clang/Basic/Diagnostic.h +++ b/clang/include/clang/Basic/Diagnostic.h @@ -68,7 +68,8 @@ public: ak_sint, // int ak_uint, // unsigned ak_identifierinfo, // IdentifierInfo - ak_qualtype // QualType + ak_qualtype, // QualType + ak_declarationname // DeclarationName }; private: diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def index e33e6562b3a..1f15366fbba 100644 --- a/clang/include/clang/Basic/DiagnosticKinds.def +++ b/clang/include/clang/Basic/DiagnosticKinds.def @@ -1218,9 +1218,9 @@ DIAG(err_typecheck_bool_condition, ERROR, 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") diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index fd65f75e085..efdb3291716 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -536,6 +536,7 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const { break; } case Diagnostic::ak_qualtype: + case Diagnostic::ak_declarationname: OutStr.push_back('\''); getDiags()->ConvertArgToString(getArgKind(ArgNo), getRawArg(ArgNo), Modifier, ModifierLen, diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index b01b5d77f3c..be21c36073c 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -22,17 +22,24 @@ using namespace clang; /// 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))); + std::string S; + if (Kind == Diagnostic::ak_qualtype) { + QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast<void*>(Val))); - // FIXME: Playing with std::string is really slow. - std::string S = Ty.getAsString(); + // 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()); } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ef24d1a34a8..fba9f3328b1 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -856,10 +856,9 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) { 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; } } diff --git a/clang/test/SemaCXX/nested-name-spec.cpp b/clang/test/SemaCXX/nested-name-spec.cpp index 18cb3b418a6..8e7e17af9d9 100644 --- a/clang/test/SemaCXX/nested-name-spec.cpp +++ b/clang/test/SemaCXX/nested-name-spec.cpp @@ -21,11 +21,11 @@ void C2::m() { } 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() { |

