llvm-project/clang/unittests/Format
Joseph Huber 037669de8b [clang-format] Do not parse certain characters in pragma directives
Currently, we parse lines inside of a compiler `#pragma` the same way we
parse any other line. This is fine for some cases, like separating
expressions and adding proper spacing, but in others it causes some poor
results from miscategorizing some tokens.

For example, the OpenMP offloading uses certain clauses that contain
special characters like `map(tofrom : A[0:N])`. This will be formatted
poorly as it will be split between lines on the first colon.
Additionally the subscript notation will lead to poor spacing. This can
be seen in the OpenMP tests as the automatic clang formatting with
inevitably ruin the formatting.

For example, the following contrived example will be formatted poorly.
```
#pragma omp target teams distribute collapse(2) map(to: A[0 : M * K])  \
    map(to: B[0:K * N]) map(tofrom:C[0:M*N]) firstprivate(Alpha) \
    firstprivate(Beta) firstprivate(X) firstprivate(D) firstprivate(Y) \
    firstprivate(E) firstprivate(Z) firstprivate(F)
```
This results in this when formatted, which is far from ideal.
```
#pragma omp target teams distribute collapse(2) map(to                         \
                                                    : A [0:M * K])             \
    map(to                                                                     \
        : B [0:K * N]) map(tofrom                                              \
                           : C [0:M * N]) firstprivate(Alpha)                  \
        firstprivate(Beta) firstprivate(X) firstprivate(D) firstprivate(Y)     \
            firstprivate(E) firstprivate(Z) firstprivate(F)
```

This patch seeks to improve this by adding extra logic where the parsing goes
awry. This is primarily caused by the colon being parsed as an inline-asm
directive and the brackes an objective-C expressions. Also the line gets
indented every single time the line is dropped.

This doesn't implement true parsing handling for OpenMP statements.

Reviewed By: HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D136100
2022-10-18 16:38:19 -05:00
..
.clang-format [clang-format][NFC] Reformat the clang/unittests/Format directory 2022-09-21 13:26:59 -07:00
CMakeLists.txt [clang-format] Add MacroUnexpander. 2022-07-12 07:11:46 +00:00
CleanupTest.cpp
DefinitionBlockSeparatorTest.cpp [clang-format] Format unit tests with InsertBraces/RemoveBracesLLVM 2022-05-21 16:13:35 -07:00
FormatTest.cpp [clang-format] Do not parse certain characters in pragma directives 2022-10-18 16:38:19 -05:00
FormatTestCSharp.cpp [clang-format] Handle C# interpolated verbatim string prefix @$ 2022-10-04 18:27:36 -07:00
FormatTestComments.cpp [clang-format] Add space to comments starting with '#'. 2022-03-13 21:56:22 +01:00
FormatTestJS.cpp [Format] Drop speculative test added in previous patch, it hits asserts? 2022-10-06 17:57:58 +02:00
FormatTestJava.cpp [clang-format] Fix aligning of java-style declarations 2022-08-15 20:27:15 -07:00
FormatTestJson.cpp [clang-format] JSON formatting add new option for controlling newlines in json arrays 2022-09-19 17:54:39 +01:00
FormatTestObjC.cpp [clang-format] [PR52015] clang-format should put __attribute__((foo)) on its own line before @interface / @implementation / @protocol 2021-10-20 09:09:31 +01:00
FormatTestProto.cpp
FormatTestRawStrings.cpp clang-format: use `pb` as a canonical raw string delimiter for google style 2021-03-09 09:07:14 +01:00
FormatTestSelective.cpp [clang-format] Avoid crash in LevelIndentTracker. 2022-07-07 10:15:45 +02:00
FormatTestTableGen.cpp
FormatTestTextProto.cpp [clang-format] don't break up #-style comment sections 2022-03-22 15:29:02 +01:00
FormatTestUtils.h [clang-format] Parse Verilog if statements 2022-06-26 01:52:15 +00:00
FormatTestVerilog.cpp [clang-format] Handle Verilog attributes 2022-07-29 00:38:30 +00:00
MacroCallReconstructorTest.cpp [clang-format][NFC] Reformat the clang/unittests/Format directory 2022-09-21 13:26:59 -07:00
MacroExpanderTest.cpp [clang-format] Reformat. NFC. 2022-03-17 09:27:31 +01:00
NamespaceEndCommentsFixerTest.cpp [clang-format] Reformat. NFC. 2022-03-17 09:27:31 +01:00
QualifierFixerTest.cpp [clang-format] Fix QualifierAlignment with global namespace qualified types. 2022-05-26 15:02:33 +02:00
SortImportsTestJS.cpp clang-format: [JS] sort import aliases. Users can define aliases for long symbols using import aliases: 2022-01-28 11:51:28 +01:00
SortImportsTestJava.cpp [clang-format] Add case aware include sorting. 2021-02-02 15:12:27 +01:00
SortIncludesTest.cpp [clang-format] add a regression test for include sorting 2022-04-28 11:02:14 +02:00
TestLexer.h [clang-format] Reformat. NFC. 2022-03-17 09:27:31 +01:00
TokenAnnotatorTest.cpp [clang-format] Correctly annotate star/amp in function pointer params 2022-10-18 08:17:23 +03:00
UsingDeclarationsSorterTest.cpp