From: Chris Lattner Date: Sun, 23 Nov 2008 09:21:17 +0000 (+0000) Subject: Genericize the qualtype formating callback to support any diag argument. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3fdf4b071dc79fae778fb5f376485480756c76a3;p=clang Genericize the qualtype formating callback to support any diag argument. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59908 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/BugReporter.h b/include/clang/Analysis/PathSensitive/BugReporter.h index cc3011f8e0..945cca3ed0 100644 --- a/include/clang/Analysis/PathSensitive/BugReporter.h +++ b/include/clang/Analysis/PathSensitive/BugReporter.h @@ -337,8 +337,8 @@ public: break; case Diagnostic::ak_qualtype: { llvm::SmallString<64> Str; - Info.getDiags()->ConvertQualTypeToString(Info.getRawArg(i), 0, 0, 0, 0, - Str); + Info.getDiags()->ConvertArgToString(Info.getArgKind(i), + Info.getRawArg(i), 0, 0, 0, 0, Str); R.addString(std::string(Str.begin(), Str.end())); break; } diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 981a559d16..144095f129 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -62,6 +62,15 @@ public: Ignored, Note, Warning, Error }; + enum ArgumentKind { + ak_std_string, // std::string + ak_c_string, // const char * + ak_sint, // int + ak_uint, // unsigned + ak_identifierinfo, // IdentifierInfo + ak_qualtype // QualType + }; + private: bool IgnoreAllWarnings; // Ignore all warnings: -w bool WarningsAsErrors; // Treat warnings like errors: @@ -84,12 +93,15 @@ private: /// CustomDiagInfo - Information for uniquing and looking up custom diags. diag::CustomDiagInfo *CustomDiagInfo; - /// QualTypeToString - A function pointer that converts QualType's to strings. + /// ArgToStringFn - A function pointer that converts an opaque diagnostic + /// argument to a strings. This takes the modifiers and argument that was + /// present in the diagnostic. /// This is a hack to avoid a layering violation between libbasic and libsema. - typedef void (*QTToStringFnTy)(intptr_t QT, const char *Modifier, unsigned ML, - const char *Argument, unsigned ArgLen, - llvm::SmallVectorImpl &Output); - QTToStringFnTy QualTypeToString; + typedef void (*ArgToStringFnTy)(ArgumentKind Kind, intptr_t Val, + const char *Modifier, unsigned ModifierLen, + const char *Argument, unsigned ArgumentLen, + llvm::SmallVectorImpl &Output); + ArgToStringFnTy ArgToStringFn; public: explicit Diagnostic(DiagnosticClient *client = 0); ~Diagnostic(); @@ -157,16 +169,17 @@ public: unsigned getCustomDiagID(Level L, const char *Message); - /// ConvertQualTypeToString - This method converts a QualType (as an intptr_t) - /// into the string that represents it if possible. - void ConvertQualTypeToString(intptr_t QT, const char *Modifier, unsigned ML, - const char *Argument, unsigned ArgLen, - llvm::SmallVectorImpl &Output) const { - QualTypeToString(QT, Modifier, ML, Argument, ArgLen, Output); + /// ConvertArgToString - This method converts a diagnostic argument (as an + /// intptr_t) into the string that represents it. + void ConvertArgToString(ArgumentKind Kind, intptr_t Val, + const char *Modifier, unsigned ModLen, + const char *Argument, unsigned ArgLen, + llvm::SmallVectorImpl &Output) const { + ArgToStringFn(Kind, Val, Modifier, ModLen, Argument, ArgLen, Output); } - void SetQualTypeToStringFn(QTToStringFnTy Fn) { - QualTypeToString = Fn; + void SetArgToStringFn(ArgToStringFnTy Fn) { + ArgToStringFn = Fn; } //===--------------------------------------------------------------------===// @@ -246,15 +259,6 @@ private: /// ProcessDiag - This is the method used to report a diagnostic that is /// finally fully formed. void ProcessDiag(); -public: - enum ArgumentKind { - ak_std_string, // std::string - ak_c_string, // const char * - ak_sint, // int - ak_uint, // unsigned - ak_identifierinfo, // IdentifierInfo - ak_qualtype // QualType - }; }; //===----------------------------------------------------------------------===// diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 8a897f5766..fd65f75e08 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -116,10 +116,11 @@ namespace clang { // Common Diagnostic implementation //===----------------------------------------------------------------------===// -static void DummyQTToStringFnTy(intptr_t QT, const char *Modifier, unsigned ML, - const char *Argument, unsigned ArgLen, - llvm::SmallVectorImpl &Output) { - const char *Str = ""; +static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT, + const char *Modifier, unsigned ML, + const char *Argument, unsigned ArgLen, + llvm::SmallVectorImpl &Output) { + const char *Str = ""; Output.append(Str, Str+strlen(Str)); } @@ -139,7 +140,7 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) { CustomDiagInfo = 0; CurDiagID = ~0U; - QualTypeToString = DummyQTToStringFnTy; + ArgToStringFn = DummyArgToStringFn; } Diagnostic::~Diagnostic() { @@ -536,9 +537,9 @@ FormatDiagnostic(llvm::SmallVectorImpl &OutStr) const { } case Diagnostic::ak_qualtype: OutStr.push_back('\''); - getDiags()->ConvertQualTypeToString(getRawArg(ArgNo), - Modifier, ModifierLen, - Argument, ArgumentLen, OutStr); + getDiags()->ConvertArgToString(getArgKind(ArgNo), getRawArg(ArgNo), + Modifier, ModifierLen, + Argument, ArgumentLen, OutStr); OutStr.push_back('\''); break; } diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index d43eadd574..b01b5d77f3 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -22,12 +22,13 @@ using namespace clang; /// ConvertQualTypeToStringFn - This function is used to pretty print the /// specified QualType as a string in diagnostics. -static void ConvertQualTypeToStringFn(intptr_t QT, +static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t QT, const char *Modifier, unsigned ML, const char *Argument, unsigned ArgLen, llvm::SmallVectorImpl &Output) { assert(ML == 0 && ArgLen == 0 && "Invalid modifier for QualType argument"); - + assert(Kind == Diagnostic::ak_qualtype); + QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast(QT))); // FIXME: Playing with std::string is really slow. @@ -126,7 +127,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer) FieldCollector.reset(new CXXFieldCollector()); // Tell diagnostics how to render things from the AST library. - PP.getDiagnostics().SetQualTypeToStringFn(ConvertQualTypeToStringFn); + PP.getDiagnostics().SetArgToStringFn(ConvertArgToStringFn); } /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.