本文整理汇总了Python中pynestml.symbols.predefined_types.PredefinedTypes类的典型用法代码示例。如果您正苦于以下问题:Python PredefinedTypes类的具体用法?Python PredefinedTypes怎么用?Python PredefinedTypes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PredefinedTypes类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: endvisit_function
def endvisit_function(self, node):
symbol = self.symbol_stack.pop()
scope = self.scope_stack.pop()
assert isinstance(symbol, FunctionSymbol), 'Not a function symbol'
for arg in node.get_parameters():
# given the fact that the name is not directly equivalent to the one as stated in the model,
# we have to get it by the sub-visitor
data_type_visitor = ASTDataTypeVisitor()
arg.get_data_type().accept(data_type_visitor)
type_name = data_type_visitor.result
# first collect the types for the parameters of the function symbol
symbol.add_parameter_type(PredefinedTypes.get_type(type_name))
# update the scope of the arg
arg.update_scope(scope)
# create the corresponding variable symbol representing the parameter
var_symbol = VariableSymbol(element_reference=arg, scope=scope, name=arg.get_name(),
block_type=BlockType.LOCAL, is_predefined=False, is_function=False,
is_recordable=False,
type_symbol=PredefinedTypes.get_type(type_name),
variable_type=VariableType.VARIABLE)
assert isinstance(scope, Scope)
scope.add_symbol(var_symbol)
if node.has_return_type():
data_type_visitor = ASTDataTypeVisitor()
node.get_return_type().accept(data_type_visitor)
symbol.set_return_type(PredefinedTypes.get_type(data_type_visitor.result))
else:
symbol.set_return_type(PredefinedTypes.get_void_type())
self.block_type_stack.pop() # before leaving update the type
开发者ID:Silmathoron,项目名称:nestml,代码行数:29,代码来源:ast_symbol_table_visitor.py
示例2: visit_simple_expression
def visit_simple_expression(self, node):
"""
Visit a simple rhs and update the type of a numeric literal.
:param node: a single meta_model node
:type node: ast_node
:return: no value returned, the type is updated in-place
:rtype: void
"""
assert node.get_scope() is not None, "Run symboltable creator."
# if variable is also set in this rhs, the var type overrides the literal
if node.get_variable() is not None:
scope = node.get_scope()
var_name = node.get_variable().get_name()
variable_symbol_resolve = scope.resolve_to_symbol(var_name, SymbolKind.VARIABLE)
if not variable_symbol_resolve is None:
node.type = variable_symbol_resolve.get_type_symbol()
else:
node.type = scope.resolve_to_symbol(var_name, SymbolKind.TYPE)
node.type.referenced_object = node
return
if node.get_numeric_literal() is not None and isinstance(node.get_numeric_literal(), float):
node.type = PredefinedTypes.get_real_type()
node.type.referenced_object = node
return
elif node.get_numeric_literal() is not None and isinstance(node.get_numeric_literal(), int):
node.type = PredefinedTypes.get_integer_type()
node.type.referenced_object = node
return
开发者ID:Silmathoron,项目名称:nestml,代码行数:30,代码来源:ast_numeric_literal_visitor.py
示例3: __register_print_function
def __register_print_function(cls):
"""
Registers the print function.
"""
params = list()
params.append(PredefinedTypes.get_string_type())
symbol = FunctionSymbol(name=cls.PRINT, param_types=params,
return_type=PredefinedTypes.get_void_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.PRINT] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:10,代码来源:predefined_functions.py
示例4: __register_logger_info_function
def __register_logger_info_function(cls):
"""
Registers the logger info method into the scope.
"""
params = list()
params.append(PredefinedTypes.get_string_type()) # the argument
symbol = FunctionSymbol(name=cls.LOGGER_INFO, param_types=params,
return_type=PredefinedTypes.get_void_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.LOGGER_INFO] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:10,代码来源:predefined_functions.py
示例5: setUp
def setUp(self):
PredefinedUnits.register_units()
PredefinedTypes.register_types()
PredefinedFunctions.register_functions()
PredefinedVariables.register_variables()
SymbolTable.initialize_symbol_table(ASTSourceLocation(start_line=0, start_column=0, end_line=0, end_column=0))
Logger.init_logger(LoggingLevel.INFO)
self.target_path = str(os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.join(
os.pardir, 'target'))))
开发者ID:Silmathoron,项目名称:nestml,代码行数:10,代码来源:nest_codegenerator_preparation_test.py
示例6: __register_logger_warning_function
def __register_logger_warning_function(cls):
"""
Registers the logger warning method.
"""
params = list()
params.append(PredefinedTypes.get_string_type()) # the argument
symbol = FunctionSymbol(name=cls.LOGGER_WARNING, param_types=params,
return_type=PredefinedTypes.get_void_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.LOGGER_WARNING] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:10,代码来源:predefined_functions.py
示例7: __register_exp1_function
def __register_exp1_function(cls):
"""
Registers the alternative version of the exponent function, exp1.
"""
params = list()
params.append(PredefinedTypes.get_real_type()) # the argument
symbol = FunctionSymbol(name=cls.EXPM1, param_types=params,
return_type=PredefinedTypes.get_real_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.EXPM1] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:10,代码来源:predefined_functions.py
示例8: __register_log_function
def __register_log_function(cls):
"""
Registers the logarithm function (to base 10).
"""
params = list()
params.append(PredefinedTypes.get_real_type()) # the argument
symbol = FunctionSymbol(name=cls.LOG, param_types=params,
return_type=PredefinedTypes.get_real_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.LOG] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:10,代码来源:predefined_functions.py
示例9: __register_time_steps_function
def __register_time_steps_function(cls):
"""
Registers the time-resolution.
"""
params = list()
params.append(PredefinedTypes.get_type('ms'))
symbol = FunctionSymbol(name=cls.TIME_STEPS, param_types=params,
return_type=PredefinedTypes.get_integer_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.TIME_STEPS] = symbol
return
开发者ID:Silmathoron,项目名称:nestml,代码行数:11,代码来源:predefined_functions.py
示例10: __register_power_function
def __register_power_function(cls):
"""
Registers the power function.
"""
params = list()
params.append(PredefinedTypes.get_real_type()) # the base type
params.append(PredefinedTypes.get_real_type()) # the exponent type
symbol = FunctionSymbol(name=cls.POW, param_types=params,
return_type=PredefinedTypes.get_real_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.POW] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:11,代码来源:predefined_functions.py
示例11: __register_convolve
def __register_convolve(cls):
"""
Registers the convolve function into the system.
"""
params = list()
params.append(PredefinedTypes.get_real_type())
params.append(PredefinedTypes.get_real_type())
symbol = FunctionSymbol(name=cls.CONVOLVE, param_types=params,
return_type=PredefinedTypes.get_real_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.CONVOLVE] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:11,代码来源:predefined_functions.py
示例12: __register_predefined_type_variables
def __register_predefined_type_variables(cls):
"""
Registers all predefined type variables, e.g., mV and integer.
"""
for name in PredefinedTypes.get_types().keys():
symbol = VariableSymbol(name=name, block_type=BlockType.PREDEFINED,
is_predefined=True,
type_symbol=PredefinedTypes.get_type(name),
variable_type=VariableType.TYPE)
cls.name2variable[name] = symbol
return
开发者ID:Silmathoron,项目名称:nestml,代码行数:11,代码来源:predefined_variables.py
示例13: __register_max_function
def __register_max_function(cls):
"""
Registers the maximum function.
"""
params = list()
params.append(PredefinedTypes.get_real_type())
params.append(PredefinedTypes.get_real_type())
symbol = FunctionSymbol(name=cls.MAX, param_types=params,
return_type=PredefinedTypes.get_real_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.MAX] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:11,代码来源:predefined_functions.py
示例14: __register_cond_sum_function
def __register_cond_sum_function(cls):
"""
Registers the cond_sum function into scope.
"""
params = list()
params.append(PredefinedTypes.get_type('nS'))
params.append(PredefinedTypes.get_real_type())
symbol = FunctionSymbol(name=cls.COND_SUM, param_types=params,
return_type=PredefinedTypes.get_type('nS'),
element_reference=None, is_predefined=True)
cls.name2function[cls.COND_SUM] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:11,代码来源:predefined_functions.py
示例15: __register_min_bounded_function
def __register_min_bounded_function(cls):
"""
Registers the minimum (bounded) function.
"""
params = list()
params.append(PredefinedTypes.get_real_type())
params.append(PredefinedTypes.get_real_type())
symbol = FunctionSymbol(name=cls.BOUNDED_MIN, param_types=params,
return_type=PredefinedTypes.get_real_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.BOUNDED_MIN] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:11,代码来源:predefined_functions.py
示例16: __register_delta_function
def __register_delta_function(cls):
"""
Registers the delta function.
"""
params = list()
params.append(PredefinedTypes.get_type('ms'))
params.append(PredefinedTypes.get_type('ms'))
symbol = FunctionSymbol(name=cls.DELTA, param_types=params,
return_type=PredefinedTypes.get_real_type(),
element_reference=None, is_predefined=True)
cls.name2function[cls.DELTA] = symbol
开发者ID:Silmathoron,项目名称:nestml,代码行数:11,代码来源:predefined_functions.py
示例17: endvisit_input_line
def endvisit_input_line(self, node):
buffer_type = BlockType.INPUT_BUFFER_SPIKE if node.is_spike() else BlockType.INPUT_BUFFER_CURRENT
if node.is_spike() and node.has_datatype():
type_symbol = node.get_datatype().get_type_symbol()
elif node.is_spike():
type_symbol = PredefinedTypes.get_type('nS')
else:
type_symbol = PredefinedTypes.get_type('pA')
type_symbol.is_buffer = True # set it as a buffer
symbol = VariableSymbol(element_reference=node, scope=node.get_scope(), name=node.get_name(),
block_type=buffer_type, vector_parameter=node.get_index_parameter(),
is_predefined=False, is_function=False, is_recordable=False,
type_symbol=type_symbol, variable_type=VariableType.BUFFER)
symbol.set_comment(node.get_comment())
node.get_scope().add_symbol(symbol)
开发者ID:Silmathoron,项目名称:nestml,代码行数:15,代码来源:ast_symbol_table_visitor.py
示例18: visit_neuron
def visit_neuron(self, node):
"""
Private method: Used to visit a single neuron and create the corresponding global as well as local scopes.
:return: a single neuron.
:rtype: ast_neuron
"""
# set current processed neuron
Logger.set_current_neuron(node)
code, message = Messages.get_start_building_symbol_table()
Logger.log_message(neuron=node, code=code, error_position=node.get_source_position(),
message=message, log_level=LoggingLevel.INFO)
# before starting the work on the neuron, make everything which was implicit explicit
# but if we have a model without an equations block, just skip this step
if node.get_equations_blocks() is not None:
make_implicit_odes_explicit(node.get_equations_blocks())
scope = Scope(scope_type=ScopeType.GLOBAL, source_position=node.get_source_position())
node.update_scope(scope)
node.get_body().update_scope(scope)
# now first, we add all predefined elements to the scope
variables = PredefinedVariables.get_variables()
functions = PredefinedFunctions.get_function_symbols()
types = PredefinedTypes.get_types()
for symbol in variables.keys():
node.get_scope().add_symbol(variables[symbol])
for symbol in functions.keys():
node.get_scope().add_symbol(functions[symbol])
for symbol in types.keys():
node.get_scope().add_symbol(types[symbol])
开发者ID:Silmathoron,项目名称:nestml,代码行数:28,代码来源:ast_symbol_table_visitor.py
示例19: check_co_co
def check_co_co(cls, _neuron=None):
"""
Checks the coco for the handed over neuron.
:param _neuron: a single neuron instance.
:type _neuron: ASTNeuron
"""
assert (_neuron is not None and isinstance(_neuron, ASTNeuron)), \
'(PyNestML.CoCo.FunctionCallsConsistent) No or wrong type of neuron provided (%s)!' % type(_neuron)
cls.__neuronName = _neuron.get_name()
for userDefinedFunction in _neuron.get_functions():
cls.processed_function = userDefinedFunction
symbol = userDefinedFunction.get_scope().resolve_to_symbol(userDefinedFunction.get_name(),
SymbolKind.FUNCTION)
# first ensure that the block contains at least one statement
if symbol is not None and len(userDefinedFunction.get_block().get_stmts()) > 0:
# now check that the last statement is a return
cls.__check_return_recursively(symbol.get_return_type(),
userDefinedFunction.get_block().get_stmts(), False)
# now if it does not have a statement, but uses a return type, it is an error
elif symbol is not None and userDefinedFunction.has_return_type() and \
not symbol.get_return_type().equals(PredefinedTypes.get_void_type()):
code, message = Messages.get_no_return()
Logger.log_message(neuron=_neuron, code=code, message=message,
error_position=userDefinedFunction.get_source_position(),
log_level=LoggingLevel.ERROR)
return
开发者ID:Silmathoron,项目名称:nestml,代码行数:26,代码来源:co_co_user_defined_function_correctly_defined.py
示例20: visit_expression
def visit_expression(self, node):
"""
Visits an expression which uses a binary logic operator and updates the type.
:param node: a single expression.
:type node: ast_expression
"""
lhs_type = node.get_lhs().type
rhs_type = node.get_rhs().type
lhs_type.referenced_object = node.get_lhs()
rhs_type.referenced_object = node.get_rhs()
if isinstance(lhs_type, BooleanTypeSymbol) and isinstance(rhs_type, BooleanTypeSymbol):
node.type = PredefinedTypes.get_boolean_type()
else:
if isinstance(lhs_type, BooleanTypeSymbol):
offending_type = lhs_type
else:
offending_type = rhs_type
code, message = Messages.get_type_different_from_expected(BooleanTypeSymbol(), offending_type)
Logger.log_message(code=code, message=message,
error_position=lhs_type.referenced_object.get_source_position(),
log_level=LoggingLevel.ERROR)
node.type = ErrorTypeSymbol()
return
开发者ID:Silmathoron,项目名称:nestml,代码行数:25,代码来源:ast_binary_logic_visitor.py
注:本文中的pynestml.symbols.predefined_types.PredefinedTypes类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论