Exemple #1
0
 def visit_ode_equation(self, node):
     """
     Ensures the coco.
     :param node: a single equation object.
     :type node: ast_ode_equation
     """
     symbol = node.get_scope().resolve_to_symbol(
         node.get_lhs().get_name_of_lhs(), SymbolKind.VARIABLE)
     if symbol is not None and not symbol.is_state():
         code, message = Messages.get_equation_var_not_in_state_block(
             node.get_lhs().get_name_of_lhs())
         Logger.log_message(code=code,
                            message=message,
                            error_position=node.get_source_position(),
                            log_level=LoggingLevel.ERROR)
         return
Exemple #2
0
    def handle_compound_assignment(self, node):
        rhs_expr = node.get_expression()
        lhs_variable_symbol = node.get_variable().resolve_in_own_scope()
        rhs_type_symbol = rhs_expr.type

        if lhs_variable_symbol is None:
            code, message = Messages.get_equation_var_not_in_state_block(
                node.get_variable().get_complete_name())
            Logger.log_message(code=code,
                               message=message,
                               error_position=node.get_source_position(),
                               log_level=LoggingLevel.ERROR)
            return

        if isinstance(rhs_type_symbol, ErrorTypeSymbol):
            LoggingHelper.drop_missing_type_error(node)
            return

        lhs_type_symbol = lhs_variable_symbol.get_type_symbol()

        if node.is_compound_product:
            if self.__types_do_not_match(lhs_type_symbol,
                                         lhs_type_symbol * rhs_type_symbol):
                TypeCaster.try_to_recover_or_error(
                    lhs_type_symbol, lhs_type_symbol * rhs_type_symbol,
                    node.get_expression())
                return
            return

        if node.is_compound_quotient:
            if self.__types_do_not_match(lhs_type_symbol,
                                         lhs_type_symbol / rhs_type_symbol):
                TypeCaster.try_to_recover_or_error(
                    lhs_type_symbol, lhs_type_symbol / rhs_type_symbol,
                    node.get_expression())
                return
            return

        assert node.is_compound_sum or node.is_compound_minus
        if self.__types_do_not_match(lhs_type_symbol, rhs_type_symbol):
            TypeCaster.try_to_recover_or_error(lhs_type_symbol,
                                               rhs_type_symbol,
                                               node.get_expression())