[llvm-branch-commits] [cfe-tag] r84812 - in /cfe/tags/cremebrulee/cremebrulee-16: include/clang-c/Index.h tools/CIndex/CIndex.cpp
Ted Kremenek
kremenek at apple.com
Wed Oct 21 17:25:15 PDT 2009
Author: kremenek
Date: Wed Oct 21 19:25:15 2009
New Revision: 84812
URL: http://llvm.org/viewvc/llvm-project?rev=84812&view=rev
Log:
Merge in r84802.
Modified:
cfe/tags/cremebrulee/cremebrulee-16/include/clang-c/Index.h
cfe/tags/cremebrulee/cremebrulee-16/tools/CIndex/CIndex.cpp
Modified: cfe/tags/cremebrulee/cremebrulee-16/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/tags/cremebrulee/cremebrulee-16/include/clang-c/Index.h?rev=84812&r1=84811&r2=84812&view=diff
==============================================================================
--- cfe/tags/cremebrulee/cremebrulee-16/include/clang-c/Index.h (original)
+++ cfe/tags/cremebrulee/cremebrulee-16/include/clang-c/Index.h Wed Oct 21 19:25:15 2009
@@ -159,12 +159,20 @@
* \brief Return the CXTranslationUnit for a given source file and the provided
* command line arguments one would pass to the compiler.
*
- * Note: If provided, this routine will strip the '-o <outputfile>' 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:
+ *
+ * '-c'
+ * '-emit-ast'
+ * '-fsyntax-only'
+ * '-o <output file>' (both '-o' and '<output file>' are ignored)
+ *
*/
CXTranslationUnit clang_createTranslationUnitFromSourceFile(
CXIndex CIdx,
- const char *source_filename,
+ const char *source_filename /* specify NULL if the source file is in clang_command_line_args */,
int num_clang_command_line_args,
const char **clang_command_line_args
);
Modified: cfe/tags/cremebrulee/cremebrulee-16/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/tags/cremebrulee/cremebrulee-16/tools/CIndex/CIndex.cpp?rev=84812&r1=84811&r2=84812&view=diff
==============================================================================
--- cfe/tags/cremebrulee/cremebrulee-16/tools/CIndex/CIndex.cpp (original)
+++ cfe/tags/cremebrulee/cremebrulee-16/tools/CIndex/CIndex.cpp Wed Oct 21 19:25:15 2009
@@ -386,24 +386,45 @@
assert(CIdx && "Passed null CXIndex");
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
- // Build up the arguments for involing clang.
- llvm::sys::Path ClangPath = static_cast<CIndexer *>(CIdx)->getClangPath();
+ // Build up the arguments for invoking 'clang'.
std::vector<const char *> argv;
+
+ // First add the complete path to the 'clang' executable.
+ llvm::sys::Path ClangPath = static_cast<CIndexer *>(CIdx)->getClangPath();
argv.push_back(ClangPath.c_str());
+
+ // Add the '-emit-ast' option as our execution mode for 'clang'.
argv.push_back("-emit-ast");
- argv.push_back(source_filename);
- argv.push_back("-o");
+
+ // 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)
+ argv.push_back(source_filename);
+
// Generate a temporary name for the AST file.
+ argv.push_back("-o");
char astTmpFile[L_tmpnam];
argv.push_back(tmpnam(astTmpFile));
- for (int i = 0; i < num_command_line_args; i++) {
- if (command_line_args[i] && strcmp(command_line_args[i], "-o") != 0)
- argv.push_back(command_line_args[i]);
- else {
- if (++i < num_command_line_args) // Skip "-o"...
- i++; // ...and the following argument as well.
+
+ // Process the compiler options, stripping off '-o', '-c', '-fsyntax-only'.
+ for (int i = 0; i < num_command_line_args; ++i)
+ if (const char *arg = command_line_args[i]) {
+ if (strcmp(arg, "-o") == 0) {
+ ++i; // Also skip the matching argument.
+ continue;
+ }
+ if (strcmp(arg, "-emit-ast") == 0 ||
+ strcmp(arg, "-c") == 0 ||
+ strcmp(arg, "-fsyntax-only") == 0) {
+ continue;
+ }
+
+ // Keep the argument.
+ argv.push_back(arg);
}
- }
+
+ // Add the null terminator.
argv.push_back(NULL);
#ifndef LLVM_ON_WIN32
More information about the llvm-branch-commits
mailing list