Simplify raw mode lexing by treating an unterminate /**/ comment the

same we we do an unterminated string or character literal.  This makes
it so we can guarantee that the lexer never calls into the 
preprocessor (which would be suicide for a raw lexer).

llvm-svn: 57395
This commit is contained in:
Chris Lattner 2008-10-12 01:31:51 +00:00
parent 6b0c5ad096
commit 7c2e9809b1
4 changed files with 8 additions and 12 deletions

View File

@ -32,7 +32,7 @@ DIAG(null_in_char , WARNING,
"null character(s) preserved in character literal")
DIAG(null_in_file , WARNING,
"null character ignored")
DIAG(nested_block_comment, WARNING,
DIAG(warn_nested_block_comment, WARNING,
"\"/*\" within block comment")
DIAG(escaped_newline_block_comment_end, WARNING,
"escaped newline between */ characters at block comment end")

View File

@ -60,9 +60,8 @@ class Lexer {
/// effect of this, implicit macro expansion is naturally disabled.
/// 3. "#" tokens at the start of a line are treated as normal tokens, not
/// implicitly transformed by the lexer.
/// 4. All diagnostic messages are disabled, except for unterminated /*.
/// 5. The only callback made into the preprocessor is to report a hard error
/// on an unterminated '/*' comment.
/// 4. All diagnostic messages are disabled.
/// 5. No callbacks are made into the preprocessor.
///
/// Note that in raw mode that the PP pointer may be null.
bool LexingRawMode;

View File

@ -931,7 +931,8 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) {
unsigned char C = getCharAndSize(CurPtr, CharSize);
CurPtr += CharSize;
if (C == 0 && CurPtr == BufferEnd+1) {
Diag(BufferPtr, diag::err_unterminated_block_comment);
if (!LexingRawMode)
Diag(BufferPtr, diag::err_unterminated_block_comment);
BufferPtr = CurPtr-1;
return true;
}
@ -1000,10 +1001,10 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) {
// If this is a /* inside of the comment, emit a warning. Don't do this
// if this is a /*/, which will end the comment. This misses cases with
// embedded escaped newlines, but oh well.
Diag(CurPtr-1, diag::nested_block_comment);
Diag(CurPtr-1, diag::warn_nested_block_comment);
}
} else if (C == 0 && CurPtr == BufferEnd+1) {
Diag(BufferPtr, diag::err_unterminated_block_comment);
if (!LexingRawMode) Diag(BufferPtr, diag::err_unterminated_block_comment);
// Note: the user probably forgot a */. We could continue immediately
// after the /*, but this would involve lexing a lot of what really is the
// comment, which surely would confuse the parser.

View File

@ -377,11 +377,7 @@ bool TokenLexer::PasteTokens(Token &Tok) {
// Lex the resultant pasted token into Result.
Token Result;
// Avoid testing /*, as the lexer would think it is the start of a comment
// and emit an error that it is unterminated.
if (Tok.is(tok::slash) && RHS.is(tok::star)) {
isInvalid = true;
} else if (Tok.is(tok::identifier) && RHS.is(tok::identifier)) {
if (Tok.is(tok::identifier) && RHS.is(tok::identifier)) {
// Common paste case: identifier+identifier = identifier. Avoid creating
// a lexer and other overhead.
PP.IncrementPasteCounter(true);