Allow casting between string and pointer types

This commit is contained in:
Bill Currie 2020-02-19 13:00:36 +09:00
parent a6f3e1753a
commit b00c866c4e
3 changed files with 14 additions and 0 deletions

View file

@ -166,6 +166,7 @@ int is_field (const type_t *type) __attribute__((pure));
int is_struct (const type_t *type) __attribute__((pure));
int is_array (const type_t *type) __attribute__((pure));
int is_func (const type_t *type) __attribute__((pure));
int is_string (const type_t *type) __attribute__((pure));
int type_compatible (const type_t *dst, const type_t *src) __attribute__((pure));
int type_assignable (const type_t *dst, const type_t *src);
int type_size (const type_t *type) __attribute__((pure));

View file

@ -2595,6 +2595,11 @@ cast_expr (type_t *type, expr_t *e)
if ((type == type_default && is_enum (e_type))
|| (is_enum (type) && e_type == type_default))
return e;
if ((is_pointer (type) && is_string (e_type))
|| (is_string (type) && is_pointer (e_type))) {
c = new_alias_expr (type, e);
return c;
}
if (!(type->type == ev_pointer
&& (e_type->type == ev_pointer || is_integral (e_type)
|| is_array (e_type)))

View file

@ -785,6 +785,14 @@ is_func (const type_t *type)
return 0;
}
int
is_string (const type_t *type)
{
if (type->type == ev_string)
return 1;
return 0;
}
int
type_compatible (const type_t *dst, const type_t *src)
{