]> granicus.if.org Git - clang/commitdiff
objective-c. Fixes a 'fixit' where location of
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 9 May 2012 21:49:29 +0000 (21:49 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 9 May 2012 21:49:29 +0000 (21:49 +0000)
'*' on objective-c class name was misplaced.
// rdar://11311333

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156517 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/TypeLoc.h
lib/Parse/ParseObjc.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaType.cpp
test/FixIt/fixit-interface-as-param.m [new file with mode: 0644]

index aab87be7c48f2117f929f8293e2a990f7a8f08c4..1d1c1d172573f2076d46d214c672efbf28ca158f 100644 (file)
@@ -831,6 +831,7 @@ public:
 
 struct ObjCInterfaceLocInfo {
   SourceLocation NameLoc;
+  SourceLocation NameEndLoc;
 };
 
 /// \brief Wrapper for source info for ObjC interfaces.
@@ -850,9 +851,17 @@ public:
   void setNameLoc(SourceLocation Loc) {
     getLocalData()->NameLoc = Loc;
   }
-
+                                                    
   SourceRange getLocalSourceRange() const {
-    return SourceRange(getNameLoc());
+    return SourceRange(getNameLoc(), getNameEndLoc());
+  }
+  
+  SourceLocation getNameEndLoc() const {
+    return getLocalData()->NameEndLoc;
+  }
+
+  void setNameEndLoc(SourceLocation Loc) {
+    getLocalData()->NameEndLoc = Loc;
   }
 
   void initializeLocal(ASTContext &Context, SourceLocation Loc) {
index 1baebd5ba929711297ae6794b4fe9ec4cd93035e..0d9a54e638d7be31d436e929f767af040db5a4b5 100644 (file)
@@ -894,6 +894,7 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS,
     DeclSpec declSpec(AttrFactory);
     declSpec.setObjCQualifiers(&DS);
     ParseSpecifierQualifierList(declSpec);
+    declSpec.SetRangeEnd(Tok.getLocation().getLocWithOffset(-1));
     Declarator declarator(declSpec, context);
     ParseDeclarator(declarator);
 
index fc37a25d8b493497b97b3eb605998e6e86c8695a..dfe73884d46a5e4ed982fae34056dc6572b80039 100644 (file)
@@ -7193,9 +7193,10 @@ ParmVarDecl *Sema::CheckParameter(DeclContext *DC, SourceLocation StartLoc,
   // Parameter declarators cannot be interface types. All ObjC objects are
   // passed by reference.
   if (T->isObjCObjectType()) {
+    SourceLocation TypeEndLoc = TSInfo->getTypeLoc().getLocEnd();
     Diag(NameLoc,
          diag::err_object_cannot_be_passed_returned_by_value) << 1 << T
-      << FixItHint::CreateInsertion(NameLoc, "*");
+      << FixItHint::CreateInsertion(TypeEndLoc, "*");
     T = Context.getObjCObjectPointerType(T);
     New->setType(T);
   }
index 527dce47d70e4072e002e371e6f11dd9d8dcebf9..13a72a533866c35937b288d9cf24f0fe0bcdb768 100644 (file)
@@ -2882,6 +2882,10 @@ namespace {
     }
     void VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
       TL.setNameLoc(DS.getTypeSpecTypeLoc());
+      // FIXME. We should have DS.getTypeSpecTypeEndLoc(). But, it requires
+      // addition field. What we have is good enough for dispay of location
+      // of 'fixit' on interface name.
+      TL.setNameEndLoc(DS.getLocEnd());
     }
     void VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
       // Handle the base type, which might not have been written explicitly.
diff --git a/test/FixIt/fixit-interface-as-param.m b/test/FixIt/fixit-interface-as-param.m
new file mode 100644 (file)
index 0000000..89a7cf8
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10  -fdiagnostics-parseable-fixits -x objective-c %s 2>&1 | FileCheck %s
+// rdar://11311333
+
+@interface NSView @end
+
+@interface INTF
+- (void) drawRect : inView:(NSView)view;
+@end
+
+// CHECK: {7:34-7:34}:"*"
+