Skip to content

Commit 2dc1437

Browse files
authored
Setup Clang Format and Clang Tidy Checking (#34)
This reformats the code with a style that's trying to be similar to the existing one, but standardizes it much more.
2 parents efaa0bf + da89ab0 commit 2dc1437

File tree

139 files changed

+3659
-2935
lines changed

Some content is hidden

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

139 files changed

+3659
-2935
lines changed

.clang-format

+270
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
Language: Cpp
2+
# BasedOnStyle: Chromium
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: Align
5+
AlignArrayOfStructures: None
6+
AlignConsecutiveAssignments:
7+
Enabled: false
8+
AcrossEmptyLines: false
9+
AcrossComments: false
10+
AlignCompound: false
11+
AlignFunctionPointers: false
12+
PadOperators: true
13+
AlignConsecutiveBitFields:
14+
Enabled: false
15+
AcrossEmptyLines: false
16+
AcrossComments: false
17+
AlignCompound: false
18+
AlignFunctionPointers: false
19+
PadOperators: false
20+
AlignConsecutiveDeclarations:
21+
Enabled: false
22+
AcrossEmptyLines: false
23+
AcrossComments: false
24+
AlignCompound: false
25+
AlignFunctionPointers: false
26+
PadOperators: false
27+
AlignConsecutiveMacros:
28+
Enabled: false
29+
AcrossEmptyLines: false
30+
AcrossComments: false
31+
AlignCompound: false
32+
AlignFunctionPointers: false
33+
PadOperators: false
34+
AlignConsecutiveShortCaseStatements:
35+
Enabled: false
36+
AcrossEmptyLines: false
37+
AcrossComments: false
38+
AlignCaseColons: false
39+
AlignEscapedNewlines: Left
40+
AlignOperands: Align
41+
AlignTrailingComments:
42+
Kind: Always
43+
OverEmptyLines: 0
44+
AllowAllArgumentsOnNextLine: true
45+
AllowAllParametersOfDeclarationOnNextLine: false
46+
AllowBreakBeforeNoexceptSpecifier: Never
47+
AllowShortBlocksOnASingleLine: Never
48+
AllowShortCaseLabelsOnASingleLine: false
49+
AllowShortCompoundRequirementOnASingleLine: true
50+
AllowShortEnumsOnASingleLine: true
51+
AllowShortFunctionsOnASingleLine: Inline
52+
AllowShortIfStatementsOnASingleLine: Never
53+
AllowShortLambdasOnASingleLine: All
54+
AllowShortLoopsOnASingleLine: false
55+
AlwaysBreakAfterDefinitionReturnType: None
56+
AlwaysBreakAfterReturnType: None
57+
AlwaysBreakBeforeMultilineStrings: true
58+
AlwaysBreakTemplateDeclarations: Yes
59+
AttributeMacros:
60+
- __capability
61+
BinPackArguments: true
62+
BinPackParameters: true
63+
BitFieldColonSpacing: Both
64+
BraceWrapping:
65+
AfterCaseLabel: false
66+
AfterClass: false
67+
AfterControlStatement: Never
68+
AfterEnum: false
69+
AfterExternBlock: false
70+
AfterFunction: false
71+
AfterNamespace: false
72+
AfterObjCDeclaration: false
73+
AfterStruct: false
74+
AfterUnion: false
75+
BeforeCatch: false
76+
BeforeElse: false
77+
BeforeLambdaBody: false
78+
BeforeWhile: false
79+
IndentBraces: false
80+
SplitEmptyFunction: true
81+
SplitEmptyRecord: true
82+
SplitEmptyNamespace: true
83+
BreakAdjacentStringLiterals: true
84+
BreakAfterAttributes: Leave
85+
BreakAfterJavaFieldAnnotations: false
86+
BreakArrays: true
87+
BreakBeforeBinaryOperators: None
88+
BreakBeforeConceptDeclarations: Always
89+
BreakBeforeBraces: Attach
90+
BreakBeforeInlineASMColon: OnlyMultiline
91+
BreakBeforeTernaryOperators: true
92+
BreakConstructorInitializers: BeforeColon
93+
BreakInheritanceList: BeforeColon
94+
BreakStringLiterals: true
95+
ColumnLimit: 80
96+
CommentPragmas: '^ IWYU pragma:'
97+
CompactNamespaces: false
98+
ConstructorInitializerIndentWidth: 4
99+
ContinuationIndentWidth: 4
100+
Cpp11BracedListStyle: true
101+
DerivePointerAlignment: false
102+
DisableFormat: false
103+
EmptyLineAfterAccessModifier: Never
104+
EmptyLineBeforeAccessModifier: LogicalBlock
105+
ExperimentalAutoDetectBinPacking: true
106+
FixNamespaceComments: true
107+
ForEachMacros:
108+
- foreach
109+
- Q_FOREACH
110+
- BOOST_FOREACH
111+
IfMacros:
112+
- KJ_IF_MAYBE
113+
IncludeBlocks: Regroup
114+
IncludeCategories:
115+
- Regex: '^<.*'
116+
Priority: 1
117+
SortPriority: 1
118+
CaseSensitive: true
119+
- Regex: '.*'
120+
Priority: 3
121+
SortPriority: 3
122+
CaseSensitive: true
123+
IncludeIsMainRegex: '([-_](test|unittest))?$'
124+
IncludeIsMainSourceRegex: ''
125+
IndentAccessModifiers: false
126+
IndentCaseBlocks: false
127+
IndentCaseLabels: true
128+
IndentExternBlock: AfterExternBlock
129+
IndentGotoLabels: true
130+
IndentPPDirectives: BeforeHash
131+
IndentRequiresClause: true
132+
IndentWidth: 4
133+
IndentWrappedFunctionNames: false
134+
InsertBraces: true
135+
InsertNewlineAtEOF: false
136+
InsertTrailingCommas: None
137+
IntegerLiteralSeparator:
138+
Binary: 0
139+
BinaryMinDigits: 0
140+
Decimal: 0
141+
DecimalMinDigits: 0
142+
Hex: 0
143+
HexMinDigits: 0
144+
JavaScriptQuotes: Leave
145+
JavaScriptWrapImports: true
146+
KeepEmptyLinesAtTheStartOfBlocks: false
147+
KeepEmptyLinesAtEOF: false
148+
LambdaBodyIndentation: Signature
149+
LineEnding: DeriveLF
150+
MacroBlockBegin: ''
151+
MacroBlockEnd: ''
152+
MaxEmptyLinesToKeep: 1
153+
NamespaceIndentation: None
154+
ObjCBinPackProtocolList: Never
155+
ObjCBlockIndentWidth: 2
156+
ObjCBreakBeforeNestedBlockParam: true
157+
ObjCSpaceAfterProperty: false
158+
ObjCSpaceBeforeProtocolList: true
159+
PackConstructorInitializers: BinPack
160+
PenaltyBreakAssignment: 2
161+
PenaltyBreakBeforeFirstCallParameter: 1
162+
PenaltyBreakComment: 300
163+
PenaltyBreakFirstLessLess: 120
164+
PenaltyBreakOpenParenthesis: 0
165+
PenaltyBreakScopeResolution: 500
166+
PenaltyBreakString: 1000
167+
PenaltyBreakTemplateDeclaration: 10
168+
PenaltyExcessCharacter: 1000000
169+
PenaltyIndentedWhitespace: 0
170+
PenaltyReturnTypeOnItsOwnLine: 200
171+
PointerAlignment: Left
172+
PPIndentWidth: 2
173+
QualifierAlignment: Leave
174+
RawStringFormats:
175+
- Language: Cpp
176+
Delimiters:
177+
- cc
178+
- CC
179+
- cpp
180+
- Cpp
181+
- CPP
182+
- 'c++'
183+
- 'C++'
184+
CanonicalDelimiter: ''
185+
BasedOnStyle: google
186+
- Language: TextProto
187+
Delimiters:
188+
- pb
189+
- PB
190+
- proto
191+
- PROTO
192+
EnclosingFunctions:
193+
- EqualsProto
194+
- EquivToProto
195+
- PARSE_PARTIAL_TEXT_PROTO
196+
- PARSE_TEST_PROTO
197+
- PARSE_TEXT_PROTO
198+
- ParseTextOrDie
199+
- ParseTextProtoOrDie
200+
- ParseTestProto
201+
- ParsePartialTestProto
202+
CanonicalDelimiter: pb
203+
BasedOnStyle: google
204+
ReferenceAlignment: Pointer
205+
ReflowComments: true
206+
RemoveBracesLLVM: false
207+
RemoveParentheses: Leave
208+
RemoveSemicolon: false
209+
RequiresClausePosition: OwnLine
210+
RequiresExpressionIndentation: OuterScope
211+
SeparateDefinitionBlocks: Leave
212+
ShortNamespaceLines: 1
213+
SkipMacroDefinitionBody: false
214+
SortIncludes: CaseSensitive
215+
SortJavaStaticImport: Before
216+
SortUsingDeclarations: LexicographicNumeric
217+
SpaceAfterCStyleCast: false
218+
SpaceAfterLogicalNot: false
219+
SpaceAfterTemplateKeyword: true
220+
SpaceAroundPointerQualifiers: Default
221+
SpaceBeforeAssignmentOperators: true
222+
SpaceBeforeCaseColon: false
223+
SpaceBeforeCpp11BracedList: false
224+
SpaceBeforeCtorInitializerColon: true
225+
SpaceBeforeInheritanceColon: true
226+
SpaceBeforeJsonColon: false
227+
SpaceBeforeParens: ControlStatements
228+
SpaceBeforeParensOptions:
229+
AfterControlStatements: true
230+
AfterForeachMacros: true
231+
AfterFunctionDefinitionName: false
232+
AfterFunctionDeclarationName: false
233+
AfterIfMacros: true
234+
AfterOverloadedOperator: false
235+
AfterPlacementOperator: true
236+
AfterRequiresInClause: false
237+
AfterRequiresInExpression: false
238+
BeforeNonEmptyParentheses: false
239+
SpaceBeforeRangeBasedForLoopColon: true
240+
SpaceBeforeSquareBrackets: false
241+
SpaceInEmptyBlock: false
242+
SpacesBeforeTrailingComments: 2
243+
SpacesInAngles: Never
244+
SpacesInContainerLiterals: true
245+
SpacesInLineCommentPrefix:
246+
Minimum: 1
247+
Maximum: -1
248+
SpacesInParens: Never
249+
SpacesInParensOptions:
250+
InCStyleCasts: false
251+
InConditionalStatements: false
252+
InEmptyParentheses: false
253+
Other: false
254+
SpacesInSquareBrackets: false
255+
Standard: Auto
256+
StatementAttributeLikeMacros:
257+
- Q_EMIT
258+
StatementMacros:
259+
- Q_UNUSED
260+
- QT_REQUIRE_VERSION
261+
TabWidth: 8
262+
UseTab: Never
263+
VerilogBreakBetweenInstancePorts: true
264+
WhitespaceSensitiveMacros:
265+
- BOOST_PP_STRINGIZE
266+
- CF_SWIFT_NAME
267+
- NS_SWIFT_NAME
268+
- PP_STRINGIZE
269+
- STRINGIZE
270+
...

.clang-tidy

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Checks: '*include*,
4141
# -hicpp-special-member-functions,
4242
# -cppcoreguidelines-pro-bounds-pointer-arithmetic,
4343
# -cppcoreguidelines-owning-memory,
44-
WarningsAsErrors: ''
44+
WarningsAsErrors: '*'
4545
HeaderFilterRegex: '^(?!.*cppunit).*$'
4646
# AnalyzeTemporaryDtors: false
4747
FormatStyle: none

.github/workflows/ci.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ jobs:
3232
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main"
3333
sudo apt-get update
3434
sudo apt-get install -y clang-18 clang-tidy-18
35-
# clang-format-17
3635
if: matrix.compiler == 'clang'
3736

37+
- name: Install Clang Format
38+
run: sudo apt-get install -y clang-format-18
39+
if: matrix.compiler == 'clang' && matrix.gc == 'GENERATIONAL'
40+
3841
- name: Build SOM VM
3942
run: |
4043
if [ "${{ matrix.compiler }}" = "clang" ]
@@ -67,6 +70,11 @@ jobs:
6770
run: |
6871
clang-tidy-18 --config-file=.clang-tidy src/**/*.cpp -- -fdiagnostics-absolute-paths -DGC_TYPE=${{ matrix.gc}} ${{ matrix.integers }} -DUNITTESTS
6972
73+
- name: Clang Format
74+
if: matrix.compiler == 'clang' && matrix.gc == 'GENERATIONAL'
75+
run: |
76+
clang-format-18 --dry-run --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h
77+
7078
# Disabled because it's too slow with the sanitizers
7179
# - name: Test SomSom
7280
# run: |

lint.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/sh
2-
CFLAGS+=' -fdiagnostics-absolute-paths'
3-
# clang-tidy-mp-18 --config-file=.clang-tidy ./src/compiler/Lexer.cpp -- -I/opt/local/include/ -DGC_TYPE=COPYING -DUNITTESTS -fdiagnostics-absolute-paths
4-
5-
# -header-filter=.*
6-
# src/**/*.cpp
7-
clang-tidy-mp-18 --config-file=.clang-tidy src/**/*.cpp -- -I/opt/local/include/ -fdiagnostics-absolute-paths -DGC_TYPE=COPYING -DUNITTESTS
2+
clang-format-mp-18 -i --style=file --Werror src/*.cpp src/**/*.cpp src/**/*.h
3+
clang-tidy-mp-18 --config-file=.clang-tidy src/**/*.cpp -- \
4+
-I/opt/local/include/ -fdiagnostics-absolute-paths \
5+
-DGC_TYPE=GENERATIONAL -DUSE_TAGGING=false -DCACHE_INTEGER=false -DUNITTESTS

src/Main.cpp

+18-23
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,50 @@
2222
THE SOFTWARE.
2323
*/
2424

25-
#include <iostream>
2625
#include <fstream>
26+
#include <iostream>
2727

2828
#include "compiler/ClassGenerationContext.h"
29-
3029
#include "memory/Heap.h"
31-
3230
#include "misc/defs.h"
33-
3431
#include "vm/Universe.h"
35-
36-
#include "vmobjects/VMObject.h"
32+
#include "vmobjects/ObjectFormats.h"
33+
#include "vmobjects/VMArray.h"
3734
#include "vmobjects/VMMethod.h"
35+
#include "vmobjects/VMObject.h"
3836
#include "vmobjects/VMString.h"
39-
#include "vmobjects/VMArray.h"
40-
#include "vmobjects/ObjectFormats.h"
4137

4238
int main(int argc, char** argv) {
43-
4439
cout << "This is SOM++" << endl;
4540

46-
if (GC_TYPE == GENERATIONAL)
41+
if (GC_TYPE == GENERATIONAL) {
4742
cout << "\tgarbage collector: generational" << endl;
48-
else if (GC_TYPE == COPYING)
43+
} else if (GC_TYPE == COPYING) {
4944
cout << "\tgarbage collector: copying" << endl;
50-
else if (GC_TYPE == MARK_SWEEP)
45+
} else if (GC_TYPE == MARK_SWEEP) {
5146
cout << "\tgarbage collector: mark-sweep" << endl;
52-
else if (GC_TYPE == DEBUG_COPYING)
47+
} else if (GC_TYPE == DEBUG_COPYING) {
5348
cout << "\tgarbage collector: debug copying" << endl;
54-
else
49+
} else {
5550
cout << "\tgarbage collector: unknown" << endl;
51+
}
5652

57-
if (USE_TAGGING)
53+
if (USE_TAGGING) {
5854
cout << "\twith tagged integers" << endl;
59-
else
55+
} else {
6056
cout << "\tnot tagging integers" << endl;
57+
}
6158

62-
if (CACHE_INTEGER)
63-
cout << "\tcaching integers from " << INT_CACHE_MIN_VALUE
64-
<< " to " << INT_CACHE_MAX_VALUE << endl;
65-
else
59+
if (CACHE_INTEGER) {
60+
cout << "\tcaching integers from " << INT_CACHE_MIN_VALUE << " to "
61+
<< INT_CACHE_MAX_VALUE << endl;
62+
} else {
6663
cout << "\tnot caching integers" << endl;
67-
64+
}
6865

6966
cout << "--------------------------------------" << endl;
7067

71-
7268
Universe::Start(argc, argv);
7369

7470
Universe::Quit(ERR_SUCCESS);
7571
}
76-

0 commit comments

Comments
 (0)