[clang] [clang-format] Fix a bug in annotating `*` in `#define`s (PR #99433)
Hirofumi Nakamura via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 18 09:30:25 PDT 2024
hnakamura5 wrote:
This change certainly fixes the issue, but also seems specific for the reported code.
For example it does not work well for the case the line contains something else as,
```
#define FN(N) void fn(void *addr) { a + f(addr, 0, N * two); }
```
This results the annotations where `*` is PointerOrReference,
```
{(hash, "#" , Unknown), (identifier, "define" , Unknown), (identifier, "FN" , Unknown), (l_paren, "(" , Unknown),
(identifier, "N" , Unknown), (r_paren, ")" , Unknown), (void, "void" , Unknown), (identifier, "fn" , FunctionDeclarationName),
(l_paren, "(" , FunctionDeclarationLParen), (void, "void" , Unknown), (star, "*" , PointerOrReference),
(identifier, "addr" , StartOfName), (r_paren, ")" , Unknown), (l_brace, "{" , FunctionLBrace)👈, (identifier, "a" , Unknown),
(plus, "+" , BinaryOperator), (identifier, "f" , Unknown), (l_paren, "(" , Unknown), (identifier, "addr" , Unknown),
(comma, "," , Unknown), (numeric_constant, "0" , Unknown), (comma, "," , Unknown), (identifier, "N" , Unknown),
(star, "*" , PointerOrReference) 👈, (identifier, "two" , StartOfName), (r_paren, ")" , Unknown), (semi, ";" , Unknown),
(r_brace, "}" , Unknown), (eof, "" , Unknown)}
```
How about judging whether the FunctionLBrace exists as the opener of the outer context?
https://github.com/llvm/llvm-project/pull/99433
More information about the cfe-commits
mailing list