Add PTHLexer::LexEndOfFile() to emit diagnostics at end-of-file similar to those by Lexer::LexEndOfFile().
llvm-svn: 109486
This commit is contained in:
parent
3d625eb2bf
commit
2bd41d1e30
|
@ -50,6 +50,8 @@ class PTHLexer : public PreprocessorLexer {
|
||||||
|
|
||||||
/// ReadToken - Used by PTHLexer to read tokens TokBuf.
|
/// ReadToken - Used by PTHLexer to read tokens TokBuf.
|
||||||
void ReadToken(Token& T);
|
void ReadToken(Token& T);
|
||||||
|
|
||||||
|
bool LexEndOfFile(Token &Result);
|
||||||
|
|
||||||
/// PTHMgr - The PTHManager object that created this PTHLexer.
|
/// PTHMgr - The PTHManager object that created this PTHLexer.
|
||||||
PTHManager& PTHMgr;
|
PTHManager& PTHMgr;
|
||||||
|
|
|
@ -101,16 +101,15 @@ LexNextToken:
|
||||||
// Save the end-of-file token.
|
// Save the end-of-file token.
|
||||||
EofToken = Tok;
|
EofToken = Tok;
|
||||||
|
|
||||||
|
// Save 'PP' to 'PPCache' as LexEndOfFile can delete 'this'.
|
||||||
Preprocessor *PPCache = PP;
|
Preprocessor *PPCache = PP;
|
||||||
|
|
||||||
assert(!ParsingPreprocessorDirective);
|
assert(!ParsingPreprocessorDirective);
|
||||||
assert(!LexingRawMode);
|
assert(!LexingRawMode);
|
||||||
|
|
||||||
// FIXME: Issue diagnostics similar to Lexer.
|
if (LexEndOfFile(Tok))
|
||||||
if (PP->HandleEndOfFile(Tok, false))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(PPCache && "Raw buffer::LexEndOfFile should return a token");
|
|
||||||
return PPCache->Lex(Tok);
|
return PPCache->Lex(Tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +133,28 @@ LexNextToken:
|
||||||
MIOpt.ReadToken();
|
MIOpt.ReadToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PTHLexer::LexEndOfFile(Token &Result) {
|
||||||
|
// 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.
|
||||||
|
if (ParsingPreprocessorDirective) {
|
||||||
|
ParsingPreprocessorDirective = false; // Done parsing the "line".
|
||||||
|
return true; // Have a token.
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(!LexingRawMode);
|
||||||
|
|
||||||
|
// If we are in a #if directive, emit an error.
|
||||||
|
while (!ConditionalStack.empty()) {
|
||||||
|
PP->Diag(ConditionalStack.back().IfLoc,
|
||||||
|
diag::err_pp_unterminated_conditional);
|
||||||
|
ConditionalStack.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, let the preprocessor handle this.
|
||||||
|
return PP->HandleEndOfFile(Result);
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: We can just grab the last token instead of storing a copy
|
// FIXME: We can just grab the last token instead of storing a copy
|
||||||
// into EofToken.
|
// into EofToken.
|
||||||
void PTHLexer::getEOF(Token& Tok) {
|
void PTHLexer::getEOF(Token& Tok) {
|
||||||
|
|
Loading…
Reference in New Issue