]> granicus.if.org Git - clang/commitdiff
Allow Preprocessor to take ownership of the HeaderSearch object. I think it should...
authorDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 21:44:21 +0000 (21:44 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 21:44:21 +0000 (21:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86882 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/Utils.h
include/clang/Lex/Preprocessor.h
lib/Frontend/InitHeaderSearch.cpp
lib/Lex/Preprocessor.cpp
tools/clang-cc/clang-cc.cpp

index 5526dfdb324fcb479266b60a9ff379da30ea89c4..cc0d1b56717a2056c7d38f919b0c07e7fc544ddf 100644 (file)
@@ -41,8 +41,9 @@ class Stmt;
 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
index 2783716b89ff3cd16d65fe235e19d64895de0968..799efa86856519c788a543a29e60310a637a2f5e 100644 (file)
@@ -94,6 +94,9 @@ class Preprocessor {
   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;
@@ -209,7 +212,8 @@ private:  // Cached tokens state.
 public:
   Preprocessor(Diagnostic &diags, const LangOptions &opts, TargetInfo &target,
                SourceManager &SM, HeaderSearch &Headers,
-               IdentifierInfoLookup *IILookup = 0);
+               IdentifierInfoLookup *IILookup = 0,
+               bool OwnsHeaderSearch = false);
 
   ~Preprocessor();
 
index 0e120e87acf103a0cdd5a0edc88f4f6d3fe92f7d..b4f48ac8fde1aabb0b7c306fa549fc419c1b3b61 100644 (file)
@@ -641,8 +641,9 @@ void InitHeaderSearch::Realize() {
   }
 }
 
-void clang::ApplyHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
-                                     HeaderSearch &HS, const LangOptions &Lang,
+void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
+                                     const HeaderSearchOptions &HSOpts,
+                                     const LangOptions &Lang,
                                      const llvm::Triple &Triple) {
   InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
 
index 487b9d63c169a687a7e6416dc14f662e00950cdd..0110e6b9a4627513afa6b90b2aead80296d7196f 100644 (file)
@@ -46,12 +46,14 @@ using namespace clang;
 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;
@@ -115,6 +117,10 @@ Preprocessor::~Preprocessor() {
   // Delete the scratch buffer info.
   delete ScratchBuf;
 
+  // Delete the header search info, if we own it.
+  if (OwnsHeaderSearch)
+    delete &HeaderInfo;
+
   delete Callbacks;
 }
 
index f6e65572096951e786b178abe083fc5f7294bc92..0b5a6d35a6e576f7ecf7fa4b1b037dde965604e8 100644 (file)
@@ -379,7 +379,7 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo,
                    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 "
@@ -400,8 +400,10 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo,
     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
@@ -1203,19 +1205,17 @@ int main(int argc, char **argv) {
     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))
@@ -1230,8 +1230,6 @@ int main(int argc, char **argv) {
     Diags.getClient()->BeginSourceFile(CompOpts.getLangOpts());
     ProcessInputFile(CompOpts, *PP, InFile, ProgAction, Context);
     Diags.getClient()->EndSourceFile();
-
-    HeaderInfo.ClearFileInfo();
   }
 
   if (CompOpts.getDiagnosticOpts().ShowCarets)