Skip to content

Commit

Permalink
Add semantic check for empty unit name
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu authored and Nicolas Cornu committed Jun 15, 2022
1 parent 4fba782 commit 3a52160
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/parser/nmodl.yy
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ units : {

unit : "(" { scanner.scan_unit(); } ")"
{
// @todo Empty units should be handled in semantic analysis
auto unit = scanner.get_unit();
auto text = unit->eval();
$$ = new ast::Unit(unit);
Expand Down
11 changes: 11 additions & 0 deletions src/visitors/semantic_analysis_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#include "ast/function_block.hpp"
#include "ast/procedure_block.hpp"
#include "ast/program.hpp"
#include "ast/string.hpp"
#include "ast/suffix.hpp"
#include "ast/table_statement.hpp"
#include "ast/unit.hpp"
#include "utils/logger.hpp"
#include "visitors/visitor_utils.hpp"

Expand Down Expand Up @@ -66,5 +68,14 @@ void SemanticAnalysisVisitor::visit_destructor_block(const ast::DestructorBlock&
/// -->
}

void SemanticAnalysisVisitor::visit_unit(const ast::Unit& node) {
/// <-- This code is for check 3
if (node.get_name()->get_value().empty()) {
logger->warn("SemanticAnalysisVisitor:: An unit cannot be created without name.");
check_fail = true;
}
/// -->
}

} // namespace visitor
} // namespace nmodl
4 changes: 4 additions & 0 deletions src/visitors/semantic_analysis_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* 1. Check that a function or a procedure containing a TABLE statement contains only one argument
* (mandatory in mod2c).
* 2. Check that destructor blocks are only inside mod file that are point_process
* 3. Check that unit always have a name
*/
#include "ast/ast.hpp"
#include "visitors/ast_visitor.hpp"
Expand Down Expand Up @@ -56,6 +57,9 @@ class SemanticAnalysisVisitor: public ConstAstVisitor {
/// Visit destructor and check that the file is of type POINT_PROCESS or ARTIFICIAL_CELL
void visit_destructor_block(const ast::DestructorBlock& node) override;

/// Visit an unit and check that name is not empty
void visit_unit(const ast::Unit& node) override;

public:
SemanticAnalysisVisitor() = default;

Expand Down

0 comments on commit 3a52160

Please sign in to comment.