@@ -41,11 +41,10 @@ class CoCoAllVariablesDefined(CoCo):
4141 """
4242
4343 @classmethod
44- def check_co_co (cls , node : ASTModel , after_ast_rewrite : bool = False ):
44+ def check_co_co (cls , node : ASTModel ):
4545 """
4646 Checks if this coco applies for the handed over neuron. Models which contain undefined variables are not correct.
4747 :param node: a single neuron instance.
48- :param after_ast_rewrite: indicates whether this coco is checked after the code generator has done rewriting of the abstract syntax tree. If True, checks are not as rigorous. Use False where possible.
4948 """
5049 # for each variable in all expressions, check if the variable has been defined previously
5150 expression_collector_visitor = ASTExpressionCollectorVisitor ()
@@ -62,32 +61,6 @@ def check_co_co(cls, node: ASTModel, after_ast_rewrite: bool = False):
6261
6362 # test if the symbol has been defined at least
6463 if symbol is None :
65- if after_ast_rewrite : # after ODE-toolbox transformations, convolutions are replaced by state variables, so cannot perform this check properly
66- symbol2 = node .get_scope ().resolve_to_symbol (var .get_name (), SymbolKind .VARIABLE )
67- if symbol2 is not None :
68- # an inline expression defining this variable name (ignoring differential order) exists
69- if "__X__" in str (symbol2 ): # if this variable was the result of a convolution...
70- continue
71- else :
72- # for kernels, also allow derivatives of that kernel to appear
73-
74- inline_expr_names = []
75- inline_exprs = []
76- for equations_block in node .get_equations_blocks ():
77- inline_expr_names .extend ([inline_expr .variable_name for inline_expr in equations_block .get_inline_expressions ()])
78- inline_exprs .extend (equations_block .get_inline_expressions ())
79-
80- if var .get_name () in inline_expr_names :
81- inline_expr_idx = inline_expr_names .index (var .get_name ())
82- inline_expr = inline_exprs [inline_expr_idx ]
83- from pynestml .utils .ast_utils import ASTUtils
84- if ASTUtils .inline_aliases_convolution (inline_expr ):
85- symbol2 = node .get_scope ().resolve_to_symbol (var .get_name (), SymbolKind .VARIABLE )
86- if symbol2 is not None :
87- # actually, no problem detected, skip error
88- # XXX: TODO: check that differential order is less than or equal to that of the kernel
89- continue
90-
9164 # check if this symbol is actually a type, e.g. "mV" in the expression "(1 + 2) * mV"
9265 symbol2 = var .get_scope ().resolve_to_symbol (var .get_complete_name (), SymbolKind .TYPE )
9366 if symbol2 is not None :
@@ -106,9 +79,14 @@ def check_co_co(cls, node: ASTModel, after_ast_rewrite: bool = False):
10679 # in this case its ok if it is recursive or defined later on
10780 continue
10881
82+ if symbol .is_predefined :
83+ continue
84+
85+ if symbol .block_type == BlockType .LOCAL and symbol .get_referenced_object ().get_source_position ().before (var .get_source_position ()):
86+ continue
87+
10988 # check if it has been defined before usage, except for predefined symbols, input ports and variables added by the AST transformation functions
110- if (not symbol .is_predefined ) \
111- and symbol .block_type != BlockType .INPUT \
89+ if symbol .block_type != BlockType .INPUT \
11290 and not symbol .get_referenced_object ().get_source_position ().is_added_source_position ():
11391 # except for parameters, those can be defined after
11492 if ((not symbol .get_referenced_object ().get_source_position ().before (var .get_source_position ()))
0 commit comments