forked from OSchip/llvm-project
Added methods createMainFileID() and createMainFileIDForMemBuffer() to
SourceManager to allow SourceManager to directly intern the MainFileID when it is created. Removed setMainFileID(). llvm-svn: 45231
This commit is contained in:
parent
e2a8ba7fec
commit
96e05d4f31
|
@ -530,19 +530,18 @@ static unsigned InitializePreprocessor(Preprocessor &PP,
|
|||
FileManager &FileMgr = PP.getFileManager();
|
||||
|
||||
// Figure out where to get and map in the main file.
|
||||
unsigned MainFileID = 0;
|
||||
SourceManager &SourceMgr = PP.getSourceManager();
|
||||
if (InFile != "-") {
|
||||
const FileEntry *File = FileMgr.getFile(InFile);
|
||||
if (File) MainFileID = SourceMgr.createFileID(File, SourceLocation());
|
||||
if (MainFileID == 0) {
|
||||
if (File) SourceMgr.createMainFileID(File, SourceLocation());
|
||||
if (SourceMgr.getMainFileID() == 0) {
|
||||
fprintf(stderr, "Error reading '%s'!\n",InFile.c_str());
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
|
||||
if (SB) MainFileID = SourceMgr.createFileIDForMemBuffer(SB);
|
||||
if (MainFileID == 0) {
|
||||
if (SB) SourceMgr.createMainFileIDForMemBuffer(SB);
|
||||
if (SourceMgr.getMainFileID() == 0) {
|
||||
fprintf(stderr, "Error reading standard input! Empty?\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -562,10 +561,8 @@ static unsigned InitializePreprocessor(Preprocessor &PP,
|
|||
PP.setPredefines(&PredefineBuffer[0]);
|
||||
|
||||
// Once we've read this, we're done.
|
||||
return MainFileID;
|
||||
return SourceMgr.getMainFileID();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Preprocessor include path information.
|
||||
|
@ -931,7 +928,7 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
|
|||
|
||||
case SerializeAST:
|
||||
// FIXME: Allow user to tailor where the file is written.
|
||||
return CreateASTSerializer(InFile, Diag, LangOpts);
|
||||
return CreateASTSerializer(InFile, OutputFile, Diag, LangOpts);
|
||||
|
||||
case RewriteTest:
|
||||
return CreateCodeRewriterTest(Diag);
|
||||
|
@ -1170,15 +1167,10 @@ int main(int argc, char **argv) {
|
|||
Preprocessor PP(Diags, LangInfo, *Target, SourceMgr, HeaderInfo);
|
||||
|
||||
std::vector<char> PredefineBuffer;
|
||||
unsigned MainFileID = InitializePreprocessor(PP, InFile, PredefineBuffer);
|
||||
|
||||
if (!MainFileID)
|
||||
if (!InitializePreprocessor(PP, InFile, PredefineBuffer))
|
||||
continue;
|
||||
|
||||
SourceMgr.setMainFileID(MainFileID);
|
||||
|
||||
ProcessInputFile(PP, InFile, *DiagClient);
|
||||
|
||||
ProcessInputFile(PP, InFile, *DiagClient);
|
||||
HeaderInfo.ClearFileInfo();
|
||||
|
||||
if (Stats)
|
||||
|
|
|
@ -237,9 +237,6 @@ public:
|
|||
/// getMainFileID - Returns the FileID of the main source file.
|
||||
unsigned getMainFileID() const { return MainFileID; }
|
||||
|
||||
/// setMainFileID - Set the FileID of the main source file.
|
||||
void setMainFileID(unsigned ID) { MainFileID = ID; }
|
||||
|
||||
/// createFileID - Create a new FileID that represents the specified file
|
||||
/// being #included from the specified IncludePosition. This returns 0 on
|
||||
/// error and translates NULL into standard input.
|
||||
|
@ -249,6 +246,15 @@ public:
|
|||
return createFileID(IR, IncludePos);
|
||||
}
|
||||
|
||||
/// createMainFileID - Create the FileID for the main source file.
|
||||
unsigned createMainFileID(const FileEntry *SourceFile,
|
||||
SourceLocation IncludePos) {
|
||||
|
||||
assert (MainFileID == 0 && "MainFileID already set!");
|
||||
MainFileID = createFileID(SourceFile,IncludePos);
|
||||
return MainFileID;
|
||||
}
|
||||
|
||||
/// createFileIDForMemBuffer - Create a new FileID that represents the
|
||||
/// specified memory buffer. This does no caching of the buffer and takes
|
||||
/// ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once.
|
||||
|
@ -256,6 +262,15 @@ public:
|
|||
return createFileID(createMemBufferContentCache(Buffer), SourceLocation());
|
||||
}
|
||||
|
||||
/// createMainFileIDForMembuffer - Create the FileID for a memory buffer
|
||||
/// that will represent the FileID for the main source. One example
|
||||
/// of when this would be used is when the main source is read from STDIN.
|
||||
unsigned createMainFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) {
|
||||
assert (MainFileID == 0 && "MainFileID already set!");
|
||||
MainFileID = createMainFileIDForMemBuffer(Buffer);
|
||||
return MainFileID;
|
||||
}
|
||||
|
||||
/// getInstantiationLoc - Return a new SourceLocation that encodes the fact
|
||||
/// that a token at Loc should actually be referenced from InstantiationLoc.
|
||||
SourceLocation getInstantiationLoc(SourceLocation Loc,
|
||||
|
|
Loading…
Reference in New Issue