[llvm-branch-commits] [cfe-branch] r119663 - in /cfe/branches/Apple/whitney: test/Index/TestClassDecl.m test/Index/TestClassForwardDecl.m test/Index/c-index-getCursor-test.m tools/libclang/CIndex.cpp
Daniel Dunbar
daniel at zuster.org
Wed Nov 17 18:38:09 PST 2010
Author: ddunbar
Date: Wed Nov 17 20:38:09 2010
New Revision: 119663
URL: http://llvm.org/viewvc/llvm-project?rev=119663&view=rev
Log:
Merge r119514:
--
Author: Douglas Gregor <dgregor at apple.com>
Date: Wed Nov 17 17:14:07 2010 +0000
When comparing the source range of a declaration against the region of
interest (e.g., as used by clang_getCursor()), count the
decl-specifier-seq as part of the source range, as we do for
clang_annotateTokens(). Makes clang_getCursor() work properly for the
result types of functions, for example.
Modified:
cfe/branches/Apple/whitney/test/Index/TestClassDecl.m
cfe/branches/Apple/whitney/test/Index/TestClassForwardDecl.m
cfe/branches/Apple/whitney/test/Index/c-index-getCursor-test.m
cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
Modified: cfe/branches/Apple/whitney/test/Index/TestClassDecl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/TestClassDecl.m?rev=119663&r1=119662&r2=119663&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/TestClassDecl.m (original)
+++ cfe/branches/Apple/whitney/test/Index/TestClassDecl.m Wed Nov 17 20:38:09 2010
@@ -20,8 +20,8 @@
// CHECK-scan: [8:8 - 8:11] ObjCClassRef=Foo:10:12
// CHECK-scan: [8:11 - 10:1] Invalid Cursor => NoDeclFound
// CHECK-scan: [10:1 - 11:5] ObjCInterfaceDecl=Foo:10:12
-// CHECK-scan: [11:5 - 13:6] Invalid Cursor => NoDeclFound
-// CHECK-scan: [13:6 - 13:15] FunctionDecl=function:13:6 (Definition)
+// CHECK-scan: [11:5 - 13:1] Invalid Cursor => NoDeclFound
+// CHECK-scan: [13:1 - 13:15] FunctionDecl=function:13:6 (Definition)
// CHECK-scan: [13:15 - 13:18] ObjCClassRef=Foo:10:12
// CHECK-scan: [13:18 - 13:24] ParmDecl=arg:13:21 (Definition)
// CHECK-scan: [13:24 - 14:1] FunctionDecl=function:13:6 (Definition)
Modified: cfe/branches/Apple/whitney/test/Index/TestClassForwardDecl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/TestClassForwardDecl.m?rev=119663&r1=119662&r2=119663&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/TestClassForwardDecl.m (original)
+++ cfe/branches/Apple/whitney/test/Index/TestClassForwardDecl.m Wed Nov 17 20:38:09 2010
@@ -15,8 +15,8 @@
// CHECK-scan: [1:1 - 8:1] Invalid Cursor => NoDeclFound
// CHECK-scan: [8:1 - 8:8] UnexposedDecl=[8:8]
// CHECK-scan: [8:8 - 8:11] ObjCClassRef=Foo:8:8
-// CHECK-scan: [8:11 - 10:6] Invalid Cursor => NoDeclFound
-// CHECK-scan: [10:6 - 10:15] FunctionDecl=function:10:6 (Definition)
+// CHECK-scan: [8:11 - 10:1] Invalid Cursor => NoDeclFound
+// CHECK-scan: [10:1 - 10:15] FunctionDecl=function:10:6 (Definition)
// CHECK-scan: [10:15 - 10:18] ObjCClassRef=Foo:8:8
// CHECK-scan: [10:18 - 10:24] ParmDecl=arg:10:21 (Definition)
// CHECK-scan: [10:24 - 11:1] FunctionDecl=function:10:6 (Definition)
Modified: cfe/branches/Apple/whitney/test/Index/c-index-getCursor-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/c-index-getCursor-test.m?rev=119663&r1=119662&r2=119663&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/c-index-getCursor-test.m (original)
+++ cfe/branches/Apple/whitney/test/Index/c-index-getCursor-test.m Wed Nov 17 20:38:09 2010
@@ -94,8 +94,8 @@
// CHECK: [31:18 - 31:21] ObjCSuperClassRef=Bar:12:12
// CHECK: [31:21 - 31:23] ObjCInterfaceDecl=Baz:31:12
// CHECK: [31:23 - 31:27] ObjCProtocolRef=SubP:27:1
-// CHECK: [31:27 - 33:9] ObjCInterfaceDecl=Baz:31:12
-// CHECK: [33:9 - 33:16] ObjCIvarDecl=_anIVar:33:9 (Definition)
+// CHECK: [31:27 - 33:5] ObjCInterfaceDecl=Baz:31:12
+// CHECK: [33:5 - 33:16] ObjCIvarDecl=_anIVar:33:9 (Definition)
// CHECK: [33:16 - 36:1] ObjCInterfaceDecl=Baz:31:12
// CHECK: [36:1 - 36:4] ObjCInstanceMethodDecl=bazMethod:36:1
// CHECK: [36:4 - 36:7] ObjCClassRef=Foo:3:12
@@ -105,8 +105,8 @@
// CHECK: [40:1 - 41:3] EnumDecl=:40:1 (Definition)
// CHECK: [41:3 - 41:11] EnumConstantDecl=someEnum:41:3 (Definition)
// CHECK: [41:11 - 42:2] EnumDecl=:40:1 (Definition)
-// CHECK: [42:2 - 44:5] Invalid Cursor => NoDeclFound
-// CHECK: [44:5 - 44:11] FunctionDecl=main:44:5 (Definition)
+// CHECK: [42:2 - 44:1] Invalid Cursor => NoDeclFound
+// CHECK: [44:1 - 44:11] FunctionDecl=main:44:5 (Definition)
// CHECK: [44:11 - 44:19] ParmDecl=argc:44:15 (Definition)
// CHECK: [44:19 - 44:27] FunctionDecl=main:44:5 (Definition)
// CHECK: [44:27 - 44:38] ParmDecl=argv:44:34 (Definition)
@@ -163,6 +163,6 @@
// CHECK: [52:36 - 52:37] CallExpr=main:44:5
// CHECK: [52:37 - 53:2] UnexposedStmt=
// CHECK: [55:9 - 55:26] macro definition=CONCAT
-// CHECK: [57:6 - 57:10] FunctionDecl=f:57:6 (Definition)
+// CHECK: [57:1 - 57:10] FunctionDecl=f:57:6 (Definition)
// CHECK: [58:4 - 58:8] VarDecl=my_var:58:8 (Definition)
// CHECK: [58:8 - 58:14] macro instantiation=CONCAT:55:9
Modified: cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp?rev=119663&r1=119662&r2=119663&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp Wed Nov 17 20:38:09 2010
@@ -354,6 +354,8 @@
} // end anonymous namespace
static SourceRange getRawCursorExtent(CXCursor C);
+static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr);
+
RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) {
return RangeCompare(AU->getSourceManager(), R, RegionOfInterest);
@@ -534,10 +536,10 @@
llvm::Optional<bool> CursorVisitor::shouldVisitCursor(CXCursor Cursor) {
if (RegionOfInterest.isValid()) {
- SourceRange Range = getRawCursorExtent(Cursor);
+ SourceRange Range = getFullCursorExtent(Cursor, AU->getSourceManager());
if (Range.isInvalid())
return llvm::Optional<bool>();
-
+
switch (CompareRegionOfInterest(Range)) {
case RangeBefore:
// This declaration comes before the region of interest; skip it.
@@ -1839,7 +1841,7 @@
EnqueueChildren(IE);
}
void EnqueueVisitor::VisitMemberExpr(MemberExpr *M) {
- WL.push_back(MemberExprParts(M, Parent));
+ WL.push_back(MemberExprParts(M, Parent));
AddStmt(M->getBase());
}
void EnqueueVisitor::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
@@ -3097,7 +3099,8 @@
unsigned SearchLine, SearchColumn;
CXFile ResultFile;
unsigned ResultLine, ResultColumn;
- CXString SearchFileName, ResultFileName, KindSpelling;
+ CXString SearchFileName, ResultFileName, KindSpelling, USR;
+ const char *IsDef = clang_isCursorDefinition(Result)? " (Definition)" : "";
CXSourceLocation ResultLoc = clang_getCursorLocation(Result);
clang_getInstantiationLocation(Loc, &SearchFile, &SearchLine, &SearchColumn,
@@ -3107,13 +3110,16 @@
SearchFileName = clang_getFileName(SearchFile);
ResultFileName = clang_getFileName(ResultFile);
KindSpelling = clang_getCursorKindSpelling(Result.kind);
- fprintf(stderr, "clang_getCursor(%s:%d:%d) = %s(%s:%d:%d)\n",
+ USR = clang_getCursorUSR(Result);
+ fprintf(stderr, "clang_getCursor(%s:%d:%d) = %s(%s:%d:%d):%s%s\n",
clang_getCString(SearchFileName), SearchLine, SearchColumn,
clang_getCString(KindSpelling),
- clang_getCString(ResultFileName), ResultLine, ResultColumn);
+ clang_getCString(ResultFileName), ResultLine, ResultColumn,
+ clang_getCString(USR), IsDef);
clang_disposeString(SearchFileName);
clang_disposeString(ResultFileName);
clang_disposeString(KindSpelling);
+ clang_disposeString(USR);
}
return Result;
@@ -3363,7 +3369,41 @@
}
return R;
}
- return SourceRange();}
+ return SourceRange();
+}
+
+/// \brief Retrieves the "raw" cursor extent, which is then extended to include
+/// the decl-specifier-seq for declarations.
+static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr) {
+ if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) {
+ Decl *D = cxcursor::getCursorDecl(C);
+ SourceRange R = D->getSourceRange();
+
+ if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
+ if (TypeSourceInfo *TI = DD->getTypeSourceInfo()) {
+ TypeLoc TL = TI->getTypeLoc();
+ SourceLocation TLoc = TL.getSourceRange().getBegin();
+ if (TLoc.isValid() && R.getBegin().isValid() &&
+ SrcMgr.isBeforeInTranslationUnit(TLoc, R.getBegin()))
+ R.setBegin(TLoc);
+ }
+
+ // FIXME: Multiple variables declared in a single declaration
+ // currently lack the information needed to correctly determine their
+ // ranges when accounting for the type-specifier. We use context
+ // stored in the CXCursor to determine if the VarDecl is in a DeclGroup,
+ // and if so, whether it is the first decl.
+ if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
+ if (!cxcursor::isFirstInDeclGroup(C))
+ R.setBegin(VD->getLocation());
+ }
+ }
+
+ return R;
+ }
+
+ return getRawCursorExtent(C);
+}
extern "C" {
More information about the llvm-branch-commits
mailing list