Reimplement the RemoveBracesLLVM feature which handles a single-statement block that would get wrapped.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Will it also add braces if they where not there yet?
clang/unittests/Format/FormatTest.cpp | ||
---|---|---|
25397 | Will it also add braces if they where not there yet? |
clang/unittests/Format/FormatTest.cpp | ||
---|---|---|
25397 | No, but you can insert braces by setting InsertBraces to true and RemoveBracesLLVM to false. |
clang/lib/Format/UnwrappedLineParser.cpp | ||
---|---|---|
465 | A bit explanation what it means that something might fit in one line would be nice. | |
479 | Especially this one is not clear to me, why do we return true here? | |
481 | Is a FormatToken "big", or expensive to copy? If not I'd save them directly, otherwise I'd prefer a unique_ptr. |
clang/lib/Format/UnwrappedLineParser.cpp | ||
---|---|---|
465 | Will do. | |
479 | We will remove braces only if the previous line (i.e. the line before the closing brace) ends with a semi or comment. I should move this check to the caller or rename the function. | |
481 | We have to make a copy of the FormatToken here so that we can restore it after the TokenAnnotator modifies it directly. | |
484 | We must save Token.Children as well. |
Added saving/restoring the children of UnwrappedLineNode and addressed review comments.
clang/lib/Format/UnwrappedLineParser.cpp | ||
---|---|---|
766 | The last token of ParsedLine is of interest here. We want the annotator to compute its TotalLength to determine whether the line might fit on a single line. I'm open to renaming the variable if you have a better suggestion. | |
777 | Both the constructor and the destructor of AnnotatedLine clear the children of UnwrappedLineNode, so we save them beforehand and restore them afterward. | |
787 |
See the assertion on line 781 above. We are computing the TotalLength of LastToken via Line. Either way works, but I prefer the simpler expression. I can change it though if you insist. |
clang/lib/Format/UnwrappedLineParser.cpp | ||
---|---|---|
787 | Yeah, what I meant is to just get rid of LastToken variable and write the suggested code. |
A bit explanation what it means that something might fit in one line would be nice.