aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/CIndex/CIndex.cpp43
-rw-r--r--tools/CIndex/CIndex.exports3
-rw-r--r--tools/c-index-test/c-index-test.c5
3 files changed, 48 insertions, 3 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index a5b7e99622..8ef9fb5ca0 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -324,6 +324,11 @@ public:
DisplayDiagnostics = Display;
}
+ bool getUseExternalASTGeneration() const { return UseExternalASTGeneration; }
+ void setUseExternalASTGeneration(bool Value) {
+ UseExternalASTGeneration = Value;
+ }
+
Diagnostic &getDiags() {
return DisplayDiagnostics ? *TextDiags : IgnoreDiags;
}
@@ -466,6 +471,12 @@ void clang_disposeIndex(CXIndex CIdx) {
delete static_cast<CIndexer *>(CIdx);
}
+void clang_setUseExternalASTGeneration(CXIndex CIdx, int value) {
+ assert(CIdx && "Passed null CXIndex");
+ CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
+ CXXIdx->setUseExternalASTGeneration(value);
+}
+
// FIXME: need to pass back error info.
CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
const char *ast_filename) {
@@ -485,6 +496,24 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
assert(CIdx && "Passed null CXIndex");
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
+ if (!CXXIdx->getUseExternalASTGeneration()) {
+ llvm::SmallVector<const char *, 16> Args;
+
+ // The 'source_filename' argument is optional. If the caller does not
+ // specify it then it is assumed that the source file is specified
+ // in the actual argument list.
+ if (source_filename)
+ Args.push_back(source_filename);
+ Args.insert(Args.end(), command_line_args,
+ command_line_args + num_command_line_args);
+
+ void *MainAddr = (void *)(uintptr_t)clang_createTranslationUnit;
+ return ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
+ CXXIdx->getDiags(), "<clang>", MainAddr,
+ CXXIdx->getOnlyLocalDecls(),
+ /* UseBumpAllocator = */ true);
+ }
+
// Build up the arguments for invoking 'clang'.
std::vector<const char *> argv;
@@ -572,8 +601,18 @@ void clang_loadTranslationUnit(CXTranslationUnit CTUnit,
ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
ASTContext &Ctx = CXXUnit->getASTContext();
- TUVisitor DVisit(CTUnit, callback, CData,
- CXXUnit->getOnlyLocalDecls()? 1 : Decl::MaxPCHLevel);
+ unsigned PCHLevel = Decl::MaxPCHLevel;
+
+ // Set the PCHLevel to filter out unwanted decls if requested.
+ if (CXXUnit->getOnlyLocalDecls()) {
+ PCHLevel = 0;
+
+ // If the main input was an AST, bump the level.
+ if (CXXUnit->isMainFileAST())
+ ++PCHLevel;
+ }
+
+ TUVisitor DVisit(CTUnit, callback, CData, PCHLevel);
DVisit.Visit(Ctx.getTranslationUnitDecl());
}
diff --git a/tools/CIndex/CIndex.exports b/tools/CIndex/CIndex.exports
index 2892ce50e7..458ad10283 100644
--- a/tools/CIndex/CIndex.exports
+++ b/tools/CIndex/CIndex.exports
@@ -6,6 +6,7 @@ _clang_disposeIndex
_clang_disposeString
_clang_disposeTranslationUnit
_clang_equalCursors
+_clang_getCString
_clang_getCompletionChunkCompletionString
_clang_getCompletionChunkKind
_clang_getCompletionChunkText
@@ -19,7 +20,6 @@ _clang_getCursorLine
_clang_getCursorSource
_clang_getCursorSourceFile
_clang_getCursorSpelling
-_clang_getCString
_clang_getDeclColumn
_clang_getDeclLine
_clang_getDeclSource
@@ -41,3 +41,4 @@ _clang_isInvalid
_clang_isReference
_clang_loadDeclaration
_clang_loadTranslationUnit
+_clang_setUseExternalASTGeneration
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index efff1ae318..7300585a1d 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -179,12 +179,17 @@ int perform_test_load_tu(const char *file, const char *filter) {
}
int perform_test_load_source(int argc, const char **argv, const char *filter) {
+ const char *UseExternalASTs =
+ getenv("CINDEXTEST_USE_EXTERNAL_AST_GENERATION");
CXIndex Idx;
CXTranslationUnit TU;
Idx = clang_createIndex(/* excludeDeclsFromPCH */
!strcmp(filter, "local") ? 1 : 0,
/* displayDiagnostics */ 1);
+ if (UseExternalASTs && strlen(UseExternalASTs))
+ clang_setUseExternalASTGeneration(Idx, 1);
+
TU = clang_createTranslationUnitFromSourceFile(Idx, 0, argc, argv);
if (!TU) {
fprintf(stderr, "Unable to load translation unit!\n");