[cfe-dev] Using "-x c++" with clang_parseTranslationUnit()
Stefan Seefeld
stefan at seefeld.name
Sat Mar 19 15:20:12 PDT 2011
On 2011-03-19 18:13, Argyrios Kyrtzidis wrote:
> Could you post some code?
Here is the relevant snippet ('bpl' is an alias to boost::python, and
cpp_flags is a Python list with additional compiler flags, such as
-I..., -D..., etc.):
char const **args = new char const*[bpl::len(cpp_flags) + 2];
args[0] = "-x";
args[1] = "c++";
for (size_t i = 0; i != bpl::len(cpp_flags); ++i)
args[i + 2] = bpl::extract<char const *>(cpp_flags[i]);
CXIndex idx = clang_createIndex(0, 1);
CXTranslationUnit_Flags flags =
CXTranslationUnit_DetailedPreprocessingRecord;
CXTranslationUnit tu =
clang_parseTranslationUnit(idx, input_file,
args,
bpl::len(cpp_flags) + 2,
0, // unsaved_files
0, // num_unsaved_files
flags);
Running this on a C++ source file with extension '.h' will first warn
about unused '-x c++', and then cause an error since its header search
path doesn't include standard C++ headers.
(I'm in fact trying to parse clang code itself to generate a cross
reference via Synopsis.)
Thanks,
Stefan
--
...ich hab' noch einen Koffer in Berlin...
More information about the cfe-dev
mailing list