[cfe-commits] r51943 - in /cfe/trunk: 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
Ted Kremenek
kremenek at apple.com
Wed Jun 4 08:55:16 PDT 2008
Author: kremenek
Date: Wed Jun 4 10:55:15 2008
New Revision: 51943
URL: http://llvm.org/viewvc/llvm-project?rev=51943&view=rev
Log:
Moved LangOptions from TranslationUnit to ASTContext. This induced a variety of cleanups in some ASTConsumers.
Modified:
cfe/trunk/Driver/ASTConsumers.cpp
cfe/trunk/Driver/ASTConsumers.h
cfe/trunk/Driver/SerializationTest.cpp
cfe/trunk/Driver/clang.cpp
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/TranslationUnit.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/TranslationUnit.cpp
cfe/trunk/lib/Sema/ParseAST.cpp
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=51943&r1=51942&r2=51943&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Wed Jun 4 10:55:15 2008
@@ -868,12 +868,10 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
llvm::sys::Path FName(InFile.c_str());
FName.appendSuffix("ast");
- return new SingleFileSerializer(FName, Diags, Features);
+ return new SingleFileSerializer(FName, Diags);
}
Modified: cfe/trunk/Driver/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=51943&r1=51942&r2=51943&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Wed Jun 4 10:55:15 2008
@@ -67,13 +67,11 @@
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
Modified: cfe/trunk/Driver/SerializationTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/SerializationTest.cpp?rev=51943&r1=51942&r2=51943&view=diff
==============================================================================
--- cfe/trunk/Driver/SerializationTest.cpp (original)
+++ cfe/trunk/Driver/SerializationTest.cpp Wed Jun 4 10:55:15 2008
@@ -33,26 +33,16 @@
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 @@
} // 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 @@
llvm::sys::Path& FNameDeclPrint) {
// Deserialize the translation unit.
- TranslationUnit* NewTU = ReadASTBitcodeFile(Filename,FMgr);
+ TranslationUnit* NewTU = ReadASTBitcodeFile(Filename, FMgr);
if (!NewTU)
return false;
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=51943&r1=51942&r2=51943&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Wed Jun 4 10:55:15 2008
@@ -1189,7 +1189,7 @@
OutputFile, VisualizeEG, TrimGraph, AnalyzeAll);
case TestSerialization:
- return CreateSerializationTest(Diag, FileMgr, LangOpts);
+ return CreateSerializationTest(Diag, FileMgr);
case EmitLLVM:
case EmitBC:
@@ -1198,7 +1198,7 @@
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 @@
// 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");
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=51943&r1=51942&r2=51943&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Jun 4 10:55:15 2008
@@ -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 @@
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 @@
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);
Modified: cfe/trunk/include/clang/AST/TranslationUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TranslationUnit.h?rev=51943&r1=51942&r2=51943&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TranslationUnit.h (original)
+++ cfe/trunk/include/clang/AST/TranslationUnit.h Wed Jun 4 10:55:15 2008
@@ -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 FileEntry;
class TranslationUnit {
- LangOptions LangOpts;
ASTContext* Context;
std::vector<Decl*> TopLevelDecls;
bool OwnsMetaData;
@@ -42,15 +41,13 @@
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 @@
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; }
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=51943&r1=51942&r2=51943&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Jun 4 10:55:15 2008
@@ -1701,6 +1701,7 @@
/// 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 @@
}
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 @@
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);
Modified: cfe/trunk/lib/AST/TranslationUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TranslationUnit.cpp?rev=51943&r1=51942&r2=51943&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TranslationUnit.cpp (original)
+++ cfe/trunk/lib/AST/TranslationUnit.cpp Wed Jun 4 10:55:15 2008
@@ -124,16 +124,13 @@
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 @@
// 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);
Modified: cfe/trunk/lib/Sema/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ParseAST.cpp?rev=51943&r1=51942&r2=51943&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/ParseAST.cpp (original)
+++ cfe/trunk/lib/Sema/ParseAST.cpp Wed Jun 4 10:55:15 2008
@@ -34,10 +34,11 @@
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);
More information about the cfe-commits
mailing list