*/
CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
int displayDiagnostics);
-CINDEX_LINKAGE void clang_disposeIndex(CXIndex);
-CINDEX_LINKAGE CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
+CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
+CINDEX_LINKAGE CXString
+clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
+
+/*
+ * \brief Request that AST's be generated external for API calls which parse
+ * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
+ *
+ * Note: This is for debugging purposes only, and may be removed at a later
+ * date.
+ *
+ * \param index - The index to update.
+ * \param value - The new flag value.
+ */
+CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
+ int value);
/*
* \brief Create a translation unit from an AST file (-emit-ast).
CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
CXIndex, const char *ast_filename
);
+
/**
* \brief Destroy the specified CXTranslationUnit object.
*/
* \brief Return the CXTranslationUnit for a given source file and the provided
* command line arguments one would pass to the compiler.
*
- * Note: The 'source_filename' argument is optional. If the caller provides a NULL pointer,
- * the name of the source file is expected to reside in the specified command line arguments.
+ * Note: The 'source_filename' argument is optional. If the caller provides a
+ * NULL pointer, the name of the source file is expected to reside in the
+ * specified command line arguments.
*
- * Note: When encountered in 'clang_command_line_args', the following options are ignored:
+ * Note: When encountered in 'clang_command_line_args', the following options
+ * are ignored:
*
* '-c'
* '-emit-ast'
* '-fsyntax-only'
* '-o <output file>' (both '-o' and '<output file>' are ignored)
*
+ *
+ * \param source_filename - The name of the source file to load, or NULL if the
+ * source file is included in clang_command_line_args.
*/
CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
- CXIndex CIdx,
- const char *source_filename /* specify NULL if the source file is in clang_command_line_args */,
+ CXIndex CIdx,
+ const char *source_filename,
int num_clang_command_line_args,
const char **clang_command_line_args
);
}
static void usage {
clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames);
- }
+ }
*/
typedef void *CXClientData;
typedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor,
CXClientData);
-CINDEX_LINKAGE void clang_loadTranslationUnit(CXTranslationUnit, CXTranslationUnitIterator,
- CXClientData);
+CINDEX_LINKAGE void clang_loadTranslationUnit(CXTranslationUnit,
+ CXTranslationUnitIterator,
+ CXClientData);
/*
Usage: clang_loadDeclaration(). Will load the declaration, issuing a
Usage: clang_getCursor() will translate a source/line/column position
into an AST cursor (to derive semantic information from the source code).
*/
-CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
- unsigned line, unsigned column);
+CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit,
+ const char *source_name,
+ unsigned line, unsigned column);
CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
* \param CIdx the \c CXIndex instance that will be used to perform code
* completion.
*
- * \param source_filename the name of the source file that should be parsed
- * to perform code-completion. This source file must be the same as or
- * include the filename described by \p complete_filename, or no code-completion
- * results will be produced. NOTE: One can also specify NULL for this argument if
- * the source file is included in command_line_args.
+ * \param source_filename the name of the source file that should be parsed to
+ * perform code-completion. This source file must be the same as or include the
+ * filename described by \p complete_filename, or no code-completion results
+ * will be produced. NOTE: One can also specify NULL for this argument if the
+ * source file is included in command_line_args.
*
* \param num_command_line_args the number of command-line arguments stored in
* \p command_line_args.
DisplayDiagnostics = Display;
}
+ bool getUseExternalASTGeneration() const { return UseExternalASTGeneration; }
+ void setUseExternalASTGeneration(bool Value) {
+ UseExternalASTGeneration = Value;
+ }
+
Diagnostic &getDiags() {
return DisplayDiagnostics ? *TextDiags : IgnoreDiags;
}
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) {
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;
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());
}