Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 6d98823

Browse files
Nicolas CornuNicolas Cornu
authored andcommitted
Add semantic check for empty unit name
1 parent cd5728e commit 6d98823

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/parser/nmodl.yy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ units : {
618618

619619
unit : "(" { scanner.scan_unit(); } ")"
620620
{
621-
// @todo Empty units should be handled in semantic analysis
622621
auto unit = scanner.get_unit();
623622
auto text = unit->eval();
624623
$$ = new ast::Unit(unit);

src/visitors/semantic_analysis_visitor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
#include "ast/function_block.hpp"
33
#include "ast/procedure_block.hpp"
44
#include "ast/program.hpp"
5+
#include "ast/string.hpp"
56
#include "ast/suffix.hpp"
67
#include "ast/table_statement.hpp"
8+
#include "ast/unit.hpp"
79
#include "utils/logger.hpp"
810
#include "visitors/visitor_utils.hpp"
911

@@ -66,5 +68,14 @@ void SemanticAnalysisVisitor::visit_destructor_block(const ast::DestructorBlock&
6668
/// -->
6769
}
6870

71+
void SemanticAnalysisVisitor::visit_unit(const ast::Unit& node) {
72+
/// <-- This code is for check 3
73+
if (node.get_name()->get_value().empty()) {
74+
logger->warn("SemanticAnalysisVisitor:: An unit cannot be created without name.");
75+
check_fail = true;
76+
}
77+
/// -->
78+
}
79+
6980
} // namespace visitor
7081
} // namespace nmodl

src/visitors/semantic_analysis_visitor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* 1. Check that a function or a procedure containing a TABLE statement contains only one argument
2727
* (mandatory in mod2c).
2828
* 2. Check that destructor blocks are only inside mod file that are point_process
29+
* 3. Check that unit always have a name
2930
*/
3031
#include "ast/ast.hpp"
3132
#include "visitors/ast_visitor.hpp"
@@ -56,6 +57,9 @@ class SemanticAnalysisVisitor: public ConstAstVisitor {
5657
/// Visit destructor and check that the file is of type POINT_PROCESS or ARTIFICIAL_CELL
5758
void visit_destructor_block(const ast::DestructorBlock& node) override;
5859

60+
/// Visit an unit and check that name is not empty
61+
void visit_unit(const ast::Unit& node) override;
62+
5963
public:
6064
SemanticAnalysisVisitor() = default;
6165

0 commit comments

Comments
 (0)