diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-03-19 16:15:56 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-03-19 16:15:56 +0000 |
commit | 7f6d60dcc2cea9975c125fe6750ecc39af6a6fb0 (patch) | |
tree | be9ba62d824d411415b67cc23233856110c3bdff /clang/lib | |
parent | 45a967cd628f44cdb8e3430ccddbd8c8c6a3b1af (diff) | |
download | bcm5719-llvm-7f6d60dcc2cea9975c125fe6750ecc39af6a6fb0.tar.gz bcm5719-llvm-7f6d60dcc2cea9975c125fe6750ecc39af6a6fb0.zip |
Optionally store a PreprocessingRecord in the preprocessor itself, and
tie its creation to a CC1 flag -detailed-preprocessing-record.
llvm-svn: 98963
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 18 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Lex/PreprocessingRecord.cpp | 16 | ||||
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 45 |
5 files changed, 54 insertions, 32 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 1aaa536cb34..935c4152437 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -278,8 +278,7 @@ public: ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI, Diagnostic &Diags, bool OnlyLocalDecls, - bool CaptureDiagnostics, - bool WantPreprocessingRecord) { + bool CaptureDiagnostics) { // Create the compiler instance to use for building the AST. CompilerInstance Clang; llvm::OwningPtr<ASTUnit> AST; @@ -329,15 +328,6 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(CompilerInvocation *CI, // Create the preprocessor. Clang.createPreprocessor(); - // If the ASTUnit was requested to store information about preprocessing, - // create storage for that information and attach an appropriate callback to - // populate that storage. - if (WantPreprocessingRecord) { - AST->Preprocessing.reset(new PreprocessingRecord); - Clang.getPreprocessor().addPPCallbacks( - new PopulatePreprocessingRecord(*AST->Preprocessing)); - } - Act.reset(new TopLevelDeclTrackerAction(*AST)); if (!Act->BeginSourceFile(Clang, Clang.getFrontendOpts().Inputs[0].second, /*IsAST=*/false)) @@ -377,8 +367,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin, bool OnlyLocalDecls, RemappedFile *RemappedFiles, unsigned NumRemappedFiles, - bool CaptureDiagnostics, - bool WantPreprocessingRecord) { + bool CaptureDiagnostics) { llvm::SmallVector<const char *, 16> Args; Args.push_back("<clang>"); // FIXME: Remove dummy argument. Args.insert(Args.end(), ArgBegin, ArgEnd); @@ -430,6 +419,5 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin, CI->getFrontendOpts().DisableFree = true; return LoadFromCompilerInvocation(CI.take(), Diags, OnlyLocalDecls, - CaptureDiagnostics, - WantPreprocessingRecord); + CaptureDiagnostics); } diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 5d399bd944e..bb0d308e7b4 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -224,6 +224,9 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags, PP->setPTHManager(PTHMgr); } + if (PPOpts.DetailedRecord) + PP->createPreprocessingRecord(); + InitializePreprocessor(*PP, PPOpts, HSOpts, FEOpts); // Handle generating dependencies, if requested. diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 5798f2f7100..d47fcf6f9b7 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -575,6 +575,8 @@ static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts, } if (!Opts.UsePredefines) Res.push_back("-undef"); + if (Opts.DetailedRecord) + Res.push_back("-detailed-preprocessing-record"); if (!Opts.ImplicitPCHInclude.empty()) { Res.push_back("-include-pch"); Res.push_back(Opts.ImplicitPCHInclude); @@ -1232,7 +1234,7 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, else Opts.TokenCache = Opts.ImplicitPTHInclude; Opts.UsePredefines = !Args.hasArg(OPT_undef); - + Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record); // Add macros from the command line. for (arg_iterator it = Args.filtered_begin(OPT_D, OPT_U), ie = Args.filtered_end(); it != ie; ++it) { diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index 3e0a03b74f8..83268e0134a 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -21,19 +21,3 @@ void PreprocessingRecord::addPreprocessedEntity(PreprocessedEntity *Entity) { PreprocessedEntities.push_back(Entity); } -void PopulatePreprocessingRecord::MacroExpands(const Token &Id, - const MacroInfo* MI) { - Record.addPreprocessedEntity( - new (Record) MacroInstantiation(Id.getIdentifierInfo(), - Id.getLocation(), - MacroDefinitions[MI])); -} - -void PopulatePreprocessingRecord::MacroDefined(const IdentifierInfo *II, - const MacroInfo *MI) { - SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc()); - MacroDefinition *Def - = new (Record) MacroDefinition(II, MI->getDefinitionLoc(), R); - MacroDefinitions[MI] = Def; - Record.addPreprocessedEntity(Def); -} diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 917a2e7412f..d9aaed4a485 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -31,6 +31,7 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Pragma.h" +#include "clang/Lex/PreprocessingRecord.h" #include "clang/Lex/ScratchBuffer.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Basic/SourceManager.h" @@ -627,3 +628,47 @@ bool Preprocessor::HandleComment(Token &result, SourceRange Comment) { } CommentHandler::~CommentHandler() { } + +namespace { + /// \brief Preprocessor callback action used to populate a preprocessing + /// record. + class PopulatePreprocessingRecord : public PPCallbacks { + /// \brief The preprocessing record this action will populate. + PreprocessingRecord &Record; + + /// \brief Mapping from MacroInfo structures to their definitions. + llvm::DenseMap<const MacroInfo *, MacroDefinition *> MacroDefinitions; + + public: + explicit PopulatePreprocessingRecord(PreprocessingRecord &Record) + : Record(Record) { } + + virtual void MacroExpands(const Token &Id, const MacroInfo* MI); + virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI); + }; +} + +void PopulatePreprocessingRecord::MacroExpands(const Token &Id, + const MacroInfo* MI) { + Record.addPreprocessedEntity( + new (Record) MacroInstantiation(Id.getIdentifierInfo(), + Id.getLocation(), + MacroDefinitions[MI])); +} + +void PopulatePreprocessingRecord::MacroDefined(const IdentifierInfo *II, + const MacroInfo *MI) { + SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc()); + MacroDefinition *Def + = new (Record) MacroDefinition(II, MI->getDefinitionLoc(), R); + MacroDefinitions[MI] = Def; + Record.addPreprocessedEntity(Def); +} + +void Preprocessor::createPreprocessingRecord() { + if (Record) + return; + + Record.reset(new PreprocessingRecord); + addPPCallbacks(new PopulatePreprocessingRecord(*Record)); +} |