Home | History | Annotate | Download | only in Format
      1 //===--- Format.h - Format C++ code -----------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 ///
     10 /// \file
     11 /// Various functions to configurably format source code.
     12 ///
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_CLANG_FORMAT_FORMAT_H
     16 #define LLVM_CLANG_FORMAT_FORMAT_H
     17 
     18 #include "clang/Basic/LangOptions.h"
     19 #include "clang/Tooling/Core/Replacement.h"
     20 #include "llvm/ADT/ArrayRef.h"
     21 #include <system_error>
     22 
     23 namespace clang {
     24 
     25 class Lexer;
     26 class SourceManager;
     27 class DiagnosticConsumer;
     28 
     29 namespace format {
     30 
     31 enum class ParseError { Success = 0, Error, Unsuitable };
     32 class ParseErrorCategory final : public std::error_category {
     33 public:
     34   const char *name() const LLVM_NOEXCEPT override;
     35   std::string message(int EV) const override;
     36 };
     37 const std::error_category &getParseCategory();
     38 std::error_code make_error_code(ParseError e);
     39 
     40 /// \brief The \c FormatStyle is used to configure the formatting to follow
     41 /// specific guidelines.
     42 struct FormatStyle {
     43   /// \brief Supported languages. When stored in a configuration file, specifies
     44   /// the language, that the configuration targets. When passed to the
     45   /// reformat() function, enables syntax features specific to the language.
     46   enum LanguageKind {
     47     /// Do not use.
     48     LK_None,
     49     /// Should be used for C, C++, ObjectiveC, ObjectiveC++.
     50     LK_Cpp,
     51     /// Should be used for Java.
     52     LK_Java,
     53     /// Should be used for JavaScript.
     54     LK_JavaScript,
     55     /// Should be used for Protocol Buffers
     56     /// (https://developers.google.com/protocol-buffers/).
     57     LK_Proto
     58   };
     59 
     60   /// \brief Language, this format style is targeted at.
     61   LanguageKind Language;
     62 
     63   /// \brief The column limit.
     64   ///
     65   /// A column limit of \c 0 means that there is no column limit. In this case,
     66   /// clang-format will respect the input's line breaking decisions within
     67   /// statements unless they contradict other rules.
     68   unsigned ColumnLimit;
     69 
     70   /// \brief The maximum number of consecutive empty lines to keep.
     71   unsigned MaxEmptyLinesToKeep;
     72 
     73   /// \brief If true, empty lines at the start of blocks are kept.
     74   bool KeepEmptyLinesAtTheStartOfBlocks;
     75 
     76   /// \brief The penalty for each line break introduced inside a comment.
     77   unsigned PenaltyBreakComment;
     78 
     79   /// \brief The penalty for each line break introduced inside a string literal.
     80   unsigned PenaltyBreakString;
     81 
     82   /// \brief The penalty for each character outside of the column limit.
     83   unsigned PenaltyExcessCharacter;
     84 
     85   /// \brief The penalty for breaking before the first \c <<.
     86   unsigned PenaltyBreakFirstLessLess;
     87 
     88   /// \brief The penalty for breaking a function call after "call(".
     89   unsigned PenaltyBreakBeforeFirstCallParameter;
     90 
     91   /// \brief The & and * alignment style.
     92   enum PointerAlignmentStyle {
     93     /// Align pointer to the left.
     94     PAS_Left,
     95     /// Align pointer to the right.
     96     PAS_Right,
     97     /// Align pointer in the middle.
     98     PAS_Middle
     99   };
    100 
    101   /// Pointer and reference alignment style.
    102   PointerAlignmentStyle PointerAlignment;
    103 
    104   /// \brief If \c true, analyze the formatted file for the most common
    105   /// alignment of & and *. \c PointerAlignment is then used only as fallback.
    106   bool DerivePointerAlignment;
    107 
    108   /// \brief The extra indent or outdent of access modifiers, e.g. \c public:.
    109   int AccessModifierOffset;
    110 
    111   /// \brief Supported language standards.
    112   enum LanguageStandard {
    113     /// Use C++03-compatible syntax.
    114     LS_Cpp03,
    115     /// Use features of C++11 (e.g. \c A<A<int>> instead of
    116     /// <tt>A<A<int> ></tt>).
    117     LS_Cpp11,
    118     /// Automatic detection based on the input.
    119     LS_Auto
    120   };
    121 
    122   /// \brief Format compatible with this standard, e.g. use
    123   /// <tt>A<A<int> ></tt> instead of \c A<A<int>> for LS_Cpp03.
    124   LanguageStandard Standard;
    125 
    126   /// \brief Indent case labels one level from the switch statement.
    127   ///
    128   /// When \c false, use the same indentation level as for the switch statement.
    129   /// Switch statement body is always indented one level more than case labels.
    130   bool IndentCaseLabels;
    131 
    132   /// \brief Indent if a function definition or declaration is wrapped after the
    133   /// type.
    134   bool IndentWrappedFunctionNames;
    135 
    136   /// \brief Different ways to indent namespace contents.
    137   enum NamespaceIndentationKind {
    138     /// Don't indent in namespaces.
    139     NI_None,
    140     /// Indent only in inner namespaces (nested in other namespaces).
    141     NI_Inner,
    142     /// Indent in all namespaces.
    143     NI_All
    144   };
    145 
    146   /// \brief The indentation used for namespaces.
    147   NamespaceIndentationKind NamespaceIndentation;
    148 
    149   /// \brief The number of spaces before trailing line comments
    150   /// (\c // - comments).
    151   ///
    152   /// This does not affect trailing block comments (\c /**/ - comments) as those
    153   /// commonly have different usage patterns and a number of special cases.
    154   unsigned SpacesBeforeTrailingComments;
    155 
    156   /// \brief If \c false, a function declaration's or function definition's
    157   /// parameters will either all be on the same line or will have one line each.
    158   bool BinPackParameters;
    159 
    160   /// \brief If \c false, a function call's arguments will either be all on the
    161   /// same line or will have one line each.
    162   bool BinPackArguments;
    163 
    164   /// \brief If \c true, clang-format detects whether function calls and
    165   /// definitions are formatted with one parameter per line.
    166   ///
    167   /// Each call can be bin-packed, one-per-line or inconclusive. If it is
    168   /// inconclusive, e.g. completely on one line, but a decision needs to be
    169   /// made, clang-format analyzes whether there are other bin-packed cases in
    170   /// the input file and act accordingly.
    171   ///
    172   /// NOTE: This is an experimental flag, that might go away or be renamed. Do
    173   /// not use this in config files, etc. Use at your own risk.
    174   bool ExperimentalAutoDetectBinPacking;
    175 
    176   /// \brief Allow putting all parameters of a function declaration onto
    177   /// the next line even if \c BinPackParameters is \c false.
    178   bool AllowAllParametersOfDeclarationOnNextLine;
    179 
    180   /// \brief Penalty for putting the return type of a function onto its own
    181   /// line.
    182   unsigned PenaltyReturnTypeOnItsOwnLine;
    183 
    184   /// \brief If the constructor initializers don't fit on a line, put each
    185   /// initializer on its own line.
    186   bool ConstructorInitializerAllOnOneLineOrOnePerLine;
    187 
    188   /// \brief Always break constructor initializers before commas and align
    189   /// the commas with the colon.
    190   bool BreakConstructorInitializersBeforeComma;
    191 
    192   /// \brief Allows contracting simple braced statements to a single line.
    193   ///
    194   /// E.g., this allows <tt>if (a) { return; }</tt> to be put on a single line.
    195   bool AllowShortBlocksOnASingleLine;
    196 
    197   /// \brief If \c true, <tt>if (a) return;</tt> can be put on a single
    198   /// line.
    199   bool AllowShortIfStatementsOnASingleLine;
    200 
    201   /// \brief If \c true, <tt>while (true) continue;</tt> can be put on a
    202   /// single line.
    203   bool AllowShortLoopsOnASingleLine;
    204 
    205   /// \brief If \c true, short case labels will be contracted to a single line.
    206   bool AllowShortCaseLabelsOnASingleLine;
    207 
    208   /// \brief Different styles for merging short functions containing at most one
    209   /// statement.
    210   enum ShortFunctionStyle {
    211     /// \brief Never merge functions into a single line.
    212     SFS_None,
    213     /// \brief Only merge functions defined inside a class.
    214     SFS_Inline,
    215     /// \brief Only merge empty functions.
    216     SFS_Empty,
    217     /// \brief Merge all functions fitting on a single line.
    218     SFS_All,
    219   };
    220 
    221   /// \brief Dependent on the value, <tt>int f() { return 0; }</tt> can be put
    222   /// on a single line.
    223   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
    224 
    225   /// \brief Add a space after \c @property in Objective-C, i.e. use
    226   /// <tt>\@property (readonly)</tt> instead of <tt>\@property(readonly)</tt>.
    227   bool ObjCSpaceAfterProperty;
    228 
    229   /// \brief Add a space in front of an Objective-C protocol list, i.e. use
    230   /// <tt>Foo <Protocol></tt> instead of \c Foo<Protocol>.
    231   bool ObjCSpaceBeforeProtocolList;
    232 
    233   /// \brief If \c true, horizontally aligns arguments after an open bracket.
    234   ///
    235   /// This applies to round brackets (parentheses), angle brackets and square
    236   /// brackets. This will result in formattings like
    237   /// \code
    238   /// someLongFunction(argument1,
    239   ///                  argument2);
    240   /// \endcode
    241   bool AlignAfterOpenBracket;
    242 
    243   /// \brief If \c true, horizontally align operands of binary and ternary
    244   /// expressions.
    245   bool AlignOperands;
    246 
    247   /// \brief If \c true, aligns trailing comments.
    248   bool AlignTrailingComments;
    249 
    250   /// \brief If \c true, aligns escaped newlines as far left as possible.
    251   /// Otherwise puts them into the right-most column.
    252   bool AlignEscapedNewlinesLeft;
    253 
    254   /// \brief The number of columns to use for indentation.
    255   unsigned IndentWidth;
    256 
    257   /// \brief The number of columns used for tab stops.
    258   unsigned TabWidth;
    259 
    260   /// \brief The number of characters to use for indentation of constructor
    261   /// initializer lists.
    262   unsigned ConstructorInitializerIndentWidth;
    263 
    264   /// \brief The number of characters to use for indentation of ObjC blocks.
    265   unsigned ObjCBlockIndentWidth;
    266 
    267   /// \brief If \c true, always break after function definition return types.
    268   ///
    269   /// More truthfully called 'break before the identifier following the type
    270   /// in a function definition'. PenaltyReturnTypeOnItsOwnLine becomes
    271   /// irrelevant.
    272   bool AlwaysBreakAfterDefinitionReturnType;
    273 
    274   /// \brief If \c true, always break after the <tt>template<...></tt> of a
    275   /// template declaration.
    276   bool AlwaysBreakTemplateDeclarations;
    277 
    278   /// \brief If \c true, always break before multiline string literals.
    279   bool AlwaysBreakBeforeMultilineStrings;
    280 
    281   /// \brief Different ways to use tab in formatting.
    282   enum UseTabStyle {
    283     /// Never use tab.
    284     UT_Never,
    285     /// Use tabs only for indentation.
    286     UT_ForIndentation,
    287     /// Use tabs whenever we need to fill whitespace that spans at least from
    288     /// one tab stop to the next one.
    289     UT_Always
    290   };
    291 
    292   /// \brief The way to use tab characters in the resulting file.
    293   UseTabStyle UseTab;
    294 
    295   /// \brief The style of breaking before or after binary operators.
    296   enum BinaryOperatorStyle {
    297     /// Break after operators.
    298     BOS_None,
    299     /// Break before operators that aren't assignments.
    300     BOS_NonAssignment,
    301     /// Break before operators.
    302     BOS_All,
    303   };
    304 
    305   /// \brief The way to wrap binary operators.
    306   BinaryOperatorStyle BreakBeforeBinaryOperators;
    307 
    308   /// \brief If \c true, ternary operators will be placed after line breaks.
    309   bool BreakBeforeTernaryOperators;
    310 
    311   /// \brief Different ways to attach braces to their surrounding context.
    312   enum BraceBreakingStyle {
    313     /// Always attach braces to surrounding context.
    314     BS_Attach,
    315     /// Like \c Attach, but break before braces on function, namespace and
    316     /// class definitions.
    317     BS_Linux,
    318     /// Like \c Attach, but break before function definitions, and 'else'.
    319     BS_Stroustrup,
    320     /// Always break before braces.
    321     BS_Allman,
    322     /// Always break before braces and add an extra level of indentation to
    323     /// braces of control statements, not to those of class, function
    324     /// or other definitions.
    325     BS_GNU
    326   };
    327 
    328   /// \brief The brace breaking style to use.
    329   BraceBreakingStyle BreakBeforeBraces;
    330 
    331   /// \brief If \c true, format braced lists as best suited for C++11 braced
    332   /// lists.
    333   ///
    334   /// Important differences:
    335   /// - No spaces inside the braced list.
    336   /// - No line break before the closing brace.
    337   /// - Indentation with the continuation indent, not with the block indent.
    338   ///
    339   /// Fundamentally, C++11 braced lists are formatted exactly like function
    340   /// calls would be formatted in their place. If the braced list follows a name
    341   /// (e.g. a type or variable name), clang-format formats as if the \c {} were
    342   /// the parentheses of a function call with that name. If there is no name,
    343   /// a zero-length name is assumed.
    344   bool Cpp11BracedListStyle;
    345 
    346   /// \brief If \c true, spaces will be inserted after '(' and before ')'.
    347   bool SpacesInParentheses;
    348 
    349   /// \brief If \c true, spaces will be inserted after '<' and before '>' in
    350   /// template argument lists
    351   bool SpacesInAngles;
    352 
    353   /// \brief If \c true, spaces will be inserted after '[' and before ']'.
    354   bool SpacesInSquareBrackets;
    355 
    356   /// \brief If \c true, spaces may be inserted into '()'.
    357   bool SpaceInEmptyParentheses;
    358 
    359   /// \brief If \c true, spaces are inserted inside container literals (e.g.
    360   /// ObjC and Javascript array and dict literals).
    361   bool SpacesInContainerLiterals;
    362 
    363   /// \brief If \c true, spaces may be inserted into C style casts.
    364   bool SpacesInCStyleCastParentheses;
    365 
    366   /// \brief If \c true, a space may be inserted after C style casts.
    367   bool SpaceAfterCStyleCast;
    368 
    369   /// \brief Different ways to put a space before opening parentheses.
    370   enum SpaceBeforeParensOptions {
    371     /// Never put a space before opening parentheses.
    372     SBPO_Never,
    373     /// Put a space before opening parentheses only after control statement
    374     /// keywords (<tt>for/if/while...</tt>).
    375     SBPO_ControlStatements,
    376     /// Always put a space before opening parentheses, except when it's
    377     /// prohibited by the syntax rules (in function-like macro definitions) or
    378     /// when determined by other style rules (after unary operators, opening
    379     /// parentheses, etc.)
    380     SBPO_Always
    381   };
    382 
    383   /// \brief Defines in which cases to put a space before opening parentheses.
    384   SpaceBeforeParensOptions SpaceBeforeParens;
    385 
    386   /// \brief If \c false, spaces will be removed before assignment operators.
    387   bool SpaceBeforeAssignmentOperators;
    388 
    389   /// \brief Indent width for line continuations.
    390   unsigned ContinuationIndentWidth;
    391 
    392   /// \brief A regular expression that describes comments with special meaning,
    393   /// which should not be split into lines or otherwise changed.
    394   std::string CommentPragmas;
    395 
    396   /// \brief Disables formatting at all.
    397   bool DisableFormat;
    398 
    399   /// \brief A vector of macros that should be interpreted as foreach loops
    400   /// instead of as function calls.
    401   ///
    402   /// These are expected to be macros of the form:
    403   /// \code
    404   /// FOREACH(<variable-declaration>, ...)
    405   ///   <loop-body>
    406   /// \endcode
    407   ///
    408   /// For example: BOOST_FOREACH.
    409   std::vector<std::string> ForEachMacros;
    410 
    411   bool operator==(const FormatStyle &R) const {
    412     return AccessModifierOffset == R.AccessModifierOffset &&
    413            AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
    414            AlignOperands == R.AlignOperands &&
    415            AlignEscapedNewlinesLeft == R.AlignEscapedNewlinesLeft &&
    416            AlignTrailingComments == R.AlignTrailingComments &&
    417            AllowAllParametersOfDeclarationOnNextLine ==
    418                R.AllowAllParametersOfDeclarationOnNextLine &&
    419            AllowShortFunctionsOnASingleLine ==
    420                R.AllowShortFunctionsOnASingleLine &&
    421            AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
    422            AllowShortIfStatementsOnASingleLine ==
    423                R.AllowShortIfStatementsOnASingleLine &&
    424            AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
    425            AlwaysBreakAfterDefinitionReturnType ==
    426                R.AlwaysBreakAfterDefinitionReturnType &&
    427            AlwaysBreakTemplateDeclarations ==
    428                R.AlwaysBreakTemplateDeclarations &&
    429            AlwaysBreakBeforeMultilineStrings ==
    430                R.AlwaysBreakBeforeMultilineStrings &&
    431            BinPackParameters == R.BinPackParameters &&
    432            BinPackArguments == R.BinPackArguments &&
    433            BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
    434            BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
    435            BreakBeforeBraces == R.BreakBeforeBraces &&
    436            BreakConstructorInitializersBeforeComma ==
    437                R.BreakConstructorInitializersBeforeComma &&
    438            ColumnLimit == R.ColumnLimit &&
    439            ConstructorInitializerAllOnOneLineOrOnePerLine ==
    440                R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
    441            ConstructorInitializerIndentWidth ==
    442                R.ConstructorInitializerIndentWidth &&
    443            DerivePointerAlignment == R.DerivePointerAlignment &&
    444            ExperimentalAutoDetectBinPacking ==
    445                R.ExperimentalAutoDetectBinPacking &&
    446            IndentCaseLabels == R.IndentCaseLabels &&
    447            IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
    448            IndentWidth == R.IndentWidth && Language == R.Language &&
    449            MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
    450            KeepEmptyLinesAtTheStartOfBlocks ==
    451                R.KeepEmptyLinesAtTheStartOfBlocks &&
    452            NamespaceIndentation == R.NamespaceIndentation &&
    453            ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
    454            ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
    455            ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
    456            PenaltyBreakComment == R.PenaltyBreakComment &&
    457            PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
    458            PenaltyBreakString == R.PenaltyBreakString &&
    459            PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
    460            PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
    461            PointerAlignment == R.PointerAlignment &&
    462            SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
    463            Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
    464            Standard == R.Standard && TabWidth == R.TabWidth &&
    465            UseTab == R.UseTab && SpacesInParentheses == R.SpacesInParentheses &&
    466            SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
    467            SpacesInAngles == R.SpacesInAngles &&
    468            SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
    469            SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
    470            SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
    471            SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
    472            SpaceBeforeParens == R.SpaceBeforeParens &&
    473            SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
    474            ContinuationIndentWidth == R.ContinuationIndentWidth &&
    475            CommentPragmas == R.CommentPragmas &&
    476            ForEachMacros == R.ForEachMacros;
    477   }
    478 };
    479 
    480 /// \brief Returns a format style complying with the LLVM coding standards:
    481 /// http://llvm.org/docs/CodingStandards.html.
    482 FormatStyle getLLVMStyle();
    483 
    484 /// \brief Returns a format style complying with one of Google's style guides:
    485 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
    486 /// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
    487 /// https://developers.google.com/protocol-buffers/docs/style.
    488 FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
    489 
    490 /// \brief Returns a format style complying with Chromium's style guide:
    491 /// http://www.chromium.org/developers/coding-style.
    492 FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
    493 
    494 /// \brief Returns a format style complying with Mozilla's style guide:
    495 /// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
    496 FormatStyle getMozillaStyle();
    497 
    498 /// \brief Returns a format style complying with Webkit's style guide:
    499 /// http://www.webkit.org/coding/coding-style.html
    500 FormatStyle getWebKitStyle();
    501 
    502 /// \brief Returns a format style complying with GNU Coding Standards:
    503 /// http://www.gnu.org/prep/standards/standards.html
    504 FormatStyle getGNUStyle();
    505 
    506 /// \brief Returns style indicating formatting should be not applied at all.
    507 FormatStyle getNoStyle();
    508 
    509 /// \brief Gets a predefined style for the specified language by name.
    510 ///
    511 /// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
    512 /// compared case-insensitively.
    513 ///
    514 /// Returns \c true if the Style has been set.
    515 bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language,
    516                         FormatStyle *Style);
    517 
    518 /// \brief Parse configuration from YAML-formatted text.
    519 ///
    520 /// Style->Language is used to get the base style, if the \c BasedOnStyle
    521 /// option is present.
    522 ///
    523 /// When \c BasedOnStyle is not present, options not present in the YAML
    524 /// document, are retained in \p Style.
    525 std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
    526 
    527 /// \brief Gets configuration in a YAML string.
    528 std::string configurationAsText(const FormatStyle &Style);
    529 
    530 /// \brief Reformats the given \p Ranges in the token stream coming out of
    531 /// \c Lex.
    532 ///
    533 /// DEPRECATED: Do not use.
    534 tooling::Replacements reformat(const FormatStyle &Style, Lexer &Lex,
    535                                SourceManager &SourceMgr,
    536                                ArrayRef<CharSourceRange> Ranges);
    537 
    538 /// \brief Reformats the given \p Ranges in the file \p ID.
    539 ///
    540 /// Each range is extended on either end to its next bigger logic unit, i.e.
    541 /// everything that might influence its formatting or might be influenced by its
    542 /// formatting.
    543 ///
    544 /// Returns the \c Replacements necessary to make all \p Ranges comply with
    545 /// \p Style.
    546 tooling::Replacements reformat(const FormatStyle &Style,
    547                                SourceManager &SourceMgr, FileID ID,
    548                                ArrayRef<CharSourceRange> Ranges);
    549 
    550 /// \brief Reformats the given \p Ranges in \p Code.
    551 ///
    552 /// Otherwise identical to the reformat() function consuming a \c Lexer.
    553 tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
    554                                ArrayRef<tooling::Range> Ranges,
    555                                StringRef FileName = "<stdin>");
    556 
    557 /// \brief Returns the \c LangOpts that the formatter expects you to set.
    558 ///
    559 /// \param Style determines specific settings for lexing mode.
    560 LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle());
    561 
    562 /// \brief Description to be used for help text for a llvm::cl option for
    563 /// specifying format style. The description is closely related to the operation
    564 /// of getStyle().
    565 extern const char *StyleOptionHelpDescription;
    566 
    567 /// \brief Construct a FormatStyle based on \c StyleName.
    568 ///
    569 /// \c StyleName can take several forms:
    570 /// \li "{<key>: <value>, ...}" - Set specic style parameters.
    571 /// \li "<style name>" - One of the style names supported by
    572 /// getPredefinedStyle().
    573 /// \li "file" - Load style configuration from a file called '.clang-format'
    574 /// located in one of the parent directories of \c FileName or the current
    575 /// directory if \c FileName is empty.
    576 ///
    577 /// \param[in] StyleName Style name to interpret according to the description
    578 /// above.
    579 /// \param[in] FileName Path to start search for .clang-format if \c StyleName
    580 /// == "file".
    581 /// \param[in] FallbackStyle The name of a predefined style used to fallback to
    582 /// in case the style can't be determined from \p StyleName.
    583 ///
    584 /// \returns FormatStyle as specified by \c StyleName. If no style could be
    585 /// determined, the default is LLVM Style (see getLLVMStyle()).
    586 FormatStyle getStyle(StringRef StyleName, StringRef FileName,
    587                      StringRef FallbackStyle);
    588 
    589 } // end namespace format
    590 } // end namespace clang
    591 
    592 namespace std {
    593 template <>
    594 struct is_error_code_enum<clang::format::ParseError> : std::true_type {};
    595 }
    596 
    597 #endif // LLVM_CLANG_FORMAT_FORMAT_H
    598