diff --git a/libsolidity/analysis/ControlFlowBuilder.cpp b/libsolidity/analysis/ControlFlowBuilder.cpp index c20968a14d79..5424980e021b 100644 --- a/libsolidity/analysis/ControlFlowBuilder.cpp +++ b/libsolidity/analysis/ControlFlowBuilder.cpp @@ -582,7 +582,7 @@ void ControlFlowBuilder::operator()(yul::FunctionCall const& _functionCall) solAssert(m_currentNode && m_inlineAssembly, ""); yul::ASTWalker::operator()(_functionCall); - if (auto const *builtinFunction = m_inlineAssembly->dialect().builtin(_functionCall.functionName.name)) + if (auto const* builtinFunction = m_inlineAssembly->dialect().builtin(_functionCall.functionName.name)) { if (builtinFunction->controlFlowSideEffects.canTerminate) connect(m_currentNode, m_transactionReturnNode); diff --git a/libsolidity/analysis/ControlFlowBuilder.h b/libsolidity/analysis/ControlFlowBuilder.h index 93bc52bd6936..db706eb7f70d 100644 --- a/libsolidity/analysis/ControlFlowBuilder.h +++ b/libsolidity/analysis/ControlFlowBuilder.h @@ -152,7 +152,7 @@ class ControlFlowBuilder: private ASTConstVisitor, private yul::ASTWalker CFGNode* newLabel(); CFGNode* createLabelHere(); - void placeAndConnectLabel(CFGNode *_node); + void placeAndConnectLabel(CFGNode* _node); CFG::NodeContainer& m_nodeContainer; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 5c28d3cd2a78..97197dba467f 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1552,7 +1552,7 @@ void TypeChecker::checkExpressionAssignment(Type const& _type, Expression const& { bool isLocalOrReturn = false; if (auto const* identifier = dynamic_cast(&_expression)) - if (auto const *variableDeclaration = dynamic_cast(identifier->annotation().referencedDeclaration)) + if (auto const* variableDeclaration = dynamic_cast(identifier->annotation().referencedDeclaration)) if (variableDeclaration->isLocalOrReturn()) isLocalOrReturn = true; if (!isLocalOrReturn) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 7b3e42143804..decaf9990fa7 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -3425,7 +3425,7 @@ MemberList::MemberMap FunctionType::nativeMembers(ASTNode const* _scope) const if (auto const* functionDefinition = dynamic_cast(m_declaration)) { solAssert(functionDefinition->visibility() > Visibility::Internal, ""); - auto const *contract = dynamic_cast(m_declaration->scope()); + auto const* contract = dynamic_cast(m_declaration->scope()); solAssert(contract, ""); solAssert(contract->isLibrary(), ""); return {{"selector", TypeProvider::fixedBytes(4)}}; diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 8eba084eba7b..6707d980a88a 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -373,7 +373,7 @@ class CompilerContext /// Stack of current visited AST nodes, used for location attachment std::stack m_visitedNodes; /// The runtime context if in Creation mode, this is used for generating tags that would be stored into the storage and then used at runtime. - CompilerContext *m_runtimeContext; + CompilerContext* m_runtimeContext; /// The index of the runtime subroutine. size_t m_runtimeSub = std::numeric_limits::max(); /// An index of low-level function labels by name. diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 517f49c35331..68e20ca815b5 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -2231,7 +2231,7 @@ bool ExpressionCompiler::visit(IndexRangeAccess const& _indexAccess) Type const& baseType = *_indexAccess.baseExpression().annotation().type; - ArrayType const *arrayType = dynamic_cast(&baseType); + ArrayType const* arrayType = dynamic_cast(&baseType); if (!arrayType) if (ArraySliceType const* sliceType = dynamic_cast(&baseType)) arrayType = &sliceType->arrayType(); diff --git a/libyul/backends/evm/StackLayoutGenerator.cpp b/libyul/backends/evm/StackLayoutGenerator.cpp index 88190b45b3fc..27191c39e2f4 100644 --- a/libyul/backends/evm/StackLayoutGenerator.cpp +++ b/libyul/backends/evm/StackLayoutGenerator.cpp @@ -346,7 +346,7 @@ void StackLayoutGenerator::processEntryPoint(CFG::BasicBlock const& _entry, CFG: // entry layout of the backwards jump target as the initial exit layout of the backwards-jumping block. while (!toVisit.empty()) { - CFG::BasicBlock const *block = *toVisit.begin(); + CFG::BasicBlock const* block = *toVisit.begin(); toVisit.pop_front(); if (visited.count(block)) diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 7bcd8cca36c9..9ba5bc5bbe92 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -4,6 +4,16 @@ set -eu ERROR_LOG="$(mktemp -t check_style_XXXXXX.log)" +if [ "$(uname)" == "Darwin" ]; then + if ! command -v ggrep &> /dev/null + then + brew install grep # install GNU grep on macOS + fi + grepCommand="ggrep" +else + grepCommand="grep" +fi + EXCLUDE_FILES=( # The line below is left unquoted to allow the shell globbing path expansion test/cmdlineTests/*/{err,output} @@ -57,7 +67,7 @@ REPO_ROOT="$(dirname "$0")"/.. cd "$REPO_ROOT" || exit 1 WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" | - grep -v "test/libsolidity/ASTJSON\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" || true + ${grepCommand} -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" || true ) if [[ "$WHITESPACE" != "" ]] @@ -70,27 +80,30 @@ fi function preparedGrep { - git grep -nIE "$1" -- '*.h' '*.cpp' | grep -v "${EXCLUDE_FILES_JOINED}" + git grep -nIE "$1" -- '*.h' '*.cpp' | ${grepCommand} -v "${EXCLUDE_FILES_JOINED}" return $? } FORMATERROR=$( ( - preparedGrep "#include \"" | grep -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters + preparedGrep "#include \"" | ${grepCommand} -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters preparedGrep "\<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch" - preparedGrep "\\s*\([^=]*\>\s:\s.*\)" # no space before range based for-loop - preparedGrep "\\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if" + preparedGrep "\[[:space:]]*\([^=]*\>[[:space:]]:[[:space:]].*\)" # no space before range based for-loop + preparedGrep "\[[:space:]]*\(.*\)[[:space:]]*\{[[:space:]]*$" # "{\n" on same line as "if" preparedGrep "namespace .*\{" - preparedGrep "[,\(<]\s*const " # const on left side of type - preparedGrep "^\s*(static)?\s*const " # const on left side of type (beginning of line) + preparedGrep "[,\(<][[:space:]]*const " # const on left side of type + preparedGrep "^[[:space:]]*(static)?[[:space:]]*const " # const on left side of type (beginning of line) preparedGrep "^ [^*]|[^*] | [^*]" # uses spaces for indentation or mixes spaces and tabs - preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | grep -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return) + preparedGrep "[a-zA-Z0-9_][[:space:]]*[&][a-zA-Z_]" | ${grepCommand} -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return) # right-aligned reference pointer star (needs to exclude return and comments) - preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | grep -E -v -e "return [*]" -e "^* [*]" -e "^*//.*" + preparedGrep "[a-zA-Z0-9_][[:space:]]*[*][a-zA-Z_]" | ${grepCommand} -E -v -e "return [*]" -e ":[[:space:]]*[*]" -e ".*//.*" # unqualified move()/forward() checks, i.e. make sure that std::move() and std::forward() are used instead of move() and forward() - preparedGrep "move\(.+\)" | grep -v "std::move" | grep -E "[^a-z]move" - preparedGrep "forward\(.+\)" | grep -v "std::forward" | grep -E "[^a-z]forward" -) | grep -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/" || true + preparedGrep "move\(.+\)" | ${grepCommand} -v "std::move" | ${grepCommand} -E "[^a-z]move" + preparedGrep "forward\(.+\)" | ${grepCommand} -v "std::forward" | ${grepCommand} -E "[^a-z]forward" + # make sure `using namespace std` is not used in INCLUDE_DIRECTORIES + # shellcheck disable=SC2068,SC2068 + ${grepCommand} -nIE -d skip "using namespace std;" ${NAMESPACE_STD_FREE_FILES[@]} +) | ${grepCommand} -E -v -e "^[a-zA-Z\./]*:[0-9]*:[[:space:]]*/(/|\*)" -e "^test/" || true ) # Special error handling for `using namespace std;` exclusion, since said statement can be present in the test directory