We had to add a bunch of keywords for a new language. Using the old
method, we had to add each keyword in the declaration, initialization,
and maybe in several lists, which turned out to be tiring and
error-prone.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/Format/FormatToken.h | ||
---|---|---|
947 | It was not in the original set for C# keywords. But since MyDeveloperDay also pointed it out I guess he simply forgot. | |
991–999 | It looks like I would have to use the KeywordLanguage:: prefix throughout the macro list and also define an operator to combine categories for keywords that several languages have. Do you know of a simpler way? With the current enum, the DEFINE_LIKE_NAMES can't be used directly outside AdditionalKeywords. |
clang/lib/Format/FormatToken.h | ||
---|---|---|
991–999 | You can always drop the class and are back at integers. | |
991–999 |
This one I don't understand? They are public and can be used, can't they? And the type I can get with decltype. |
clang/lib/Format/FormatToken.h | ||
---|---|---|
884 | I didn't see this before... for me this is a hard no, I think macro code is ugly, it causes clang-format itself a whole host of issues, and I don't want to proliferate it. plus it begins a path of you using flags and I think that is unstructure C way of coding. I know you want to add other keywords for Verilog but this to me isn't nice I don't understand why you couldn't have added the Verilog keywords like we did for JavaScript and C# |
Allow me another attempt in justifying this patch.
Using the macros, it is easier to see when a keyword is not classified as some language's keyword. The author and reviewers didn't notice final and dollar being in only one place previously. With the old way, when someone adds a new keyword he is also more likely to forget to include it in the sets.
In the commit message when I said the old way turned out to be error-prone, I did debug why some code doesn't get formatted right only to find I forgot to add a keyword in one of the places.
With the isIdentifier and isKeyword functions matching the sets separately, it is more likely one of them will get it wrong. In the original isCSharpKeyword function, the check is wrong, it should be !=.
CSharpExtraKeywords.find(Tok.Tok.getIdentifierInfo()) == CSharpExtraKeywords.end()
I didn't see this before... for me this is a hard no, I think macro code is ugly, it causes clang-format itself a whole host of issues, and I don't want to proliferate it. plus it begins a path of you using flags and I think that is unstructure C way of coding.
I know you want to add other keywords for Verilog but this to me isn't nice I don't understand why you couldn't have added the Verilog keywords like we did for JavaScript and C#