[cfe-commits] r157216 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseObjc.cpp test/FixIt/fixit-objc-message-comma-separator.m

Fariborz Jahanian fjahanian at apple.com
Mon May 21 15:43:44 PDT 2012


Author: fjahanian
Date: Mon May 21 17:43:44 2012
New Revision: 157216

URL: http://llvm.org/viewvc/llvm-project?rev=157216&view=rev
Log:
objective-c: provide a useful 'fixit' suggestion when
errornously using commas to separate ObjC message arguments.
// rdar://11376372

Added:
    cfe/trunk/test/FixIt/fixit-objc-message-comma-separator.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/lib/Parse/ParseObjc.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=157216&r1=157215&r2=157216&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Mon May 21 17:43:44 2012
@@ -378,6 +378,8 @@
 def warn_semicolon_before_method_body : Warning<
   "semicolon before method body is ignored">,
   InGroup<DiagGroup<"semicolon-before-method-body">>, DefaultIgnore;
+def note_extra_comma_message_arg : Note<
+  "comma separating objective-c messaging arguments">;
 
 def err_expected_field_designator : Error<
   "expected a field designator, such as '.field = 4'">;

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=157216&r1=157215&r2=157216&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon May 21 17:43:44 2012
@@ -2452,10 +2452,14 @@
     }
     // Parse the, optional, argument list, comma separated.
     while (Tok.is(tok::comma)) {
-      ConsumeToken(); // Eat the ','.
+      SourceLocation commaLoc = ConsumeToken(); // Eat the ','.
       ///  Parse the expression after ','
       ExprResult Res(ParseAssignmentExpression());
       if (Res.isInvalid()) {
+        if (Tok.is(tok::colon)) {
+          Diag(commaLoc, diag::note_extra_comma_message_arg) <<
+            FixItHint::CreateRemoval(commaLoc);
+        }
         // We must manually skip to a ']', otherwise the expression skipper will
         // stop at the ']' when it skips to the ';'.  We want it to skip beyond
         // the enclosing expression.

Added: cfe/trunk/test/FixIt/fixit-objc-message-comma-separator.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-objc-message-comma-separator.m?rev=157216&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/fixit-objc-message-comma-separator.m (added)
+++ cfe/trunk/test/FixIt/fixit-objc-message-comma-separator.m Mon May 21 17:43:44 2012
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10  -fdiagnostics-parseable-fixits -x objective-c %s 2>&1 | FileCheck %s
+// rdar://11376372
+
+ at class NSObject;
+
+ at interface TestObj {
+}
+-(void)aMethodWithArg1:(NSObject*)arg1 arg2:(NSObject*)arg2;
+ at end
+
+int main(int argc, char *argv[])
+{
+    TestObj *obj;
+    [obj aMethodWithArg1:@"Arg 1 Good", arg2:@"Arg 2 Good"]; 
+}
+
+// CHECK: {14:39-14:40}:""





More information about the cfe-commits mailing list