当前位置: 首页>>代码示例>>Python>>正文


Python PredefinedTypes.get_boolean_type方法代码示例

本文整理汇总了Python中pynestml.symbols.predefined_types.PredefinedTypes.get_boolean_type方法的典型用法代码示例。如果您正苦于以下问题:Python PredefinedTypes.get_boolean_type方法的具体用法?Python PredefinedTypes.get_boolean_type怎么用?Python PredefinedTypes.get_boolean_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pynestml.symbols.predefined_types.PredefinedTypes的用法示例。


在下文中一共展示了PredefinedTypes.get_boolean_type方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visit_expression

# 需要导入模块: from pynestml.symbols.predefined_types import PredefinedTypes [as 别名]
# 或者: from pynestml.symbols.predefined_types.PredefinedTypes import get_boolean_type [as 别名]
    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,代码行数:27,代码来源:ast_binary_logic_visitor.py

示例2: visit_declaration

# 需要导入模块: from pynestml.symbols.predefined_types import PredefinedTypes [as 别名]
# 或者: from pynestml.symbols.predefined_types.PredefinedTypes import get_boolean_type [as 别名]
 def visit_declaration(self, node):
     """
     Checks the coco for a declaration.
     :param node: a single declaration.
     :type node: ASTDeclaration
     """
     assert isinstance(node, ASTDeclaration)
     if node.has_invariant():
         invariant_type = node.get_invariant().type
         if invariant_type is None or isinstance(invariant_type, ErrorTypeSymbol):
             code, message = Messages.get_type_could_not_be_derived(str(node.get_invariant()))
             Logger.log_message(error_position=node.get_invariant().get_source_position(), code=code,
                                message=message, log_level=LoggingLevel.ERROR)
         elif not invariant_type.equals(PredefinedTypes.get_boolean_type()):
             code, message = Messages.get_type_different_from_expected(PredefinedTypes.get_boolean_type(),
                                                                       invariant_type)
             Logger.log_message(error_position=node.get_invariant().get_source_position(), code=code,
                                message=message, log_level=LoggingLevel.ERROR)
     return
开发者ID:Silmathoron,项目名称:nestml,代码行数:21,代码来源:co_co_invariant_is_boolean.py

示例3: visit_expression

# 需要导入模块: from pynestml.symbols.predefined_types import PredefinedTypes [as 别名]
# 或者: from pynestml.symbols.predefined_types.PredefinedTypes import get_boolean_type [as 别名]
    def visit_expression(self, expr):
        """
        Visits a single comparison operator expression and updates the type.
        :param expr: an expression
        :type expr: ast_expression
        """
        lhs_type = expr.get_lhs().type
        rhs_type = expr.get_rhs().type

        lhs_type.referenced_object = expr.get_lhs()
        rhs_type.referenced_object = expr.get_rhs()

        if (lhs_type.is_numeric_primitive() and rhs_type.is_numeric_primitive()) \
                or (lhs_type.equals(rhs_type) and lhs_type.is_numeric()) or (
                isinstance(lhs_type, BooleanTypeSymbol) and isinstance(rhs_type, BooleanTypeSymbol)):
            expr.type = PredefinedTypes.get_boolean_type()
            return

        # Error message for any other operation
        if (isinstance(lhs_type, UnitTypeSymbol) and rhs_type.is_numeric()) or (
                isinstance(rhs_type, UnitTypeSymbol) and lhs_type.is_numeric()):
            # if the incompatibility exists between a unit and a numeric, the c++ will still be fine, just WARN
            error_msg = ErrorStrings.message_comparison(self, expr.get_source_position())
            expr.type = PredefinedTypes.get_boolean_type()
            Logger.log_message(message=error_msg, code=MessageCode.SOFT_INCOMPATIBILITY,
                               error_position=expr.get_source_position(),
                               log_level=LoggingLevel.WARNING)
            return
        else:
            # hard incompatibility, cannot recover in c++, ERROR
            error_msg = ErrorStrings.message_comparison(self, expr.get_source_position())
            expr.type = ErrorTypeSymbol()
            Logger.log_message(code=MessageCode.HARD_INCOMPATIBILITY,
                               error_position=expr.get_source_position(),
                               message=error_msg, log_level=LoggingLevel.ERROR)
            return
开发者ID:Silmathoron,项目名称:nestml,代码行数:38,代码来源:ast_comparison_operator_visitor.py

示例4: visit_data_type

# 需要导入模块: from pynestml.symbols.predefined_types import PredefinedTypes [as 别名]
# 或者: from pynestml.symbols.predefined_types.PredefinedTypes import get_boolean_type [as 别名]
 def visit_data_type(self, node):
     """
     Visits a single data type meta_model node and updates, checks correctness and updates its type symbol.
     This visitor can also be used to derive the original name of the unit.
     :param node: a single datatype node.
     :type node: ast_data_type
     """
     if node.is_integer:
         self.symbol = PredefinedTypes.get_integer_type()
         node.set_type_symbol(self.symbol)
     elif node.is_real:
         self.symbol = PredefinedTypes.get_real_type()
         node.set_type_symbol(self.symbol)
     elif node.is_string:
         self.symbol = PredefinedTypes.get_string_type()
         node.set_type_symbol(self.symbol)
     elif node.is_boolean:
         self.symbol = PredefinedTypes.get_boolean_type()
         node.set_type_symbol(self.symbol)
     elif node.is_void:
         self.symbol = PredefinedTypes.get_void_type()
         node.set_type_symbol(self.symbol)
开发者ID:Silmathoron,项目名称:nestml,代码行数:24,代码来源:ast_data_type_visitor.py

示例5: visit_expression

# 需要导入模块: from pynestml.symbols.predefined_types import PredefinedTypes [as 别名]
# 或者: from pynestml.symbols.predefined_types.PredefinedTypes import get_boolean_type [as 别名]
    def visit_expression(self, node):
        """
        Visits an rhs consisting of the ternary operator and updates its type.
        :param node: a single rhs
        :type node: ast_expression
        """
        condition = node.get_condition().type
        if_true = node.get_if_true().type
        if_not = node.get_if_not().type

        condition.referenced_object = node.get_condition()
        if_true.referenced_object = node.get_if_true()
        if_not.referenced_object = node.get_if_not()

        # Condition must be a bool
        if not condition.equals(PredefinedTypes.get_boolean_type()):
            error_msg = ErrorStrings.message_ternary(self, node.get_source_position())
            node.type = ErrorTypeSymbol()
            Logger.log_message(message=error_msg, error_position=node.get_source_position(),
                               code=MessageCode.TYPE_DIFFERENT_FROM_EXPECTED,
                               log_level=LoggingLevel.ERROR)
            return

        # Alternatives match exactly -> any is valid
        if if_true.equals(if_not):
            node.type = if_true
            return

        # Both are units but not matching-> real WARN
        if isinstance(if_true, UnitTypeSymbol) and isinstance(if_not, UnitTypeSymbol):
            error_msg = ErrorStrings.message_ternary_mismatch(self, if_true.print_symbol(), if_not.print_symbol(),
                                                              node.get_source_position())
            node.type = PredefinedTypes.get_real_type()
            Logger.log_message(message=error_msg,
                               code=MessageCode.TYPE_DIFFERENT_FROM_EXPECTED,
                               error_position=if_true.referenced_object.get_source_position(),
                               log_level=LoggingLevel.WARNING)
            return

        # one Unit and one numeric primitive and vice versa -> assume unit, WARN
        if (isinstance(if_true, UnitTypeSymbol) and if_not.is_numeric_primitive()) or (
                isinstance(if_not, UnitTypeSymbol) and if_true.is_numeric_primitive()):
            if isinstance(if_true, UnitTypeSymbol):
                unit_type = if_true
            else:
                unit_type = if_not
            error_msg = ErrorStrings.message_ternary_mismatch(self, str(if_true), str(if_not),
                                                              node.get_source_position())
            node.type = unit_type
            Logger.log_message(message=error_msg,
                               code=MessageCode.TYPE_DIFFERENT_FROM_EXPECTED,
                               error_position=if_true.referenced_object.get_source_position(),
                               log_level=LoggingLevel.WARNING)
            return

        # both are numeric primitives (and not equal) ergo one is real and one is integer -> real
        if if_true.is_numeric_primitive() and if_not.is_numeric_primitive():
            node.type = PredefinedTypes.get_real_type()
            return

        # if we get here it is an error
        error_msg = ErrorStrings.message_ternary_mismatch(self, str(if_true), str(if_not),
                                                          node.get_source_position())
        node.type = ErrorTypeSymbol()
        Logger.log_message(message=error_msg,
                           error_position=node.get_source_position(),
                           code=MessageCode.TYPE_DIFFERENT_FROM_EXPECTED,
                           log_level=LoggingLevel.ERROR)
开发者ID:Silmathoron,项目名称:nestml,代码行数:70,代码来源:ast_condition_visitor.py


注:本文中的pynestml.symbols.predefined_types.PredefinedTypes.get_boolean_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。