Skip to content

Commit

Permalink
Enhance integer handling in solver by casting to appropriate types an…
Browse files Browse the repository at this point in the history
…d improve compiler warnings for MSVC and GCC
  • Loading branch information
riccardodebenedictis committed Dec 31, 2024
1 parent fa3a6bc commit 9defb48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ if(BUILD_TESTING)
add_subdirectory(tests)
endif()

if(MSVC)
target_compile_options(utils PRIVATE /W4)
else()
target_compile_options(utils PRIVATE -Wall -Wextra -Wpedantic)
if (ENABLE_COVERAGE)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(utils PRIVATE --coverage)
target_link_libraries(utils PUBLIC gcov)
endif()
endif()
endif()

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
8 changes: 4 additions & 4 deletions src/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace ratio
}

riddle::arith_expr solver::new_int() { return std::make_shared<arith_item>(static_cast<riddle::int_type &>(get_type(riddle::int_kw)), ctx.int_const(("i" + std::to_string(int_count++)).c_str())); }
riddle::arith_expr solver::new_int(const INT_TYPE value) { return std::make_shared<arith_item>(static_cast<riddle::int_type &>(get_type(riddle::int_kw)), ctx.int_val(value)); }
riddle::arith_expr solver::new_int(const INT_TYPE value) { return std::make_shared<arith_item>(static_cast<riddle::int_type &>(get_type(riddle::int_kw)), ctx.int_val(static_cast<int64_t>(value))); }
riddle::arith_expr solver::new_int(const INT_TYPE lb, const INT_TYPE ub)
{
auto xpr = ctx.int_const(("i" + std::to_string(int_count++)).c_str());
slv.add(xpr >= ctx.int_val(lb));
slv.add(xpr <= ctx.int_val(ub));
slv.add(xpr >= ctx.int_val(static_cast<int64_t>(lb)));
slv.add(xpr <= ctx.int_val(static_cast<int64_t>(ub)));
return std::make_shared<arith_item>(static_cast<riddle::int_type &>(get_type(riddle::int_kw)), std::move(xpr));
}
riddle::arith_expr solver::new_uncertain_int(const INT_TYPE lb, const INT_TYPE ub) { return std::make_shared<arith_item>(static_cast<riddle::int_type &>(get_type(riddle::int_kw)), ctx.int_const(("i" + std::to_string(int_count++)).c_str())); }
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace ratio
{
auto xpr = ctx.int_const(("e" + std::to_string(enum_count++)).c_str());
slv.add(xpr >= ctx.int_val(0));
slv.add(xpr < ctx.int_val(values.size()));
slv.add(xpr < ctx.int_val(static_cast<uint64_t>(values.size())));
return std::make_shared<enum_item>(static_cast<riddle::enum_type &>(tp), std::move(xpr), std::move(values));
}

Expand Down

0 comments on commit 9defb48

Please sign in to comment.