diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index 5db0eca42adb..1d82e1a1063b 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -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(getParams()), NumParams), - EndLoc); + DeclEndLoc); return getStoredSelLocs()[Index]; } diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index b6b3f7d4c0af..37fb03914251 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -451,7 +451,8 @@ void ObjCMethodDecl::setMethodParams(ASTContext &C, if (isImplicit()) return setParamsAndSelLocs(C, Params, ArrayRef()); - SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, EndLoc); + SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params, + DeclEndLoc); if (SelLocsKind != SelLoc_NonStandard) return setParamsAndSelLocs(C, Params, ArrayRef()); @@ -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(Family); if (family != static_cast(InvalidObjCMethodFamily)) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 399f518fcc9e..be62818c205f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -7634,8 +7634,6 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, } else if (ObjCMethodDecl *MD = dyn_cast_or_null(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(), diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index d9e060c91df8..f5f9ba25988a 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -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 Params; Params.reserve(NumParams); diff --git a/clang/test/Index/get-cursor.m b/clang/test/Index/get-cursor.m index 32ac53fe3bf9..d3da9ec19726 100644 --- a/clang/test/Index/get-cursor.m +++ b/clang/test/Index/get-cursor.m @@ -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 diff --git a/clang/test/Index/overrides.m b/clang/test/Index/overrides.m index f0f3e5fedbf6..d0447b74739d 100644 --- a/clang/test/Index/overrides.m +++ b/clang/test/Index/overrides.m @@ -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]