-- v2: widl: Introduce a new append_declspec helper. widl: Inline write_args into write_type_right. widl: Cleanup indentation and variables in write_type_right. widl: Remove now unnecessary write_callconv argument.
From: Rémi Bernon rbernon@codeweavers.com
--- tools/widl/header.c | 12 ++++++------ tools/widl/header.h | 2 +- tools/widl/typegen.c | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c index a14c9e16946..b1489989cb5 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -154,7 +154,7 @@ static void write_type_v( FILE *h, const decl_spec_t *ds, bool is_field, const c type_t *t = ds->type;
if (!h) return; - if (t) write_type_left( h, ds, name_type, true ); + if (t) write_type_left( h, ds, name_type ); if (name) fprintf( h, "%s%s", !t || needs_space_after( t ) ? " " : "", name ); if (t) write_type_right( h, t, is_field ); } @@ -376,11 +376,11 @@ static void write_type_definition_left( FILE *h, const decl_spec_t *decl_spec, e } }
-void write_type_left( FILE *h, const decl_spec_t *ds, enum name_type name_type, bool write_callconv ) +void write_type_left( FILE *h, const decl_spec_t *ds, enum name_type name_type ) { struct strbuf str = {0}; if (!h) return; - append_type_left( &str, ds, name_type, write_callconv ? is_object_interface ? "STDMETHODCALLTYPE" : "" : NULL ); + append_type_left( &str, ds, name_type, is_object_interface ? "STDMETHODCALLTYPE" : "" ); fwrite( str.buf, 1, str.pos, h ); }
@@ -474,7 +474,7 @@ static void write_type( FILE *f, type_t *t, bool define ) } indent(f, 0); if (define) write_type_definition_left( f, &ds, NAME_DEFAULT, true ); - else write_type_left( f, &ds, NAME_DEFAULT, true ); + else write_type_left( f, &ds, NAME_DEFAULT ); fprintf(f, ";\n"); if(in_namespace) { t->written = false; @@ -482,7 +482,7 @@ static void write_type( FILE *f, type_t *t, bool define ) fprintf(f, "extern "C" {\n"); fprintf(f, "#else\n"); if (define) write_type_definition_left( f, &ds, NAME_C, true ); - else write_type_left( f, &ds, NAME_C, true ); + else write_type_left( f, &ds, NAME_C ); fprintf(f, ";\n"); if (winrt_mode) write_widl_using_macros(f, t); fprintf(f, "#endif\n\n"); @@ -499,7 +499,7 @@ void write_type_decl(FILE *f, const decl_spec_t *t, const char *name)
void write_type_decl_left(FILE *f, const decl_spec_t *ds) { - write_type_left( f, ds, NAME_DEFAULT, true ); + write_type_left( f, ds, NAME_DEFAULT ); }
static int user_type_registered(const char *name) diff --git a/tools/widl/header.h b/tools/widl/header.h index e995815ee8b..b1bcbfee6b8 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -24,7 +24,7 @@ #include "typetree.h"
extern const char* get_name(const var_t *v); -extern void write_type_left( FILE *h, const decl_spec_t *ds, enum name_type name_type, bool write_callconv ); +extern void write_type_left( FILE *h, const decl_spec_t *ds, enum name_type name_type ); extern void write_type_right(FILE *h, type_t *t, int is_field); extern void write_type_decl(FILE *f, const decl_spec_t *t, const char *name); extern void write_type_decl_left(FILE *f, const decl_spec_t *ds); diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c index cb8e030a206..ddde229bee8 100644 --- a/tools/widl/typegen.c +++ b/tools/widl/typegen.c @@ -5064,7 +5064,7 @@ void write_func_param_struct( FILE *file, const type_t *iface, const type_t *fun { print_file(file, 2, "%s", ""); init_param_struct_declspec( &declspec, &arg->declspec ); - write_type_left( file, &declspec, NAME_DEFAULT, true ); + write_type_left( file, &declspec, NAME_DEFAULT ); if (needs_space_after( arg->declspec.type )) fputc( ' ', file ); if (is_array( arg->declspec.type ) && !type_array_is_decl_as_ptr( arg->declspec.type )) fputc( '*', file );
@@ -5081,7 +5081,7 @@ void write_func_param_struct( FILE *file, const type_t *iface, const type_t *fun { print_file(file, 2, "%s", ""); init_param_struct_declspec( &declspec, &retval->declspec ); - write_type_left( file, &declspec, NAME_DEFAULT, true ); + write_type_left( file, &declspec, NAME_DEFAULT ); if (needs_space_after( retval->declspec.type )) fputc( ' ', file ); if (!is_array( retval->declspec.type ) && !is_ptr( retval->declspec.type ) && type_memsize( retval->declspec.type ) != pointer_size) @@ -5132,9 +5132,9 @@ int write_expr_eval_routines(FILE *file, const char *iface) { decl_spec_t ds = {.type = (type_t *)eval->cont_type}; print_file(file, 1, "%s", ""); - write_type_left( file, &ds, NAME_DEFAULT, true ); + write_type_left( file, &ds, NAME_DEFAULT ); fprintf(file, " *%s = (", var_name); - write_type_left( file, &ds, NAME_DEFAULT, true ); + write_type_left( file, &ds, NAME_DEFAULT ); fprintf(file, " *)(pStubMsg->StackTop - %u);\n", eval->baseoff); } print_file(file, 1, "pStubMsg->Offset = 0;\n"); /* FIXME */
From: Rémi Bernon rbernon@codeweavers.com
--- tools/widl/header.c | 120 +++++++++++++++++++++---------------------- tools/widl/header.h | 2 +- tools/widl/typegen.c | 2 +- 3 files changed, 61 insertions(+), 63 deletions(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c index b1489989cb5..6472a44f2a4 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -384,73 +384,71 @@ void write_type_left( FILE *h, const decl_spec_t *ds, enum name_type name_type ) fwrite( str.buf, 1, str.pos, h ); }
-void write_type_right(FILE *h, type_t *t, int is_field) +void write_type_right( FILE *h, type_t *type, bool is_field ) { - if (!h) return; - if (type_is_alias(t)) return; + if (!h) return; + if (type_is_alias( type )) return;
- switch (type_get_type(t)) - { - case TYPE_ARRAY: - { - type_t *elem = type_array_get_element_type(t); - if (type_array_is_decl_as_ptr(t)) + switch (type_get_type( type )) { - if (decl_needs_parens(elem)) - fprintf(h, ")"); + case TYPE_ARRAY: + { + type_t *elem = type_array_get_element_type( type ); + if (type_array_is_decl_as_ptr( type )) + { + if (decl_needs_parens( elem )) fprintf( h, ")" ); + } + else + { + if (is_conformant_array( type )) fprintf( h, "[%s]", is_field ? "1" : "" ); + else fprintf( h, "[%u]", type_array_get_dim( type ) ); + } + write_type_right( h, elem, false ); + break; } - else + + case TYPE_FUNCTION: { - if (is_conformant_array(t)) - fprintf(h, "[%s]", is_field ? "1" : ""); - else - fprintf(h, "[%u]", type_array_get_dim(t)); + const var_list_t *args = type_function_get_args( type ); + fputc( '(', h ); + if (args) write_args( h, args, NULL, 0, false, NAME_DEFAULT ); + else fprintf( h, "void" ); + fputc( ')', h ); + write_type_right( h, type_function_get_rettype( type ), false ); + break; + } + + case TYPE_POINTER: + { + type_t *ref = type_pointer_get_ref_type( type ); + if (decl_needs_parens( ref )) fprintf( h, ")" ); + write_type_right( h, ref, false ); + break; + } + + case TYPE_BITFIELD: + fprintf( h, " : %u", type_bitfield_get_bits( type )->cval ); + break; + + case TYPE_VOID: + case TYPE_BASIC: + case TYPE_ENUM: + case TYPE_STRUCT: + case TYPE_ENCAPSULATED_UNION: + case TYPE_UNION: + case TYPE_ALIAS: + case TYPE_MODULE: + case TYPE_COCLASS: + case TYPE_INTERFACE: + case TYPE_RUNTIMECLASS: + case TYPE_DELEGATE: + case TYPE_PARAMETERIZED_TYPE: + case TYPE_PARAMETER: break; + case TYPE_APICONTRACT: + /* not supposed to be here */ + assert( 0 ); + break; } - write_type_right(h, elem, FALSE); - break; - } - case TYPE_FUNCTION: - { - const var_list_t *args = type_function_get_args(t); - fputc('(', h); - if (args) write_args(h, args, NULL, 0, FALSE, NAME_DEFAULT); - else - fprintf(h, "void"); - fputc(')', h); - write_type_right(h, type_function_get_rettype(t), FALSE); - break; - } - case TYPE_POINTER: - { - type_t *ref = type_pointer_get_ref_type(t); - if (decl_needs_parens(ref)) - fprintf(h, ")"); - write_type_right(h, ref, FALSE); - break; - } - case TYPE_BITFIELD: - fprintf(h, " : %u", type_bitfield_get_bits(t)->cval); - break; - case TYPE_VOID: - case TYPE_BASIC: - case TYPE_ENUM: - case TYPE_STRUCT: - case TYPE_ENCAPSULATED_UNION: - case TYPE_UNION: - case TYPE_ALIAS: - case TYPE_MODULE: - case TYPE_COCLASS: - case TYPE_INTERFACE: - case TYPE_RUNTIMECLASS: - case TYPE_DELEGATE: - case TYPE_PARAMETERIZED_TYPE: - case TYPE_PARAMETER: - break; - case TYPE_APICONTRACT: - /* not supposed to be here */ - assert(0); - break; - } }
static void write_type( FILE *f, type_t *t, bool define ) diff --git a/tools/widl/header.h b/tools/widl/header.h index b1bcbfee6b8..ddae3a40cc4 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -25,7 +25,7 @@
extern const char* get_name(const var_t *v); extern void write_type_left( FILE *h, const decl_spec_t *ds, enum name_type name_type ); -extern void write_type_right(FILE *h, type_t *t, int is_field); +extern void write_type_right( FILE *h, type_t *t, bool is_field ); extern void write_type_decl(FILE *f, const decl_spec_t *t, const char *name); extern void write_type_decl_left(FILE *f, const decl_spec_t *ds); extern unsigned int get_context_handle_offset( const type_t *type ); diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c index ddde229bee8..76d7a2bde21 100644 --- a/tools/widl/typegen.c +++ b/tools/widl/typegen.c @@ -4909,7 +4909,7 @@ void declare_stub_args( FILE *file, int indent, const var_t *func ) fprintf(file, "(*%s)", var->name); } else fprintf(file, "%s", var->name); - write_type_right(file, var->declspec.type, FALSE); + write_type_right( file, var->declspec.type, false ); fprintf(file, ";\n");
if (decl_indirect(var->declspec.type))
From: Rémi Bernon rbernon@codeweavers.com
--- tools/widl/header.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c index 6472a44f2a4..c8bf62ad704 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -410,10 +410,17 @@ void write_type_right( FILE *h, type_t *type, bool is_field ) case TYPE_FUNCTION: { const var_list_t *args = type_function_get_args( type ); + const var_t *arg; + fputc( '(', h ); - if (args) write_args( h, args, NULL, 0, false, NAME_DEFAULT ); - else fprintf( h, "void" ); + if (!args) fprintf( h, "void" ); + else LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry ) + { + write_type_v( h, &arg->declspec, false, arg->name, NAME_DEFAULT ); + if (arg->entry.next != args) fprintf( h, "," ); + } fputc( ')', h ); + write_type_right( h, type_function_get_rettype( type ), false ); break; }
From: Rémi Bernon rbernon@codeweavers.com
--- tools/widl/header.c | 79 ++++------------------------------------- tools/widl/typetree.c | 82 +++++++++++++++++++++++++++++++++++++++++++ tools/widl/typetree.h | 3 ++ 3 files changed, 91 insertions(+), 73 deletions(-)
diff --git a/tools/widl/header.c b/tools/widl/header.c index c8bf62ad704..775851caaa2 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -151,12 +151,11 @@ static void write_type_definition( FILE *h, const decl_spec_t *ds, bool is_field
static void write_type_v( FILE *h, const decl_spec_t *ds, bool is_field, const char *name, enum name_type name_type ) { - type_t *t = ds->type; + struct strbuf str = {0};
if (!h) return; - if (t) write_type_left( h, ds, name_type ); - if (name) fprintf( h, "%s%s", !t || needs_space_after( t ) ? " " : "", name ); - if (t) write_type_right( h, t, is_field ); + append_declspec( &str, ds, name_type, is_object_interface ? "STDMETHODCALLTYPE" : "", is_field, name ); + fwrite( str.buf, 1, str.pos, h ); }
static void write_fields(FILE *h, var_list_t *fields, enum name_type name_type) @@ -386,76 +385,10 @@ void write_type_left( FILE *h, const decl_spec_t *ds, enum name_type name_type )
void write_type_right( FILE *h, type_t *type, bool is_field ) { + struct strbuf str = {0}; if (!h) return; - if (type_is_alias( type )) return; - - switch (type_get_type( type )) - { - case TYPE_ARRAY: - { - type_t *elem = type_array_get_element_type( type ); - if (type_array_is_decl_as_ptr( type )) - { - if (decl_needs_parens( elem )) fprintf( h, ")" ); - } - else - { - if (is_conformant_array( type )) fprintf( h, "[%s]", is_field ? "1" : "" ); - else fprintf( h, "[%u]", type_array_get_dim( type ) ); - } - write_type_right( h, elem, false ); - break; - } - - case TYPE_FUNCTION: - { - const var_list_t *args = type_function_get_args( type ); - const var_t *arg; - - fputc( '(', h ); - if (!args) fprintf( h, "void" ); - else LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry ) - { - write_type_v( h, &arg->declspec, false, arg->name, NAME_DEFAULT ); - if (arg->entry.next != args) fprintf( h, "," ); - } - fputc( ')', h ); - - write_type_right( h, type_function_get_rettype( type ), false ); - break; - } - - case TYPE_POINTER: - { - type_t *ref = type_pointer_get_ref_type( type ); - if (decl_needs_parens( ref )) fprintf( h, ")" ); - write_type_right( h, ref, false ); - break; - } - - case TYPE_BITFIELD: - fprintf( h, " : %u", type_bitfield_get_bits( type )->cval ); - break; - - case TYPE_VOID: - case TYPE_BASIC: - case TYPE_ENUM: - case TYPE_STRUCT: - case TYPE_ENCAPSULATED_UNION: - case TYPE_UNION: - case TYPE_ALIAS: - case TYPE_MODULE: - case TYPE_COCLASS: - case TYPE_INTERFACE: - case TYPE_RUNTIMECLASS: - case TYPE_DELEGATE: - case TYPE_PARAMETERIZED_TYPE: - case TYPE_PARAMETER: break; - case TYPE_APICONTRACT: - /* not supposed to be here */ - assert( 0 ); - break; - } + append_type_right( &str, type, is_object_interface ? "STDMETHODCALLTYPE" : "", is_field ); + fwrite( str.buf, 1, str.pos, h ); }
static void write_type( FILE *f, type_t *t, bool define ) diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c index 20081980422..c77efbc834f 100644 --- a/tools/widl/typetree.c +++ b/tools/widl/typetree.c @@ -302,6 +302,88 @@ void append_type_left( struct strbuf *str, const decl_spec_t *decl_spec, enum na } }
+void append_type_right( struct strbuf *str, const type_t *type, const char *callconv, bool is_field ) +{ + if (type_is_alias( type )) return; + + switch (type_get_type( type )) + { + case TYPE_ARRAY: + { + type_t *elem = type_array_get_element_type( type ); + if (type_array_is_decl_as_ptr( type )) + { + if (decl_needs_parens( elem )) strappend( str, ")" ); + } + else + { + if (is_conformant_array( type )) strappend( str, "[%s]", is_field ? "1" : "" ); + else strappend( str, "[%u]", type_array_get_dim( type ) ); + } + append_type_right( str, elem, callconv, false ); + break; + } + + case TYPE_FUNCTION: + { + const var_list_t *args = type_function_get_args( type ); + const var_t *arg; + + strappend( str, "(" ); + if (!args) strappend( str, "void" ); + else LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry ) + { + append_declspec( str, &arg->declspec, NAME_DEFAULT, callconv, false, arg->name ); + if (arg->entry.next != args) strappend( str, "," ); + } + strappend( str, ")" ); + + append_type_right( str, type_function_get_rettype( type ), callconv, false ); + break; + } + + case TYPE_POINTER: + { + type_t *ref = type_pointer_get_ref_type( type ); + if (decl_needs_parens( ref )) strappend( str, ")" ); + append_type_right( str, ref, callconv, false ); + break; + } + + case TYPE_BITFIELD: + strappend( str, " : %u", type_bitfield_get_bits( type )->cval ); + break; + + case TYPE_VOID: + case TYPE_BASIC: + case TYPE_ENUM: + case TYPE_STRUCT: + case TYPE_ENCAPSULATED_UNION: + case TYPE_UNION: + case TYPE_ALIAS: + case TYPE_MODULE: + case TYPE_COCLASS: + case TYPE_INTERFACE: + case TYPE_RUNTIMECLASS: + case TYPE_DELEGATE: + case TYPE_PARAMETERIZED_TYPE: + case TYPE_PARAMETER: break; + case TYPE_APICONTRACT: + /* not supposed to be here */ + assert( 0 ); + break; + } +} + +void append_declspec( struct strbuf *str, const decl_spec_t *decl_spec, enum name_type name_type, + const char *callconv, bool is_field, const char *name ) +{ + const type_t *type = decl_spec->type; + if (type) append_type_left( str, decl_spec, name_type, callconv ); + if (name) strappend( str, "%s%s", !type || needs_space_after( type ) ? " " : "", name ); + if (type) append_type_right( str, type, callconv, is_field ); +} + static void append_namespace( struct strbuf *str, const struct namespace *namespace, const char *separator, const char *abi_prefix ) { diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h index 9c2844aad4a..d49d7fe5244 100644 --- a/tools/widl/typetree.h +++ b/tools/widl/typetree.h @@ -95,6 +95,9 @@ extern void append_basic_type( struct strbuf *str, const type_t *type ); extern void append_pointer_left( struct strbuf *str, const type_t *type, const char *callconv ); extern void append_type_left( struct strbuf *str, const decl_spec_t *decl_spec, enum name_type name_type, const char *callconv ); +extern void append_type_right( struct strbuf *str, const type_t *type, const char *callconv, bool is_field ); +extern void append_declspec( struct strbuf *str, const decl_spec_t *decl_spec, enum name_type name_type, + const char *callconv, bool is_field, const char *name );
extern char *format_namespace( const struct namespace *namespace, const char *prefix, const char *separator, const char *suffix, const char *abi_prefix );
v2: Drop some leftover `strfree`.
This merge request was approved by Huw Davies.