def try_to_recover_or_error(_lhs_type_symbol, _rhs_type_symbol, _containing_expression): if _rhs_type_symbol.is_castable_to(_lhs_type_symbol): if isinstance(_lhs_type_symbol, UnitTypeSymbol) \ and isinstance(_rhs_type_symbol, UnitTypeSymbol): conversion_factor = UnitTypeSymbol.get_conversion_factor( _lhs_type_symbol.astropy_unit, _rhs_type_symbol.astropy_unit) if not conversion_factor == 1.: # the units are mutually convertible, but require a factor unequal to 1 (e.g. mV and A*Ohm) TypeCaster.do_magnitude_conversion_rhs_to_lhs( _rhs_type_symbol, _lhs_type_symbol, _containing_expression) # the units are mutually convertible (e.g. V and A*Ohm) code, message = Messages.get_implicit_cast_rhs_to_lhs( _rhs_type_symbol.print_symbol(), _lhs_type_symbol.print_symbol()) Logger.log_message( error_position=_containing_expression.get_source_position(), code=code, message=message, log_level=LoggingLevel.INFO) else: code, message = Messages.get_type_different_from_expected( _lhs_type_symbol, _rhs_type_symbol) Logger.log_message( error_position=_containing_expression.get_source_position(), code=code, message=message, log_level=LoggingLevel.ERROR)
def drop_implicit_cast_warning(source_position, lhs_type_symbol, rhs_type_symbol): code, message = Messages.get_implicit_cast_rhs_to_lhs( rhs_type_symbol.print_symbol(), lhs_type_symbol.print_symbol()) Logger.log_message(error_position=source_position, code=code, message=message, log_level=LoggingLevel.WARNING)
def warn_implicit_cast_from_to(self, _from, _to): code, message = Messages.get_implicit_cast_rhs_to_lhs( _to.print_symbol(), _from.print_symbol()) Logger.log_message( code=code, message=message, error_position=self.get_referenced_object().get_source_position(), log_level=LoggingLevel.WARNING) return _to
def warn_implicit_cast_from_to(self, _from, _to): code, message = Messages.get_implicit_cast_rhs_to_lhs(_to.print_symbol(), _from.print_symbol()) Logger.log_message(code=code, message=message, error_position=self.get_referenced_object().get_source_position(), log_level=LoggingLevel.WARNING) return _to
def drop_implicit_cast_warning(source_position, lhs_type_symbol, rhs_type_symbol): code, message = Messages.get_implicit_cast_rhs_to_lhs(rhs_type_symbol.print_symbol(), lhs_type_symbol.print_symbol()) Logger.log_message(error_position=source_position, code=code, message=message, log_level=LoggingLevel.WARNING)