]> granicus.if.org Git - clang/commitdiff
Teach ASTContext and Preprocessor to hold on to references to the same
authorDouglas Gregor <dgregor@apple.com>
Thu, 1 Sep 2011 20:23:19 +0000 (20:23 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 1 Sep 2011 20:23:19 +0000 (20:23 +0000)
LangOptions, rather than making distinct copies of
LangOptions. Granted, LangOptions doesn't actually get modified, but
this will eventually make it easier to construct ASTContext and
Preprocessor before we know all of the LangOptions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138959 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
include/clang/Frontend/ASTUnit.h
include/clang/Lex/Preprocessor.h
include/clang/Serialization/ASTReader.h
lib/AST/ASTContext.cpp
lib/Frontend/ASTUnit.cpp
lib/Lex/Preprocessor.cpp

index ac32b1a526c056768b6a71a4a9d963c07d5ecb6a..7d034478f3b62bf003732d233a456df6e1e837c6 100644 (file)
@@ -316,7 +316,7 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> {
 
   /// LangOpts - The language options used to create the AST associated with
   ///  this ASTContext object.
-  LangOptions LangOpts;
+  LangOptions &LangOpts;
 
   /// \brief The allocator used to create AST objects.
   ///
@@ -478,7 +478,7 @@ public:
   mutable QualType AutoDeductTy;     // Deduction against 'auto'.
   mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'.
 
-  ASTContext(const LangOptions& LOpts, SourceManager &SM, const TargetInfo &t,
+  ASTContext(LangOptions& LOpts, SourceManager &SM, const TargetInfo &t,
              IdentifierTable &idents, SelectorTable &sels,
              Builtin::Context &builtins,
              unsigned size_reserve);
index 731ce383fc7032f1b5dea35da3011c1ec95c8348..2fc1491c1ad5f7bc045c717f3935ef29d18cb4e8 100644 (file)
@@ -249,7 +249,10 @@ private:
   /// \brief Whether we want to include nested macro expansions in the
   /// detailed preprocessing record.
   bool NestedMacroExpansions;
-  
+  /// \brief The language options used when we load an AST file.
+  LangOptions ASTFileLangOpts;
+
   static void ConfigureDiags(llvm::IntrusiveRefCntPtr<Diagnostic> &Diags,
                              const char **ArgBegin, const char **ArgEnd,
                              ASTUnit &AST, bool CaptureDiagnostics);
index 2871c8f080a30e19bc11e4202ce1b5f6c57a78eb..c9e45d0c97e72966799afe0cc7a6bbaebb848ecf 100644 (file)
@@ -58,7 +58,7 @@ class ModuleLoader;
 ///
 class Preprocessor : public llvm::RefCountedBase<Preprocessor> {
   Diagnostic        *Diags;
-  LangOptions        Features;
+  LangOptions       &Features;
   const TargetInfo  &Target;
   FileManager       &FileMgr;
   SourceManager     &SourceMgr;
@@ -298,7 +298,7 @@ private:  // Cached tokens state.
   MacroInfo *getInfoForMacro(IdentifierInfo *II) const;
   
 public:
-  Preprocessor(Diagnostic &diags, const LangOptions &opts,
+  Preprocessor(Diagnostic &diags, LangOptions &opts,
                const TargetInfo &target,
                SourceManager &SM, HeaderSearch &Headers,
                ModuleLoader &TheModuleLoader,
index 0cec2f455b5ffda9f44453acd325e4fc9d6678ed..71a597f9a572f7b9ce49e97d430d59eb9669165f 100644 (file)
@@ -224,7 +224,7 @@ private:
   SourceManager &SourceMgr;
   FileManager &FileMgr;
   Diagnostic &Diags;
-
+  
   /// \brief The semantic analysis object that will be processing the
   /// AST files and the translation unit that uses it.
   Sema *SemaObj;
index 75a573e301b0a228529724f34ed8fef03a48363f..3406be552c7193879042634c2c03c2d7905821a2 100644 (file)
@@ -212,7 +212,7 @@ static const LangAS::Map &getAddressSpaceMap(const TargetInfo &T,
   }
 }
 
-ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
+ASTContext::ASTContext(LangOptions& LOpts, SourceManager &SM,
                        const TargetInfo &t,
                        IdentifierTable &idents, SelectorTable &sels,
                        Builtin::Context &builtins,
index eee5b1a7ccabe30421a49af08c51e048d2531d87..b09c435c8a06c4571af5bb8f54e8597c9acc980b 100644 (file)
@@ -572,7 +572,6 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
   
   // Gather Info for preprocessor construction later on.
 
-  LangOptions LangInfo;
   HeaderSearch &HeaderInfo = *AST->HeaderInfo.get();
   std::string TargetTriple;
   std::string Predefines;
@@ -587,8 +586,8 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
   llvm::CrashRecoveryContextCleanupRegistrar<ASTReader>
     ReaderCleanup(Reader.get());
 
-  Reader->setListener(new ASTInfoCollector(LangInfo, HeaderInfo, TargetTriple,
-                                           Predefines, Counter));
+  Reader->setListener(new ASTInfoCollector(AST->ASTFileLangOpts, HeaderInfo, 
+                                           TargetTriple, Predefines, Counter));
 
   switch (Reader->ReadAST(Filename, serialization::MK_MainFile)) {
   case ASTReader::Success:
@@ -615,8 +614,9 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
   TargetOpts.Triple = TargetTriple;
   AST->Target = TargetInfo::CreateTargetInfo(AST->getDiagnostics(),
                                              TargetOpts);
-  AST->PP = new Preprocessor(AST->getDiagnostics(), LangInfo, *AST->Target,
-                             AST->getSourceManager(), HeaderInfo, *AST);
+  AST->PP = new Preprocessor(AST->getDiagnostics(), AST->ASTFileLangOpts, 
+                             *AST->Target, AST->getSourceManager(), HeaderInfo, 
+                             *AST);
   Preprocessor &PP = *AST->PP;
 
   PP.setPredefines(Reader->getSuggestedPredefines());
@@ -625,7 +625,7 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
 
   // Create and initialize the ASTContext.
 
-  AST->Ctx = new ASTContext(LangInfo,
+  AST->Ctx = new ASTContext(AST->ASTFileLangOpts,
                             AST->getSourceManager(),
                             *AST->Target,
                             PP.getIdentifierTable(),
index b285660c0853c014b6983c4f8202a482823ee8b4..f00349081cd34930fa8738fd301e2c15812bfe5b 100644 (file)
@@ -49,7 +49,7 @@ using namespace clang;
 //===----------------------------------------------------------------------===//
 ExternalPreprocessorSource::~ExternalPreprocessorSource() { }
 
-Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts,
+Preprocessor::Preprocessor(Diagnostic &diags, LangOptions &opts,
                            const TargetInfo &target, SourceManager &SM,
                            HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
                            IdentifierInfoLookup* IILookup,