From da05848f04ef5c5052810b56e31f9d8b20fcb293 Mon Sep 17 00:00:00 2001 From: Ilia Udalov Date: Wed, 15 Feb 2017 01:39:51 +0300 Subject: [PATCH 1/3] Add clang-format --- .clang-format | 94 ++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 8 ++++ src/cpp/lua-module.cpp | 10 ++--- src/cpp/shared-table.cpp | 8 ++-- src/cpp/threading.cpp | 22 +++++----- src/cpp/threading.h | 2 +- 6 files changed, 123 insertions(+), 21 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3177ab8 --- /dev/null +++ b/.clang-format @@ -0,0 +1,94 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignOperands: false +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +BreakStringLiterals: true +ColumnLimit: 120 +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 8 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '$' +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: false +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... + diff --git a/CMakeLists.txt b/CMakeLists.txt index e6c29b7..0a2bec3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,3 +46,11 @@ set_target_properties(tests PROPERTIES COMPILE_FLAGS "${ENABLE_WARNINGS} ${GENER install(FILES ${LUA_SOURCES} ${LUA_TEST_SOURCES} DESTINATION ${CMAKE_BINARY_DIR} PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ) + +#---------- +# FORMAT - +#---------- +add_custom_target( + format + COMMAND clang-format -i ${TEST_SOURCES} ${SOURCES} +) diff --git a/src/cpp/lua-module.cpp b/src/cpp/lua-module.cpp index 64739bd..15a08d7 100644 --- a/src/cpp/lua-module.cpp +++ b/src/cpp/lua-module.cpp @@ -24,11 +24,11 @@ extern "C" int luaopen_libeffil(lua_State *L) { SharedTable::getUserType(lua); ThreadFactory::getUserType(lua); sol::table public_api = lua.create_table_with( - "thread", createThreadFactory, - "thread_id", threadId, - "sleep", sleep, - "yield", yield, - "share", createShare + "thread", createThreadFactory, // + "thread_id", threadId, // + "sleep", sleep, // + "yield", yield, // + "share", createShare // ); sol::stack::push(lua, public_api); return 1; diff --git a/src/cpp/shared-table.cpp b/src/cpp/shared-table.cpp index 16622c5..1b77c71 100644 --- a/src/cpp/shared-table.cpp +++ b/src/cpp/shared-table.cpp @@ -19,10 +19,10 @@ SharedTable::SharedTable(const SharedTable& init) sol::object SharedTable::getUserType(sol::state_view &lua) { static sol::usertype type( - "new", sol::no_constructor, - sol::meta_function::new_index, &SharedTable::luaSet, - sol::meta_function::index, &SharedTable::luaGet, - sol::meta_function::length, &SharedTable::size + "new", sol::no_constructor, // + sol::meta_function::new_index, &SharedTable::luaSet,// + sol::meta_function::index, &SharedTable::luaGet,// + sol::meta_function::length, &SharedTable::size // ); sol::stack::push(lua, type); return sol::stack::pop(lua); diff --git a/src/cpp/threading.cpp b/src/cpp/threading.cpp index 83b1f7b..c9b4e63 100644 --- a/src/cpp/threading.cpp +++ b/src/cpp/threading.cpp @@ -167,11 +167,11 @@ std::string LuaThread::status() const sol::object LuaThread::getUserType(sol::state_view &lua) { static sol::usertype type( - "new", sol::no_constructor, - "cancel", &LuaThread::cancel, - "pause", &LuaThread::pause, - "resume", &LuaThread::resume, - "status", &LuaThread::status, + "new", sol::no_constructor, // + "cancel", &LuaThread::cancel, // + "pause", &LuaThread::pause, // + "resume", &LuaThread::resume, // + "status", &LuaThread::status, // "wait", &LuaThread::wait ); sol::stack::push(lua, type); @@ -248,12 +248,12 @@ std::string ThreadFactory::packageCPath(const sol::optional& value) sol::object ThreadFactory::getUserType(sol::state_view &lua) { static sol::usertype type( - "new", sol::no_constructor, - sol::meta_function::call, &ThreadFactory::runThread, - "stepwise", &ThreadFactory::stepwise, - "step", &ThreadFactory::step, - "package_path", &ThreadFactory::packagePath, - "package_cpath", &ThreadFactory::packageCPath + "new", sol::no_constructor, // + sol::meta_function::call, &ThreadFactory::runThread,// + "stepwise", &ThreadFactory::stepwise, // + "step", &ThreadFactory::step, // + "package_path", &ThreadFactory::packagePath, // + "package_cpath", &ThreadFactory::packageCPath // ); sol::stack::push(lua, type); return sol::stack::pop(lua); diff --git a/src/cpp/threading.h b/src/cpp/threading.h index 7c0d28b..7395a29 100644 --- a/src/cpp/threading.h +++ b/src/cpp/threading.h @@ -16,7 +16,7 @@ void sleep(int64_t, sol::optional); class LuaThread { public: enum class ThreadStatus { - Running, + Running = 1, Paused, Canceled, Completed, From e15dac51a01ae1102160e052092aa443f3ee96b8 Mon Sep 17 00:00:00 2001 From: Ilia Udalov Date: Wed, 15 Feb 2017 17:13:42 +0300 Subject: [PATCH 2/3] Fix format target in CMakeLists.txt --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a2bec3..304ce41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,6 @@ install(FILES ${LUA_SOURCES} ${LUA_TEST_SOURCES} #---------- # FORMAT - #---------- -add_custom_target( - format +add_custom_target( format COMMAND clang-format -i ${TEST_SOURCES} ${SOURCES} ) From 98049e6cf995cc3e896a8e9dcc5706e6cc945ff4 Mon Sep 17 00:00:00 2001 From: Ilia Udalov Date: Fri, 17 Feb 2017 21:37:10 +0300 Subject: [PATCH 3/3] Git rid from unsupported options --- .clang-format | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.clang-format b/.clang-format index 3177ab8..23f0d05 100644 --- a/.clang-format +++ b/.clang-format @@ -36,7 +36,6 @@ BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: true -BreakStringLiterals: true ColumnLimit: 120 ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 8 @@ -53,12 +52,9 @@ IncludeCategories: Priority: 3 - Regex: '.*' Priority: 1 -IncludeIsMainRegex: '$' IndentCaseLabels: true IndentWidth: 4 IndentWrappedFunctionNames: false -JavaScriptQuotes: Leave -JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true MacroBlockBegin: '' MacroBlockEnd: '' @@ -77,7 +73,6 @@ PointerAlignment: Left ReflowComments: true SortIncludes: false SpaceAfterCStyleCast: false -SpaceAfterTemplateKeyword: false SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements SpaceInEmptyParentheses: false