Skip to content

Commit

Permalink
Removed "has no effect" warnings on external functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mikucionisaau committed Apr 11, 2024
1 parent 29fc3ad commit 0534605
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/dynlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ void* library_t::get_symbol(const char* name)

#elif defined(_WIN32) || defined(__MINGW32__)

static std::string get_error_message(const char* msg, DWORD err)
static std::string get_error_message(const std::string& msg, DWORD err)
{
auto ss = std::ostringstream{};
ss << msg << " 0x" << std::hex << err;
ss << msg << ": error " << err;
LPTSTR lpMessage = nullptr;
DWORD sz =
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
Expand All @@ -95,12 +95,13 @@ inline library_t::state_t::state_t(const char* name): handle{LoadLibrary(TEXT(na
auto err = GetLastError();
auto path = std::filesystem::path{name};
if (path.extension().string() == dll_extension)
throw std::runtime_error(get_error_message("Failed to open dynamic library", err));
throw std::runtime_error(get_error_message("Failed to open dynamic library " + path.string(), err));
else {
path = name + dll_extension;
handle = LoadLibrary(TEXT(path.string().c_str()));
if (handle == nullptr)
throw std::runtime_error(get_error_message("Failed to open dynamic library", GetLastError()));
throw std::runtime_error(
get_error_message("Failed to open dynamic library " + path.string(), GetLastError()));
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/typechecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,11 @@ void TypeChecker::handleError(T expr, const std::string& msg)
*/
void TypeChecker::checkIgnoredValue(expression_t expr)
{
if (!expr.changes_any_variable()) {
handleWarning(expr, "$Expression_does_not_have_any_effect");
} else if (expr.get_kind() == COMMA && !expr[1].changes_any_variable()) {
handleWarning(expr[1], "$Expression_does_not_have_any_effect");
static const auto message = "$Expression_does_not_have_any_effect";
if (!expr.changes_any_variable() && expr.get_kind() != FUN_CALL_EXT) {
handleWarning(expr, message);
} else if (expr.get_kind() == COMMA && !expr[1].changes_any_variable() && expr[1].get_kind() != FUN_CALL_EXT) {
handleWarning(expr[1], message);
}
}

Expand Down Expand Up @@ -1110,7 +1111,7 @@ bool TypeChecker::checkAssignmentExpression(expression_t expr)
return false;
}

if (expr.get_kind() != CONSTANT || expr.get_value() != 1) {
if (expr.get_kind() != FUN_CALL_EXT && (expr.get_kind() != CONSTANT || expr.get_value() != 1)) {
checkIgnoredValue(expr);
}

Expand Down Expand Up @@ -2624,14 +2625,13 @@ int32_t parse_XML_buffer(const char* buffer, Document* doc, bool newxta,
auto builder = DocumentBuilder{*doc, paths};
int err = parse_XML_buffer(buffer, &builder, newxta);

if (err) {
if (err)
return err;
}

if (!doc->has_errors()) {
TypeChecker checker(*doc);
auto checker = TypeChecker{*doc};
doc->accept(checker);
FeatureChecker fchecker(*doc);
auto fchecker = FeatureChecker{*doc};
doc->set_supported_methods(fchecker.get_supported_methods());
}

Expand Down
3 changes: 2 additions & 1 deletion test/models/external_fn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ int number = get_number();
<transition id="id2">
<source ref="id1"/>
<target ref="id0"/>
<label kind="assignment" x="18" y="0">fast_double(dd, 3),
<label kind="assignment" x="18" y="0">set_number(14),
fast_double(dd, 3),
set_number(17)</label>
</transition>
</template>
Expand Down

0 comments on commit 0534605

Please sign in to comment.