From ba5a96815751a04402e8a9803a8f2ae658d07f15 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 3 Sep 2003 20:16:24 +0000 Subject: [PATCH] Added partial support for function pointers. --- tools/widl/header.c | 67 ++++++++++++++++++++++++++++++------------ tools/widl/header.h | 2 +- tools/widl/parser.y | 11 +++++++ tools/widl/proxy.c | 2 +- tools/widl/widltypes.h | 1 + 5 files changed, 62 insertions(+), 21 deletions(-) diff --git a/tools/widl/header.c b/tools/widl/header.c index 0c5bd364c52..71c77370f8f 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -446,8 +446,19 @@ static void write_icom_method_def(type_t *iface) fprintf(header, ")(%s", arg ? "THIS_ " : "THIS" ); while (arg) { write_type(header, arg->type, arg, arg->tname); - fprintf(header, " "); - write_name(header,arg); + if (arg->args) + { + fprintf(header, " (STDMETHODCALLTYPE *"); + write_name(header,arg); + fprintf( header,")("); + write_args(header, arg->args, NULL, 0, FALSE); + fprintf(header,")"); + } + else + { + fprintf(header, " "); + write_name(header,arg); + } write_array(header, arg->array, 0); arg = PREV_LINK(arg); if (arg) fprintf(header, ", "); @@ -503,35 +514,53 @@ static int write_method_macro(type_t *iface, char *name) return idx; } -void write_args(FILE *h, var_t *arg, char *name, int method) +void write_args(FILE *h, var_t *arg, char *name, int method, int do_indent) { int count = 0; if (arg) { while (NEXT_LINK(arg)) arg = NEXT_LINK(arg); } - if (h == header) { - indentation++; - indent(0); - } else fprintf(h, " "); + if (do_indent) + { + if (h == header) { + indentation++; + indent(0); + } else fprintf(h, " "); + } if (method == 1) { fprintf(h, "%s* This", name); count++; } while (arg) { if (count) { - fprintf(h, ",\n"); - if (h == header) indent(0); - else fprintf(h, " "); + if (do_indent) + { + fprintf(h, ",\n"); + if (h == header) indent(0); + else fprintf(h, " "); + } + else fprintf(h, ","); } write_type(h, arg->type, arg, arg->tname); - fprintf(h, " "); - write_name(h, arg); + if (arg->args) + { + fprintf(h, " (STDMETHODCALLTYPE *"); + write_name(h,arg); + fprintf(h, ")("); + write_args(h, arg->args, NULL, 0, FALSE); + fprintf(h, ")"); + } + else + { + fprintf(h, " "); + write_name(h, arg); + } write_array(h, arg->array, 0); arg = PREV_LINK(arg); count++; } - if (h == header) indentation--; + if (do_indent && h == header) indentation--; } static void write_cpp_method_def(type_t *iface) @@ -549,7 +578,7 @@ static void write_cpp_method_def(type_t *iface) fprintf(header, " STDMETHODCALLTYPE "); write_name(header, def); fprintf(header, "(\n"); - write_args(header, cur->args, iface->name, 2); + write_args(header, cur->args, iface->name, 2, TRUE); fprintf(header, ") = 0;\n"); fprintf(header, "\n"); } @@ -575,7 +604,7 @@ static void do_write_c_method_def(type_t *iface, char *name) fprintf(header, " (STDMETHODCALLTYPE *"); write_name(header, def); fprintf(header, ")(\n"); - write_args(header, cur->args, name, 1); + write_args(header, cur->args, name, 1, TRUE); fprintf(header, ");\n"); fprintf(header, "\n"); } @@ -603,7 +632,7 @@ static void write_method_proto(type_t *iface) fprintf(header, " CALLBACK %s_", iface->name); write_name(header, def); fprintf(header, "_Proxy(\n"); - write_args(header, cur->args, iface->name, 1); + write_args(header, cur->args, iface->name, 1, TRUE); fprintf(header, ");\n"); /* stub prototype */ fprintf(header, "void __RPC_STUB %s_", iface->name); @@ -625,14 +654,14 @@ static void write_method_proto(type_t *iface) fprintf(header, " CALLBACK %s_", iface->name); write_name(header, mdef); fprintf(header, "_Proxy(\n"); - write_args(header, m->args, iface->name, 1); + write_args(header, m->args, iface->name, 1, TRUE); fprintf(header, ");\n"); /* stub prototype - use remotable prototype */ write_type(header, def->type, def, def->tname); fprintf(header, " __RPC_STUB %s_", iface->name); write_name(header, mdef); fprintf(header, "_Stub(\n"); - write_args(header, cur->args, iface->name, 1); + write_args(header, cur->args, iface->name, 1, TRUE); fprintf(header, ");\n"); } else { @@ -655,7 +684,7 @@ static void write_function_proto(type_t *iface) fprintf(header, " "); write_name(header, def); fprintf(header, "(\n"); - write_args(header, cur->args, iface->name, 0); + write_args(header, cur->args, iface->name, 0, TRUE); fprintf(header, ");\n"); cur = PREV_LINK(cur); diff --git a/tools/widl/header.h b/tools/widl/header.h index 7b85cd457c5..9c10b09740d 100644 --- a/tools/widl/header.h +++ b/tools/widl/header.h @@ -28,7 +28,7 @@ extern void write_type(FILE *h, type_t *t, var_t *v, char *n); extern int is_object(attr_t *a); extern int is_local(attr_t *a); extern var_t *is_callas(attr_t *a); -extern void write_args(FILE *h, var_t *arg, char *name, int obj); +extern void write_args(FILE *h, var_t *arg, char *name, int obj, int do_indent); extern void write_forward(type_t *iface); extern void write_interface(type_t *iface); extern void write_typedef(type_t *type, var_t *names); diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 820f6db989e..a427e6b863f 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -243,6 +243,17 @@ arg: attributes type pident array { $$ = $3; | type pident array { $$ = $2; set_type($$, $1, $3); } + | attributes type pident '(' m_args ')' { $$ = $3; + $$->ptr_level--; + set_type($$, $2, NULL); + $$->attrs = $1; + $$->args = $5; + } + | type pident '(' m_args ')' { $$ = $2; + $$->ptr_level--; + set_type($$, $1, NULL); + $$->args = $4; + } ; array: { $$ = NULL; } diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c index 8e14ade5c6f..0234b03f62b 100644 --- a/tools/widl/proxy.c +++ b/tools/widl/proxy.c @@ -69,7 +69,7 @@ static void gen_proxy(type_t *iface, func_t *cur, int idx) fprintf(proxy, " CALLBACK %s_", iface->name); write_name(proxy, def); fprintf(proxy, "_Proxy(\n"); - write_args(proxy, cur->args, iface->name, 1); + write_args(proxy, cur->args, iface->name, 1, TRUE); fprintf(proxy, ")\n"); fprintf(proxy, "{\n"); /* local variables */ diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 11183f92a12..bc7d57abf66 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -146,6 +146,7 @@ struct _var_t { int ptr_level; expr_t *array; type_t *type; + var_t *args; /* for function pointers */ char *tname; attr_t *attrs; expr_t *eval;