Skip to content

Commit 063c397

Browse files
authored
Adds clang-format configuration and scripts for formatting (LLNL#605)
This commit adds the following: * A .clang-format file for configuring formatting * A script for autoformatting with clang-format * A Dockerfile for running the autoformatting script with clang-format 17.0.6 * A script for building and running the autoformatting Dockerfile * A script for checking formatting with clang-format * A Dockerfile for running the format check script with clang-format 17.0.6 * A script for building and running the format check Dockerfile * A GitHub Actions CI file for checking formatting * The results of reformatting the repo
1 parent 20c9057 commit 063c397

File tree

337 files changed

+17798
-18756
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

337 files changed

+17798
-18756
lines changed

.clang-format

+220
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
---
2+
BasedOnStyle: Microsoft
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: BlockIndent
5+
AlignArrayOfStructures: None
6+
AlignConsecutiveAssignments:
7+
Enabled: true
8+
AcrossEmptyLines: false
9+
AcrossComments: false
10+
AlignCompound: false
11+
PadOperators: true
12+
AlignConsecutiveBitFields:
13+
Enabled: false
14+
AcrossEmptyLines: false
15+
AcrossComments: false
16+
AlignCompound: false
17+
PadOperators: false
18+
AlignConsecutiveDeclarations:
19+
Enabled: true
20+
AcrossEmptyLines: false
21+
AcrossComments: false
22+
AlignCompound: false
23+
PadOperators: false
24+
AlignConsecutiveMacros:
25+
Enabled: false
26+
AcrossEmptyLines: false
27+
AcrossComments: false
28+
AlignCompound: false
29+
PadOperators: false
30+
AlignEscapedNewlines: Left
31+
AlignOperands: Align
32+
AlignTrailingComments:
33+
Kind: Always
34+
OverEmptyLines: 0
35+
AllowAllArgumentsOnNextLine: false
36+
AllowAllParametersOfDeclarationOnNextLine: false
37+
AllowShortBlocksOnASingleLine: Never
38+
AllowShortCaseLabelsOnASingleLine: false
39+
AllowShortEnumsOnASingleLine: true
40+
AllowShortFunctionsOnASingleLine: InlineOnly
41+
AllowShortIfStatementsOnASingleLine: Never
42+
AllowShortLambdasOnASingleLine: Inline
43+
AllowShortLoopsOnASingleLine: false
44+
AlwaysBreakAfterDefinitionReturnType: None
45+
AlwaysBreakAfterReturnType: None
46+
AlwaysBreakBeforeMultilineStrings: true
47+
AlwaysBreakTemplateDeclarations: Yes
48+
AttributeMacros:
49+
- __capability
50+
BinPackArguments: false
51+
BinPackParameters: false
52+
BitFieldColonSpacing: Both
53+
BraceWrapping:
54+
AfterCaseLabel: false
55+
AfterClass: true
56+
AfterControlStatement: Never
57+
AfterEnum: false
58+
AfterFunction: true
59+
AfterNamespace: true
60+
AfterObjCDeclaration: true
61+
AfterStruct: false
62+
AfterUnion: false
63+
AfterExternBlock: true
64+
BeforeCatch: false
65+
BeforeElse: false
66+
BeforeLambdaBody: false
67+
BeforeWhile: false
68+
IndentBraces: false
69+
SplitEmptyFunction: false
70+
SplitEmptyRecord: false
71+
SplitEmptyNamespace: false
72+
BreakAfterAttributes: Never
73+
BreakAfterJavaFieldAnnotations: false
74+
BreakArrays: false
75+
BreakBeforeBinaryOperators: NonAssignment
76+
BreakBeforeBraces: Custom
77+
BreakBeforeConceptDeclarations: Always
78+
BreakBeforeInlineASMColon: OnlyMultiline
79+
BreakBeforeTernaryOperators: true
80+
BreakConstructorInitializers: BeforeColon
81+
BreakInheritanceList: BeforeColon
82+
BreakStringLiterals: true
83+
ColumnLimit: 120
84+
CommentPragmas: ^\\.+
85+
CompactNamespaces: false
86+
ConstructorInitializerIndentWidth: 4
87+
ContinuationIndentWidth: 4
88+
Cpp11BracedListStyle: false
89+
DerivePointerAlignment: false
90+
DisableFormat: false
91+
EmptyLineAfterAccessModifier: Always
92+
EmptyLineBeforeAccessModifier: Always
93+
ExperimentalAutoDetectBinPacking: false
94+
FixNamespaceComments: true
95+
ForEachMacros:
96+
- foreach
97+
- Q_FOREACH
98+
- BOOST_FOREACH
99+
IfMacros:
100+
- KJ_IF_MAYBE
101+
IncludeBlocks: Preserve
102+
IncludeCategories:
103+
- Regex: ^"(llvm|llvm-c|clang|clang-c)/
104+
Priority: 2
105+
SortPriority: 0
106+
CaseSensitive: false
107+
- Regex: ^(<|"(gtest|gmock|isl|json)/)
108+
Priority: 3
109+
SortPriority: 0
110+
CaseSensitive: false
111+
- Regex: .*
112+
Priority: 1
113+
SortPriority: 0
114+
CaseSensitive: false
115+
IncludeIsMainRegex: (Test)?$
116+
IncludeIsMainSourceRegex: ""
117+
IndentAccessModifiers: false
118+
IndentCaseBlocks: true
119+
IndentCaseLabels: false
120+
IndentExternBlock: NoIndent
121+
IndentGotoLabels: false
122+
IndentPPDirectives: None
123+
IndentRequiresClause: true
124+
IndentWidth: 4
125+
IndentWrappedFunctionNames: false
126+
InsertBraces: false
127+
InsertNewlineAtEOF: false
128+
InsertTrailingCommas: None
129+
IntegerLiteralSeparator:
130+
Binary: 0
131+
Decimal: 0
132+
Hex: 0
133+
JavaScriptQuotes: Leave
134+
JavaScriptWrapImports: true
135+
KeepEmptyLinesAtTheStartOfBlocks: true
136+
LambdaBodyIndentation: Signature
137+
Language: Cpp
138+
LineEnding: DeriveLF
139+
MacroBlockBegin: ""
140+
MacroBlockEnd: ""
141+
MaxEmptyLinesToKeep: 1
142+
NamespaceIndentation: None
143+
ObjCBinPackProtocolList: Auto
144+
ObjCBlockIndentWidth: 2
145+
ObjCBreakBeforeNestedBlockParam: true
146+
ObjCSpaceAfterProperty: false
147+
ObjCSpaceBeforeProtocolList: true
148+
PPIndentWidth: -1
149+
PackConstructorInitializers: NextLine
150+
PenaltyBreakAssignment: 2
151+
PenaltyBreakBeforeFirstCallParameter: 19
152+
PenaltyBreakComment: 300
153+
PenaltyBreakFirstLessLess: 120
154+
PenaltyBreakOpenParenthesis: 0
155+
PenaltyBreakString: 1000
156+
PenaltyBreakTemplateDeclaration: 10
157+
PenaltyExcessCharacter: 1000000
158+
PenaltyIndentedWhitespace: 0
159+
PenaltyReturnTypeOnItsOwnLine: 1000
160+
PointerAlignment: Left
161+
QualifierAlignment: Leave
162+
ReferenceAlignment: Pointer
163+
ReflowComments: false
164+
RemoveBracesLLVM: false
165+
RemoveSemicolon: false
166+
RequiresClausePosition: OwnLine
167+
RequiresExpressionIndentation: OuterScope
168+
SeparateDefinitionBlocks: Always
169+
ShortNamespaceLines: 1
170+
SortIncludes: Never
171+
SortJavaStaticImport: Before
172+
SortUsingDeclarations: LexicographicNumeric
173+
SpaceAfterCStyleCast: true
174+
SpaceAfterLogicalNot: false
175+
SpaceAfterTemplateKeyword: true
176+
SpaceAroundPointerQualifiers: Default
177+
SpaceBeforeAssignmentOperators: true
178+
SpaceBeforeCaseColon: false
179+
SpaceBeforeCpp11BracedList: true
180+
SpaceBeforeCtorInitializerColon: true
181+
SpaceBeforeInheritanceColon: true
182+
SpaceBeforeParens: Custom
183+
SpaceBeforeParensOptions:
184+
AfterControlStatements: true
185+
AfterForeachMacros: true
186+
AfterFunctionDeclarationName: false
187+
AfterFunctionDefinitionName: false
188+
AfterIfMacros: true
189+
AfterOverloadedOperator: true
190+
AfterRequiresInClause: false
191+
AfterRequiresInExpression: false
192+
BeforeNonEmptyParentheses: false
193+
SpaceBeforeRangeBasedForLoopColon: true
194+
SpaceBeforeSquareBrackets: false
195+
SpaceInEmptyBlock: false
196+
SpaceInEmptyParentheses: false
197+
SpacesBeforeTrailingComments: 1
198+
SpacesInAngles: Never
199+
SpacesInCStyleCastParentheses: false
200+
SpacesInConditionalStatement: false
201+
SpacesInContainerLiterals: true
202+
SpacesInLineCommentPrefix:
203+
Minimum: 1
204+
Maximum: -1
205+
SpacesInParentheses: false
206+
SpacesInSquareBrackets: false
207+
Standard: c++11
208+
StatementAttributeLikeMacros:
209+
- Q_EMIT
210+
StatementMacros:
211+
- Q_UNUSED
212+
- QT_REQUIRE_VERSION
213+
TabWidth: 4
214+
UseTab: Never
215+
WhitespaceSensitiveMacros:
216+
- BOOST_PP_STRINGIZE
217+
- CF_SWIFT_NAME
218+
- NS_SWIFT_NAME
219+
- PP_STRINGIZE
220+
- STRINGIZE

.github/workflows/format-check.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Check code formatting
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
cpp-format-check:
11+
runs-on: ubuntu-24.04
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install clang-format
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y --no-install-recommends \
20+
build-essential \
21+
clang-format-17
22+
23+
- name: Test formatting
24+
run: |
25+
./scripts/formatting/check-formatting.sh /usr/bin/clang-format-17

examples/apps/c-example.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
void print_help()
1717
{
18-
const char* helpstr =
18+
const char* helpstr =
1919
"Usage: c-example [caliper-config(arg=...,),...]."
2020
"\nRuns \"runtime-report\" configuration by default."
2121
"\nUse \"none\" to run without a ConfigManager configuration."
@@ -81,8 +81,8 @@ int main(int argc, char* argv[])
8181

8282
// Mark a code region. Opens region "annotation=init" in Caliper.
8383
CALI_MARK_BEGIN("init");
84-
int count = 4;
85-
double t = 0;
84+
int count = 4;
85+
double t = 0;
8686
CALI_MARK_END("init");
8787

8888
// Mark a loop. Opens region "loop=mainloop" in Caliper.

examples/apps/cali-functional.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2019, Lawrence Livermore National Security, LLC.
22
// See top-level LICENSE file for details.
33

4-
// A minimal Caliper function object demo
4+
// A minimal Caliper function object demo
55

66
#include <caliper/cali.h>
77
#include <caliper/CaliFunctional.h>
@@ -24,8 +24,9 @@ int sum(int x, int y){
2424

2525
// To instrument, instead first rename your function to "wrapped"
2626

27-
int wrapped_sum(int x, int y){
28-
return x + y;
27+
int wrapped_sum(int x, int y)
28+
{
29+
return x + y;
2930
}
3031

3132
// Then make a function object with the original name
@@ -35,17 +36,17 @@ int wrapped_sum(int x, int y){
3536
//
3637
// In this case we want to name the function "sum" and
3738
// create it by wrapping "wrapped_sum"
38-
auto sum = cali::wrap_function_and_args("sum",wrapped_sum);
39+
auto sum = cali::wrap_function_and_args("sum", wrapped_sum);
3940

4041
// You can wrap anything you can get a handle to, see:
41-
auto wrapped_malloc = cali::wrap_function_and_args("malloc",malloc);
42+
auto wrapped_malloc = cali::wrap_function_and_args("malloc", malloc);
4243

4344
// Note that you don't have to profile arguments and return values:
44-
auto minimally_wrapped_free = cali::wrap_function("free",free);
45+
auto minimally_wrapped_free = cali::wrap_function("free", free);
4546

4647
int main(int argc, char* argv[])
4748
{
48-
int seven = sum(3,4);
49-
int* int_pointer = (int*)wrapped_malloc(sizeof(int)* 100);
49+
int seven = sum(3, 4);
50+
int* int_pointer = (int*) wrapped_malloc(sizeof(int) * 100);
5051
minimally_wrapped_free(int_pointer);
5152
}

0 commit comments

Comments
 (0)