diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-05-29 16:25:46 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-05-29 16:25:46 +0000 | 
| commit | b5aee35cc5d62f11d98539f62e4fe63f0ac9edc6 (patch) | |
| tree | 3e6ab962dbc73cfe1445a60d2eb4dfba7c939a22 /lib/Format/Format.cpp | |
| parent | aa803409c3bd3930126db630c29f63d42f255153 (diff) | |
Notes
Diffstat (limited to 'lib/Format/Format.cpp')
| -rw-r--r-- | lib/Format/Format.cpp | 30 | 
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index ac83379e6b15..2ef6516e02ee 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -123,6 +123,14 @@ template <> struct ScalarEnumerationTraits<FormatStyle::BraceBreakingStyle> {    }  }; +template <> struct ScalarEnumerationTraits<FormatStyle::BreakConstructorInitializersStyle> { +  static void enumeration(IO &IO, FormatStyle::BreakConstructorInitializersStyle &Value) { +    IO.enumCase(Value, "BeforeColon", FormatStyle::BCIS_BeforeColon); +    IO.enumCase(Value, "BeforeComma", FormatStyle::BCIS_BeforeComma); +    IO.enumCase(Value, "AfterColon", FormatStyle::BCIS_AfterColon); +  } +}; +  template <>  struct ScalarEnumerationTraits<FormatStyle::ReturnTypeBreakingStyle> {    static void enumeration(IO &IO, FormatStyle::ReturnTypeBreakingStyle &Value) { @@ -304,8 +312,19 @@ template <> struct MappingTraits<FormatStyle> {      IO.mapOptional("BreakBeforeBraces", Style.BreakBeforeBraces);      IO.mapOptional("BreakBeforeTernaryOperators",                     Style.BreakBeforeTernaryOperators); + +    bool BreakConstructorInitializersBeforeComma = false;      IO.mapOptional("BreakConstructorInitializersBeforeComma", -                   Style.BreakConstructorInitializersBeforeComma); +                   BreakConstructorInitializersBeforeComma); +    IO.mapOptional("BreakConstructorInitializers", +                   Style.BreakConstructorInitializers); +    // If BreakConstructorInitializersBeforeComma was specified but +    // BreakConstructorInitializers was not, initialize the latter from the +    // former for backwards compatibility. +    if (BreakConstructorInitializersBeforeComma && +        Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeColon) +      Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma; +      IO.mapOptional("BreakAfterJavaFieldAnnotations",                     Style.BreakAfterJavaFieldAnnotations);      IO.mapOptional("BreakStringLiterals", Style.BreakStringLiterals); @@ -537,7 +556,7 @@ FormatStyle getLLVMStyle() {    LLVMStyle.BraceWrapping = {false, false, false, false, false, false,                               false, false, false, false, false};    LLVMStyle.BreakAfterJavaFieldAnnotations = false; -  LLVMStyle.BreakConstructorInitializersBeforeComma = false; +  LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;    LLVMStyle.BreakBeforeInheritanceComma = false;    LLVMStyle.BreakStringLiterals = true;    LLVMStyle.ColumnLimit = 80; @@ -694,7 +713,7 @@ FormatStyle getMozillaStyle() {    MozillaStyle.BinPackParameters = false;    MozillaStyle.BinPackArguments = false;    MozillaStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla; -  MozillaStyle.BreakConstructorInitializersBeforeComma = true; +  MozillaStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;    MozillaStyle.BreakBeforeInheritanceComma = true;    MozillaStyle.ConstructorInitializerIndentWidth = 2;    MozillaStyle.ContinuationIndentWidth = 2; @@ -717,7 +736,7 @@ FormatStyle getWebKitStyle() {    Style.AlignTrailingComments = false;    Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;    Style.BreakBeforeBraces = FormatStyle::BS_WebKit; -  Style.BreakConstructorInitializersBeforeComma = true; +  Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;    Style.Cpp11BracedListStyle = false;    Style.ColumnLimit = 0;    Style.FixNamespaceComments = false; @@ -1891,6 +1910,9 @@ tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,  tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,                                ArrayRef<tooling::Range> Ranges,                                StringRef FileName) { +  // cleanups only apply to C++ (they mostly concern ctor commas etc.) +  if (Style.Language != FormatStyle::LK_Cpp) +    return tooling::Replacements();    std::unique_ptr<Environment> Env =        Environment::CreateVirtualEnvironment(Code, FileName, Ranges);    Cleaner Clean(*Env, Style);  | 
