Switch clang_createTranslationUnitFromSourceFile to use ASTUnit::LoadFromCommandLine.
- This is much faster, as it avoids the overhead of dumping an AST file to disk and reloading it.
- For debugging purposes, there is a clang_setUseExternalASTGeneration hook which can be used to disable this.
On the Sketch Cocoa app, the speedup is pretty nice, especially when using a PCH file while scanning the source:
Wall time to c-index-test all files (no PCH):
Old: 23.4221
New: 12.3884
Wall time to c-index-test all files (with a PCH, and "local" mode):
Old: 10.9233
New: 1.9038
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90385 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 8e6eeb5..4e76809 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -202,8 +202,22 @@
*/
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).
@@ -211,6 +225,7 @@
CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
CXIndex, const char *ast_filename
);
+
/**
* \brief Destroy the specified CXTranslationUnit object.
*/
@@ -220,20 +235,25 @@
* \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
);
@@ -253,13 +273,14 @@
}
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
@@ -320,8 +341,9 @@
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);
@@ -634,11 +656,11 @@
* \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.