From 949ab6c9f956ce4d68787a9854c27b402f6e9ec5 Mon Sep 17 00:00:00 2001 From: Steffen Schulz Date: Thu, 8 Sep 2022 07:54:02 -0700 Subject: [PATCH] add a .clang-format for Qemu style plus various fixes Based on https://gist.githubusercontent.com/elmarco/aa5e0b23567f46fb7f0e73cde586a0c1/raw/bab9fdd5d10e94410c8760c1379132241225a3cd/.clang-format --- .clang-format | 113 +++++++++++++++++++++++++++++++++++++++++++ .clang-format-ignore | 2 + 2 files changed, 115 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-format-ignore diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..7706453ba9 --- /dev/null +++ b/.clang-format @@ -0,0 +1,113 @@ +# Style based on https://gist.github.com/elmarco/aa5e0b23567f46fb7f0e73cde586a0c1 +# Discussion: https://lore.kernel.org/all/1443720628-16512-1-git-send-email-marcandre.lureau@redhat.com/ +# +# See also: +# https://clang.llvm.org/docs/ClangFormat.html +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html +--- +Language: Cpp +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: true +AlignArrayOfStructures: Right +AlignConsecutiveDeclarations: true +AlignConsecutiveMacros: true +AlignTrailingComments: true +AlignEscapedNewlinesLeft: true +AlignOperands: true +AlignTrailingComments: true +AlignConsecutiveBitFields: true + +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None # AlwaysBreakAfterDefinitionReturnType is taken into account +AlwaysBreakBeforeMultilineStrings: false +BinPackArguments: true +BinPackParameters: false + +BreakBeforeBinaryOperators: None #NonAssignment +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: false +BreakStringLiterals: true + +BraceWrapping: + AfterControlStatement: MultiLine # need for multi-line if() { + AfterEnum: false + AfterFunction: true + AfterStruct: false + AfterUnion: false + BeforeElse: false + IndentBraces: false + +DerivePointerAlignment: false +PointerAlignment: Right +ReferenceAlignment: Right +SpaceAroundPointerQualifiers: Default + +# CommentPragmas: '^ IWYU pragma:' +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DisableFormat: false +ForEachMacros: [ + 'CPU_FOREACH', + 'CPU_FOREACH_REVERSE', + 'CPU_FOREACH_SAFE', + 'IOMMU_NOTIFIER_FOREACH', + 'QLIST_FOREACH', + 'QLIST_FOREACH_ENTRY', + 'QLIST_FOREACH_RCU', + 'QLIST_FOREACH_SAFE', + 'QLIST_FOREACH_SAFE_RCU', + 'QSIMPLEQ_FOREACH', + 'QSIMPLEQ_FOREACH_SAFE', + 'QSLIST_FOREACH', + 'QSLIST_FOREACH_SAFE', + 'QTAILQ_FOREACH', + 'QTAILQ_FOREACH_REVERSE', + 'QTAILQ_FOREACH_SAFE', + 'QTAILQ_RAW_FOREACH', + 'RAMBLOCK_FOREACH' +] +IncludeCategories: + - Regex: '^"qemu/osdep.h' + Priority: -3 + - Regex: '^"(block|chardev|crypto|disas|exec|fpu|hw|io|libdecnumber|migration|monitor|net|qapi|qemu|qom|standard-headers|sysemu|ui)/' + Priority: -2 + - Regex: '^"(elf.h|qemu-common.h|glib-compat.h|qemu-io.h|trace-tcg.h)' + Priority: -1 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '$' +IndentCaseLabels: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '.*_BEGIN$' # only PREC_BEGIN ? +MacroBlockEnd: '.*_END$' +MaxEmptyLinesToKeep: 2 + +ColumnLimit: 85 +PenaltyExcessCharacter: 10 +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 200 +PenaltyReturnTypeOnItsOwnLine: 200 +PenaltyBreakFirstLessLess: 400 +PenaltyBreakComment: 500 +PenaltyBreakString: 500 + +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +UseTab: Never +... diff --git a/.clang-format-ignore b/.clang-format-ignore new file mode 100644 index 0000000000..e45bf4d908 --- /dev/null +++ b/.clang-format-ignore @@ -0,0 +1,2 @@ +nyx/khash.h +nyx/mmh3.c