From be8c7a2804b466972f1b7c2ab964a81e2349217f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Barzowski?= Date: Fri, 21 Jul 2017 15:05:07 -0400 Subject: [PATCH] Braces style: Linux -> WebKit --- .clang-format | 2 +- core/ast.h | 6 ++---- core/desugarer.cpp | 6 ++---- core/formatter.cpp | 42 +++++++++++++-------------------------- core/lexer_test.cpp | 3 +-- core/libjsonnet.cpp | 3 +-- core/parser.cpp | 6 ++---- core/parser_test.cpp | 3 +-- core/pass.cpp | 3 +-- core/pass.h | 3 +-- core/state.h | 6 ++---- core/unicode.h | 3 +-- core/vm.cpp | 9 +++------ cpp/libjsonnet++.cpp | 6 ++---- cpp/libjsonnet++_test.cpp | 3 +-- include/libjsonnet++.h | 6 ++---- 16 files changed, 37 insertions(+), 73 deletions(-) diff --git a/.clang-format b/.clang-format index abab679a3..13df42c10 100644 --- a/.clang-format +++ b/.clang-format @@ -21,7 +21,7 @@ AlwaysBreakTemplateDeclarations: true BinPackArguments: false BinPackParameters: true BreakBeforeBinaryOperators: None -BreakBeforeBraces: Linux +BreakBeforeBraces: WebKit BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false diff --git a/core/ast.h b/core/ast.h index 83a0a68b5..ce0b3a6cb 100644 --- a/core/ast.h +++ b/core/ast.h @@ -893,8 +893,7 @@ struct Var : public AST { /** Allocates ASTs on demand, frees them in its destructor. */ -class Allocator -{ +class Allocator { std::map internedIdentifiers; ASTs allocated; @@ -941,8 +940,7 @@ class Allocator } }; -namespace -{ +namespace { // Precedences used by various compilation units are defined here. const int APPLY_PRECEDENCE = 2; // Function calls and indexing. const int UNARY_PRECEDENCE = 4; // Logical and bitwise negation, unary + - diff --git a/core/desugarer.cpp b/core/desugarer.cpp index 32ac4faf4..771d108a6 100644 --- a/core/desugarer.cpp +++ b/core/desugarer.cpp @@ -82,8 +82,7 @@ static constexpr char STD_CODE[] = { * Temporary variables introduced here should be prefixed with $ to ensure they do not clash with * variables used in user code. */ -class Desugarer -{ +class Desugarer { Allocator *alloc; template @@ -316,8 +315,7 @@ class Desugarer * * Returns all variables and original expressions via super_vars. */ - class SubstituteSelfSuper : public CompilerPass - { + class SubstituteSelfSuper : public CompilerPass { Desugarer *desugarer; SuperVars &superVars; unsigned &counter; diff --git a/core/formatter.cpp b/core/formatter.cpp index a6d043687..11e3c92ec 100644 --- a/core/formatter.cpp +++ b/core/formatter.cpp @@ -123,8 +123,7 @@ static void fodder_count(unsigned &column, const Fodder &fodder, bool space_befo column++; } -class Unparser -{ +class Unparser { public: private: std::ostream &o; @@ -640,8 +639,7 @@ static void fodder_move_front(Fodder &a, Fodder &b) /** A generic Pass that does nothing but can be extended to easily define real passes. */ -class FmtPass : public CompilerPass -{ +class FmtPass : public CompilerPass { protected: FmtOpts opts; @@ -649,8 +647,7 @@ class FmtPass : public CompilerPass FmtPass(Allocator &alloc, const FmtOpts &opts) : CompilerPass(alloc), opts(opts) {} }; -class EnforceStringStyle : public FmtPass -{ +class EnforceStringStyle : public FmtPass { using FmtPass::visit; public: @@ -685,8 +682,7 @@ class EnforceStringStyle : public FmtPass } }; -class EnforceCommentStyle : public FmtPass -{ +class EnforceCommentStyle : public FmtPass { public: bool firstFodder; EnforceCommentStyle(Allocator &alloc, const FmtOpts &opts) @@ -726,8 +722,7 @@ class EnforceCommentStyle : public FmtPass } }; -class EnforceMaximumBlankLines : public FmtPass -{ +class EnforceMaximumBlankLines : public FmtPass { public: EnforceMaximumBlankLines(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) {} void fodderElement(FodderElement &f) @@ -738,8 +733,7 @@ class EnforceMaximumBlankLines : public FmtPass } }; -class StripComments : public FmtPass -{ +class StripComments : public FmtPass { public: StripComments(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) {} void fodder(Fodder &fodder) @@ -753,8 +747,7 @@ class StripComments : public FmtPass } }; -class StripEverything : public FmtPass -{ +class StripEverything : public FmtPass { public: StripEverything(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) {} void fodder(Fodder &fodder) @@ -763,8 +756,7 @@ class StripEverything : public FmtPass } }; -class StripAllButComments : public FmtPass -{ +class StripAllButComments : public FmtPass { public: StripAllButComments(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) {} Fodder comments; @@ -814,8 +806,7 @@ bool contains_newline(const Fodder &fodder) } /* Commas should appear at the end of an object/array only if the closing token is on a new line. */ -class FixTrailingCommas : public FmtPass -{ +class FixTrailingCommas : public FmtPass { using FmtPass::visit; public: @@ -889,8 +880,7 @@ class FixTrailingCommas : public FmtPass }; /* Remove nested parens. */ -class FixParens : public FmtPass -{ +class FixParens : public FmtPass { using FmtPass::visit; public: @@ -908,8 +898,7 @@ class FixParens : public FmtPass }; /* Ensure ApplyBrace syntax sugar is used in the case of A + { }. */ -class FixPlusObject : public FmtPass -{ +class FixPlusObject : public FmtPass { using FmtPass::visit; public: @@ -933,8 +922,7 @@ class FixPlusObject : public FmtPass }; /* Remove final colon in slices. */ -class NoRedundantSliceColon : public FmtPass -{ +class NoRedundantSliceColon : public FmtPass { using FmtPass::visit; public: @@ -954,8 +942,7 @@ class NoRedundantSliceColon : public FmtPass }; /* Ensure syntax sugar is used where possible. */ -class PrettyFieldNames : public FmtPass -{ +class PrettyFieldNames : public FmtPass { using FmtPass::visit; public: @@ -1024,8 +1011,7 @@ class PrettyFieldNames : public FmtPass } }; -class FixIndentation -{ +class FixIndentation { FmtOpts opts; unsigned column; diff --git a/core/lexer_test.cpp b/core/lexer_test.cpp index cd654bc53..fd2e8b98b 100644 --- a/core/lexer_test.cpp +++ b/core/lexer_test.cpp @@ -19,8 +19,7 @@ limitations under the License. #include #include "gtest/gtest.h" -namespace -{ +namespace { void testLex(const char* name, const char* input, const std::list& tokens, const std::string& error) { diff --git a/core/libjsonnet.cpp b/core/libjsonnet.cpp index d77c44fc8..8f6d688c8 100644 --- a/core/libjsonnet.cpp +++ b/core/libjsonnet.cpp @@ -467,8 +467,7 @@ char *jsonnet_fmt_snippet(JsonnetVm *vm, const char *filename, const char *snipp return nullptr; // Never happens. } -namespace -{ +namespace { enum EvalKind { REGULAR, MULTI, STREAM }; } // namespace diff --git a/core/parser.cpp b/core/parser.cpp index 9bfc4ee4c..ba5ff4dd7 100644 --- a/core/parser.cpp +++ b/core/parser.cpp @@ -45,8 +45,7 @@ std::string jsonnet_unparse_number(double v) return ss.str(); } -namespace -{ +namespace { static bool op_is_unary(const std::string &op, UnaryOp &uop) { auto it = unary_map.find(op); @@ -82,8 +81,7 @@ LocationRange span(const Token &begin, AST *end) /** Holds state while parsing a given token list. */ -class Parser -{ +class Parser { // The private member functions are utilities for dealing with the token stream. StaticError unexpected(const Token &tok, const std::string &while_) diff --git a/core/parser_test.cpp b/core/parser_test.cpp index fa124134e..cd9620669 100644 --- a/core/parser_test.cpp +++ b/core/parser_test.cpp @@ -21,8 +21,7 @@ limitations under the License. #include "gtest/gtest.h" #include "lexer.h" -namespace -{ +namespace { // Checks whether the provided snippet parses successfully. // TODO(dzc): Update this test to check the parsed AST against an expected AST. void testParse(const char* snippet) diff --git a/core/pass.cpp b/core/pass.cpp index 55abd5095..7902d9b90 100644 --- a/core/pass.cpp +++ b/core/pass.cpp @@ -361,8 +361,7 @@ void CompilerPass::file(AST *&body, Fodder &final_fodder) } /** A pass that clones the AST it is given. */ -class ClonePass : public CompilerPass -{ +class ClonePass : public CompilerPass { public: ClonePass(Allocator &alloc) : CompilerPass(alloc) {} virtual void expr(AST *&ast); diff --git a/core/pass.h b/core/pass.h index d57fd41dc..230294e20 100644 --- a/core/pass.h +++ b/core/pass.h @@ -21,8 +21,7 @@ limitations under the License. /** A generic Pass that does nothing but can be extended to easily define real passes. */ -class CompilerPass -{ +class CompilerPass { public: protected: Allocator &alloc; diff --git a/core/state.h b/core/state.h index f80fd701c..a5aa4e315 100644 --- a/core/state.h +++ b/core/state.h @@ -17,8 +17,7 @@ limitations under the License. #ifndef JSONNET_STATE_H #define JSONNET_STATE_H -namespace -{ +namespace { /** Mark & sweep: advanced by 1 each GC cycle. */ typedef unsigned char GarbageCollectionMark; @@ -261,8 +260,7 @@ struct HeapString : public HeapEntity { }; /** The heap does memory management, i.e. garbage collection. */ -class Heap -{ +class Heap { /** How many objects must exist in the heap before we bother doing garbage collection? */ unsigned gcTuneMinObjects; diff --git a/core/unicode.h b/core/unicode.h index c8f32d9e6..5742c4ff9 100644 --- a/core/unicode.h +++ b/core/unicode.h @@ -145,8 +145,7 @@ static inline UString decode_utf8(const std::string &s) /** A stringstream-like class capable of holding unicode codepoints. * The C++ standard does not support std::basic_stringstream* outputs) { for (const char* c = jsonnet_output; *c != '\0';) { diff --git a/cpp/libjsonnet++_test.cpp b/cpp/libjsonnet++_test.cpp index c5a4a98c4..8a753bd08 100644 --- a/cpp/libjsonnet++_test.cpp +++ b/cpp/libjsonnet++_test.cpp @@ -22,8 +22,7 @@ limitations under the License. #include "gtest/gtest.h" -namespace jsonnet -{ +namespace jsonnet { std::string readFile(const std::string& filename) { std::ifstream in(filename); diff --git a/include/libjsonnet++.h b/include/libjsonnet++.h index 5639fd01f..7b4b857cc 100644 --- a/include/libjsonnet++.h +++ b/include/libjsonnet++.h @@ -26,10 +26,8 @@ extern "C" { #include "libjsonnet.h" } -namespace jsonnet -{ -class Jsonnet -{ +namespace jsonnet { +class Jsonnet { public: Jsonnet(); ~Jsonnet();