aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/TokenConcatenation.cpp
diff options
context:
space:
mode:
authoryronglin <yronglin777@gmail.com>2024-07-20 20:41:00 +0800
committerGitHub <noreply@github.com>2024-07-20 20:41:00 +0800
commite77a01d79a48e15c94c89e4aa4bd27424a96b49b (patch)
treede9dcfce36f2d950bd058ac191222595bf8ffa9a /clang/lib/Lex/TokenConcatenation.cpp
parent710dab6e18ad9ed22c2529b9125d7b8813165ede (diff)
downloadllvm-e77a01d79a48e15c94c89e4aa4bd27424a96b49b.zip
llvm-e77a01d79a48e15c94c89e4aa4bd27424a96b49b.tar.gz
llvm-e77a01d79a48e15c94c89e4aa4bd27424a96b49b.tar.bz2
[Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (#90574)
This PR implement [P3034R1 Module Declarations Shouldn’t be Macros](https://wg21.link/P3034R1), and refactor the convoluted state machines in module name lexical analysis. --------- Signed-off-by: yronglin <yronglin777@gmail.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com>
Diffstat (limited to 'clang/lib/Lex/TokenConcatenation.cpp')
-rw-r--r--clang/lib/Lex/TokenConcatenation.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Lex/TokenConcatenation.cpp b/clang/lib/Lex/TokenConcatenation.cpp
index 865879d..cdb6369 100644
--- a/clang/lib/Lex/TokenConcatenation.cpp
+++ b/clang/lib/Lex/TokenConcatenation.cpp
@@ -160,6 +160,13 @@ static char GetFirstChar(const Preprocessor &PP, const Token &Tok) {
bool TokenConcatenation::AvoidConcat(const Token &PrevPrevTok,
const Token &PrevTok,
const Token &Tok) const {
+ // If previous token is a module name, we need avoid concat it with current
+ // token, otherwise, there will has an extra space between 'M' and ';' for the
+ // following code:
+ //
+ // import M;
+ if (PrevTok.is(tok::annot_module_name))
+ return false;
// Conservatively assume that every annotation token that has a printable
// form requires whitespace.
if (PrevTok.isAnnotation())
@@ -190,6 +197,9 @@ bool TokenConcatenation::AvoidConcat(const Token &PrevPrevTok,
return true;
ConcatInfo &= ~aci_avoid_equal;
}
+
+ if (Tok.is(tok::annot_module_name))
+ return true;
if (Tok.isAnnotation()) {
// Modules annotation can show up when generated automatically for includes.
assert(Tok.isOneOf(tok::annot_module_include, tok::annot_module_begin,