#author("2020-08-08T12:13:53+00:00","","") #author("2021-03-26T14:05:40+00:00","","") #topicpath ////////////////////////////////////////////////////////////////////////////// * 目次 [#zf6aaa09] #contents(); ////////////////////////////////////////////////////////////////////////////// * 書式オプション(抜粋) [#cbbe2cff] - clang-format で使用される書式設定ファイル ''.clang-format'' に記述するオプションについて記載する。 //============================================================================ ** Language: [#Language] |~val |~description | |None |使用しない | |Cpp |C, C++, Objective-C, Objective-C++ を使用する | |Java |Java を使用する | |JavaScript |JavaScript を使用する | |Proto |[[Protocol Buffers>https://developers.google.com/protocol-buffers/]] | //============================================================================ ** AccessModifierOffset: [#AccessModifierOffset] - アクセス修飾子(C++ class の public:, private:, protected: など)の追加のインデント幅を指定する。 - パラメータと挙動 -- ''0'' class CFoo : public CSuperFoo { public: CFoo(int ini_a, char* ini_b) : m_a(ini_a), m_b(ini_b), m_c{} {} private: char* m_b; uint64_t m_c; }; -- ''-2'' class CFoo : public CSuperFoo { public: CFoo(int ini_a, char* ini_b) : m_a(ini_a), m_b(ini_b), m_c{} {} private: int m_a; char* m_b; uint64_t m_c; }; -- ''-4'' class CFoo : public CSuperFoo { public: CFoo(int ini_a, char* ini_b) : m_a(ini_a), m_b(ini_b), m_c{} {} private: int m_a; char* m_b; uint64_t m_c; }; //============================================================================ ** AlignAfterOpenBracket: [#AlignAfterOpenBracket] - 括弧 (()、<>、[]) 内のパラメータが1行に収まらない場合の開始括弧の直後の整列方法を指定する。下記の例では、1行を80カラムとしている(ColumnLimit:80) - パラメータと挙動 -- Align // 仮引数は、カラム上限にかかった場合に改行される。仮引数の整列はアリ void func_c(std::string& hoge_name, std::vector<std::string>& name_list, std::vector<uint64_t> param_list) { uint32_t local_count(0); for (std::vector<std::string>::iterator it_of_name_list = name_list.begin(); it_of_name_list != name_list.end(); ++it_of_name_list) { uint32_t ret = sub_func(hoge_name, *it_of_name_list, param_list, local_count); ++local_count; } // カラム上限に達していなければ改行されない for (uint32_t i = 1; i < max_count; ++i) { sub_func_2(hoge_name, name_list, param_list); } } -- DontAlign // 仮引数は、カラム上限にかかった場合に改行される。仮引数の整列はナシ void func_c(std::string& hoge_name, std::vector<std::string>& name_list, std::vector<uint64_t> param_list) { uint32_t local_count(0); for (std::vector<std::string>::iterator it_of_name_list = name_list.begin(); it_of_name_list != name_list.end(); ++it_of_name_list) { uint32_t ret = sub_func(hoge_name, *it_of_name_list, param_list, local_count); ++local_count; } // カラム上限に達していなければ改行されない for (uint32_t i = 1; i < max_count; ++i) { sub_func_2(hoge_name, name_list, param_list); } } -- AlwaysBreak // 仮引数は、先頭と、カラム上限にかかった場合に改行される。結果的に整列されたに等しくなる。 void func_c( std::string& hoge_name, std::vector<std::string>& name_list, std::vector<uint64_t> param_list) { uint32_t local_count(0); for (std::vector<std::string>::iterator it_of_name_list = name_list.begin(); it_of_name_list != name_list.end(); ++it_of_name_list) { uint32_t ret = sub_func(hoge_name, *it_of_name_list, param_list, local_count); ++local_count; } // カラム上限に達していなければ改行されない for (uint32_t i = 1; i < max_count; ++i) { sub_func_2(hoge_name, name_list, param_list); } } //============================================================================ ** AlignConsecutiveAssignments: [#AlignConsecutiveAssignments] - 連続する行の代入式を ''='' で整列するか否か - パラメータと挙動 -- true : 整列する int32_t var_1 = 12; std::string var_2 = "foo"; const char* const var_3 = "bar"; -- false : 整列しない int32_t var_1 = 12; std::string var_2 = "foo"; const char* const var_3 = "bar"; //============================================================================ ** AlignConsecutiveDeclarations: [#AlignConsecutiveDeclarations] - 連続する行の宣言の変数名を整列させるか否か - パラメータと挙動 -- true : 整列する int32_t var_11 = 12; std::string var_2 = "foo"; const char* const var_3 = "bar"; -- false : 整列しない int32_t var_11 = 12; std::string var_2 = "foo"; const char* const var_3 = "bar"; //============================================================================ ** AlignEscapedNewlinesLeft: [#AlignEscapedNewlinesLeft] - エスケープされた改行の位置を調整する - パラメータと挙動 -- true : 可能な限り左に寄せる #define LOG_PREFIX \ "[DEBUG]" \ "[MODULE_A]" \ "[MOD_SUB_2]" -- false : column limit に配置する // ColumnLimit: 80 の場合 #define LOG_PREFIX \ "[DEBUG]" \ "[MODULE_A]" \ "[MOD_SUB_2]" //============================================================================ ** AlignOperands: [#n00eac18] //============================================================================ ** AlignTrailingComments: [#vfbf452b] //============================================================================ ** AllowAllParametersOfDeclarationOnNextLine: [#sae7368d] //============================================================================ ** AllowShortBlocksOnASingleLine: [#AllowShortBlocksOnASingleLine] - 短いブレース文を単一の行に押し込むか否か - パラメータと挙動 - true : 単一行に押し込む if (arg > 10) { var_11 += arg; } - false : 単一行に押し込まない if (arg > 10) { var_11 += arg; } - 但し、以下のような構造体初期化文には効力がない模様 st_aaa aaa = { 0, }; //============================================================================ ** AllowShortCaseLabelsOnASingleLine: [#z131c8bc] ** AllowShortCaseLabelsOnASingleLine: [#AllowShortCaseLabelsOnASingleLine] - switch-case 文に於いて、短い case 文を1行で書くことを許容するか否かを指定する。 - true 短い case 文を1行にする switch (tcx_type) { case TCX_TYPE1: break; case TCX_TYPE2: break; case TCX_TYPE2_NORMAL_STYLE: break; case TCX_TYPE3: break; case TCX_TYPE3_______________________________LONG: break; default: break; } - false 短い case 文を1行にしない。 switch (tcx_type) { case TCX_TYPE1: break; case TCX_TYPE2: break; case TCX_TYPE2_NORMAL_STYLE: break; case TCX_TYPE3: break; case TCX_TYPE3_______________________________LONG: break; default: break; } //============================================================================ ** AllowShortFunctionsOnASingleLine: [#dce76bfa] //============================================================================ ** AllowShortIfStatementsOnASingleLine: [#w26c3548] //============================================================================ ** AllowShortLoopsOnASingleLine: [#kff2e776] //============================================================================ ** AlwaysBreakAfterDefinitionReturnType: [#e2cf0f79] //============================================================================ ** AlwaysBreakAfterReturnType: [#u32cd482] //============================================================================ ** AlwaysBreakBeforeMultilineStrings: [#v40e1938] //============================================================================ ** AlwaysBreakTemplateDeclarations: [#y25557f4] //============================================================================ ** BinPackArguments: [#ia3d009b] //============================================================================ ** BinPackParameters: [#v9fb1dea] //============================================================================ ** BraceWrapping: [#n9ac2f6f] //---------------------------------------------------------------------------- *** AfterClass: [#r3ca3958] //---------------------------------------------------------------------------- *** AfterControlStatement: [#kae57280] //---------------------------------------------------------------------------- *** AfterEnum: [#k51b89c7] //---------------------------------------------------------------------------- *** AfterFunction: [#a31f9cf9] //---------------------------------------------------------------------------- *** AfterNamespace: [#c3c1226f] //---------------------------------------------------------------------------- *** AfterObjCDeclaration: [#c89d4168] //---------------------------------------------------------------------------- *** AfterStruct: [#g2564b61] //---------------------------------------------------------------------------- *** AfterUnion: [#haacaa46] //---------------------------------------------------------------------------- *** BeforeCatch: [#ae2a006c] //---------------------------------------------------------------------------- *** BeforeElse: [#m3b859c3] //---------------------------------------------------------------------------- *** IndentBraces: [#w79f7cc5] //============================================================================ ** BreakBeforeBinaryOperators: [#eba844fb] |~style |~style option | |LLVM |BasedOnStyle: LLVM | |google |BasedOnStyle: Google | |Chromium |BasedOnStyle: Chromium | |Mozilla |BasedOnStyle: Mozilla | |WebKit |BasedOnStyle: WebKit | |linux |BasedOnStyle: LLVM | |~| IndentWidth: 8 | |~| UseTab: Always | |~| BreakBeforeBraces: Linux | |~| AllowShortIfStatementsOnASingleLine: false | |~| IndentCaseLabels: false | |Visual Studio |UseTab: Never | |~| IndentWidth: 4 | |~| BreakBeforeBraces: Allman | |~| AllowShortIfStatementsOnASingleLine: false | |~| IndentCaseLabels: false | |~| ColumnLimit: 0 | //============================================================================ ** BreakBeforeBraces: [#BreakBeforeBraces] - 波括弧 ''{ }'' の改行の設定 - パラメータと挙動 -- Attach // 波括弧は常に周囲のコンテキストにくっつける。 enum HOGE_EN { EN_AAA, EN_ABC, EN_ZZZ, }; struct st_aaa { int aaa[2]; uint64_t ax; }; void func(int arg) { // ... if (arg == 0) { // ... } else { // ... } return; } -- Linux // Attach に似るが、関数や名前空間、クラス定義の前は改行する。 enum HOGE_EN { EN_AAA, EN_ABC, EN_ZZZ, }; struct st_aaa { int aaa[2]; uint64_t ax; }; void func(int arg) { // ... if (arg == 0) { // ... } else { // ... } return; } -- Mozilla // Attach と似るが、 enum、関数定義などの前には改行する。 enum HOGE_EN { EN_AAA, EN_ABC, EN_ZZZ, }; struct st_aaa { int aaa[2]; uint64_t ax; }; void func(int arg) { // ... if (arg == 0) { // ... } else { // ... } return; } -- Stroustrup // Attach と似るが、catch, else などの前は改行する。 enum HOGE_EN { EN_AAA, EN_ABC, EN_ZZZ, }; struct st_aaa { int aaa[2]; uint64_t ax; }; void func(int arg) { // ... if (arg == 0) { // ... } else { // ... } return; } -- Allman // 波括弧の前は全て改行する。 enum HOGE_EN { EN_AAA, EN_ABC, EN_ZZZ, }; struct st_aaa { int aaa[2]; uint64_t ax; }; void func(int arg) { // ... if (arg == 0) { // ... } else { // ... } return; } -- GNU // 波括弧の前は全て改行するし、新たにインデントを加える。但し、クラス定義や関数定義などの場合は除く。 enum HOGE_EN { EN_AAA, EN_ABC, EN_ZZZ, }; struct st_aaa { int aaa[2]; uint64_t ax; }; void func(int arg) { // ... if (arg == 0) { // ... } else { // ... } return; } //============================================================================ ** BreakBeforeTernaryOperators: [#sffea887] //============================================================================ ** BreakConstructorInitializersBeforeComma: [#r8e30fba] - コンストラクタの変数初期化のコンマの前で改行し、コンマとコロンを整列させるかどうか - パラメータと挙動 -- true -- false //============================================================================ ** ColumnLimit: [#ColumnLimit] - 行の長さの上限値。 - 0 に設定した場合は、上限なしとなる。 //============================================================================ ** CommentPragmas: [#u99be49b] //============================================================================ ** ConstructorInitializerAllOnOneLineOrOnePerLine: [#r75290fb] //============================================================================ ** ConstructorInitializerIndentWidth: [#ze984459] //============================================================================ ** ContinuationIndentWidth: [#aaefdf2a] //============================================================================ ** Cpp11BracedListStyle: [#iedfc19b] //============================================================================ ** DerivePointerAlignment: [#f9b31830] //============================================================================ ** DisableFormat: [#v21da5cf] //============================================================================ ** ExperimentalAutoDetectBinPacking: [#q9649d58] //============================================================================ ** ForEachMacros: [#e39475f0] //============================================================================ ** IncludeCategories: [#ucb42990] //---------------------------------------------------------------------------- *** - [#be585d44] //---------------------------------------------------------------------------- *** Priority: [#lc646fac] //---------------------------------------------------------------------------- *** - [#w1262625] //---------------------------------------------------------------------------- *** Priority: [#hde528d1] //---------------------------------------------------------------------------- *** - [#l3196565] //---------------------------------------------------------------------------- *** Priority: [#g1cb84bf] //============================================================================ ** IndentCaseLabels: [#x3a42b57] //============================================================================ ** IndentWidth: [#d4935225] //============================================================================ ** IndentWrappedFunctionNames: [#vb5d40c0] //============================================================================ ** KeepEmptyLinesAtTheStartOfBlocks: [#n643d905] //============================================================================ ** MacroBlockBegin: [#h7d1a026] //============================================================================ ** MacroBlockEnd: [#k77ca862] //============================================================================ ** MaxEmptyLinesToKeep: [#mf4db716] //============================================================================ ** NamespaceIndentation: [#o82a7483] //============================================================================ ** ObjCBlockIndentWidth: [#d2ad2676] //============================================================================ ** ObjCSpaceAfterProperty: [#p8f59fc2] //============================================================================ ** ObjCSpaceBeforeProtocolList: [#rc1aedf9] //============================================================================ ** PenaltyBreakBeforeFirstCallParameter: [#b8c42877] //============================================================================ ** PenaltyBreakComment: [#s63e6446] //============================================================================ ** PenaltyBreakFirstLessLess: [#v647e833] //============================================================================ ** PenaltyBreakString: [#qbd919c2] //============================================================================ ** PenaltyExcessCharacter: [#t230560c] //============================================================================ ** PenaltyReturnTypeOnItsOwnLine: [#cc33121d] //============================================================================ ** PointerAlignment: [#v30bb7ce] //============================================================================ ** ReflowComments: [#ucf9ed66] //============================================================================ ** SortIncludes: [#b6797f9d] //============================================================================ ** SpaceAfterCStyleCast: [#uebb1034] //============================================================================ ** SpaceBeforeAssignmentOperators: [#x29447e9] //============================================================================ ** SpaceBeforeParens: [#iacb23cc] //============================================================================ ** SpaceInEmptyParentheses: [#t24393b1] //============================================================================ ** SpacesBeforeTrailingComments: [#da132129] //============================================================================ ** SpacesInAngles: [#i7770e5a] //============================================================================ ** SpacesInContainerLiterals: [#k77db928] //============================================================================ ** SpacesInCStyleCastParentheses: [#w07105c2] //============================================================================ ** SpacesInParentheses: [#d281fbe1] //============================================================================ ** SpacesInSquareBrackets: [#m8113bc9] //============================================================================ ** Standard: [#z92f7f34] //============================================================================ ** TabWidth: [#pbdbd121] //============================================================================ ** UseTab: [#f5d7899e] ////////////////////////////////////////////////////////////////////////////// * 参考リンク [#links] - [[ClangFormat — Algo13 2016.12.17 ドキュメント>http://algo13.net/clang/clang-format-style-oputions.html]] - [[clang-format を イイ感じに設定する - def yasuharu519(self):>https://yasuharu519.hatenablog.com/entry/2015/12/13/210825]]