r181196 - Added Mozilla style, cleaned get*Style methods.
Alexander Kornienko
alexfh at google.com
Mon May 6 07:11:27 PDT 2013
Author: alexfh
Date: Mon May 6 09:11:27 2013
New Revision: 181196
URL: http://llvm.org/viewvc/llvm-project?rev=181196&view=rev
Log:
Added Mozilla style, cleaned get*Style methods.
Summary: Patch based on a patch by Ehsan Akhgari.
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D750
Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/tools/clang-format/ClangFormat.cpp
Modified: cfe/trunk/include/clang/Format/Format.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=181196&r1=181195&r2=181196&view=diff
==============================================================================
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Mon May 6 09:11:27 2013
@@ -57,9 +57,6 @@ struct FormatStyle {
/// instead of \c A<A<int>> for LS_Cpp03.
LanguageStandard Standard;
- /// \brief If \c true, analyze the formatted file for C++03 compatibility.
- bool DeriveBackwardsCompatibility;
-
/// \brief Indent case labels one level from the switch statement.
///
/// When false, use the same indentation level as for the switch statement.
@@ -109,6 +106,10 @@ FormatStyle getGoogleStyle();
/// http://www.chromium.org/developers/coding-style.
FormatStyle getChromiumStyle();
+/// \brief Returns a format style complying with Mozilla's style guide:
+/// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
+FormatStyle getMozillaStyle();
+
/// \brief Reformats the given \p Ranges in the token stream coming out of
/// \c Lex.
///
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=181196&r1=181195&r2=181196&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon May 6 09:11:27 2013
@@ -36,43 +36,43 @@ namespace format {
FormatStyle getLLVMStyle() {
FormatStyle LLVMStyle;
- LLVMStyle.ColumnLimit = 80;
- LLVMStyle.MaxEmptyLinesToKeep = 1;
- LLVMStyle.PointerBindsToType = false;
- LLVMStyle.DerivePointerBinding = false;
LLVMStyle.AccessModifierOffset = -2;
- LLVMStyle.Standard = FormatStyle::LS_Cpp03;
- LLVMStyle.IndentCaseLabels = false;
- LLVMStyle.SpacesBeforeTrailingComments = 1;
- LLVMStyle.BinPackParameters = true;
+ LLVMStyle.AlignEscapedNewlinesLeft = false;
LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
- LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
+ LLVMStyle.BinPackParameters = true;
+ LLVMStyle.ColumnLimit = 80;
+ LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
+ LLVMStyle.DerivePointerBinding = false;
+ LLVMStyle.IndentCaseLabels = false;
+ LLVMStyle.MaxEmptyLinesToKeep = 1;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
LLVMStyle.PenaltyExcessCharacter = 1000000;
LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 75;
- LLVMStyle.AlignEscapedNewlinesLeft = false;
+ LLVMStyle.PointerBindsToType = false;
+ LLVMStyle.SpacesBeforeTrailingComments = 1;
+ LLVMStyle.Standard = FormatStyle::LS_Cpp03;
return LLVMStyle;
}
FormatStyle getGoogleStyle() {
FormatStyle GoogleStyle;
- GoogleStyle.ColumnLimit = 80;
- GoogleStyle.MaxEmptyLinesToKeep = 1;
- GoogleStyle.PointerBindsToType = true;
- GoogleStyle.DerivePointerBinding = true;
GoogleStyle.AccessModifierOffset = -1;
- GoogleStyle.Standard = FormatStyle::LS_Auto;
- GoogleStyle.IndentCaseLabels = true;
- GoogleStyle.SpacesBeforeTrailingComments = 2;
- GoogleStyle.BinPackParameters = true;
+ GoogleStyle.AlignEscapedNewlinesLeft = true;
GoogleStyle.AllowAllParametersOfDeclarationOnNextLine = true;
- GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
+ GoogleStyle.BinPackParameters = true;
+ GoogleStyle.ColumnLimit = 80;
+ GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
+ GoogleStyle.DerivePointerBinding = true;
+ GoogleStyle.IndentCaseLabels = true;
+ GoogleStyle.MaxEmptyLinesToKeep = 1;
GoogleStyle.ObjCSpaceBeforeProtocolList = false;
GoogleStyle.PenaltyExcessCharacter = 1000000;
GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
- GoogleStyle.AlignEscapedNewlinesLeft = true;
+ GoogleStyle.PointerBindsToType = true;
+ GoogleStyle.SpacesBeforeTrailingComments = 2;
+ GoogleStyle.Standard = FormatStyle::LS_Auto;
return GoogleStyle;
}
@@ -86,6 +86,18 @@ FormatStyle getChromiumStyle() {
return ChromiumStyle;
}
+FormatStyle getMozillaStyle() {
+ FormatStyle MozillaStyle = getLLVMStyle();
+ MozillaStyle.AllowAllParametersOfDeclarationOnNextLine = false;
+ MozillaStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
+ MozillaStyle.DerivePointerBinding = true;
+ MozillaStyle.IndentCaseLabels = true;
+ MozillaStyle.ObjCSpaceBeforeProtocolList = false;
+ MozillaStyle.PenaltyReturnTypeOnItsOwnLine = 200;
+ MozillaStyle.PointerBindsToType = true;
+ return MozillaStyle;
+}
+
// Returns the length of everything up to the first possible line break after
// the ), ], } or > matching \c Tok.
static unsigned getLengthToMatchingParen(const AnnotatedToken &Tok) {
Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=181196&r1=181195&r2=181196&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Mon May 6 09:11:27 2013
@@ -36,7 +36,7 @@ Lengths("length", cl::desc("Format a ran
"Can only be used with one input file."));
static cl::opt<std::string> Style(
"style",
- cl::desc("Coding style, currently supports: LLVM, Google, Chromium."),
+ cl::desc("Coding style, currently supports: LLVM, Google, Chromium, Mozilla."),
cl::init("LLVM"));
static cl::opt<bool> Inplace("i",
cl::desc("Inplace edit <file>s, if specified."));
@@ -63,8 +63,13 @@ static FormatStyle getStyle() {
FormatStyle TheStyle = getGoogleStyle();
if (Style == "LLVM")
TheStyle = getLLVMStyle();
- if (Style == "Chromium")
+ else if (Style == "Chromium")
TheStyle = getChromiumStyle();
+ else if (Style == "Mozilla")
+ TheStyle = getMozillaStyle();
+ else if (Style != "Google")
+ llvm::errs() << "Unknown style " << Style << ", using Google style.\n";
+
return TheStyle;
}
More information about the cfe-commits
mailing list