[cfe-commits] r40104 - in /cfe/trunk: Driver/TextDiagnosticPrinter.cpp Lex/Lexer.cpp Lex/MacroExpander.cpp Lex/Pragma.cpp Lex/Preprocessor.cpp include/clang/Lex/Lexer.h
Chris Lattner
sabre at nondot.org
Fri Jul 20 09:52:04 PDT 2007
Author: lattner
Date: Fri Jul 20 11:52:03 2007
New Revision: 40104
URL: http://llvm.org/viewvc/llvm-project?rev=40104&view=rev
Log:
simplify the lexer ctor to take a SLoc instead of a sloc and a redundant buffer*.
Modified:
cfe/trunk/Driver/TextDiagnosticPrinter.cpp
cfe/trunk/Lex/Lexer.cpp
cfe/trunk/Lex/MacroExpander.cpp
cfe/trunk/Lex/Pragma.cpp
cfe/trunk/Lex/Preprocessor.cpp
cfe/trunk/include/clang/Lex/Lexer.h
Modified: cfe/trunk/Driver/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.cpp?rev=40104&r1=40103&r2=40104&view=diff
==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.cpp Fri Jul 20 11:52:03 2007
@@ -108,15 +108,11 @@
// 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();
}
Modified: cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Lexer.cpp?rev=40104&r1=40103&r2=40104&view=diff
==============================================================================
--- cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/trunk/Lex/Lexer.cpp Fri Jul 20 11:52:03 2007
@@ -34,20 +34,24 @@
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;
Modified: cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/MacroExpander.cpp?rev=40104&r1=40103&r2=40104&view=diff
==============================================================================
--- cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/trunk/Lex/MacroExpander.cpp Fri Jul 20 11:52:03 2007
@@ -578,13 +578,8 @@
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
Modified: cfe/trunk/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Pragma.cpp?rev=40104&r1=40103&r2=40104&view=diff
==============================================================================
--- cfe/trunk/Lex/Pragma.cpp (original)
+++ cfe/trunk/Lex/Pragma.cpp Fri Jul 20 11:52:03 2007
@@ -140,12 +140,9 @@
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
Modified: cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Preprocessor.cpp?rev=40104&r1=40103&r2=40104&view=diff
==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Fri Jul 20 11:52:03 2007
@@ -281,8 +281,7 @@
// 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 @@
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);
}
Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=40104&r1=40103&r2=40104&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Fri Jul 20 11:52:03 2007
@@ -36,7 +36,7 @@
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 @@
/// 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!
More information about the cfe-commits
mailing list