[cfe-commits] r86882 - in /cfe/trunk: include/clang/Frontend/Utils.h include/clang/Lex/Preprocessor.h lib/Frontend/InitHeaderSearch.cpp lib/Lex/Preprocessor.cpp tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Wed Nov 11 13:44:22 PST 2009


Author: ddunbar
Date: Wed Nov 11 15:44:21 2009
New Revision: 86882

URL: http://llvm.org/viewvc/llvm-project?rev=86882&view=rev
Log:
Allow Preprocessor to take ownership of the HeaderSearch object. I think it should probably always own the header search object, but I'm not sure...

Modified:
    cfe/trunk/include/clang/Frontend/Utils.h
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Frontend/Utils.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=86882&r1=86881&r2=86882&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/Utils.h (original)
+++ cfe/trunk/include/clang/Frontend/Utils.h Wed Nov 11 15:44:21 2009
@@ -41,8 +41,9 @@
 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

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=86882&r1=86881&r2=86882&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Nov 11 15:44:21 2009
@@ -94,6 +94,9 @@
   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 @@
 public:
   Preprocessor(Diagnostic &diags, const LangOptions &opts, TargetInfo &target,
                SourceManager &SM, HeaderSearch &Headers,
-               IdentifierInfoLookup *IILookup = 0);
+               IdentifierInfoLookup *IILookup = 0,
+               bool OwnsHeaderSearch = false);
 
   ~Preprocessor();
 

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=86882&r1=86881&r2=86882&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Wed Nov 11 15:44:21 2009
@@ -641,8 +641,9 @@
   }
 }
 
-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);
 

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=86882&r1=86881&r2=86882&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Nov 11 15:44:21 2009
@@ -46,12 +46,14 @@
 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 @@
   // Delete the scratch buffer info.
   delete ScratchBuf;
 
+  // Delete the header search info, if we own it.
+  if (OwnsHeaderSearch)
+    delete &HeaderInfo;
+
   delete Callbacks;
 }
 

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86882&r1=86881&r2=86882&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Nov 11 15:44:21 2009
@@ -379,7 +379,7 @@
                    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 @@
     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 @@
     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 @@
     Diags.getClient()->BeginSourceFile(CompOpts.getLangOpts());
     ProcessInputFile(CompOpts, *PP, InFile, ProgAction, Context);
     Diags.getClient()->EndSourceFile();
-
-    HeaderInfo.ClearFileInfo();
   }
 
   if (CompOpts.getDiagnosticOpts().ShowCarets)





More information about the cfe-commits mailing list