// 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
// 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)
// 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
} // 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);
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.
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) {
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,
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;
}
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" {