diff --git a/pynestml/codegeneration/nest_code_generator.py b/pynestml/codegeneration/nest_code_generator.py
index aad4f60cd..aa2d68f73 100644
--- a/pynestml/codegeneration/nest_code_generator.py
+++ b/pynestml/codegeneration/nest_code_generator.py
@@ -49,8 +49,7 @@
from pynestml.codegeneration.printers.ode_toolbox_expression_printer import ODEToolboxExpressionPrinter
from pynestml.codegeneration.printers.ode_toolbox_function_call_printer import ODEToolboxFunctionCallPrinter
from pynestml.codegeneration.printers.ode_toolbox_variable_printer import ODEToolboxVariablePrinter
-from pynestml.codegeneration.printers.unitless_cpp_simple_expression_printer import UnitlessCppSimpleExpressionPrinter
-from pynestml.codegeneration.printers.unitless_sympy_simple_expression_printer import UnitlessSympySimpleExpressionPrinter
+from pynestml.codegeneration.printers.sympy_simple_expression_printer import SympySimpleExpressionPrinter
from pynestml.frontend.frontend_configuration import FrontendConfiguration
from pynestml.meta_model.ast_assignment import ASTAssignment
from pynestml.meta_model.ast_input_port import ASTInputPort
@@ -59,7 +58,6 @@
from pynestml.meta_model.ast_node_factory import ASTNodeFactory
from pynestml.meta_model.ast_ode_equation import ASTOdeEquation
from pynestml.symbol_table.symbol_table import SymbolTable
-from pynestml.symbols.boolean_type_symbol import BooleanTypeSymbol
from pynestml.symbols.real_type_symbol import RealTypeSymbol
from pynestml.symbols.unit_type_symbol import UnitTypeSymbol
from pynestml.symbols.symbol import SymbolKind
@@ -235,17 +233,17 @@ def setup_printers(self):
else:
self._gsl_function_call_printer = NESTGSLFunctionCallPrinter(None)
- self._gsl_printer = CppExpressionPrinter(simple_expression_printer=UnitlessCppSimpleExpressionPrinter(variable_printer=self._gsl_variable_printer,
- constant_printer=self._constant_printer,
- function_call_printer=self._gsl_function_call_printer))
+ self._gsl_printer = CppExpressionPrinter(simple_expression_printer=CppSimpleExpressionPrinter(variable_printer=self._gsl_variable_printer,
+ constant_printer=self._constant_printer,
+ function_call_printer=self._gsl_function_call_printer))
self._gsl_function_call_printer._expression_printer = self._gsl_printer
# ODE-toolbox printers
self._ode_toolbox_variable_printer = ODEToolboxVariablePrinter(None)
self._ode_toolbox_function_call_printer = ODEToolboxFunctionCallPrinter(None)
- self._ode_toolbox_printer = ODEToolboxExpressionPrinter(simple_expression_printer=UnitlessSympySimpleExpressionPrinter(variable_printer=self._ode_toolbox_variable_printer,
- constant_printer=self._constant_printer,
- function_call_printer=self._ode_toolbox_function_call_printer))
+ self._ode_toolbox_printer = ODEToolboxExpressionPrinter(simple_expression_printer=SympySimpleExpressionPrinter(variable_printer=self._ode_toolbox_variable_printer,
+ constant_printer=self._constant_printer,
+ function_call_printer=self._ode_toolbox_function_call_printer))
self._ode_toolbox_variable_printer._expression_printer = self._ode_toolbox_printer
self._ode_toolbox_function_call_printer._expression_printer = self._ode_toolbox_printer
diff --git a/pynestml/codegeneration/nest_compartmental_code_generator.py b/pynestml/codegeneration/nest_compartmental_code_generator.py
index 00f061775..30716efbc 100644
--- a/pynestml/codegeneration/nest_compartmental_code_generator.py
+++ b/pynestml/codegeneration/nest_compartmental_code_generator.py
@@ -27,6 +27,7 @@
from jinja2 import TemplateRuntimeError
from odetoolbox import analysis
+from pynestml.codegeneration.printers.sympy_simple_expression_printer import SympySimpleExpressionPrinter
import pynestml
from pynestml.cocos.co_cos_manager import CoCosManager
@@ -46,7 +47,6 @@
from pynestml.codegeneration.printers.ode_toolbox_expression_printer import ODEToolboxExpressionPrinter
from pynestml.codegeneration.printers.ode_toolbox_function_call_printer import ODEToolboxFunctionCallPrinter
from pynestml.codegeneration.printers.ode_toolbox_variable_printer import ODEToolboxVariablePrinter
-from pynestml.codegeneration.printers.unitless_cpp_simple_expression_printer import UnitlessCppSimpleExpressionPrinter
from pynestml.frontend.frontend_configuration import FrontendConfiguration
from pynestml.meta_model.ast_assignment import ASTAssignment
from pynestml.meta_model.ast_block_with_variables import ASTBlockWithVariables
@@ -172,16 +172,16 @@ def setup_printers(self):
self._gsl_function_call_printer = NESTGSLFunctionCallPrinter(None)
self._gsl_printer = CppExpressionPrinter(
- simple_expression_printer=UnitlessCppSimpleExpressionPrinter(variable_printer=self._gsl_variable_printer,
- constant_printer=self._constant_printer,
- function_call_printer=self._gsl_function_call_printer))
+ simple_expression_printer=CppSimpleExpressionPrinter(variable_printer=self._gsl_variable_printer,
+ constant_printer=self._constant_printer,
+ function_call_printer=self._gsl_function_call_printer))
self._gsl_function_call_printer._expression_printer = self._gsl_printer
# ODE-toolbox printers
self._ode_toolbox_variable_printer = ODEToolboxVariablePrinter(None)
self._ode_toolbox_function_call_printer = ODEToolboxFunctionCallPrinter(None)
self._ode_toolbox_printer = ODEToolboxExpressionPrinter(
- simple_expression_printer=UnitlessCppSimpleExpressionPrinter(
+ simple_expression_printer=SympySimpleExpressionPrinter(
variable_printer=self._ode_toolbox_variable_printer,
constant_printer=self._constant_printer,
function_call_printer=self._ode_toolbox_function_call_printer))
diff --git a/pynestml/codegeneration/printers/__init__.py b/pynestml/codegeneration/printers/__init__.py
index b62bf5e3f..23299a4be 100644
--- a/pynestml/codegeneration/printers/__init__.py
+++ b/pynestml/codegeneration/printers/__init__.py
@@ -20,6 +20,7 @@
# along with NEST. If not, see .
__all__ = ["ast_printer",
+ "c_simple_expression_printer",
"constant_printer",
"cpp_expression_printer",
"cpp_function_call_printer",
@@ -29,7 +30,6 @@
"cpp_variable_printer",
"expression_printer",
"function_call_printer",
- "function_printer",
"gsl_variable_printer",
"latex_expression_printer",
"latex_function_call_printer",
@@ -42,14 +42,13 @@
"nest_gsl_function_call_printer",
"nestml_printer",
"nestml_variable_printer",
- "nest_simple_expression_printer",
"nest_variable_printer",
"ode_toolbox_expression_printer",
"ode_toolbox_function_call_printer",
"ode_toolbox_variable_printer",
+ "python_simple_expression_printer",
"python_type_symbol_printer",
"simple_expression_printer",
"symbol_printer",
"type_symbol_printer",
- "unitless_cpp_simple_expression_printer",
"variable_printer"]
diff --git a/pynestml/codegeneration/printers/gsl_variable_printer.py b/pynestml/codegeneration/printers/gsl_variable_printer.py
index 4de36651a..463833a43 100644
--- a/pynestml/codegeneration/printers/gsl_variable_printer.py
+++ b/pynestml/codegeneration/printers/gsl_variable_printer.py
@@ -18,16 +18,19 @@
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see .
-
+from pynestml.codegeneration.nest_unit_converter import NESTUnitConverter
from pynestml.codegeneration.printers.cpp_variable_printer import CppVariablePrinter
from pynestml.meta_model.ast_variable import ASTVariable
+from pynestml.symbols.predefined_units import PredefinedUnits
from pynestml.symbols.symbol import SymbolKind
from pynestml.utils.ast_utils import ASTUtils
+from pynestml.utils.logger import Logger, LoggingLevel
+from pynestml.utils.messages import Messages
class GSLVariablePrinter(CppVariablePrinter):
r"""
- Reference converter for C++ syntax and using the GSL (GNU Scientific Library) API from inside the ``extern "C"`` stepping function.
+ Variable printer for C++ syntax and using the GSL (GNU Scientific Library) API from inside the ``extern "C"`` stepping function.
"""
def print_variable(self, node: ASTVariable) -> str:
@@ -39,6 +42,16 @@ def print_variable(self, node: ASTVariable) -> str:
assert isinstance(node, ASTVariable)
symbol = node.get_scope().resolve_to_symbol(node.get_complete_name(), SymbolKind.VARIABLE)
+ if symbol is None:
+ # test if variable name can be resolved to a type
+ if PredefinedUnits.is_unit(node.get_complete_name()):
+ return str(NESTUnitConverter.get_factor(PredefinedUnits.get_unit(node.get_complete_name()).get_unit()))
+
+ code, message = Messages.get_could_not_resolve(node.get_name())
+ Logger.log_message(log_level=LoggingLevel.ERROR, code=code, message=message,
+ error_position=node.get_source_position())
+ return ""
+
if node.is_delay_variable():
return self._print_delay_variable(node)
diff --git a/pynestml/codegeneration/printers/unitless_sympy_simple_expression_printer.py b/pynestml/codegeneration/printers/sympy_simple_expression_printer.py
similarity index 94%
rename from pynestml/codegeneration/printers/unitless_sympy_simple_expression_printer.py
rename to pynestml/codegeneration/printers/sympy_simple_expression_printer.py
index bd41a0cc2..bf9c64bea 100644
--- a/pynestml/codegeneration/printers/unitless_sympy_simple_expression_printer.py
+++ b/pynestml/codegeneration/printers/sympy_simple_expression_printer.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# unitless_sympy_simple_expression_printer.py
+# sympy_simple_expression_printer.py
#
# This file is part of NEST.
#
@@ -21,6 +21,7 @@
from pynestml.codegeneration.nest_unit_converter import NESTUnitConverter
from pynestml.codegeneration.printers.cpp_simple_expression_printer import CppSimpleExpressionPrinter
+from pynestml.codegeneration.printers.simple_expression_printer import SimpleExpressionPrinter
from pynestml.meta_model.ast_function_call import ASTFunctionCall
from pynestml.meta_model.ast_node import ASTNode
from pynestml.meta_model.ast_simple_expression import ASTSimpleExpression
@@ -29,7 +30,7 @@
from pynestml.symbols.symbol import SymbolKind
-class UnitlessSympySimpleExpressionPrinter(CppSimpleExpressionPrinter):
+class SympySimpleExpressionPrinter(CppSimpleExpressionPrinter):
r"""
Printer for ASTSimpleExpressions in Sympy syntax.
"""
diff --git a/pynestml/codegeneration/printers/unitless_c_simple_expression_printer.py b/pynestml/codegeneration/printers/unitless_c_simple_expression_printer.py
deleted file mode 100644
index e0aa938e6..000000000
--- a/pynestml/codegeneration/printers/unitless_c_simple_expression_printer.py
+++ /dev/null
@@ -1,59 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# unitless_c_simple_expression_printer.py
-#
-# This file is part of NEST.
-#
-# Copyright (C) 2004 The NEST Initiative
-#
-# NEST is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# NEST is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with NEST. If not, see .
-
-from pynestml.codegeneration.printers.c_simple_expression_printer import CSimpleExpressionPrinter
-from pynestml.codegeneration.spinnaker_unit_converter import SpinnakerUnitConverter
-from pynestml.meta_model.ast_simple_expression import ASTSimpleExpression
-from pynestml.symbols.symbol import SymbolKind
-from pynestml.symbols.predefined_units import PredefinedUnits
-
-
-class UnitlessCSimpleExpressionPrinter(CSimpleExpressionPrinter):
- r"""
- An adjusted version of the printer which prints in the units of the target platform (XXX: just nest?)
- """
-
- def print_simple_expression(self, node: ASTSimpleExpression) -> str:
- r"""Print an expression.
-
- Parameters
- ----------
- node
- The expression node to print.
-
- Returns
- -------
- s
- The expression string.
- """
- assert isinstance(node, ASTSimpleExpression)
-
- if node.is_numeric_literal():
- return self._constant_printer.print_constant(node.get_numeric_literal())
-
- if node.is_variable() and node.get_scope() is not None:
- node_is_variable_symbol = node.get_scope().resolve_to_symbol(
- node.variable.get_complete_name(), SymbolKind.VARIABLE) is not None
- if not node_is_variable_symbol and PredefinedUnits.is_unit(node.variable.get_complete_name()):
- # case for a literal unit, e.g. "ms"
- return str(SpinnakerUnitConverter.get_factor(PredefinedUnits.get_unit(node.variable.get_complete_name()).get_unit()))
-
- return super().print_simple_expression(node)
diff --git a/pynestml/codegeneration/printers/unitless_cpp_simple_expression_printer.py b/pynestml/codegeneration/printers/unitless_cpp_simple_expression_printer.py
deleted file mode 100644
index f8c107452..000000000
--- a/pynestml/codegeneration/printers/unitless_cpp_simple_expression_printer.py
+++ /dev/null
@@ -1,59 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# unitless_cpp_simple_expression_printer.py
-#
-# This file is part of NEST.
-#
-# Copyright (C) 2004 The NEST Initiative
-#
-# NEST is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-#
-# NEST is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with NEST. If not, see .
-
-from pynestml.codegeneration.printers.cpp_simple_expression_printer import CppSimpleExpressionPrinter
-from pynestml.codegeneration.nest_unit_converter import NESTUnitConverter
-from pynestml.meta_model.ast_simple_expression import ASTSimpleExpression
-from pynestml.symbols.symbol import SymbolKind
-from pynestml.symbols.predefined_units import PredefinedUnits
-
-
-class UnitlessCppSimpleExpressionPrinter(CppSimpleExpressionPrinter):
- r"""
- An adjusted version of the printer which prints in the units of the target platform (XXX: just nest?)
- """
-
- def print_simple_expression(self, node: ASTSimpleExpression) -> str:
- r"""Print an expression.
-
- Parameters
- ----------
- node
- The expression node to print.
-
- Returns
- -------
- s
- The expression string.
- """
- assert isinstance(node, ASTSimpleExpression)
-
- if node.is_numeric_literal():
- return self._constant_printer.print_constant(node.get_numeric_literal())
-
- if node.is_variable() and node.get_scope() is not None:
- node_is_variable_symbol = node.get_scope().resolve_to_symbol(
- node.variable.get_complete_name(), SymbolKind.VARIABLE) is not None
- if not node_is_variable_symbol and PredefinedUnits.is_unit(node.variable.get_complete_name()):
- # case for a literal unit, e.g. "ms"
- return str(NESTUnitConverter.get_factor(PredefinedUnits.get_unit(node.variable.get_complete_name()).get_unit()))
-
- return super().print_simple_expression(node)
diff --git a/pynestml/codegeneration/python_standalone_code_generator.py b/pynestml/codegeneration/python_standalone_code_generator.py
index 56f32f771..76421aa8f 100644
--- a/pynestml/codegeneration/python_standalone_code_generator.py
+++ b/pynestml/codegeneration/python_standalone_code_generator.py
@@ -111,8 +111,6 @@ def setup_printers(self):
self._nest_variable_printer_no_origin._expression_printer = self._printer_no_origin
self._nest_function_call_printer_no_origin._expression_printer = self._printer_no_origin
- self._nest_unitless_function_call_printer = PythonFunctionCallPrinter(None)
-
# GSL printers
self._gsl_variable_printer = PythonSteppingFunctionVariablePrinter(None)
self._gsl_function_call_printer = PythonSteppingFunctionFunctionCallPrinter(None)
diff --git a/pynestml/codegeneration/spinnaker_code_generator.py b/pynestml/codegeneration/spinnaker_code_generator.py
index 0fab611ed..ba47f8c14 100644
--- a/pynestml/codegeneration/spinnaker_code_generator.py
+++ b/pynestml/codegeneration/spinnaker_code_generator.py
@@ -46,7 +46,6 @@
from pynestml.codegeneration.printers.spinnaker_python_function_call_printer import SpinnakerPythonFunctionCallPrinter
from pynestml.codegeneration.printers.spinnaker_python_simple_expression_printer import SpinnakerPythonSimpleExpressionPrinter
from pynestml.codegeneration.printers.spinnaker_python_type_symbol_printer import SpinnakerPythonTypeSymbolPrinter
-from pynestml.codegeneration.printers.unitless_c_simple_expression_printer import UnitlessCSimpleExpressionPrinter
from pynestml.codegeneration.python_standalone_code_generator import PythonStandaloneCodeGenerator
from pynestml.meta_model.ast_model import ASTModel
from pynestml.visitors.ast_symbol_table_visitor import ASTSymbolTableVisitor
@@ -85,16 +84,16 @@ def setup_printers(self):
self._gsl_function_call_printer = SpinnakerGSLFunctionCallPrinter(None)
self._gsl_printer = CppExpressionPrinter(
- simple_expression_printer=UnitlessCSimpleExpressionPrinter(variable_printer=self._gsl_variable_printer,
- constant_printer=self._constant_printer,
- function_call_printer=self._gsl_function_call_printer))
+ simple_expression_printer=CSimpleExpressionPrinter(variable_printer=self._gsl_variable_printer,
+ constant_printer=self._constant_printer,
+ function_call_printer=self._gsl_function_call_printer))
self._gsl_function_call_printer._expression_printer = self._gsl_printer
# ODE-toolbox printers
self._ode_toolbox_variable_printer = ODEToolboxVariablePrinter(None)
self._ode_toolbox_function_call_printer = ODEToolboxFunctionCallPrinter(None)
self._ode_toolbox_printer = ODEToolboxExpressionPrinter(
- simple_expression_printer=UnitlessCSimpleExpressionPrinter(
+ simple_expression_printer=CSimpleExpressionPrinter(
variable_printer=self._ode_toolbox_variable_printer,
constant_printer=self._constant_printer,
function_call_printer=self._ode_toolbox_function_call_printer))
@@ -133,8 +132,6 @@ def setup_printers(self):
self._nest_variable_printer_no_origin._expression_printer = self._printer_no_origin
self._nest_function_call_printer_no_origin._expression_printer = self._printer_no_origin
- self._nest_unitless_function_call_printer = SpinnakerPythonFunctionCallPrinter(None)
-
# GSL printers
self._gsl_variable_printer = PythonSteppingFunctionVariablePrinter(None)
self._gsl_function_call_printer = PythonSteppingFunctionFunctionCallPrinter(None)
diff --git a/pynestml/utils/mechanism_processing.py b/pynestml/utils/mechanism_processing.py
index e53c2d05a..d45257adf 100644
--- a/pynestml/utils/mechanism_processing.py
+++ b/pynestml/utils/mechanism_processing.py
@@ -23,12 +23,14 @@
import copy
+from pynestml.codegeneration.printers.sympy_simple_expression_printer import SympySimpleExpressionPrinter
+
+from pynestml.codegeneration.printers.cpp_simple_expression_printer import CppSimpleExpressionPrinter
from pynestml.codegeneration.printers.nestml_printer import NESTMLPrinter
from pynestml.codegeneration.printers.constant_printer import ConstantPrinter
from pynestml.codegeneration.printers.ode_toolbox_expression_printer import ODEToolboxExpressionPrinter
from pynestml.codegeneration.printers.ode_toolbox_function_call_printer import ODEToolboxFunctionCallPrinter
from pynestml.codegeneration.printers.ode_toolbox_variable_printer import ODEToolboxVariablePrinter
-from pynestml.codegeneration.printers.unitless_cpp_simple_expression_printer import UnitlessCppSimpleExpressionPrinter
from pynestml.meta_model.ast_expression import ASTExpression
from pynestml.meta_model.ast_model import ASTModel
from pynestml.meta_model.ast_simple_expression import ASTSimpleExpression
@@ -56,7 +58,7 @@ class MechanismProcessing:
_ode_toolbox_variable_printer = ODEToolboxVariablePrinter(None)
_ode_toolbox_function_call_printer = ODEToolboxFunctionCallPrinter(None)
_ode_toolbox_printer = ODEToolboxExpressionPrinter(
- simple_expression_printer=UnitlessCppSimpleExpressionPrinter(
+ simple_expression_printer=SympySimpleExpressionPrinter(
variable_printer=_ode_toolbox_variable_printer,
constant_printer=_constant_printer,
function_call_printer=_ode_toolbox_function_call_printer))