Introduce a new libclang parsing flag,
CXTranslationUnit_NestedMacroInstantiations, which indicates whether
we want to see "nested" macro instantiations (e.g., those that occur
inside other macro instantiations) within the detailed preprocessing
record. Many clients (e.g., those that only care about visible tokens)
don't care about this information, and in code that uses preprocessor
metaprogramming, this information can have a very high cost.
Addresses <rdar://problem/9389320>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130990 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 7234da3..f17a415 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -2376,10 +2376,12 @@
const char * const *command_line_args,
unsigned num_unsaved_files,
struct CXUnsavedFile *unsaved_files) {
+ unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord |
+ CXTranslationUnit_NestedMacroInstantiations;
return clang_parseTranslationUnit(CIdx, source_filename,
command_line_args, num_command_line_args,
unsaved_files, num_unsaved_files,
- CXTranslationUnit_DetailedPreprocessingRecord);
+ Options);
}
struct ParseTranslationUnitInfo {
@@ -2480,9 +2482,12 @@
Args->push_back(source_filename);
// Do we need the detailed preprocessing record?
+ bool NestedMacroInstantiations = false;
if (options & CXTranslationUnit_DetailedPreprocessingRecord) {
Args->push_back("-Xclang");
Args->push_back("-detailed-preprocessing-record");
+ NestedMacroInstantiations
+ = (options & CXTranslationUnit_NestedMacroInstantiations);
}
unsigned NumErrors = Diags->getClient()->getNumErrors();
@@ -2501,7 +2506,8 @@
CompleteTranslationUnit,
CacheCodeCompetionResults,
CXXPrecompilePreamble,
- CXXChainedPCH));
+ CXXChainedPCH,
+ NestedMacroInstantiations));
if (NumErrors != Diags->getClient()->getNumErrors()) {
// Make sure to check that 'Unit' is non-NULL.