[all-commits] [llvm/llvm-project] ab7cee: [clang-format] Handle C++ keywords in other langua...
sstwcw via All-commits
all-commits at lists.llvm.org
Mon Mar 31 06:55:30 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: ab7cee8a0ecf29fdb47c64c8d431a694d63390d2
https://github.com/llvm/llvm-project/commit/ab7cee8a0ecf29fdb47c64c8d431a694d63390d2
Author: sstwcw <su3e8a96kzlver at posteo.net>
Date: 2025-03-31 (Mon, 31 Mar 2025)
Changed paths:
M clang/lib/Format/FormatTokenLexer.cpp
M clang/unittests/Format/FormatTestJS.cpp
M clang/unittests/Format/FormatTestJava.cpp
Log Message:
-----------
[clang-format] Handle C++ keywords in other languages better (#132941)
There is some code to make sure that C++ keywords that are identifiers
in the other languages are not treated as keywords. Right now, the kind
is set to identifier, and the identifier info is cleared. The latter is
probably so that the code for identifying C++ structures does not
recognize those structures by mistake when formatting a language that
does not have those structures. But we did not find an instance where
the language can have the sequence of tokens, the code tries to parse
the structure as if it is C++ using the identifier info instead of the
token kind, but without checking for the language setting. However,
there are places where the code checks whether the identifier info field
is null or not. They are places where an identifier and a keyword are
treated the same way. For example, the name of a function in
JavaScript. This patch removes the lines that clear the identifier
info. This way, a C++ keyword gets treated in the same way as an
identifier in those places.
JavaScript
New
```JavaScript
async function
union(
myparamnameiswaytooloooong) {
}
```
Old
```JavaScript
async function
union(
myparamnameiswaytooloooong) {
}
```
Java
New
```Java
enum union { ABC, CDE }
```
Old
```Java
enum
union { ABC, CDE }
```
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list