-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy path.clang-format
More file actions
217 lines (174 loc) · 6.46 KB
/
Copy path.clang-format
File metadata and controls
217 lines (174 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#
# Clang-format config enforcing the established RVVM codestyle.
# (Obviously with minor differences, but not for the worse usually)
#
# Requires clang-format 16 or newer.
# Each new added option should document whether it requires a similarly modern version.
#
# Commented out options are helpful in rare situations (Like formatting huge switches),
# and otherwise introduce unwanted codestyle changes.
# Those should be used with care and the code in question later covered with // clang-format off
#
# NOTE: This WILL mess up formatting in some rare cases, namely multi-line macros and
# short case statements like keycode translations. Older clang-format versions might also
# mess everything up on detecting unknown config key, so please update/disable it then.
#
# Please review formatting results before commits, at least for now, and use /**/ for manual
# multi-line macro breaks, or cover in // clang-format off as you see fit.
#
# Use this config for C, C++ code
Language: Cpp
#
# File settings
#
# Wrap at column width 120
ColumnLimit: 120
# Force LF line ending (clang-format 16)
LineEnding: LF
# Insert newline at EOF if missing (clang-format 16)
InsertNewlineAtEOF: true
#
# Language settings
#
# Always use `type* val` pointer style
PointerAlignment: Left
# Align pointer qualifiers
SpaceAroundPointerQualifiers: Both
# Always insert a single newline between function/struct bodies (clang-format 14)
SeparateDefinitionBlocks: Always
# Keep up to 3 consecutive empty lines between declarations (For header structuring)
MaxEmptyLinesToKeep: 3
# Break before an operator on arithmetic/logic wrapping
BreakBeforeBinaryOperators: true
BreakBeforeTernaryOperators: true
# Align arithmetic operands after wrapped operator
AlignOperands: AlignAfterOperator
# Set to ControlStatementsExceptControlMacros if you ever wish to remove space in vector_foreach() and the likes
SpaceBeforeParens: ControlStatements
# Allow single-line function declaration for empty body (Stubs)
AllowShortFunctionsOnASingleLine: Empty
# Never allow single-line loops
AllowShortLoopsOnASingleLine: false
# No spaces around elements in a braced list initializer, {0, 1, 2, 3}
Cpp11BracedListStyle: true
SpaceBeforeCpp11BracedList: true
#
# Indentation settings
#
# Always use 4 spaces for indentation
TabWidth: 4
IndentWidth: 4
ContinuationIndentWidth: 4
UseTab: Never
# Indent switch case labels
IndentCaseLabels: true
#
# Braces handling
#
# Enforce braces after control flow statements
InsertBraces: true
# Only break before function body braces, distantly similar to Linux
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeWhile: false
IndentBraces: false
#
# Pretty alignment
#
# Table-like alignment for function declarations and function pointers
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignFunctionPointers: true
# Table-like alignment for assignments (With operator padding)
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: true
PadOperators: true
# Table-like alignment for definitions and comments
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignTrailingComments: true
# Uniformly spread function arguments on wrapping
BinPackArguments: true
BinPackParameters: true
# Indent function arguments to open bracket on wrapping
AlignAfterOpenBracket: Align
# Right-align structure fields in structure array initializer (clang-format 13)
AlignArrayOfStructures: Right
#
# Formatting rules specifically for C++ code
#
# Format range-based for loops as `for (auto v : vector) {}`
SpaceBeforeRangeBasedForLoopColon: true
# Always split template declarations into separate lines
AlwaysBreakTemplateDeclarations: true
# Do not indent class access modifiers
AccessModifierOffset: -4
#
# Possibly helpful, but not yet used options
#
# Allow short case labels to fit onto a single line, helps with huge translation switches
# NOTE: This messes up a lot of code, disable and use occasionally, then clang-format off
#AllowShortCaseLabelsOnASingleLine: true
# Align short case statements (clang-format 17)
#AlignConsecutiveShortCaseStatements:
# Enabled: true
# AcrossEmptyLines: true
# AcrossComments: true
# AlignCaseColons: false
# Do not format macro bodies, might be useful sometimes (clang-format 18)
# NOTE: This breaks AlignConsecutiveMacros as of clang-format 19
#SkipMacroDefinitionBody: true
#
# RVVM-specific handling of attribute, foreach-like and scoped macros.
#
# The vector_foreach(), vector_foreach_back() macros are from `src/vector.h`
# The hashmap_foreach() macro is from `src/hashmap.h`
#
# Scoped locking helpers are from `src/spinlock.h` and `src/rcu_lib.h` respectively
#
# DO_ONCE_SCOPED {} macro is from `src/utils.h`
#
# All other macros (attributes, CHECK_INCLUDE() and scoped helpers) are found in `src/compiler.h`
#
# Do not break before braces for following foreach-like macros
ForEachMacros: [
# Vector
vector_foreach, vector_foreach_back, vector_search_sorted, vector_find_sorted,
# Hashmap
hashmap_foreach,
# Locking
rvvm_scoped_lock, rvvm_scoped_try_lock, rvvm_scoped_lock_slow,
rvvm_scoped_read_lock, rvvm_scoped_try_read_lock, rvvm_scoped_read_lock_slow,
# Legacy spinlock
scoped_spin_lock, scoped_spin_try_lock, scoped_spin_read_lock,
scoped_spin_try_read_lock, scoped_spin_lock_slow, scoped_spin_read_lock_slow,
# Do-once
DO_ONCE_SCOPED,
# Scoped helpers
BREAKABLE_SCOPE, SCOPED_COND_NAMED, POST_COND_NAMED, SCOPED_STMT_NAMED,
POST_STMT_NAMED, SCOPED_COND, POST_COND, SCOPED_STMT, POST_STMT, SCOPED_HELPER
]
# Template vector type
TypenameMacros: [vector_t]
# Do not mess up my string-handling macros!
WhitespaceSensitiveMacros: [CHECK_INCLUDE, MACRO_TOSTRING, MACRO_CONCAT]
# Type attribute macros
AttributeMacros: [safe_aliasing, align_type, randomize_layout]
# Function attribute macros
StatementAttributeLikeMacros: [forceinline, no_inline, slow_path, flatten_calls, warn_unused_ret, deallocate_with,
THREAD_LOCAL, TSAN_SUPPRESS, MSAN_SUPPRESS, GNU_DESTRUCTOR, GNU_CONSTRUCTOR]