/// Diag - Forwarding function for diagnostics. This translate a source
/// position in the current buffer into a SourceLocation object for rendering.
DiagnosticBuilder Lexer::Diag(const char *Loc, unsigned DiagID) const {
- if (LexingRawMode && Diagnostic::isBuiltinNoteWarningOrExtension(DiagID))
- return DiagnosticBuilder();
return PP->Diag(getSourceLocation(Loc), DiagID);
}
if (!Res || !L) return Res;
if (!L->getFeatures().Trigraphs) {
- L->Diag(CP-2, diag::trigraph_ignored);
+ if (!L->isLexingRawMode())
+ L->Diag(CP-2, diag::trigraph_ignored);
return 0;
}
- L->Diag(CP-2, diag::trigraph_converted) << std::string()+Res;
+ if (!L->isLexingRawMode())
+ L->Diag(CP-2, diag::trigraph_converted) << std::string()+Res;
return Res;
}
if (Tok) Tok->setFlag(Token::NeedsCleaning);
// Warn if there was whitespace between the backslash and newline.
- if (SizeTmp != 1 && Tok)
+ if (SizeTmp != 1 && Tok && !isLexingRawMode())
Diag(Ptr, diag::backslash_newline_space);
// If this is a \r\n or \n\r, skip the newlines.
if (!Features.DollarIdents) goto FinishIdentifier;
// Otherwise, emit a diagnostic and continue.
- Diag(CurPtr, diag::ext_dollar_in_identifier);
+ if (!isLexingRawMode())
+ Diag(CurPtr, diag::ext_dollar_in_identifier);
CurPtr = ConsumeChar(CurPtr, Size, Result);
C = getCharAndSize(CurPtr, Size);
continue;
C = getAndAdvanceChar(CurPtr, Result);
} else if (C == '\n' || C == '\r' || // Newline.
(C == 0 && CurPtr-1 == BufferEnd)) { // End of file.
- if (!LexingRawMode) Diag(BufferPtr, diag::err_unterminated_string);
+ if (!isLexingRawMode())
+ Diag(BufferPtr, diag::err_unterminated_string);
FormTokenWithChars(Result, CurPtr-1, tok::unknown);
return;
} else if (C == 0) {
}
// If a nul character existed in the string, warn about it.
- if (NulCharacter) Diag(NulCharacter, diag::null_in_string);
+ if (NulCharacter && !isLexingRawMode())
+ Diag(NulCharacter, diag::null_in_string);
// Update the location of the token as well as the BufferPtr instance var.
FormTokenWithChars(Result, CurPtr,
C = getAndAdvanceChar(CurPtr, Result);
} else if (C == '\n' || C == '\r' || // Newline.
(C == 0 && CurPtr-1 == BufferEnd)) { // End of file.
- if (!LexingRawMode) Diag(BufferPtr, diag::err_unterminated_string);
+ if (!isLexingRawMode())
+ Diag(BufferPtr, diag::err_unterminated_string);
FormTokenWithChars(Result, CurPtr-1, tok::unknown);
return;
} else if (C == 0) {
}
// If a nul character existed in the string, warn about it.
- if (NulCharacter) Diag(NulCharacter, diag::null_in_string);
+ if (NulCharacter && !isLexingRawMode())
+ Diag(NulCharacter, diag::null_in_string);
// Update the location of token as well as BufferPtr.
FormTokenWithChars(Result, CurPtr, tok::angle_string_literal);
// Handle the common case of 'x' and '\y' efficiently.
char C = getAndAdvanceChar(CurPtr, Result);
if (C == '\'') {
- if (!LexingRawMode) Diag(BufferPtr, diag::err_empty_character);
+ if (!isLexingRawMode())
+ Diag(BufferPtr, diag::err_empty_character);
FormTokenWithChars(Result, CurPtr, tok::unknown);
return;
} else if (C == '\\') {
C = getAndAdvanceChar(CurPtr, Result);
} else if (C == '\n' || C == '\r' || // Newline.
(C == 0 && CurPtr-1 == BufferEnd)) { // End of file.
- if (!LexingRawMode) Diag(BufferPtr, diag::err_unterminated_char);
+ if (!isLexingRawMode())
+ Diag(BufferPtr, diag::err_unterminated_char);
FormTokenWithChars(Result, CurPtr-1, tok::unknown);
return;
} else if (C == 0) {
} while (C != '\'');
}
- if (NulCharacter) Diag(NulCharacter, diag::null_in_char);
+ if (NulCharacter && !isLexingRawMode())
+ Diag(NulCharacter, diag::null_in_char);
// Update the location of token as well as BufferPtr.
FormTokenWithChars(Result, CurPtr, tok::char_constant);
bool Lexer::SkipBCPLComment(Token &Result, const char *CurPtr) {
// If BCPL comments aren't explicitly enabled for this language, emit an
// extension warning.
- if (!Features.BCPLComment) {
+ if (!Features.BCPLComment && !isLexingRawMode()) {
Diag(BufferPtr, diag::ext_bcpl_comment);
// Mark them enabled so we only emit one warning for this translation
break;
}
- Diag(OldPtr-1, diag::ext_multi_line_bcpl_comment);
+ if (!isLexingRawMode())
+ Diag(OldPtr-1, diag::ext_multi_line_bcpl_comment);
break;
}
}
// If no trigraphs are enabled, warn that we ignored this trigraph and
// ignore this * character.
if (!L->getFeatures().Trigraphs) {
- L->Diag(CurPtr, diag::trigraph_ignored_block_comment);
+ if (!L->isLexingRawMode())
+ L->Diag(CurPtr, diag::trigraph_ignored_block_comment);
return false;
}
- L->Diag(CurPtr, diag::trigraph_ends_block_comment);
+ if (!L->isLexingRawMode())
+ L->Diag(CurPtr, diag::trigraph_ends_block_comment);
}
// Warn about having an escaped newline between the */ characters.
- L->Diag(CurPtr, diag::escaped_newline_block_comment_end);
+ if (!L->isLexingRawMode())
+ L->Diag(CurPtr, diag::escaped_newline_block_comment_end);
// If there was space between the backslash and newline, warn about it.
- if (HasSpace) L->Diag(CurPtr, diag::backslash_newline_space);
+ if (HasSpace && !L->isLexingRawMode())
+ L->Diag(CurPtr, diag::backslash_newline_space);
return true;
}
unsigned char C = getCharAndSize(CurPtr, CharSize);
CurPtr += CharSize;
if (C == 0 && CurPtr == BufferEnd+1) {
- if (!LexingRawMode)
+ if (!isLexingRawMode())
Diag(BufferPtr, diag::err_unterminated_block_comment);
--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::warn_nested_block_comment);
+ if (!isLexingRawMode())
+ Diag(CurPtr-1, diag::warn_nested_block_comment);
}
} else if (C == 0 && CurPtr == BufferEnd+1) {
- if (!LexingRawMode) Diag(BufferPtr, diag::err_unterminated_block_comment);
+ if (!isLexingRawMode())
+ 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.
// If we are in raw mode, return this event as an EOF token. Let the caller
// that put us in raw mode handle the event.
- if (LexingRawMode) {
+ if (isLexingRawMode()) {
Result.startToken();
BufferPtr = BufferEnd;
FormTokenWithChars(Result, BufferEnd, tok::eof);
return PPCache->Lex(Result);
}
- Diag(CurPtr-1, diag::null_in_file);
+ if (!isLexingRawMode())
+ Diag(CurPtr-1, diag::null_in_file);
Result.setFlag(Token::LeadingSpace);
if (SkipWhitespace(Result, CurPtr))
return; // KeepWhitespaceMode
case '$': // $ in identifiers.
if (Features.DollarIdents) {
- Diag(CurPtr-1, diag::ext_dollar_in_identifier);
+ if (!isLexingRawMode())
+ Diag(CurPtr-1, diag::ext_dollar_in_identifier);
// Notify MIOpt that we read a non-whitespace/non-comment token.
MIOpt.ReadToken();
return LexIdentifier(Result, CurPtr);
SizeTmp2, Result);
} else if (Char == '@' && Features.Microsoft) { // %:@ -> #@ -> Charize
CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
- Diag(BufferPtr, diag::charize_microsoft_ext);
+ if (!isLexingRawMode())
+ Diag(BufferPtr, diag::charize_microsoft_ext);
Kind = tok::hashat;
} else {
Kind = tok::hash; // '%:' -> '#'
CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
} else if (Char == '@' && Features.Microsoft) { // #@ -> Charize
Kind = tok::hashat;
- Diag(BufferPtr, diag::charize_microsoft_ext);
+ if (!isLexingRawMode())
+ Diag(BufferPtr, diag::charize_microsoft_ext);
CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
} else {
Kind = tok::hash;