Skip to content

Commit

Permalink
Added clang-tidy support and fixed all the warnings (except bison and…
Browse files Browse the repository at this point in the history
… libxml2)
  • Loading branch information
mikucionisaau committed Sep 22, 2023
1 parent b1fcb2e commit ded3ad2
Show file tree
Hide file tree
Showing 33 changed files with 788 additions and 746 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ option(FIND_FATAL "Stop upon find_package errors" OFF)
cmake_policy(SET CMP0048 NEW) # project() command manages VERSION variables
include(cmake/stdcpp.cmake)
include(cmake/sanitizers.cmake)
include(cmake/clang-tidy.cmake)

set(UTAP_PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(UTAP_VERSION "${PACKAGE_VERSION}")
Expand All @@ -37,6 +38,11 @@ find_package(FLEX 2.6.4 REQUIRED)
find_package(BISON 3.6.0 REQUIRED)
include(cmake/libxml2.cmake)

if (UTAP_WITH_TESTS)
include(cmake/doctest.cmake)
enable_testing()
endif(UTAP_WITH_TESTS)

if(UTAP_STATIC)
#set(CMAKE_CXX_STANDARD_LIBRARIES "-static -static-libgcc -static-libstdc++ ${CMAKE_CXX_STANDARD_LIBRARIES}")
set(CMAKE_EXE_LINKER_FLAGS -static)
Expand All @@ -50,10 +56,8 @@ endif()
add_subdirectory(src)

if (UTAP_WITH_TESTS)
include(cmake/doctest.cmake)
enable_testing()
endif(UTAP_WITH_TESTS)
add_subdirectory(test)
add_subdirectory(test)
endif (UTAP_WITH_TESTS)

target_include_directories(UTAP
PRIVATE
Expand Down
20 changes: 20 additions & 0 deletions cmake/clang-tidy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
find_program(CLANG_TIDY_PROGRAM clang-tidy-14 clang-tidy)
if(CLANG_TIDY_PROGRAM)
execute_process(COMMAND ${CLANG_TIDY_PROGRAM} --version OUTPUT_VARIABLE CLANG_TIDY_VERSION_STRING)
string(REGEX MATCH "LLVM version ([0-9A-Za-z]+)\\.([0-9A-Za-z\\.]+)" TIDY_VERSION "${CLANG_TIDY_VERSION_STRING}")
set(TIDY_MAJOR_VERSION "${CMAKE_MATCH_1}")
set(TIDY_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}")

# We use NOLINTBEGIN and NOLINTEND to preserve some macros
# This was only introduced in version 14
if (TIDY_MAJOR_VERSION GREATER_EQUAL 14)
# Add good checks which produce a minimal amount of false positives
# One or two false positives can be dealt with using // NOLINT
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_PROGRAM} -checks=-*,cppcoreguidelines-macro-usage,hicpp-deprecated-headers,modernize-deprecated-headers,hicpp-use-override,hicpp-use-emplace,modernize-use-emplace,hicpp-use-auto,readability-container-size-empty,readability-implicit-bool-conversion,readability-redundant-smartptr-get,readability-qualified-auto,performance-unnecessary-value-param,modernize-make-unique,modernize-make-shared,misc-unused-using-decls,performance-move-const-arg,modernize-use-using,modernize-use-nullptr,modernize-deprecated-headers,modernize-loop-convert,misc-unused-using-decls,misc-static-assert,misc-redundant-expression,modernize-use-bool-literals,readability-delete-null-pointer,readability-redundant-member-init --warnings-as-errors=-*)
message(STATUS "Enabled clang-tidy ${TIDY_VERSION}: ${CLANG_TIDY_PROGRAM}")
else()
message(WARNING "Found clang-tidy ${TIDY_VERSION}, but >=14 is required, thus disabled.")
endif()
else(CLANG_TIDY_PROGRAM)
message(WARNING "No clang-tidy found. Some checks are not enabled")
endif(CLANG_TIDY_PROGRAM)
9 changes: 8 additions & 1 deletion cmake/sanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
option(SSP "Stack Smashing Protector" OFF) # Available on Windows too
option(UBSAN "Undefined Behavior Sanitizer" OFF)
option(ASAN "Address Sanitizer" OFF)
option(LSAN "Leak Sanitizer" OFF)
option(TSAN "Thread Sanitizer" OFF)

if (SSP)
Expand All @@ -12,7 +13,7 @@ if (SSP)
message(STATUS "Enable Stack Smashing Protector")
endif(SSP)

if (ASAN OR UBSAN OR TSAN)
if (ASAN OR UBSAN OR LSAN OR TSAN)
add_compile_options(-fno-omit-frame-pointer)
add_link_options(-fno-omit-frame-pointer)
endif()
Expand All @@ -29,6 +30,12 @@ if (ASAN)
message(STATUS "Enabled Address Sanitizer")
endif(ASAN)

if (LSAN)
add_compile_options(-fsanitize=leak)
add_link_options(-fsanitize=leak)
message(STATUS "Enabled Leak Sanitizer")
endif(LSAN)

if (TSAN)
add_compile_options(-fsanitize=thread)
add_link_options(-fsanitize=thread)
Expand Down
4 changes: 2 additions & 2 deletions include/utap/ExpressionBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ class ExpressionBuilder : public AbstractBuilder
void expr_sum_dynamic_end(const char* name) override;
void expr_foreach_dynamic_begin(const char*, const char*) override;
void expr_foreach_dynamic_end(const char* name) override;
void push_dynamic_frame_of(template_t* t, std::string name); // no override
void pop_dynamic_frame_of(std::string name);
void push_dynamic_frame_of(template_t* t, const std::string& name); // no override
void pop_dynamic_frame_of(const std::string& name);
};
} // namespace UTAP

Expand Down
4 changes: 2 additions & 2 deletions include/utap/StatementBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class StatementBuilder : public ExpressionBuilder
virtual variable_t* addVariable(type_t type, const std::string& name, expression_t init, position_t pos) = 0;
virtual bool addFunction(type_t type, const std::string& name, position_t pos) = 0;

static void collectDependencies(std::set<symbol_t>&, expression_t);
static void collectDependencies(std::set<symbol_t>&, type_t);
static void collectDependencies(std::set<symbol_t>&, const expression_t&);
static void collectDependencies(std::set<symbol_t>&, const type_t&);

public:
explicit StatementBuilder(Document&, std::vector<std::filesystem::path> libpaths = {});
Expand Down
2 changes: 1 addition & 1 deletion include/utap/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ int32_t parse_XTA(const char*, UTAP::ParserBuilder*, bool newxta);
* is used; otherwise the 3.x syntax is used. On success, this
* function returns with a positive value.
*/
int32_t parse_XTA(const char*, UTAP::ParserBuilder*, bool newxta, UTAP::xta_part_t part, std::string xpath);
int32_t parse_XTA(const char*, UTAP::ParserBuilder*, bool newxta, UTAP::xta_part_t part, const std::string& xpath);

/**
* Parse a buffer in the XML format, reporting the document to the given
Expand Down
18 changes: 9 additions & 9 deletions include/utap/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ struct declarations_t : stringify_t<declarations_t>
std::list<gantt_t> ganttChart;

/** Add function declaration. */
bool add_function(type_t type, std::string name, position_t, function_t*&);
bool add_function(type_t type, const std::string& name, position_t, function_t*&);
/** The following methods are used to write the declarations in an XML file */
std::string str(bool global) const;
std::ostream& print(std::ostream&, bool global = false) const;
Expand Down Expand Up @@ -535,14 +535,14 @@ class Document
variable_t* add_variable(declarations_t*, type_t type, const std::string&, expression_t initial, position_t);
void add_progress_measure(declarations_t*, expression_t guard, expression_t measure);

template_t& add_template(const std::string& name, frame_t params, position_t, bool isTA = true,
template_t& add_template(const std::string& name, const frame_t& params, position_t, bool isTA = true,
const std::string& type = "", const std::string& mode = "");
template_t& add_dynamic_template(const std::string& name, frame_t params, position_t pos);
template_t& add_dynamic_template(const std::string& name, const frame_t& params, position_t pos);

instance_t& add_instance(const std::string& name, instance_t& instance, frame_t params,
instance_t& add_instance(const std::string& name, instance_t& instance, const frame_t& params,
const std::vector<expression_t>& arguments, position_t);

instance_t& add_LSC_instance(const std::string& name, instance_t& instance, frame_t params,
instance_t& add_LSC_instance(const std::string& name, instance_t& instance, const frame_t& params,
const std::vector<expression_t>& arguments, position_t);
void remove_process(instance_t& instance); // LSC

Expand All @@ -555,10 +555,10 @@ class Document
void add_gantt(declarations_t*, gantt_t); // copies gantt_t and moves it
void accept(DocumentVisitor&);

void set_before_update(expression_t);
expression_t get_before_update();
void set_after_update(expression_t);
expression_t get_after_update();
void set_before_update(expression_t e) { before_update = std::move(e); }
expression_t& get_before_update() { return before_update; }
void set_after_update(expression_t e) { after_update = std::move(e); }
expression_t& get_after_update() { return after_update; }

void add_query(query_t query); // creates a copy and moves it
bool queries_empty() const;
Expand Down
16 changes: 8 additions & 8 deletions include/utap/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ class expression_t

/** Makes a deep clone of the expression and replaces the symbol
* "from" with the symbol "to". */
expression_t clone_deeper(symbol_t from, symbol_t to) const;
expression_t clone_deeper(const symbol_t& from, const symbol_t& to) const;

/** Makes a deep clone of the expression and replaces each symbol
* with a symbol from the given frame(s), with the same name */
expression_t clone_deeper(frame_t frame, frame_t select = {}) const;
expression_t clone_deeper(const frame_t& frame, const frame_t& select = {}) const;

/** Returns the kind of the expression. */
Constants::kind_t get_kind() const;
Expand Down Expand Up @@ -206,13 +206,13 @@ class expression_t

/** Less-than operator. Makes it possible to put expression_t
objects into an STL set. */
bool operator<(const expression_t) const;
bool operator<(const expression_t&) const;

/** Equality operator. Returns true if the two references point
to the same expression object. */
bool operator==(const expression_t) const;
bool operator==(const expression_t&) const;

expression_t subst(symbol_t, expression_t) const;
expression_t subst(const symbol_t&, expression_t) const;

/**
* Precedence of expression type, higher precedence goes before low precedence
Expand All @@ -228,7 +228,7 @@ class expression_t
static expression_t create_string(StringIndex, position_t = {});

/** Create an IDENTIFIER expression */
static expression_t create_identifier(symbol_t, position_t = {});
static expression_t create_identifier(const symbol_t&, position_t = {});

/** Create a unary expression */
static expression_t create_unary(Constants::kind_t, expression_t, position_t = {}, type_t = {});
Expand Down Expand Up @@ -257,10 +257,10 @@ class expression_t
// true if empty or equal to 1.
bool is_true() const;
int get_precedence() const;
friend std::ostream& operator<<(std::ostream& o, const UTAP::expression_t& e) { return o << e.str(); }
friend std::ostream& operator<<(std::ostream& o, const UTAP::expression_t& e) { return e.print(o); }

private:
std::ostream& print_bound_type(std::ostream& os, expression_t e) const;
std::ostream& print_bound_type(std::ostream& os, const expression_t& e) const;
};

} // namespace UTAP
Expand Down
2 changes: 1 addition & 1 deletion include/utap/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class PropertyBuilder : public std::enable_shared_from_this<PropertyBuilder>, pu
UTAP::position_t pos) override;
bool addFunction(UTAP::type_t type, const std::string& name, UTAP::position_t pos) override;

void typeCheck(UTAP::expression_t expr);
void typeCheck(UTAP::expression_t& expr);
bool allowProcessReferences() override;

virtual void typeProperty(UTAP::expression_t);
Expand Down
4 changes: 2 additions & 2 deletions include/utap/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ class frame_t
void add(symbol_t);

/** Add all symbols from the given frame */
void add(frame_t);
void add(const frame_t&);

/** Move all symbols from this to a given one (leaving this empty). */
void move_to(frame_t);

/** removes the given symbol*/
void remove(symbol_t s);
void remove(const symbol_t& s);

/** Resolves a name in this frame or a parent frame. */
bool resolve(const std::string& name, symbol_t& symbol) const;
Expand Down
6 changes: 3 additions & 3 deletions include/utap/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class type_t
* the type (expressions that occur as ranges either on
* array sizes, scalars or integers) with \a expr.
*/
type_t subst(symbol_t symbol, expression_t expr) const;
type_t subst(const symbol_t& symbol, const expression_t& expr) const;
/**
* Creates a new type by adding a prefix to it. The prefix
* could be anything and it is the responsibility of the
Expand All @@ -358,7 +358,7 @@ class type_t

/**
*/
static type_t create_range(type_t, expression_t, expression_t, position_t = position_t());
static type_t create_range(type_t, const expression_t&, const expression_t&, position_t = position_t());

/** Create a primitive type. */
static type_t create_primitive(Constants::kind_t, position_t = position_t());
Expand All @@ -373,7 +373,7 @@ class type_t
static type_t create_process(frame_t, position_t = position_t());

/** Creates a new processset type. */
static type_t create_process_set(type_t instance, position_t = position_t());
static type_t create_process_set(const type_t& instance, position_t = position_t());

/** Creates a new record type */
static type_t create_record(const std::vector<type_t>&, const std::vector<std::string>&, position_t = position_t());
Expand Down
68 changes: 34 additions & 34 deletions include/utap/typechecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CompileTimeComputableValues : public DocumentVisitor
void visitVariable(variable_t&) override;
void visitInstance(instance_t&) override;
void add_symbol(symbol_t);
bool contains(symbol_t) const;
bool contains(const symbol_t&) const;
};

/**
Expand All @@ -58,35 +58,35 @@ class TypeChecker : public DocumentVisitor, public AbstractStatementVisitor
{
private:
Document& document;
CompileTimeComputableValues compileTimeComputableValues;
mutable CompileTimeComputableValues compileTimeComputableValues;
function_t* function; /**< Current function being type checked. */
bool refinementWarnings;

template <class T>
void handleError(T, const std::string&);
void handleError(T, const std::string&) const;
template <class T>
void handleWarning(T, const std::string&);
void handleWarning(T, const std::string&) const;

expression_t checkInitialiser(type_t type, expression_t init);
bool areAssignmentCompatible(type_t lvalue, type_t rvalue, bool init = false) const;
bool areInlineIfCompatible(type_t result_type, type_t thenArg, type_t elseArg) const;
expression_t checkInitialiser(const type_t& type, const expression_t& init);
bool areAssignmentCompatible(const type_t& lvalue, const type_t& rvalue, bool init = false) const;
bool areInlineIfCompatible(const type_t& result_type, const type_t& thenArg, const type_t& elseArg) const;
type_t getInlineIfCommonType(type_t t1, type_t t2) const;
bool areEqCompatible(type_t t1, type_t t2) const;
bool isLValue(expression_t) const;
bool isModifiableLValue(expression_t) const;
bool isUniqueReference(expression_t expr) const;
bool isParameterCompatible(type_t param, expression_t arg);
bool checkParameterCompatible(type_t param, expression_t arg);
void checkIgnoredValue(expression_t expr);
bool checkAssignmentExpression(expression_t);
bool checkConditionalExpressionInFunction(expression_t);
void checkObservationConstraints(expression_t);

bool isCompileTimeComputable(expression_t expr) const;
void checkType(type_t, bool initialisable = false, bool inStruct = false);
bool areEqCompatible(const type_t& t1, const type_t& t2) const;
bool isLValue(const expression_t&) const;
bool isModifiableLValue(const expression_t&) const;
bool isUniqueReference(const expression_t& expr) const;
bool isParameterCompatible(const type_t& param, const expression_t& arg) const;
bool checkParameterCompatible(const type_t& param, const expression_t& arg) const;
void checkIgnoredValue(const expression_t& expr) const;
bool checkAssignmentExpression(expression_t&);
bool checkConditionalExpressionInFunction(const expression_t&);
void checkObservationConstraints(const expression_t&);

bool isCompileTimeComputable(const expression_t& expr) const;
void checkType(const type_t&, bool initialisable = false, bool inStruct = false) const;

public:
static bool areEquivalent(type_t, type_t);
static bool areEquivalent(const type_t&, const type_t&);
explicit TypeChecker(Document& doc, bool refinement = false);
void visitTemplateAfter(template_t&) override;
bool visitTemplateBefore(template_t&) override;
Expand All @@ -95,10 +95,10 @@ class TypeChecker : public DocumentVisitor, public AbstractStatementVisitor
void visitLocation(location_t&) override;
void visitEdge(edge_t&) override;
void visitInstance(instance_t&) override;
virtual void visitProperty(expression_t); // FIXME: does not override?!
virtual void visitProperty(expression_t&); // FIXME: does not override?!
void visitFunction(function_t&) override;
void visitProgressMeasure(progress_t&) override;
virtual void visitHybridClock(expression_t); // FIXME: does not override?!
virtual void visitHybridClock(expression_t&); // FIXME: does not override?!
void visitIODecl(iodecl_t&) override;
void visitGanttChart(gantt_t&) override;
void visitProcess(instance_t&) override;
Expand All @@ -119,8 +119,8 @@ class TypeChecker : public DocumentVisitor, public AbstractStatementVisitor

bool checkDynamicExpressions(Statement* stat);
/** Type check an expression */
bool checkExpression(expression_t);
bool checkSpawnParameterCompatible(type_t param, expression_t arg);
bool checkExpression(expression_t&) const;
bool checkSpawnParameterCompatible(const type_t& param, const expression_t& arg) const;

private:
int syncUsed; // Keep track of sync declarations, 0->nothing, 1->IO, 2->CSP, -1->error.
Expand All @@ -130,15 +130,15 @@ class TypeChecker : public DocumentVisitor, public AbstractStatementVisitor
1) consistent semantic checks by code reuse,
2) meaningful names to the otherwise anonymous expressions.
*/
bool checkNrOfRuns(const expression_t& expr);
bool checkBoundTypeOrBoundedExpr(const expression_t& expr);
bool checkBound(const expression_t& expr);
bool checkPredicate(const expression_t& expr);
bool checkProbBound(const expression_t& expr);
bool checkUntilCond(Constants::kind_t kind, const expression_t& expr);
bool checkMonitoredExpr(const expression_t& expr);
bool checkPathQuant(const expression_t& expr);
bool checkAggregationOp(const expression_t& expr);
bool checkNrOfRuns(const expression_t& expr) const;
bool checkBoundTypeOrBoundedExpr(const expression_t& expr) const;
bool checkBound(const expression_t& expr) const;
bool checkPredicate(const expression_t& expr) const;
bool checkProbBound(const expression_t& expr) const;
bool checkUntilCond(Constants::kind_t kind, const expression_t& expr) const;
bool checkMonitoredExpr(const expression_t& expr) const;
bool checkPathQuant(const expression_t& expr) const;
bool checkAggregationOp(const expression_t& expr) const;
};
} // namespace UTAP

Expand Down
Loading

0 comments on commit ded3ad2

Please sign in to comment.