summaryrefslogtreecommitdiffstats
path: root/clang/tools
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-01-20 00:23:15 +0000
committerDouglas Gregor <dgregor@apple.com>2010-01-20 00:23:15 +0000
commitd2fc7277be6aff4056db2b3e1ce9da73037ffc1d (patch)
tree4fdec740da084cf999cb6bede430416080aaa530 /clang/tools
parent91970b4ea2fc6747de5f37b25ce0f5f044b1d224 (diff)
downloadbcm5719-llvm-d2fc7277be6aff4056db2b3e1ce9da73037ffc1d.tar.gz
bcm5719-llvm-d2fc7277be6aff4056db2b3e1ce9da73037ffc1d.zip
Introduce a special cursor kind for the translation unit, to serve as
the root of the conceptual cursor hierarchy (just like we do with declarations). This will be used when we get to unify clang_loadTranslationUnit() and clang_loadDeclaration() into something more generally useful. llvm-svn: 93954
Diffstat (limited to 'clang/tools')
-rw-r--r--clang/tools/CIndex/CIndex.cpp13
-rw-r--r--clang/tools/CIndex/CIndex.exports2
-rw-r--r--clang/tools/CIndex/CXCursor.cpp5
3 files changed, 20 insertions, 0 deletions
diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp
index 032dd126f69..8dfaa4cbe12 100644
--- a/clang/tools/CIndex/CIndex.cpp
+++ b/clang/tools/CIndex/CIndex.cpp
@@ -565,6 +565,11 @@ CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) {
true);
}
+CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
+ CXCursor Result = { CXCursor_TranslationUnit, { TU, 0, 0 } };
+ return Result;
+}
+
void clang_loadTranslationUnit(CXTranslationUnit CTUnit,
CXTranslationUnitIterator callback,
CXClientData CData) {
@@ -803,6 +808,9 @@ static Decl *getDeclFromExpr(Stmt *E) {
extern "C" {
CXString clang_getCursorSpelling(CXCursor C) {
assert(getCursorDecl(C) && "CXCursor has null decl");
+ if (clang_isTranslationUnit(C.kind))
+ return clang_getTranslationUnitSpelling(C.data[0]);
+
if (clang_isReference(C.kind)) {
switch (C.kind) {
case CXCursor_ObjCSuperClassRef: {
@@ -867,6 +875,7 @@ const char *clang_getCursorKindSpelling(enum CXCursorKind Kind) {
case CXCursor_InvalidFile: return "InvalidFile";
case CXCursor_NoDeclFound: return "NoDeclFound";
case CXCursor_NotImplemented: return "NotImplemented";
+ case CXCursor_TranslationUnit: return "TranslationUnit";
}
llvm_unreachable("Unhandled CXCursorKind");
@@ -947,6 +956,10 @@ unsigned clang_isStatement(enum CXCursorKind K) {
return K >= CXCursor_FirstStmt && K <= CXCursor_LastStmt;
}
+unsigned clang_isTranslationUnit(enum CXCursorKind K) {
+ return K == CXCursor_TranslationUnit;
+}
+
CXCursorKind clang_getCursorKind(CXCursor C) {
return C.kind;
}
diff --git a/clang/tools/CIndex/CIndex.exports b/clang/tools/CIndex/CIndex.exports
index b05c2ccad38..7a70e545b60 100644
--- a/clang/tools/CIndex/CIndex.exports
+++ b/clang/tools/CIndex/CIndex.exports
@@ -39,6 +39,7 @@ _clang_getNullCursor
_clang_getNumCompletionChunks
_clang_getRangeEnd
_clang_getRangeStart
+_clang_getTranslationUnitCursor
_clang_getTranslationUnitSpelling
_clang_isCursorDefinition
_clang_isDeclaration
@@ -46,6 +47,7 @@ _clang_isExpression
_clang_isInvalid
_clang_isReference
_clang_isStatement
+_clang_isTranslationUnit
_clang_loadDeclaration
_clang_loadTranslationUnit
_clang_setUseExternalASTGeneration
diff --git a/clang/tools/CIndex/CXCursor.cpp b/clang/tools/CIndex/CXCursor.cpp
index f13e2eea89f..7dd3ae9cc00 100644
--- a/clang/tools/CIndex/CXCursor.cpp
+++ b/clang/tools/CIndex/CXCursor.cpp
@@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//
#include "CXCursor.h"
+#include "clang/Frontend/ASTUnit.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
@@ -320,6 +321,10 @@ ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
case CXCursor_UnexposedStmt:
return static_cast<Decl *>(Cursor.data[0])->getASTContext();
+ case CXCursor_TranslationUnit: {
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(Cursor.data[0]);
+ return CXXUnit->getASTContext();
+ }
}
llvm_unreachable("No context available");
OpenPOWER on IntegriCloud