X-Git-Url: https://deadsoftware.ru/gitweb?p=dsw-obn.git;a=blobdiff_plain;f=src%2Foberon-type-compat.c;h=3da62edc2bb5b059b7ee20b90f20c238400de495;hp=4291f6c5f402d97b9e5c859056dd107099b31895;hb=ba1a55241f3841d1254317d76d45322c85fb687b;hpb=b18a306febda9b321fadd6c828fb7abc392b40c4 diff --git a/src/oberon-type-compat.c b/src/oberon-type-compat.c index 4291f6c..3da62ed 100644 --- a/src/oberon-type-compat.c +++ b/src/oberon-type-compat.c @@ -281,6 +281,12 @@ oberon_is_const_string(oberon_expr_t * e) return e -> result -> class == OBERON_TYPE_STRING && e -> is_item && e -> item.mode == MODE_STRING; } +bool +oberon_is_string_of_one(oberon_expr_t * e) +{ + return oberon_is_const_string(e) && strlen(e -> item.string) == 1; +} + bool oberon_is_assignment_compatible_expressions(oberon_expr_t * e, oberon_type_t * Tv) { @@ -308,7 +314,7 @@ oberon_is_assignment_compatible_expressions(oberon_expr_t * e, oberon_type_t * T || ((oberon_is_pointer_type(Tv) || oberon_is_procedure_type(Tv)) && oberon_is_nil_type(Te)) || (oberon_is_array_of_char_type(Tv) && !oberon_is_open_array(Tv) && oberon_is_const_string(e) && (strlen(e -> item.string) < Tv -> size)) || (oberon_is_procedure_type(Tv) && e -> is_item && e -> item.var -> class == OBERON_CLASS_PROC && oberon_is_some_procedure_signatures(Tv, e -> result)) - || (oberon_is_char_type(Tv) && oberon_is_const_string(e) && strlen(e -> item.string) == 1) + || (oberon_is_char_type(Tv) && oberon_is_string_of_one(e)) || (oberon_is_system_byte_type(Tv) && (oberon_is_char_type(Te) || oberon_is_byte_type(Te))) || (oberon_is_system_ptr_type(Tv) && oberon_is_pointer_type(Te)); } @@ -344,6 +350,27 @@ oberon_check_compatible_arrays(oberon_context_t * ctx, oberon_object_t * f, ober } } +bool +oberon_is_compatible_bin_expr(int token, oberon_expr_t * a, oberon_expr_t * b) +{ + if(token == EQUAL || token == NEQ || token == LESS || token == LEQ || token == GREAT || token == GEQ) + { + if((oberon_is_char_type(a -> result) || oberon_is_string_of_one(a)) + && (oberon_is_char_type(b -> result) || oberon_is_string_of_one(b))) + { + return true; + } + else + { + return oberon_is_compatible_bin_expr_types(token, a -> result, b -> result); + } + } + else + { + return oberon_is_compatible_bin_expr_types(token, a -> result, b -> result); + } +} + bool oberon_is_compatible_bin_expr_types(int token, oberon_type_t * a, oberon_type_t * b) { @@ -473,9 +500,9 @@ oberon_check_type_expr(oberon_context_t * ctx, oberon_expr_t * e) } void -oberon_check_compatible_bin_expr_types(oberon_context_t * ctx, int token, oberon_type_t * a, oberon_type_t * b) +oberon_check_compatible_bin_expr(oberon_context_t * ctx, int token, oberon_expr_t * a, oberon_expr_t * b) { - if(!oberon_is_compatible_bin_expr_types(token, a, b)) + if(!oberon_is_compatible_bin_expr(token, a, b)) { oberon_error(ctx, "incompatibe expression types"); }