simplify the lexer ctor to take a SLoc instead of a sloc and a redundant buffer*.
llvm-svn: 40104
This commit is contained in:
parent
dc5c055fd1
commit
77e9de50a1
|
@ -108,15 +108,11 @@ unsigned TextDiagnosticPrinter::GetTokenLength(SourceLocation Loc) {
|
|||
// TODO: this could be special cased for common tokens like identifiers, ')',
|
||||
// etc to make this faster, if it mattered. This could use
|
||||
// Lexer::isObviouslySimpleCharacter for example.
|
||||
unsigned FileID = Loc.getFileID();
|
||||
|
||||
// Create a lexer starting at the beginning of this token.
|
||||
Lexer TheLexer(SourceMgr.getBuffer(FileID), Loc,
|
||||
*ThePreprocessor, StrData);
|
||||
|
||||
Lexer TheLexer(Loc, *ThePreprocessor, StrData);
|
||||
LexerToken TheTok;
|
||||
TheLexer.LexRawToken(TheTok);
|
||||
|
||||
return TheTok.getLength();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,20 +34,24 @@ using namespace clang;
|
|||
|
||||
static void InitCharacterInfo();
|
||||
|
||||
Lexer::Lexer(const llvm::MemoryBuffer *File, SourceLocation fileloc,
|
||||
Preprocessor &pp, const char *BufStart, const char *BufEnd)
|
||||
: BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()),
|
||||
InputFile(File), FileLoc(fileloc), PP(pp), Features(PP.getLangOptions()) {
|
||||
Lexer::Lexer(SourceLocation fileloc, Preprocessor &pp,
|
||||
const char *BufStart, const char *BufEnd)
|
||||
: FileLoc(fileloc), PP(pp), Features(PP.getLangOptions()) {
|
||||
|
||||
SourceManager &SourceMgr = PP.getSourceManager();
|
||||
InputFile =SourceMgr.getBuffer(SourceMgr.getPhysicalLoc(FileLoc).getFileID());
|
||||
|
||||
Is_PragmaLexer = false;
|
||||
IsMainFile = false;
|
||||
InitCharacterInfo();
|
||||
|
||||
BufferPtr = BufStart ? BufStart : InputFile->getBufferStart();
|
||||
BufferEnd = BufEnd ? BufEnd : InputFile->getBufferEnd();
|
||||
|
||||
assert(BufferEnd[0] == 0 &&
|
||||
"We assume that the input buffer has a null character at the end"
|
||||
" to simplify lexing!");
|
||||
|
||||
BufferPtr = BufStart ? BufStart : File->getBufferStart();
|
||||
|
||||
|
||||
// Start of the file is a start of line.
|
||||
IsAtStartOfLine = true;
|
||||
|
||||
|
|
|
@ -578,13 +578,8 @@ void MacroExpander::PasteTokens(LexerToken &Tok) {
|
|||
SourceManager &SourceMgr = PP.getSourceManager();
|
||||
const char *ResultStrData = SourceMgr.getCharacterData(ResultTokLoc);
|
||||
|
||||
unsigned FileID = ResultTokLoc.getFileID();
|
||||
assert(FileID && "Could not get FileID for paste?");
|
||||
|
||||
// Make a lexer object so that we lex and expand the paste result.
|
||||
Lexer *TL = new Lexer(SourceMgr.getBuffer(FileID),
|
||||
SourceLocation::getFileLoc(FileID, 0), PP,
|
||||
ResultStrData,
|
||||
Lexer *TL = new Lexer(ResultTokLoc, PP, ResultStrData,
|
||||
ResultStrData+LHSLen+RHSLen /*don't include null*/);
|
||||
|
||||
// Lex a token in raw mode. This way it won't look up identifiers
|
||||
|
|
|
@ -140,12 +140,9 @@ void Preprocessor::Handle_Pragma(LexerToken &Tok) {
|
|||
SourceLocation TokLoc = CreateString(&StrVal[0], StrVal.size(), StrLoc);
|
||||
const char *StrData = SourceMgr.getCharacterData(TokLoc);
|
||||
|
||||
unsigned FileID = SourceMgr.getPhysicalLoc(TokLoc).getFileID();
|
||||
assert(FileID && "Could not get FileID for _Pragma?");
|
||||
|
||||
// Make and enter a lexer object so that we lex and expand the tokens just
|
||||
// like any others.
|
||||
Lexer *TL = new Lexer(SourceMgr.getBuffer(FileID), TokLoc, *this,
|
||||
Lexer *TL = new Lexer(TokLoc, *this,
|
||||
StrData, StrData+StrVal.size()-1 /* no null */);
|
||||
|
||||
// Ensure that the lexer thinks it is inside a directive, so that end \n will
|
||||
|
|
|
@ -281,8 +281,7 @@ SourceLocation Preprocessor::AdvanceToTokenCharacter(SourceLocation TokStart,
|
|||
// lexer to parse it correctly.
|
||||
if (CharNo != 0) {
|
||||
// Create a lexer starting at this token position.
|
||||
const llvm::MemoryBuffer *SrcBuf =SourceMgr.getBuffer(TokStart.getFileID());
|
||||
Lexer TheLexer(SrcBuf, TokStart, *this, TokPtr);
|
||||
Lexer TheLexer(TokStart, *this, TokPtr);
|
||||
LexerToken Tok;
|
||||
// Skip over characters the remaining characters.
|
||||
const char *TokStartPtr = TokPtr;
|
||||
|
@ -390,9 +389,7 @@ void Preprocessor::EnterSourceFile(unsigned FileID,
|
|||
if (MaxIncludeStackDepth < IncludeMacroStack.size())
|
||||
MaxIncludeStackDepth = IncludeMacroStack.size();
|
||||
|
||||
const llvm::MemoryBuffer *Buffer = SourceMgr.getBuffer(FileID);
|
||||
Lexer *TheLexer = new Lexer(Buffer, SourceLocation::getFileLoc(FileID, 0),
|
||||
*this);
|
||||
Lexer *TheLexer = new Lexer(SourceLocation::getFileLoc(FileID, 0), *this);
|
||||
if (isMainFile) TheLexer->setIsMainFile();
|
||||
EnterSourceFileWithLexer(TheLexer, CurDir);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class Preprocessor;
|
|||
class Lexer {
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Constant configuration values for this lexer.
|
||||
const char * const BufferEnd; // End of the buffer.
|
||||
const char *BufferEnd; // End of the buffer.
|
||||
const llvm::MemoryBuffer *InputFile; // The file we are reading from.
|
||||
SourceLocation FileLoc; // Location for start of file.
|
||||
Preprocessor &PP; // Preprocessor object controlling lexing.
|
||||
|
@ -93,15 +93,17 @@ class Lexer {
|
|||
/// we are currently in.
|
||||
std::vector<PPConditionalInfo> ConditionalStack;
|
||||
|
||||
Lexer(const Lexer&); // DO NOT IMPLEMENT
|
||||
void operator=(const Lexer&); // DO NOT IMPLEMENT
|
||||
friend class Preprocessor;
|
||||
public:
|
||||
|
||||
/// Lexer constructor - Create a new lexer object for the specified buffer
|
||||
/// with the specified preprocessor managing the lexing process. This lexer
|
||||
/// assumes that the specified MemoryBuffer and Preprocessor objects will
|
||||
/// outlive it, but doesn't take ownership of either pointer.
|
||||
Lexer(const llvm::MemoryBuffer *InBuffer, SourceLocation FileLoc,
|
||||
Preprocessor &PP, const char *BufStart = 0, const char *BufEnd = 0);
|
||||
/// assumes that the associated MemoryBuffer and Preprocessor objects will
|
||||
/// outlive it, so it doesn't take ownership of either of them.
|
||||
Lexer(SourceLocation FileLoc, Preprocessor &PP,
|
||||
const char *BufStart = 0, const char *BufEnd = 0);
|
||||
|
||||
/// getFeatures - Return the language features currently enabled. NOTE: this
|
||||
/// lexer modifies features as a file is parsed!
|
||||
|
|
Loading…
Reference in New Issue