diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CIndex/CIndex.cpp | 37 | ||||
-rw-r--r-- | tools/CIndex/CIndex.exports | 1 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 11 |
3 files changed, 36 insertions, 13 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index de9c0a370f..1efb50fab5 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -265,10 +265,6 @@ CXEntity clang_getEntity(const char *URI) // // CXDecl Operations. // -CXCursor clang_getCursorFromDecl(CXDecl) -{ - return CXCursor(); -} CXEntity clang_getEntityFromDecl(CXDecl) { return 0; @@ -347,6 +343,9 @@ const char *clang_getCursorKindSpelling(enum CXCursorKind Kind) case CXCursor_ObjCSuperClassRef: return "ObjCSuperClassRef"; case CXCursor_ObjCProtocolRef: return "ObjCProtocolRef"; case CXCursor_ObjCClassRef: return "ObjCClassRef"; + case CXCursor_InvalidFile: return "InvalidFile"; + case CXCursor_NoDeclFound: return "NoDeclFound"; + case CXCursor_NotImplemented: return "NotImplemented"; default: return "<not implemented>"; } } @@ -370,7 +369,7 @@ static enum CXCursorKind TranslateKind(Decl *D) { } default: break; } - return CXCursor_Invalid; + return CXCursor_NotImplemented; } // // CXCursor Operations. @@ -383,21 +382,39 @@ CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name, FileManager &FMgr = CXXUnit->getFileManager(); const FileEntry *File = FMgr.getFile(source_name, - source_name+strlen(source_name)); - assert(File && "clang_getCursor(): FileManager returned 0"); - + source_name+strlen(source_name)); + if (!File) { + CXCursor C = { CXCursor_InvalidFile, 0 }; + return C; + } SourceLocation SLoc = CXXUnit->getSourceManager().getLocation(File, line, column); ASTLocation ALoc = ResolveLocationInAST(CXXUnit->getASTContext(), SLoc); Decl *Dcl = ALoc.getDecl(); - assert(Dcl && "clang_getCursor(): ASTLocation has a null decl"); + if (Dcl) { + CXCursor C = { TranslateKind(Dcl), Dcl }; + return C; + } + CXCursor C = { CXCursor_NoDeclFound, 0 }; + return C; +} + +CXCursor clang_getCursorFromDecl(CXDecl AnonDecl) +{ + assert(AnonDecl && "Passed null CXDecl"); + NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl); - CXCursor C = { TranslateKind(Dcl), Dcl }; + CXCursor C = { TranslateKind(ND), ND }; return C; } +unsigned clang_isInvalid(enum CXCursorKind K) +{ + return K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid; +} + unsigned clang_isDeclaration(enum CXCursorKind K) { return K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl; diff --git a/tools/CIndex/CIndex.exports b/tools/CIndex/CIndex.exports index 7c9660b4d0..17aba04493 100644 --- a/tools/CIndex/CIndex.exports +++ b/tools/CIndex/CIndex.exports @@ -17,6 +17,7 @@ _clang_createTranslationUnit _clang_isDeclaration _clang_isReference _clang_isDefinition +_clang_isInvalid _clang_getCursorSpelling _clang_getCursorKindSpelling _clang_getTranslationUnitSpelling diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 101d71223a..e7043c1482 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -5,8 +5,11 @@ #include <string.h> static void PrintCursor(CXCursor Cursor) { - printf("%s => %s ", clang_getCursorKindSpelling(Cursor.kind), - clang_getCursorSpelling(Cursor)); + if (clang_isInvalid(Cursor.kind)) + printf("Invalid Cursor => %s\n", clang_getCursorKindSpelling(Cursor.kind)); + else + printf("%s => %s ", clang_getCursorKindSpelling(Cursor.kind), + clang_getCursorSpelling(Cursor)); } static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter) @@ -47,8 +50,10 @@ int main(int argc, char **argv) { /* methodSignature - returns a cursor of type ObjCInstanceMethodDecl */ C = clang_getCursor(TU, "/System/Library/Frameworks/Foundation.framework/Headers/NSInvocation.h", 22, 1); PrintCursor(C); + C = clang_getCursor(TU, "Large.m", 5, 18); + PrintCursor(C); } else if (argc == 3) { - enum CXCursorKind K = CXCursor_Invalid; + enum CXCursorKind K = CXCursor_NotImplemented; if (!strcmp(argv[2], "all")) { clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0); |