widl: Move declarray property to array_details.
Invert the property since an array being declared as a pointer is more surprising than an array being declared as an array. Provide an accessor, type_array_is_decl_as_ptr.
This commit is contained in:
parent
3db77ce50b
commit
7e08ff27c2
|
@ -498,7 +498,7 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc
|
|||
if (result.type && is_ptr(result.type))
|
||||
result.type = type_pointer_get_ref(result.type);
|
||||
else if(result.type && is_array(result.type)
|
||||
&& !result.type->declarray)
|
||||
&& type_array_is_decl_as_ptr(result.type))
|
||||
result.type = type_array_get_element(result.type);
|
||||
else
|
||||
error_loc_info(&expr_loc->v->loc_info, "dereference operator applied to non-pointer type in expression%s%s\n",
|
||||
|
|
|
@ -183,7 +183,7 @@ static void write_enums(FILE *h, var_list_t *enums)
|
|||
int needs_space_after(type_t *t)
|
||||
{
|
||||
return (type_is_alias(t) ||
|
||||
(!is_ptr(t) && (!is_conformant_array(t) || t->declarray || (is_array(t) && t->name))));
|
||||
(!is_ptr(t) && (!is_conformant_array(t) || !type_array_is_decl_as_ptr(t) || t->name)));
|
||||
}
|
||||
|
||||
void write_type_left(FILE *h, type_t *t, int declonly)
|
||||
|
@ -191,11 +191,10 @@ void write_type_left(FILE *h, type_t *t, int declonly)
|
|||
if (!h) return;
|
||||
|
||||
if (is_attr(t->attrs, ATTR_CONST) &&
|
||||
(type_is_alias(t) || t->declarray || !is_ptr(t)))
|
||||
(type_is_alias(t) || !is_ptr(t)))
|
||||
fprintf(h, "const ");
|
||||
|
||||
if (type_is_alias(t)) fprintf(h, "%s", t->name);
|
||||
else if (t->declarray) write_type_left(h, type_array_get_element(t), declonly);
|
||||
else {
|
||||
switch (type_get_type_detect_alias(t)) {
|
||||
case TYPE_ENUM:
|
||||
|
@ -244,12 +243,13 @@ void write_type_left(FILE *h, type_t *t, int declonly)
|
|||
if (is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const ");
|
||||
break;
|
||||
case TYPE_ARRAY:
|
||||
if (t->name)
|
||||
if (t->name && type_array_is_decl_as_ptr(t))
|
||||
fprintf(h, "%s", t->name);
|
||||
else
|
||||
{
|
||||
write_type_left(h, type_array_get_element(t), declonly);
|
||||
fprintf(h, "%s*", needs_space_after(type_array_get_element(t)) ? " " : "");
|
||||
if (type_array_is_decl_as_ptr(t))
|
||||
fprintf(h, "%s*", needs_space_after(type_array_get_element(t)) ? " " : "");
|
||||
}
|
||||
break;
|
||||
case TYPE_BASIC:
|
||||
|
@ -275,12 +275,14 @@ void write_type_right(FILE *h, type_t *t, int is_field)
|
|||
{
|
||||
if (!h) return;
|
||||
|
||||
if (t->declarray) {
|
||||
if (type_get_type(t) == TYPE_ARRAY && !type_array_is_decl_as_ptr(t)) {
|
||||
if (is_conformant_array(t)) {
|
||||
fprintf(h, "[%s]", is_field ? "1" : "");
|
||||
t = type_array_get_element(t);
|
||||
}
|
||||
for ( ; t->declarray; t = type_array_get_element(t))
|
||||
for ( ;
|
||||
type_get_type(t) == TYPE_ARRAY && !type_array_is_decl_as_ptr(t);
|
||||
t = type_array_get_element(t))
|
||||
fprintf(h, "[%u]", type_array_get_dim(t));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1294,7 +1294,6 @@ type_t *make_type(unsigned char type, type_t *ref)
|
|||
memset(&t->details, 0, sizeof(t->details));
|
||||
t->typestring_offset = 0;
|
||||
t->ptrdesc = 0;
|
||||
t->declarray = FALSE;
|
||||
t->ignore = (parse_only != 0);
|
||||
t->sign = 0;
|
||||
t->defined = FALSE;
|
||||
|
@ -1506,7 +1505,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl,
|
|||
else
|
||||
sizeless = TRUE;
|
||||
|
||||
*ptype = type_new_array(NULL, *ptype, TRUE,
|
||||
*ptype = type_new_array(NULL, *ptype, FALSE,
|
||||
dim->is_const ? dim->cval : 0,
|
||||
dim->is_const ? NULL : dim, NULL);
|
||||
}
|
||||
|
@ -1522,11 +1521,11 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl,
|
|||
error_loc("%s: cannot specify size_is for a fixed sized array\n", v->name);
|
||||
else
|
||||
*ptype = type_new_array((*ptype)->name,
|
||||
type_array_get_element(*ptype), TRUE,
|
||||
type_array_get_element(*ptype), FALSE,
|
||||
0, dim, NULL);
|
||||
}
|
||||
else if (is_ptr(*ptype))
|
||||
*ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), FALSE,
|
||||
*ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), TRUE,
|
||||
0, dim, NULL);
|
||||
else
|
||||
error_loc("%s: size_is attribute applied to illegal type\n", v->name);
|
||||
|
@ -1546,7 +1545,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl,
|
|||
{
|
||||
*ptype = type_new_array((*ptype)->name,
|
||||
type_array_get_element(*ptype),
|
||||
(*ptype)->declarray,
|
||||
type_array_is_decl_as_ptr(*ptype),
|
||||
type_array_get_dim(*ptype),
|
||||
type_array_get_conformance(*ptype),
|
||||
dim);
|
||||
|
|
|
@ -468,7 +468,7 @@ static void gen_stub(type_t *iface, const var_t *func, const char *cas,
|
|||
if (type_get_function_args(func->type))
|
||||
{
|
||||
LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), const var_t, entry )
|
||||
fprintf(proxy, ", %s__frame->%s", arg->type->declarray ? "*" : "", arg->name);
|
||||
fprintf(proxy, ", %s__frame->%s", is_array(arg->type) && !type_array_is_decl_as_ptr(arg->type) ? "*" :"" , arg->name);
|
||||
}
|
||||
fprintf(proxy, ");\n");
|
||||
fprintf(proxy, "\n");
|
||||
|
|
|
@ -185,7 +185,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
|
|||
}
|
||||
else
|
||||
{
|
||||
print_server("%s__frame->%s", var->type->declarray ? "*" : "", var->name);
|
||||
print_server("%s__frame->%s", is_array(var->type) && !type_array_is_decl_as_ptr(var->type) ? "*" : "", var->name);
|
||||
}
|
||||
}
|
||||
fprintf(server, ");\n");
|
||||
|
|
|
@ -201,7 +201,7 @@ unsigned char get_struct_fc(const type_t *type)
|
|||
|
||||
typegen_type = typegen_detect_type(t, field->attrs, TDT_IGNORE_STRINGS);
|
||||
|
||||
if (typegen_type == TGT_ARRAY && t->declarray)
|
||||
if (typegen_type == TGT_ARRAY && !type_array_is_decl_as_ptr(t))
|
||||
{
|
||||
if (is_string_type(field->attrs, field->type))
|
||||
{
|
||||
|
@ -885,7 +885,7 @@ static unsigned int write_conf_or_var_desc(FILE *file, const type_t *structure,
|
|||
return 4;
|
||||
}
|
||||
|
||||
if (is_ptr(type) || (is_array(type) && !type->declarray))
|
||||
if (is_ptr(type) || (is_array(type) && type_array_is_decl_as_ptr(type)))
|
||||
{
|
||||
conftype = RPC_FC_POINTER_CONFORMANCE;
|
||||
conftype_string = "field pointer, ";
|
||||
|
@ -1185,7 +1185,7 @@ unsigned int type_memsize(const type_t *t, unsigned int *align)
|
|||
if (size > *align) *align = size;
|
||||
break;
|
||||
case TYPE_ARRAY:
|
||||
if (t->declarray)
|
||||
if (!type_array_is_decl_as_ptr(t))
|
||||
{
|
||||
if (is_conformant_array(t))
|
||||
{
|
||||
|
@ -1478,7 +1478,8 @@ static int write_no_repeat_pointer_descriptions(
|
|||
int written = 0;
|
||||
unsigned int align;
|
||||
|
||||
if (is_ptr(type) || (!type->declarray && is_conformant_array(type)))
|
||||
if (is_ptr(type) ||
|
||||
(is_conformant_array(type) && type_array_is_decl_as_ptr(type)))
|
||||
{
|
||||
unsigned int memsize;
|
||||
|
||||
|
@ -1864,7 +1865,8 @@ static void write_pointer_description(FILE *file, type_t *type,
|
|||
|
||||
/* pass 3: search for pointers in conformant only arrays (but don't descend
|
||||
* into conformant varying or varying arrays) */
|
||||
if ((!type->declarray || !current_structure) && is_conformant_array(type))
|
||||
if (is_conformant_array(type) &&
|
||||
(type_array_is_decl_as_ptr(type) || !current_structure))
|
||||
write_conformant_array_pointer_descriptions(
|
||||
file, NULL, type, 0, typestring_offset);
|
||||
else if (type_get_type(type) == TYPE_STRUCT &&
|
||||
|
@ -1888,7 +1890,7 @@ static void write_pointer_description(FILE *file, type_t *type,
|
|||
|
||||
int is_declptr(const type_t *t)
|
||||
{
|
||||
return is_ptr(t) || (is_conformant_array(t) && !t->declarray);
|
||||
return is_ptr(t) || (type_get_type(t) == TYPE_ARRAY && type_array_is_decl_as_ptr(t));
|
||||
}
|
||||
|
||||
static unsigned int write_string_tfs(FILE *file, const attr_list_t *attrs,
|
||||
|
@ -1938,7 +1940,7 @@ static unsigned int write_string_tfs(FILE *file, const attr_list_t *attrs,
|
|||
return start_offset;
|
||||
}
|
||||
|
||||
if (type->declarray && !is_conformant_array(type))
|
||||
if (type_get_type(type) == TYPE_ARRAY && !type_array_has_conformance(type))
|
||||
{
|
||||
unsigned int dim = type_array_get_dim(type);
|
||||
|
||||
|
@ -1972,7 +1974,7 @@ static unsigned int write_string_tfs(FILE *file, const attr_list_t *attrs,
|
|||
|
||||
*typestring_offset += write_conf_or_var_desc(
|
||||
file, current_structure,
|
||||
(type->declarray && current_structure
|
||||
(!type_array_is_decl_as_ptr(type) && current_structure
|
||||
? type_memsize(current_structure, &align)
|
||||
: 0),
|
||||
type, type_array_get_conformance(type));
|
||||
|
@ -2004,7 +2006,7 @@ static unsigned int write_array_tfs(FILE *file, const attr_list_t *attrs, type_t
|
|||
int has_pointer;
|
||||
int pointer_type = get_attrv(attrs, ATTR_POINTERTYPE);
|
||||
unsigned int baseoff
|
||||
= type->declarray && current_structure
|
||||
= !type_array_is_decl_as_ptr(type) && current_structure
|
||||
? type_memsize(current_structure, &align)
|
||||
: 0;
|
||||
|
||||
|
@ -2072,7 +2074,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 (has_pointer && (!type->declarray || !current_structure))
|
||||
if (has_pointer && (type_array_is_decl_as_ptr(type) || !current_structure))
|
||||
{
|
||||
print_file(file, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP);
|
||||
print_file(file, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD);
|
||||
|
@ -2115,7 +2117,7 @@ static const var_t *find_array_or_string_in_struct(const type_t *type)
|
|||
last_field = LIST_ENTRY( list_tail(fields), const var_t, entry );
|
||||
ft = last_field->type;
|
||||
|
||||
if (ft->declarray && is_conformant_array(ft))
|
||||
if (is_conformant_array(ft) && !type_array_is_decl_as_ptr(ft))
|
||||
return last_field;
|
||||
|
||||
if (type_get_type(ft) == TYPE_STRUCT)
|
||||
|
@ -2137,7 +2139,7 @@ static void write_struct_members(FILE *file, const type_t *type,
|
|||
if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
|
||||
{
|
||||
type_t *ft = field->type;
|
||||
if (!ft->declarray || !is_conformant_array(ft))
|
||||
if (!is_conformant_array(ft) || type_array_is_decl_as_ptr(ft))
|
||||
{
|
||||
unsigned int align = 0;
|
||||
unsigned int size = type_memsize(ft, &align);
|
||||
|
@ -2282,7 +2284,7 @@ static unsigned int write_struct_tfs(FILE *file, type_t *type,
|
|||
else
|
||||
write_pointer_tfs(file, ft, tfsoff);
|
||||
}
|
||||
else if (!ft->declarray && is_conformant_array(ft))
|
||||
else if (type_get_type(ft) == TYPE_ARRAY && type_array_is_decl_as_ptr(ft))
|
||||
{
|
||||
unsigned int absoff = ft->typestring_offset;
|
||||
short reloff = absoff - (*tfsoff + 2);
|
||||
|
@ -2752,7 +2754,7 @@ static int write_embedded_types(FILE *file, const attr_list_t *attrs, type_t *ty
|
|||
}
|
||||
case TGT_ARRAY:
|
||||
/* conformant arrays and strings are handled specially */
|
||||
if (!type->declarray || !is_conformant_array(type))
|
||||
if (!is_conformant_array(type) || type_array_is_decl_as_ptr(type) )
|
||||
{
|
||||
write_array_tfs(file, attrs, type, name, tfsoff);
|
||||
if (is_conformant_array(type))
|
||||
|
@ -3695,7 +3697,8 @@ void declare_stub_args( FILE *file, int indent, const var_t *func )
|
|||
type_t *type_to_print;
|
||||
char name[16];
|
||||
print_file(file, indent, "%s", "");
|
||||
if (var->type->declarray)
|
||||
if (type_get_type(var->type) == TYPE_ARRAY &&
|
||||
!type_array_is_decl_as_ptr(var->type))
|
||||
type_to_print = var->type;
|
||||
else
|
||||
type_to_print = type_pointer_get_ref(var->type);
|
||||
|
@ -3707,7 +3710,8 @@ void declare_stub_args( FILE *file, int indent, const var_t *func )
|
|||
print_file(file, indent, "%s", "");
|
||||
write_type_decl_left(file, var->type);
|
||||
fprintf(file, " ");
|
||||
if (var->type->declarray) {
|
||||
if (type_get_type(var->type) == TYPE_ARRAY &&
|
||||
!type_array_is_decl_as_ptr(var->type)) {
|
||||
fprintf(file, "(*%s)", var->name);
|
||||
} else
|
||||
fprintf(file, "%s", var->name);
|
||||
|
|
|
@ -186,7 +186,7 @@ unsigned short get_type_vt(type_t *t)
|
|||
return VT_PTR;
|
||||
|
||||
case TYPE_ARRAY:
|
||||
if (t->declarray)
|
||||
if (!type_array_is_decl_as_ptr(t))
|
||||
error("get_type_vt: array types not supported\n");
|
||||
return VT_PTR;
|
||||
|
||||
|
|
|
@ -63,7 +63,6 @@ type_t *type_new_alias(type_t *t, const char *name)
|
|||
|
||||
a->name = xstrdup(name);
|
||||
a->attrs = NULL;
|
||||
a->declarray = FALSE;
|
||||
a->orig = t;
|
||||
a->is_alias = TRUE;
|
||||
init_loc_info(&a->loc_info);
|
||||
|
@ -79,12 +78,12 @@ type_t *type_new_module(char *name)
|
|||
return type;
|
||||
}
|
||||
|
||||
type_t *type_new_array(const char *name, type_t *element, int declarray,
|
||||
type_t *type_new_array(const char *name, type_t *element, int declptr,
|
||||
unsigned int dim, expr_t *size_is, expr_t *length_is)
|
||||
{
|
||||
type_t *t = make_type(RPC_FC_LGFARRAY, element);
|
||||
if (name) t->name = xstrdup(name);
|
||||
t->declarray = declarray;
|
||||
t->details.array.declptr = declptr;
|
||||
t->details.array.length_is = length_is;
|
||||
if (size_is)
|
||||
t->details.array.size_is = size_is;
|
||||
|
|
|
@ -28,7 +28,7 @@ type_t *type_new_function(var_list_t *args);
|
|||
type_t *type_new_pointer(type_t *ref, attr_list_t *attrs);
|
||||
type_t *type_new_alias(type_t *t, const char *name);
|
||||
type_t *type_new_module(char *name);
|
||||
type_t *type_new_array(const char *name, type_t *element, int declarray,
|
||||
type_t *type_new_array(const char *name, type_t *element, int declptr,
|
||||
unsigned int dim, expr_t *size_is, expr_t *length_is);
|
||||
void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
|
||||
void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods);
|
||||
|
@ -221,6 +221,13 @@ static inline type_t *type_array_get_element(const type_t *type)
|
|||
return type->ref;
|
||||
}
|
||||
|
||||
static inline int type_array_is_decl_as_ptr(const type_t *type)
|
||||
{
|
||||
type = type_get_real_type(type);
|
||||
assert(type_get_type(type) == TYPE_ARRAY);
|
||||
return type->details.array.declptr;
|
||||
}
|
||||
|
||||
static inline int type_is_alias(const type_t *type)
|
||||
{
|
||||
return type->is_alias;
|
||||
|
|
|
@ -293,7 +293,9 @@ struct module_details
|
|||
struct array_details
|
||||
{
|
||||
unsigned int dim;
|
||||
expr_t *size_is, *length_is;
|
||||
expr_t *size_is;
|
||||
expr_t *length_is;
|
||||
unsigned int declptr; /* if declared as a pointer */
|
||||
};
|
||||
|
||||
struct coclass_details
|
||||
|
@ -338,7 +340,6 @@ struct _type_t {
|
|||
unsigned int ptrdesc; /* used for complex structs */
|
||||
int typelib_idx;
|
||||
loc_info_t loc_info;
|
||||
unsigned int declarray : 1; /* if declared as an array */
|
||||
unsigned int ignore : 1;
|
||||
unsigned int defined : 1;
|
||||
unsigned int written : 1;
|
||||
|
|
|
@ -1068,13 +1068,15 @@ static int encode_var(
|
|||
chat("encode_var: var %p type %p type->name %s type->ref %p\n",
|
||||
var, type, type->name ? type->name : "NULL", type->ref);
|
||||
|
||||
if (type->declarray) {
|
||||
if (is_array(type) && !type_array_is_decl_as_ptr(type)) {
|
||||
int num_dims, elements = 1, arrayoffset;
|
||||
type_t *atype;
|
||||
int *arraydata;
|
||||
|
||||
num_dims = 0;
|
||||
for (atype = type; atype->declarray; atype = type_array_get_element(atype))
|
||||
for (atype = type;
|
||||
is_array(atype) && !type_array_is_decl_as_ptr(atype);
|
||||
atype = type_array_get_element(atype))
|
||||
++num_dims;
|
||||
|
||||
chat("array with %d dimensions\n", num_dims);
|
||||
|
@ -1087,7 +1089,9 @@ static int encode_var(
|
|||
arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
|
||||
|
||||
arraydata += 2;
|
||||
for (atype = type; atype->declarray; atype = type_array_get_element(atype))
|
||||
for (atype = type;
|
||||
is_array(atype) && !type_array_is_decl_as_ptr(atype);
|
||||
atype = type_array_get_element(atype))
|
||||
{
|
||||
arraydata[0] = type_array_get_dim(atype);
|
||||
arraydata[1] = 0;
|
||||
|
|
Loading…
Reference in New Issue