forked from OSchip/llvm-project
[AST/libclang] Fix the selector locations that are reported for a
method definition that has its '{' attached to the method name without a space. With a method like: -(id)meth{ ..... } the logic in ObjCMethodDecl that determined the selector locations got confused because it was initialized based on an end location for '{' but that end location changed to '}' after the method was finished. Fix this by having an immutable end location for the declarator and for getLocEnd() get the end location from the body itself. Fixes rdar://11659739. llvm-svn: 158583
This commit is contained in:
parent
52de271da1
commit
33b4bfcef5
|
@ -171,7 +171,7 @@ private:
|
|||
unsigned NumParams;
|
||||
|
||||
/// List of attributes for this method declaration.
|
||||
SourceLocation EndLoc; // the location of the ';' or '}'.
|
||||
SourceLocation DeclEndLoc; // the location of the ';' or '{'.
|
||||
|
||||
// The following are only used for method definitions, null otherwise.
|
||||
// FIXME: space savings opportunity, consider a sub-class.
|
||||
|
@ -242,7 +242,7 @@ private:
|
|||
SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0),
|
||||
MethodDeclType(T), ResultTInfo(ResultTInfo),
|
||||
ParamsAndSelLocs(0), NumParams(0),
|
||||
EndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {
|
||||
DeclEndLoc(endLoc), Body(0), SelfDecl(0), CmdDecl(0) {
|
||||
setImplicit(isImplicitlyDeclared);
|
||||
}
|
||||
|
||||
|
@ -290,12 +290,16 @@ public:
|
|||
bool isRedeclaration() const { return IsRedeclaration; }
|
||||
void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
|
||||
|
||||
/// \brief Returns the location where the declarator ends. It will be
|
||||
/// the location of ';' for a method declaration and the location of '{'
|
||||
/// for a method definition.
|
||||
SourceLocation getDeclaratorEndLoc() const { return DeclEndLoc; }
|
||||
|
||||
// Location information, modeled after the Stmt API.
|
||||
SourceLocation getLocStart() const LLVM_READONLY { return getLocation(); }
|
||||
SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
|
||||
void setEndLoc(SourceLocation Loc) { EndLoc = Loc; }
|
||||
SourceLocation getLocEnd() const LLVM_READONLY;
|
||||
virtual SourceRange getSourceRange() const LLVM_READONLY {
|
||||
return SourceRange(getLocation(), EndLoc);
|
||||
return SourceRange(getLocation(), getLocEnd());
|
||||
}
|
||||
|
||||
SourceLocation getSelectorStartLoc() const {
|
||||
|
@ -310,7 +314,7 @@ public:
|
|||
getSelLocsKind() == SelLoc_StandardWithSpace,
|
||||
llvm::makeArrayRef(const_cast<ParmVarDecl**>(getParams()),
|
||||
NumParams),
|
||||
EndLoc);
|
||||
DeclEndLoc);
|
||||
return getStoredSelLocs()[Index];
|
||||
}
|
||||
|
||||
|
|
|
@ -451,7 +451,8 @@ void ObjCMethodDecl::setMethodParams(ASTContext &C,
|
|||
if (isImplicit())
|
||||
return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>());
|
||||
|
||||
SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, EndLoc);
|
||||
SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params,
|
||||
DeclEndLoc);
|
||||
if (SelLocsKind != SelLoc_NonStandard)
|
||||
return setParamsAndSelLocs(C, Params, ArrayRef<SourceLocation>());
|
||||
|
||||
|
@ -523,6 +524,12 @@ ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
|
|||
return this;
|
||||
}
|
||||
|
||||
SourceLocation ObjCMethodDecl::getLocEnd() const {
|
||||
if (Stmt *Body = getBody())
|
||||
return Body->getLocEnd();
|
||||
return DeclEndLoc;
|
||||
}
|
||||
|
||||
ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const {
|
||||
ObjCMethodFamily family = static_cast<ObjCMethodFamily>(Family);
|
||||
if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
|
||||
|
|
|
@ -7634,8 +7634,6 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
|
|||
} else if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) {
|
||||
assert(MD == getCurMethodDecl() && "Method parsing confused");
|
||||
MD->setBody(Body);
|
||||
if (Body)
|
||||
MD->setEndLoc(Body->getLocEnd());
|
||||
if (!MD->isInvalidDecl()) {
|
||||
DiagnoseUnusedParameters(MD->param_begin(), MD->param_end());
|
||||
DiagnoseSizeOfParametersAndReturnValue(MD->param_begin(), MD->param_end(),
|
||||
|
|
|
@ -655,7 +655,7 @@ void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
|
|||
MD->SetRelatedResultType(Record[Idx++]);
|
||||
MD->setResultType(Reader.readType(F, Record, Idx));
|
||||
MD->setResultTypeSourceInfo(GetTypeSourceInfo(Record, Idx));
|
||||
MD->setEndLoc(ReadSourceLocation(Record, Idx));
|
||||
MD->DeclEndLoc = ReadSourceLocation(Record, Idx);
|
||||
unsigned NumParams = Record[Idx++];
|
||||
SmallVector<ParmVarDecl *, 16> Params;
|
||||
Params.reserve(NumParams);
|
||||
|
|
|
@ -82,6 +82,13 @@ void foo3(Test3 *test3) {
|
|||
@implementation Test5
|
||||
@synthesize prop1, prop2;
|
||||
@dynamic prop3, prop4;
|
||||
|
||||
-(id)meth1 {
|
||||
return 0;
|
||||
}
|
||||
-(id)meth2{
|
||||
return 0;
|
||||
}
|
||||
@end
|
||||
|
||||
// RUN: c-index-test -cursor-at=%s:4:28 -cursor-at=%s:5:28 %s | FileCheck -check-prefix=CHECK-PROP %s
|
||||
|
@ -124,3 +131,7 @@ void foo3(Test3 *test3) {
|
|||
// CHECK-MULTISYNTH: 83:20 ObjCSynthesizeDecl=prop2:77:23 (Definition) Extent=[83:1 - 83:25] Spelling=prop2 ([83:20 - 83:25])
|
||||
// CHECK-MULTISYNTH: 84:10 ObjCDynamicDecl=prop3:78:23 (Definition) Extent=[84:1 - 84:15] Spelling=prop3 ([84:10 - 84:15])
|
||||
// CHECK-MULTISYNTH: 84:17 ObjCDynamicDecl=prop4:79:23 (Definition) Extent=[84:1 - 84:22] Spelling=prop4 ([84:17 - 84:22])
|
||||
|
||||
// RUN: c-index-test -cursor-at=%s:86:7 -cursor-at=%s:89:7 %s | FileCheck -check-prefix=CHECK-SELECTORLOC %s
|
||||
// CHECK-SELECTORLOC: 86:6 ObjCInstanceMethodDecl=meth1:86:6 (Definition) Extent=[86:1 - 88:2] Spelling=meth1 ([86:6 - 86:11]) Selector index=0
|
||||
// CHECK-SELECTORLOC: 89:6 ObjCInstanceMethodDecl=meth2:89:6 (Definition) Extent=[89:1 - 91:2] Spelling=meth2 ([89:6 - 89:11]) Selector index=0
|
||||
|
|
|
@ -116,4 +116,4 @@
|
|||
// CHECK: overrides.m:81:23: ObjCInstanceMethodDecl=setProp::81:23 [Overrides @77:8] Extent=[81:23 - 81:27]
|
||||
// CHECK: overrides.m:92:8: ObjCInstanceMethodDecl=meth:92:8 Extent=[92:1 - 92:13]
|
||||
// CHECK: overrides.m:95:17: ObjCImplementationDecl=I5:95:17 (Definition) Extent=[95:1 - 97:2]
|
||||
// CHECK: overrides.m:96:9: ObjCInstanceMethodDecl=meth:96:9 (Definition) [Overrides @92:8] Extent=[96:1 - 96:14]
|
||||
// CHECK: overrides.m:96:8: ObjCInstanceMethodDecl=meth:96:8 (Definition) [Overrides @92:8] Extent=[96:1 - 96:14]
|
||||
|
|
Loading…
Reference in New Issue