aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Driver/TextDiagnosticPrinter.cpp6
-rw-r--r--Lex/Lexer.cpp18
-rw-r--r--Lex/MacroExpander.cpp7
-rw-r--r--Lex/Pragma.cpp5
-rw-r--r--Lex/Preprocessor.cpp7
-rw-r--r--include/clang/Lex/Lexer.h12
6 files changed, 23 insertions, 32 deletions
diff --git a/Driver/TextDiagnosticPrinter.cpp b/Driver/TextDiagnosticPrinter.cpp
index f37732c241..87f33741b0 100644
--- a/Driver/TextDiagnosticPrinter.cpp
+++ b/Driver/TextDiagnosticPrinter.cpp
@@ -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();
}
diff --git a/Lex/Lexer.cpp b/Lex/Lexer.cpp
index a1db060c3e..4efd62113d 100644
--- a/Lex/Lexer.cpp
+++ b/Lex/Lexer.cpp
@@ -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;
diff --git a/Lex/MacroExpander.cpp b/Lex/MacroExpander.cpp
index 9a80ac3c3f..53ff3f14ca 100644
--- a/Lex/MacroExpander.cpp
+++ b/Lex/MacroExpander.cpp
@@ -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
diff --git a/Lex/Pragma.cpp b/Lex/Pragma.cpp
index 596b7e76e4..d717d040a5 100644
--- a/Lex/Pragma.cpp
+++ b/Lex/Pragma.cpp
@@ -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
diff --git a/Lex/Preprocessor.cpp b/Lex/Preprocessor.cpp
index c3fd554264..59ade23f5c 100644
--- a/Lex/Preprocessor.cpp
+++ b/Lex/Preprocessor.cpp
@@ -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);
}
diff --git a/include/clang/Lex/Lexer.h b/include/clang/Lex/Lexer.h
index 268231c0ea..5b797bb7df 100644
--- a/include/clang/Lex/Lexer.h
+++ b/include/clang/Lex/Lexer.h
@@ -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!