Skip to content

Commit

Permalink
Added more strict testing to make sure that the found symbol is eithe…
Browse files Browse the repository at this point in the history
…r function or procedure and related test
  • Loading branch information
iomaganaris committed Jan 11, 2024
1 parent fb609b8 commit af2a387
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/visitors/semantic_analysis_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
namespace nmodl {
namespace visitor {

using symtab::syminfo::NmodlType;

bool SemanticAnalysisVisitor::check(const ast::Program& node) {
check_fail = false;

Expand Down Expand Up @@ -93,8 +95,10 @@ void SemanticAnalysisVisitor::visit_function_call(const ast::FunctionCall& node)
return;
}
auto func_symbol = psymtab->lookup(func_name);
// If symbol is not found or there are no AST nodes for it return
if (!func_symbol || func_symbol->get_nodes().empty()) {
// If symbol is not found or there are no AST nodes for it or it's not a function or procedure
// return
if (!func_symbol || func_symbol->get_nodes().empty() ||
!func_symbol->has_any_property(NmodlType::function_block | NmodlType::procedure_block)) {
return;

Check warning on line 102 in src/visitors/semantic_analysis_visitor.cpp

View check run for this annotation

Codecov / codecov/patch

src/visitors/semantic_analysis_visitor.cpp#L102

Added line #L102 was not covered by tests
}
const auto func_block = func_symbol->get_nodes()[0];
Expand Down
4 changes: 3 additions & 1 deletion test/unit/visitor/semantic_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,11 @@ SCENARIO("Recursive function calls", "[visitor][semantic_analysis]") {
std::string nmodl_text = R"(
FUNCTION a() {
b()
a = 42
}
PROCEDURE b() {
a()
LOCAL x
x = a()
}
)";
THEN("Semantic analysis should fail") {
Expand Down

0 comments on commit af2a387

Please sign in to comment.