[cfe-commits] r89044 - in /cfe/trunk: test/Index/c-index-api-test.m tools/CIndex/CIndex.cpp tools/c-index-test/c-index-test.c
Ted Kremenek
kremenek at apple.com
Mon Nov 16 21:31:58 PST 2009
Author: kremenek
Date: Mon Nov 16 23:31:58 2009
New Revision: 89044
URL: http://llvm.org/viewvc/llvm-project?rev=89044&view=rev
Log:
Have clang_getCursorSource() return NULL when the source location is invalid or refers to a built-in buffer. Implements <rdar://problem/7296243>.
Modified:
cfe/trunk/test/Index/c-index-api-test.m
cfe/trunk/tools/CIndex/CIndex.cpp
cfe/trunk/tools/c-index-test/c-index-test.c
Modified: cfe/trunk/test/Index/c-index-api-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-api-test.m?rev=89044&r1=89043&r2=89044&view=diff
==============================================================================
--- cfe/trunk/test/Index/c-index-api-test.m (original)
+++ cfe/trunk/test/Index/c-index-api-test.m Mon Nov 16 23:31:58 2009
@@ -8,13 +8,13 @@
// CHECK: <invalid loc>:0:0: ObjCInterfaceDecl=Protocol:0:0 [Context=c-index-api-test.m]
// CHECK: <invalid loc>:0:0: TypedefDecl=id:0:0 [Context=c-index-api-test.m]
// CHECK: <invalid loc>:0:0: TypedefDecl=Class:0:0 [Context=c-index-api-test.m]
-// CHECK: <built-in>:80:16: StructDecl=__va_list_tag:80:16 [Context=c-index-api-test.m]
-// CHECK: <built-in>:80:42: FieldDecl=gp_offset:80:42 [Context=__va_list_tag]
-// CHECK: <built-in>:80:63: FieldDecl=fp_offset:80:63 [Context=__va_list_tag]
-// CHECK: <built-in>:80:81: FieldDecl=overflow_arg_area:80:81 [Context=__va_list_tag]
-// CHECK: <built-in>:80:107: FieldDecl=reg_save_area:80:107 [Context=__va_list_tag]
-// CHECK: <built-in>:80:123: TypedefDecl=__va_list_tag:80:123 [Context=c-index-api-test.m]
-// CHECK: <built-in>:80:159: TypedefDecl=__builtin_va_list:80:159 [Context=c-index-api-test.m]
+// CHECK: <invalid loc>:80:16: StructDecl=__va_list_tag:80:16 [Context=c-index-api-test.m]
+// CHECK: <invalid loc>:80:42: FieldDecl=gp_offset:80:42 [Context=__va_list_tag]
+// CHECK: <invalid loc>:80:63: FieldDecl=fp_offset:80:63 [Context=__va_list_tag]
+// CHECK: <invalid loc>:80:81: FieldDecl=overflow_arg_area:80:81 [Context=__va_list_tag]
+// CHECK: <invalid loc>:80:107: FieldDecl=reg_save_area:80:107 [Context=__va_list_tag]
+// CHECK: <invalid loc>:80:123: TypedefDecl=__va_list_tag:80:123 [Context=c-index-api-test.m]
+// CHECK: <invalid loc>:80:159: TypedefDecl=__builtin_va_list:80:159 [Context=c-index-api-test.m]
//
@interface Foo
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=89044&r1=89043&r2=89044&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Mon Nov 16 23:31:58 2009
@@ -980,8 +980,11 @@
SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND);
- if (SLoc.isFileID())
- return SourceMgr.getBufferName(SLoc);
+
+ if (SLoc.isFileID()) {
+ const char *bufferName = SourceMgr.getBufferName(SLoc);
+ return bufferName[0] == '<' ? NULL : bufferName;
+ }
// Retrieve the file in which the macro was instantiated, then provide that
// buffer name.
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=89044&r1=89043&r2=89044&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Nov 16 23:31:58 2009
@@ -40,11 +40,18 @@
}
}
+static const char* GetCursorSource(CXCursor Cursor) {
+ const char *source = clang_getCursorSource(Cursor);
+ if (!source)
+ return "<invalid loc>";
+ return basename(source);
+}
+
static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter)
{
if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
CXString string;
- printf("// CHECK: %s:%d:%d: ", basename(clang_getCursorSource(Cursor)),
+ printf("// CHECK: %s:%d:%d: ", GetCursorSource(Cursor),
clang_getCursorLine(Cursor),
clang_getCursorColumn(Cursor));
PrintCursor(Cursor);
@@ -58,7 +65,7 @@
{
if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
CXString string;
- printf("// CHECK: %s:%d:%d: ", basename(clang_getCursorSource(Cursor)),
+ printf("// CHECK: %s:%d:%d: ", GetCursorSource(Cursor),
clang_getCursorLine(Cursor),
clang_getCursorColumn(Cursor));
PrintCursor(Cursor);
@@ -94,8 +101,8 @@
/* Nothing found here; that's fine. */
} else if (Ref.kind != CXCursor_FunctionDecl) {
CXString string;
- printf("// CHECK: %s:%d:%d: ", basename(clang_getCursorSource(Ref)),
- curLine, curColumn);
+ printf("// CHECK: %s:%d:%d: ", GetCursorSource(Ref),
+ curLine, curColumn);
PrintCursor(Ref);
string = clang_getDeclSpelling(Ref.decl);
printf(" [Context:%s]\n", clang_getCString(string));
More information about the cfe-commits
mailing list