Revert "[clang-format] Fix WhitespaceSensitiveMacros not being honoured when macro...
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Wed, 18 May 2022 05:25:12 +0000 (07:25 +0200)
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Wed, 18 May 2022 05:27:45 +0000 (07:27 +0200)
This reverts commit 50cd52d9357224cce66a9e00c9a0417c658a5655.

It provoked regressions in C++ and ObjectiveC as described in https://reviews.llvm.org/D123676#3515949.

Reproducers:
```
MACRO_BEGIN
#if A
int f();
#else
int f();
#endif
```

```
NS_SWIFT_NAME(A)
@interface B : C
@property(readonly) D value;
@end
```

clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

index d1d236c..187b30f 100644 (file)
@@ -1027,10 +1027,7 @@ FormatToken *FormatTokenLexer::getNextToken() {
           Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() ==
               tok::pp_define) &&
         it != Macros.end()) {
-      if (it->second == TT_UntouchableMacroFunc)
-        FormatTok->setFinalizedType(TT_UntouchableMacroFunc);
-      else
-        FormatTok->setType(it->second);
+      FormatTok->setType(it->second);
       if (it->second == TT_IfMacro) {
         // The lexer token currently has type tok::kw_unknown. However, for this
         // substitution to be treated correctly in the TokenAnnotator, faking
index bde5431..be081a9 100644 (file)
@@ -1839,8 +1839,7 @@ void UnwrappedLineParser::parseStructuralElement(IfStmtKind *IfKind,
                 : CommentsBeforeNextToken.front()->NewlinesBefore > 0;
 
         if (FollowedByNewline && (Text.size() >= 5 || FunctionLike) &&
-            tokenCanStartNewLine(*FormatTok) && Text == Text.upper() &&
-            !PreviousToken->isTypeFinalized()) {
+            tokenCanStartNewLine(*FormatTok) && Text == Text.upper()) {
           PreviousToken->setFinalizedType(TT_FunctionLikeOrFreestandingMacro);
           addUnwrappedLine();
           return;
index 22c46a1..e54a6db 100644 (file)
@@ -23661,11 +23661,6 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
 
   // Don't use the helpers here, since 'mess up' will change the whitespace
   // and these are all whitespace sensitive by definition
-
-  // Newlines are important here.
-  EXPECT_EQ("FOO(1+2  );\n", format("FOO(1+2  );\n", Style));
-  EXPECT_EQ("FOO(1+2  )\n", format("FOO(1+2  )\n", Style));
-
   EXPECT_EQ("FOO(String-ized&Messy+But(: :Still)=Intentional);",
             format("FOO(String-ized&Messy+But(: :Still)=Intentional);", Style));
   EXPECT_EQ(