diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -1849,7 +1849,8 @@ /// Returns a format style complying with the LLVM coding standards: /// http://llvm.org/docs/CodingStandards.html. -FormatStyle getLLVMStyle(); +FormatStyle getLLVMStyle( + FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp); /// Returns a format style complying with one of Google's style guides: /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml. @@ -1996,7 +1997,8 @@ /// Returns the ``LangOpts`` that the formatter expects you to set. /// /// \param Style determines specific settings for lexing mode. -LangOptions getFormattingLangOpts(const FormatStyle &Style = getLLVMStyle()); +LangOptions getFormattingLangOpts( + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)); /// Description to be used for help text for a ``llvm::cl`` option for /// specifying format style. The description is closely related to the operation diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -189,7 +189,7 @@ FormatStyle PredefinedStyle; if (!getPredefinedStyle(RawStringFormat.BasedOnStyle, RawStringFormat.Language, &PredefinedStyle)) { - PredefinedStyle = getLLVMStyle(); + PredefinedStyle = getLLVMStyle(FormatStyle::LK_Cpp); PredefinedStyle.Language = RawStringFormat.Language; } LanguageStyle = PredefinedStyle; diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -618,9 +618,9 @@ return Expanded; } -FormatStyle getLLVMStyle() { +FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { FormatStyle LLVMStyle; - LLVMStyle.Language = FormatStyle::LK_Cpp; + LLVMStyle.Language = Language; LLVMStyle.AccessModifierOffset = -2; LLVMStyle.AlignEscapedNewlines = FormatStyle::ENAS_Right; LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align; @@ -718,6 +718,11 @@ LLVMStyle.StatementMacros.push_back("Q_UNUSED"); LLVMStyle.StatementMacros.push_back("QT_REQUIRE_VERSION"); + // Defaults that differ when not C++. + if (Language == FormatStyle::LK_TableGen) { + LLVMStyle.SpacesInContainerLiterals = false; + } + return LLVMStyle; } @@ -729,8 +734,7 @@ return GoogleStyle; } - FormatStyle GoogleStyle = getLLVMStyle(); - GoogleStyle.Language = Language; + FormatStyle GoogleStyle = getLLVMStyle(Language); GoogleStyle.AccessModifierOffset = -1; GoogleStyle.AlignEscapedNewlines = FormatStyle::ENAS_Left; @@ -878,7 +882,7 @@ } FormatStyle getMozillaStyle() { - FormatStyle MozillaStyle = getLLVMStyle(); + FormatStyle MozillaStyle = getLLVMStyle(FormatStyle::LK_Cpp); MozillaStyle.AllowAllParametersOfDeclarationOnNextLine = false; MozillaStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; MozillaStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_TopLevel; @@ -904,7 +908,7 @@ } FormatStyle getWebKitStyle() { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AccessModifierOffset = -4; Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; Style.AlignOperands = false; @@ -925,7 +929,7 @@ } FormatStyle getGNUStyle() { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All; Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions; Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All; @@ -940,7 +944,7 @@ } FormatStyle getNoStyle() { - FormatStyle NoStyle = getLLVMStyle(); + FormatStyle NoStyle = getLLVMStyle(FormatStyle::LK_Cpp); NoStyle.DisableFormat = true; NoStyle.SortIncludes = false; NoStyle.SortUsingDeclarations = false; @@ -950,7 +954,7 @@ bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style) { if (Name.equals_lower("llvm")) { - *Style = getLLVMStyle(); + *Style = getLLVMStyle(FormatStyle::LK_Cpp); } else if (Name.equals_lower("chromium")) { *Style = getChromiumStyle(Language); } else if (Name.equals_lower("mozilla")) { @@ -2318,7 +2322,7 @@ if (Extension.empty() || Extension == ".h") { auto NonEmptyFileName = FileName.empty() ? "guess.h" : FileName; Environment Env(Code, NonEmptyFileName, /*Ranges=*/{}); - ObjCHeaderStyleGuesser Guesser(Env, getLLVMStyle()); + ObjCHeaderStyleGuesser Guesser(Env, getLLVMStyle(FormatStyle::LK_Cpp)); Guesser.process(); if (Guesser.isObjC()) return FormatStyle::LK_ObjC; @@ -2338,8 +2342,7 @@ if (!FS) { FS = llvm::vfs::getRealFileSystem().get(); } - FormatStyle Style = getLLVMStyle(); - Style.Language = guessLanguage(FileName, Code); + FormatStyle Style = getLLVMStyle(guessLanguage(FileName, Code)); FormatStyle FallbackStyle = getNoStyle(); if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle)) diff --git a/clang/lib/Index/CommentToXML.cpp b/clang/lib/Index/CommentToXML.cpp --- a/clang/lib/Index/CommentToXML.cpp +++ b/clang/lib/Index/CommentToXML.cpp @@ -592,7 +592,7 @@ unsigned Offset = 0; unsigned Length = Declaration.size(); - format::FormatStyle Style = format::getLLVMStyle(); + format::FormatStyle Style = format::getLLVMStyle(format::FormatStyle::LK_Cpp); Style.FixNamespaceComments = false; tooling::Replacements Replaces = reformat(Style, StringDecl, tooling::Range(Offset, Length), "xmldecl.xd"); diff --git a/clang/unittests/Format/CleanupTest.cpp b/clang/unittests/Format/CleanupTest.cpp --- a/clang/unittests/Format/CleanupTest.cpp +++ b/clang/unittests/Format/CleanupTest.cpp @@ -23,9 +23,9 @@ class CleanupTest : public ::testing::Test { protected: - std::string cleanup(llvm::StringRef Code, - const std::vector &Ranges, - const FormatStyle &Style = getLLVMStyle()) { + std::string + cleanup(llvm::StringRef Code, const std::vector &Ranges, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { tooling::Replacements Replaces = format::cleanup(Style, Code, Ranges); auto Result = applyAllReplacements(Code, Replaces); @@ -34,9 +34,9 @@ } // Returns code after cleanup around \p Offsets. - std::string cleanupAroundOffsets(llvm::ArrayRef Offsets, - llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + std::string cleanupAroundOffsets( + llvm::ArrayRef Offsets, llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { std::vector Ranges; for (auto Offset : Offsets) Ranges.push_back(tooling::Range(Offset, 0)); @@ -113,7 +113,7 @@ "}\n"; std::string Expected = "\n\n\n\n\n\n\n\n\n\n"; std::vector Ranges(1, tooling::Range(0, Code.size())); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BraceWrapping.AfterNamespace = true; std::string Result = cleanup(Code, Ranges, Style); EXPECT_EQ(Expected, Result); @@ -132,7 +132,7 @@ "#else\n" "#endif\n"; std::vector Ranges(1, tooling::Range(0, Code.size())); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); std::string Result = cleanup(Code, Ranges, Style); EXPECT_EQ(Expected, Result); } @@ -331,7 +331,7 @@ } const std::string FileName = "fix.cpp"; - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); }; TEST_F(CleanUpReplacementsTest, FixOnlyAffectedCodeAfterReplacements) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -35,9 +35,10 @@ SC_DoNotCheck }; - std::string format(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle(), - StatusCheck CheckComplete = SC_ExpectComplete) { + std::string + format(llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp), + StatusCheck CheckComplete = SC_ExpectComplete) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); std::vector Ranges(1, tooling::Range(0, Code.size())); @@ -62,15 +63,16 @@ } FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) { - return getStyleWithColumns(getLLVMStyle(), ColumnLimit); + return getStyleWithColumns(getLLVMStyle(FormatStyle::LK_Cpp), ColumnLimit); } FormatStyle getGoogleStyleWithColumns(unsigned ColumnLimit) { return getStyleWithColumns(getGoogleStyle(), ColumnLimit); } - void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + void + verifyFormat(llvm::StringRef Expected, llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { EXPECT_EQ(Expected.str(), format(Expected, Style)) << "Expected code is not stable"; EXPECT_EQ(Expected.str(), format(Code, Style)); @@ -83,13 +85,15 @@ } } - void verifyFormat(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + void + verifyFormat(llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { verifyFormat(Code, test::messUp(Code), Style); } - void verifyIncompleteFormat(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + void verifyIncompleteFormat( + llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { EXPECT_EQ(Code.str(), format(test::messUp(Code), Style, SC_ExpectIncomplete)); } @@ -104,8 +108,9 @@ } /// \brief Verify that clang-format does not crash on the given input. - void verifyNoCrash(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + void + verifyNoCrash(llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { format(Code, Style, SC_DoNotCheck); } @@ -120,6 +125,15 @@ EXPECT_EQ("a\n#b c d\ne", test::messUp("a\n#b\\\nc\\\nd\ne")); } +TEST_F(FormatTest, DefaultLLVMStyleIsCpp) { + EXPECT_EQ(FormatStyle::LK_Cpp, getLLVMStyle().Language); +} + +TEST_F(FormatTest, LLVMStyleOverride) { + EXPECT_EQ(FormatStyle::LK_Proto, + getLLVMStyle(FormatStyle::LK_Proto).Language); +} + //===----------------------------------------------------------------------===// // Basic function tests. //===----------------------------------------------------------------------===// @@ -276,7 +290,7 @@ " }\n" "\n" "}", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("void f() {\n" " if (a) {\n" " f();\n" @@ -314,7 +328,7 @@ "}")); // Don't remove empty lines before namespace endings. - FormatStyle LLVMWithNoNamespaceFix = getLLVMStyle(); + FormatStyle LLVMWithNoNamespaceFix = getLLVMStyle(FormatStyle::LK_Cpp); LLVMWithNoNamespaceFix.FixNamespaceComments = false; EXPECT_EQ("namespace {\n" "int i;\n" @@ -361,7 +375,7 @@ "\n" "} // namespace")); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; Style.MaxEmptyLinesToKeep = 2; Style.BreakBeforeBraces = FormatStyle::BS_Custom; @@ -428,7 +442,7 @@ " }\n" "g();"); - FormatStyle AllowsMergedIf = getLLVMStyle(); + FormatStyle AllowsMergedIf = getLLVMStyle(FormatStyle::LK_Cpp); AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left; AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true; verifyFormat("if (a)\n" @@ -479,7 +493,7 @@ } TEST_F(FormatTest, FormatLoopsWithoutCompoundStatement) { - FormatStyle AllowsMergedLoops = getLLVMStyle(); + FormatStyle AllowsMergedLoops = getLLVMStyle(FormatStyle::LK_Cpp); AllowsMergedLoops.AllowShortLoopsOnASingleLine = true; verifyFormat("while (true) continue;", AllowsMergedLoops); verifyFormat("for (;;) continue;", AllowsMergedLoops); @@ -502,7 +516,7 @@ } TEST_F(FormatTest, FormatShortBracedStatements) { - FormatStyle AllowSimpleBracedStatements = getLLVMStyle(); + FormatStyle AllowSimpleBracedStatements = getLLVMStyle(FormatStyle::LK_Cpp); AllowSimpleBracedStatements.ColumnLimit = 40; AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine = true; @@ -807,7 +821,7 @@ verifyFormat("Foo *x;\nfor (x in y) {\n}"); verifyFormat("for (const Foo &baz = in.value(); !baz.at_end(); ++baz) {\n}"); - FormatStyle NoBinPacking = getLLVMStyle(); + FormatStyle NoBinPacking = getLLVMStyle(FormatStyle::LK_Cpp); NoBinPacking.BinPackParameters = false; verifyFormat("for (int aaaaaaaaaaa = 1;\n" " aaaaaaaaaaa <= aaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa,\n" @@ -824,7 +838,7 @@ " ++I) {\n}", NoBinPacking); - FormatStyle AlignLeft = getLLVMStyle(); + FormatStyle AlignLeft = getLLVMStyle(FormatStyle::LK_Cpp); AlignLeft.PointerAlignment = FormatStyle::PAS_Left; verifyFormat("for (A* a = start; a < end; ++a, ++value) {\n}", AlignLeft); } @@ -1033,7 +1047,7 @@ " break;\n" " }\n" "});", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("switch (n) {\n" "case 0: {\n" " return false;\n" @@ -1051,7 +1065,7 @@ " return true;\n" "}\n" "}", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); verifyFormat("switch (a) {\n" "case (b):\n" " return;\n" @@ -1064,7 +1078,7 @@ "}", getLLVMStyleWithColumns(34)); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.IndentCaseLabels = true; Style.AllowShortBlocksOnASingleLine = false; Style.BreakBeforeBraces = FormatStyle::BS_Custom; @@ -1101,7 +1115,7 @@ } TEST_F(FormatTest, ShortCaseLabels) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AllowShortCaseLabelsOnASingleLine = true; verifyFormat("switch (a) {\n" "case 1: x = 1; break;\n" @@ -1449,7 +1463,8 @@ } TEST_F(FormatTest, BreakInheritanceStyle) { - FormatStyle StyleWithInheritanceBreakBeforeComma = getLLVMStyle(); + FormatStyle StyleWithInheritanceBreakBeforeComma = + getLLVMStyle(FormatStyle::LK_Cpp); StyleWithInheritanceBreakBeforeComma.BreakInheritanceList = FormatStyle::BILS_BeforeComma; verifyFormat("class MyClass : public X {};", @@ -1467,7 +1482,8 @@ " aaaaaaaaaaaaaaaa> {};", StyleWithInheritanceBreakBeforeComma); - FormatStyle StyleWithInheritanceBreakAfterColon = getLLVMStyle(); + FormatStyle StyleWithInheritanceBreakAfterColon = + getLLVMStyle(FormatStyle::LK_Cpp); StyleWithInheritanceBreakAfterColon.BreakInheritanceList = FormatStyle::BILS_AfterColon; verifyFormat("class MyClass : public X {};", @@ -1617,7 +1633,7 @@ } TEST_F(FormatTest, FormatsTypedefEnum) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.ColumnLimit = 40; verifyFormat("typedef enum {} EmptyEnum;"); verifyFormat("typedef enum { A, B, C } ShortEnum;"); @@ -1687,7 +1703,7 @@ } TEST_F(FormatTest, FormatsNamespaces) { - FormatStyle LLVMWithNoNamespaceFix = getLLVMStyle(); + FormatStyle LLVMWithNoNamespaceFix = getLLVMStyle(FormatStyle::LK_Cpp); LLVMWithNoNamespaceFix.FixNamespaceComments = false; verifyFormat("namespace some_namespace {\n" @@ -1766,7 +1782,7 @@ "}", LLVMWithNoNamespaceFix)); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.NamespaceIndentation = FormatStyle::NI_All; EXPECT_EQ("namespace out {\n" " int i;\n" @@ -1799,7 +1815,7 @@ } TEST_F(FormatTest, FormatsCompactNamespaces) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.CompactNamespaces = true; verifyFormat("namespace A { namespace B {\n" @@ -1946,7 +1962,7 @@ " return i;\n" "}"); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterFunction = true; verifyFormat("extern \"C\" int foo() {}", Style); @@ -2075,7 +2091,7 @@ } TEST_F(FormatTest, FormatTryCatchBraceStyles) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); for (auto BraceStyle : {FormatStyle::BS_Attach, FormatStyle::BS_Mozilla, FormatStyle::BS_WebKit}) { Style.BreakBeforeBraces = BraceStyle; @@ -2374,7 +2390,8 @@ } TEST_F(FormatTest, HashInMacroDefinition) { - EXPECT_EQ("#define A(c) L#c", format("#define A(c) L#c", getLLVMStyle())); + EXPECT_EQ("#define A(c) L#c", + format("#define A(c) L#c", getLLVMStyle(FormatStyle::LK_Cpp))); verifyFormat("#define A \\\n b #c;", getLLVMStyleWithColumns(11)); verifyFormat("#define A \\\n" " { \\\n" @@ -2627,7 +2644,7 @@ " A(X x)\n" " try : t(0) {} catch (...) {}\n" "};")); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterControlStatement = true; Style.BraceWrapping.AfterFunction = true; @@ -2661,7 +2678,7 @@ verifyFormat("MACRO(>)"); // Some macros contain an implicit semicolon. - Style = getLLVMStyle(); + Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.StatementMacros.push_back("FOO"); verifyFormat("FOO(a) int b = 0;"); verifyFormat("FOO(a)\n" @@ -2709,7 +2726,7 @@ } TEST_F(FormatTest, IndentPreprocessorDirectives) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.IndentPPDirectives = FormatStyle::PPDIS_None; Style.ColumnLimit = 40; verifyFormat("#ifdef _WIN32\n" @@ -2991,7 +3008,7 @@ EXPECT_EQ("/* \\ \\ \\\n */", format("\\\n/* \\ \\ \\\n */")); EXPECT_EQ("", format("")); - FormatStyle AlignLeft = getLLVMStyle(); + FormatStyle AlignLeft = getLLVMStyle(FormatStyle::LK_Cpp); AlignLeft.AlignEscapedNewlines = FormatStyle::ENAS_Left; EXPECT_EQ("#define MACRO(x) \\\n" "private: \\\n" @@ -3016,7 +3033,7 @@ " int x(int a);\r\n", AlignLeft)); - FormatStyle DontAlign = getLLVMStyle(); + FormatStyle DontAlign = getLLVMStyle(FormatStyle::LK_Cpp); DontAlign.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign; DontAlign.MaxEmptyLinesToKeep = 3; // FIXME: can't use verifyFormat here because the newline before @@ -3147,7 +3164,7 @@ } TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) { - FormatStyle SingleLine = getLLVMStyle(); + FormatStyle SingleLine = getLLVMStyle(FormatStyle::LK_Cpp); SingleLine.AllowShortIfStatementsOnASingleLine = true; verifyFormat("#if 0\n" "#elif 1\n" @@ -3317,7 +3334,7 @@ } TEST_F(FormatTest, FormatBeginBlockEndMacros) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.MacroBlockBegin = "^[A-Z_]+_BEGIN$"; Style.MacroBlockEnd = "^[A-Z_]+_END$"; verifyFormat("FOO_BEGIN\n" @@ -3450,7 +3467,7 @@ " 5) {\n" "}"); - FormatStyle OnePerLine = getLLVMStyle(); + FormatStyle OnePerLine = getLLVMStyle(FormatStyle::LK_Cpp); OnePerLine.BinPackParameters = false; verifyFormat( "if (aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n" @@ -3512,7 +3529,7 @@ // indent). The RHS is aligned right of the operator and so compasses // everything until something with the same indent as the operator is found. // FIXME: Is this a good system? - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All; verifyFormat( "bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" @@ -3601,7 +3618,7 @@ } TEST_F(FormatTest, NoOperandAlignment) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AlignOperands = false; verifyFormat("aaaaaaaaaaaaaa(aaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n" @@ -3637,7 +3654,7 @@ } TEST_F(FormatTest, BreakingBeforeNonAssigmentOperators) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; verifyFormat("int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" @@ -3646,7 +3663,7 @@ } TEST_F(FormatTest, AllowBinPackingInsideArguments) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; Style.BinPackArguments = false; Style.ColumnLimit = 40; @@ -3758,7 +3775,7 @@ " aaaaaaaaaaa(aaaaaaaaaaa),\n" " aaaaaaaaaaaaaaaaaaaaat(aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}"); - FormatStyle OnePerLine = getLLVMStyle(); + FormatStyle OnePerLine = getLLVMStyle(FormatStyle::LK_Cpp); OnePerLine.ConstructorInitializerAllOnOneLineOrOnePerLine = true; OnePerLine.AllowAllParametersOfDeclarationOnNextLine = false; verifyFormat("SomeClass::Constructor()\n" @@ -3809,7 +3826,7 @@ } TEST_F(FormatTest, BreakConstructorInitializersAfterColon) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon; verifyFormat("Constructor() : Initializer(FitsOnTheLine) {}"); @@ -4055,7 +4072,7 @@ getLLVMStyleWithColumns(65)); // This test takes VERY long when memoization is broken. - FormatStyle OnePerLine = getLLVMStyle(); + FormatStyle OnePerLine = getLLVMStyle(FormatStyle::LK_Cpp); OnePerLine.ConstructorInitializerAllOnOneLineOrOnePerLine = true; OnePerLine.BinPackParameters = false; std::string input = "Constructor()\n" @@ -4173,7 +4190,7 @@ "aaaaaaaaaaaaaaaaaaaaaaa::aaaaaaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa);"); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.PointerAlignment = FormatStyle::PAS_Left; verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaaaa* const aaaaaaaaaaaa) {}", @@ -4739,7 +4756,7 @@ } TEST_F(FormatTest, ConfigurableBreakAssignmentPenalty) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); verifyFormat("int aaaaaaaaaaaaaaaaaaaaaaaaaa =\n" " bbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccccccccccccc;", Style); @@ -4802,7 +4819,7 @@ verifyFormat( "SomeLongVariableName->someFunction(foooooooo(aaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaaa));"); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " aaaaaaaaaaa aaaaaaaa, aaaaaaaaa aaaaaaa) {}", @@ -4985,7 +5002,7 @@ " : aaaaaaaaaaaaaaaaaaaaaa\n" " : aaaaaaaaaaaaaaaaaaaaaaaaaaaa;"); - FormatStyle NoBinPacking = getLLVMStyle(); + FormatStyle NoBinPacking = getLLVMStyle(FormatStyle::LK_Cpp); NoBinPacking.BinPackArguments = false; verifyFormat( "void f() {\n" @@ -5033,7 +5050,7 @@ } TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeTernaryOperators = false; Style.ColumnLimit = 70; verifyFormat( @@ -5239,7 +5256,7 @@ } TEST_F(FormatTest, ReturnTypeBreakingStyle) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); // No declarations or definitions should be moved to own line. Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None; verifyFormat("class A {\n" @@ -5373,9 +5390,9 @@ } TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) { - FormatStyle NoBreak = getLLVMStyle(); + FormatStyle NoBreak = getLLVMStyle(FormatStyle::LK_Cpp); NoBreak.AlwaysBreakBeforeMultilineStrings = false; - FormatStyle Break = getLLVMStyle(); + FormatStyle Break = getLLVMStyle(FormatStyle::LK_Cpp); Break.AlwaysBreakBeforeMultilineStrings = true; verifyFormat("aaaa = \"bbbb\"\n" " \"cccc\";", @@ -5687,7 +5704,7 @@ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" " .a();"); - FormatStyle NoBinPacking = getLLVMStyle(); + FormatStyle NoBinPacking = getLLVMStyle(FormatStyle::LK_Cpp); NoBinPacking.BinPackParameters = false; verifyFormat("aaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)\n" " .aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)\n" @@ -5776,7 +5793,7 @@ verifyFormat("int aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " const typename aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa);"); - FormatStyle AlwaysBreak = getLLVMStyle(); + FormatStyle AlwaysBreak = getLLVMStyle(FormatStyle::LK_Cpp); AlwaysBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes; verifyFormat("template \nclass C {};", AlwaysBreak); verifyFormat("template \nvoid f();", AlwaysBreak); @@ -5796,7 +5813,7 @@ " E *f();\n" "};"); - FormatStyle NeverBreak = getLLVMStyle(); + FormatStyle NeverBreak = getLLVMStyle(FormatStyle::LK_Cpp); NeverBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_No; verifyFormat("template class C {};", NeverBreak); verifyFormat("template void f();", NeverBreak); @@ -5875,7 +5892,7 @@ } TEST_F(FormatTest, WrapsTemplateParameters) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; Style.BreakBeforeBinaryOperators = FormatStyle::BOS_None; verifyFormat( @@ -6045,7 +6062,7 @@ verifyFormat( "(aaaaaaaaaa->*bbbbbbb)(\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa));"); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.PointerAlignment = FormatStyle::PAS_Left; verifyFormat("typedef bool* (Class::*Member)() const;", Style); } @@ -6165,7 +6182,7 @@ "void F(T) && = delete;", getGoogleStyle()); - FormatStyle AlignLeft = getLLVMStyle(); + FormatStyle AlignLeft = getLLVMStyle(FormatStyle::LK_Cpp); AlignLeft.PointerAlignment = FormatStyle::PAS_Left; verifyFormat("void A::b() && {}", AlignLeft); verifyFormat("Deleted& operator=(const Deleted&) & = default;", AlignLeft); @@ -6180,7 +6197,7 @@ verifyFormat("void Fn(T const&) const&;", AlignLeft); verifyFormat("void Fn(T const volatile&&) const volatile&&;", AlignLeft); - FormatStyle Spaces = getLLVMStyle(); + FormatStyle Spaces = getLLVMStyle(FormatStyle::LK_Cpp); Spaces.SpacesInCStyleCastParentheses = true; verifyFormat("Deleted &operator=(const Deleted &) & = default;", Spaces); verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;", Spaces); @@ -6318,7 +6335,7 @@ verifyGoogleFormat("template \n" "void f(int i = 0, SomeType** temps = NULL);"); - FormatStyle Left = getLLVMStyle(); + FormatStyle Left = getLLVMStyle(FormatStyle::LK_Cpp); Left.PointerAlignment = FormatStyle::PAS_Left; verifyFormat("x = *a(x) = *a(y);", Left); verifyFormat("for (;; *a = b) {\n}", Left); @@ -6434,7 +6451,7 @@ // foo d > v; doesn't make sense. verifyFormat("foo d> v;"); - FormatStyle PointerMiddle = getLLVMStyle(); + FormatStyle PointerMiddle = getLLVMStyle(FormatStyle::LK_Cpp); PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle; verifyFormat("delete *x;", PointerMiddle); verifyFormat("int * x;", PointerMiddle); @@ -6464,7 +6481,7 @@ verifyFormat("SomeType s __attribute__((unused)) (InitValue);"); verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused))\n" "aaaaaaaaaaaaaaaaaaaaaaa(int i);"); - FormatStyle AfterType = getLLVMStyle(); + FormatStyle AfterType = getLLVMStyle(FormatStyle::LK_Cpp); AfterType.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions; verifyFormat("__attribute__((nodebug)) void\n" "foo() {}\n", @@ -6490,7 +6507,7 @@ verifyFormat("int a = std::vector{1, 2, 3}[0];"); // Make sure we do not parse attributes as lambda introducers. - FormatStyle MultiLineFunctions = getLLVMStyle(); + FormatStyle MultiLineFunctions = getLLVMStyle(FormatStyle::LK_Cpp); MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; verifyFormat("[[unused]] int b() {\n" " return 42;\n" @@ -6503,7 +6520,7 @@ verifyFormat("template void Foo(Ts... ts) { Foo(ts...); }"); verifyFormat("template void Foo(Ts *... ts) {}"); - FormatStyle PointersLeft = getLLVMStyle(); + FormatStyle PointersLeft = getLLVMStyle(FormatStyle::LK_Cpp); PointersLeft.PointerAlignment = FormatStyle::PAS_Left; verifyFormat("template void Foo(Ts*... ts) {}", PointersLeft); } @@ -6738,7 +6755,7 @@ "LooooooooooooooooooooooooooongFunctionDeclaration(T... t);"); verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n" "LooooooooooooooooooooooooooongFunctionDeclaration(T /*t*/) {}"); - FormatStyle Indented = getLLVMStyle(); + FormatStyle Indented = getLLVMStyle(FormatStyle::LK_Cpp); Indented.IndentWrappedFunctionNames = true; verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n" " LoooooooooooooooooooooooooooooooongFunctionDeclaration();", @@ -6810,7 +6827,7 @@ verifyFormat("template // Templates on own line.\n" "static int // Some comment.\n" "MyFunction(int a);", - getLLVMStyle()); + getLLVMStyle(FormatStyle::LK_Cpp)); } TEST_F(FormatTest, FormatsArrays) { @@ -6890,7 +6907,7 @@ verifyFormat("import \"aaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaa\";", getLLVMStyleWithColumns(30)); - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AlwaysBreakBeforeMultilineStrings = true; Style.ColumnLimit = 0; verifyFormat("#import \"abc.h\"", Style); @@ -6905,7 +6922,7 @@ //===----------------------------------------------------------------------===// TEST_F(FormatTest, IncompleteParameterLists) { - FormatStyle NoBinPacking = getLLVMStyle(); + FormatStyle NoBinPacking = getLLVMStyle(FormatStyle::LK_Cpp); NoBinPacking.BinPackParameters = false; verifyFormat("void aaaaaaaaaaaaaaaaaa(int level,\n" " double *min_x,\n" @@ -7102,7 +7119,7 @@ verifyFormat("#define A {a, a},"); // Avoid breaking between equal sign and opening brace - FormatStyle AvoidBreakingFirstArgument = getLLVMStyle(); + FormatStyle AvoidBreakingFirstArgument = getLLVMStyle(FormatStyle::LK_Cpp); AvoidBreakingFirstArgument.PenaltyBreakBeforeFirstCallParameter = 200; verifyFormat("const std::unordered_map MyHashTable =\n" " {{\"aaaaaaaaaaaaaaaaaaaaa\", 0},\n" @@ -7135,7 +7152,7 @@ "SomeType t;"); // In combination with BinPackArguments = false. - FormatStyle NoBinPacking = getLLVMStyle(); + FormatStyle NoBinPacking = getLLVMStyle(FormatStyle::LK_Cpp); NoBinPacking.BinPackArguments = false; verifyFormat("const Aaaaaa aaaaa = {aaaaa,\n" " bbbbb,\n" @@ -7210,7 +7227,7 @@ format("vector SomeVector = { // aaa\n" " 1, 2, };")); - FormatStyle ExtraSpaces = getLLVMStyle(); + FormatStyle ExtraSpaces = getLLVMStyle(FormatStyle::LK_Cpp); ExtraSpaces.Cpp11BracedListStyle = false; ExtraSpaces.ColumnLimit = 75; verifyFormat("vector x{ 1, 2, 3, 4 };", ExtraSpaces); @@ -7282,7 +7299,7 @@ "};", ExtraSpaces); - FormatStyle SpaceBeforeBrace = getLLVMStyle(); + FormatStyle SpaceBeforeBrace = getLLVMStyle(FormatStyle::LK_Cpp); SpaceBeforeBrace.SpaceBeforeCpp11BracedList = true; verifyFormat("vector x {1, 2, 3, 4};", SpaceBeforeBrace); verifyFormat("f({}, {{}, {}}, MyMap[{k, v}]);", SpaceBeforeBrace); @@ -7444,7 +7461,7 @@ } TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { - FormatStyle DoNotMerge = getLLVMStyle(); + FormatStyle DoNotMerge = getLLVMStyle(FormatStyle::LK_Cpp); DoNotMerge.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; verifyFormat("void f() { return 42; }"); @@ -7490,7 +7507,7 @@ "};", getGoogleStyle()); - FormatStyle NoColumnLimit = getLLVMStyle(); + FormatStyle NoColumnLimit = getLLVMStyle(FormatStyle::LK_Cpp); NoColumnLimit.ColumnLimit = 0; EXPECT_EQ("A() : b(0) {}", format("A():b(0){}", NoColumnLimit)); EXPECT_EQ("class C {\n" @@ -7535,7 +7552,7 @@ } TEST_F(FormatTest, PullEmptyFunctionDefinitionsIntoSingleLine) { - FormatStyle MergeEmptyOnly = getLLVMStyle(); + FormatStyle MergeEmptyOnly = getLLVMStyle(FormatStyle::LK_Cpp); MergeEmptyOnly.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; verifyFormat("class C {\n" " int f() {}\n" @@ -7564,7 +7581,7 @@ } TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) { - FormatStyle MergeInlineOnly = getLLVMStyle(); + FormatStyle MergeInlineOnly = getLLVMStyle(FormatStyle::LK_Cpp); MergeInlineOnly.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; verifyFormat("class C {\n" " int f() { return 42; }\n" @@ -7604,7 +7621,7 @@ } TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) { - FormatStyle MergeInlineOnly = getLLVMStyle(); + FormatStyle MergeInlineOnly = getLLVMStyle(FormatStyle::LK_Cpp); MergeInlineOnly.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_InlineOnly; verifyFormat("class C {\n" @@ -7650,7 +7667,7 @@ } TEST_F(FormatTest, SplitEmptyFunction) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterFunction = true; @@ -7717,7 +7734,7 @@ Style); } TEST_F(FormatTest, KeepShortFunctionAfterPPElse) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; verifyFormat("#ifdef A\n" "int f() {}\n" @@ -7728,7 +7745,7 @@ } TEST_F(FormatTest, SplitEmptyClass) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterClass = true; Style.BraceWrapping.SplitEmptyRecord = false; @@ -7754,7 +7771,7 @@ } TEST_F(FormatTest, SplitEmptyStruct) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterStruct = true; Style.BraceWrapping.SplitEmptyRecord = false; @@ -7781,7 +7798,7 @@ } TEST_F(FormatTest, SplitEmptyUnion) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterUnion = true; Style.BraceWrapping.SplitEmptyRecord = false; @@ -7804,7 +7821,7 @@ } TEST_F(FormatTest, SplitEmptyNamespace) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterNamespace = true; Style.BraceWrapping.SplitEmptyNamespace = false; @@ -7832,7 +7849,7 @@ } TEST_F(FormatTest, NeverMergeShortRecords) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); verifyFormat("class Foo {\n" " Foo();\n" @@ -8084,7 +8101,7 @@ // Deeply nested part is untouched, rest is formatted. EXPECT_EQ(std::string("int i;\n") + Code + "int j;\n", format(std::string("int i;\n") + Code + "int j;\n", - getLLVMStyle(), SC_ExpectIncomplete)); + getLLVMStyle(FormatStyle::LK_Cpp), SC_ExpectIncomplete)); } //===----------------------------------------------------------------------===// @@ -8127,7 +8144,7 @@ " outRange9:(NSRange)out_range9;"); // When the function name has to be wrapped. - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); // ObjC ignores IndentWrappedFunctionNames when wrapping methods // and always indents instead. Style.IndentWrappedFunctionNames = false; @@ -8578,7 +8595,7 @@ } TEST_F(FormatTest, DoesNotTryToParseUDLiteralsInPreCpp11Code) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.Standard = FormatStyle::LS_Cpp03; EXPECT_EQ("#define x(_a) printf(\"foo\" _a);", format("#define x(_a) printf(\"foo\"_a);", Style)); @@ -9174,14 +9191,14 @@ format(" \"qqqqqqqqqqqqqqqqqqqqqqqqqq\\\n" "q\"; /* some\n" " comment */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("// qqqqqqqqqqqqqqqqqqqqqqqqqq\n" "/* some\n" " comment */", format("// qqqqqqqqqqqqqqqqqqqqqqqqqq\n" " /* some\n" " comment */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("// qqqqqqqqqqqqqqqqqqqqqqqqqq\\\n" "qqq\n" "/* some\n" @@ -9190,18 +9207,18 @@ "qqq\n" " /* some\n" " comment */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("inttt qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\\\n" "wwww; /* some\n" " comment */", format(" inttt qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\\\n" "wwww; /* some\n" " comment */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); } TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { - FormatStyle NoSpace = getLLVMStyle(); + FormatStyle NoSpace = getLLVMStyle(FormatStyle::LK_Cpp); NoSpace.SpaceBeforeParens = FormatStyle::SBPO_Never; verifyFormat("while(true)\n" @@ -9236,7 +9253,7 @@ verifyFormat("T A::operator()();", NoSpace); verifyFormat("X A::operator++(T);", NoSpace); - FormatStyle Space = getLLVMStyle(); + FormatStyle Space = getLLVMStyle(FormatStyle::LK_Cpp); Space.SpaceBeforeParens = FormatStyle::SBPO_Always; verifyFormat("int f ();", Space); @@ -9285,7 +9302,7 @@ } TEST_F(FormatTest, ConfigurableSpacesInParentheses) { - FormatStyle Spaces = getLLVMStyle(); + FormatStyle Spaces = getLLVMStyle(FormatStyle::LK_Cpp); Spaces.SpacesInParentheses = true; verifyFormat("do_something( ::globalVar );", Spaces); @@ -9395,7 +9412,7 @@ verifyFormat("int a[5];"); verifyFormat("a[3] += 42;"); - FormatStyle Spaces = getLLVMStyle(); + FormatStyle Spaces = getLLVMStyle(FormatStyle::LK_Cpp); Spaces.SpacesInSquareBrackets = true; // Lambdas unchanged. verifyFormat("int c = []() -> int { return 2; }();\n", Spaces); @@ -9418,7 +9435,7 @@ verifyFormat("a += 42;"); verifyFormat("a or_eq 8;"); - FormatStyle Spaces = getLLVMStyle(); + FormatStyle Spaces = getLLVMStyle(FormatStyle::LK_Cpp); Spaces.SpaceBeforeAssignmentOperators = false; verifyFormat("int a= 5;", Spaces); verifyFormat("a+= 42;", Spaces); @@ -9519,7 +9536,7 @@ " public bbbbbbbbbbbbbbbbbb {}", InheritanceStyle); - FormatStyle ForLoopStyle = getLLVMStyle(); + FormatStyle ForLoopStyle = getLLVMStyle(FormatStyle::LK_Cpp); ForLoopStyle.SpaceBeforeRangeBasedForLoopColon = false; verifyFormat("class Foo : public Bar {};", ForLoopStyle); verifyFormat("Foo::Foo() : foo(1) {}", ForLoopStyle); @@ -9536,7 +9553,7 @@ "}", ForLoopStyle); - FormatStyle NoSpaceStyle = getLLVMStyle(); + FormatStyle NoSpaceStyle = getLLVMStyle(FormatStyle::LK_Cpp); NoSpaceStyle.SpaceBeforeCtorInitializerColon = false; NoSpaceStyle.SpaceBeforeInheritanceColon = false; NoSpaceStyle.SpaceBeforeRangeBasedForLoopColon = false; @@ -9557,7 +9574,7 @@ } TEST_F(FormatTest, AlignConsecutiveAssignments) { - FormatStyle Alignment = getLLVMStyle(); + FormatStyle Alignment = getLLVMStyle(FormatStyle::LK_Cpp); Alignment.AlignConsecutiveAssignments = false; verifyFormat("int a = 5;\n" "int oneTwoThree = 123;", @@ -9746,7 +9763,7 @@ } TEST_F(FormatTest, AlignConsecutiveDeclarations) { - FormatStyle Alignment = getLLVMStyle(); + FormatStyle Alignment = getLLVMStyle(FormatStyle::LK_Cpp); Alignment.AlignConsecutiveDeclarations = false; verifyFormat("float const a = 5;\n" "int oneTwoThree = 123;", @@ -10083,7 +10100,7 @@ } TEST_F(FormatTest, LinuxBraceBreaking) { - FormatStyle LinuxBraceStyle = getLLVMStyle(); + FormatStyle LinuxBraceStyle = getLLVMStyle(FormatStyle::LK_Cpp); LinuxBraceStyle.BreakBeforeBraces = FormatStyle::BS_Linux; verifyFormat("namespace a\n" "{\n" @@ -10124,7 +10141,7 @@ } TEST_F(FormatTest, MozillaBraceBreaking) { - FormatStyle MozillaBraceStyle = getLLVMStyle(); + FormatStyle MozillaBraceStyle = getLLVMStyle(FormatStyle::LK_Cpp); MozillaBraceStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla; MozillaBraceStyle.FixNamespaceComments = false; verifyFormat("namespace a {\n" @@ -10169,7 +10186,7 @@ } TEST_F(FormatTest, StroustrupBraceBreaking) { - FormatStyle StroustrupBraceStyle = getLLVMStyle(); + FormatStyle StroustrupBraceStyle = getLLVMStyle(FormatStyle::LK_Cpp); StroustrupBraceStyle.BreakBeforeBraces = FormatStyle::BS_Stroustrup; verifyFormat("namespace a {\n" "class A {\n" @@ -10231,7 +10248,7 @@ } TEST_F(FormatTest, AllmanBraceBreaking) { - FormatStyle AllmanBraceStyle = getLLVMStyle(); + FormatStyle AllmanBraceStyle = getLLVMStyle(FormatStyle::LK_Cpp); AllmanBraceStyle.BreakBeforeBraces = FormatStyle::BS_Allman; EXPECT_EQ("namespace a\n" @@ -10450,7 +10467,7 @@ } TEST_F(FormatTest, GNUBraceBreaking) { - FormatStyle GNUBraceStyle = getLLVMStyle(); + FormatStyle GNUBraceStyle = getLLVMStyle(FormatStyle::LK_Cpp); GNUBraceStyle.BreakBeforeBraces = FormatStyle::BS_GNU; verifyFormat("namespace a\n" "{\n" @@ -10574,7 +10591,7 @@ } TEST_F(FormatTest, WebKitBraceBreaking) { - FormatStyle WebKitBraceStyle = getLLVMStyle(); + FormatStyle WebKitBraceStyle = getLLVMStyle(FormatStyle::LK_Cpp); WebKitBraceStyle.BreakBeforeBraces = FormatStyle::BS_WebKit; WebKitBraceStyle.FixNamespaceComments = false; verifyFormat("namespace a {\n" @@ -10618,7 +10635,7 @@ " } catch (const Exception &e) {\n" " }\n" "}\n", - getLLVMStyle()); + getLLVMStyle(FormatStyle::LK_Cpp)); } TEST_F(FormatTest, UnderstandsPragmas) { @@ -10638,7 +10655,7 @@ } TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.ColumnLimit = 20; verifyFormat("int a; // the\n" @@ -10753,7 +10770,7 @@ SmallVector Styles; Styles.resize(3); - Styles[0] = getLLVMStyle(); + Styles[0] = getLLVMStyle(FormatStyle::LK_Cpp); EXPECT_TRUE(getPredefinedStyle("LLVM", FormatStyle::LK_Cpp, &Styles[1])); EXPECT_TRUE(getPredefinedStyle("lLvM", FormatStyle::LK_Cpp, &Styles[2])); EXPECT_ALL_STYLES_EQUAL(Styles); @@ -10798,31 +10815,31 @@ Styles.resize(2); Styles[0] = getGoogleStyle(); - Styles[1] = getLLVMStyle(); + Styles[1] = getLLVMStyle(FormatStyle::LK_Cpp); EXPECT_EQ(0, parseConfiguration("BasedOnStyle: Google", &Styles[1]).value()); EXPECT_ALL_STYLES_EQUAL(Styles); Styles.resize(5); Styles[0] = getGoogleStyle(FormatStyle::LK_JavaScript); - Styles[1] = getLLVMStyle(); + Styles[1] = getLLVMStyle(FormatStyle::LK_Cpp); Styles[1].Language = FormatStyle::LK_JavaScript; EXPECT_EQ(0, parseConfiguration("BasedOnStyle: Google", &Styles[1]).value()); - Styles[2] = getLLVMStyle(); + Styles[2] = getLLVMStyle(FormatStyle::LK_Cpp); Styles[2].Language = FormatStyle::LK_JavaScript; EXPECT_EQ(0, parseConfiguration("Language: JavaScript\n" "BasedOnStyle: Google", &Styles[2]) .value()); - Styles[3] = getLLVMStyle(); + Styles[3] = getLLVMStyle(FormatStyle::LK_Cpp); Styles[3].Language = FormatStyle::LK_JavaScript; EXPECT_EQ(0, parseConfiguration("BasedOnStyle: Google\n" "Language: JavaScript", &Styles[3]) .value()); - Styles[4] = getLLVMStyle(); + Styles[4] = getLLVMStyle(FormatStyle::LK_Cpp); Styles[4].Language = FormatStyle::LK_JavaScript; EXPECT_EQ(0, parseConfiguration("---\n" "BasedOnStyle: LLVM\n" @@ -11073,7 +11090,7 @@ FormatStyle::SBPO_ControlStatements); Style.ColumnLimit = 123; - FormatStyle BaseStyle = getLLVMStyle(); + FormatStyle BaseStyle = getLLVMStyle(FormatStyle::LK_Cpp); CHECK_PARSE("BasedOnStyle: LLVM", ColumnLimit, BaseStyle.ColumnLimit); CHECK_PARSE("BasedOnStyle: LLVM\nColumnLimit: 1234", ColumnLimit, 1234u); @@ -11327,7 +11344,7 @@ } TEST_F(FormatTest, ConfigurationRoundTripTest) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); std::string YAML = configurationAsText(Style); FormatStyle ParsedStyle = {}; ParsedStyle.Language = FormatStyle::LK_Cpp; @@ -11462,7 +11479,7 @@ #endif // _MSC_VER TEST_F(FormatTest, ConstructorInitializerIndentWidth) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.ConstructorInitializerIndentWidth = 4; verifyFormat( @@ -11496,7 +11513,7 @@ } TEST_F(FormatTest, BreakConstructorInitializersBeforeComma) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma; Style.ConstructorInitializerIndentWidth = 4; verifyFormat("SomeClass::Constructor()\n" @@ -11980,7 +11997,7 @@ } TEST_F(FormatTest, FormatsBlocks) { - FormatStyle ShortBlocks = getLLVMStyle(); + FormatStyle ShortBlocks = getLLVMStyle(FormatStyle::LK_Cpp); ShortBlocks.AllowShortBlocksOnASingleLine = true; verifyFormat("int (^Block)(int, int);", ShortBlocks); verifyFormat("int (^Block1)(int, int) = ^(int i, int j)", ShortBlocks); @@ -12074,7 +12091,7 @@ verifyFormat("BOOL (^aaa)(void) = ^BOOL {\n" "};"); - FormatStyle FourIndent = getLLVMStyle(); + FormatStyle FourIndent = getLLVMStyle(FormatStyle::LK_Cpp); FourIndent.ObjCBlockIndentWidth = 4; verifyFormat("[operation setCompletionBlock:^{\n" " [self onOperationDone];\n" @@ -12083,7 +12100,7 @@ } TEST_F(FormatTest, FormatsBlocksWithZeroColumnWidth) { - FormatStyle ZeroColumn = getLLVMStyle(); + FormatStyle ZeroColumn = getLLVMStyle(FormatStyle::LK_Cpp); ZeroColumn.ColumnLimit = 0; verifyFormat("[[SessionService sharedService] " @@ -12156,21 +12173,21 @@ format("int a;\r\n" " int b;\r\n" " int c;\r\n", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("int a;\r\n" "int b;\r\n" "int c;\r\n", format("int a;\r\n" " int b;\n" " int c;\r\n", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("int a;\n" "int b;\n" "int c;\n", format("int a;\r\n" " int b;\n" " int c;\n", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("\"aaaaaaa \"\r\n" "\"bbbbbbb\";\r\n", format("\"aaaaaaa bbbbbbb\";\r\n", getLLVMStyleWithColumns(10))); @@ -12221,7 +12238,7 @@ } TEST_F(FormatTest, SpacesInAngles) { - FormatStyle Spaces = getLLVMStyle(); + FormatStyle Spaces = getLLVMStyle(FormatStyle::LK_Cpp); Spaces.SpacesInAngles = true; verifyFormat("static_cast< int >(arg);", Spaces); @@ -12249,7 +12266,7 @@ } TEST_F(FormatTest, SpaceAfterTemplateKeyword) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.SpaceAfterTemplateKeyword = false; verifyFormat("template void foo();", Style); } @@ -12432,7 +12449,7 @@ } TEST_F(FormatTest, FormatsTableGenCode) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.Language = FormatStyle::LK_TableGen; verifyFormat("include \"a.td\"\ninclude \"b.td\"", Style); } @@ -12441,7 +12458,7 @@ EXPECT_EQ("auto a = new unique_ptr[10];", format("auto a = new unique_ptr [ 10];")); - FormatStyle Spaces = getLLVMStyle(); + FormatStyle Spaces = getLLVMStyle(FormatStyle::LK_Cpp); Spaces.SpacesInSquareBrackets = true; EXPECT_EQ("auto a = new unique_ptr[ 10 ];", format("auto a = new unique_ptr [10];", Spaces)); @@ -12451,7 +12468,7 @@ EXPECT_EQ("auto a = unique_ptr[10]>;", format("auto a = unique_ptr < Foo < Bar>[ 10]> ;")); - FormatStyle Spaces = getLLVMStyle(); + FormatStyle Spaces = getLLVMStyle(FormatStyle::LK_Cpp); Spaces.SpacesInSquareBrackets = true; EXPECT_EQ("auto a = unique_ptr[ 10 ]>;", format("auto a = unique_ptr < Foo < Bar>[10]> ;", Spaces)); @@ -12478,7 +12495,7 @@ FS.addFile("/a/test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int i;"))); auto Style1 = getStyle("file", "/a/.clang-format", "Google", "", &FS); ASSERT_TRUE((bool)Style1); - ASSERT_EQ(*Style1, getLLVMStyle()); + ASSERT_EQ(*Style1, getLLVMStyle(FormatStyle::LK_Cpp)); // Test 2.1: fallback to default. ASSERT_TRUE( @@ -12498,12 +12515,12 @@ llvm::MemoryBuffer::getMemBuffer("IndentWidth: 2"))); Style2 = getStyle("file", "/b/test.cpp", "none", "", &FS); ASSERT_TRUE((bool)Style2); - ASSERT_EQ(*Style2, getLLVMStyle()); + ASSERT_EQ(*Style2, getLLVMStyle(FormatStyle::LK_Cpp)); // Test 2.4: format if yaml with no based style, while fallback is 'none'. Style2 = getStyle("{}", "a.h", "none", "", &FS); ASSERT_TRUE((bool)Style2); - ASSERT_EQ(*Style2, getLLVMStyle()); + ASSERT_EQ(*Style2, getLLVMStyle(FormatStyle::LK_Cpp)); // Test 3: format file in parent directory. ASSERT_TRUE( @@ -12566,7 +12583,7 @@ tooling::Replacement(Context.Sources, Context.getLocation(ID, 4, 13), 1, "nullptr")}); - format::FormatStyle Style = format::getLLVMStyle(); + format::FormatStyle Style = format::getLLVMStyle(FormatStyle::LK_Cpp); Style.ColumnLimit = 20; // Set column limit to 20 to increase readibility. auto FormattedReplaces = formatReplacements(Code, Replaces, Style); EXPECT_TRUE(static_cast(FormattedReplaces)) @@ -12595,7 +12612,7 @@ {tooling::Replacement(Context.Sources, Context.getLocation(ID, 1, 1), 0, "#include \"b.h\"\n")}); - format::FormatStyle Style = format::getLLVMStyle(); + format::FormatStyle Style = format::getLLVMStyle(FormatStyle::LK_Cpp); Style.SortIncludes = true; auto FormattedReplaces = formatReplacements(Code, Replaces, Style); EXPECT_TRUE(static_cast(FormattedReplaces)) @@ -12613,7 +12630,7 @@ } TEST_F(FormatTest, UTF8CharacterLiteralCpp03) { - format::FormatStyle Style = format::getLLVMStyle(); + format::FormatStyle Style = format::getLLVMStyle(FormatStyle::LK_Cpp); Style.Standard = FormatStyle::LS_Cpp03; // cpp03 recognize this string as identifier u8 and literal character 'a' EXPECT_EQ("auto c = u8 'a';", format("auto c = u8'a';", Style)); @@ -12658,19 +12675,21 @@ EXPECT_EQ("const auto &&[a, b] = f();", format("const auto && [a, b] = f();")); // Make sure we don't mistake structured bindings for lambdas. - FormatStyle PointerMiddle = getLLVMStyle(); + FormatStyle PointerMiddle = getLLVMStyle(FormatStyle::LK_Cpp); PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle; verifyFormat("auto [a1, b]{A * i};", getGoogleStyle()); - verifyFormat("auto [a2, b]{A * i};", getLLVMStyle()); + verifyFormat("auto [a2, b]{A * i};", getLLVMStyle(FormatStyle::LK_Cpp)); verifyFormat("auto [a3, b]{A * i};", PointerMiddle); verifyFormat("auto const [a1, b]{A * i};", getGoogleStyle()); - verifyFormat("auto const [a2, b]{A * i};", getLLVMStyle()); + verifyFormat("auto const [a2, b]{A * i};", getLLVMStyle(FormatStyle::LK_Cpp)); verifyFormat("auto const [a3, b]{A * i};", PointerMiddle); verifyFormat("auto const& [a1, b]{A * i};", getGoogleStyle()); - verifyFormat("auto const &[a2, b]{A * i};", getLLVMStyle()); + verifyFormat("auto const &[a2, b]{A * i};", + getLLVMStyle(FormatStyle::LK_Cpp)); verifyFormat("auto const & [a3, b]{A * i};", PointerMiddle); verifyFormat("auto const&& [a1, b]{A * i};", getGoogleStyle()); - verifyFormat("auto const &&[a2, b]{A * i};", getLLVMStyle()); + verifyFormat("auto const &&[a2, b]{A * i};", + getLLVMStyle(FormatStyle::LK_Cpp)); verifyFormat("auto const && [a3, b]{A * i};", PointerMiddle); EXPECT_EQ("for (const auto &&[a, b] : some_range) {\n}", @@ -12688,7 +12707,7 @@ EXPECT_EQ("auto const &[x, y]{expr};", format("auto const & [x,y] {expr};")); EXPECT_EQ("auto const &&[x, y]{expr};", format("auto const && [x,y] {expr};")); - format::FormatStyle Spaces = format::getLLVMStyle(); + format::FormatStyle Spaces = format::getLLVMStyle(FormatStyle::LK_Cpp); Spaces.SpacesInSquareBrackets = true; verifyFormat("auto [ a, b ] = f();", Spaces); verifyFormat("auto &&[ a, b ] = f();", Spaces); diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -34,9 +34,10 @@ SC_DoNotCheck }; - std::string format(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle(), - StatusCheck CheckComplete = SC_ExpectComplete) { + std::string + format(llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp), + StatusCheck CheckComplete = SC_ExpectComplete) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); std::vector Ranges(1, tooling::Range(0, Code.size())); @@ -56,7 +57,7 @@ } FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.ColumnLimit = ColumnLimit; return Style; } @@ -67,8 +68,9 @@ return Style; } - void verifyFormat(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + void + verifyFormat(llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable"; EXPECT_EQ(Code.str(), format(test::messUp(Code), Style)); } @@ -78,8 +80,9 @@ } /// \brief Verify that clang-format does not crash on the given input. - void verifyNoCrash(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + void + verifyNoCrash(llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { format(Code, Style, SC_DoNotCheck); } @@ -457,7 +460,7 @@ verifyFormat("f(/* aaaaaaaaaaaaaaaaaa = */\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); - FormatStyle NoBinPacking = getLLVMStyle(); + FormatStyle NoBinPacking = getLLVMStyle(FormatStyle::LK_Cpp); NoBinPacking.BinPackParameters = false; verifyFormat("aaaaaaaa(/* parameter 1 */ aaaaaa,\n" " /* parameter 2 */ aaaaaa,\n" @@ -625,12 +628,14 @@ EXPECT_EQ("//! Add leading\n" "//! whitespace", format("//!Add leading whitespace", getLLVMStyleWithColumns(20))); - EXPECT_EQ("// whitespace", format("//whitespace", getLLVMStyle())); + EXPECT_EQ("// whitespace", + format("//whitespace", getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("// Even if it makes the line exceed the column\n" "// limit", format("//Even if it makes the line exceed the column limit", getLLVMStyleWithColumns(51))); - EXPECT_EQ("//--But not here", format("//--But not here", getLLVMStyle())); + EXPECT_EQ("//--But not here", + format("//--But not here", getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/// line 1\n" "// add leading whitespace", format("/// line 1\n" @@ -2422,7 +2427,7 @@ " bbbbbbbbbbbb */ bbbbbbbbbbbbbbbbbbbbbbbbbbbb;", getLLVMStyleWithColumns(50))); - FormatStyle NoBinPacking = getLLVMStyle(); + FormatStyle NoBinPacking = getLLVMStyle(FormatStyle::LK_Cpp); NoBinPacking.BinPackParameters = false; EXPECT_EQ("someFunction(1, /* comment 1 */\n" " 2, /* comment 2 */\n" @@ -2791,62 +2796,65 @@ EXPECT_EQ("/*\n" " */", format("/*\n" - "*/", getLLVMStyle())); + "*/", + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/*\n" " */", format("/*\n" - " */", getLLVMStyle())); + " */", + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/*\n" " */", format("/*\n" - " */", getLLVMStyle())); + " */", + getLLVMStyle(FormatStyle::LK_Cpp))); // Align a single line. EXPECT_EQ("/*\n" " * line */", format("/*\n" "* line */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/*\n" " * line */", format("/*\n" " * line */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/*\n" " * line */", format("/*\n" " * line */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/*\n" " * line */", format("/*\n" " * line */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/**\n" " * line */", format("/**\n" "* line */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/**\n" " * line */", format("/**\n" " * line */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/**\n" " * line */", format("/**\n" " * line */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/**\n" " * line */", format("/**\n" " * line */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/**\n" " * line */", format("/**\n" " * line */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); // Align the end '*/' after a line. EXPECT_EQ("/*\n" @@ -2854,61 +2862,64 @@ " */", format("/*\n" "* line\n" - "*/", getLLVMStyle())); + "*/", + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/*\n" " * line\n" " */", format("/*\n" " * line\n" - " */", getLLVMStyle())); + " */", + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/*\n" " * line\n" " */", format("/*\n" " * line\n" - " */", getLLVMStyle())); + " */", + getLLVMStyle(FormatStyle::LK_Cpp))); // Align two lines. EXPECT_EQ("/* line 1\n" " * line 2 */", format("/* line 1\n" " * line 2 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/* line 1\n" " * line 2 */", format("/* line 1\n" "* line 2 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/* line 1\n" " * line 2 */", format("/* line 1\n" " * line 2 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/* line 1\n" " * line 2 */", format("/* line 1\n" " * line 2 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/* line 1\n" " * line 2 */", format("/* line 1\n" " * line 2 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("int i; /* line 1\n" " * line 2 */", format("int i; /* line 1\n" "* line 2 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("int i; /* line 1\n" " * line 2 */", format("int i; /* line 1\n" " * line 2 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("int i; /* line 1\n" " * line 2 */", format("int i; /* line 1\n" " * line 2 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); // Align several lines. EXPECT_EQ("/* line 1\n" @@ -2917,14 +2928,14 @@ format("/* line 1\n" " * line 2\n" "* line 3 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/* line 1\n" " * line 2\n" " * line 3 */", format("/* line 1\n" " * line 2\n" "* line 3 */", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); EXPECT_EQ("/*\n" "** line 1\n" "** line 2\n" @@ -2933,7 +2944,7 @@ "** line 1\n" " ** line 2\n" "*/", - getLLVMStyle())); + getLLVMStyle(FormatStyle::LK_Cpp))); // Align with different indent after the decorations. EXPECT_EQ("/*\n" @@ -2947,7 +2958,8 @@ " * line 2\n" " * line 3\n" "* line 4\n" - "*/", getLLVMStyle())); + "*/", + getLLVMStyle(FormatStyle::LK_Cpp))); // Align empty or blank lines. EXPECT_EQ("/**\n" @@ -2959,7 +2971,8 @@ "* \n" " * \n" " *\n" - "*/", getLLVMStyle())); + "*/", + getLLVMStyle(FormatStyle::LK_Cpp))); // Align while breaking and reflowing. EXPECT_EQ("/*\n" diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -27,7 +27,7 @@ class FormatTestObjC : public ::testing::Test { protected: FormatTestObjC() { - Style = getLLVMStyle(); + Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.Language = FormatStyle::LK_ObjC; } @@ -919,7 +919,7 @@ // Respect continuation indent and colon alignment (e.g. when object name is // short, and first selector is the longest one) - Style = getLLVMStyle(); + Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.Language = FormatStyle::LK_ObjC; Style.ContinuationIndentWidth = 8; verifyFormat("[self performSelectorOnMainThread:@selector(loadAccessories)\n" diff --git a/clang/unittests/Format/FormatTestRawStrings.cpp b/clang/unittests/Format/FormatTestRawStrings.cpp --- a/clang/unittests/Format/FormatTestRawStrings.cpp +++ b/clang/unittests/Format/FormatTestRawStrings.cpp @@ -29,9 +29,10 @@ protected: enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck }; - std::string format(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle(), - StatusCheck CheckComplete = SC_ExpectComplete) { + std::string + format(llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp), + StatusCheck CheckComplete = SC_ExpectComplete) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); std::vector Ranges(1, tooling::Range(0, Code.size())); @@ -56,13 +57,13 @@ } FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) { - return getStyleWithColumns(getLLVMStyle(), ColumnLimit); + return getStyleWithColumns(getLLVMStyle(FormatStyle::LK_Cpp), ColumnLimit); } int ReplacementCount; FormatStyle getRawStringPbStyleWithColumns(unsigned ColumnLimit) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.ColumnLimit = ColumnLimit; Style.RawStringFormats = { { @@ -77,7 +78,7 @@ } FormatStyle getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle) { - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); Style.RawStringFormats = { { /*Language=*/FormatStyle::LK_Cpp, diff --git a/clang/unittests/Format/FormatTestSelective.cpp b/clang/unittests/Format/FormatTestSelective.cpp --- a/clang/unittests/Format/FormatTestSelective.cpp +++ b/clang/unittests/Format/FormatTestSelective.cpp @@ -33,7 +33,7 @@ return *Result; } - FormatStyle Style = getLLVMStyle(); + FormatStyle Style = getLLVMStyle(FormatStyle::LK_Cpp); }; TEST_F(FormatTestSelective, RemovesTrailingWhitespaceOfFormattedLine) { diff --git a/clang/unittests/Format/FormatTestTableGen.cpp b/clang/unittests/Format/FormatTestTableGen.cpp --- a/clang/unittests/Format/FormatTestTableGen.cpp +++ b/clang/unittests/Format/FormatTestTableGen.cpp @@ -51,5 +51,9 @@ " \"very long help string\">;\n"); } +TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) { + verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;\n"); +} + } // namespace format } // end namespace clang diff --git a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp --- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp @@ -20,10 +20,9 @@ class NamespaceEndCommentsFixerTest : public ::testing::Test { protected: - std::string - fixNamespaceEndComments(llvm::StringRef Code, - const std::vector &Ranges, - const FormatStyle &Style = getLLVMStyle()) { + std::string fixNamespaceEndComments( + llvm::StringRef Code, const std::vector &Ranges, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); tooling::Replacements Replaces = @@ -34,9 +33,9 @@ return *Result; } - std::string - fixNamespaceEndComments(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + std::string fixNamespaceEndComments( + llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { return fixNamespaceEndComments( Code, /*Ranges=*/{1, tooling::Range(0, Code.size())}, Style); @@ -185,7 +184,7 @@ "}")); // Add comment for namespaces which will be 'compacted' - FormatStyle CompactNamespacesStyle = getLLVMStyle(); + FormatStyle CompactNamespacesStyle = getLLVMStyle(FormatStyle::LK_Cpp); CompactNamespacesStyle.CompactNamespaces = true; EXPECT_EQ("namespace out { namespace in {\n" "int i;\n" @@ -424,7 +423,7 @@ fixNamespaceEndComments("namespace A {}; // namespace")); // Update invalid comments for compacted namespaces. - FormatStyle CompactNamespacesStyle = getLLVMStyle(); + FormatStyle CompactNamespacesStyle = getLLVMStyle(FormatStyle::LK_Cpp); CompactNamespacesStyle.CompactNamespaces = true; EXPECT_EQ("namespace out { namespace in {\n" "}} // namespace out::in", diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp --- a/clang/unittests/Format/SortIncludesTest.cpp +++ b/clang/unittests/Format/SortIncludesTest.cpp @@ -44,7 +44,7 @@ return Cursor; } - FormatStyle FmtStyle = getLLVMStyle(); + FormatStyle FmtStyle = getLLVMStyle(FormatStyle::LK_Cpp); tooling::IncludeStyle &Style = FmtStyle.IncludeStyle; }; diff --git a/clang/unittests/Format/UsingDeclarationsSorterTest.cpp b/clang/unittests/Format/UsingDeclarationsSorterTest.cpp --- a/clang/unittests/Format/UsingDeclarationsSorterTest.cpp +++ b/clang/unittests/Format/UsingDeclarationsSorterTest.cpp @@ -19,9 +19,9 @@ class UsingDeclarationsSorterTest : public ::testing::Test { protected: - std::string sortUsingDeclarations(llvm::StringRef Code, - const std::vector &Ranges, - const FormatStyle &Style = getLLVMStyle()) { + std::string sortUsingDeclarations( + llvm::StringRef Code, const std::vector &Ranges, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); tooling::Replacements Replaces = @@ -32,8 +32,9 @@ return *Result; } - std::string sortUsingDeclarations(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + std::string sortUsingDeclarations( + llvm::StringRef Code, + const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Cpp)) { return sortUsingDeclarations(Code, /*Ranges=*/{1, tooling::Range(0, Code.size())}, Style); diff --git a/clang/unittests/Rename/ClangRenameTest.h b/clang/unittests/Rename/ClangRenameTest.h --- a/clang/unittests/Rename/ClangRenameTest.h +++ b/clang/unittests/Rename/ClangRenameTest.h @@ -93,8 +93,9 @@ } std::string format(llvm::StringRef Code) { - tooling::Replacements Replaces = format::reformat( - format::getLLVMStyle(), Code, {tooling::Range(0, Code.size())}); + tooling::Replacements Replaces = + format::reformat(format::getLLVMStyle(format::FormatStyle::LK_Cpp), + Code, {tooling::Range(0, Code.size())}); auto ChangedCode = tooling::applyAllReplacements(Code, Replaces); EXPECT_TRUE(static_cast(ChangedCode)); if (!ChangedCode) { diff --git a/clang/unittests/Tooling/HeaderIncludesTest.cpp b/clang/unittests/Tooling/HeaderIncludesTest.cpp --- a/clang/unittests/Tooling/HeaderIncludesTest.cpp +++ b/clang/unittests/Tooling/HeaderIncludesTest.cpp @@ -41,7 +41,8 @@ } const std::string FileName = "fix.cpp"; - IncludeStyle Style = format::getLLVMStyle().IncludeStyle; + IncludeStyle Style = + format::getLLVMStyle(format::FormatStyle::LK_Cpp).IncludeStyle; }; TEST_F(HeaderIncludesTest, NoExistingIncludeWithoutDefine) { diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp --- a/clang/unittests/Tooling/RefactoringTest.cpp +++ b/clang/unittests/Tooling/RefactoringTest.cpp @@ -1299,7 +1299,7 @@ ApplyAtomicChangesTest() : FilePath("file.cc") { Spec.Cleanup = true; Spec.Format = ApplyChangesSpec::kAll; - Spec.Style = format::getLLVMStyle(); + Spec.Style = format::getLLVMStyle(format::FormatStyle::LK_Cpp); } ~ApplyAtomicChangesTest() override {}