summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-21 07:50:02 +0000
committerChris Lattner <sabre@nondot.org>2008-11-21 07:50:02 +0000
commit2b78690a9ce871f299ddd3c3d66e8c659a7c8d3d (patch)
treeb8b87b5df601d2f3d1fd36d0a62044f0077df1f5 /clang/lib/Sema/SemaDeclCXX.cpp
parent09a203765a045a567baf638eea4a7ad5716cf993 (diff)
downloadbcm5719-llvm-2b78690a9ce871f299ddd3c3d66e8c659a7c8d3d.tar.gz
bcm5719-llvm-2b78690a9ce871f299ddd3c3d66e8c659a7c8d3d.zip
Add the concept of "modifiers" to the clang diagnostic format
strings. This allows us to have considerable flexibility in how these things are displayed and provides extra information that allows us to merge away diagnostics that are very similar. Diagnostic modifiers are a string of characters with the regex [-a-z]+ that occur between the % and digit. They may optionally have an argument that can parameterize them. For now, I've added two example modifiers. One is a very useful tool that allows you to factor commonality across diagnostics that need single words or phrases combined. Basically you can use %select{a|b|c}4 with with an integer argument that selects either a/b/c based on an integer value in the range [0..3). The second modifier is also an integer modifier, aimed to help English diagnostics handle plurality. "%s3" prints to 's' if integer argument #3 is not 1, otherwise it prints to nothing. I'm fully aware that 's' is an English concept and doesn't apply to all situations (mouse vs mice). However, this is very useful and we can add other crazy modifiers once we add support for polish! ;-) I converted a couple C++ diagnostics over to use this as an example, I'd appreciate it if others could merge the other likely candiates. If you have other modifiers that you want, lets talk on cfe-dev. llvm-svn: 59803
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp32
1 files changed, 9 insertions, 23 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 2368bc65104..f4a95f05319 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1874,22 +1874,13 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
// We have the wrong number of parameters.
diag::kind DK;
if (CanBeUnaryOperator && CanBeBinaryOperator) {
- if (NumParams == 1)
- DK = diag::err_operator_overload_must_be_unary_or_binary;
- else
- DK = diag::err_operator_overload_must_be_unary_or_binary;
+ DK = diag::err_operator_overload_must_be_unary_or_binaryx;
} else if (CanBeUnaryOperator) {
- if (NumParams == 1)
- DK = diag::err_operator_overload_must_be_unary;
- else
- DK = diag::err_operator_overload_must_be_unary_plural;
- } else if (CanBeBinaryOperator) {
- if (NumParams == 1)
- DK = diag::err_operator_overload_must_be_binary;
- else
- DK = diag::err_operator_overload_must_be_binary_plural;
+ DK = diag::err_operator_overload_must_be_unaryx;
} else {
- assert(false && "All non-call overloaded operators are unary or binary!");
+ assert(CanBeBinaryOperator &&
+ "All non-call overloaded operators are unary or binary!");
+ DK = diag::err_operator_overload_must_be_binaryx;
}
return Diag(FnDecl->getLocation(), DK) << FnDecl->getName() << NumParams;
@@ -1925,15 +1916,10 @@ bool Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
if (const BuiltinType *BT = LastParam->getType()->getAsBuiltinType())
ParamIsInt = BT->getKind() == BuiltinType::Int;
- if (!ParamIsInt) {
- diag::kind DK;
- if (Op == OO_PlusPlus)
- DK = diag::err_operator_overload_post_inc_must_be_int;
- else
- DK = diag::err_operator_overload_post_dec_must_be_int;
- return Diag(LastParam->getLocation(), DK)
- << LastParam->getType().getAsString();
- }
+ if (!ParamIsInt)
+ return Diag(LastParam->getLocation(),
+ diag::err_operator_overload_post_incdec_must_be_int)
+ << LastParam->getType().getAsString() << (Op == OO_MinusMinus);
}
return false;
OpenPOWER on IntegriCloud