widl: Refactor to have array type's element use decl_spec_t rather than type_t.

Signed-off-by: Richard Pospesel <richard@torproject.org>
Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Richard Pospesel 2019-07-05 14:51:31 -07:00 committed by Alexandre Julliard
parent 1ffb6494db
commit c7d68454af
10 changed files with 62 additions and 57 deletions

View File

@ -583,7 +583,7 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc
result.type = type_pointer_get_ref(result.type);
else if(result.type && is_array(result.type)
&& type_array_is_decl_as_ptr(result.type))
result.type = type_array_get_element(result.type);
result.type = type_array_get_element_type(result.type);
else
error_loc_info(&expr_loc->v->loc_info, "dereference operator applied to non-pointer type in expression%s%s\n",
expr_loc->attr ? " for attribute " : "",
@ -665,7 +665,7 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc
if (result.type && is_array(result.type))
{
struct expression_type index_result;
result.type = type_array_get_element(result.type);
result.type = type_array_get_element_type(result.type);
index_result = resolve_expression(expr_loc, cont_type /* FIXME */, e->u.ext);
if (!index_result.type || !is_integer_type(index_result.type))
error_loc_info(&expr_loc->v->loc_info, "array subscript not of integral type in expression%s%s\n",

View File

@ -361,9 +361,9 @@ void write_type_left(FILE *h, type_t *t, enum name_type name_type, int declonly)
fprintf(h, "%s", t->name);
else
{
write_type_left(h, type_array_get_element(t), name_type, declonly);
write_type_left(h, type_array_get_element_type(t), name_type, declonly);
if (type_array_is_decl_as_ptr(t))
write_pointer_left(h, type_array_get_element(t));
write_pointer_left(h, type_array_get_element_type(t));
}
break;
case TYPE_BASIC:
@ -443,7 +443,7 @@ void write_type_right(FILE *h, type_t *t, int is_field)
{
case TYPE_ARRAY:
{
type_t *elem = type_array_get_element(t);
type_t *elem = type_array_get_element_type(t);
if (type_array_is_decl_as_ptr(t))
{
if (!type_is_alias(elem) && is_array(elem) && !type_array_is_decl_as_ptr(elem))
@ -705,7 +705,7 @@ void check_for_additional_prototype_types(type_t *type)
else if (is_ptr(type))
type = type_pointer_get_ref(type);
else if (is_array(type))
type = type_array_get_element(type);
type = type_array_get_element_type(type);
else
break;
}

View File

@ -88,7 +88,7 @@ static inline int last_ptr(const type_t *type)
static inline int last_array(const type_t *type)
{
return is_array(type) && !is_array(type_array_get_element(type));
return is_array(type) && !is_array(type_array_get_element_type(type));
}
static inline int is_string_type(const attr_list_t *attrs, const type_t *type)

View File

@ -1469,7 +1469,7 @@ static type_t *get_array_or_ptr_ref(type_t *type)
if (is_ptr(type))
return type_pointer_get_ref(type);
else if (is_array(type))
return type_array_get_element(type);
return type_array_get_element_type(type);
return NULL;
}
@ -1485,7 +1485,7 @@ static type_t *append_chain_type(type_t *chain, type_t *type)
if (is_ptr(chain_type))
chain_type->details.pointer.ref = type;
else if (is_array(chain_type))
chain_type->details.array.elem = type;
chain_type->details.array.elem.type = type;
else
assert(0);
@ -1587,7 +1587,7 @@ static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const decl
if (is_ptr(t))
t = type_pointer_get_ref(t);
else if (is_array(t))
t = type_array_get_element(t);
t = type_array_get_element_type(t);
else
break;
}
@ -1624,7 +1624,7 @@ static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const decl
error_loc("%s: cannot specify size_is for an already sized array\n", v->name);
else
*ptype = type_new_array((*ptype)->name,
type_array_get_element(*ptype), FALSE,
type_array_get_element_type(*ptype), FALSE,
0, dim, NULL, FC_RP);
}
else if (is_ptr(*ptype))
@ -1637,7 +1637,7 @@ static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const decl
if (is_ptr(*ptype))
ptype = &(*ptype)->details.pointer.ref;
else if (is_array(*ptype))
ptype = &(*ptype)->details.array.elem;
ptype = &(*ptype)->details.array.elem.type;
else
error_loc("%s: too many expressions in size_is attribute\n", v->name);
}
@ -1650,7 +1650,7 @@ static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const decl
if (is_array(*ptype))
{
*ptype = type_new_array((*ptype)->name,
type_array_get_element(*ptype),
type_array_get_element_type(*ptype),
type_array_is_decl_as_ptr(*ptype),
type_array_get_dim(*ptype),
type_array_get_conformance(*ptype),
@ -1663,7 +1663,7 @@ static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const decl
if (is_ptr(*ptype))
ptype = &(*ptype)->details.pointer.ref;
else if (is_array(*ptype))
ptype = &(*ptype)->details.array.elem;
ptype = &(*ptype)->details.array.elem.type;
else
error_loc("%s: too many expressions in length_is attribute\n", v->name);
}
@ -2648,7 +2648,7 @@ static void check_field_common(const type_t *container_type,
more_to_do = TRUE;
break;
case TGT_ARRAY:
type = type_array_get_element(type);
type = type_array_get_element_type(type);
more_to_do = TRUE;
break;
case TGT_USER_TYPE:

View File

@ -510,7 +510,7 @@ unsigned char get_struct_fc(const type_t *type)
continue;
}
if (is_array(type_array_get_element(field->declspec.type)))
if (is_array(type_array_get_element_type(field->declspec.type)))
return FC_BOGUS_STRUCT;
if (type_array_has_conformance(field->declspec.type))
@ -523,7 +523,7 @@ unsigned char get_struct_fc(const type_t *type)
if (type_array_has_variance(t))
has_variance = 1;
t = type_array_get_element(t);
t = type_array_get_element_type(t);
typegen_type = typegen_detect_type(t, field->attrs, TDT_IGNORE_STRINGS);
}
@ -625,7 +625,7 @@ static unsigned char get_array_fc(const type_t *type)
const expr_t *size_is;
const type_t *elem_type;
elem_type = type_array_get_element(type);
elem_type = type_array_get_element_type(type);
size_is = type_array_get_conformance(type);
if (!size_is)
@ -714,7 +714,7 @@ static int type_has_pointers(const type_t *type)
case TGT_POINTER:
return TRUE;
case TGT_ARRAY:
return type_array_is_decl_as_ptr(type) || type_has_pointers(type_array_get_element(type));
return type_array_is_decl_as_ptr(type) || type_has_pointers(type_array_get_element_type(type));
case TGT_STRUCT:
{
var_list_t *fields = type_struct_get_fields(type);
@ -768,7 +768,7 @@ static int type_has_full_pointer(const type_t *type, const attr_list_t *attrs,
if (get_pointer_fc(type, attrs, toplevel_param) == FC_FP)
return TRUE;
else
return type_has_full_pointer(type_array_get_element(type), NULL, FALSE);
return type_has_full_pointer(type_array_get_element_type(type), NULL, FALSE);
case TGT_STRUCT:
{
var_list_t *fields = type_struct_get_fields(type);
@ -1944,12 +1944,12 @@ unsigned int type_memsize_and_alignment(const type_t *t, unsigned int *align)
{
if (is_conformant_array(t))
{
type_memsize_and_alignment(type_array_get_element(t), align);
type_memsize_and_alignment(type_array_get_element_type(t), align);
size = 0;
}
else
size = type_array_get_dim(t) *
type_memsize_and_alignment(type_array_get_element(t), align);
type_memsize_and_alignment(type_array_get_element_type(t), align);
}
else /* declared as a pointer */
{
@ -2054,7 +2054,7 @@ static unsigned int type_buffer_alignment(const type_t *t)
break;
case TYPE_ARRAY:
if (!type_array_is_decl_as_ptr(t))
return type_buffer_alignment( type_array_get_element(t) );
return type_buffer_alignment( type_array_get_element_type(t) );
/* else fall through */
case TYPE_POINTER:
return 4;
@ -2378,7 +2378,7 @@ static void write_member_type(FILE *file, const type_t *cont,
static void write_array_element_type(FILE *file, const attr_list_t *attrs, const type_t *type,
int cont_is_complex, unsigned int *tfsoff)
{
type_t *elem = type_array_get_element(type);
type_t *elem = type_array_get_element_type(type);
if (!is_embedded_complex(elem) && is_ptr(elem))
{
@ -2506,7 +2506,7 @@ static int write_pointer_description_offsets(
if (is_array(type))
{
return write_pointer_description_offsets(
file, attrs, type_array_get_element(type), offset_in_memory,
file, attrs, type_array_get_element_type(type), offset_in_memory,
offset_in_buffer, typestring_offset);
}
else if (is_non_complex_struct(type))
@ -2609,14 +2609,14 @@ static int write_fixed_array_pointer_descriptions(
/* unfortunately, this needs to be done in two passes to avoid
* writing out redundant FC_FIXED_REPEAT descriptions */
pointer_count = write_pointer_description_offsets(
NULL, attrs, type_array_get_element(type), NULL, NULL, &temp);
NULL, attrs, type_array_get_element_type(type), NULL, NULL, &temp);
if (pointer_count > 0)
{
unsigned int increment_size;
unsigned int offset_of_array_pointer_mem = 0;
unsigned int offset_of_array_pointer_buf = 0;
increment_size = type_memsize(type_array_get_element(type));
increment_size = type_memsize(type_array_get_element_type(type));
print_file(file, 2, "0x%02x, /* FC_FIXED_REPEAT */\n", FC_FIXED_REPEAT);
print_file(file, 2, "0x%02x, /* FC_PAD */\n", FC_PAD);
@ -2680,14 +2680,14 @@ static int write_conformant_array_pointer_descriptions(
/* unfortunately, this needs to be done in two passes to avoid
* writing out redundant FC_VARIABLE_REPEAT descriptions */
pointer_count = write_pointer_description_offsets(
NULL, attrs, type_array_get_element(type), NULL, NULL, &temp);
NULL, attrs, type_array_get_element_type(type), NULL, NULL, &temp);
if (pointer_count > 0)
{
unsigned int increment_size;
unsigned int offset_of_array_pointer_mem = offset_in_memory;
unsigned int offset_of_array_pointer_buf = offset_in_memory;
increment_size = type_memsize(type_array_get_element(type));
increment_size = type_memsize(type_array_get_element_type(type));
if (increment_size > USHRT_MAX)
error("array size of %u bytes is too large\n", increment_size);
@ -2700,7 +2700,7 @@ static int write_conformant_array_pointer_descriptions(
*typestring_offset += 8;
pointer_count = write_pointer_description_offsets(
file, attrs, type_array_get_element(type),
file, attrs, type_array_get_element_type(type),
&offset_of_array_pointer_mem, &offset_of_array_pointer_buf,
typestring_offset);
}
@ -2724,12 +2724,12 @@ static int write_varying_array_pointer_descriptions(
/* unfortunately, this needs to be done in two passes to avoid
* writing out redundant FC_VARIABLE_REPEAT descriptions */
pointer_count = write_pointer_description_offsets(
NULL, attrs, type_array_get_element(type), NULL, NULL, &temp);
NULL, attrs, type_array_get_element_type(type), NULL, NULL, &temp);
if (pointer_count > 0)
{
unsigned int increment_size;
increment_size = type_memsize(type_array_get_element(type));
increment_size = type_memsize(type_array_get_element_type(type));
if (increment_size > USHRT_MAX)
error("array size of %u bytes is too large\n", increment_size);
@ -2742,7 +2742,7 @@ static int write_varying_array_pointer_descriptions(
*typestring_offset += 8;
pointer_count = write_pointer_description_offsets(
file, attrs, type_array_get_element(type), offset_in_memory,
file, attrs, type_array_get_element_type(type), offset_in_memory,
offset_in_buffer, typestring_offset);
}
}
@ -2864,7 +2864,7 @@ static unsigned int write_string_tfs(FILE *file, const attr_list_t *attrs,
}
if (is_array(type))
elem_type = type_array_get_element(type);
elem_type = type_array_get_element_type(type);
else
elem_type = type_pointer_get_ref(type);
@ -2957,11 +2957,11 @@ static unsigned int write_array_tfs(FILE *file, const attr_list_t *attrs, type_t
? type_memsize(current_structure)
: 0;
if (!is_string_type(attrs, type_array_get_element(type)))
write_embedded_types(file, attrs, type_array_get_element(type), name, FALSE, typestring_offset);
if (!is_string_type(attrs, type_array_get_element_type(type)))
write_embedded_types(file, attrs, type_array_get_element_type(type), name, FALSE, typestring_offset);
size = type_memsize(is_conformant_array(type) ? type_array_get_element(type) : type);
align = type_buffer_alignment(is_conformant_array(type) ? type_array_get_element(type) : type);
size = type_memsize(is_conformant_array(type) ? type_array_get_element_type(type) : type);
align = type_buffer_alignment(is_conformant_array(type) ? type_array_get_element_type(type) : type);
fc = get_array_fc(type);
start_offset = *typestring_offset;
@ -2992,7 +2992,7 @@ static unsigned int write_array_tfs(FILE *file, const attr_list_t *attrs, type_t
if (fc == FC_SMVARRAY || fc == FC_LGVARRAY)
{
unsigned int elsize = type_memsize(type_array_get_element(type));
unsigned int elsize = type_memsize(type_array_get_element_type(type));
unsigned int dim = type_array_get_dim(type);
if (fc == FC_LGVARRAY)
@ -3015,7 +3015,7 @@ static unsigned int write_array_tfs(FILE *file, const attr_list_t *attrs, type_t
+= write_conf_or_var_desc(file, current_structure, baseoff,
type, length_is);
if (type_has_pointers(type_array_get_element(type)) &&
if (type_has_pointers(type_array_get_element_type(type)) &&
(type_array_is_decl_as_ptr(type) || !current_structure))
{
print_file(file, 2, "0x%x,\t/* FC_PP */\n", FC_PP);
@ -3868,7 +3868,7 @@ static unsigned int get_required_buffer_size_type(
case FC_SMFARRAY:
case FC_LGFARRAY:
return type_array_get_dim(type) *
get_required_buffer_size_type(type_array_get_element(type), name,
get_required_buffer_size_type(type_array_get_element_type(type), name,
NULL, FALSE, alignment);
}
}
@ -4098,7 +4098,7 @@ expr_t *get_size_is_expr(const type_t *t, const char *name)
{
expr_t *x = NULL;
for ( ; is_array(t); t = type_array_get_element(t))
for ( ; is_array(t); t = type_array_get_element_type(t))
if (type_array_has_conformance(t) &&
type_array_get_conformance(t)->type != EXPR_VOID)
{
@ -4704,7 +4704,7 @@ void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char
fprintf(file, " = NdrAllocate(&__frame->_StubMsg, ");
for (type = var->declspec.type;
is_array(type) && type_array_has_conformance(type);
type = type_array_get_element(type))
type = type_array_get_element_type(type))
{
write_expr(file, type_array_get_conformance(type), TRUE,
TRUE, NULL, NULL, local_var_prefix);
@ -4716,7 +4716,7 @@ void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char
print_file(file, indent, "memset(%s%s, 0, ", local_var_prefix, var->name);
for (type = var->declspec.type;
is_array(type) && type_array_has_conformance(type);
type = type_array_get_element(type))
type = type_array_get_element_type(type))
{
write_expr(file, type_array_get_conformance(type), TRUE,
TRUE, NULL, NULL, local_var_prefix);
@ -4750,7 +4750,7 @@ void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char
print_file(file, indent, "%s_W%u = 0;\n", local_var_prefix, i);
break;
}
ref = type_array_get_element(ref);
ref = type_array_get_element_type(ref);
/* fall through */
case TGT_STRUCT:
case TGT_UNION:

View File

@ -97,7 +97,7 @@ static unsigned short builtin_vt(const type_t *t)
{
const type_t *elem_type;
if (is_array(t))
elem_type = type_array_get_element(t);
elem_type = type_array_get_element_type(t);
else
elem_type = type_pointer_get_ref(t);
if (type_get_type(elem_type) == TYPE_BASIC)
@ -198,7 +198,7 @@ unsigned short get_type_vt(type_t *t)
case TYPE_ARRAY:
if (type_array_is_decl_as_ptr(t))
{
if (match(type_array_get_element(t)->name, "SAFEARRAY"))
if (match(type_array_get_element_type(t)->name, "SAFEARRAY"))
return VT_SAFEARRAY;
return VT_PTR;
}

View File

@ -235,7 +235,7 @@ type_t *type_new_array(const char *name, type_t *element, int declptr,
t->details.array.size_is = size_is;
else
t->details.array.dim = dim;
t->details.array.elem = element;
t->details.array.elem.type = element;
t->details.array.ptr_def_fc = ptr_default_fc;
return t;
}

View File

@ -250,11 +250,16 @@ static inline expr_t *type_array_get_variance(const type_t *type)
return type->details.array.length_is;
}
static inline type_t *type_array_get_element(const type_t *type)
static inline const decl_spec_t *type_array_get_element(const type_t *type)
{
type = type_get_real_type(type);
assert(type_get_type(type) == TYPE_ARRAY);
return type->details.array.elem;
return &type->details.array.elem;
}
static inline type_t *type_array_get_element_type(const type_t *type)
{
return type_array_get_element(type)->type;
}
static inline int type_array_is_decl_as_ptr(const type_t *type)

View File

@ -364,7 +364,7 @@ struct array_details
{
expr_t *size_is;
expr_t *length_is;
struct _type_t *elem;
struct _decl_spec_t elem;
unsigned int dim;
unsigned char ptr_def_fc;
unsigned char declptr; /* if declared as a pointer */

View File

@ -912,10 +912,10 @@ static int encode_type(
case VT_SAFEARRAY:
{
type_t *element_type = type_alias_get_aliasee(type_array_get_element(type));
type_t *element_type = type_alias_get_aliasee(type_array_get_element_type(type));
int next_vt = get_type_vt(element_type);
encode_type(typelib, next_vt, type_alias_get_aliasee(type_array_get_element(type)),
encode_type(typelib, next_vt, type_alias_get_aliasee(type_array_get_element_type(type)),
&target_type, &child_size);
for (typeoffset = 0; typeoffset < typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
@ -1056,7 +1056,7 @@ static int encode_var(
num_dims = 0;
for (atype = type;
is_array(atype) && !type_array_is_decl_as_ptr(atype);
atype = type_array_get_element(atype))
atype = type_array_get_element_type(atype))
++num_dims;
chat("array with %d dimensions\n", num_dims);
@ -1071,7 +1071,7 @@ static int encode_var(
arraydata += 2;
for (atype = type;
is_array(atype) && !type_array_is_decl_as_ptr(atype);
atype = type_array_get_element(atype))
atype = type_array_get_element_type(atype))
{
arraydata[0] = type_array_get_dim(atype);
arraydata[1] = 0;
@ -1093,7 +1093,7 @@ static int encode_var(
vt = get_type_vt(type);
if (vt == VT_PTR) {
type_t *ref = is_ptr(type) ?
type_pointer_get_ref(type) : type_array_get_element(type);
type_pointer_get_ref(type) : type_array_get_element_type(type);
int skip_ptr = encode_var(typelib, ref, var, &target_type, &child_size);
if(skip_ptr == 2) {
@ -1114,7 +1114,7 @@ static int encode_var(
if (target_type & 0x80000000) {
mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
} else if (get_type_vt(ref) == VT_SAFEARRAY) {
type_t *element_type = type_alias_get_aliasee(type_array_get_element(ref));
type_t *element_type = type_alias_get_aliasee(type_array_get_element_type(ref));
mix_field = get_type_vt(element_type) | VT_ARRAY | VT_BYREF;
} else {
typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];