Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check unit empty #883

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
alkino marked this conversation as resolved.
Show resolved Hide resolved
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