Based off of Linux kernel style with some local modifications and DPDK foreach macros.
A couple of open questions to be resolved befor merging. Is GPL license ok for config file (inherited from Linux here)? Do we want to have per-driver files for some drivers (like MLX5)? Signed-off-by: Stephen Hemminger <step...@networkplumber.org> --- .clang-format | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000000..ad4d30520253 --- /dev/null +++ b/.clang-format @@ -0,0 +1,181 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# clang-format configuration file. Intended for clang-format >= 11. +# +# For more information, see: +# +# Documentation/process/clang-format.rst +# https://clang.llvm.org/docs/ClangFormat.html +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html +# +--- +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: All +AlwaysBreakBeforeMultilineStrings: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: false +ColumnLimit: 100 +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 8 +ContinuationIndentWidth: 8 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false + +# Taken from: +# git grep -h '^#define [^[:space:]]*[A-Z_]*FOREACH[A-Z_]*' lib/ drivers/ \ +# | sed "s,^#define \([:space:]]*[A-Z_]*FOREACH[A-Z_]*\)(.*$, - \1," \ +# | LC_ALL=C sort -u +ForEachMacros: + - CIRBUF_FOREACH + - FOREACH_ABS_FUNC_IN_PORT + - FOREACH_DEVICE_ON_AUXILARY_BUS + - FOREACH_DEVICE_ON_PCIBUS + - FOREACH_DEVICE_ON_PLATFORM_BUS + - FOREACH_DEVICE_ON_VMBUS + - FOREACH_DRIVER_ON_AUXILARY_BUS + - FOREACH_DRIVER_ON_PCIBUS + - FOREACH_DRIVER_ON_PLATFORM_BUS + - FOREACH_DRIVER_ON_VMBUS + - FOREACH_SUBDEV + - FOREACH_SUBDEV_STATE + - ILIST_FOREACH + - LIST_FOREACH + - LIST_FOREACH_FROM + - LIST_FOREACH_FROM_SAFE + - LIST_FOREACH_SAFE + - MLX5_ETH_FOREACH_DEV + - MLX5_IPOOL_FOREACH + - MLX5_L3T_FOREACH + - ML_AVG_FOREACH_QP + - ML_AVG_RESET_FOREACH_QP + - ML_MAX_FOREACH_QP + - ML_MAX_RESET_FOREACH_QP + - ML_MIN_FOREACH_QP + - ML_MIN_RESET_FOREACH_QP + - PLT_TAILQ_FOREACH_SAFE + - RTE_BBDEV_FORWEACH + - RTE_DEV_FOREACH + - RTE_EAL_DEVARGS_FOREACH + - RTE_ETH_FOREACH_DEV + - RTE_ETH_FOREACH_DEV_OWNED_BY + - RTE_ETH_FOREACH_DEV_SIBLING + - RTE_ETH_FOREACH_MATCHING_DEV + - RTE_ETH_FOREACH_VALID_DEV + - RTE_GPU_FOREACH + - RTE_GPU_FOREACH_CHILD + - RTE_GPU_FOREACH_PARENT + - RTE_LCORE_FOREACH + - RTE_LCORE_FOREACH_WORKER + - RTE_TAILQ_FOREACH + - RTE_TAILQ_FOREACH_SAFE + - SILIST_FOREACH + - SLIST_FOREACH + - SLIST_FOREACH_FROM + - SLIST_FOREACH_FROM_SAFE + - SLIST_FOREACH_SAFE + - STAILQ_FOREACH + - TAILQ_FOREACH + - TAILQ_FOREACH_ENTRY + - TAILQ_FOREACH_ENTRY_SAFE + - TAILQ_FOREACH_FROM_SAFE + - TAILQ_FOREACH_SAFE + - json_array_foreach + - json_object_foreach + - rte_graph_foreach + - rte_graph_foreach_node + - vdev_netvsc_foreach_iface + +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentGotoLabels: false +IndentPPDirectives: None +IndentWidth: 8 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 8 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true + +# Taken from git's rules +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 30 +PenaltyBreakComment: 10 +PenaltyBreakFirstLessLess: 0 +PenaltyBreakString: 10 +PenaltyExcessCharacter: 100 +PenaltyReturnTypeOnItsOwnLine: 60 + +PointerAlignment: Right +ReflowComments: false +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatementsExceptForEachMacros +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp03 +TabWidth: 8 +UseTab: Always +... -- 2.39.2