Skip to content

Commit 1c92e23

Browse files
committed
Reformat Bifcl in Spicy style
1 parent c7bf54c commit 1c92e23

6 files changed

+292
-253
lines changed

.clang-format

+108-62
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,66 @@
1-
# Clang-format configuration for Zeek. This configuration requires
2-
# at least clang-format 12.0.1 to format correctly.
3-
4-
Language: Cpp
5-
Standard: c++17
6-
7-
BreakBeforeBraces: Whitesmiths
8-
9-
# BraceWrapping:
10-
# AfterCaseLabel: true
11-
# AfterClass: false
12-
# AfterControlStatement: Always
13-
# AfterEnum: false
14-
# AfterFunction: true
15-
# AfterNamespace: false
16-
# AfterStruct: false
17-
# AfterUnion: false
18-
# AfterExternBlock: false
19-
# BeforeCatch: true
20-
# BeforeElse: true
21-
# BeforeWhile: false
22-
# IndentBraces: true
23-
# SplitEmptyFunction: false
24-
# SplitEmptyRecord: false
25-
# SplitEmptyNamespace: false
1+
# Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details.
262

3+
---
4+
Language: Cpp
275
AccessModifierOffset: -4
286
AlignAfterOpenBracket: Align
29-
AlignTrailingComments: false
30-
AllowShortBlocksOnASingleLine: Empty
31-
AllowShortEnumsOnASingleLine: true
32-
AllowShortFunctionsOnASingleLine: Inline
7+
AlignConsecutiveAssignments: false
8+
AlignConsecutiveDeclarations: false
9+
AlignEscapedNewlines: Right
10+
AlignOperands: true
11+
AlignTrailingComments: true
12+
AllowAllParametersOfDeclarationOnNextLine: false
13+
AllowShortBlocksOnASingleLine: false
14+
AllowShortCaseLabelsOnASingleLine: true
15+
AllowShortFunctionsOnASingleLine: true
3316
AllowShortIfStatementsOnASingleLine: false
34-
AllowShortLambdasOnASingleLine: Empty
3517
AllowShortLoopsOnASingleLine: false
18+
AlwaysBreakAfterDefinitionReturnType: None
3619
AlwaysBreakAfterReturnType: None
20+
AlwaysBreakBeforeMultilineStrings: true
21+
AlwaysBreakTemplateDeclarations: Yes
3722
BinPackArguments: true
3823
BinPackParameters: true
39-
BreakConstructorInitializers: BeforeColon
24+
BraceWrapping:
25+
AfterClass: false
26+
AfterControlStatement: false
27+
AfterEnum: false
28+
AfterFunction: false
29+
AfterNamespace: false
30+
AfterObjCDeclaration: false
31+
AfterStruct: false
32+
AfterUnion: false
33+
AfterExternBlock: false
34+
BeforeCatch: false
35+
BeforeElse: true
36+
IndentBraces: false
37+
SplitEmptyFunction: false
38+
SplitEmptyRecord: false
39+
SplitEmptyNamespace: false
40+
BreakBeforeBinaryOperators: None
41+
BreakBeforeBraces: Custom
42+
BreakBeforeInheritanceComma: false
4043
BreakInheritanceList: BeforeColon
41-
ColumnLimit: 100
42-
ConstructorInitializerAllOnOneLineOrOnePerLine: false
43-
FixNamespaceComments: false
44-
IndentCaseLabels: true
45-
IndentCaseBlocks: false
46-
IndentExternBlock: NoIndent
47-
IndentPPDirectives: None
48-
IndentWidth: 4
49-
NamespaceIndentation: None
50-
PointerAlignment: Left
51-
SpaceAfterCStyleCast: false
52-
SpaceAfterLogicalNot: true
53-
SpaceBeforeAssignmentOperators: true
54-
SpaceBeforeCpp11BracedList: false
55-
SpaceBeforeCtorInitializerColon: true
56-
SpaceBeforeInheritanceColon: true
57-
SpaceBeforeParens: ControlStatements
58-
SpaceBeforeRangeBasedForLoopColon: true
59-
SpaceInEmptyBlock: true
60-
SpaceInEmptyParentheses: false
61-
SpacesInAngles: false
62-
SpacesInConditionalStatement: true
63-
SpacesInContainerLiterals: false
64-
SpacesInParentheses: false
65-
TabWidth: 4
66-
UseTab: AlignWithSpaces
67-
68-
# Setting this to a high number causes clang-format to prefer breaking somewhere else
69-
# over breaking after the assignment operator in a line that's over the column limit
70-
PenaltyBreakAssignment: 100
71-
44+
BreakBeforeTernaryOperators: false
45+
BreakConstructorInitializersBeforeComma: false
46+
BreakConstructorInitializers: BeforeColon
47+
BreakAfterJavaFieldAnnotations: false
48+
BreakStringLiterals: true
49+
ColumnLimit: 120
50+
CommentPragmas: 'NOLINT'
51+
CompactNamespaces: false
52+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
53+
ConstructorInitializerIndentWidth: 4
54+
ContinuationIndentWidth: 4
55+
Cpp11BracedListStyle: true
56+
DerivePointerAlignment: false
57+
DisableFormat: false
58+
ExperimentalAutoDetectBinPacking: false
59+
FixNamespaceComments: true
60+
ForEachMacros:
61+
- foreach
62+
- Q_FOREACH
63+
- BOOST_FOREACH
7264
IncludeBlocks: Regroup
7365

7466
# Include categories go like this:
@@ -98,3 +90,57 @@ IncludeCategories:
9890
Priority: 4
9991
- Regex: '.*'
10092
Priority: 5
93+
94+
IncludeIsMainRegex: '$'
95+
IndentCaseLabels: true
96+
IndentPPDirectives: None
97+
IndentWidth: 4
98+
IndentWrappedFunctionNames: false
99+
JavaScriptQuotes: Leave
100+
JavaScriptWrapImports: true
101+
KeepEmptyLinesAtTheStartOfBlocks: false
102+
MacroBlockBegin: '^BEGIN_'
103+
MacroBlockEnd: '^END_'
104+
MaxEmptyLinesToKeep: 2
105+
NamespaceIndentation: None
106+
ObjCBinPackProtocolList: Auto
107+
ObjCBlockIndentWidth: 2
108+
ObjCSpaceAfterProperty: false
109+
ObjCSpaceBeforeProtocolList: true
110+
PenaltyBreakAssignment: 2
111+
PenaltyBreakBeforeFirstCallParameter: 500
112+
PenaltyBreakComment: 300
113+
PenaltyBreakFirstLessLess: 120
114+
PenaltyBreakString: 1000
115+
PenaltyBreakTemplateDeclaration: 10
116+
PenaltyExcessCharacter: 1000000
117+
PenaltyReturnTypeOnItsOwnLine: 1000
118+
PointerAlignment: Left
119+
ReflowComments: true
120+
SortIncludes: true
121+
SortUsingDeclarations: true
122+
SpaceAfterCStyleCast: false
123+
SpaceAfterTemplateKeyword: false
124+
SpaceAfterLogicalNot: true
125+
SpaceBeforeAssignmentOperators: true
126+
SpaceBeforeCpp11BracedList: false
127+
SpaceBeforeCtorInitializerColon: true
128+
SpaceBeforeInheritanceColon: true
129+
SpaceBeforeParens: ControlStatements
130+
SpaceBeforeRangeBasedForLoopColon: true
131+
SpaceInEmptyParentheses: false
132+
SpacesBeforeTrailingComments: 1
133+
SpacesInAngles: false
134+
SpacesInContainerLiterals: true
135+
SpacesInCStyleCastParentheses: false
136+
SpacesInParentheses: false
137+
SpacesInSquareBrackets: false
138+
SpacesInConditionalStatement: true
139+
Standard: Cpp11
140+
StatementMacros:
141+
- STANDARD_OPERATOR_1
142+
TabWidth: 4
143+
UseTab: Never
144+
---
145+
Language: Json
146+
...

.pre-commit-config.yaml

+20-4
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,33 @@
33
#
44
repos:
55
- repo: https://github.com/pre-commit/mirrors-clang-format
6-
rev: 'v13.0.0'
6+
rev: 'v17.0.3'
77
hooks:
88
- id: clang-format
9+
types_or:
10+
- "c"
11+
- "c++"
12+
- "json"
913

1014
- repo: https://github.com/maxwinterstein/shfmt-py
11-
rev: 3.3.1.8
15+
rev: v3.7.0.1
1216
hooks:
1317
- id: shfmt
1418
args: ["-w", "-i", "4", "-ci"]
1519

16-
- repo: https://github.com/pre-commit/mirrors-yapf
17-
rev: v0.31.0
20+
- repo: https://github.com/google/yapf
21+
rev: v0.40.2
1822
hooks:
1923
- id: yapf
24+
25+
- repo: https://github.com/cheshirekow/cmake-format-precommit
26+
rev: v0.6.13
27+
hooks:
28+
- id: cmake-format
29+
exclude: '^auxil/.*$'
30+
31+
- repo: https://github.com/crate-ci/typos
32+
rev: v1.16.21
33+
hooks:
34+
- id: typos
35+
exclude: '^(.typos.toml|src/SmithWaterman.cc|testing/.*|auxil/.*|scripts/base/frameworks/files/magic/.*|CHANGES)$'

CMakeLists.txt

+46-45
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,74 @@ include(cmake/CommonCMakeConfig.cmake)
66
find_package(BISON REQUIRED)
77
find_package(FLEX REQUIRED)
88

9-
if (MSVC)
9+
if(MSVC)
1010
add_compile_options(/J) # Similar to -funsigned-char on other platforms
11-
set_property(SOURCE bif_lex.cc APPEND_STRING PROPERTY COMPILE_FLAGS "/wd4018")
11+
set_property(
12+
SOURCE bif_lex.cc
13+
APPEND_STRING
14+
PROPERTY COMPILE_FLAGS "/wd4018")
1215
else()
13-
set_property(SOURCE bif_lex.cc APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-sign-compare")
16+
set_property(
17+
SOURCE bif_lex.cc
18+
APPEND_STRING
19+
PROPERTY COMPILE_FLAGS "-Wno-sign-compare")
1420
endif()
1521

16-
include_directories(BEFORE
17-
${BifCl_SOURCE_DIR}/include
18-
${BifCl_BINARY_DIR}
19-
)
22+
include_directories(BEFORE ${BifCl_SOURCE_DIR}/include ${BifCl_BINARY_DIR})
2023

2124
set(BISON_FLAGS "--debug")
2225

2326
# BIF parser/scanner
24-
bison_target(BIFParser builtin-func.y
25-
${BifCl_BINARY_DIR}/bif_parse.cc
26-
DEFINES_FILE ${BifCl_BINARY_DIR}/bif_parse.h
27-
COMPILE_FLAGS "${BISON_FLAGS}")
27+
bison_target(
28+
BIFParser builtin-func.y ${BifCl_BINARY_DIR}/bif_parse.cc
29+
DEFINES_FILE ${BifCl_BINARY_DIR}/bif_parse.h
30+
COMPILE_FLAGS "${BISON_FLAGS}")
2831
flex_target(BIFScanner builtin-func.l ${BifCl_BINARY_DIR}/bif_lex.cc)
2932
add_flex_bison_dependency(BIFScanner BIFParser)
3033

3134
set(bifcl_SRCS
32-
${BISON_BIFParser_INPUT}
33-
${FLEX_BIFScanner_INPUT}
34-
${BISON_BIFParser_OUTPUTS}
35-
${FLEX_BIFScanner_OUTPUTS}
36-
bif_arg.cc
37-
include/bif_arg.h
38-
module_util.cc
39-
include/module_util.h
40-
)
35+
${BISON_BIFParser_INPUT}
36+
${FLEX_BIFScanner_INPUT}
37+
${BISON_BIFParser_OUTPUTS}
38+
${FLEX_BIFScanner_OUTPUTS}
39+
bif_arg.cc
40+
include/bif_arg.h
41+
module_util.cc
42+
include/module_util.h)
4143

4244
add_executable(bifcl ${bifcl_SRCS})
4345
target_compile_features(bifcl PRIVATE cxx_std_17)
4446
set_target_properties(bifcl PROPERTIES CXX_EXTENSIONS OFF)
4547

46-
if (MSVC)
47-
# If building separately from zeek, we need to add the libunistd subdirectory so
48-
# that linking doesn't fail.
49-
if ("${CMAKE_PROJECT_NAME}" STREQUAL "BifCl")
50-
add_subdirectory(auxil/libunistd EXCLUDE_FROM_ALL)
51-
endif()
52-
target_link_libraries(bifcl PRIVATE libunistd)
48+
if(MSVC)
49+
# If building separately from zeek, we need to add the libunistd subdirectory
50+
# so that linking doesn't fail.
51+
if("${CMAKE_PROJECT_NAME}" STREQUAL "BifCl")
52+
add_subdirectory(auxil/libunistd EXCLUDE_FROM_ALL)
53+
endif()
54+
target_link_libraries(bifcl PRIVATE libunistd)
5355
endif()
5456

5557
install(TARGETS bifcl DESTINATION bin)
5658

57-
if (CMAKE_BUILD_TYPE)
58-
string(TOUPPER ${CMAKE_BUILD_TYPE} BuildType)
59-
endif ()
59+
if(CMAKE_BUILD_TYPE)
60+
string(TOUPPER ${CMAKE_BUILD_TYPE} BuildType)
61+
endif()
6062

6163
message(
62-
"\n====================| Bifcl Build Summary |====================="
63-
"\n"
64-
"\nBuild type: ${CMAKE_BUILD_TYPE}"
65-
"\nBuild dir: ${PROJECT_BINARY_DIR}"
66-
"\nInstall prefix: ${CMAKE_INSTALL_PREFIX}"
67-
"\nDebug mode: ${ENABLE_DEBUG}"
68-
"\n"
69-
"\nCC: ${CMAKE_C_COMPILER}"
70-
"\nCFLAGS: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BuildType}}"
71-
"\nCXX: ${CMAKE_CXX_COMPILER}"
72-
"\nCXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BuildType}}"
73-
"\nCPP: ${CMAKE_CXX_COMPILER}"
74-
"\n"
75-
"\n================================================================\n"
76-
)
64+
"\n====================| Bifcl Build Summary |====================="
65+
"\n"
66+
"\nBuild type: ${CMAKE_BUILD_TYPE}"
67+
"\nBuild dir: ${PROJECT_BINARY_DIR}"
68+
"\nInstall prefix: ${CMAKE_INSTALL_PREFIX}"
69+
"\nDebug mode: ${ENABLE_DEBUG}"
70+
"\n"
71+
"\nCC: ${CMAKE_C_COMPILER}"
72+
"\nCFLAGS: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BuildType}}"
73+
"\nCXX: ${CMAKE_CXX_COMPILER}"
74+
"\nCXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BuildType}}"
75+
"\nCPP: ${CMAKE_CXX_COMPILER}"
76+
"\n"
77+
"\n================================================================\n")
7778

7879
include(UserChangedWarning)

0 commit comments

Comments
 (0)