From: Fariborz Jahanian Date: Wed, 9 May 2012 21:49:29 +0000 (+0000) Subject: objective-c. Fixes a 'fixit' where location of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1de6a6cb485fb58b4fb100282bb3cf298eedacd9;p=clang objective-c. Fixes a 'fixit' where location of '*' 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 --- diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index aab87be7c4..1d1c1d1725 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -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) { diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 1baebd5ba9..0d9a54e638 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -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); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index fc37a25d8b..dfe73884d4 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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); } diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 527dce47d7..13a72a5338 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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 index 0000000000..89a7cf8fdd --- /dev/null +++ b/test/FixIt/fixit-interface-as-param.m @@ -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}:"*" +