3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-10-08 17:01:55 +00:00

Add .clang-format file for consistent C++ code formatting

This addresses issue #1441 by providing a comprehensive clang-format
configuration that matches Z3's existing C++ coding style patterns.

Key features:
- 4-space indentation consistent with existing Z3 code
- Preserves existing include organization (no auto-sorting)
- Left-aligned pointers/references (type* var style)
- Attach brace style for control statements
- 120 character line limit
- Proper spacing and alignment rules

Usage:
  clang-format --sort-includes=false -i <file>     # Format file in-place
  git clang-format --style=file                    # Format staged changes

Based on analysis of existing Z3 source code patterns in:
- src/ast/*.cpp and src/ast/*.h files
- src/api/*.cpp and src/api/*.h files
- src/smt/*.cpp files
- Various utility and core library files

Resolves #1441
This commit is contained in:
Daily Backlog Burner 2025-09-17 01:32:57 +00:00
parent 81da4be228
commit be174cef87

108
.clang-format Normal file
View file

@ -0,0 +1,108 @@
# Z3 C++ Code Style Configuration for clang-format
# Based on analysis of existing Z3 source code patterns
#
# Usage:
# clang-format --sort-includes=false -i <file> # Format file in-place
# git clang-format --style=file # Format staged changes
#
# References:
# - https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# - Issue #1441: https://github.com/Z3Prover/z3/issues/1441
BasedOnStyle: LLVM
# Indentation - Z3 uses 4-space indentation
IndentWidth: 4
TabWidth: 4
UseTab: Never
ContinuationIndentWidth: 4
ConstructorInitializerIndentWidth: 4
AccessModifierOffset: -4
IndentCaseLabels: false
# Line length and wrapping
ColumnLimit: 120
ReflowComments: true
# Brace wrapping - Z3 uses mixed style
BreakBeforeBraces: Attach # Braces attach to control statements, but classes/functions on new line
# Spacing around pointers and references - Z3 uses "type* var" style
PointerAlignment: Left
ReferenceAlignment: Left
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
# Function and method formatting
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: true
BinPackParameters: true
# Constructor and class formatting
BreakConstructorInitializers: BeforeComma
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Cpp11BracedListStyle: true
# Template formatting
SpaceAfterTemplateKeyword: true
# Include sorting - preserve Z3's existing organization
SortIncludes: Never
IncludeBlocks: Preserve
# Statement formatting
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
# Break formatting
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakStringLiterals: true
CompactNamespaces: false
# Comment formatting
CommentPragmas: '^(IWYU pragma:|NOLINT)'
DisableFormat: false
# Penalty settings for line breaking decisions
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
# Namespace formatting
NamespaceIndentation: None
FixNamespaceComments: false
# Language standard
Standard: Cpp11
# Keep empty lines
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
# Alignment
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
# Preprocessor formatting
IndentPPDirectives: None