class TargetInfo;
/// Apply the header search options to get given HeaderSearch object.
-void ApplyHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
- HeaderSearch &HS, const LangOptions &Lang,
+void ApplyHeaderSearchOptions(HeaderSearch &HS,
+ const HeaderSearchOptions &HSOpts,
+ const LangOptions &Lang,
const llvm::Triple &triple);
/// InitializePreprocessor - Initialize the preprocessor getting it and the
bool DisableMacroExpansion : 1; // True if macro expansion is disabled.
bool InMacroArgs : 1; // True if parsing fn macro invocation args.
+ /// Whether the preprocessor owns the header search object.
+ bool OwnsHeaderSearch : 1;
+
/// Identifiers - This is mapping/lookup information for all identifiers in
/// the program, including program keywords.
mutable IdentifierTable Identifiers;
public:
Preprocessor(Diagnostic &diags, const LangOptions &opts, TargetInfo &target,
SourceManager &SM, HeaderSearch &Headers,
- IdentifierInfoLookup *IILookup = 0);
+ IdentifierInfoLookup *IILookup = 0,
+ bool OwnsHeaderSearch = false);
~Preprocessor();
Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts,
TargetInfo &target, SourceManager &SM,
HeaderSearch &Headers,
- IdentifierInfoLookup* IILookup)
+ IdentifierInfoLookup* IILookup,
+ bool OwnsHeaders)
: Diags(&diags), Features(opts), Target(target),FileMgr(Headers.getFileMgr()),
SourceMgr(SM), HeaderInfo(Headers), Identifiers(opts, IILookup),
BuiltinInfo(Target), CurPPLexer(0), CurDirLookup(0), Callbacks(0) {
ScratchBuf = new ScratchBuffer(SourceMgr);
CounterValue = 0; // __COUNTER__ starts at 0.
+ OwnsHeaderSearch = OwnsHeaders;
// Clear stats.
NumDirectives = NumDefined = NumUndefined = NumPragma = 0;
// Delete the scratch buffer info.
delete ScratchBuf;
+ // Delete the header search info, if we own it.
+ if (OwnsHeaderSearch)
+ delete &HeaderInfo;
+
delete Callbacks;
}
const PreprocessorOptions &PPOpts,
const DependencyOutputOptions &DepOpts,
TargetInfo &Target, SourceManager &SourceMgr,
- HeaderSearch &HeaderInfo) {
+ FileManager &FileMgr) {
PTHManager *PTHMgr = 0;
if (!TokenCache.empty() && !PPOpts.getImplicitPTHInclude().empty()) {
fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
exit(1);
// Create the Preprocessor.
+ HeaderSearch *HeaderInfo = new HeaderSearch(FileMgr);
Preprocessor *PP = new Preprocessor(Diags, LangInfo, Target,
- SourceMgr, HeaderInfo, PTHMgr);
+ SourceMgr, *HeaderInfo, PTHMgr,
+ /*OwnsHeaderSearch=*/true);
// Note that this is different then passing PTHMgr to Preprocessor's ctor.
// That argument is used as the IdentifierInfoLookup argument to
if (i)
SourceMgr.clearIDTables();
- // Process the -I options and set them in the HeaderInfo.
- HeaderSearch HeaderInfo(FileMgr);
-
- // Apply all the options to the header search object.
- ApplyHeaderSearchOptions(CompOpts.getHeaderSearchOpts(), HeaderInfo,
- CompOpts.getLangOpts(), Triple);
-
// Set up the preprocessor with these options.
llvm::OwningPtr<Preprocessor>
PP(CreatePreprocessor(Diags, CompOpts.getLangOpts(),
CompOpts.getPreprocessorOpts(),
CompOpts.getDependencyOutputOpts(),
- *Target, SourceMgr, HeaderInfo));
+ *Target, SourceMgr, FileMgr));
+
+ // Apply all the options to the header search object.
+ ApplyHeaderSearchOptions(PP->getHeaderSearchInfo(),
+ CompOpts.getHeaderSearchOpts(),
+ CompOpts.getLangOpts(), Triple);
if (CompOpts.getPreprocessorOpts().getImplicitPCHInclude().empty()) {
if (InitializeSourceManager(*PP.get(), InFile))
Diags.getClient()->BeginSourceFile(CompOpts.getLangOpts());
ProcessInputFile(CompOpts, *PP, InFile, ProgAction, Context);
Diags.getClient()->EndSourceFile();
-
- HeaderInfo.ClearFileInfo();
}
if (CompOpts.getDiagnosticOpts().ShowCarets)