Skip to content

Commit

Permalink
add include statement
Browse files Browse the repository at this point in the history
  • Loading branch information
C.A.P. Linssen committed Nov 30, 2024
1 parent 16e9913 commit 8076f2c
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 251 deletions.
1 change: 1 addition & 0 deletions pynestml/cocos/co_co_all_variables_defined.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def check_co_co(cls, node: ASTModel):
# now check that they are not defined recursively, e.g. V_m mV = V_m + 1
# todo: we should not check this for invariants
if (symbol.get_referenced_object().get_source_position().encloses(var.get_source_position())
and not symbol.get_referenced_object().get_source_position().included_file
and not symbol.get_referenced_object().get_source_position().is_added_source_position()):
code, message = Messages.get_variable_defined_recursively(var.get_name())
Logger.log_message(code=code, message=message, error_position=symbol.get_referenced_object().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

from pynestml.cocos.co_co import CoCo
from pynestml.meta_model.ast_assignment import ASTAssignment
from pynestml.meta_model.ast_model import ASTModel
from pynestml.cocos.co_co import CoCo
from pynestml.symbol_table.scope import ScopeType
from pynestml.symbols.symbol import SymbolKind
from pynestml.symbols.variable_symbol import BlockType
from pynestml.utils.ast_utils import ASTUtils
from pynestml.utils.logger import LoggingLevel, Logger
from pynestml.utils.messages import Messages
Expand Down
1 change: 0 additions & 1 deletion pynestml/cocos/co_cos_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
from pynestml.cocos.co_co_vector_parameter_declared_in_right_block import CoCoVectorParameterDeclaredInRightBlock
from pynestml.cocos.co_co_vector_variable_in_non_vector_declaration import CoCoVectorVariableInNonVectorDeclaration
from pynestml.frontend.frontend_configuration import FrontendConfiguration
from pynestml.utils.logger import Logger
from pynestml.meta_model.ast_model import ASTModel
from pynestml.utils.logger import Logger

Expand Down
1 change: 0 additions & 1 deletion pynestml/codegeneration/spinnaker_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,4 @@ def generate_code(self, models: Sequence[ASTModel]) -> None:
cloned_models.append(cloned_model)

self.codegen_cpp.generate_code(cloned_models)
CoCosManager.check_cocos(cloned_model)
self.codegen_py.generate_code(cloned_models)
5 changes: 2 additions & 3 deletions pynestml/frontend/pynestml_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,14 @@ def process() -> bool:
# validation -- check cocos for models that do not have errors already
excluded_models = []
for model in models:
if not Logger.has_errors(model.name):
CoCosManager.check_cocos(model)

if Logger.has_errors(model.name):
code, message = Messages.get_model_contains_errors(model.get_name())
Logger.log_message(node=model, code=code, message=message,
error_position=model.get_source_position(),
log_level=LoggingLevel.WARNING)
excluded_models.append(model)
else:
CoCosManager.check_cocos(model)

# exclude models that have errors
models = list(set(models) - set(excluded_models))
Expand Down
1 change: 1 addition & 0 deletions pynestml/meta_model/ast_small_stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, assignment: Optional[ASTAssignment] = None, function_call: Op
self.declaration = declaration
self.return_stmt = return_stmt
self.include_stmt = include_stmt
assert self.assignment or self.function_call or self.declaration or self.return_stmt or self.include_stmt

def clone(self):
"""
Expand Down
1 change: 1 addition & 0 deletions pynestml/symbol_table/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ScopeType(Enum):
FUNCTION = 3
ON_RECEIVE = 4
ON_CONDITION = 5
INCLUDED_FILE = 6


class Scope:
Expand Down
21 changes: 15 additions & 6 deletions pynestml/utils/ast_source_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

import sys


Expand Down Expand Up @@ -47,6 +48,7 @@ def __init__(self, start_line, start_column, end_line, end_column):
self.start_column = start_column
self.end_line = end_line
self.end_column = end_column
self.included_file = None

@classmethod
def make_ast_source_position(cls, start_line, start_column, end_line, end_column):
Expand Down Expand Up @@ -197,16 +199,23 @@ def encloses(self, source_position):
else:
return False

def __str__(self):
def __str__(self) -> str:
"""
A string representation of this source position.
:return: a string representation
:rtype: str
"""
s = "["
if self.included_file:
s += "In code included from '" + self.included_file + "': "

if self.is_added_source_position():
return '<ADDED_BY_SOLVER>'
s += "ADDED_BY_SOLVER"
elif self.is_predefined_source_position():
return '<PREDEFINED>'
s += "PREDEFINED"
else:
return '[' + str(self.get_start_line()) + ':' + str(self.get_start_column()) + ';' + \
str(self.get_end_line()) + ':' + str(self.get_end_column()) + ']'
s += str(self.get_start_line()) + ':' + str(self.get_start_column()) + ';' \
+ str(self.get_end_line()) + ':' + str(self.get_end_column())

s += "]"

return s
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

from pynestml.utils.ast_vector_parameter_setter_and_printer import ASTVectorParameterSetterAndPrinter
from pynestml.visitors.ast_visitor import ASTVisitor

from pynestml.utils.model_parser import ModelParser
from pynestml.visitors.ast_symbol_table_visitor import ASTSymbolTableVisitor
from pynestml.symbol_table.scope import Scope, ScopeType, Symbol, SymbolKind
from pynestml.symbols.variable_symbol import VariableSymbol


class ASTVectorParameterSetterAndPrinterFactory:
Expand Down
5 changes: 5 additions & 0 deletions pynestml/utils/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def get_parser_error(cls):
message = 'Error occurred during parsing: abort'
return MessageCode.PARSER_ERROR, message

@classmethod
def get_parser_error_verbose(cls, string: str):
message = 'Parse error: ' + string
return MessageCode.PARSER_ERROR, message

@classmethod
def get_binary_operation_not_defined(cls, lhs, operator, rhs):
message = 'Operation %s %s %s is not defined!' % (lhs, operator, rhs)
Expand Down
Loading

0 comments on commit 8076f2c

Please sign in to comment.