diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2014-05-09 09:02:49 +0100 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2014-05-09 09:27:15 +0100 |
commit | 72b0110b607311d671953d0475044c8a2eb13553 (patch) | |
tree | 90c636e52a74fc7d2f4842dc1cd23b34164ca94a | |
parent | 46e127a803ec7bf3b22044ee1f2128a3bd8156f2 (diff) |
clang-plugin: Fix diagnostics to correctly use format placeholders
-rw-r--r-- | clang-plugin/debug.cpp | 24 | ||||
-rw-r--r-- | clang-plugin/debug.h | 6 | ||||
-rw-r--r-- | clang-plugin/gir-attributes.cpp | 16 | ||||
-rw-r--r-- | clang-plugin/gsignal-checker.cpp | 183 | ||||
-rw-r--r-- | clang-plugin/gvariant-checker.cpp | 176 | ||||
-rw-r--r-- | clang-plugin/nullability-checker.cpp | 75 | ||||
-rw-r--r-- | clang-plugin/plugin.cpp | 14 |
7 files changed, 207 insertions, 287 deletions
diff --git a/clang-plugin/debug.cpp b/clang-plugin/debug.cpp index 7a37058..21b0468 100644 --- a/clang-plugin/debug.cpp +++ b/clang-plugin/debug.cpp @@ -29,7 +29,7 @@ using namespace clang; /* Build and emit a warning or error report about the user’s code. */ DiagnosticBuilder -Debug::emit_report (DiagnosticsEngine::Level level, const std::string& message, +Debug::emit_report (DiagnosticsEngine::Level level, const char *format_string, CompilerInstance& compiler, SourceLocation location) { DiagnosticsEngine& engine = compiler.getDiagnostics (); @@ -43,31 +43,33 @@ Debug::emit_report (DiagnosticsEngine::Level level, const std::string& message, engine.getErrorsAsFatal ()) level = DiagnosticsEngine::Fatal; - const std::string prefixed_message = "[tartan]: " + message; + /* Add a prefix. */ + std::string prefixed_format_string = + "[tartan]: " + std::string (format_string); + + unsigned diag_id = engine.getCustomDiagID (level, + prefixed_format_string); if (!location.isValid ()) { - return engine.Report (engine.getCustomDiagID (level, - prefixed_message)); + return engine.Report (diag_id); } - return engine.Report (location, - engine.getCustomDiagID (level, - prefixed_message)); + return engine.Report (location, diag_id); } /* Convenience wrappers. */ DiagnosticBuilder -Debug::emit_error (const std::string& message, CompilerInstance& compiler, +Debug::emit_error (const char *format_string, CompilerInstance& compiler, SourceLocation location) { - return Debug::emit_report (DiagnosticsEngine::Error, message, + return Debug::emit_report (DiagnosticsEngine::Error, format_string, compiler, location); } DiagnosticBuilder -Debug::emit_warning (const std::string& message, CompilerInstance& compiler, +Debug::emit_warning (const char *format_string, CompilerInstance& compiler, SourceLocation location) { - return Debug::emit_report (DiagnosticsEngine::Warning, message, + return Debug::emit_report (DiagnosticsEngine::Warning, format_string, compiler, location); } diff --git a/clang-plugin/debug.h b/clang-plugin/debug.h index ddd211f..ffa7437 100644 --- a/clang-plugin/debug.h +++ b/clang-plugin/debug.h @@ -47,13 +47,13 @@ namespace Debug { llvm::errs () << "\n" DiagnosticBuilder emit_report (DiagnosticsEngine::Level level, - const std::string& message, + const char *format_string, CompilerInstance& compiler, SourceLocation location); - DiagnosticBuilder emit_error (const std::string& message, + DiagnosticBuilder emit_error (const char *format_string, CompilerInstance& compiler, SourceLocation location); - DiagnosticBuilder emit_warning (const std::string& message, + DiagnosticBuilder emit_warning (const char *format_string, CompilerInstance& compiler, SourceLocation location); } diff --git a/clang-plugin/gir-attributes.cpp b/clang-plugin/gir-attributes.cpp index 96b2be4..a6ac027 100644 --- a/clang-plugin/gir-attributes.cpp +++ b/clang-plugin/gir-attributes.cpp @@ -421,22 +421,22 @@ GirAttributesChecker::_handle_function_decl (FunctionDecl& func) return_transfer != GI_TRANSFER_NOTHING) { Debug::emit_error ( "Missing (transfer none) annotation on the " - "return value of function " + - func.getNameAsString () + "() " - "(already has a const modifier).", + "return value of function %0() (already has a " + "const modifier).", this->_compiler, - func.getLocStart ()); + func.getLocStart ()) + << func.getNameAsString (); } else if (return_transfer == GI_TRANSFER_NOTHING && _type_should_be_const (return_transfer, return_type_tag) && !_function_return_type_is_const (func)) { Debug::emit_error ( "Missing const modifier on the return value of " - "function " + - func.getNameAsString () + "() " - "(already has a (transfer none) annotation).", + "function %0() (already has a (transfer none) " + "annotation).", this->_compiler, - func.getLocStart ()); + func.getLocStart ()) + << func.getNameAsString (); } break; diff --git a/clang-plugin/gsignal-checker.cpp b/clang-plugin/gsignal-checker.cpp index 1855075..b289395 100644 --- a/clang-plugin/gsignal-checker.cpp +++ b/clang-plugin/gsignal-checker.cpp @@ -465,22 +465,17 @@ _check_signal_callback_type (const Expr *expr, if (value_type->isFunctionNoProtoType ()) { /* Warning. */ - gchar *error; /* TODO: Emit expected type of signal callback? */ - std::string c_type (gir_manager.get_c_name_for_type (static_gobject_info)); - error = g_strdup_printf ("Could not check type of " - "handler for signal " - "‘%s::%s’. Callback function " - "declaration does not contain " - "parameter types.", - c_type.c_str (), - g_base_info_get_name (signal_info)); - Debug::emit_warning (error, compiler, expr->getLocStart ()) + Debug::emit_warning ("Could not check type of handler " + "for signal ‘%0::%1’. Callback " + "function declaration does not " + "contain parameter types.", + compiler, expr->getLocStart ()) + << gir_manager.get_c_name_for_type (static_gobject_info) + << g_base_info_get_name (signal_info) << decl_range; - g_free (error); - return false; } else if (!value_type->isFunctionProtoType ()) { /* Error. */ @@ -533,21 +528,18 @@ _check_signal_callback_type (const Expr *expr, if (n_args != callback_type->getNumArgs ()) { /* Error. */ - gchar *error; /* TODO: Emit expected type of signal callback? */ - std::string c_type (gir_manager.get_c_name_for_type (static_gobject_info)); - error = g_strdup_printf ("Incorrect number of arguments in " - "signal handler for signal " - "‘%s::%s’. Expected %u but saw %u.", - c_type.c_str (), - g_base_info_get_name (signal_info), - n_args, callback_type->getNumArgs ()); - Debug::emit_error (error, compiler, expr->getLocStart ()) + Debug::emit_error ("Incorrect number of arguments in signal " + "handler for signal ‘%0::%1’. Expected %2 " + "but saw %3.", + compiler, expr->getLocStart ()) + << gir_manager.get_c_name_for_type (static_gobject_info) + << g_base_info_get_name (signal_info) + << n_args + << callback_type->getNumArgs () << decl_range; - g_free (error); - return false; } @@ -578,25 +570,21 @@ _check_signal_callback_type (const Expr *expr, if (actual_type_info == NULL) { /* Error. */ - gchar *error; /* TODO: Emit expected type of signal callback? */ - error = g_strdup_printf ("Failed to resolve " - "type of argument " - "‘%s’ in signal " - "handler for signal " - "‘%s::%s’. Cannot " - "find type with name " - "‘%s’.", - arg_name, c_type.c_str (), - g_base_info_get_name (signal_info), - actual_type_str.c_str ()); - Debug::emit_warning (error, compiler, + Debug::emit_warning ("Failed to resolve type " + "of argument ‘%0’ in " + "signal handler for " + "signal ‘%1::%2’. Cannot " + "find type with name " + "‘%3’.", compiler, expr->getLocStart ()) + << arg_name + << c_type + << g_base_info_get_name (signal_info) + << actual_type_str << decl_range; - g_free (error); - continue; } @@ -652,26 +640,21 @@ _check_signal_callback_type (const Expr *expr, if (expected_type.isNull ()) { /* Error. */ - gchar *error; /* TODO: Emit expected type of signal callback? */ - std::string c_type (gir_manager.get_c_name_for_type (static_gobject_info)); - error = g_strdup_printf ("Failed to resolve " - "type of argument " - "‘%s’ in signal " - "handler for signal " - "‘%s::%s’. Cannot " - "find type with name " - "‘%s’.", - arg_name, c_type.c_str (), - g_base_info_get_name (signal_info), - g_base_info_get_name (&expected_type_info)); - Debug::emit_warning (error, compiler, + Debug::emit_warning ("Failed to resolve type " + "of argument ‘%0’ in " + "signal handler for " + "signal ‘%1::%2’. Cannot " + "find type with name " + "‘%3’.", compiler, expr->getLocStart ()) + << arg_name + << gir_manager.get_c_name_for_type (static_gobject_info) + << g_base_info_get_name (signal_info) + << g_base_info_get_name (&expected_type_info) << decl_range; - g_free (error); - continue; } @@ -690,24 +673,20 @@ _check_signal_callback_type (const Expr *expr, * so further errors would just be noise. */ if (type_error) { /* Error. */ - gchar *error; /* TODO: Emit expected type of signal callback? */ - std::string c_type (gir_manager.get_c_name_for_type (static_gobject_info)); - error = g_strdup_printf ("Incorrect type for argument " - "‘%s’ in signal handler for " - "signal ‘%s::%s’. Expected " - "‘%s’ but saw ‘%s’.", - arg_name, c_type.c_str (), - g_base_info_get_name (signal_info), - expected_type.getAsString ().c_str (), - actual_type.getAsString ().c_str ()); - Debug::emit_error (error, compiler, + Debug::emit_error ("Incorrect type for argument ‘%0’ " + "in signal handler for signal " + "‘%1::%2’. Expected ‘%3’ but saw " + "‘%4’.", compiler, expr->getLocStart ()) + << arg_name + << gir_manager.get_c_name_for_type (static_gobject_info) + << g_base_info_get_name (signal_info) + << expected_type.getAsString () + << actual_type.getAsString () << decl_range; - g_free (error); - return false; } } @@ -719,44 +698,33 @@ _check_signal_callback_type (const Expr *expr, gir_manager); if (expected_type.isNull ()) { /* Error. */ - gchar *error; /* TODO: Emit expected type of signal callback? */ - std::string c_type (gir_manager.get_c_name_for_type (static_gobject_info)); - error = g_strdup_printf ("Failed to resolve return type in " - "signal handler for signal ‘%s::%s’. " - "Cannot find type with name ‘%s’.", - c_type.c_str (), - g_base_info_get_name (signal_info), - g_base_info_get_name (&expected_type_info)); - Debug::emit_warning (error, compiler, + Debug::emit_warning ("Failed to resolve return type in signal " + "handler for signal ‘%0::%1’. Cannot find " + "type with name ‘%2’.", compiler, expr->getLocStart ()) + << gir_manager.get_c_name_for_type (static_gobject_info) + << g_base_info_get_name (signal_info) + << g_base_info_get_name (&expected_type_info) << decl_range; - g_free (error); - return false; } if (!context.hasSameType (actual_type, expected_type)) { /* Error. */ - gchar *error; /* TODO: Emit expected type of signal callback? */ - std::string c_type (gir_manager.get_c_name_for_type (static_gobject_info)); - error = g_strdup_printf ("Incorrect return type from " - "signal handler for signal ‘%s::%s’. " - "Expected ‘%s’ but saw ‘%s’.", - c_type.c_str (), - g_base_info_get_name (signal_info), - expected_type.getAsString ().c_str (), - actual_type.getAsString ().c_str ()); - Debug::emit_error (error, compiler, - expr->getLocStart ()) + Debug::emit_error ("Incorrect return type from signal handler " + "for signal ‘%0::%1’. Expected ‘%2’ but saw " + "‘%3’.", compiler, expr->getLocStart ()) + << gir_manager.get_c_name_for_type (static_gobject_info) + << g_base_info_get_name (signal_info) + << expected_type.getAsString () + << actual_type.getAsString () << decl_range; - g_free (error); - return false; } @@ -825,21 +793,16 @@ _check_gsignal_callback_type (const CallExpr &call, context, gir_manager); if (dynamic_gobject_info == NULL) { /* Warning. */ - gchar *error; - - error = g_strdup_printf ("Could not find GObject subclass for " - "expression when connecting to signal " - "‘%s’. To improve static analysis, " - "add a typecast to the GObject " - "parameter of %s().", - signal_name.c_str (), - func_info->func_name); - Debug::emit_warning (error, compiler, call.getLocStart ()) + Debug::emit_warning ("Could not find GObject subclass for " + "expression when connecting to signal " + "‘%0’. To improve static analysis, add a " + "typecast to the GObject parameter of " + "%1().", compiler, call.getLocStart ()) + << signal_name + << func_info->func_name << gobject_arg->getSourceRange () << signal_name_arg->getSourceRange (); - g_free (error); - return false; } @@ -857,20 +820,16 @@ _check_gsignal_callback_type (const CallExpr &call, signal_name.c_str ()); if (signal_info == NULL) { /* Warning. */ - gchar *error; - - std::string c_type (gir_manager.get_c_name_for_type (dynamic_gobject_info)); - error = g_strdup_printf ("No signal named ‘%s’ in GObject " - "class ‘%s’. To improve static " - "analysis, add a typecast to the " - "GObject parameter of %s().", - signal_name.c_str (), c_type.c_str (), - func_info->func_name); - Debug::emit_warning (error, compiler, call.getLocStart ()) + Debug::emit_warning ("No signal named ‘%0’ in GObject class " + "‘%1’. To improve static analysis, add a " + "typecast to the GObject parameter of " + "%2().", compiler, call.getLocStart ()) + << signal_name + << gir_manager.get_c_name_for_type (dynamic_gobject_info) + << func_info->func_name << gobject_arg->getSourceRange () << signal_name_arg->getSourceRange (); - g_free (error); g_base_info_unref (dynamic_gobject_info); return false; diff --git a/clang-plugin/gvariant-checker.cpp b/clang-plugin/gvariant-checker.cpp index 03b653e..e32dddf 100644 --- a/clang-plugin/gvariant-checker.cpp +++ b/clang-plugin/gvariant-checker.cpp @@ -286,15 +286,10 @@ _consume_variadic_argument (QualType expected_type, expected_type.getAsString () << "’."); if (*args_begin == *args_end) { - gchar *error; - - error = g_strdup_printf ( - "Expected a GVariant variadic argument of type ‘%s’ " - "but there wasn’t one.", - expected_type_str.c_str ()); - Debug::emit_error (error, compiler, - format_arg_str->getLocStart ()); - g_free (error); + Debug::emit_error ("Expected a GVariant variadic argument of " + "type ‘%0’ but there wasn’t one.", compiler, + format_arg_str->getLocStart ()) + << expected_type_str; return false; } @@ -320,15 +315,10 @@ _consume_variadic_argument (QualType expected_type, if (is_null_constant && !(flags & CHECK_FLAG_ALLOW_MAYBE) && expected_type->isPointerType ()) { - gchar *error; - - error = g_strdup_printf ( - "Expected a GVariant variadic argument of type ‘%s’ " - "but saw NULL instead.", - expected_type_str.c_str ()); - Debug::emit_error (error, compiler, - arg->getLocStart ()); - g_free (error); + Debug::emit_error ("Expected a GVariant variadic argument of " + "type ‘%0’ but saw NULL instead.", compiler, + arg->getLocStart ()) + << expected_type_str; return false; } else if (!is_null_constant && @@ -342,16 +332,12 @@ _consume_variadic_argument (QualType expected_type, * hacky approach instead. */ const PointerType *actual_pointer_type = dyn_cast<PointerType> (actual_type); if (actual_pointer_type == NULL) { - gchar *error; - - error = g_strdup_printf ( - "Expected a GVariant variadic argument of type " - "‘%s’ but saw one of type ‘%s’.", - expected_type_str.c_str (), - actual_type.getAsString ().c_str ()); - Debug::emit_error (error, compiler, - arg->getLocStart ()); - g_free (error); + Debug::emit_error ("Expected a GVariant variadic " + "argument of type ‘%0’ but saw one " + "of type ‘%1’.", compiler, + arg->getLocStart ()) + << expected_type_str + << actual_type; return false; } @@ -366,17 +352,13 @@ _consume_variadic_argument (QualType expected_type, } else if (!(flags & CHECK_FLAG_FORCE_VALIST)) { const PointerType *actual_pointer2_type = dyn_cast<PointerType> (actual_pointee_type); if (actual_pointer2_type == NULL) { - gchar *error; - - error = g_strdup_printf ( - "Expected a GVariant variadic argument " - "of type ‘%s’ but saw one of type " - "‘%s’.", - expected_type_str.c_str (), - actual_type.getAsString ().c_str ()); - Debug::emit_error (error, compiler, - arg->getLocStart ()); - g_free (error); + Debug::emit_error ("Expected a GVariant " + "variadic argument of type " + "‘%0’ but saw one of type " + "‘%1’.", compiler, + arg->getLocStart ()) + << expected_type_str + << actual_type; return false; } @@ -394,16 +376,12 @@ _consume_variadic_argument (QualType expected_type, actual_pointee_type_str == "va_list") && !(flags & CHECK_FLAG_FORCE_GVARIANTITER && actual_pointee_type_str == "GVariantIter")) { - gchar *error; - - error = g_strdup_printf ( - "Expected a GVariant variadic argument of type " - "‘%s’ but saw one of type ‘%s’.", - expected_type_str.c_str (), - actual_type.getAsString ().c_str ()); - Debug::emit_error (error, compiler, - arg->getLocStart ()); - g_free (error); + Debug::emit_error ("Expected a GVariant variadic " + "argument of type ‘%0’ but saw one " + "of type ‘%1’.", compiler, + arg->getLocStart ()) + << expected_type_str + << actual_type; return false; } @@ -415,16 +393,12 @@ _consume_variadic_argument (QualType expected_type, /* Normal non-GVariant, non-GVariantBuilder case. */ if (!_compare_types (actual_type, expected_type, flags, context)) { - gchar *error; - - error = g_strdup_printf ( - "Expected a GVariant variadic argument of type " - "‘%s’ but saw one of type ‘%s’.", - expected_type.getAsString ().c_str (), - actual_type.getAsString ().c_str ()); - Debug::emit_error (error, compiler, - arg->getLocStart ()); - g_free (error); + Debug::emit_error ("Expected a GVariant variadic " + "argument of type ‘%0’ but saw one " + "of type ‘%1’.", compiler, + arg->getLocStart ()) + << expected_type + << actual_type; return false; } @@ -504,13 +478,10 @@ _check_basic_type_string (const gchar **type_str, flags |= CHECK_FLAG_FORCE_GVARIANT; break; default: - gchar *error; - - error = g_strdup_printf ("Expected a GVariant basic type " - "string but saw ‘%c’.", **type_str); - Debug::emit_error (error, compiler, - format_arg_str->getLocStart ()); - g_free (error); + Debug::emit_error ("Expected a GVariant basic type string but " + "saw ‘%0’.", compiler, + format_arg_str->getLocStart ()) + << **type_str; return false; } @@ -620,11 +591,10 @@ _check_type_string (const gchar **type_str, } if (**type_str != ')') { - Debug::emit_error ( - "Invalid GVariant type string: tuple " - "did not end with ‘)’.", - compiler, - format_arg_str->getLocStart ()); + Debug::emit_error ("Invalid GVariant type string: " + "tuple did not end with ‘)’.", + compiler, + format_arg_str->getLocStart ()); return false; } @@ -985,12 +955,12 @@ _check_gvariant_format_param (const CallExpr& call, const StringLiteral *format_arg_str = dyn_cast<StringLiteral> (format_arg); if (format_arg_str == NULL) { Debug::emit_warning ( - "Non-literal GVariant format string in call to " + - func.getNameAsString () + - "(). Cannot check format string correctness. Instead " + "Non-literal GVariant format string in call to %0(). " + "Cannot check format string correctness. Instead " "of a non-literal format string, use GVariantBuilder.", compiler, - format_arg->getLocStart ()); + format_arg->getLocStart ()) + << func.getNameAsString (); return false; } @@ -1034,17 +1004,13 @@ _check_gvariant_format_param (const CallExpr& call, * string. Don’t emit any error messages about unpaired variadic * arguments because that would just confuse things. */ if (*format_str != '\0') { - gchar *error; - - error = g_strdup_printf ("Unexpected GVariant format strings " - "‘%s’ with unpaired arguments. If " - "using multiple format strings, they " - "should be enclosed in brackets to " - "create a tuple (e.g. ‘(%s)’).", - format_str, whole_format_str); - Debug::emit_error (error, compiler, - format_arg_str->getLocStart ()); - g_free (error); + Debug::emit_error ("Unexpected GVariant format strings ‘%0’ " + "with unpaired arguments. If using multiple " + "format strings, they should be enclosed in " + "brackets to create a tuple (e.g. ‘(%1)’).", + compiler, format_arg_str->getLocStart ()) + << format_str + << whole_format_str; g_free (whole_format_str); @@ -1059,33 +1025,33 @@ _check_gvariant_format_param (const CallExpr& call, for (; !func_info->uses_va_list && args_begin != args_end; ++args_begin) { const Expr *arg = *args_begin; - gchar *error; gchar *error_format_str; error_format_str = _gvariant_format_string_for_type (arg->getType ()); if (error_format_str != NULL) { - error = g_strdup_printf ( - "Unexpected GVariant variadic argument of type " - "‘%s’. A ‘%s’ GVariant format string should be " - "added to the format argument to use it.", - arg->getType ().getAsString ().c_str (), - error_format_str); + Debug::emit_error ("Unexpected GVariant variadic " + "argument of type ‘%0’. A ‘%1’ " + "GVariant format string should be " + "added to the format argument to " + "use it.", + compiler, arg->getLocStart ()) + << arg->getType () + << error_format_str; } else { - error = g_strdup_printf ( - "Unexpected GVariant variadic argument of type " - "‘%s’. A GVariant format string should be " - "added to the format argument to use it, but " - "there is no known GVariant representation of " - "the argument’s type. The argument must be " - "serialized to a GVariant-representable type " - "first.", - arg->getType ().getAsString ().c_str ()); + Debug::emit_error ("Unexpected GVariant variadic " + "argument of type ‘%0’. A GVariant " + "format string should be added to " + "the format argument to use it, but " + "there is no known GVariant " + "representation of the argument’s " + "type. The argument must be " + "serialized to a " + "GVariant-representable type first.", + compiler, arg->getLocStart ()) + << arg->getType (); } - Debug::emit_error (error, compiler, arg->getLocStart ()); - g_free (error); - retval = false; } diff --git a/clang-plugin/nullability-checker.cpp b/clang-plugin/nullability-checker.cpp index 3ad564b..475d244 100644 --- a/clang-plugin/nullability-checker.cpp +++ b/clang-plugin/nullability-checker.cpp @@ -218,80 +218,77 @@ NullabilityVisitor::TraverseFunctionDecl (FunctionDecl* func) if (has_nonnull == EXPLICIT_NONNULL && has_allow_none) { Debug::emit_error ( "Conflict between nonnull attribute and " - "(allow-none) annotation on the ‘" + - parm_decl->getNameAsString () + - "’ parameter of function " + - func->getNameAsString () + "().", + "(allow-none) annotation on the ‘%0’ parameter " + "of function %1().", this->_compiler, - parm_decl->getLocStart ()); + parm_decl->getLocStart ()) + << parm_decl->getNameAsString () + << func->getNameAsString (); } else if (has_allow_none && has_assertion) { Debug::emit_error ( "Conflict between (allow-none) annotation and " - "non-NULL precondition assertion on the ‘" + - parm_decl->getNameAsString () + - "’ parameter of function " + - func->getNameAsString () + "().", + "non-NULL precondition assertion on the ‘%0’ " + "parameter of function %1().", this->_compiler, - parm_decl->getLocStart ()); + parm_decl->getLocStart ()) + << parm_decl->getNameAsString () + << func->getNameAsString (); } else if (!has_allow_none && !has_assertion) { switch (has_nonnull) { case EXPLICIT_NULLABLE: Debug::emit_warning ( "Missing (allow-none) annotation on " - "the ‘" + - parm_decl->getNameAsString () + - "’ parameter of function " + - func->getNameAsString () + "() " + "the ‘%0’ parameter of function %1() " "(already has a nonnull attribute or " "no non-NULL precondition assertion).", this->_compiler, - parm_decl->getLocStart ()); + parm_decl->getLocStart ()) + << parm_decl->getNameAsString () + << func->getNameAsString (); break; case MAYBE: Debug::emit_warning ( "Missing (allow-none) annotation or " "non-NULL precondition assertion on " - "the ‘" + - parm_decl->getNameAsString () + - "’ parameter of function " + - func->getNameAsString () + "().", + "the ‘%0’ parameter of function %1().", this->_compiler, - parm_decl->getLocStart ()); + parm_decl->getLocStart ()) + << parm_decl->getNameAsString () + << func->getNameAsString (); break; case EXPLICIT_NONNULL: Debug::emit_warning ( "Missing non-NULL precondition " - "assertion on the ‘" + - parm_decl->getNameAsString () + - "’ parameter of function " + - func->getNameAsString () + "() " - "(already has a nonnull attribute or " - "no (allow-none) annotation).", + "assertion on the ‘%0’ parameter of " + "function %1() (already has a nonnull " + "attribute or no (allow-none) " + "annotation).", this->_compiler, - parm_decl->getLocStart ()); + parm_decl->getLocStart ()) + << parm_decl->getNameAsString () + << func->getNameAsString (); break; } } else if (has_nonnull == EXPLICIT_NULLABLE && has_assertion) { Debug::emit_warning ( "Conflict between nonnull attribute and " - "non-NULL precondition annotation on the ‘" + - parm_decl->getNameAsString () + - "’ parameter of function " + - func->getNameAsString () + "().", + "non-NULL precondition annotation on the ‘%0’ " + "parameter of function %1().", this->_compiler, - parm_decl->getLocStart ()); + parm_decl->getLocStart ()) + << parm_decl->getNameAsString () + << func->getNameAsString (); } else if (has_nonnull == MAYBE && has_assertion) { /* TODO: Make this a soft warning (disabled by default) * if it comes up with too many false positives. */ Debug::emit_warning ( - "Missing nonnull attribute for the ‘" + - parm_decl->getNameAsString () + - "’ parameter of function " + - func->getNameAsString () + "() " - "(already has a non-NULL precondition " - "assertion).", + "Missing nonnull attribute for the ‘%0’ " + "parameter of function %1() (already has a " + "non-NULL precondition assertion).", this->_compiler, - parm_decl->getLocStart ()); + parm_decl->getLocStart ()) + << parm_decl->getNameAsString () + << func->getNameAsString (); } } diff --git a/clang-plugin/plugin.cpp b/clang-plugin/plugin.cpp index de5f6bf..22c423b 100644 --- a/clang-plugin/plugin.cpp +++ b/clang-plugin/plugin.cpp @@ -140,18 +140,14 @@ private: if (error != NULL) { /* Warn about the bogus include path and * continue. */ - gchar *error_msg; DiagnosticsEngine &d = CI.getDiagnostics (); - error_msg = g_strdup_printf ( - "Error opening typelib path ‘%s’: %s", - typelib_path, error->message); - unsigned int id = d.getCustomDiagID ( - DiagnosticsEngine::Warning, error_msg); - d.Report (id); - - g_free (error_msg); + DiagnosticsEngine::Warning, + "Error opening typelib path ‘%0’: %1"); + d.Report (id) + << typelib_path + << error->message; continue; } |