Genericize the qualtype formating callback to support any diag argument.
No functionality change. llvm-svn: 59908
This commit is contained in:
parent
6a2ed6f6dc
commit
63ecc509e3
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<char> &Output);
|
||||
QTToStringFnTy QualTypeToString;
|
||||
typedef void (*ArgToStringFnTy)(ArgumentKind Kind, intptr_t Val,
|
||||
const char *Modifier, unsigned ModifierLen,
|
||||
const char *Argument, unsigned ArgumentLen,
|
||||
llvm::SmallVectorImpl<char> &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<char> &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<char> &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
|
||||
};
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -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<char> &Output) {
|
||||
const char *Str = "<can't format QualType>";
|
||||
static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT,
|
||||
const char *Modifier, unsigned ML,
|
||||
const char *Argument, unsigned ArgLen,
|
||||
llvm::SmallVectorImpl<char> &Output) {
|
||||
const char *Str = "<can't format argument>";
|
||||
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<char> &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;
|
||||
}
|
||||
|
|
|
@ -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<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.
|
||||
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue