// 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();
}
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;
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
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
// 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;
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);
}
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.
/// 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!