widl: Pass a decl_spec_t to write_type_v().

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-08-15 20:13:18 -05:00 committed by Alexandre Julliard
parent d0e10aa372
commit aa2bd521d9
8 changed files with 50 additions and 37 deletions

View File

@ -136,7 +136,7 @@ static void write_function_stub( const type_t *iface, const var_t *func,
if (has_ret) if (has_ret)
{ {
print_client("%s", ""); print_client("%s", "");
write_type_decl(client, retval->declspec.type, retval->name); write_type_decl(client, &retval->declspec, retval->name);
fprintf(client, ";\n"); fprintf(client, ";\n");
} }
print_client("RPC_MESSAGE _RpcMessage;\n"); print_client("RPC_MESSAGE _RpcMessage;\n");
@ -488,7 +488,7 @@ static void write_implicithandledecl(type_t *iface)
if (implicit_handle) if (implicit_handle)
{ {
write_type_decl( client, implicit_handle->declspec.type, implicit_handle->name ); write_type_decl(client, &implicit_handle->declspec, implicit_handle->name);
fprintf(client, ";\n\n"); fprintf(client, ";\n\n");
} }
} }

View File

@ -759,13 +759,13 @@ void write_expr(FILE *h, const expr_t *e, int brackets,
break; break;
case EXPR_CAST: case EXPR_CAST:
fprintf(h, "("); fprintf(h, "(");
write_type_decl(h, e->u.tref.type, NULL); write_type_decl(h, &e->u.tref, NULL);
fprintf(h, ")"); fprintf(h, ")");
write_expr(h, e->ref, 1, toplevel, toplevel_prefix, cont_type, local_var_prefix); write_expr(h, e->ref, 1, toplevel, toplevel_prefix, cont_type, local_var_prefix);
break; break;
case EXPR_SIZEOF: case EXPR_SIZEOF:
fprintf(h, "sizeof("); fprintf(h, "sizeof(");
write_type_decl(h, e->u.tref.type, NULL); write_type_decl(h, &e->u.tref, NULL);
fprintf(h, ")"); fprintf(h, ")");
break; break;
case EXPR_SHL: case EXPR_SHL:

View File

@ -43,7 +43,7 @@ user_type_list_t user_type_list = LIST_INIT(user_type_list);
context_handle_list_t context_handle_list = LIST_INIT(context_handle_list); context_handle_list_t context_handle_list = LIST_INIT(context_handle_list);
generic_handle_list_t generic_handle_list = LIST_INIT(generic_handle_list); generic_handle_list_t generic_handle_list = LIST_INIT(generic_handle_list);
static void write_type_def_or_decl(FILE *f, type_t *t, int field, const char *name); static void write_type_def_or_decl(FILE *f, const decl_spec_t *t, int field, const char *name);
static void indent(FILE *h, int delta) static void indent(FILE *h, int delta)
{ {
@ -252,7 +252,7 @@ static void write_fields(FILE *h, var_list_t *fields)
default: default:
; ;
} }
write_type_def_or_decl(h, v->declspec.type, TRUE, name); write_type_def_or_decl(h, &v->declspec, TRUE, name);
fprintf(h, ";\n"); fprintf(h, ";\n");
} }
} }
@ -485,9 +485,9 @@ void write_type_right(FILE *h, type_t *t, int is_field)
} }
} }
static void write_type_v(FILE *h, type_t *t, int is_field, int declonly, const char *name) static void write_type_v(FILE *h, const decl_spec_t *ds, int is_field, int declonly, const char *name)
{ {
type_t *pt = NULL; type_t *t = ds->type, *pt = NULL;
int ptr_level = 0; int ptr_level = 0;
if (!h) return; if (!h) return;
@ -529,7 +529,7 @@ static void write_type_v(FILE *h, type_t *t, int is_field, int declonly, const c
} }
} }
static void write_type_def_or_decl(FILE *f, type_t *t, int field, const char *name) static void write_type_def_or_decl(FILE *f, const decl_spec_t *t, int field, const char *name)
{ {
write_type_v(f, t, field, FALSE, name); write_type_v(f, t, field, FALSE, name);
} }
@ -558,7 +558,7 @@ static void write_type_definition(FILE *f, type_t *t)
} }
} }
void write_type_decl(FILE *f, type_t *t, const char *name) void write_type_decl(FILE *f, const decl_spec_t *t, const char *name)
{ {
write_type_v(f, t, FALSE, TRUE, name); write_type_v(f, t, FALSE, TRUE, name);
} }
@ -789,7 +789,7 @@ static void write_generic_handle_routines(FILE *header)
static void write_typedef(FILE *header, type_t *type) static void write_typedef(FILE *header, type_t *type)
{ {
fprintf(header, "typedef "); fprintf(header, "typedef ");
write_type_def_or_decl(header, type_alias_get_aliasee_type(type), FALSE, type->name); write_type_def_or_decl(header, type_alias_get_aliasee(type), FALSE, type->name);
fprintf(header, ";\n"); fprintf(header, ";\n");
} }
@ -833,7 +833,7 @@ static void write_declaration(FILE *header, const var_t *v)
fprintf(header, "extern "); fprintf(header, "extern ");
break; break;
} }
write_type_def_or_decl(header, v->declspec.type, FALSE, v->name); write_type_def_or_decl(header, &v->declspec, FALSE, v->name);
fprintf(header, ";\n\n"); fprintf(header, ";\n\n");
} }
} }
@ -1073,7 +1073,7 @@ void write_args(FILE *h, const var_list_t *args, const char *name, int method, i
} }
else fprintf(h, ","); else fprintf(h, ",");
} }
write_type_decl(h, arg->declspec.type, arg->name); write_type_decl(h, &arg->declspec, arg->name);
if (method == 2) { if (method == 2) {
const expr_t *expr = get_attrp(arg->attrs, ATTR_DEFAULTVALUE); const expr_t *expr = get_attrp(arg->attrs, ATTR_DEFAULTVALUE);
if (expr) { if (expr) {
@ -1337,12 +1337,12 @@ static void write_locals(FILE *fp, const type_t *iface, int body)
write_args(fp, type_function_get_args(m->declspec.type), iface->name, 1, TRUE); write_args(fp, type_function_get_args(m->declspec.type), iface->name, 1, TRUE);
fprintf(fp, ")"); fprintf(fp, ")");
if (body) { if (body) {
type_t *rt = type_function_get_rettype(m->declspec.type); const decl_spec_t *rt = type_function_get_ret(m->declspec.type);
fprintf(fp, "\n{\n"); fprintf(fp, "\n{\n");
fprintf(fp, " %s\n", comment); fprintf(fp, " %s\n", comment);
if (rt->name && strcmp(rt->name, "HRESULT") == 0) if (rt->type->name && strcmp(rt->type->name, "HRESULT") == 0)
fprintf(fp, " return E_NOTIMPL;\n"); fprintf(fp, " return E_NOTIMPL;\n");
else if (type_get_type(rt) != TYPE_VOID) { else if (type_get_type(rt->type) != TYPE_VOID) {
fprintf(fp, " "); fprintf(fp, " ");
write_type_decl(fp, rt, "rv"); write_type_decl(fp, rt, "rv");
fprintf(fp, ";\n"); fprintf(fp, ";\n");
@ -1536,7 +1536,7 @@ static void write_rpc_interface_start(FILE *header, const type_t *iface)
if (var) if (var)
{ {
fprintf(header, "extern "); fprintf(header, "extern ");
write_type_decl( header, var->declspec.type, var->name ); write_type_decl( header, &var->declspec, var->name );
fprintf(header, ";\n"); fprintf(header, ";\n");
} }
if (old_names) if (old_names)

View File

@ -31,7 +31,7 @@ extern unsigned int get_attrv(const attr_list_t *list, enum attr_type t);
extern const char* get_name(const var_t *v); extern const char* get_name(const var_t *v);
extern void write_type_left(FILE *h, type_t *t, enum name_type name_type, int declonly); extern void write_type_left(FILE *h, type_t *t, enum name_type name_type, int declonly);
extern void write_type_right(FILE *h, type_t *t, int is_field); extern void write_type_right(FILE *h, type_t *t, int is_field);
extern void write_type_decl(FILE *f, type_t *t, const char *name); extern void write_type_decl(FILE *f, const decl_spec_t *t, const char *name);
extern void write_type_decl_left(FILE *f, type_t *t); extern void write_type_decl_left(FILE *f, type_t *t);
extern unsigned int get_context_handle_offset( const type_t *type ); extern unsigned int get_context_handle_offset( const type_t *type );
extern unsigned int get_generic_handle_offset( const type_t *type ); extern unsigned int get_generic_handle_offset( const type_t *type );

View File

@ -229,7 +229,7 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx,
/* local variables */ /* local variables */
if (has_ret) { if (has_ret) {
print_proxy( "%s", "" ); print_proxy( "%s", "" );
write_type_decl(proxy, retval->declspec.type, retval->name); write_type_decl(proxy, &retval->declspec, retval->name);
fprintf( proxy, ";\n" ); fprintf( proxy, ";\n" );
} }
print_proxy( "RPC_MESSAGE _RpcMessage;\n" ); print_proxy( "RPC_MESSAGE _RpcMessage;\n" );

View File

@ -159,7 +159,7 @@ static void write_function_stub(const type_t *iface, const var_t *func, unsigned
{ {
print_server("__frame->_RetVal = NDRSContextUnmarshall((char*)0, _pRpcMessage->DataRepresentation);\n"); print_server("__frame->_RetVal = NDRSContextUnmarshall((char*)0, _pRpcMessage->DataRepresentation);\n");
print_server("*(("); print_server("*((");
write_type_decl(server, ret_type, NULL); write_type_decl(server, type_function_get_ret(func->declspec.type), NULL);
fprintf(server, "*)NDRSContextValue(__frame->_RetVal)) = "); fprintf(server, "*)NDRSContextValue(__frame->_RetVal)) = ");
} }
else else

View File

@ -2217,8 +2217,9 @@ static unsigned int write_simple_pointer(FILE *file, const attr_list_t *attrs,
static void print_start_tfs_comment(FILE *file, type_t *t, unsigned int tfsoff) static void print_start_tfs_comment(FILE *file, type_t *t, unsigned int tfsoff)
{ {
const decl_spec_t ds = {.type = t};
print_file(file, 0, "/* %u (", tfsoff); print_file(file, 0, "/* %u (", tfsoff);
write_type_decl(file, t, NULL); write_type_decl(file, &ds, NULL);
print_file(file, 0, ") */\n"); print_file(file, 0, ") */\n");
} }
@ -4006,8 +4007,9 @@ void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
} }
else else
{ {
const type_t *ref = is_ptr(type) ? type_pointer_get_ref_type(type) : type; const decl_spec_t *ref = is_ptr(type) ? type_pointer_get_ref(type) : &var->declspec;
switch (get_basic_fc(ref))
switch (get_basic_fc(ref->type))
{ {
case FC_BYTE: case FC_BYTE:
case FC_CHAR: case FC_CHAR:
@ -4044,7 +4046,7 @@ void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
default: default:
error("print_phase_basetype: Unsupported type: %s (0x%02x, ptr_level: 0)\n", error("print_phase_basetype: Unsupported type: %s (0x%02x, ptr_level: 0)\n",
var->name, get_basic_fc(ref)); var->name, get_basic_fc(ref->type));
} }
if (phase == PHASE_MARSHAL && alignment > 1) if (phase == PHASE_MARSHAL && alignment > 1)
@ -4055,7 +4057,7 @@ void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
if (phase == PHASE_MARSHAL) if (phase == PHASE_MARSHAL)
{ {
print_file(file, indent, "*("); print_file(file, indent, "*(");
write_type_decl(file, is_ptr(type) ? type_pointer_get_ref_type(type) : type, NULL); write_type_decl(file, ref, NULL);
if (is_ptr(type)) if (is_ptr(type))
fprintf(file, " *)__frame->_StubMsg.Buffer = *"); fprintf(file, " *)__frame->_StubMsg.Buffer = *");
else else
@ -4066,7 +4068,7 @@ void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
else if (phase == PHASE_UNMARSHAL) else if (phase == PHASE_UNMARSHAL)
{ {
print_file(file, indent, "if (__frame->_StubMsg.Buffer + sizeof("); print_file(file, indent, "if (__frame->_StubMsg.Buffer + sizeof(");
write_type_decl(file, is_ptr(type) ? type_pointer_get_ref_type(type) : type, NULL); write_type_decl(file, ref, NULL);
fprintf(file, ") > __frame->_StubMsg.BufferEnd)\n"); fprintf(file, ") > __frame->_StubMsg.BufferEnd)\n");
print_file(file, indent, "{\n"); print_file(file, indent, "{\n");
print_file(file, indent + 1, "RpcRaiseException(RPC_X_BAD_STUB_DATA);\n"); print_file(file, indent + 1, "RpcRaiseException(RPC_X_BAD_STUB_DATA);\n");
@ -4078,12 +4080,12 @@ void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
fprintf(file, " = ("); fprintf(file, " = (");
else else
fprintf(file, " = *("); fprintf(file, " = *(");
write_type_decl(file, is_ptr(type) ? type_pointer_get_ref_type(type) : type, NULL); write_type_decl(file, ref, NULL);
fprintf(file, " *)__frame->_StubMsg.Buffer;\n"); fprintf(file, " *)__frame->_StubMsg.Buffer;\n");
} }
print_file(file, indent, "__frame->_StubMsg.Buffer += sizeof("); print_file(file, indent, "__frame->_StubMsg.Buffer += sizeof(");
write_type_decl(file, is_ptr(type) ? type_pointer_get_ref_type(type) : type, NULL); write_type_decl(file, ref, NULL);
fprintf(file, ");\n"); fprintf(file, ");\n");
} }
} }
@ -4388,9 +4390,9 @@ static void write_remoting_arg(FILE *file, int indent, const var_t *func, const
range_max = LIST_ENTRY(list_next(range_list, list_head(range_list)), const expr_t, entry); range_max = LIST_ENTRY(list_next(range_list, list_head(range_list)), const expr_t, entry);
print_file(file, indent, "if ((%s%s < (", local_var_prefix, var->name); print_file(file, indent, "if ((%s%s < (", local_var_prefix, var->name);
write_type_decl(file, var->declspec.type, NULL); write_type_decl(file, &var->declspec, NULL);
fprintf(file, ")0x%x) || (%s%s > (", range_min->cval, local_var_prefix, var->name); fprintf(file, ")0x%x) || (%s%s > (", range_min->cval, local_var_prefix, var->name);
write_type_decl(file, var->declspec.type, NULL); write_type_decl(file, &var->declspec, NULL);
fprintf(file, ")0x%x))\n", range_max->cval); fprintf(file, ")0x%x))\n", range_max->cval);
print_file(file, indent, "{\n"); print_file(file, indent, "{\n");
print_file(file, indent+1, "RpcRaiseException(RPC_S_INVALID_BOUND);\n"); print_file(file, indent+1, "RpcRaiseException(RPC_S_INVALID_BOUND);\n");
@ -4605,7 +4607,7 @@ void declare_stub_args( FILE *file, int indent, const var_t *func )
{ {
int in_attr, out_attr; int in_attr, out_attr;
int i = 0; int i = 0;
const var_t *var = type_function_get_retval(func->declspec.type); var_t *var = type_function_get_retval(func->declspec.type);
/* declare return value */ /* declare return value */
if (!is_void(var->declspec.type)) if (!is_void(var->declspec.type))
@ -4615,7 +4617,7 @@ void declare_stub_args( FILE *file, int indent, const var_t *func )
else else
{ {
print_file(file, indent, "%s", ""); print_file(file, indent, "%s", "");
write_type_decl(file, var->declspec.type, var->name); write_type_decl(file, &var->declspec, var->name);
fprintf(file, ";\n"); fprintf(file, ";\n");
} }
} }
@ -4623,7 +4625,7 @@ void declare_stub_args( FILE *file, int indent, const var_t *func )
if (!type_function_get_args(func->declspec.type)) if (!type_function_get_args(func->declspec.type))
return; return;
LIST_FOR_EACH_ENTRY( var, type_function_get_args(func->declspec.type), const var_t, entry ) LIST_FOR_EACH_ENTRY( var, type_function_get_args(func->declspec.type), var_t, entry )
{ {
in_attr = is_attr(var->attrs, ATTR_IN); in_attr = is_attr(var->attrs, ATTR_IN);
out_attr = is_attr(var->attrs, ATTR_OUT); out_attr = is_attr(var->attrs, ATTR_OUT);
@ -4636,14 +4638,14 @@ void declare_stub_args( FILE *file, int indent, const var_t *func )
{ {
if (!in_attr && !is_conformant_array(var->declspec.type)) if (!in_attr && !is_conformant_array(var->declspec.type))
{ {
type_t *type_to_print; const decl_spec_t *type_to_print;
char name[16]; char name[16];
print_file(file, indent, "%s", ""); print_file(file, indent, "%s", "");
if (type_get_type(var->declspec.type) == TYPE_ARRAY && if (type_get_type(var->declspec.type) == TYPE_ARRAY &&
!type_array_is_decl_as_ptr(var->declspec.type)) !type_array_is_decl_as_ptr(var->declspec.type))
type_to_print = var->declspec.type; type_to_print = &var->declspec;
else else
type_to_print = type_pointer_get_ref_type(var->declspec.type); type_to_print = type_pointer_get_ref(var->declspec.type);
sprintf(name, "_W%u", i++); sprintf(name, "_W%u", i++);
write_type_decl(file, type_to_print, name); write_type_decl(file, type_to_print, name);
fprintf(file, ";\n"); fprintf(file, ";\n");
@ -4820,7 +4822,7 @@ void write_func_param_struct( FILE *file, const type_t *iface, const type_t *fun
if (add_retval && !is_void( retval->declspec.type )) if (add_retval && !is_void( retval->declspec.type ))
{ {
print_file(file, 2, "%s", ""); print_file(file, 2, "%s", "");
write_type_decl( file, retval->declspec.type, retval->name ); write_type_decl( file, &retval->declspec, retval->name );
if (is_array( retval->declspec.type ) || is_ptr( retval->declspec.type ) || if (is_array( retval->declspec.type ) || is_ptr( retval->declspec.type ) ||
type_memsize( retval->declspec.type ) == pointer_size) type_memsize( retval->declspec.type ) == pointer_size)
fprintf( file, ";\n" ); fprintf( file, ";\n" );

View File

@ -105,6 +105,11 @@ static inline var_t *type_function_get_retval(const type_t *type)
return type->details.function->retval; return type->details.function->retval;
} }
static inline const decl_spec_t *type_function_get_ret(const type_t *type)
{
return &type_function_get_retval(type)->declspec;
}
static inline type_t *type_function_get_rettype(const type_t *type) static inline type_t *type_function_get_rettype(const type_t *type)
{ {
return type_function_get_retval(type)->declspec.type; return type_function_get_retval(type)->declspec.type;
@ -302,6 +307,12 @@ static inline int type_is_alias(const type_t *type)
return type->type_type == TYPE_ALIAS; return type->type_type == TYPE_ALIAS;
} }
static inline const decl_spec_t *type_alias_get_aliasee(const type_t *type)
{
assert(type_is_alias(type));
return &type->details.alias.aliasee;
}
static inline type_t *type_alias_get_aliasee_type(const type_t *type) static inline type_t *type_alias_get_aliasee_type(const type_t *type)
{ {
assert(type_is_alias(type)); assert(type_is_alias(type));