Added partial support for function pointers.

This commit is contained in:
Alexandre Julliard 2003-09-03 20:16:24 +00:00
parent 3e1c5afdba
commit ba5a968157
5 changed files with 62 additions and 21 deletions

View File

@ -446,8 +446,19 @@ static void write_icom_method_def(type_t *iface)
fprintf(header, ")(%s", arg ? "THIS_ " : "THIS" ); fprintf(header, ")(%s", arg ? "THIS_ " : "THIS" );
while (arg) { while (arg) {
write_type(header, arg->type, arg, arg->tname); write_type(header, arg->type, arg, arg->tname);
fprintf(header, " "); if (arg->args)
write_name(header,arg); {
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); write_array(header, arg->array, 0);
arg = PREV_LINK(arg); arg = PREV_LINK(arg);
if (arg) fprintf(header, ", "); if (arg) fprintf(header, ", ");
@ -503,35 +514,53 @@ static int write_method_macro(type_t *iface, char *name)
return idx; 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; int count = 0;
if (arg) { if (arg) {
while (NEXT_LINK(arg)) while (NEXT_LINK(arg))
arg = NEXT_LINK(arg); arg = NEXT_LINK(arg);
} }
if (h == header) { if (do_indent)
indentation++; {
indent(0); if (h == header) {
} else fprintf(h, " "); indentation++;
indent(0);
} else fprintf(h, " ");
}
if (method == 1) { if (method == 1) {
fprintf(h, "%s* This", name); fprintf(h, "%s* This", name);
count++; count++;
} }
while (arg) { while (arg) {
if (count) { if (count) {
fprintf(h, ",\n"); if (do_indent)
if (h == header) indent(0); {
else fprintf(h, " "); fprintf(h, ",\n");
if (h == header) indent(0);
else fprintf(h, " ");
}
else fprintf(h, ",");
} }
write_type(h, arg->type, arg, arg->tname); write_type(h, arg->type, arg, arg->tname);
fprintf(h, " "); if (arg->args)
write_name(h, arg); {
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); write_array(h, arg->array, 0);
arg = PREV_LINK(arg); arg = PREV_LINK(arg);
count++; count++;
} }
if (h == header) indentation--; if (do_indent && h == header) indentation--;
} }
static void write_cpp_method_def(type_t *iface) 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 "); fprintf(header, " STDMETHODCALLTYPE ");
write_name(header, def); write_name(header, def);
fprintf(header, "(\n"); 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, ") = 0;\n");
fprintf(header, "\n"); fprintf(header, "\n");
} }
@ -575,7 +604,7 @@ static void do_write_c_method_def(type_t *iface, char *name)
fprintf(header, " (STDMETHODCALLTYPE *"); fprintf(header, " (STDMETHODCALLTYPE *");
write_name(header, def); write_name(header, def);
fprintf(header, ")(\n"); fprintf(header, ")(\n");
write_args(header, cur->args, name, 1); write_args(header, cur->args, name, 1, TRUE);
fprintf(header, ");\n"); fprintf(header, ");\n");
fprintf(header, "\n"); fprintf(header, "\n");
} }
@ -603,7 +632,7 @@ static void write_method_proto(type_t *iface)
fprintf(header, " CALLBACK %s_", iface->name); fprintf(header, " CALLBACK %s_", iface->name);
write_name(header, def); write_name(header, def);
fprintf(header, "_Proxy(\n"); fprintf(header, "_Proxy(\n");
write_args(header, cur->args, iface->name, 1); write_args(header, cur->args, iface->name, 1, TRUE);
fprintf(header, ");\n"); fprintf(header, ");\n");
/* stub prototype */ /* stub prototype */
fprintf(header, "void __RPC_STUB %s_", iface->name); 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); fprintf(header, " CALLBACK %s_", iface->name);
write_name(header, mdef); write_name(header, mdef);
fprintf(header, "_Proxy(\n"); fprintf(header, "_Proxy(\n");
write_args(header, m->args, iface->name, 1); write_args(header, m->args, iface->name, 1, TRUE);
fprintf(header, ");\n"); fprintf(header, ");\n");
/* stub prototype - use remotable prototype */ /* stub prototype - use remotable prototype */
write_type(header, def->type, def, def->tname); write_type(header, def->type, def, def->tname);
fprintf(header, " __RPC_STUB %s_", iface->name); fprintf(header, " __RPC_STUB %s_", iface->name);
write_name(header, mdef); write_name(header, mdef);
fprintf(header, "_Stub(\n"); fprintf(header, "_Stub(\n");
write_args(header, cur->args, iface->name, 1); write_args(header, cur->args, iface->name, 1, TRUE);
fprintf(header, ");\n"); fprintf(header, ");\n");
} }
else { else {
@ -655,7 +684,7 @@ static void write_function_proto(type_t *iface)
fprintf(header, " "); fprintf(header, " ");
write_name(header, def); write_name(header, def);
fprintf(header, "(\n"); fprintf(header, "(\n");
write_args(header, cur->args, iface->name, 0); write_args(header, cur->args, iface->name, 0, TRUE);
fprintf(header, ");\n"); fprintf(header, ");\n");
cur = PREV_LINK(cur); cur = PREV_LINK(cur);

View File

@ -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_object(attr_t *a);
extern int is_local(attr_t *a); extern int is_local(attr_t *a);
extern var_t *is_callas(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_forward(type_t *iface);
extern void write_interface(type_t *iface); extern void write_interface(type_t *iface);
extern void write_typedef(type_t *type, var_t *names); extern void write_typedef(type_t *type, var_t *names);

View File

@ -243,6 +243,17 @@ arg: attributes type pident array { $$ = $3;
| type pident array { $$ = $2; | type pident array { $$ = $2;
set_type($$, $1, $3); 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; } array: { $$ = NULL; }

View File

@ -69,7 +69,7 @@ static void gen_proxy(type_t *iface, func_t *cur, int idx)
fprintf(proxy, " CALLBACK %s_", iface->name); fprintf(proxy, " CALLBACK %s_", iface->name);
write_name(proxy, def); write_name(proxy, def);
fprintf(proxy, "_Proxy(\n"); 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");
fprintf(proxy, "{\n"); fprintf(proxy, "{\n");
/* local variables */ /* local variables */

View File

@ -146,6 +146,7 @@ struct _var_t {
int ptr_level; int ptr_level;
expr_t *array; expr_t *array;
type_t *type; type_t *type;
var_t *args; /* for function pointers */
char *tname; char *tname;
attr_t *attrs; attr_t *attrs;
expr_t *eval; expr_t *eval;