forked from OSchip/llvm-project
Removed "SourceFile" from TranslationUnit. This same information will (soon)
be available by querying the SourceManager within the ASTContext referenced by the TranslationUnit. llvm-svn: 45223
This commit is contained in:
parent
7bd082e188
commit
6c7807716b
|
@ -100,10 +100,6 @@ void TranslationUnit::Emit(llvm::Serializer& Sezr) const {
|
||||||
// around to the block for the Selectors during deserialization.
|
// around to the block for the Selectors during deserialization.
|
||||||
Sezr.EnterBlock();
|
Sezr.EnterBlock();
|
||||||
|
|
||||||
// Emit the name of the source file.
|
|
||||||
Sezr.EmitCStr(SourceFile.c_str());
|
|
||||||
Sezr.FlushRecord();
|
|
||||||
|
|
||||||
// Emit the SourceManager.
|
// Emit the SourceManager.
|
||||||
Sezr.Emit(Context->getSourceManager());
|
Sezr.Emit(Context->getSourceManager());
|
||||||
|
|
||||||
|
@ -186,12 +182,6 @@ TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr,
|
||||||
FoundBlock = Dezr.SkipToBlock(BasicMetadataBlock);
|
FoundBlock = Dezr.SkipToBlock(BasicMetadataBlock);
|
||||||
assert (FoundBlock);
|
assert (FoundBlock);
|
||||||
|
|
||||||
{ // Read the SourceFile.
|
|
||||||
char* SName = Dezr.ReadCStr(NULL,0,true);
|
|
||||||
TU->SourceFile = SName;
|
|
||||||
delete [] SName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the SourceManager.
|
// Read the SourceManager.
|
||||||
SourceManager::CreateAndRegister(Dezr,FMgr);
|
SourceManager::CreateAndRegister(Dezr,FMgr);
|
||||||
|
|
||||||
|
|
|
@ -614,10 +614,9 @@ namespace {
|
||||||
TranslationUnit TU;
|
TranslationUnit TU;
|
||||||
const llvm::sys::Path FName;
|
const llvm::sys::Path FName;
|
||||||
public:
|
public:
|
||||||
ASTSerializer(const std::string& SourceFile,
|
ASTSerializer(const llvm::sys::Path& F, Diagnostic &diags,
|
||||||
const llvm::sys::Path& F, Diagnostic &diags,
|
|
||||||
const LangOptions &LO)
|
const LangOptions &LO)
|
||||||
: Diags(diags), TU(SourceFile,LO), FName(F) {}
|
: Diags(diags), TU(LO), FName(F) {}
|
||||||
|
|
||||||
virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
|
virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
|
||||||
TU.setContext(&Context);
|
TU.setContext(&Context);
|
||||||
|
@ -637,7 +636,7 @@ namespace {
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
ASTConsumer* clang::CreateASTSerializer(const std::string& SourceFile,
|
ASTConsumer* clang::CreateASTSerializer(const std::string& InFile,
|
||||||
Diagnostic &Diags,
|
Diagnostic &Diags,
|
||||||
const LangOptions &Features) {
|
const LangOptions &Features) {
|
||||||
// FIXME: If the translation unit we are serializing came was itself
|
// FIXME: If the translation unit we are serializing came was itself
|
||||||
|
@ -646,15 +645,15 @@ ASTConsumer* clang::CreateASTSerializer(const std::string& SourceFile,
|
||||||
// be completely replaced momentarily.
|
// be completely replaced momentarily.
|
||||||
|
|
||||||
// FIXME: This is a hack: "/" separator not portable.
|
// FIXME: This is a hack: "/" separator not portable.
|
||||||
std::string::size_type idx = SourceFile.rfind("/");
|
std::string::size_type idx = InFile.rfind("/");
|
||||||
|
|
||||||
if (idx != std::string::npos && idx == SourceFile.size()-1)
|
if (idx != std::string::npos && idx == InFile.size()-1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
std::string TargetPrefix( idx == std::string::npos ?
|
std::string TargetPrefix( idx == std::string::npos ?
|
||||||
SourceFile : SourceFile.substr(idx+1));
|
InFile : InFile.substr(idx+1));
|
||||||
|
|
||||||
llvm::sys::Path FName = llvm::sys::Path((TargetPrefix + ".ast").c_str());
|
llvm::sys::Path FName = llvm::sys::Path((TargetPrefix + ".ast").c_str());
|
||||||
|
|
||||||
return new ASTSerializer(SourceFile, FName, Diags, Features);
|
return new ASTSerializer(FName, Diags, Features);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,20 +26,30 @@ class FileManager;
|
||||||
struct LangOptions;
|
struct LangOptions;
|
||||||
|
|
||||||
ASTConsumer *CreateASTPrinter(std::ostream* OS = NULL);
|
ASTConsumer *CreateASTPrinter(std::ostream* OS = NULL);
|
||||||
|
|
||||||
ASTConsumer *CreateASTDumper();
|
ASTConsumer *CreateASTDumper();
|
||||||
|
|
||||||
ASTConsumer *CreateASTViewer();
|
ASTConsumer *CreateASTViewer();
|
||||||
|
|
||||||
ASTConsumer *CreateCFGDumper(bool ViewGraphs = false);
|
ASTConsumer *CreateCFGDumper(bool ViewGraphs = false);
|
||||||
|
|
||||||
ASTConsumer *CreateLiveVarAnalyzer();
|
ASTConsumer *CreateLiveVarAnalyzer();
|
||||||
|
|
||||||
ASTConsumer *CreateDeadStoreChecker(Diagnostic &Diags);
|
ASTConsumer *CreateDeadStoreChecker(Diagnostic &Diags);
|
||||||
|
|
||||||
ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
|
ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
|
||||||
|
|
||||||
ASTConsumer *CreateLLVMEmitter(Diagnostic &Diags, const LangOptions &Features);
|
ASTConsumer *CreateLLVMEmitter(Diagnostic &Diags, const LangOptions &Features);
|
||||||
|
|
||||||
ASTConsumer *CreateCodeRewriterTest(Diagnostic &Diags);
|
ASTConsumer *CreateCodeRewriterTest(Diagnostic &Diags);
|
||||||
ASTConsumer *CreateSerializationTest(const std::string& SourceFile,
|
|
||||||
Diagnostic &Diags, FileManager& FMgr,
|
ASTConsumer *CreateSerializationTest(Diagnostic &Diags,
|
||||||
|
FileManager& FMgr,
|
||||||
const LangOptions &LOpts);
|
const LangOptions &LOpts);
|
||||||
|
|
||||||
ASTConsumer *CreateASTSerializer(const std::string& SourceFile,
|
ASTConsumer *CreateASTSerializer(const std::string& InFile,
|
||||||
Diagnostic &Diags, const LangOptions &LOpts);
|
Diagnostic &Diags,
|
||||||
|
const LangOptions &LOpts);
|
||||||
|
|
||||||
} // end clang namespace
|
} // end clang namespace
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,8 @@ class SerializationTest : public ASTConsumer {
|
||||||
Diagnostic &Diags;
|
Diagnostic &Diags;
|
||||||
FileManager &FMgr;
|
FileManager &FMgr;
|
||||||
public:
|
public:
|
||||||
SerializationTest(const std::string& SourceFile, Diagnostic &d,
|
SerializationTest(Diagnostic &d, FileManager& fmgr, const LangOptions& LOpts)
|
||||||
FileManager& fmgr, const LangOptions& LOpts)
|
: TU(LOpts), Diags(d), FMgr(fmgr) {}
|
||||||
: TU(SourceFile, LOpts), Diags(d), FMgr(fmgr) {}
|
|
||||||
|
|
||||||
~SerializationTest();
|
~SerializationTest();
|
||||||
|
|
||||||
|
@ -59,9 +58,10 @@ private:
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
ASTConsumer*
|
ASTConsumer*
|
||||||
clang::CreateSerializationTest(const std::string& SourceFile, Diagnostic &Diags,
|
clang::CreateSerializationTest(Diagnostic &Diags, FileManager& FMgr,
|
||||||
FileManager& FMgr, const LangOptions &LOpts) {
|
const LangOptions &LOpts) {
|
||||||
return new SerializationTest(SourceFile,Diags,FMgr,LOpts);
|
|
||||||
|
return new SerializationTest(Diags,FMgr,LOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -894,7 +894,7 @@ static void ParseFile(Preprocessor &PP, MinimalAction *PA, unsigned MainFileID){
|
||||||
/// CreateASTConsumer - Create the ASTConsumer for the corresponding program
|
/// CreateASTConsumer - Create the ASTConsumer for the corresponding program
|
||||||
/// action. These consumers can operate on both ASTs that are freshly
|
/// action. These consumers can operate on both ASTs that are freshly
|
||||||
/// parsed from source files as well as those deserialized from Bitcode.
|
/// parsed from source files as well as those deserialized from Bitcode.
|
||||||
static ASTConsumer* CreateASTConsumer(const std::string& SourceFile,
|
static ASTConsumer* CreateASTConsumer(const std::string& InFile,
|
||||||
Diagnostic& Diag, FileManager& FileMgr,
|
Diagnostic& Diag, FileManager& FileMgr,
|
||||||
const LangOptions& LangOpts) {
|
const LangOptions& LangOpts) {
|
||||||
switch (ProgAction) {
|
switch (ProgAction) {
|
||||||
|
@ -924,14 +924,14 @@ static ASTConsumer* CreateASTConsumer(const std::string& SourceFile,
|
||||||
return CreateUnitValsChecker(Diag);
|
return CreateUnitValsChecker(Diag);
|
||||||
|
|
||||||
case TestSerialization:
|
case TestSerialization:
|
||||||
return CreateSerializationTest(SourceFile, Diag, FileMgr, LangOpts);
|
return CreateSerializationTest(Diag, FileMgr, LangOpts);
|
||||||
|
|
||||||
case EmitLLVM:
|
case EmitLLVM:
|
||||||
return CreateLLVMEmitter(Diag, LangOpts);
|
return CreateLLVMEmitter(Diag, LangOpts);
|
||||||
|
|
||||||
case SerializeAST:
|
case SerializeAST:
|
||||||
// FIXME: Allow user to tailor where the file is written.
|
// FIXME: Allow user to tailor where the file is written.
|
||||||
return CreateASTSerializer(SourceFile, Diag, LangOpts);
|
return CreateASTSerializer(InFile, Diag, LangOpts);
|
||||||
|
|
||||||
case RewriteTest:
|
case RewriteTest:
|
||||||
return CreateCodeRewriterTest(Diag);
|
return CreateCodeRewriterTest(Diag);
|
||||||
|
@ -941,7 +941,7 @@ static ASTConsumer* CreateASTConsumer(const std::string& SourceFile,
|
||||||
/// ProcessInputFile - Process a single input file with the specified state.
|
/// ProcessInputFile - Process a single input file with the specified state.
|
||||||
///
|
///
|
||||||
static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID,
|
static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID,
|
||||||
const std::string &SourceFile,
|
const std::string &InFile,
|
||||||
TextDiagnostics &OurDiagnosticClient) {
|
TextDiagnostics &OurDiagnosticClient) {
|
||||||
|
|
||||||
ASTConsumer* Consumer = NULL;
|
ASTConsumer* Consumer = NULL;
|
||||||
|
@ -949,7 +949,8 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID,
|
||||||
|
|
||||||
switch (ProgAction) {
|
switch (ProgAction) {
|
||||||
default:
|
default:
|
||||||
Consumer = CreateASTConsumer(SourceFile, PP.getDiagnostics(),
|
Consumer = CreateASTConsumer(InFile,
|
||||||
|
PP.getDiagnostics(),
|
||||||
PP.getFileManager(),
|
PP.getFileManager(),
|
||||||
PP.getLangOptions());
|
PP.getLangOptions());
|
||||||
|
|
||||||
|
@ -957,6 +958,7 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID,
|
||||||
fprintf(stderr, "Unexpected program action!\n");
|
fprintf(stderr, "Unexpected program action!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DumpTokens: { // Token dump mode.
|
case DumpTokens: { // Token dump mode.
|
||||||
|
@ -1012,7 +1014,7 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Stats) {
|
if (Stats) {
|
||||||
fprintf(stderr, "\nSTATISTICS FOR '%s':\n", SourceFile.c_str());
|
fprintf(stderr, "\nSTATISTICS FOR '%s':\n", InFile.c_str());
|
||||||
PP.PrintStats();
|
PP.PrintStats();
|
||||||
PP.getIdentifierTable().PrintStats();
|
PP.getIdentifierTable().PrintStats();
|
||||||
PP.getHeaderSearchInfo().PrintStats();
|
PP.getHeaderSearchInfo().PrintStats();
|
||||||
|
@ -1054,8 +1056,7 @@ static void ProcessSerializedFile(const std::string& InFile, Diagnostic& Diag,
|
||||||
// Observe that we use the source file name stored in the deserialized
|
// Observe that we use the source file name stored in the deserialized
|
||||||
// translation unit, rather than InFile.
|
// translation unit, rather than InFile.
|
||||||
llvm::scoped_ptr<ASTConsumer>
|
llvm::scoped_ptr<ASTConsumer>
|
||||||
Consumer(CreateASTConsumer(TU->getSourceFile(), Diag, FileMgr,
|
Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOpts()));
|
||||||
TU->getLangOpts()));
|
|
||||||
|
|
||||||
if (!Consumer) {
|
if (!Consumer) {
|
||||||
fprintf(stderr, "Unsupported program action with serialized ASTs!\n");
|
fprintf(stderr, "Unsupported program action with serialized ASTs!\n");
|
||||||
|
|
|
@ -31,7 +31,6 @@ class Decl;
|
||||||
class FileEntry;
|
class FileEntry;
|
||||||
|
|
||||||
class TranslationUnit {
|
class TranslationUnit {
|
||||||
std::string SourceFile;
|
|
||||||
LangOptions LangOpts;
|
LangOptions LangOpts;
|
||||||
ASTContext* Context;
|
ASTContext* Context;
|
||||||
std::vector<Decl*> TopLevelDecls;
|
std::vector<Decl*> TopLevelDecls;
|
||||||
|
@ -40,15 +39,14 @@ class TranslationUnit {
|
||||||
explicit TranslationUnit() : Context(NULL) {}
|
explicit TranslationUnit() : Context(NULL) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TranslationUnit(const std::string& sourcefile,
|
explicit TranslationUnit(const LangOptions& lopt)
|
||||||
const LangOptions& lopt)
|
: LangOpts(lopt), Context(NULL) {}
|
||||||
: SourceFile(sourcefile), LangOpts(lopt), Context(NULL) {}
|
|
||||||
|
|
||||||
|
|
||||||
void setContext(ASTContext* context) { Context = context; }
|
void setContext(ASTContext* context) { Context = context; }
|
||||||
ASTContext* getContext() const { return Context; }
|
ASTContext* getContext() const { return Context; }
|
||||||
|
|
||||||
const LangOptions& getLangOpts() const { return LangOpts; }
|
const LangOptions& getLangOpts() const { return LangOpts; }
|
||||||
const std::string& getSourceFile() const { return SourceFile; }
|
const std::string& getSourceFile() const;
|
||||||
|
|
||||||
/// Emit - Emit the translation unit to an arbitray bitcode stream.
|
/// Emit - Emit the translation unit to an arbitray bitcode stream.
|
||||||
void Emit(llvm::Serializer& S) const;
|
void Emit(llvm::Serializer& S) const;
|
||||||
|
|
Loading…
Reference in New Issue