widl: Add a new function, type_array_get_element.

Use it whenever retrieving the element type of an array.
This commit is contained in:
Rob Shearman 2009-01-05 23:34:52 +00:00 committed by Alexandre Julliard
parent 8a42bc1f7b
commit 2b87d269e1
7 changed files with 48 additions and 36 deletions

View File

@ -549,7 +549,7 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc
if (result.type && is_array(result.type)) if (result.type && is_array(result.type))
{ {
struct expression_type index_result; struct expression_type index_result;
result.type = result.type->ref; result.type = type_array_get_element(result.type);
index_result = resolve_expression(expr_loc, cont_type /* FIXME */, e->u.ext); index_result = resolve_expression(expr_loc, cont_type /* FIXME */, e->u.ext);
if (!index_result.type || !is_integer_type(index_result.type)) 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", error_loc_info(&expr_loc->v->loc_info, "array subscript not of integral type in expression%s%s\n",

View File

@ -198,7 +198,7 @@ void write_type_left(FILE *h, type_t *t, int declonly)
fprintf(h, "const "); fprintf(h, "const ");
if (type_is_alias(t)) fprintf(h, "%s", t->name); if (type_is_alias(t)) fprintf(h, "%s", t->name);
else if (t->declarray) write_type_left(h, t->ref, declonly); else if (t->declarray) write_type_left(h, type_array_get_element(t), declonly);
else { else {
if (t->sign > 0) fprintf(h, "signed "); if (t->sign > 0) fprintf(h, "signed ");
else if (t->sign < 0) fprintf(h, "unsigned "); else if (t->sign < 0) fprintf(h, "unsigned ");
@ -253,13 +253,16 @@ void write_type_left(FILE *h, type_t *t, int declonly)
case RPC_FC_UP: case RPC_FC_UP:
case RPC_FC_FP: case RPC_FC_FP:
case RPC_FC_OP: case RPC_FC_OP:
case RPC_FC_CARRAY:
case RPC_FC_CVARRAY:
case RPC_FC_BOGUS_ARRAY:
write_type_left(h, t->ref, declonly); write_type_left(h, t->ref, declonly);
fprintf(h, "%s*", needs_space_after(t->ref) ? " " : ""); fprintf(h, "%s*", needs_space_after(t->ref) ? " " : "");
if (is_ptr(t) && is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const "); if (is_ptr(t) && is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const ");
break; break;
case RPC_FC_CARRAY:
case RPC_FC_CVARRAY:
case RPC_FC_BOGUS_ARRAY:
write_type_left(h, type_array_get_element(t), declonly);
fprintf(h, "%s*", needs_space_after(type_array_get_element(t)) ? " " : "");
break;
default: default:
fprintf(h, "%s", t->name); fprintf(h, "%s", t->name);
} }
@ -273,9 +276,9 @@ void write_type_right(FILE *h, type_t *t, int is_field)
if (t->declarray) { if (t->declarray) {
if (is_conformant_array(t)) { if (is_conformant_array(t)) {
fprintf(h, "[%s]", is_field ? "1" : ""); fprintf(h, "[%s]", is_field ? "1" : "");
t = t->ref; t = type_array_get_element(t);
} }
for ( ; t->declarray; t = t->ref) for ( ; t->declarray; t = type_array_get_element(t))
fprintf(h, "[%lu]", type_array_get_dim(t)); fprintf(h, "[%lu]", type_array_get_dim(t));
} }
} }

View File

@ -21,7 +21,7 @@
#ifndef __WIDL_HEADER_H #ifndef __WIDL_HEADER_H
#define __WIDL_HEADER_H #define __WIDL_HEADER_H
#include "widltypes.h" #include "typetree.h"
extern int is_ptrchain_attr(const var_t *var, enum attr_type t); extern int is_ptrchain_attr(const var_t *var, enum attr_type t);
extern int is_aliaschain_attr(const type_t *var, enum attr_type t); extern int is_aliaschain_attr(const type_t *var, enum attr_type t);
@ -63,7 +63,7 @@ static inline int last_ptr(const type_t *type)
static inline int last_array(const type_t *type) static inline int last_array(const type_t *type)
{ {
return is_array(type) && !is_array(type->ref); return is_array(type) && !is_array(type_array_get_element(type));
} }
static inline int is_string_type(const attr_list_t *attrs, const type_t *type) static inline int is_string_type(const attr_list_t *attrs, const type_t *type)

View File

@ -2381,8 +2381,10 @@ static void check_field_common(const type_t *container_type,
} }
if (type_is_alias(type)) if (type_is_alias(type))
type = type->orig; type = type->orig;
else if (is_ptr(type) || is_array(type)) else if (is_ptr(type))
type = type->ref; type = type->ref;
else if (is_array(type))
type = type_array_get_element(type);
else else
break; break;
} }

View File

@ -165,7 +165,7 @@ static int get_struct_type(const type_t *type)
if (type_array_has_variance(field->type)) if (type_array_has_variance(field->type))
has_variance = 1; has_variance = 1;
t = field->type->ref; t = type_array_get_element(field->type);
} }
switch (get_struct_type(t)) switch (get_struct_type(t))
@ -285,7 +285,7 @@ static int get_array_type(const type_t *type)
{ {
if (is_array(type)) if (is_array(type))
{ {
const type_t *rt = type->ref; const type_t *rt = type_array_get_element(type);
if (is_user_type(rt)) if (is_user_type(rt))
return RPC_FC_BOGUS_ARRAY; return RPC_FC_BOGUS_ARRAY;
switch (get_struct_type(rt)) switch (get_struct_type(rt))
@ -363,7 +363,7 @@ static int type_has_pointers(const type_t *type)
else if (is_ptr(type)) else if (is_ptr(type))
return TRUE; return TRUE;
else if (is_array(type)) else if (is_array(type))
return type_has_pointers(type->ref); return type_has_pointers(type_array_get_element(type));
else if (is_struct(type->type)) else if (is_struct(type->type))
{ {
var_list_t *fields = type_struct_get_fields(type); var_list_t *fields = type_struct_get_fields(type);
@ -398,7 +398,7 @@ static int type_has_full_pointer(const type_t *type)
else if (is_ptr(type)) else if (is_ptr(type))
return FALSE; return FALSE;
else if (is_array(type)) else if (is_array(type))
return type_has_full_pointer(type->ref); return type_has_full_pointer(type_array_get_element(type));
else if (is_struct(type->type)) else if (is_struct(type->type))
{ {
var_list_t *fields = type_struct_get_fields(type); var_list_t *fields = type_struct_get_fields(type);
@ -1009,7 +1009,7 @@ size_t type_memsize(const type_t *t, unsigned int *align)
size = type_memsize(t->orig, align); size = type_memsize(t->orig, align);
else if (t->declarray && is_conformant_array(t)) else if (t->declarray && is_conformant_array(t))
{ {
type_memsize(t->ref, align); type_memsize(type_array_get_element(t), align);
size = 0; size = 0;
} }
else if (is_ptr(t) || is_conformant_array(t)) else if (is_ptr(t) || is_conformant_array(t))
@ -1066,7 +1066,7 @@ size_t type_memsize(const type_t *t, unsigned int *align)
case RPC_FC_SMVARRAY: case RPC_FC_SMVARRAY:
case RPC_FC_LGVARRAY: case RPC_FC_LGVARRAY:
case RPC_FC_BOGUS_ARRAY: case RPC_FC_BOGUS_ARRAY:
size = type_array_get_dim(t) * type_memsize(t->ref, align); size = type_array_get_dim(t) * type_memsize(type_array_get_element(t), align);
break; break;
default: default:
error("type_memsize: Unknown type 0x%x\n", t->type); error("type_memsize: Unknown type 0x%x\n", t->type);
@ -1425,8 +1425,8 @@ static int write_pointer_description_offsets(
if (is_array(type)) if (is_array(type))
{ {
return write_pointer_description_offsets( return write_pointer_description_offsets(
file, attrs, type->ref, offset_in_memory, offset_in_buffer, file, attrs, type_array_get_element(type), offset_in_memory,
typestring_offset); offset_in_buffer, typestring_offset);
} }
else if (is_non_complex_struct(type)) else if (is_non_complex_struct(type))
{ {
@ -1482,7 +1482,7 @@ static int write_fixed_array_pointer_descriptions(
/* unfortunately, this needs to be done in two passes to avoid /* unfortunately, this needs to be done in two passes to avoid
* writing out redundant FC_FIXED_REPEAT descriptions */ * writing out redundant FC_FIXED_REPEAT descriptions */
pointer_count = write_pointer_description_offsets( pointer_count = write_pointer_description_offsets(
NULL, attrs, type->ref, NULL, NULL, &temp); NULL, attrs, type_array_get_element(type), NULL, NULL, &temp);
if (pointer_count > 0) if (pointer_count > 0)
{ {
unsigned int increment_size; unsigned int increment_size;
@ -1490,7 +1490,7 @@ static int write_fixed_array_pointer_descriptions(
size_t offset_of_array_pointer_buf = 0; size_t offset_of_array_pointer_buf = 0;
align = 0; align = 0;
increment_size = type_memsize(type->ref, &align); increment_size = type_memsize(type_array_get_element(type), &align);
print_file(file, 2, "0x%02x, /* FC_FIXED_REPEAT */\n", RPC_FC_FIXED_REPEAT); print_file(file, 2, "0x%02x, /* FC_FIXED_REPEAT */\n", RPC_FC_FIXED_REPEAT);
print_file(file, 2, "0x%02x, /* FC_PAD */\n", RPC_FC_PAD); print_file(file, 2, "0x%02x, /* FC_PAD */\n", RPC_FC_PAD);
@ -1556,7 +1556,7 @@ static int write_conformant_array_pointer_descriptions(
/* unfortunately, this needs to be done in two passes to avoid /* unfortunately, this needs to be done in two passes to avoid
* writing out redundant FC_VARIABLE_REPEAT descriptions */ * writing out redundant FC_VARIABLE_REPEAT descriptions */
pointer_count = write_pointer_description_offsets( pointer_count = write_pointer_description_offsets(
NULL, attrs, type->ref, NULL, NULL, &temp); NULL, attrs, type_array_get_element(type), NULL, NULL, &temp);
if (pointer_count > 0) if (pointer_count > 0)
{ {
unsigned int increment_size; unsigned int increment_size;
@ -1564,7 +1564,7 @@ static int write_conformant_array_pointer_descriptions(
size_t offset_of_array_pointer_buf = offset_in_memory; size_t offset_of_array_pointer_buf = offset_in_memory;
align = 0; align = 0;
increment_size = type_memsize(type->ref, &align); increment_size = type_memsize(type_array_get_element(type), &align);
if (increment_size > USHRT_MAX) if (increment_size > USHRT_MAX)
error("array size of %u bytes is too large\n", increment_size); error("array size of %u bytes is too large\n", increment_size);
@ -1577,8 +1577,9 @@ static int write_conformant_array_pointer_descriptions(
*typestring_offset += 8; *typestring_offset += 8;
pointer_count = write_pointer_description_offsets( pointer_count = write_pointer_description_offsets(
file, attrs, type->ref, &offset_of_array_pointer_mem, file, attrs, type_array_get_element(type),
&offset_of_array_pointer_buf, typestring_offset); &offset_of_array_pointer_mem, &offset_of_array_pointer_buf,
typestring_offset);
} }
} }
@ -1601,13 +1602,13 @@ static int write_varying_array_pointer_descriptions(
/* unfortunately, this needs to be done in two passes to avoid /* unfortunately, this needs to be done in two passes to avoid
* writing out redundant FC_VARIABLE_REPEAT descriptions */ * writing out redundant FC_VARIABLE_REPEAT descriptions */
pointer_count = write_pointer_description_offsets( pointer_count = write_pointer_description_offsets(
NULL, attrs, type->ref, NULL, NULL, &temp); NULL, attrs, type_array_get_element(type), NULL, NULL, &temp);
if (pointer_count > 0) if (pointer_count > 0)
{ {
unsigned int increment_size; unsigned int increment_size;
align = 0; align = 0;
increment_size = type_memsize(type->ref, &align); increment_size = type_memsize(type_array_get_element(type), &align);
if (increment_size > USHRT_MAX) if (increment_size > USHRT_MAX)
error("array size of %u bytes is too large\n", increment_size); error("array size of %u bytes is too large\n", increment_size);
@ -1829,13 +1830,13 @@ static size_t write_array_tfs(FILE *file, const attr_list_t *attrs, type_t *type
if (!pointer_type) if (!pointer_type)
pointer_type = RPC_FC_RP; pointer_type = RPC_FC_RP;
if (write_embedded_types(file, attrs, type->ref, name, FALSE, typestring_offset)) if (write_embedded_types(file, attrs, type_array_get_element(type), name, FALSE, typestring_offset))
has_pointer = TRUE; has_pointer = TRUE;
else else
has_pointer = type_has_pointers(type->ref); has_pointer = type_has_pointers(type_array_get_element(type));
align = 0; align = 0;
size = type_memsize((is_conformant_array(type) ? type->ref : type), &align); size = type_memsize((is_conformant_array(type) ? type_array_get_element(type) : type), &align);
real_type = get_array_type( type ); real_type = get_array_type( type );
start_offset = *typestring_offset; start_offset = *typestring_offset;
@ -1867,7 +1868,7 @@ static size_t write_array_tfs(FILE *file, const attr_list_t *attrs, type_t *type
if (real_type == RPC_FC_SMVARRAY || real_type == RPC_FC_LGVARRAY) if (real_type == RPC_FC_SMVARRAY || real_type == RPC_FC_LGVARRAY)
{ {
unsigned int elalign = 0; unsigned int elalign = 0;
size_t elsize = type_memsize(type->ref, &elalign); size_t elsize = type_memsize(type_array_get_element(type), &elalign);
unsigned long dim = type_array_get_dim(type); unsigned long dim = type_array_get_dim(type);
if (real_type == RPC_FC_LGVARRAY) if (real_type == RPC_FC_LGVARRAY)
@ -1900,7 +1901,7 @@ static size_t write_array_tfs(FILE *file, const attr_list_t *attrs, type_t *type
*typestring_offset += 1; *typestring_offset += 1;
} }
write_member_type(file, type, NULL, type->ref, NULL, typestring_offset); write_member_type(file, type, NULL, type_array_get_element(type), NULL, typestring_offset);
write_end(file, typestring_offset); write_end(file, typestring_offset);
} }
else else
@ -1914,7 +1915,7 @@ static size_t write_array_tfs(FILE *file, const attr_list_t *attrs, type_t *type
*typestring_offset *typestring_offset
+= write_conf_or_var_desc(file, current_structure, baseoff, += write_conf_or_var_desc(file, current_structure, baseoff,
type, length_is); type, length_is);
write_member_type(file, type, NULL, type->ref, NULL, typestring_offset); write_member_type(file, type, NULL, type_array_get_element(type), NULL, typestring_offset);
write_end(file, typestring_offset); write_end(file, typestring_offset);
} }
@ -2920,7 +2921,7 @@ expr_t *get_size_is_expr(const type_t *t, const char *name)
{ {
expr_t *x = NULL; expr_t *x = NULL;
for ( ; is_array(t); t = t->ref) for ( ; is_array(t); t = type_array_get_element(t))
if (type_array_has_conformance(t)) if (type_array_has_conformance(t))
{ {
if (!x) if (!x)
@ -3370,7 +3371,7 @@ void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char
fprintf(file, " = NdrAllocate(&__frame->_StubMsg, "); fprintf(file, " = NdrAllocate(&__frame->_StubMsg, ");
for ( ; for ( ;
is_array(type) && type_array_has_conformance(type); is_array(type) && type_array_has_conformance(type);
type = type->ref) type = type_array_get_element(type))
{ {
write_expr(file, type_array_get_conformance(type), TRUE, write_expr(file, type_array_get_conformance(type), TRUE,
TRUE, NULL, NULL, local_var_prefix); TRUE, NULL, NULL, local_var_prefix);

View File

@ -141,6 +141,12 @@ static inline expr_t *type_array_get_variance(const type_t *type)
return type->details.array.length_is; return type->details.array.length_is;
} }
static inline type_t *type_array_get_element(const type_t *type)
{
assert(is_array(type));
return type->ref;
}
static inline type_t *type_get_real_type(const type_t *type) static inline type_t *type_get_real_type(const type_t *type)
{ {
if (type->is_alias) if (type->is_alias)

View File

@ -1080,7 +1080,7 @@ static int encode_var(
int *arraydata; int *arraydata;
num_dims = 0; num_dims = 0;
for (atype = type; atype->declarray; atype = atype->ref) for (atype = type; atype->declarray; atype = type_array_get_element(atype))
++num_dims; ++num_dims;
chat("array with %d dimensions\n", num_dims); chat("array with %d dimensions\n", num_dims);
@ -1093,7 +1093,7 @@ static int encode_var(
arraydata[1] |= ((num_dims * 2 * sizeof(long)) << 16); arraydata[1] |= ((num_dims * 2 * sizeof(long)) << 16);
arraydata += 2; arraydata += 2;
for (atype = type; atype->declarray; atype = atype->ref) for (atype = type; atype->declarray; atype = type_array_get_element(atype))
{ {
arraydata[0] = type_array_get_dim(atype); arraydata[0] = type_array_get_dim(atype);
arraydata[1] = 0; arraydata[1] = 0;