diff options
Diffstat (limited to 'lib/Lex')
-rw-r--r-- | lib/Lex/PTHLexer.cpp | 27 | ||||
-rw-r--r-- | lib/Lex/PreprocessorLexer.cpp | 5 |
2 files changed, 16 insertions, 16 deletions
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index 5adcd9f6a1..936a03ac0f 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -17,21 +17,19 @@ using namespace clang; PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc, - const Token *TokArray, unsigned NumToks) - : PreprocessorLexer(&pp, fileloc), FileLoc(fileloc), - Tokens(TokArray), NumTokens(NumToks), CurToken(0) { + const Token *TokArray, unsigned NumTokens) + : PreprocessorLexer(&pp, fileloc), + Tokens(TokArray), + LastToken(NumTokens - 1), + CurToken(0) { - assert (Tokens[NumTokens-1].is(tok::eof)); - --NumTokens; - - LexingRawMode = false; - ParsingPreprocessorDirective = false; - ParsingFilename = false; + assert (NumTokens >= 1); + assert (Tokens[LastToken].is(tok::eof)); } void PTHLexer::Lex(Token& Tok) { - if (CurToken == NumTokens) { + if (CurToken == LastToken) { // If we hit the end of the file while parsing a preprocessor directive, // end the preprocessor directive first. The next token returned will // then be the end of file. @@ -73,8 +71,7 @@ void PTHLexer::Lex(Token& Tok) { } void PTHLexer::setEOF(Token& Tok) { - Tok = Tokens[NumTokens]; // NumTokens is already adjusted, so this isn't - // an overflow. + Tok = Tokens[LastToken]; } void PTHLexer::DiscardToEndOfLine() { @@ -82,17 +79,17 @@ void PTHLexer::DiscardToEndOfLine() { "Must be in a preprocessing directive!"); // Already at end-of-file? - if (CurToken == NumTokens) + if (CurToken == LastToken) return; // Find the first token that is not the start of the *current* line. - for ( ++CurToken; CurToken != NumTokens ; ++CurToken ) + for ( ++CurToken; CurToken != LastToken ; ++CurToken ) if (Tokens[CurToken].isAtStartOfLine()) return; } unsigned PTHLexer::isNextPPTokenLParen() { - if (CurToken == NumTokens) + if (CurToken == LastToken) return 2; return Tokens[CurToken].is(tok::l_paren); diff --git a/lib/Lex/PreprocessorLexer.cpp b/lib/Lex/PreprocessorLexer.cpp index 2ce181ef83..1916f298db 100644 --- a/lib/Lex/PreprocessorLexer.cpp +++ b/lib/Lex/PreprocessorLexer.cpp @@ -19,7 +19,10 @@ using namespace clang; PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L) - : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()) {} + : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()), + ParsingPreprocessorDirective(false), + ParsingFilename(false), + LexingRawMode(false) {} PreprocessorLexer::~PreprocessorLexer() {} |