Commit 67ac03ae authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

widl: Add a new function, type_pointer_get_ref.

Use it for retrieving the type that a pointer refers to.
parent 2b87d269
...@@ -469,7 +469,7 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc ...@@ -469,7 +469,7 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc
case EXPR_PPTR: case EXPR_PPTR:
result = resolve_expression(expr_loc, cont_type, e->ref); result = resolve_expression(expr_loc, cont_type, e->ref);
if (result.type && is_ptr(result.type)) if (result.type && is_ptr(result.type))
result.type = result.type->ref; result.type = type_pointer_get_ref(result.type);
else else
error_loc_info(&expr_loc->v->loc_info, "dereference operator applied to non-pointer type in expression%s%s\n", 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 " : "", expr_loc->attr ? " for attribute " : "",
......
...@@ -65,7 +65,7 @@ int is_ptrchain_attr(const var_t *var, enum attr_type t) ...@@ -65,7 +65,7 @@ int is_ptrchain_attr(const var_t *var, enum attr_type t)
else if (type_is_alias(type)) else if (type_is_alias(type))
type = type->orig; type = type->orig;
else if (is_ptr(type)) else if (is_ptr(type))
type = type->ref; type = type_pointer_get_ref(type);
else return 0; else return 0;
} }
} }
...@@ -253,9 +253,9 @@ void write_type_left(FILE *h, type_t *t, int declonly) ...@@ -253,9 +253,9 @@ 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:
write_type_left(h, t->ref, declonly); write_type_left(h, type_pointer_get_ref(t), declonly);
fprintf(h, "%s*", needs_space_after(t->ref) ? " " : ""); fprintf(h, "%s*", needs_space_after(type_pointer_get_ref(t)) ? " " : "");
if (is_ptr(t) && is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const "); if (is_attr(t->attrs, ATTR_CONST)) fprintf(h, "const ");
break; break;
case RPC_FC_CARRAY: case RPC_FC_CARRAY:
case RPC_FC_CVARRAY: case RPC_FC_CVARRAY:
...@@ -291,7 +291,7 @@ void write_type_v(FILE *h, type_t *t, int is_field, int declonly, ...@@ -291,7 +291,7 @@ void write_type_v(FILE *h, type_t *t, int is_field, int declonly,
if (!h) return; if (!h) return;
for (pt = t; is_ptr(pt); pt = pt->ref, ptr_level++) for (pt = t; is_ptr(pt); pt = type_pointer_get_ref(pt), ptr_level++)
; ;
if (pt->type == RPC_FC_FUNCTION) { if (pt->type == RPC_FC_FUNCTION) {
...@@ -378,10 +378,11 @@ void check_for_additional_prototype_types(const var_list_t *list) ...@@ -378,10 +378,11 @@ void check_for_additional_prototype_types(const var_list_t *list)
if (!list) return; if (!list) return;
LIST_FOR_EACH_ENTRY( v, list, const var_t, entry ) LIST_FOR_EACH_ENTRY( v, list, const var_t, entry )
{ {
type_t *type; type_t *type = v->type;
for (type = v->type; type; type = type_is_alias(type) ? type->orig : type->ref) { if (!type) continue;
for (;;) {
const char *name = type->name; const char *name = type->name;
if (type->user_types_registered) continue; if (type->user_types_registered) break;
type->user_types_registered = 1; type->user_types_registered = 1;
if (is_attr(type->attrs, ATTR_CONTEXTHANDLE)) { if (is_attr(type->attrs, ATTR_CONTEXTHANDLE)) {
if (!context_handle_registered(name)) if (!context_handle_registered(name))
...@@ -425,6 +426,15 @@ void check_for_additional_prototype_types(const var_list_t *list) ...@@ -425,6 +426,15 @@ void check_for_additional_prototype_types(const var_list_t *list)
vars = type_union_get_cases(type); vars = type_union_get_cases(type);
check_for_additional_prototype_types(vars); check_for_additional_prototype_types(vars);
} }
if (type_is_alias(type))
type = type->orig;
else if (is_ptr(type))
type = type_pointer_get_ref(type);
else if (is_array(type))
type = type_array_get_element(type);
else
break;
} }
} }
} }
...@@ -482,7 +492,7 @@ int is_const_decl(const var_t *var) ...@@ -482,7 +492,7 @@ int is_const_decl(const var_t *var)
if (is_attr(t->attrs, ATTR_CONST)) if (is_attr(t->attrs, ATTR_CONST))
return TRUE; return TRUE;
else if (is_ptr(t)) else if (is_ptr(t))
t = t->ref; t = type_pointer_get_ref(t);
else break; else break;
} }
return FALSE; return FALSE;
...@@ -541,7 +551,7 @@ const var_t* get_explicit_handle_var(const var_t *func) ...@@ -541,7 +551,7 @@ const var_t* get_explicit_handle_var(const var_t *func)
const type_t* get_explicit_generic_handle_type(const var_t* var) const type_t* get_explicit_generic_handle_type(const var_t* var)
{ {
const type_t *t; const type_t *t;
for (t = var->type; is_ptr(t); t = t->ref) for (t = var->type; is_ptr(t); t = type_pointer_get_ref(t))
if (t->type != RPC_FC_BIND_PRIMITIVE && is_attr(t->attrs, ATTR_HANDLE)) if (t->type != RPC_FC_BIND_PRIMITIVE && is_attr(t->attrs, ATTR_HANDLE))
return t; return t;
return NULL; return NULL;
......
...@@ -58,7 +58,7 @@ extern int is_const_decl(const var_t *var); ...@@ -58,7 +58,7 @@ extern int is_const_decl(const var_t *var);
static inline int last_ptr(const type_t *type) static inline int last_ptr(const type_t *type)
{ {
return is_ptr(type) && !is_declptr(type->ref); return is_ptr(type) && !is_declptr(type_pointer_get_ref(type));
} }
static inline int last_array(const type_t *type) static inline int last_array(const type_t *type)
...@@ -75,7 +75,7 @@ static inline int is_string_type(const attr_list_t *attrs, const type_t *type) ...@@ -75,7 +75,7 @@ static inline int is_string_type(const attr_list_t *attrs, const type_t *type)
static inline int is_context_handle(const type_t *type) static inline int is_context_handle(const type_t *type)
{ {
const type_t *t; const type_t *t;
for (t = type; is_ptr(t); t = t->ref) for (t = type; is_ptr(t); t = type_pointer_get_ref(t))
if (is_attr(t->attrs, ATTR_CONTEXTHANDLE)) if (is_attr(t->attrs, ATTR_CONTEXTHANDLE))
return 1; return 1;
return 0; return 0;
......
...@@ -1419,7 +1419,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl, ...@@ -1419,7 +1419,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl,
{ {
type_t *t; type_t *t;
/* move inline attribute from return type node to function node */ /* move inline attribute from return type node to function node */
for (t = func_type; is_ptr(t); t = t->ref) for (t = func_type; is_ptr(t); t = type_pointer_get_ref(t))
; ;
t->attrs = move_attr(t->attrs, type->attrs, ATTR_INLINE); t->attrs = move_attr(t->attrs, type->attrs, ATTR_INLINE);
} }
...@@ -1556,13 +1556,13 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl, ...@@ -1556,13 +1556,13 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl,
type_t *ft, *t; type_t *ft, *t;
type_t *return_type = v->type; type_t *return_type = v->type;
v->type = func_type; v->type = func_type;
for (ft = v->type; is_ptr(ft); ft = ft->ref) for (ft = v->type; is_ptr(ft); ft = type_pointer_get_ref(ft))
; ;
assert(ft->type == RPC_FC_FUNCTION); assert(ft->type == RPC_FC_FUNCTION);
ft->ref = return_type; ft->ref = return_type;
/* move calling convention attribute, if present, from pointer nodes to /* move calling convention attribute, if present, from pointer nodes to
* function node */ * function node */
for (t = v->type; is_ptr(t); t = t->ref) for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
ft->attrs = move_attr(ft->attrs, t->attrs, ATTR_CALLCONV); ft->attrs = move_attr(ft->attrs, t->attrs, ATTR_CALLCONV);
if (is_object_interface && !is_attr(ft->attrs, ATTR_CALLCONV)) if (is_object_interface && !is_attr(ft->attrs, ATTR_CALLCONV))
{ {
...@@ -1574,7 +1574,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl, ...@@ -1574,7 +1574,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl,
else else
{ {
type_t *t; type_t *t;
for (t = v->type; is_ptr(t); t = t->ref) for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
if (is_attr(t->attrs, ATTR_CALLCONV)) if (is_attr(t->attrs, ATTR_CALLCONV))
error_loc("calling convention applied to non-function-pointer type\n"); error_loc("calling convention applied to non-function-pointer type\n");
} }
...@@ -1826,7 +1826,7 @@ static type_t *reg_typedefs(decl_spec_t *decl_spec, declarator_list_t *decls, at ...@@ -1826,7 +1826,7 @@ static type_t *reg_typedefs(decl_spec_t *decl_spec, declarator_list_t *decls, at
unsigned char c; unsigned char c;
while (is_ptr(t)) while (is_ptr(t))
t = t->ref; t = type_pointer_get_ref(t);
c = t->type; c = t->type;
if (c != RPC_FC_CHAR && c != RPC_FC_BYTE && c != RPC_FC_WCHAR) if (c != RPC_FC_CHAR && c != RPC_FC_BYTE && c != RPC_FC_WCHAR)
...@@ -2281,7 +2281,7 @@ static int is_ptr_guid_type(const type_t *type) ...@@ -2281,7 +2281,7 @@ static int is_ptr_guid_type(const type_t *type)
/* second, make sure it is a pointer to something of size sizeof(GUID), /* second, make sure it is a pointer to something of size sizeof(GUID),
* i.e. 16 bytes */ * i.e. 16 bytes */
return (type_memsize(type->ref, &align) == 16); return (type_memsize(type_pointer_get_ref(type), &align) == 16);
} }
static void check_conformance_expr_list(const char *attr_name, const var_t *arg, const type_t *container_type, expr_list_t *expr_list) static void check_conformance_expr_list(const char *attr_name, const var_t *arg, const type_t *container_type, expr_list_t *expr_list)
...@@ -2446,7 +2446,7 @@ static void check_remoting_args(const var_t *func) ...@@ -2446,7 +2446,7 @@ static void check_remoting_args(const var_t *func)
else if (is_ptr(type)) else if (is_ptr(type))
{ {
ptr_level++; ptr_level++;
type = type->ref; type = type_pointer_get_ref(type);
} }
else else
break; break;
......
...@@ -164,10 +164,10 @@ int cant_be_null(const var_t *v) ...@@ -164,10 +164,10 @@ int cant_be_null(const var_t *v)
if (is_user_type(type)) if (is_user_type(type))
return 0; return 0;
if (! attrs && type) if (!attrs && is_ptr(type))
{ {
attrs = type->attrs; attrs = type->attrs;
type = type->ref; type = type_pointer_get_ref(type);
} }
while (attrs) while (attrs)
...@@ -180,10 +180,10 @@ int cant_be_null(const var_t *v) ...@@ -180,10 +180,10 @@ int cant_be_null(const var_t *v)
if (t == RPC_FC_RP) if (t == RPC_FC_RP)
return 1; return 1;
if (type) if (is_ptr(type))
{ {
attrs = type->attrs; attrs = type->attrs;
type = type->ref; type = type_pointer_get_ref(type);
} }
else else
attrs = NULL; attrs = NULL;
......
...@@ -124,12 +124,19 @@ static unsigned short builtin_vt(const type_t *t) ...@@ -124,12 +124,19 @@ static unsigned short builtin_vt(const type_t *t)
return kwp->vt; return kwp->vt;
} }
if (is_string_type (t->attrs, t)) if (is_string_type (t->attrs, t))
switch (t->ref->type) {
unsigned char fc;
if (is_array(t))
fc = type_array_get_element(t)->type;
else
fc = type_pointer_get_ref(t)->type;
switch (fc)
{ {
case RPC_FC_CHAR: return VT_LPSTR; case RPC_FC_CHAR: return VT_LPSTR;
case RPC_FC_WCHAR: return VT_LPWSTR; case RPC_FC_WCHAR: return VT_LPWSTR;
default: break; default: break;
} }
}
return 0; return 0;
} }
......
...@@ -166,4 +166,10 @@ static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type) ...@@ -166,4 +166,10 @@ static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type)
return type->details.coclass.ifaces; return type->details.coclass.ifaces;
} }
static inline type_t *type_pointer_get_ref(const type_t *type)
{
assert(is_ptr(type));
return type->ref;
}
#endif /* WIDL_TYPE_TREE_H */ #endif /* WIDL_TYPE_TREE_H */
...@@ -876,8 +876,8 @@ static int encode_type( ...@@ -876,8 +876,8 @@ static int encode_type(
case VT_PTR: case VT_PTR:
{ {
int next_vt; int next_vt;
for(next_vt = 0; type->ref; type = type->ref) { for(next_vt = 0; is_ptr(type); type = type_pointer_get_ref(type)) {
next_vt = get_type_vt(type->ref); next_vt = get_type_vt(type_pointer_get_ref(type));
if (next_vt != 0) if (next_vt != 0)
break; break;
} }
...@@ -885,7 +885,8 @@ static int encode_type( ...@@ -885,7 +885,8 @@ static int encode_type(
if (next_vt == 0) if (next_vt == 0)
next_vt = VT_VOID; next_vt = VT_VOID;
encode_type(typelib, next_vt, type->ref, &target_type, NULL, NULL, &child_size); encode_type(typelib, next_vt, type_pointer_get_ref(type),
&target_type, NULL, NULL, &child_size);
/* these types already have an implicit pointer, so we don't need to /* these types already have an implicit pointer, so we don't need to
* add another */ * add another */
if(next_vt == VT_DISPATCH || next_vt == VT_UNKNOWN) { if(next_vt == VT_DISPATCH || next_vt == VT_UNKNOWN) {
...@@ -1115,7 +1116,10 @@ static int encode_var( ...@@ -1115,7 +1116,10 @@ static int encode_var(
vt = get_type_vt(type); vt = get_type_vt(type);
if (vt == VT_PTR) { if (vt == VT_PTR) {
int skip_ptr = encode_var(typelib, type->ref, var, &target_type, NULL, NULL, &child_size); type_t *ref = is_ptr(type) ?
type_pointer_get_ref(type) : type_array_get_element(type);
int skip_ptr = encode_var(typelib, ref, var,
&target_type, NULL, NULL, &child_size);
if(skip_ptr == 2) { if(skip_ptr == 2) {
chat("encode_var: skipping ptr\n"); chat("encode_var: skipping ptr\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment