mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-14 03:29:57 +00:00
Move LexingRawMode handling of file EOF out of the preprocessor into the
lexer. This makes more logical sense and also unbreaks the case when the lexer hasn't been pushed onto the PP include stack. This is the case when pasting identifiers. This patch implements macro_paste_bcpl_comment.c. llvm-svn: 38736
This commit is contained in:
parent
ab30c0360d
commit
30a2fa14ae
@ -904,23 +904,32 @@ bool Lexer::LexEndOfFile(LexerToken &Result, const char *CurPtr) {
|
||||
return true; // Have a token.
|
||||
}
|
||||
|
||||
// If we aren't in raw mode, issue diagnostics. If we are in raw mode, let the
|
||||
// code that put us into raw mode do this: there are multiple possible reasons
|
||||
// for raw mode, and not all want these diagnostics.
|
||||
if (!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();
|
||||
}
|
||||
|
||||
// If the file was empty or didn't end in a newline, issue a pedwarn.
|
||||
if (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')
|
||||
Diag(BufferEnd, diag::ext_no_newline_eof);
|
||||
// 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) {
|
||||
Result.StartToken();
|
||||
BufferPtr = BufferEnd;
|
||||
FormTokenWithChars(Result, BufferEnd);
|
||||
Result.SetKind(tok::eof);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, issue diagnostics for unterminated #if and missing newline.
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
// If the file was empty or didn't end in a newline, issue a pedwarn.
|
||||
if (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')
|
||||
Diag(BufferEnd, diag::ext_no_newline_eof);
|
||||
|
||||
BufferPtr = CurPtr;
|
||||
|
||||
// Finally, let the preprocessor handle this.
|
||||
return PP.HandleEndOfFile(Result);
|
||||
}
|
||||
|
||||
|
@ -1009,19 +1009,6 @@ bool Preprocessor::HandleEndOfFile(LexerToken &Result, bool isEndOfMacro) {
|
||||
assert(!CurMacroExpander &&
|
||||
"Ending a file when currently in a macro!");
|
||||
|
||||
// If we are in a #if 0 block skipping tokens, and we see the end of the file,
|
||||
// this is an error condition. Just return the EOF token up to
|
||||
// SkipExcludedConditionalBlock. The code that enabled skipping will issue
|
||||
// errors for the unterminated #if's on the conditional stack if it is
|
||||
// interested.
|
||||
if (isSkipping()) {
|
||||
Result.StartToken();
|
||||
CurLexer->BufferPtr = CurLexer->BufferEnd;
|
||||
CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd);
|
||||
Result.SetKind(tok::eof);
|
||||
return true;
|
||||
}
|
||||
|
||||
// See if this file had a controlling macro.
|
||||
if (CurLexer) { // Not ending a macro, ignore it.
|
||||
if (const IdentifierInfo *ControllingMacro =
|
||||
|
5
clang/test/Preprocessor/macro_paste_bcpl_comment.c
Normal file
5
clang/test/Preprocessor/macro_paste_bcpl_comment.c
Normal file
@ -0,0 +1,5 @@
|
||||
// RUN: clang %s -Eonly 2>&1 | grep error
|
||||
|
||||
#define COMM1 / ## /
|
||||
COMM1
|
||||
|
Loading…
Reference in New Issue
Block a user