[PATCH] D135871: [clang-format][NFC] Handle language specific stuff at the top...
Björn Schäpers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 13 05:39:01 PDT 2022
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius, rymiel.
HazardyKnusperkeks added a project: clang-format.
Herald added a project: All.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
... of TokenAnnotator::splitPenalty. That is in my eyes a bit clearer in the workflow.
As a drive-by introduce (but not adapt anywhere else) isProto().
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135871
Files:
clang/include/clang/Format/Format.h
clang/lib/Format/TokenAnnotator.cpp
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3095,6 +3095,7 @@
if (Left.is(tok::semi))
return 0;
+ // Language specific handling.
if (Style.Language == FormatStyle::LK_Java) {
if (Right.isOneOf(Keywords.kw_extends, Keywords.kw_throws))
return 1;
@@ -3114,13 +3115,16 @@
// Prefer breaking call chains (".foo") over empty "{}", "[]" or "()".
if (Left.opensScope() && Right.closesScope())
return 200;
+ } else if (Style.isProto()) {
+ if (Right.is(tok::l_square))
+ return 1;
+ if (Right.is(tok::period))
+ return 500;
}
if (Right.is(tok::identifier) && Right.Next && Right.Next->is(TT_DictLiteral))
return 1;
if (Right.is(tok::l_square)) {
- if (Style.Language == FormatStyle::LK_Proto)
- return 1;
if (Left.is(tok::r_square))
return 200;
// Slightly prefer formatting local lambda definitions like functions.
@@ -3133,10 +3137,8 @@
}
}
- if (Left.is(tok::coloncolon) ||
- (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto)) {
+ if (Left.is(tok::coloncolon))
return 500;
- }
if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName) ||
Right.is(tok::kw_operator)) {
if (Line.startsWith(tok::kw_for) && Right.PartOfMultiVariableDeclStmt)
Index: clang/include/clang/Format/Format.h
===================================================================
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -2617,6 +2617,7 @@
bool isJson() const { return Language == LK_Json; }
bool isJavaScript() const { return Language == LK_JavaScript; }
bool isVerilog() const { return Language == LK_Verilog; }
+ bool isProto() const { return Language == LK_Proto; }
/// Language, this format style is targeted at.
/// \version 3.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135871.467452.patch
Type: text/x-patch
Size: 1971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221013/03dde2a5/attachment.bin>
More information about the cfe-commits
mailing list