Index: cfe/trunk/include/clang/Format/Format.h =================================================================== --- cfe/trunk/include/clang/Format/Format.h +++ cfe/trunk/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. Index: cfe/trunk/lib/Format/Format.cpp =================================================================== --- cfe/trunk/lib/Format/Format.cpp +++ cfe/trunk/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; @@ -729,8 +729,7 @@ return GoogleStyle; } - FormatStyle GoogleStyle = getLLVMStyle(); - GoogleStyle.Language = Language; + FormatStyle GoogleStyle = getLLVMStyle(Language); GoogleStyle.AccessModifierOffset = -1; GoogleStyle.AlignEscapedNewlines = FormatStyle::ENAS_Left; @@ -2344,8 +2343,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)) Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -120,6 +120,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. //===----------------------------------------------------------------------===//