]> granicus.if.org Git - clang/commitdiff
Moved LangOptions from TranslationUnit to ASTContext. This induced a variety of...
authorTed Kremenek <kremenek@apple.com>
Wed, 4 Jun 2008 15:55:15 +0000 (15:55 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 4 Jun 2008 15:55:15 +0000 (15:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51943 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/ASTConsumers.cpp
Driver/ASTConsumers.h
Driver/SerializationTest.cpp
Driver/clang.cpp
include/clang/AST/ASTContext.h
include/clang/AST/TranslationUnit.h
lib/AST/ASTContext.cpp
lib/AST/TranslationUnit.cpp
lib/Sema/ParseAST.cpp

index 9ab6157cfaa3d7e88c241a998eef664f37d6f041..5d45f312e2e77956f539bed987c3418c17fa2d16 100644 (file)
@@ -868,12 +868,10 @@ namespace {
 class ASTSerializer : public ASTConsumer {
 protected:
   Diagnostic &Diags;
-  const LangOptions& lang;
   TranslationUnit* TU;
 
 public:
-  ASTSerializer(Diagnostic& diags, const LangOptions& LO)
-    : Diags(diags), lang(LO), TU(0) {}
+  ASTSerializer(Diagnostic& diags) : Diags(diags), TU(0) {}
     
   virtual ~ASTSerializer() { delete TU; }
   
@@ -892,9 +890,8 @@ public:
 class SingleFileSerializer : public ASTSerializer {
   const llvm::sys::Path FName;
 public:
-  SingleFileSerializer(const llvm::sys::Path& F, Diagnostic &diags,
-                          const LangOptions &LO)
-  : ASTSerializer(diags,LO), FName(F) {}    
+  SingleFileSerializer(const llvm::sys::Path& F, Diagnostic &diags)
+  : ASTSerializer(diags), FName(F) {}    
   
   ~SingleFileSerializer() {
     EmitASTBitcodeFile(TU, FName);
@@ -904,9 +901,8 @@ public:
 class BuildSerializer : public ASTSerializer {
   llvm::sys::Path EmitDir;  
 public:
-  BuildSerializer(const llvm::sys::Path& dir, Diagnostic &diags,
-                  const LangOptions &LO)
-  : ASTSerializer(diags,LO), EmitDir(dir) {}
+  BuildSerializer(const llvm::sys::Path& dir, Diagnostic &diags)
+  : ASTSerializer(diags), EmitDir(dir) {}
   
   ~BuildSerializer() {
 
@@ -950,8 +946,7 @@ public:
 
 ASTConsumer* clang::CreateASTSerializer(const std::string& InFile,
                                         const std::string& OutputFile,
-                                        Diagnostic &Diags,
-                                        const LangOptions &Features) {
+                                        Diagnostic &Diags) {
   
   if (OutputFile.size()) {
     if (InFile == "-") {
@@ -982,7 +977,7 @@ ASTConsumer* clang::CreateASTSerializer(const std::string& InFile,
     
     // FIXME: We should probably only allow using BuildSerializer when
     // the ASTs come from parsed source files, and not from .ast files.
-    return new BuildSerializer(EmitDir, Diags, Features);
+    return new BuildSerializer(EmitDir, Diags);
   }
 
   // The user did not specify an output directory for serialized ASTs.
@@ -991,5 +986,5 @@ ASTConsumer* clang::CreateASTSerializer(const std::string& InFile,
   
   llvm::sys::Path FName(InFile.c_str());
   FName.appendSuffix("ast");
-  return new SingleFileSerializer(FName, Diags, Features);  
+  return new SingleFileSerializer(FName, Diags);  
 }
index 7037ade1ddff8ad52405931f01df4141091f74f5..ca93e0fbf9ab13764edd612518825c089024655e 100644 (file)
@@ -67,13 +67,11 @@ ASTConsumer* CreateHTMLPrinter(const std::string &OutFile, Diagnostic &D,
                                Preprocessor *PP, PreprocessorFactory* PPF);
 
 ASTConsumer *CreateSerializationTest(Diagnostic &Diags,
-                                     FileManager& FMgr, 
-                                     const LangOptions &LOpts);
+                                     FileManager& FMgr);
   
 ASTConsumer *CreateASTSerializer(const std::string& InFile,
                                  const std::string& EmitDir,
-                                 Diagnostic &Diags,
-                                 const LangOptions &LOpts);
+                                 Diagnostic &Diags);
 
 } // end clang namespace
 
index 5f7b94fca409b7d30b65dc21ebb27f6b052dc845..946a4c87d6ae83560702955245a375256283d8c8 100644 (file)
@@ -33,26 +33,16 @@ using namespace clang;
 namespace {
   
 class SerializationTest : public ASTConsumer {
-  llvm::OwningPtr<TranslationUnit> TU;
+  TranslationUnit* TU;
   Diagnostic &Diags;
   FileManager &FMgr;  
-  const LangOptions& lopts;
 public:  
-  SerializationTest(Diagnostic &d, FileManager& fmgr, const LangOptions& LOpts)
-                    : Diags(d), FMgr(fmgr), lopts(LOpts) {}
+  SerializationTest(Diagnostic &d, FileManager& fmgr)
+                    : TU(0), Diags(d), FMgr(fmgr) {}
   
   ~SerializationTest();
 
-  virtual void Initialize(ASTContext& context) {
-    if (!TU) {
-      TU.reset(new TranslationUnit(context, lopts));
-      TU->SetOwnsDecls(false);
-    }
-  }  
-
-  virtual void HandleTopLevelDecl(Decl *D) {
-    TU->AddTopLevelDecl(D);
-  }
+  virtual void InitializeTU(TranslationUnit& tu) { TU = &tu; }  
   
 private:
   bool Serialize(llvm::sys::Path& Filename, llvm::sys::Path& FNameDeclPrint);
@@ -62,10 +52,8 @@ private:
 } // end anonymous namespace
 
 ASTConsumer*
-clang::CreateSerializationTest(Diagnostic &Diags, FileManager& FMgr,
-                               const LangOptions &LOpts) {
-  
-  return new SerializationTest(Diags,FMgr,LOpts);
+clang::CreateSerializationTest(Diagnostic &Diags, FileManager& FMgr) {  
+  return new SerializationTest(Diags, FMgr);
 }
 
 
@@ -89,7 +77,7 @@ bool SerializationTest::Deserialize(llvm::sys::Path& Filename,
                                     llvm::sys::Path& FNameDeclPrint) {
   
   // Deserialize the translation unit.
-  TranslationUnit* NewTU = ReadASTBitcodeFile(Filename,FMgr);
+  TranslationUnit* NewTU = ReadASTBitcodeFile(Filename, FMgr);
 
   if (!NewTU)
     return false;
index 7a61145c66cbdb0a38e3b71f90c6577aa17391a4..df41e54b32d4db812eef879a66c0345fb0e40096 100644 (file)
@@ -1189,7 +1189,7 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
                                 OutputFile, VisualizeEG, TrimGraph, AnalyzeAll);
       
     case TestSerialization:
-      return CreateSerializationTest(Diag, FileMgr, LangOpts);
+      return CreateSerializationTest(Diag, FileMgr);
       
     case EmitLLVM:
     case EmitBC:
@@ -1198,7 +1198,7 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
 
     case SerializeAST:
       // FIXME: Allow user to tailor where the file is written.
-      return CreateASTSerializer(InFile, OutputFile, Diag, LangOpts);
+      return CreateASTSerializer(InFile, OutputFile, Diag);
       
     case RewriteObjC:
       return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts);
@@ -1362,8 +1362,8 @@ static void ProcessSerializedFile(const std::string& InFile, Diagnostic& Diag,
   // translation unit, rather than InFile.
   llvm::Module *DestModule;
   llvm::OwningPtr<ASTConsumer>
-    Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOpts(), 0, 0,
-                               DestModule));
+    Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOptions(),
+                               0, 0, DestModule));
   
   if (!Consumer) {      
     fprintf(stderr, "Unsupported program action with serialized ASTs!\n");
index dfe117053cf400638395e6bf928aa639f4d93235..cf04f94990979ee00986de8986eba52b7becfd2d 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_AST_ASTCONTEXT_H
 #define LLVM_CLANG_AST_ASTCONTEXT_H
 
+#include "clang/Basic/LangOptions.h"
 #include "clang/AST/Builtins.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecordLayout.h"
@@ -77,15 +78,24 @@ class ASTContext {
 
   TranslationUnitDecl *TUDecl;
 
+  /// SourceMgr - The associated SourceManager object.
   SourceManager &SourceMgr;
+  
+  /// LangOpts - The language options used to create the AST associated with
+  ///  this ASTContext object.
+  LangOptions LangOpts;
+
+  /// Allocator - The allocator object used to create AST objects.
   llvm::MallocAllocator Allocator;
+
 public:
   TargetInfo &Target;
   IdentifierTable &Idents;
   SelectorTable &Selectors;
   
   SourceManager& getSourceManager() { return SourceMgr; }
-  llvm::MallocAllocator &getAllocator() { return Allocator; }
+  llvm::MallocAllocator &getAllocator() { return Allocator; }  
+  const LangOptions& getLangOptions() const { return LangOpts; }
   
   FullSourceLoc getFullLoc(SourceLocation Loc) const { 
     return FullSourceLoc(Loc,SourceMgr);
@@ -109,9 +119,10 @@ public:
   QualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
   QualType VoidPtrTy;
   
-  ASTContext(SourceManager &SM, TargetInfo &t, IdentifierTable &idents,
-             SelectorTable &sels, unsigned size_reserve=0 ) : 
-    CFConstantStringTypeDecl(0), SourceMgr(SM), Target(t), 
+  ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
+             IdentifierTable &idents, SelectorTable &sels,
+             unsigned size_reserve=0 ) : 
+    CFConstantStringTypeDecl(0), SourceMgr(SM), LangOpts(LOpts), Target(t), 
     Idents(idents), Selectors(sels) {
 
     if (size_reserve > 0) Types.reserve(size_reserve);    
index 13b29c14a8fb64b20379fd20393d00837865fa19..c5f499b6791e7e0778636b8f7d21bfe89ee2c758 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef LLVM_CLANG_TRANSLATION_UNIT_H
 #define LLVM_CLANG_TRANSLATION_UNIT_H
 
-#include "clang/Basic/LangOptions.h"
+#include "clang/AST/ASTContext.h"
 #include "llvm/Bitcode/SerializationFwd.h"
 #include "llvm/System/Path.h"
 #include <vector>
@@ -31,7 +31,6 @@ class Decl;
 class FileEntry;
   
 class TranslationUnit {
-  LangOptions LangOpts;
   ASTContext* Context;
   std::vector<Decl*> TopLevelDecls;
   bool OwnsMetaData;
@@ -42,15 +41,13 @@ class TranslationUnit {
                                OwnsDecls(true) {}
   
 public:
-  explicit TranslationUnit(ASTContext& Ctx, const LangOptions& lopt)
-    : LangOpts(lopt), Context(&Ctx), OwnsMetaData(false),
-      OwnsDecls(true) {}
+  explicit TranslationUnit(ASTContext& Ctx)
+    : Context(&Ctx), OwnsMetaData(false), OwnsDecls(true) {}
 
   void SetOwnsDecls(bool val) { OwnsDecls = val; }
 
   ~TranslationUnit();
 
-  const LangOptions& getLangOpts() const { return LangOpts; }
   const std::string& getSourceFile() const;
   
   /// Emit - Emit the translation unit to an arbitray bitcode stream.
@@ -60,7 +57,7 @@ public:
   static TranslationUnit* Create(llvm::Deserializer& D, FileManager& FMgr);
   
   // Accessors
-  const LangOptions& getLangOptions() const { return LangOpts; }
+  const LangOptions& getLangOptions() const { return Context->getLangOptions();}
 
   ASTContext&        getContext() { return *Context; }
   const ASTContext&  getContext() const { return *Context; }
index a87efa7425ee0578a91c46cfb0a056504aa384e2..2fe1f515c0ceb28da5a883f82821961ec0880e03 100644 (file)
@@ -1701,6 +1701,7 @@ bool ASTContext::typesAreCompatible(QualType LHS_NC, QualType RHS_NC) {
 
 /// Emit - Serialize an ASTContext object to Bitcode.
 void ASTContext::Emit(llvm::Serializer& S) const {
+  S.Emit(LangOpts);
   S.EmitRef(SourceMgr);
   S.EmitRef(Target);
   S.EmitRef(Idents);
@@ -1720,6 +1721,11 @@ void ASTContext::Emit(llvm::Serializer& S) const {
 }
 
 ASTContext* ASTContext::Create(llvm::Deserializer& D) {
+  
+  // Read the language options.
+  LangOptions LOpts;
+  LOpts.Read(D);
+  
   SourceManager &SM = D.ReadRef<SourceManager>();
   TargetInfo &t = D.ReadRef<TargetInfo>();
   IdentifierTable &idents = D.ReadRef<IdentifierTable>();
@@ -1727,7 +1733,7 @@ ASTContext* ASTContext::Create(llvm::Deserializer& D) {
 
   unsigned size_reserve = D.ReadInt();
   
-  ASTContext* A = new ASTContext(SM,t,idents,sels,size_reserve);
+  ASTContext* A = new ASTContext(LOpts, SM, t, idents, sels, size_reserve);
   
   for (unsigned i = 0; i < size_reserve; ++i)
     Type::Create(*A,i,D);
index f1505b062186712228db096f7246e964f93771ff..f8416f18fa1d7aa888659c6e68f2364a03f760da 100644 (file)
@@ -124,16 +124,13 @@ void TranslationUnit::Emit(llvm::Serializer& Sezr) const {
   
   Sezr.EnterBlock(BasicMetadataBlock);
   
-  // Block for SourceManager, LangOptions, and Target.  Allows easy skipping
+  // Block for SourceManager and Target.  Allows easy skipping
   // around to the block for the Selectors during deserialization.
   Sezr.EnterBlock();
     
   // Emit the SourceManager.
   Sezr.Emit(Context->getSourceManager());
-  
-  // Emit the LangOptions.
-  Sezr.Emit(LangOpts);
-  
+    
   // Emit the Target.
   Sezr.EmitPtr(&Context->Target);
   Sezr.EmitCStr(Context->Target.getTargetTriple());
@@ -211,10 +208,7 @@ TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr,
   
   // Read the SourceManager.
   SourceManager::CreateAndRegister(Dezr,FMgr);
-  
-  // Read the LangOptions.
-  TU->LangOpts.Read(Dezr);
-  
+    
   { // Read the TargetInfo.
     llvm::SerializedPtrID PtrID = Dezr.ReadPtrID();
     char* triple = Dezr.ReadCStr(NULL,0,true);
index 9199179af74dac48ec1cba3f1c7a701fafd4e84f..67b6546637fd83aea676c166c976dd3011ff8ac9 100644 (file)
@@ -34,10 +34,11 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
     Stmt::CollectingStats(true);
   }
   
-  ASTContext Context(PP.getSourceManager(), PP.getTargetInfo(),
+  ASTContext Context(PP.getLangOptions(), PP.getSourceManager(),
+                     PP.getTargetInfo(),
                      PP.getIdentifierTable(), PP.getSelectorTable());
   
-  TranslationUnit TU(Context, PP.getLangOptions());
+  TranslationUnit TU(Context);
 
   Sema S(PP, Context, *Consumer);
   Parser P(PP, S);