Clang-format-options Chinese translation (not to be continued)

Source: Internet
Author: User
Tags function definition parent directory

Update log:

2017/07/12 10:17 Update to

A simple way to get the available. Clang-format files and include all the configuration options for a predefined style:

2017/07/13 0:34 Update to

alignconsecutivedeclarations (BOOL)

2017/07/15 0:34 Update to

binpackparameters (BOOL)

Original address: http://clang.llvm.org/docs/ClangFormatStyleOptions.html

Clang-format Style Options

The Clang-format style options describe the configurable formatting styles that are supported by Libformat and Clangformat.

When using the clang-format tool or the Clang::format::reformat (...) in the code under the command line Functions, you can create custom styles using defined code styles (LLVM, Google, Chromium, Mozilla, WebKit) or by configuring specific style options.

# # # # Clang-format configuration style

Clang-format supports two custom style options: Specify the style configuration directly from the-style= command line, or use the-style=file and place the style configuration in the project directory. Clang-format or _ The Clang-format file.

When using-style=file, Clang-format tries to find the. clang-format file in the nearest parent directory for each input file. When using standard input, the lookup starts at the current directory.

. Clang-format using the Yaml style:

Key1:value1
key2:value2
# A comment.
...

The configuration file consists of several parts, each with a different language: The parameter describes the programming language for that part. Refer to the following language option descriptions for a list of supported languages. The first part may not have a language set, The default formatting options are used for all languages. Configuration for a specific language overrides the default configuration options.

When Clang-format formats a file, it automatically detects the language by its file name. When using standard input or a file with an extension that does not have a corresponding language, the-assume-filename= option can be used to overwrite the file name so that Clang-format gets the language automatically.

A sample configuration file for multiple languages

---
# We ll use defaults from the LLVM style, but with 4 columns indentation.
BASEDONSTYLE:LLVM
indentwidth:4
---
language:cpp
# Force pointers to the type for C + +.
Derivepointeralignment:false
pointeralignment:left
---
language:javascript
# Use Columns For JS.
columnlimit:100
---
language:proto
# Don ' t format. Proto files.
Disableformat:true ...

A simple way to get the available. Clang-format files and include all the configuration options for a predefined style:

Clang-format-style=llvm-dump-config >. clang-format

When you use the-style= option to customize the configuration, all input files will be in the same style. The format of the custom configuration is as follows:

-style= ' {key1:value1, key2:value2, ...} '
Disabling formatting for a piece of code

Clang-format also supports the use of special annotations to switch styles to a limited range of code. In comments//clang-format off (or/* clang-format off */) and//clang-format on (or/* The code between Clang-format on * * will not be formatted. The comment itself will still be formatted (aligned).

int formatted_code;
Clang-format off
    void    Unformatted_code  ;
Clang-format on
void Formatted_code_again;
Configuring styles in code

When using Clang::format::reformat (...) When you wait for a function, the format style will specify configurable format style options by using Clang::format::formatstyle

This section lists the supported style options. Each option can be specified as a value type. For enumeration types, values may be specified as C + + enumeration members (prefixed, for example, Ls_auto), and values available in the configuration (Auto with no prefix).

Basedonstyle (string)

This style is used for option styles other than those specifically set.

This option is only supported in the Clang-format configuration (-style={} and. clang-format files).

Desirable value: LLVM will use the style of the LLVM code standard Google will use the style of the Google C + + code guide Chromium will use the Chromium Code guide style Mozilla will use the style of the Mozilla Code guide WebKit will use the style of the WebKit Code guide

Accessmodifieroffset (int)

Indents or bulges of access modifiers, such as public

Alignafteropenbracket (Bracketalignmentstyle)

If true, keep the horizontal alignment after opening the brackets.

This applies to parentheses (parentheses), angle brackets, and square brackets.

Desirable value: The Bas_align (Align in configuration) parameter is aligned according to the opening brackets, as follows

Somelongfunction (argument1,
                 argument2);
Bas_dontalign (dontalign in configuration) is not aligned, use Continuationindentwidth, as follows
Somelongfunction (argument1,
    argument2);
Bas_alwaysbreak (alwaysbreak in configuration) If the argument does not fit on one line, it will wrap in the opening parenthesis, as follows
Somelongfunction (
    argument1, argument2);

alignconsecutiveassignments (BOOL)

If true, the continuous assignment operator is aligned.

This aligns the assignment operators for successive multiline rows. The effect is as follows:

int aaaa = n;
int b    = all;
int CCC  = 23;

alignconsecutivedeclarations (BOOL)

If true, the continuous Declaration is aligned.

This aligns the declared variable names for successive lines. The effect is as follows:

int         aaaa = n;
float       b = all;
std::string CCC = 23;

Alignescapednewlines (Escapednewlinealignmentstyle)

Options for line break ()

Desirable value: Enas_dontalign (dontalign in configuration) line break () is not aligned

#define A \
  int aaaa; \
  int b; \
  int dddddddddd;
Enas_left (left in configuration) line break () try to align to the right
true:
#define A   \
  int aaaa; \
  int b;    \
  int dddddddddd;

False
Enas_right (right in configuration) line break () try to justify
#define A                                                                      \
  int aaaa;                                                                    \
  int b;                                                                       \
  int dddddddddd;

Alignoperands (BOOL)

If true, the operands of the Chi operator and the three-mesh operator are horizontal

Specifically, this splits the single-line expression into multiline alignment, as follows:

int AAA = bbbbbbbbbbbbbbb +
          CCCCCCCCCCCCCCC;

aligntrailingcomments (BOOL)

If true, the annotation is aligned

true:                                   false:
int A;     My comment a      vs.     int A;//my comment a
int b = 2;//comment  b                int b = 2;//comment about B

Allowallparametersofdeclarationonnextline (BOOL)

All parameters are allowed to be dropped one line in the function declaration, unless false.

true:                                   false:
myFunction (foo,                 vs.     myFunction (foo, bar, plop);
           Bar,
           plop);

Allowshortblocksonasingleline (BOOL)

Allow simple statements to be placed on one line

Example: if (a) {return;} will be on one line

Allowshortcaselabelsonasingleline (BOOL)

True to compress a simple case code on one line

true:                                   false:
switch (a) {                    vs.     switch (a) {case
1:x = 1;                   Case 1: Case
2:return;                           x = 1;
}                                         break;
                                        Case 2:
                                          return;
                                        }

Allowshortfunctionsonasingleline (Shortfunctionstyle)

Depending on the value, int f () {return 0;} may be on a separate line.

The desirable value:

Sfs_none (None in configuration) does not merge functions on one line

Sfs_inlineonly (inlineonly in configuration) merges only functions and inline functions defined within the class and does not combine empty functions: for example, top-level null functions are not merged

Class Foo {
  void F () {Foo ();}
};
void F () {
  foo ();
}
void F () {
}
Sfs_empty (empty in configuration) only merges null functions
void F () {}
void F2 () {
  bar2 ();
}
Sfs_inline (inline in configuration) merges only in-class functions and empty functions
Class Foo {
  void F () {Foo ();}
};
void F () {
  foo ();
}
void F () {}
Sfs_all (all in configuration) merges all functions in one row
Class Foo {
  void F () {Foo ();}
};
void F () {bar ();}

Allowshortifstatementsonasingleline (BOOL)

If true, if (a) return;

Allowshortloopsonasingleline (BOOL)

If true, while (true) continue;

Alwaysbreakafterdefinitionreturntype (Definitionreturntypebreakingstyle)

Returns a single row of type in a function declaration. This option is deprecated and remains as backward compatible.

The desirable value:

Drtbs_none (None in configuration) returns a type after wrapping, but is affected by the penaltyreturntypeonitsownline option.

Drtbs_all (all in configuration) returns a type and always wraps.

Drtbs_toplevel (toplevel in configuration) always wraps after the return type of the top-level function

Alwaysbreakafterreturntype (Returntypebreakingstyle)

Style style of return type in function definition

Desirable value: Rtbs_none (None in configuration) returns type after wrapping, but is affected by the Penaltyreturntypeonitsownline option

Class A {
  int f () {return 0;};
};
int f ();
int F () {return 1;}
Rtbs_all (all in configuration) returns a type and always wraps.
Class A {
  int
  f () {
    return 0;
  };
};
int
f ();
int
f () {
  return 1;
}
Rtbs_toplevel (toplevel in configuration) always wraps after the return type of the top-level function
Class A {
  int f () {return 0;};
};
int
f ();
int
f () {
  return 1;
}
Rtbs_alldefinitions (alldefinitions in configuration) is always wrapped after a return type in a function definition
Class A {
  int
  f () {
    return 0;
  };
};
int f ();
int
f () {
  return 1;
}
Rtbs_topleveldefinitions (topleveldefinitions in configuration) The return type in the top-level function definition is always wrapped
Class A {
  int f () {return 0;};
};
int f ();
int
f () {
  return 1;
}

alwaysbreakbeforemultilinestrings (BOOL)

If true, the line is always wrapped before a multiline string

This option means that the visual is more consistent in the case of multiple multiline strings in the code. Therefore, it only takes effect when the string is wrapped and indents it from the beginning of the line with continuationindentwidth spaces.

true:                                  false:
AAAA =                         vs.     aaaa = "bbbb"
    "bbbb"                                    "CCCC";
    " CCCC ";

alwaysbreaktemplatedeclarations (BOOL)

If true, the template<...> will always be wrapped after the definition in the template

true:                                  false:
template <typename t>          vs.     template <typename t> class C {};
Class C {};

binpackarguments (BOOL)

If False, the arguments of the calling function are not on the same line or on each row.

true:
void F () {
  f (aaaaaaaaaaaaaaaaaaaa, AAAAAAAAAAAAAAAAAAAA,
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA);
}

false:
void F () {
  f (aaaaaaaaaaaaaaaaaaaa,
    aaaaaaaaaaaaaaaaaaaa,
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA);
}

binpackparameters (BOOL)

If False, the shape arguments of the function definition will not be the same line or row

true:
void f (int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
       int AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) {}

false:
void f (int aaaaaaaaaaaaaaaaaaaa,
       int AAAAAAAAAAAAAAAAAAAA,
       int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}

To be continued , and to be completed before 2017/7/17

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.