From bbcc915316efa71c27abb841bcc4290cdd06bfd4 Mon Sep 17 00:00:00 2001 From: Lucian Radu Teodorescu Date: Sun, 7 Jul 2019 22:07:35 +0300 Subject: [PATCH] Apply clang-tidy to the project Changed the way clang-tidy is applied; now it's an addon to the compilation. --- CMakeLists.txt | 34 ++++++++++--------- src/Feather/Utils/cppif/FeatherNodes.hpp | 6 ++-- src/Feather/Utils/cppif/FeatherTypes.hpp | 22 ++++++------ src/Feather/src/Utils/cppif/FeatherNodes.cpp | 12 +++---- src/Feather/src/Utils/cppif/FeatherTypes.cpp | 18 +++++----- src/Nest/Utils/cppif/NodeHandle.hpp | 5 ++- src/Nest/Utils/cppif/StringRef.hpp | 8 ++--- src/Nest/Utils/cppif/TypeWithStorage.hpp | 2 +- src/SparrowCompiler/SparrowCompiler.cpp | 1 + src/SparrowFrontend/Grammar/Parser.cpp | 6 ++-- src/SparrowFrontend/Helpers/DeclsHelpers.cpp | 1 + src/SparrowFrontend/Nodes/Decl.cpp | 4 +-- src/SparrowFrontend/Nodes/Decl.hpp | 12 +++---- src/SparrowFrontend/Nodes/Exp.cpp | 1 + src/SparrowFrontend/Nodes/Exp.hpp | 6 ++-- src/SparrowFrontend/Nodes/Generics.cpp | 6 ++-- src/SparrowFrontend/Nodes/Generics.hpp | 10 +++--- src/SparrowFrontend/Nodes/Module.hpp | 4 +-- .../Services/Callable/CallableHelpers.cpp | 4 +-- .../Services/Convert/ConversionResult.cpp | 2 +- src/SparrowFrontend/SparrowFrontendTypes.cpp | 2 +- src/SparrowFrontend/SparrowFrontendTypes.hpp | 2 +- unittests/Common/BackendMock.cpp | 2 +- unittests/Feather/TestFeatherNodes.cpp | 14 ++++---- unittests/Feather/TestTypes.cpp | 14 ++++---- unittests/Nest/TestType.cpp | 4 +-- .../SprCommon/GenGenericParams.cpp | 5 +-- unittests/SparrowFrontend/TestCallable.cpp | 6 ---- unittests/SparrowFrontend/TestConvert.cpp | 2 +- unittests/SparrowFrontend/TestGenerics.cpp | 6 ---- .../metatests/TestGenCallableDecl.cpp | 7 ---- .../metatests/TestGenGenericParams.cpp | 6 ---- .../metatests/TestGenValueForType.cpp | 6 ---- 33 files changed, 104 insertions(+), 136 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8415948a..2d8216f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,8 @@ option(BOOTSTRAP_SPARROW "Use system-wide SparrowCompiler to compile Sparrow fil message(STATUS "BOOTSTRAP_SPARROW: ${BOOTSTRAP_SPARROW}") option(SPARROW_PROFILING "Enable Tracy integration into Sparrow compiler" OFF) message(STATUS "SPARROW_PROFILING: ${SPARROW_PROFILING}") +option(ENABLE_TIDY "Enable clang-tidy checks when building" OFF) +message(STATUS "ENABLE_TIDY: ${ENABLE_TIDY}") # Where to output the results of the compilation set(OutDir ${CMAKE_CURRENT_SOURCE_DIR}/build/bin) @@ -121,39 +123,39 @@ endif() # Add target for clang-tidy set(TIDY_CHECKS - #-*, # Disable for non-debug builds + -*, # Disable for non-debug builds modernize-*, + bugprone-*, cppcoreguidelines-*, + -cppcoreguidelines-owning-memory, # not met, requires gsl -cppcoreguidelines-pro-bounds-array-to-pointer-decay, # not met, requires gsl -cppcoreguidelines-pro-bounds-constant-array-index, # not met, requires gsl -cppcoreguidelines-pro-bounds-pointer-arithmetic, # not met, requires gsl -cppcoreguidelines-pro-type-union-access, # not met (we use some unions) -cppcoreguidelines-pro-type-vararg, # not met (we are using printf) ) +string (REPLACE ";" " " TIDY_CHECKS "${TIDY_CHECKS}") -find_program(CLANG_TIDY_SCRIPT "run-clang-tidy.py" HINTS ${LLVM_TOOLS_BINARY_DIR}/../share/clang) -if(CLANG_TIDY_SCRIPT) +if(ENABLE_TIDY) # Search for clang-tidy and clang-apply-replacements find_program(CLANG_TIDY "clang-tidy" HINTS ${LLVM_TOOLS_BINARY_DIR}) - find_program(CLANG_APPLY_REPLACEMENTS "clang-apply-replacements" HINTS ${LLVM_TOOLS_BINARY_DIR}) + + message(STATUS "Tidy checks: ${TIDY_CHECKS}") + + set(TIDY_HEADER_FILTER ${CMAKE_SOURCE_DIR}/*) # Set extra arguments - set(TIDY_FIX 0) - set(TIDY_EXTRA_ARGS -quiet -format -style file) + set(TIDY_FIX 1) + set(TIDY_EXTRA_ARGS -quiet;-format-style=file) if (TIDY_FIX) - set(TIDY_EXTRA_ARGS ${TIDY_EXTRA_ARGS} -j 1 -fix) + set(TIDY_EXTRA_ARGS ${TIDY_EXTRA_ARGS};-fix) endif() - # Actually add the target - add_custom_target( - clang-tidy - COMMAND - ${CLANG_TIDY_SCRIPT} -header-filter='\.\.\/src\/.*\.hpp' -checks='${TIDY_CHECKS}' - -clang-tidy-binary ${CLANG_TIDY} - -clang-apply-replacements-binary ${CLANG_APPLY_REPLACEMENTS} - ${TIDY_EXTRA_ARGS} - ) + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-checks=\"${TIDY_CHECKS}\";-header-filter='${TIDY_HEADER_FILTER}';${TIDY_EXTRA_ARGS}" + CACHE STRING "" FORCE) +else() + set(CMAKE_CXX_CLANG_TIDY "") endif() # Ensure generation of compile_commands.json; needed for clang-tidy diff --git a/src/Feather/Utils/cppif/FeatherNodes.hpp b/src/Feather/Utils/cppif/FeatherNodes.hpp index 0554924f..61e18402 100644 --- a/src/Feather/Utils/cppif/FeatherNodes.hpp +++ b/src/Feather/Utils/cppif/FeatherNodes.hpp @@ -418,7 +418,7 @@ struct FunctionDecl : DeclNode { void setBody(NodeHandle body); //! @copydoc Nest::NodeHandle::type() - FunctionType type() const { return FunctionType(DeclNode::type()); } + FunctionType type() const { return {DeclNode::type()}; } private: static void setContextForChildrenImpl(ThisNodeType node); @@ -452,7 +452,7 @@ struct StructDecl : DeclNode { NodeRange fields() const; //! @copydoc Nest::NodeHandle::type() - DataType type() const { return DataType(DeclNode::type()); } + DataType type() const { return {DeclNode::type()}; } private: static void setContextForChildrenImpl(ThisNodeType node); @@ -489,7 +489,7 @@ struct VarDecl : DeclNode { NodeHandle typeNode() const; //! @copydoc Nest::NodeHandle::type() - TypeWithStorage type() const { return TypeWithStorage(DeclNode::type()); } + TypeWithStorage type() const { return {DeclNode::type()}; } private: static void setContextForChildrenImpl(ThisNodeType node); diff --git a/src/Feather/Utils/cppif/FeatherTypes.hpp b/src/Feather/Utils/cppif/FeatherTypes.hpp index 9b0d50b0..f5299743 100644 --- a/src/Feather/Utils/cppif/FeatherTypes.hpp +++ b/src/Feather/Utils/cppif/FeatherTypes.hpp @@ -54,7 +54,7 @@ struct DataType : TypeWithStorage { //! @copydoc Type::changeMode DataType changeMode(Nest::EvalMode mode, Nest::Location loc = Nest::Location{}) const { - return DataType(Type::changeMode(mode, loc)); + return {Type::changeMode(mode, loc)}; } }; @@ -82,14 +82,14 @@ struct ConstType : TypeWithStorage { static ConstType get(TypeWithStorage base, Nest::Location loc = {}); //! Returns the base type of this type - TypeWithStorage base() const { return TypeWithStorage(type_->subTypes[0]); } + TypeWithStorage base() const { return {type_->subTypes[0]}; } //! Transform this type into a corresponding DataType with the same number of references. DataType toRef() const; //! @copydoc Type::changeMode ConstType changeMode(Nest::EvalMode mode, Nest::Location loc = Nest::Location{}) const { - return ConstType(Type::changeMode(mode, loc)); + return {Type::changeMode(mode, loc)}; } }; @@ -117,14 +117,14 @@ struct MutableType : TypeWithStorage { static MutableType get(TypeWithStorage base, Nest::Location loc = {}); //! Returns the base type of this type - TypeWithStorage base() const { return TypeWithStorage(type_->subTypes[0]); } + TypeWithStorage base() const { return {type_->subTypes[0]}; } //! Transform this type into a corresponding DataType with the same number of references. DataType toRef() const; //! @copydoc Type::changeMode MutableType changeMode(Nest::EvalMode mode, Nest::Location loc = Nest::Location{}) const { - return MutableType(Type::changeMode(mode, loc)); + return {Type::changeMode(mode, loc)}; } }; @@ -152,14 +152,14 @@ struct TempType : TypeWithStorage { static TempType get(TypeWithStorage base, Nest::Location loc = {}); //! Returns the base type of this type - TypeWithStorage base() const { return TypeWithStorage(type_->subTypes[0]); } + TypeWithStorage base() const { return {type_->subTypes[0]}; } //! Transform this type into a corresponding DataType with the same number of references. DataType toRef() const; //! @copydoc Type::changeMode TempType changeMode(Nest::EvalMode mode, Nest::Location loc = Nest::Location{}) const { - return TempType(Type::changeMode(mode, loc)); + return {Type::changeMode(mode, loc)}; } }; @@ -185,13 +185,13 @@ struct ArrayType : TypeWithStorage { static ArrayType get(TypeWithStorage unitType, int count); //! Returns the unit type of this array type - TypeWithStorage unitType() const { return TypeWithStorage(type_->subTypes[0]); } + TypeWithStorage unitType() const { return {type_->subTypes[0]}; } //! Returns the number of elements in the array int count() const { return type_->flags; } //! @copydoc Type::changeMode ArrayType changeMode(Nest::EvalMode mode, Nest::Location loc = Nest::Location{}) const { - return ArrayType(Type::changeMode(mode, loc)); + return {Type::changeMode(mode, loc)}; } }; @@ -226,11 +226,11 @@ struct FunctionType : TypeWithStorage { //! Returns the number of parameters that we have int numParams() const { return type_->numSubtypes - 1; } //! Access operators for the parameters - TypeWithStorage operator[](int idx) const { return TypeWithStorage(type_->subTypes[idx + 1]); } + TypeWithStorage operator[](int idx) const { return {type_->subTypes[idx + 1]}; } //! @copydoc Type::changeMode FunctionType changeMode(Nest::EvalMode mode, Nest::Location loc = Nest::Location{}) const { - return FunctionType(Type::changeMode(mode, loc)); + return {Type::changeMode(mode, loc)}; } }; diff --git a/src/Feather/src/Utils/cppif/FeatherNodes.cpp b/src/Feather/src/Utils/cppif/FeatherNodes.cpp index 16e855f1..bb5594e1 100644 --- a/src/Feather/src/Utils/cppif/FeatherNodes.cpp +++ b/src/Feather/src/Utils/cppif/FeatherNodes.cpp @@ -596,9 +596,7 @@ CtValueExp CtValueExp::create(const Location& loc, TypeWithStorage type, StringR res.setProperty("valueData", data); return res; } -TypeWithStorage CtValueExp::valueType() const { - return TypeWithStorage(getCheckPropertyType("valueType")); -} +TypeWithStorage CtValueExp::valueType() const { return {getCheckPropertyType("valueType")}; } StringRef CtValueExp::valueData() const { return getCheckPropertyString("valueData"); } NodeHandle CtValueExp::semanticCheckImpl(CtValueExp node) { // Check the type @@ -701,7 +699,7 @@ VarRefExp VarRefExp::create(const Location& loc, VarDecl varDecl) { res.setReferredNodes(NodeRange{varDecl}); return res; } -VarDecl VarRefExp::varDecl() const { return VarDecl(referredNodes()[0]); } +VarDecl VarRefExp::varDecl() const { return {referredNodes()[0]}; } NodeHandle VarRefExp::semanticCheckImpl(VarRefExp node) { VarDecl var = node.varDecl(); ASSERT(var); @@ -737,7 +735,7 @@ FieldRefExp FieldRefExp::create(const Location& loc, NodeHandle obj, VarDecl fie return res; } NodeHandle FieldRefExp::object() const { return children()[0]; } -VarDecl FieldRefExp::fieldDecl() const { return VarDecl(referredNodes()[0]); } +VarDecl FieldRefExp::fieldDecl() const { return {referredNodes()[0]}; } NodeHandle FieldRefExp::semanticCheckImpl(FieldRefExp node) { NodeHandle obj = node.object(); VarDecl field = node.fieldDecl(); @@ -806,7 +804,7 @@ FunRefExp FunRefExp::create(const Location& loc, FunctionDecl funDecl, NodeHandl res.setReferredNodes(NodeRange{funDecl}); return res; } -FunctionDecl FunRefExp::funDecl() const { return FunctionDecl(referredNodes()[0]); } +FunctionDecl FunRefExp::funDecl() const { return {referredNodes()[0]}; } NodeHandle FunRefExp::resTypeNode() const { return children()[0]; } NodeHandle FunRefExp::semanticCheckImpl(FunRefExp node) { NodeHandle resType = node.resTypeNode(); @@ -833,7 +831,7 @@ FunCallExp FunCallExp::create(const Location& loc, FunctionDecl funDecl, NodeRan res.setReferredNodes(NodeRange{funDecl}); return res; } -FunctionDecl FunCallExp::funDecl() const { return FunctionDecl(referredNodes()[0]); } +FunctionDecl FunCallExp::funDecl() const { return {referredNodes()[0]}; } NodeRange FunCallExp::arguments() const { return children(); } NodeHandle FunCallExp::semanticCheckImpl(FunCallExp node) { FunctionDecl fun = node.funDecl(); diff --git a/src/Feather/src/Utils/cppif/FeatherTypes.cpp b/src/Feather/src/Utils/cppif/FeatherTypes.cpp index 3213ddcb..e1219586 100644 --- a/src/Feather/src/Utils/cppif/FeatherTypes.cpp +++ b/src/Feather/src/Utils/cppif/FeatherTypes.cpp @@ -25,7 +25,7 @@ DataType::DataType(Nest::TypeRef type) } DataType DataType::get(Nest::NodeHandle decl, int numReferences, Nest::EvalMode mode) { - return DataType(Feather_getDataType(decl, numReferences, mode)); + return {Feather_getDataType(decl, numReferences, mode)}; } ConstType::ConstType(Nest::TypeRef type) @@ -39,10 +39,10 @@ ConstType ConstType::get(TypeWithStorage base, Nest::Location loc) { REP_INTERNAL(loc, "Null type given as base to const type"); int baseKind = base.kind(); if (baseKind == typeKindConst) - return ConstType(base); + return {base}; else if (baseKind == typeKindMutable || baseKind == typeKindTemp) REP_ERROR(loc, "Cannot construct a const type based on %1%") % base; - return ConstType(Feather_getConstType(base)); + return {Feather_getConstType(base)}; } DataType ConstType::toRef() const { return DataType::get(referredNode(), numReferences(), mode()); } @@ -58,10 +58,10 @@ MutableType MutableType::get(TypeWithStorage base, Nest::Location loc) { REP_INTERNAL(loc, "Null type given as base to const type"); int baseKind = base.kind(); if (baseKind == typeKindMutable) - return MutableType(base); + return {base}; else if (baseKind == typeKindConst || baseKind == typeKindTemp) REP_ERROR(loc, "Cannot construct a mutable type based on %1%") % base; - return MutableType(Feather_getMutableType(base)); + return {Feather_getMutableType(base)}; } DataType MutableType::toRef() const { @@ -79,10 +79,10 @@ TempType TempType::get(TypeWithStorage base, Nest::Location loc) { REP_INTERNAL(loc, "Null type given as base to const type"); int baseKind = base.kind(); if (baseKind == typeKindTemp) - return TempType(base); + return {base}; else if (baseKind == typeKindConst || baseKind == typeKindMutable) REP_ERROR(loc, "Cannot construct a tmp type based on %1%") % base; - return TempType(Feather_getTempType(base)); + return {Feather_getTempType(base)}; } DataType TempType::toRef() const { return DataType::get(referredNode(), numReferences(), mode()); } @@ -94,7 +94,7 @@ ArrayType::ArrayType(Nest::TypeRef type) } ArrayType ArrayType::get(TypeWithStorage unitType, int count) { - return ArrayType(Feather_getArrayType(unitType, count)); + return {Feather_getArrayType(unitType, count)}; } FunctionType::FunctionType(Nest::TypeRef type) @@ -105,7 +105,7 @@ FunctionType::FunctionType(Nest::TypeRef type) FunctionType FunctionType::get( Nest::TypeRef* resultTypeAndParams, int numTypes, Nest::EvalMode mode) { - return FunctionType(Feather_getFunctionType(resultTypeAndParams, numTypes, mode)); + return {Feather_getFunctionType(resultTypeAndParams, numTypes, mode)}; } bool isDataLikeType(Type type) { diff --git a/src/Nest/Utils/cppif/NodeHandle.hpp b/src/Nest/Utils/cppif/NodeHandle.hpp index 16602c28..0cfcc6a4 100644 --- a/src/Nest/Utils/cppif/NodeHandle.hpp +++ b/src/Nest/Utils/cppif/NodeHandle.hpp @@ -20,9 +20,8 @@ struct NodeRangeM; */ struct NodeHandle { //! The actual handle to the node - Nest_Node* handle; - NodeHandle() - : handle(nullptr){}; + Nest_Node* handle{nullptr}; + NodeHandle(){}; //! Construct a node handle from an actual C-style Nest_Node pointer NodeHandle(Nest_Node* h) : handle(h) {} diff --git a/src/Nest/Utils/cppif/StringRef.hpp b/src/Nest/Utils/cppif/StringRef.hpp index fe9eb6f3..0c325837 100644 --- a/src/Nest/Utils/cppif/StringRef.hpp +++ b/src/Nest/Utils/cppif/StringRef.hpp @@ -45,12 +45,10 @@ struct StringRef : Nest_StringRef { //! The mutable version of StringRef -- we can modify its content struct StringRefM { - char* begin; ///< The beginning of the string - char* end; ///< One past the last character of the string + char* begin{nullptr}; ///< The beginning of the string + char* end{nullptr}; ///< One past the last character of the string - StringRefM() - : begin(nullptr) - , end(nullptr) {} + StringRefM() {} StringRefM(int size); operator StringRef() { return {begin, end}; } diff --git a/src/Nest/Utils/cppif/TypeWithStorage.hpp b/src/Nest/Utils/cppif/TypeWithStorage.hpp index 9fc303d2..7af5bd58 100644 --- a/src/Nest/Utils/cppif/TypeWithStorage.hpp +++ b/src/Nest/Utils/cppif/TypeWithStorage.hpp @@ -23,7 +23,7 @@ struct TypeWithStorage : Type { //! @copydoc Type::changeMode TypeWithStorage changeMode(Nest::EvalMode mode, Nest::Location loc = Nest::Location{}) const { - return TypeWithStorage(Type::changeMode(mode, loc)); + return {Type::changeMode(mode, loc)}; } //!@} diff --git a/src/SparrowCompiler/SparrowCompiler.cpp b/src/SparrowCompiler/SparrowCompiler.cpp index 91db4f5d..ea2f396e 100644 --- a/src/SparrowCompiler/SparrowCompiler.cpp +++ b/src/SparrowCompiler/SparrowCompiler.cpp @@ -196,6 +196,7 @@ vector gatherModules() { return res; } +// NOLINTNEXTLINE(bugprone-exception-escape) int main(int argc, char* argv[]) { CompilerStats& stats = CompilerStats::instance(); auto startTime = chrono::steady_clock::now(); diff --git a/src/SparrowFrontend/Grammar/Parser.cpp b/src/SparrowFrontend/Grammar/Parser.cpp index 6397d568..79e20a75 100644 --- a/src/SparrowFrontend/Grammar/Parser.cpp +++ b/src/SparrowFrontend/Grammar/Parser.cpp @@ -80,7 +80,8 @@ struct AstBuilder { //! Compiler implementation or error reporter struct CompilerErrorReporter : ErrorReporter { - CompilerErrorReporter() { + CompilerErrorReporter() + : ErrorReporter() { self = this; reportErrorFn = &CompilerErrorReporter::reportError; } @@ -92,7 +93,8 @@ struct CompilerErrorReporter : ErrorReporter { //! Compiler implementation or error reporter struct CompilerAstBuilder : AstBuilder { - CompilerAstBuilder() { + CompilerAstBuilder() + : AstBuilder() { self = this; addToNodeListFn = &CompilerAstBuilder::addToNodeList_Impl; diff --git a/src/SparrowFrontend/Helpers/DeclsHelpers.cpp b/src/SparrowFrontend/Helpers/DeclsHelpers.cpp index 8b6c8b8c..f47a9c13 100644 --- a/src/SparrowFrontend/Helpers/DeclsHelpers.cpp +++ b/src/SparrowFrontend/Helpers/DeclsHelpers.cpp @@ -148,6 +148,7 @@ Nest_NodeArray SprFrontend::expandDecls(Nest_NodeRange decls, Node* seenFrom) { } // Make sure we run again for the newly replaced decl + // NOLINTNEXTLINE goto run_loop_again; } } diff --git a/src/SparrowFrontend/Nodes/Decl.cpp b/src/SparrowFrontend/Nodes/Decl.cpp index 0f4a2390..90b2e0fd 100644 --- a/src/SparrowFrontend/Nodes/Decl.cpp +++ b/src/SparrowFrontend/Nodes/Decl.cpp @@ -1053,9 +1053,7 @@ ConceptDecl ConceptDecl::create(const Location& loc, StringRef name, StringRef p StringRef ConceptDecl::paramName() const { return getCheckPropertyString("spr.paramName"); } -InstantiationsSet ConceptDecl::instantiationsSet() const { - return InstantiationsSet(children()[2]); -}; +InstantiationsSet ConceptDecl::instantiationsSet() const { return {children()[2]}; }; void ConceptDecl::setContextForChildrenImpl(ConceptDecl node) { commonSetContextForChildren(node, ContextChangeType::withSymTab); diff --git a/src/SparrowFrontend/Nodes/Decl.hpp b/src/SparrowFrontend/Nodes/Decl.hpp index 3181738e..5fa160c1 100644 --- a/src/SparrowFrontend/Nodes/Decl.hpp +++ b/src/SparrowFrontend/Nodes/Decl.hpp @@ -141,7 +141,7 @@ struct PackageDecl : Feather::DeclNode { NodeHandle body() const { return children()[0]; }; //! Returns the node containing the parameters - NodeList parameters() const { return NodeList(children()[1]); }; + NodeList parameters() const { return {children()[1]}; }; //! Returns the if clause node NodeHandle ifClause() const { return children()[2]; }; @@ -205,9 +205,7 @@ struct VariableDecl : Feather::DeclNode { //! Returns the resulting Feather VarDecl object. //! A Sparrow variable will always be implemented in terms for a Feather VarDecl node - Feather::VarDecl resultingVar() const { - return Feather::VarDecl(getCheckPropertyNode("spr.resultingVar")); - } + Feather::VarDecl resultingVar() const { return {getCheckPropertyNode("spr.resultingVar")}; } private: static void setContextForChildrenImpl(VariableDecl node); @@ -251,10 +249,10 @@ struct DataTypeDecl : Feather::DeclNode { NodeHandle underlyingData, NodeHandle ifClause, NodeList body); //! Returns the body of the data type (fields + using decls) - NodeList body() const { return NodeList(children()[1]); }; + NodeList body() const { return {children()[1]}; }; //! Returns the parameters given to the data type declarations (for generic datatypes) - NodeList parameters() const { return NodeList(children()[0]); }; + NodeList parameters() const { return {children()[0]}; }; //! Returns the if clause for the data type declaration (for generic datatypes) NodeHandle ifClause() const { return children()[2]; }; @@ -336,7 +334,7 @@ struct SprFunctionDecl : Feather::DeclNode { NodeHandle returnType, NodeHandle body, NodeHandle ifClause = {}); //! Returns the parameters of the function - NodeList parameters() const { return NodeList(children()[0]); }; + NodeList parameters() const { return {children()[0]}; }; //! Returns the return type of the function (if any) NodeHandle returnType() const { return children()[1]; }; diff --git a/src/SparrowFrontend/Nodes/Exp.cpp b/src/SparrowFrontend/Nodes/Exp.cpp index e6ad0706..fc449ad7 100644 --- a/src/SparrowFrontend/Nodes/Exp.cpp +++ b/src/SparrowFrontend/Nodes/Exp.cpp @@ -497,6 +497,7 @@ SearchScopes buildSearchScopes(CompilationContext* nodeCtx, StringRef operation, // Step 1: Try to find an operator that match in the class of the base expression if (searchInside) { + ASSERT(base); mode = base.type().mode(); ctx = baseDecl.childrenContext(); ASSERT(ctx); diff --git a/src/SparrowFrontend/Nodes/Exp.hpp b/src/SparrowFrontend/Nodes/Exp.hpp index 422d4329..8a7895d7 100644 --- a/src/SparrowFrontend/Nodes/Exp.hpp +++ b/src/SparrowFrontend/Nodes/Exp.hpp @@ -168,7 +168,7 @@ struct FunApplication : NodeHandle { NodeHandle base() const { return children()[0]; }; //! Returns the node-list of arguments - NodeList arguments() const { return NodeList(children()[1]); }; + NodeList arguments() const { return {children()[1]}; }; private: static NodeHandle semanticCheckImpl(FunApplication node); @@ -320,7 +320,7 @@ struct LambdaExp : NodeHandle { NodeHandle body, NodeHandle bodyExp, NodeList closureParams); //! Returns the parameters - NodeList parameters() const { return NodeList(referredNodes()[0]); }; + NodeList parameters() const { return {referredNodes()[0]}; }; //! Returns the return type of the lambda NodeHandle returnType() const { return referredNodes()[1]; }; @@ -329,7 +329,7 @@ struct LambdaExp : NodeHandle { NodeHandle body() const { return referredNodes()[2]; }; //! Returns the closure params - NodeList closureParams() const { return NodeList(referredNodes()[3]); }; + NodeList closureParams() const { return {referredNodes()[3]}; }; private: static NodeHandle semanticCheckImpl(LambdaExp node); diff --git a/src/SparrowFrontend/Nodes/Generics.cpp b/src/SparrowFrontend/Nodes/Generics.cpp index ea5039e4..3d034fdb 100644 --- a/src/SparrowFrontend/Nodes/Generics.cpp +++ b/src/SparrowFrontend/Nodes/Generics.cpp @@ -39,7 +39,7 @@ GenericPackage GenericPackage::create( return res; } -InstantiationsSet GenericPackage::instSet() const { return InstantiationsSet(children()[0]); } +InstantiationsSet GenericPackage::instSet() const { return {children()[0]}; } NodeHandle GenericPackage::semanticCheckImpl(GenericPackage node) { return Feather::Nop::create(node.location()); @@ -71,7 +71,7 @@ GenericDatatype GenericDatatype::create( return res; } -InstantiationsSet GenericDatatype::instSet() const { return InstantiationsSet(children()[0]); } +InstantiationsSet GenericDatatype::instSet() const { return {children()[0]}; } NodeHandle GenericDatatype::semanticCheckImpl(GenericDatatype node) { return Feather::Nop::create(node.location()); @@ -94,7 +94,7 @@ GenericFunction GenericFunction::create( return res; } -InstantiationsSet GenericFunction::instSet() const { return InstantiationsSet(children()[0]); } +InstantiationsSet GenericFunction::instSet() const { return {children()[0]}; } NodeHandle GenericFunction::semanticCheckImpl(GenericFunction node) { return Feather::Nop::create(node.location()); diff --git a/src/SparrowFrontend/Nodes/Generics.hpp b/src/SparrowFrontend/Nodes/Generics.hpp index 70a44f55..04793906 100644 --- a/src/SparrowFrontend/Nodes/Generics.hpp +++ b/src/SparrowFrontend/Nodes/Generics.hpp @@ -35,7 +35,7 @@ struct GenericPackage : Feather::DeclNode { InstantiationsSet instSet() const; //! Returns the original package - PackageDecl original() const { return PackageDecl(referredNodes()[0]); } + PackageDecl original() const { return {referredNodes()[0]}; } private: static NodeHandle semanticCheckImpl(GenericPackage node); @@ -64,7 +64,7 @@ struct GenericDatatype : Feather::DeclNode { InstantiationsSet instSet() const; //! Returns the original datatype decl - DataTypeDecl original() const { return DataTypeDecl(referredNodes()[0]); } + DataTypeDecl original() const { return {referredNodes()[0]}; } private: static NodeHandle semanticCheckImpl(GenericDatatype node); @@ -95,7 +95,7 @@ struct GenericFunction : Feather::DeclNode { InstantiationsSet instSet() const; //! Returns the original function decl - SprFunctionDecl original() const { return SprFunctionDecl(referredNodes()[0]); } + SprFunctionDecl original() const { return {referredNodes()[0]}; } //! Returns the original params of the function NodeRangeT originalParams() const { @@ -137,7 +137,7 @@ struct Instantiation : NodeHandle { static Instantiation create(const Location& loc, NodeRange boundValues, NodeRange boundVars); //! Returns the node list containing all the bound variables - NodeList boundVarsNode() const { return NodeList(children()[0]); } + NodeList boundVarsNode() const { return {children()[0]}; } //! Returns the bound values (immutable access) NodeRange boundValues() const { return referredNodes(); } @@ -205,7 +205,7 @@ struct InstantiationsSet : NodeHandle { void addInstantiation(Instantiation inst); //! Returns the parent node - Feather::DeclNode parentNode() const { return Feather::DeclNode(referredNodes()[0]); } + Feather::DeclNode parentNode() const { return {referredNodes()[0]}; } //! Returns the range of parameters for this instantiation set NodeRangeT params() const { return NodeRangeT(referredNodes()[1].children()); diff --git a/src/SparrowFrontend/Nodes/Module.hpp b/src/SparrowFrontend/Nodes/Module.hpp index b20ac6cd..51037073 100644 --- a/src/SparrowFrontend/Nodes/Module.hpp +++ b/src/SparrowFrontend/Nodes/Module.hpp @@ -57,7 +57,7 @@ struct Module : Feather::DeclNode { NodeHandle moduleName() const { return children()[0]; }; //! Returns the node with the declarations of the module - NodeList decls() const { return NodeList(children()[1]); }; + NodeList decls() const { return {children()[1]}; }; private: static void setContextForChildrenImpl(Module node); @@ -113,7 +113,7 @@ struct ImportName : Feather::DeclNode { NodeHandle moduleName() const { return children()[0]; }; //! Returns the imported decls names - NodeList importedDeclNames() const { return NodeList(children()[1]); }; + NodeList importedDeclNames() const { return {children()[1]}; }; //! Returns the alias we set to the imported module StringRef name() const { return getPropertyStringDeref("name"); }; diff --git a/src/SparrowFrontend/Services/Callable/CallableHelpers.cpp b/src/SparrowFrontend/Services/Callable/CallableHelpers.cpp index 0ce91f9c..d947dcec 100644 --- a/src/SparrowFrontend/Services/Callable/CallableHelpers.cpp +++ b/src/SparrowFrontend/Services/Callable/CallableHelpers.cpp @@ -159,8 +159,8 @@ void getBoundValuesClassic(SmallVector& boundVals, NodeRange args) { boundVals.clear(); boundVals.reserve(args.size()); - for (int i = 0; i < args.size(); ++i) { - auto arg = args[i]; + for (auto i : args) { + auto arg = i; // Evaluate the node and add the resulting CtValue as a bound argument if (!arg.computeType()) { diff --git a/src/SparrowFrontend/Services/Convert/ConversionResult.cpp b/src/SparrowFrontend/Services/Convert/ConversionResult.cpp index 049b037a..e8824db7 100644 --- a/src/SparrowFrontend/Services/Convert/ConversionResult.cpp +++ b/src/SparrowFrontend/Services/Convert/ConversionResult.cpp @@ -41,7 +41,7 @@ ConversionType bestConv(ConversionType lhs, ConversionType rhs) { return (ConversionType)max(lhs, rhs); } -ConversionResult::ConversionResult() {} +ConversionResult::ConversionResult() = default; ConversionResult::ConversionResult(ConversionType convType) : convType_(convType) {} diff --git a/src/SparrowFrontend/SparrowFrontendTypes.cpp b/src/SparrowFrontend/SparrowFrontendTypes.cpp index 18f35e5a..60fb2335 100644 --- a/src/SparrowFrontend/SparrowFrontendTypes.cpp +++ b/src/SparrowFrontend/SparrowFrontendTypes.cpp @@ -67,7 +67,7 @@ ConceptType::ConceptType(Nest::TypeRef type) } ConceptType ConceptType::get(Nest::NodeHandle decl, int numReferences, Nest::EvalMode mode) { - return ConceptType(getConceptType(decl, numReferences, mode)); + return {getConceptType(decl, numReferences, mode)}; } Nest::NodeHandle ConceptType::decl() const { return referredNode(); } diff --git a/src/SparrowFrontend/SparrowFrontendTypes.hpp b/src/SparrowFrontend/SparrowFrontendTypes.hpp index 3646ebfe..18fd6ccd 100644 --- a/src/SparrowFrontend/SparrowFrontendTypes.hpp +++ b/src/SparrowFrontend/SparrowFrontendTypes.hpp @@ -44,7 +44,7 @@ struct ConceptType : TypeWithStorage { //! @copydoc Type::changeMode ConceptType changeMode(Nest::EvalMode mode, Nest::Location loc = Nest::Location{}) { - return ConceptType(Type::changeMode(mode, loc)); + return {Type::changeMode(mode, loc)}; } }; diff --git a/unittests/Common/BackendMock.cpp b/unittests/Common/BackendMock.cpp index 758c74e2..51c6f460 100644 --- a/unittests/Common/BackendMock.cpp +++ b/unittests/Common/BackendMock.cpp @@ -23,7 +23,7 @@ BackendMock::BackendMock() ctApiRegisterFun = &BackendMock::CtApiRegisterFun; } -BackendMock::~BackendMock() {} +BackendMock::~BackendMock() = default; void BackendMock::Init(Nest_Backend* /*backend*/, const char* /*mainFilename*/) { // Nothing to do diff --git a/unittests/Feather/TestFeatherNodes.cpp b/unittests/Feather/TestFeatherNodes.cpp index 80e5377e..6d111a80 100644 --- a/unittests/Feather/TestFeatherNodes.cpp +++ b/unittests/Feather/TestFeatherNodes.cpp @@ -24,13 +24,13 @@ struct FeatherNodesFixture : SparrowGeneralFixture { FeatherNodesFixture::FeatherNodesFixture() { using TypeFactory::g_dataTypeDecls; - g_dataTypeDecls.push_back(createNativeDatatypeNode(StringRef("i1"), globalContext_)); - g_dataTypeDecls.push_back(createNativeDatatypeNode(StringRef("i8"), globalContext_)); - g_dataTypeDecls.push_back(createNativeDatatypeNode(StringRef("i16"), globalContext_)); - g_dataTypeDecls.push_back(createNativeDatatypeNode(StringRef("i32"), globalContext_)); - g_dataTypeDecls.push_back(createDatatypeNode(StringRef("FooType"), globalContext_)); - g_dataTypeDecls.push_back(createDatatypeNode(StringRef("BarType"), globalContext_)); - g_dataTypeDecls.push_back(createDatatypeNode(StringRef("NullType"), globalContext_)); + g_dataTypeDecls.emplace_back(createNativeDatatypeNode(StringRef("i1"), globalContext_)); + g_dataTypeDecls.emplace_back(createNativeDatatypeNode(StringRef("i8"), globalContext_)); + g_dataTypeDecls.emplace_back(createNativeDatatypeNode(StringRef("i16"), globalContext_)); + g_dataTypeDecls.emplace_back(createNativeDatatypeNode(StringRef("i32"), globalContext_)); + g_dataTypeDecls.emplace_back(createDatatypeNode(StringRef("FooType"), globalContext_)); + g_dataTypeDecls.emplace_back(createDatatypeNode(StringRef("BarType"), globalContext_)); + g_dataTypeDecls.emplace_back(createDatatypeNode(StringRef("NullType"), globalContext_)); } FeatherNodesFixture::~FeatherNodesFixture() { FeatherNodeFactory::instance().reset(); diff --git a/unittests/Feather/TestTypes.cpp b/unittests/Feather/TestTypes.cpp index 80f9f57e..4705097a 100644 --- a/unittests/Feather/TestTypes.cpp +++ b/unittests/Feather/TestTypes.cpp @@ -19,14 +19,14 @@ struct FeatherTypesFixture : SparrowGeneralFixture { FeatherTypesFixture::FeatherTypesFixture() { using TypeFactory::g_dataTypeDecls; - g_dataTypeDecls.push_back(createNativeDatatypeNode(StringRef("i8"), globalContext_)); - g_dataTypeDecls.push_back(createNativeDatatypeNode(StringRef("i16"), globalContext_)); - g_dataTypeDecls.push_back(createNativeDatatypeNode(StringRef("i32"), globalContext_)); - g_dataTypeDecls.push_back(createDatatypeNode(StringRef("FooType"), globalContext_)); - g_dataTypeDecls.push_back(createDatatypeNode(StringRef("BarType"), globalContext_)); - g_dataTypeDecls.push_back(createDatatypeNode(StringRef("NullType"), globalContext_)); + g_dataTypeDecls.emplace_back(createNativeDatatypeNode(StringRef("i8"), globalContext_)); + g_dataTypeDecls.emplace_back(createNativeDatatypeNode(StringRef("i16"), globalContext_)); + g_dataTypeDecls.emplace_back(createNativeDatatypeNode(StringRef("i32"), globalContext_)); + g_dataTypeDecls.emplace_back(createDatatypeNode(StringRef("FooType"), globalContext_)); + g_dataTypeDecls.emplace_back(createDatatypeNode(StringRef("BarType"), globalContext_)); + g_dataTypeDecls.emplace_back(createDatatypeNode(StringRef("NullType"), globalContext_)); } -FeatherTypesFixture::~FeatherTypesFixture() {} +FeatherTypesFixture::~FeatherTypesFixture() = default; TEST_CASE_METHOD(FeatherTypesFixture, "User can create Feather types with given properties") { rc::prop("Can create VoidTypes for proper mode", [](EvalMode mode) { diff --git a/unittests/Nest/TestType.cpp b/unittests/Nest/TestType.cpp index e183aae9..58eb912b 100644 --- a/unittests/Nest/TestType.cpp +++ b/unittests/Nest/TestType.cpp @@ -12,8 +12,8 @@ struct TypesFixture : NestGeneralFixture { ~TypesFixture(); }; -TypesFixture::TypesFixture() {} -TypesFixture::~TypesFixture() {} +TypesFixture::TypesFixture() = default; +TypesFixture::~TypesFixture() = default; TEST_CASE_METHOD(TypesFixture, "User can register a new type") { SECTION("first time register") { diff --git a/unittests/SparrowFrontend/SprCommon/GenGenericParams.cpp b/unittests/SparrowFrontend/SprCommon/GenGenericParams.cpp index 1867012f..c05b3001 100644 --- a/unittests/SparrowFrontend/SprCommon/GenGenericParams.cpp +++ b/unittests/SparrowFrontend/SprCommon/GenGenericParams.cpp @@ -88,8 +88,8 @@ rc::Gen> arbBoundValues(const ParamsData& params, const Sampl // If this is a regular param (RT, non-concept), don't create a bound value for it if (t && t.kind() != typeKindConcept && t.mode() == modeRt) { - values.push_back(nullptr); - valTypes.push_back(nullptr); + values.emplace_back(nullptr); + valTypes.emplace_back(nullptr); continue; } @@ -105,6 +105,7 @@ rc::Gen> arbBoundValues(const ParamsData& params, const Sampl auto* t = Feather_getCtValueData(prevValAsCtValue); if (!t || !*t) REP_INTERNAL(prevValAsCtValue.location(), "No type was set for node"); + ASSERT(t); valueType = *t; } value = createTypeNode(nullptr, g_LocationGen(), valueType); diff --git a/unittests/SparrowFrontend/TestCallable.cpp b/unittests/SparrowFrontend/TestCallable.cpp index 73f89321..cfdb2e74 100644 --- a/unittests/SparrowFrontend/TestCallable.cpp +++ b/unittests/SparrowFrontend/TestCallable.cpp @@ -31,9 +31,6 @@ using namespace SprFrontend; using namespace rc; struct CallableFixture : SparrowGeneralFixture { - CallableFixture(); - ~CallableFixture(); - //! Ensures that the generated callable matches the original decl void checkCallable(Callable& c, NodeHandle decl, const ParamsData* paramsData = nullptr); @@ -61,9 +58,6 @@ struct CallableFixture : SparrowGeneralFixture { SampleTypes types_; }; -CallableFixture::CallableFixture() {} - -CallableFixture::~CallableFixture() {} void CallableFixture::checkCallable(Callable& c, NodeHandle decl, const ParamsData* paramsData) { RC_ASSERT(c.valid()); diff --git a/unittests/SparrowFrontend/TestConvert.cpp b/unittests/SparrowFrontend/TestConvert.cpp index e35267d1..b9eb890a 100644 --- a/unittests/SparrowFrontend/TestConvert.cpp +++ b/unittests/SparrowFrontend/TestConvert.cpp @@ -44,7 +44,7 @@ struct ConvertFixture : SparrowGeneralFixture { ConvertFixture::ConvertFixture() { types_.init(*this); } -ConvertFixture::~ConvertFixture() {} +ConvertFixture::~ConvertFixture() = default; TEST_CASE("User shall be able to combine two ConversionType values") { SECTION("combine function") { diff --git a/unittests/SparrowFrontend/TestGenerics.cpp b/unittests/SparrowFrontend/TestGenerics.cpp index 87706633..bc154614 100644 --- a/unittests/SparrowFrontend/TestGenerics.cpp +++ b/unittests/SparrowFrontend/TestGenerics.cpp @@ -21,9 +21,6 @@ using namespace SprFrontend; using namespace rc; struct GenericsFixture : SparrowGeneralFixture { - GenericsFixture(); - ~GenericsFixture(); - //! Checks if the created instantiation is OK, matching the parameters and given bound values static void checkInst(Instantiation inst, const ParamsData& paramsData, NodeRange values); @@ -31,9 +28,6 @@ struct GenericsFixture : SparrowGeneralFixture { SampleTypes types_; }; -GenericsFixture::GenericsFixture() {} - -GenericsFixture::~GenericsFixture() {} //! Checks if the created instantiation is OK, matching the parameters and given bound values void GenericsFixture::checkInst( diff --git a/unittests/SparrowFrontend/metatests/TestGenCallableDecl.cpp b/unittests/SparrowFrontend/metatests/TestGenCallableDecl.cpp index 66dbb9d9..2a16263f 100644 --- a/unittests/SparrowFrontend/metatests/TestGenCallableDecl.cpp +++ b/unittests/SparrowFrontend/metatests/TestGenCallableDecl.cpp @@ -13,19 +13,12 @@ using namespace SprFrontend; using namespace rc; struct GenCallableDeclFixture : SparrowGeneralFixture { - GenCallableDeclFixture(); - ~GenCallableDeclFixture(); - void checkSemanticallyOk(NodeHandle decl); //! The types that we are using while performing our tests SampleTypes types_; }; -GenCallableDeclFixture::GenCallableDeclFixture() {} - -GenCallableDeclFixture::~GenCallableDeclFixture() {} - void GenCallableDeclFixture::checkSemanticallyOk(NodeHandle decl) { if (!decl) return; diff --git a/unittests/SparrowFrontend/metatests/TestGenGenericParams.cpp b/unittests/SparrowFrontend/metatests/TestGenGenericParams.cpp index f619a6d1..ca715f94 100644 --- a/unittests/SparrowFrontend/metatests/TestGenGenericParams.cpp +++ b/unittests/SparrowFrontend/metatests/TestGenGenericParams.cpp @@ -15,16 +15,10 @@ using namespace SprFrontend; using namespace rc; struct GenGenericParamsFixture : SparrowGeneralFixture { - GenGenericParamsFixture(); - ~GenGenericParamsFixture(); - //! The types that we are using while performing our tests SampleTypes types_; }; -GenGenericParamsFixture::GenGenericParamsFixture() {} - -GenGenericParamsFixture::~GenGenericParamsFixture() {} TEST_CASE_METHOD(GenGenericParamsFixture, "Test GenGenericParams.genParams") { types_.init(*this); diff --git a/unittests/SparrowFrontend/metatests/TestGenValueForType.cpp b/unittests/SparrowFrontend/metatests/TestGenValueForType.cpp index 1634b8c5..731c5d85 100644 --- a/unittests/SparrowFrontend/metatests/TestGenValueForType.cpp +++ b/unittests/SparrowFrontend/metatests/TestGenValueForType.cpp @@ -15,9 +15,6 @@ using namespace SprFrontend; using namespace rc; struct GenValueForTypeFixture : SparrowGeneralFixture { - GenValueForTypeFixture(); - ~GenValueForTypeFixture(); - void computeType(Nest::NodeHandle node) { RC_ASSERT(node); node.setContext(globalContext_); @@ -29,9 +26,6 @@ struct GenValueForTypeFixture : SparrowGeneralFixture { SampleTypes types_; }; -GenValueForTypeFixture::GenValueForTypeFixture() {} - -GenValueForTypeFixture::~GenValueForTypeFixture() {} TEST_CASE_METHOD(GenValueForTypeFixture, "genValueForType functions generate expected results") { types_.init(*this);