add format and logger
This commit is contained in:
parent
5c492ddbf4
commit
32e3dc7a77
137
.clang-format
Normal file
137
.clang-format
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveMacros: false
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 80
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DeriveLineEnding: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||||
|
Priority: 3
|
||||||
|
SortPriority: 0
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 1
|
||||||
|
SortPriority: 0
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
PointerAlignment: Right
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: true
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInConditionalStatement: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
Standard: Latest
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 8
|
||||||
|
UseCRLF: false
|
||||||
|
UseTab: Never
|
||||||
|
...
|
||||||
|
|
||||||
@ -12,7 +12,16 @@ include_directories(${ANTLR4_INCLUDE_DIR})
|
|||||||
# Custom sources start here
|
# Custom sources start here
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/antlrgen)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/antlrgen)
|
||||||
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.cc")
|
||||||
|
file(GLOB_RECURSE HEADERS "include/*.hpp" "include/*.h" "include/*.hh")
|
||||||
|
|
||||||
|
file(GLOB MY_SOURCES "src/*.cpp")
|
||||||
|
file(GLOB MY_HEADERS "include/*.h")
|
||||||
|
|
||||||
|
include(formatting.cmake)
|
||||||
|
clang_format(format ${MY_SOURCES} ${MY_HEADERS})
|
||||||
|
clang_format_check(format_check ${MY_SOURCES} ${MY_HEADERS})
|
||||||
|
|
||||||
add_executable(sysy ${SOURCES})
|
add_executable(sysy ${SOURCES})
|
||||||
|
# message(STATUS "${SOURCES}")
|
||||||
target_link_libraries(sysy antlr4_static)
|
target_link_libraries(sysy antlr4_static)
|
||||||
174
formatting.cmake
Normal file
174
formatting.cmake
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2019 by George Cave - gcave@stablecoder.ca
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
# use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
# the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations under
|
||||||
|
# the License.
|
||||||
|
|
||||||
|
#
|
||||||
|
# clang-format
|
||||||
|
#
|
||||||
|
find_program(CLANG_FORMAT_EXE "clang-format")
|
||||||
|
mark_as_advanced(FORCE CLANG_FORMAT_EXE)
|
||||||
|
if(CLANG_FORMAT_EXE)
|
||||||
|
message(STATUS "clang-format found: ${CLANG_FORMAT_EXE}")
|
||||||
|
else()
|
||||||
|
message(STATUS "clang-format not found!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Generates a 'format' target using a custom name, files, and include
|
||||||
|
# directories all being parameters.
|
||||||
|
#
|
||||||
|
# Do note that in order for sources to be inherited properly, the source paths
|
||||||
|
# must be reachable from where the macro is called, or otherwise require a full
|
||||||
|
# path for proper inheritance.
|
||||||
|
#
|
||||||
|
# ~~~
|
||||||
|
# Required:
|
||||||
|
# TARGET_NAME - The name of the target to create.
|
||||||
|
#
|
||||||
|
# Optional: ARGN - The list of targets OR files to format. Relative and absolute
|
||||||
|
# paths are accepted.
|
||||||
|
# ~~~
|
||||||
|
function(clang_format TARGET_NAME)
|
||||||
|
if(CLANG_FORMAT_EXE)
|
||||||
|
set(FORMAT_FILES)
|
||||||
|
# Check through the ARGN's, determine existent files
|
||||||
|
foreach(item IN LISTS ARGN)
|
||||||
|
if(TARGET ${item})
|
||||||
|
# If the item is a target, then we'll attempt to grab the associated
|
||||||
|
# source files from it.
|
||||||
|
get_target_property(_TARGET_TYPE ${item} TYPE)
|
||||||
|
if(NOT _TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
|
||||||
|
get_property(
|
||||||
|
_TEMP
|
||||||
|
TARGET ${item}
|
||||||
|
PROPERTY SOURCES)
|
||||||
|
foreach(iter IN LISTS _TEMP)
|
||||||
|
if(EXISTS ${iter})
|
||||||
|
set(FORMAT_FILES ${FORMAT_FILES} ${iter})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
elseif(EXISTS ${item})
|
||||||
|
# Check if it's a full file path
|
||||||
|
set(FORMAT_FILES ${FORMAT_FILES} ${item})
|
||||||
|
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${item})
|
||||||
|
# Check if it's based on the current source dir
|
||||||
|
set(FORMAT_FILES ${FORMAT_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/${item})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Make the target
|
||||||
|
if(FORMAT_FILES)
|
||||||
|
add_custom_target(${TARGET_NAME} COMMAND ${CLANG_FORMAT_EXE} -i
|
||||||
|
-style=file ${FORMAT_FILES})
|
||||||
|
|
||||||
|
if(NOT TARGET format)
|
||||||
|
add_custom_target(format)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_dependencies(format ${TARGET_NAME})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(clang_format_check TARGET_NAME)
|
||||||
|
if(CLANG_FORMAT_EXE)
|
||||||
|
set(FORMAT_FILES)
|
||||||
|
# Check through the ARGN's, determine existent files
|
||||||
|
foreach(item IN LISTS ARGN)
|
||||||
|
if(TARGET ${item})
|
||||||
|
# If the item is a target, then we'll attempt to grab the associated
|
||||||
|
# source files from it.
|
||||||
|
get_target_property(_TARGET_TYPE ${item} TYPE)
|
||||||
|
if(NOT _TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
|
||||||
|
get_property(
|
||||||
|
_TEMP
|
||||||
|
TARGET ${item}
|
||||||
|
PROPERTY SOURCES)
|
||||||
|
foreach(iter IN LISTS _TEMP)
|
||||||
|
if(EXISTS ${iter})
|
||||||
|
set(FORMAT_FILES ${FORMAT_FILES} ${iter})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
elseif(EXISTS ${item})
|
||||||
|
# Check if it's a full file path
|
||||||
|
set(FORMAT_FILES ${FORMAT_FILES} ${item})
|
||||||
|
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${item})
|
||||||
|
# Check if it's based on the current source dir
|
||||||
|
set(FORMAT_FILES ${FORMAT_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/${item})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Make the target
|
||||||
|
if(FORMAT_FILES)
|
||||||
|
add_custom_target(${TARGET_NAME} COMMAND ${CLANG_FORMAT_EXE} -n -Werror
|
||||||
|
-style=file ${FORMAT_FILES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
#
|
||||||
|
# cmake-format
|
||||||
|
#
|
||||||
|
find_program(CMAKE_FORMAT_EXE "cmake-format")
|
||||||
|
mark_as_advanced(FORCE CMAKE_FORMAT_EXE)
|
||||||
|
if(CMAKE_FORMAT_EXE)
|
||||||
|
message(STATUS "cmake-format found: ${CMAKE_FORMAT_EXE}")
|
||||||
|
else()
|
||||||
|
message(STATUS "cmake-format not found!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# When called, this function will call 'cmake-format' program on all listed
|
||||||
|
# files (if both the program and the files exist and are found)
|
||||||
|
# ~~~
|
||||||
|
# Required:
|
||||||
|
# TARGET_NAME - The name of the target to create.
|
||||||
|
#
|
||||||
|
# Optional:
|
||||||
|
# ARGN - Any arguments passed in will be considered as 'files' to perform the
|
||||||
|
# formatting on. Any items that are not files will be ignored. Both relative and
|
||||||
|
# absolute paths are accepted.
|
||||||
|
# ~~~
|
||||||
|
function(cmake_format TARGET_NAME)
|
||||||
|
if(CMAKE_FORMAT_EXE)
|
||||||
|
set(FORMAT_FILES)
|
||||||
|
# Determine files that exist
|
||||||
|
foreach(iter IN LISTS ARGN)
|
||||||
|
if(EXISTS ${iter})
|
||||||
|
set(FORMAT_FILES ${FORMAT_FILES} ${iter})
|
||||||
|
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${iter})
|
||||||
|
set(FORMAT_FILES ${FORMAT_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/${iter})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Generate target
|
||||||
|
if(FORMAT_FILES)
|
||||||
|
if(TARGET ${TARGET_NAME})
|
||||||
|
message(
|
||||||
|
ERROR
|
||||||
|
"Cannot create cmake-format target '${TARGET_NAME}', already exists.")
|
||||||
|
else()
|
||||||
|
add_custom_target(${TARGET_NAME} COMMAND ${CMAKE_FORMAT_EXE} -i
|
||||||
|
${FORMAT_FILES})
|
||||||
|
|
||||||
|
if(NOT TARGET cmake-format)
|
||||||
|
add_custom_target(cmake-format)
|
||||||
|
endif()
|
||||||
|
add_dependencies(cmake-format ${TARGET_NAME})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
@ -506,10 +506,12 @@ public:
|
|||||||
m_num_args_range = NArgsRange{0, 1};
|
m_num_args_range = NArgsRange{0, 1};
|
||||||
break;
|
break;
|
||||||
case nargs_pattern::any:
|
case nargs_pattern::any:
|
||||||
m_num_args_range = NArgsRange{0, (std::numeric_limits<std::size_t>::max)()};
|
m_num_args_range =
|
||||||
|
NArgsRange{0, (std::numeric_limits<std::size_t>::max)()};
|
||||||
break;
|
break;
|
||||||
case nargs_pattern::at_least_one:
|
case nargs_pattern::at_least_one:
|
||||||
m_num_args_range = NArgsRange{1, (std::numeric_limits<std::size_t>::max)()};
|
m_num_args_range =
|
||||||
|
NArgsRange{1, (std::numeric_limits<std::size_t>::max)()};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@ -706,8 +708,7 @@ public:
|
|||||||
using ValueType = typename T::value_type;
|
using ValueType = typename T::value_type;
|
||||||
auto lhs = get<T>();
|
auto lhs = get<T>();
|
||||||
return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs),
|
return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs),
|
||||||
std::end(rhs),
|
std::end(rhs), [](const auto &a, const auto &b) {
|
||||||
[](const auto &a, const auto &b) {
|
|
||||||
return std::any_cast<const ValueType &>(a) == b;
|
return std::any_cast<const ValueType &>(a) == b;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1120,16 +1121,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
explicit operator bool() const {
|
explicit operator bool() const {
|
||||||
auto arg_used = std::any_of(m_argument_map.cbegin(),
|
auto arg_used = std::any_of(m_argument_map.cbegin(), m_argument_map.cend(),
|
||||||
m_argument_map.cend(),
|
[](auto &it) { return it.second->m_is_used; });
|
||||||
[](auto &it) {
|
auto subparser_used =
|
||||||
return it.second->m_is_used;
|
std::any_of(m_subparser_used.cbegin(), m_subparser_used.cend(),
|
||||||
});
|
[](auto &it) { return it.second; });
|
||||||
auto subparser_used = std::any_of(m_subparser_used.cbegin(),
|
|
||||||
m_subparser_used.cend(),
|
|
||||||
[](auto &it) {
|
|
||||||
return it.second;
|
|
||||||
});
|
|
||||||
|
|
||||||
return m_is_parsed && (arg_used || subparser_used);
|
return m_is_parsed && (arg_used || subparser_used);
|
||||||
}
|
}
|
||||||
@ -1183,8 +1179,7 @@ public:
|
|||||||
/* Getter for arguments and subparsers.
|
/* Getter for arguments and subparsers.
|
||||||
* @throws std::logic_error in case of an invalid argument or subparser name
|
* @throws std::logic_error in case of an invalid argument or subparser name
|
||||||
*/
|
*/
|
||||||
template <typename T = Argument>
|
template <typename T = Argument> T &at(std::string_view name) {
|
||||||
T& at(std::string_view name) {
|
|
||||||
if constexpr (std::is_same_v<T, Argument>) {
|
if constexpr (std::is_same_v<T, Argument>) {
|
||||||
return (*this)[name];
|
return (*this)[name];
|
||||||
} else {
|
} else {
|
||||||
@ -1660,7 +1655,8 @@ private:
|
|||||||
}
|
}
|
||||||
std::size_t max_size = 0;
|
std::size_t max_size = 0;
|
||||||
for ([[maybe_unused]] const auto &[unused, argument] : m_argument_map) {
|
for ([[maybe_unused]] const auto &[unused, argument] : m_argument_map) {
|
||||||
max_size = std::max<std::size_t>(max_size, argument->get_arguments_length());
|
max_size =
|
||||||
|
std::max<std::size_t>(max_size, argument->get_arguments_length());
|
||||||
}
|
}
|
||||||
for ([[maybe_unused]] const auto &[command, unused] : m_subparser_map) {
|
for ([[maybe_unused]] const auto &[command, unused] : m_subparser_map) {
|
||||||
max_size = std::max<std::size_t>(max_size, command.size());
|
max_size = std::max<std::size_t>(max_size, command.size());
|
||||||
5037
include/3rdparty/easylogging++.h
vendored
Normal file
5037
include/3rdparty/easylogging++.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3526
src/3rdparty/easylogging++.cpp
vendored
Normal file
3526
src/3rdparty/easylogging++.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user