aboutsummaryrefslogtreecommitdiff
path: root/tools/libclang/CIndex.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-10-20 22:00:55 +0000
committerDouglas Gregor <dgregor@apple.com>2010-10-20 22:00:55 +0000
commitecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0ed (patch)
tree9a88c438fa389bc46038d92d1a78c94ca43e831c /tools/libclang/CIndex.cpp
parent93f5e6a5d7690f90bc8a94e6b40d6c7d19719e0c (diff)
Extend the preprocessing record and libclang with support for
inclusion directives, keeping track of every #include, #import, etc. in the translation unit. We keep track of the source location and kind of the inclusion, how the file name was spelled, and the underlying file to which the inclusion resolved. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116952 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/CIndex.cpp')
-rw-r--r--tools/libclang/CIndex.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 722e2cb738..c944883fa4 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -555,6 +555,13 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) {
continue;
}
+
+ if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) {
+ if (Visit(MakeInclusionDirectiveCursor(ID, CXXUnit)))
+ return true;
+
+ continue;
+ }
}
}
return false;
@@ -2565,6 +2572,9 @@ CXString clang_getCursorSpelling(CXCursor C) {
return createCXString(getCursorMacroDefinition(C)->getName()
->getNameStart());
+ if (C.kind == CXCursor_InclusionDirective)
+ return createCXString(getCursorInclusionDirective(C)->getFileName());
+
if (clang_isDeclaration(C.kind))
return getDeclSpelling(getCursorDecl(C));
@@ -2757,6 +2767,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return createCXString("macro definition");
case CXCursor_MacroInstantiation:
return createCXString("macro instantiation");
+ case CXCursor_InclusionDirective:
+ return createCXString("inclusion directive");
case CXCursor_Namespace:
return createCXString("Namespace");
case CXCursor_LinkageSpec:
@@ -2977,7 +2989,13 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) {
SourceLocation L = cxcursor::getCursorMacroDefinition(C)->getLocation();
return cxloc::translateSourceLocation(getCursorContext(C), L);
}
-
+
+ if (C.kind == CXCursor_InclusionDirective) {
+ SourceLocation L
+ = cxcursor::getCursorInclusionDirective(C)->getSourceRange().getBegin();
+ return cxloc::translateSourceLocation(getCursorContext(C), L);
+ }
+
if (C.kind < CXCursor_FirstDecl || C.kind > CXCursor_LastDecl)
return clang_getNullLocation();
@@ -3043,12 +3061,14 @@ static SourceRange getRawCursorExtent(CXCursor C) {
if (C.kind == CXCursor_MacroDefinition)
return cxcursor::getCursorMacroDefinition(C)->getSourceRange();
-
+
+ if (C.kind == CXCursor_InclusionDirective)
+ return cxcursor::getCursorInclusionDirective(C)->getSourceRange();
+
if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl)
return getCursorDecl(C)->getSourceRange();
- return SourceRange();
-}
+ return SourceRange();}
extern "C" {
@@ -4149,6 +4169,14 @@ void clang_disposeOverriddenCursors(CXCursor *overridden) {
delete [] overridden;
}
+CXFile clang_getIncludedFile(CXCursor cursor) {
+ if (cursor.kind != CXCursor_InclusionDirective)
+ return 0;
+
+ InclusionDirective *ID = getCursorInclusionDirective(cursor);
+ return (void *)ID->getFile();
+}
+
} // end: extern "C"