[PATCH 2/5] widl: Pass a decl_spec_t to write_type_v().
Zebediah Figura
z.figura12 at gmail.com
Thu Aug 15 20:13:18 CDT 2019
From: Richard Pospesel <richard at torproject.org>
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
This supersedes <https://source.winehq.org/patches/data/167612>.
tools/widl/client.c | 4 ++--
tools/widl/expr.c | 4 ++--
tools/widl/header.c | 26 +++++++++++++-------------
tools/widl/header.h | 2 +-
tools/widl/proxy.c | 2 +-
tools/widl/server.c | 2 +-
tools/widl/typegen.c | 36 +++++++++++++++++++-----------------
tools/widl/typetree.h | 11 +++++++++++
8 files changed, 50 insertions(+), 37 deletions(-)
diff --git a/tools/widl/client.c b/tools/widl/client.c
index 3c0a0711b9..6b1da134ec 100644
--- a/tools/widl/client.c
+++ b/tools/widl/client.c
@@ -136,7 +136,7 @@ static void write_function_stub( const type_t *iface, const var_t *func,
if (has_ret)
{
print_client("%s", "");
- write_type_decl(client, retval->declspec.type, retval->name);
+ write_type_decl(client, &retval->declspec, retval->name);
fprintf(client, ";\n");
}
print_client("RPC_MESSAGE _RpcMessage;\n");
@@ -488,7 +488,7 @@ static void write_implicithandledecl(type_t *iface)
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");
}
}
diff --git a/tools/widl/expr.c b/tools/widl/expr.c
index 3d40da571f..41afb4b40e 100644
--- a/tools/widl/expr.c
+++ b/tools/widl/expr.c
@@ -759,13 +759,13 @@ void write_expr(FILE *h, const expr_t *e, int brackets,
break;
case EXPR_CAST:
fprintf(h, "(");
- write_type_decl(h, e->u.tref.type, NULL);
+ write_type_decl(h, &e->u.tref, NULL);
fprintf(h, ")");
write_expr(h, e->ref, 1, toplevel, toplevel_prefix, cont_type, local_var_prefix);
break;
case EXPR_SIZEOF:
fprintf(h, "sizeof(");
- write_type_decl(h, e->u.tref.type, NULL);
+ write_type_decl(h, &e->u.tref, NULL);
fprintf(h, ")");
break;
case EXPR_SHL:
diff --git a/tools/widl/header.c b/tools/widl/header.c
index 51c2be7eef..b5a88bc107 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -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);
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)
{
@@ -252,7 +252,7 @@ static void write_fields(FILE *h, var_list_t *fields)
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");
}
}
@@ -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;
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);
}
@@ -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);
}
@@ -789,7 +789,7 @@ static void write_generic_handle_routines(FILE *header)
static void write_typedef(FILE *header, type_t *type)
{
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");
}
@@ -833,7 +833,7 @@ static void write_declaration(FILE *header, const var_t *v)
fprintf(header, "extern ");
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");
}
}
@@ -1073,7 +1073,7 @@ void write_args(FILE *h, const var_list_t *args, const char *name, int method, i
}
else fprintf(h, ",");
}
- write_type_decl(h, arg->declspec.type, arg->name);
+ write_type_decl(h, &arg->declspec, arg->name);
if (method == 2) {
const expr_t *expr = get_attrp(arg->attrs, ATTR_DEFAULTVALUE);
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);
fprintf(fp, ")");
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, " %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");
- else if (type_get_type(rt) != TYPE_VOID) {
+ else if (type_get_type(rt->type) != TYPE_VOID) {
fprintf(fp, " ");
write_type_decl(fp, rt, "rv");
fprintf(fp, ";\n");
@@ -1536,7 +1536,7 @@ static void write_rpc_interface_start(FILE *header, const type_t *iface)
if (var)
{
fprintf(header, "extern ");
- write_type_decl( header, var->declspec.type, var->name );
+ write_type_decl( header, &var->declspec, var->name );
fprintf(header, ";\n");
}
if (old_names)
diff --git a/tools/widl/header.h b/tools/widl/header.h
index 94b90a391f..8d728c5df5 100644
--- a/tools/widl/header.h
+++ b/tools/widl/header.h
@@ -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 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_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 unsigned int get_context_handle_offset( const type_t *type );
extern unsigned int get_generic_handle_offset( const type_t *type );
diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c
index 22c045d788..1633e6c9b2 100644
--- a/tools/widl/proxy.c
+++ b/tools/widl/proxy.c
@@ -229,7 +229,7 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx,
/* local variables */
if (has_ret) {
print_proxy( "%s", "" );
- write_type_decl(proxy, retval->declspec.type, retval->name);
+ write_type_decl(proxy, &retval->declspec, retval->name);
fprintf( proxy, ";\n" );
}
print_proxy( "RPC_MESSAGE _RpcMessage;\n" );
diff --git a/tools/widl/server.c b/tools/widl/server.c
index 1ab305950a..3004efc8d2 100644
--- a/tools/widl/server.c
+++ b/tools/widl/server.c
@@ -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("*((");
- write_type_decl(server, ret_type, NULL);
+ write_type_decl(server, type_function_get_ret(func->declspec.type), NULL);
fprintf(server, "*)NDRSContextValue(__frame->_RetVal)) = ");
}
else
diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c
index e266764144..5d47a72112 100644
--- a/tools/widl/typegen.c
+++ b/tools/widl/typegen.c
@@ -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)
{
+ const decl_spec_t ds = {.type = t};
print_file(file, 0, "/* %u (", tfsoff);
- write_type_decl(file, t, NULL);
+ write_type_decl(file, &ds, NULL);
print_file(file, 0, ") */\n");
}
@@ -4006,8 +4007,9 @@ void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
}
else
{
- const type_t *ref = is_ptr(type) ? type_pointer_get_ref_type(type) : type;
- switch (get_basic_fc(ref))
+ const decl_spec_t *ref = is_ptr(type) ? type_pointer_get_ref(type) : &var->declspec;
+
+ switch (get_basic_fc(ref->type))
{
case FC_BYTE:
case FC_CHAR:
@@ -4044,7 +4046,7 @@ void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
default:
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)
@@ -4055,7 +4057,7 @@ void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
if (phase == PHASE_MARSHAL)
{
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))
fprintf(file, " *)__frame->_StubMsg.Buffer = *");
else
@@ -4066,7 +4068,7 @@ void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix,
else if (phase == PHASE_UNMARSHAL)
{
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");
print_file(file, indent, "{\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, " = (");
else
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");
}
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");
}
}
@@ -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);
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);
- write_type_decl(file, var->declspec.type, NULL);
+ write_type_decl(file, &var->declspec, NULL);
fprintf(file, ")0x%x))\n", range_max->cval);
print_file(file, indent, "{\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 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 */
if (!is_void(var->declspec.type))
@@ -4615,7 +4617,7 @@ void declare_stub_args( FILE *file, int indent, const var_t *func )
else
{
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");
}
}
@@ -4623,7 +4625,7 @@ void declare_stub_args( FILE *file, int indent, const var_t *func )
if (!type_function_get_args(func->declspec.type))
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);
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))
{
- type_t *type_to_print;
+ const decl_spec_t *type_to_print;
char name[16];
print_file(file, indent, "%s", "");
if (type_get_type(var->declspec.type) == TYPE_ARRAY &&
!type_array_is_decl_as_ptr(var->declspec.type))
- type_to_print = var->declspec.type;
+ type_to_print = &var->declspec;
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++);
write_type_decl(file, type_to_print, name);
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 ))
{
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 ) ||
type_memsize( retval->declspec.type ) == pointer_size)
fprintf( file, ";\n" );
diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h
index 58b388c825..d5f28fe590 100644
--- a/tools/widl/typetree.h
+++ b/tools/widl/typetree.h
@@ -105,6 +105,11 @@ static inline var_t *type_function_get_retval(const type_t *type)
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)
{
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;
}
+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)
{
assert(type_is_alias(type));
--
2.22.0
More information about the wine-devel
mailing list