widl: Convert function lists to standard Wine lists.

This commit is contained in:
Alexandre Julliard 2007-01-22 14:23:08 +01:00
parent e262933bdf
commit 58827d026b
8 changed files with 103 additions and 127 deletions

View File

@ -107,14 +107,13 @@ static void check_pointers(const func_t *func)
static void write_function_stubs(type_t *iface, unsigned int *proc_offset, unsigned int *type_offset)
{
const func_t *func = iface->funcs;
const func_t *func;
const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
int explicit_handle = is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE);
var_t *var;
int method_count = 0;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
if (iface->funcs) LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry )
{
const var_t *def = func->def;
const var_t* explicit_handle_var;
@ -301,7 +300,6 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset, unsig
fprintf(client, "\n");
method_count++;
func = PREV_LINK(func);
}
}

View File

@ -514,15 +514,15 @@ const var_t *is_callas(const attr_list_t *a)
static void write_method_macro(const type_t *iface, const char *name)
{
func_t *cur = iface->funcs;
const func_t *cur;
if (iface->ref) write_method_macro(iface->ref, name);
if (!cur) return;
while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
if (!iface->funcs) return;
fprintf(header, "/*** %s methods ***/\n", iface->name);
while (cur) {
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
{
var_t *def = cur->def;
if (!is_callas(def->attrs)) {
var_t *arg = cur->args;
@ -547,7 +547,6 @@ static void write_method_macro(const type_t *iface, const char *name)
fprintf(header, ",%c", c+'a');
fprintf(header, ")\n");
}
cur = PREV_LINK(cur);
}
}
@ -600,11 +599,12 @@ void write_args(FILE *h, var_t *arg, const char *name, int method, int do_indent
static void write_cpp_method_def(const type_t *iface)
{
func_t *cur = iface->funcs;
const func_t *cur;
if (!cur) return;
while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
while (cur) {
if (!iface->funcs) return;
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
{
var_t *def = cur->def;
if (!is_callas(def->attrs)) {
indent(header, 0);
@ -617,21 +617,20 @@ static void write_cpp_method_def(const type_t *iface)
fprintf(header, ") = 0;\n");
fprintf(header, "\n");
}
cur = PREV_LINK(cur);
}
}
static void do_write_c_method_def(const type_t *iface, const char *name)
{
const func_t *cur = iface->funcs;
const func_t *cur;
if (iface->ref) do_write_c_method_def(iface->ref, name);
if (!cur) return;
while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
if (!iface->funcs) return;
indent(header, 0);
fprintf(header, "/*** %s methods ***/\n", iface->name);
while (cur) {
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
{
const var_t *def = cur->def;
if (!is_callas(def->attrs)) {
indent(header, 0);
@ -643,7 +642,6 @@ static void do_write_c_method_def(const type_t *iface, const char *name)
fprintf(header, ");\n");
fprintf(header, "\n");
}
cur = PREV_LINK(cur);
}
}
@ -659,11 +657,11 @@ static void write_c_disp_method_def(const type_t *iface)
static void write_method_proto(const type_t *iface)
{
const func_t *cur = iface->funcs;
const func_t *cur;
if (!cur) return;
while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
while (cur) {
if (!iface->funcs) return;
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
{
const var_t *def = cur->def;
const var_t *cas = is_callas(def->attrs);
const var_t *args;
@ -692,10 +690,10 @@ static void write_method_proto(const type_t *iface)
check_for_user_types(args);
}
if (cas) {
const func_t *m = iface->funcs;
while (m && strcmp(get_name(m->def), cas->name))
m = NEXT_LINK(m);
if (m) {
const func_t *m;
LIST_FOR_EACH_ENTRY( m, iface->funcs, const func_t, entry )
if (!strcmp(get_name(m->def), cas->name)) break;
if (&m->entry != iface->funcs) {
const var_t *mdef = m->def;
/* proxy prototype - use local prototype */
write_type(header, mdef->type, mdef, mdef->tname);
@ -716,8 +714,6 @@ static void write_method_proto(const type_t *iface)
parser_warning("invalid call_as attribute (%s -> %s)\n", get_name(def), cas->name);
}
}
cur = PREV_LINK(cur);
}
}
@ -726,10 +722,11 @@ static void write_function_proto(const type_t *iface)
const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
int explicit_handle = is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE);
const var_t* explicit_handle_var;
const func_t *cur;
func_t *cur = iface->funcs;
while (NEXT_LINK(cur)) cur = NEXT_LINK(cur);
while (cur) {
if (!iface->funcs) return;
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
{
var_t *def = cur->def;
/* check for a defined binding handle */
@ -756,8 +753,6 @@ static void write_function_proto(const type_t *iface)
else
fprintf(header, " void");
fprintf(header, ");\n");
cur = PREV_LINK(cur);
}
}

View File

@ -83,6 +83,7 @@ static void set_type(var_t *v, typeref_t *ref, expr_t *arr);
static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
static ifref_t *make_ifref(type_t *iface);
static var_t *make_var(char *name);
static func_list_t *append_func(func_list_t *list, func_t *func);
static func_t *make_func(var_t *def, var_t *args);
static type_t *make_class(char *name);
static type_t *make_safearray(void);
@ -123,6 +124,7 @@ static void check_arg(var_t *arg);
typeref_t *tref;
var_t *var;
func_t *func;
func_list_t *func_list;
ifref_t *ifref;
ifref_list_t *ifref_list;
char *str;
@ -229,8 +231,8 @@ static void check_arg(var_t *arg);
%type <var> fields field s_field cases case enums enum_list enum constdef externdef
%type <var> m_ident t_ident ident p_ident pident pident_list
%type <var> dispint_props
%type <func> funcdef int_statements
%type <func> dispint_meths
%type <func> funcdef
%type <func_list> int_statements dispint_meths
%type <type> coclass coclasshdr coclassdef
%type <num> pointer_type version
%type <str> libraryhdr
@ -283,7 +285,7 @@ imp_statements: {}
;
int_statements: { $$ = NULL; }
| int_statements funcdef ';' { $$ = $2; LINK($$, $1); }
| int_statements funcdef ';' { $$ = append_func( $1, $2 ); }
| int_statements statement { $$ = $1; }
;
@ -704,7 +706,7 @@ dispint_props: tPROPERTIES ':' { $$ = NULL; }
;
dispint_meths: tMETHODS ':' { $$ = NULL; }
| dispint_meths funcdef ';' { LINK($2, $1); $$ = $2; }
| dispint_meths funcdef ';' { $$ = append_func( $1, $2 ); }
;
dispinterfacedef: dispinterfacehdr '{'
@ -1238,6 +1240,18 @@ static var_t *make_var(char *name)
return v;
}
static func_list_t *append_func(func_list_t *list, func_t *func)
{
if (!func) return list;
if (!list)
{
list = xmalloc( sizeof(*list) );
list_init( list );
}
list_add_tail( list, &func->entry );
return list;
}
static func_t *make_func(var_t *def, var_t *args)
{
func_t *f = xmalloc(sizeof(func_t));
@ -1245,7 +1259,6 @@ static func_t *make_func(var_t *def, var_t *args)
f->args = args;
f->ignore = parse_only;
f->idx = -1;
INIT_LINK(f);
return f;
}
@ -1634,20 +1647,17 @@ static void write_iid(type_t *iface)
static int compute_method_indexes(type_t *iface)
{
int idx;
func_t *f = iface->funcs;
func_t *f;
if (iface->ref)
idx = compute_method_indexes(iface->ref);
else
idx = 0;
if (! f)
if (!iface->funcs)
return idx;
while (NEXT_LINK(f))
f = NEXT_LINK(f);
for ( ; f ; f = PREV_LINK(f))
LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry )
if (! is_callas(f->def->attrs))
f->idx = idx++;

View File

@ -576,7 +576,7 @@ static void proxy_free_variables( var_t *arg )
}
}
static void gen_proxy(type_t *iface, func_t *cur, int idx)
static void gen_proxy(type_t *iface, const func_t *cur, int idx)
{
var_t *def = cur->def;
int has_ret = !is_void(def->type, def);
@ -762,7 +762,7 @@ static void stub_genmarshall( var_t *args )
stub_gen_marshall_copydata( args );
}
static void gen_stub(type_t *iface, func_t *cur, const char *cas)
static void gen_stub(type_t *iface, const func_t *cur, const char *cas)
{
var_t *def = cur->def;
var_t *arg;
@ -865,13 +865,11 @@ static void gen_stub(type_t *iface, func_t *cur, const char *cas)
static int write_proxy_methods(type_t *iface)
{
func_t *cur = iface->funcs;
const func_t *cur;
int i = 0;
END_OF_LIST(cur);
if (iface->ref) i = write_proxy_methods(iface->ref);
while (cur) {
if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
var_t *def = cur->def;
if (!is_callas(def->attrs)) {
if (i) fprintf(proxy, ",\n");
@ -880,21 +878,19 @@ static int write_proxy_methods(type_t *iface)
fprintf(proxy, "_Proxy");
i++;
}
cur = PREV_LINK(cur);
}
return i;
}
static int write_stub_methods(type_t *iface)
{
func_t *cur = iface->funcs;
const func_t *cur;
int i = 0;
END_OF_LIST(cur);
if (iface->ref) i = write_stub_methods(iface->ref);
else return i; /* skip IUnknown */
while (cur) {
if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
var_t *def = cur->def;
if (!is_local(def->attrs)) {
if (i) fprintf(proxy,",\n");
@ -903,7 +899,6 @@ static int write_stub_methods(type_t *iface)
fprintf(proxy, "_Stub");
i++;
}
cur = PREV_LINK(cur);
}
return i;
}
@ -911,28 +906,30 @@ static int write_stub_methods(type_t *iface)
static void write_proxy(type_t *iface)
{
int midx = -1, stubs;
func_t *cur = iface->funcs;
const func_t *cur;
if (!cur) return;
END_OF_LIST(cur);
if (!iface->funcs) return;
/* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
fprintf(proxy, "/*****************************************************************************\n");
fprintf(proxy, " * %s interface\n", iface->name);
fprintf(proxy, " */\n");
while (cur) {
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
{
const var_t *def = cur->def;
if (!is_local(def->attrs)) {
const var_t *cas = is_callas(def->attrs);
const char *cname = cas ? cas->name : NULL;
int idx = cur->idx;
if (cname) {
const func_t *m = iface->funcs;
while (m && strcmp(get_name(m->def), cname))
m = NEXT_LINK(m);
idx = m->idx;
const func_t *m;
LIST_FOR_EACH_ENTRY( m, iface->funcs, const func_t, entry )
if (!strcmp(get_name(m->def), cname))
{
idx = m->idx;
break;
}
}
gen_proxy(iface, cur, idx);
gen_stub(iface, cur, cname);
@ -940,7 +937,6 @@ static void write_proxy(type_t *iface)
else if (midx != idx) parser_error("method index mismatch in write_proxy");
midx++;
}
cur = PREV_LINK(cur);
}
/* proxy vtable */

View File

@ -186,12 +186,12 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset, unsig
{
char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
int explicit_handle = is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE);
const func_t *func = iface->funcs;
const func_t *func;
const var_t *var;
const var_t* explicit_handle_var;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
if (!iface->funcs) return;
LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry )
{
const var_t *def = func->def;
unsigned long buffer_size = 0;
@ -429,8 +429,6 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset, unsig
*proc_offset += get_size_procformatstring_var(def);
else
*proc_offset += 2; /* FC_END and FC_PAD */
func = PREV_LINK(func);
}
}
@ -439,13 +437,13 @@ static void write_dispatchtable(type_t *iface)
{
unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
unsigned long method_count = 0;
func_t *func = iface->funcs;
const func_t *func;
print_server("static RPC_DISPATCH_FUNCTION %s_table[] =\n", iface->name);
print_server("{\n");
indent++;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
if (iface->funcs) LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry )
{
var_t *def = func->def;
@ -454,7 +452,6 @@ static void write_dispatchtable(type_t *iface)
fprintf(server, ",\n");
method_count++;
func = PREV_LINK(func);
}
print_server("0\n");
indent--;

View File

@ -280,9 +280,8 @@ void write_procformatstring(FILE *file, const ifref_list_t *ifaces, int for_obje
if (iface->iface->funcs)
{
func_t *func = iface->iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
for (; func; func = PREV_LINK(func))
const func_t *func;
LIST_FOR_EACH_ENTRY( func, iface->iface->funcs, const func_t, entry )
{
/* emit argument data */
if (func->args)
@ -1479,9 +1478,8 @@ void write_typeformatstring(FILE *file, const ifref_list_t *ifaces, int for_obje
if (iface->iface->funcs)
{
func_t *func = iface->iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
for (; func; func = PREV_LINK(func))
const func_t *func;
LIST_FOR_EACH_ENTRY( func, iface->iface->funcs, const func_t, entry )
{
current_func = func;
if (func->args)
@ -1967,7 +1965,7 @@ size_t get_size_procformatstring(const ifref_list_t *ifaces, int for_objects)
{
const ifref_t *iface;
size_t size = 1;
func_t *func;
const func_t *func;
var_t *var;
if (ifaces) LIST_FOR_EACH_ENTRY( iface, ifaces, const ifref_t, entry )
@ -1977,9 +1975,7 @@ size_t get_size_procformatstring(const ifref_list_t *ifaces, int for_objects)
if (iface->iface->funcs)
{
func = iface->iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
LIST_FOR_EACH_ENTRY( func, iface->iface->funcs, const func_t, entry )
{
/* argument list size */
if (func->args)
@ -1999,8 +1995,6 @@ size_t get_size_procformatstring(const ifref_list_t *ifaces, int for_objects)
size += 2;
else
size += get_size_procformatstring_var(var);
func = PREV_LINK(func);
}
}
}
@ -2011,7 +2005,7 @@ size_t get_size_typeformatstring(const ifref_list_t *ifaces, int for_objects)
{
const ifref_t *iface;
size_t size = 3;
func_t *func;
const func_t *func;
var_t *var;
if (ifaces) LIST_FOR_EACH_ENTRY( iface, ifaces, const ifref_t, entry )
@ -2021,9 +2015,7 @@ size_t get_size_typeformatstring(const ifref_list_t *ifaces, int for_objects)
if (iface->iface->funcs)
{
func = iface->iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
LIST_FOR_EACH_ENTRY( func, iface->iface->funcs, const func_t, entry )
{
/* argument list size */
if (func->args)
@ -2036,8 +2028,6 @@ size_t get_size_typeformatstring(const ifref_list_t *ifaces, int for_objects)
var = PREV_LINK(var);
}
}
func = PREV_LINK(func);
}
}
}

View File

@ -47,6 +47,7 @@ typedef struct _importinfo_t importinfo_t;
typedef struct _typelib_t typelib_t;
typedef struct list attr_list_t;
typedef struct list func_list_t;
typedef struct list ifref_list_t;
#define DECL_LINK(type) \
@ -208,7 +209,7 @@ struct _type_t {
unsigned char type;
struct _type_t *ref;
const attr_list_t *attrs;
func_t *funcs; /* interfaces and modules */
func_list_t *funcs; /* interfaces and modules */
var_t *fields; /* interfaces, structures and enumerations */
ifref_list_t *ifaces; /* coclasses */
type_t *orig; /* dup'd types */
@ -245,7 +246,7 @@ struct _func_t {
int ignore, idx;
/* parser-internal */
DECL_LINK(func_t);
struct list entry;
};
struct _ifref_t {

View File

@ -1243,7 +1243,7 @@ static HRESULT set_custdata(msft_typelib_t *typelib, REFGUID guid,
return S_OK;
}
static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, func_t *func, int index)
static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int index)
{
int offset, name_offset;
int *typedata, typedata_size;
@ -1897,7 +1897,7 @@ static void add_dispatch(msft_typelib_t *typelib)
static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinterface)
{
int idx = 0;
func_t *func;
const func_t *func;
var_t *var;
msft_typeinfo_t *msft_typeinfo;
@ -1916,13 +1916,8 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte
msft_typeinfo->typeinfo->cImplTypes = 1;
/* count the no of funcs, as the variable indices come after the funcs */
if((func = dispinterface->funcs)) {
idx++;
while(NEXT_LINK(func)) {
func = NEXT_LINK(func);
idx++;
}
}
if (dispinterface->funcs)
LIST_FOR_EACH_ENTRY( func, dispinterface->funcs, const func_t, entry ) idx++;
if((var = dispinterface->fields)) {
while(NEXT_LINK(var)) var = NEXT_LINK(var);
@ -1933,19 +1928,19 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte
}
}
idx = 0;
/* the func count above has already left us pointing at the first func */
while(func) {
if(add_func_desc(msft_typeinfo, func, idx) == S_OK)
idx++;
func = PREV_LINK(func);
if (dispinterface->funcs)
{
idx = 0;
LIST_FOR_EACH_ENTRY( func, dispinterface->funcs, const func_t, entry )
if(add_func_desc(msft_typeinfo, func, idx) == S_OK)
idx++;
}
}
static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface)
{
int idx = 0;
func_t *func;
const func_t *func;
type_t *ref;
msft_typeinfo_t *msft_typeinfo;
importinfo_t *ref_importinfo = NULL;
@ -1987,20 +1982,17 @@ static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface)
/* count the number of inherited interfaces and non-local functions */
for(ref = interface->ref; ref; ref = ref->ref) {
num_parents++;
for(func = ref->funcs; func; func = NEXT_LINK(func))
if (!is_local(func->def->attrs)) num_funcs++;
if (ref->funcs)
LIST_FOR_EACH_ENTRY( func, ref->funcs, const func_t, entry )
if (!is_local(func->def->attrs)) num_funcs++;
}
msft_typeinfo->typeinfo->datatype2 = num_funcs << 16 | num_parents;
msft_typeinfo->typeinfo->cbSizeVft = num_funcs * 4;
if((func = interface->funcs)) {
while(NEXT_LINK(func)) func = NEXT_LINK(func);
while(func) {
if (interface->funcs)
LIST_FOR_EACH_ENTRY( func, interface->funcs, const func_t, entry )
if(add_func_desc(msft_typeinfo, func, idx) == S_OK)
idx++;
func = PREV_LINK(func);
}
}
}
static void add_structure_typeinfo(msft_typelib_t *typelib, type_t *structure)
@ -2139,7 +2131,7 @@ static void add_coclass_typeinfo(msft_typelib_t *typelib, type_t *cls)
static void add_module_typeinfo(msft_typelib_t *typelib, type_t *module)
{
int idx = 0;
func_t *func;
const func_t *func;
msft_typeinfo_t *msft_typeinfo;
if (-1 < module->typelib_idx)
@ -2149,14 +2141,11 @@ static void add_module_typeinfo(msft_typelib_t *typelib, type_t *module)
msft_typeinfo = create_msft_typeinfo(typelib, TKIND_MODULE, module->name, module->attrs);
msft_typeinfo->typeinfo->typekind |= 0x0a00;
if((func = module->funcs)) {
while(NEXT_LINK(func)) func = NEXT_LINK(func);
while(func) {
if (module->funcs)
LIST_FOR_EACH_ENTRY( func, module->funcs, const func_t, entry )
if(add_func_desc(msft_typeinfo, func, idx) == S_OK)
idx++;
func = PREV_LINK(func);
}
}
msft_typeinfo->typeinfo->size = idx;
}