Commit 901a42b7 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

widl: Move funcs and stmts fields from type_t structure to module_details and function_details.

parent b1f8560a
......@@ -50,14 +50,14 @@ static void print_client( const char *format, ... )
}
static void check_pointers(const func_t *func)
static void check_pointers(const var_t *func)
{
const var_t *var;
if (!func->args)
if (!type_get_function_args(func->type))
return;
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
{
if (is_var_ptr(var) && cant_be_null(var))
{
......@@ -73,7 +73,7 @@ static void check_pointers(const func_t *func)
static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
{
const func_t *func;
const statement_t *stmt;
const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
const var_t *var;
int method_count = 0;
......@@ -81,14 +81,15 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
if (!implicit_handle)
print_client("static RPC_BINDING_HANDLE %s__MIDL_AutoBindHandle;\n\n", iface->name);
if (iface->funcs) LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry )
STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts )
{
const var_t *def = func->def;
const var_t *func = stmt->u.var;
const var_t* explicit_handle_var;
const var_t* explicit_generic_handle_var = NULL;
const var_t* context_handle_var = NULL;
int has_full_pointer = is_full_pointer_function(func);
const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
const var_list_t *args = type_get_function_args(func->type);
/* check for a defined binding handle */
explicit_handle_var = get_explicit_handle_var(func);
......@@ -99,7 +100,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
context_handle_var = get_context_handle_var(func);
}
print_client( "struct __frame_%s%s\n{\n", prefix_client, get_name(def) );
print_client( "struct __frame_%s%s\n{\n", prefix_client, get_name(func) );
indent++;
print_client( "__DECL_EXCEPTION_FRAME\n" );
print_client("MIDL_STUB_MESSAGE _StubMsg;\n");
......@@ -119,8 +120,8 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
indent--;
print_client( "};\n\n" );
print_client( "static void __finally_%s%s(", prefix_client, get_name(def) );
print_client( " struct __frame_%s%s *__frame )\n{\n", prefix_client, get_name(def) );
print_client( "static void __finally_%s%s(", prefix_client, get_name(func) );
print_client( " struct __frame_%s%s *__frame )\n{\n", prefix_client, get_name(func) );
indent++;
/* FIXME: emit client finally code */
......@@ -147,10 +148,10 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
if (needs_space_after(get_func_return_type(func)))
fprintf(client, " ");
if (callconv) fprintf(client, "%s ", callconv);
fprintf(client, "%s%s(\n", prefix_client, get_name(def));
fprintf(client, "%s%s(\n", prefix_client, get_name(func));
indent++;
if (func->args)
write_args(client, func->args, iface->name, 0, TRUE);
if (args)
write_args(client, args, iface->name, 0, TRUE);
else
print_client("void");
fprintf(client, ")\n");
......@@ -159,7 +160,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
/* write the functions body */
fprintf(client, "{\n");
indent++;
print_client( "struct __frame_%s%s __f, * const __frame = &__f;\n", prefix_client, get_name(def) );
print_client( "struct __frame_%s%s __f, * const __frame = &__f;\n", prefix_client, get_name(func) );
/* declare return value '_RetVal' */
if (!is_void(get_func_return_type(func)))
......@@ -184,7 +185,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
}
fprintf(client, "\n");
print_client( "RpcExceptionInit( 0, __finally_%s%s );\n", prefix_client, get_name(def) );
print_client( "RpcExceptionInit( 0, __finally_%s%s );\n", prefix_client, get_name(func) );
if (has_full_pointer)
write_full_pointer_init(client, indent, func, FALSE);
......@@ -199,12 +200,12 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
print_client("NdrClientInitializeNew(&_RpcMessage, &__frame->_StubMsg, &%s_StubDesc, %d);\n",
iface->name, method_count);
if (is_attr(def->attrs, ATTR_IDEMPOTENT) || is_attr(def->attrs, ATTR_BROADCAST))
if (is_attr(func->attrs, ATTR_IDEMPOTENT) || is_attr(func->attrs, ATTR_BROADCAST))
{
print_client("_RpcMessage.RpcFlags = ( RPC_NCA_FLAGS_DEFAULT ");
if (is_attr(def->attrs, ATTR_IDEMPOTENT))
if (is_attr(func->attrs, ATTR_IDEMPOTENT))
fprintf(client, "| RPC_NCA_FLAGS_IDEMPOTENT ");
if (is_attr(def->attrs, ATTR_BROADCAST))
if (is_attr(func->attrs, ATTR_BROADCAST))
fprintf(client, "| RPC_NCA_FLAGS_BROADCAST ");
fprintf(client, ");\n\n");
}
......@@ -294,9 +295,9 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
}
/* update proc_offset */
if (func->args)
if (args)
{
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
LIST_FOR_EACH_ENTRY( var, args, const var_t, entry )
*proc_offset += get_size_procformatstring_type(var->name, var->type, var->attrs);
}
if (!is_void(get_func_return_type(func)))
......@@ -309,7 +310,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
print_client("RpcFinally\n");
print_client("{\n");
indent++;
print_client( "__finally_%s%s( __frame );\n", prefix_client, get_name(def) );
print_client( "__finally_%s%s( __frame );\n", prefix_client, get_name(func) );
indent--;
print_client("}\n");
print_client("RpcEndFinally\n");
......@@ -466,6 +467,8 @@ static void write_client_ifaces(const statement_list_t *stmts, int expr_eval_rou
{
if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
{
int has_func = 0;
const statement_t *stmt2;
type_t *iface = stmt->u.type;
if (!need_stub(iface))
return;
......@@ -475,7 +478,13 @@ static void write_client_ifaces(const statement_list_t *stmts, int expr_eval_rou
fprintf(client, " */\n");
fprintf(client, "\n");
if (iface->funcs)
STATEMENTS_FOR_EACH_FUNC(stmt2, iface->details.iface->stmts)
{
has_func = 1;
break;
}
if (has_func)
{
write_implicithandledecl(iface);
......
......@@ -47,11 +47,11 @@ extern int need_proxy_file(const statement_list_t *stmts);
extern const var_t *is_callas(const attr_list_t *list);
extern void write_args(FILE *h, const var_list_t *arg, const char *name, int obj, int do_indent);
extern void write_array(FILE *h, array_dims_t *v, int field);
extern const var_t* get_explicit_handle_var(const func_t* func);
extern const var_t* get_explicit_handle_var(const var_t *func);
extern const type_t* get_explicit_generic_handle_type(const var_t* var);
extern const var_t* get_explicit_generic_handle_var(const func_t* func);
extern const var_t* get_context_handle_var(const func_t* func);
extern int has_out_arg_or_return(const func_t *func);
extern const var_t* get_explicit_generic_handle_var(const var_t *func);
extern const var_t* get_context_handle_var(const var_t *func);
extern int has_out_arg_or_return(const var_t *func);
extern void write_guid(FILE *f, const char *guid_prefix, const char *name,
const UUID *uuid);
extern int is_const_decl(const var_t *var);
......
......@@ -45,6 +45,4 @@ void pop_import(void);
int is_type(const char *name);
func_list_t *gen_function_list(const statement_list_t *stmts);
#endif
......@@ -152,7 +152,7 @@ static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs);
const char *get_attr_display_name(enum attr_type type);
static void add_explicit_handle_if_necessary(func_t *func);
static void add_explicit_handle_if_necessary(var_t *func);
static void check_def(const type_t *t);
static statement_t *make_statement(enum statement_type type);
......@@ -929,8 +929,7 @@ modulehdr: attributes module { $$ = $2;
moduledef: modulehdr '{' int_statements '}'
semicolon_opt { $$ = $1;
$$->stmts = $3;
$$->funcs = gen_function_list($3);
type_module_define($$, $3);
}
;
......@@ -1299,7 +1298,6 @@ type_t *make_type(unsigned char type, type_t *ref)
t->ref = ref;
t->attrs = NULL;
t->orig = NULL;
t->funcs = NULL;
memset(&t->details, 0, sizeof(t->details));
t->ifaces = NULL;
t->dim = 0;
......@@ -1392,15 +1390,14 @@ static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_
return t;
}
static void function_add_head_arg(func_t *func, var_t *arg)
static void type_function_add_head_arg(type_t *type, var_t *arg)
{
if (!func->def->type->details.function->args)
if (!type->details.function->args)
{
func->def->type->details.function->args = xmalloc( sizeof(*func->def->type->details.function->args) );
list_init( func->def->type->details.function->args );
type->details.function->args = xmalloc( sizeof(*type->details.function->args) );
list_init( type->details.function->args );
}
list_add_head( func->def->type->details.function->args, &arg->entry );
func->args = func->def->type->details.function->args;
list_add_head( type->details.function->args, &arg->entry );
}
static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type)
......@@ -1705,8 +1702,6 @@ static func_t *make_func(var_t *def)
{
func_t *f = xmalloc(sizeof(func_t));
f->def = def;
f->args = def->type->details.function->args;
f->idx = -1;
return f;
}
......@@ -1980,25 +1975,6 @@ var_t *find_const(const char *name, int f)
return cur->var;
}
func_list_t *gen_function_list(const statement_list_t *stmts)
{
func_list_t *func_list = NULL;
const statement_t *stmt;
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
{
if (stmt->type == STMT_DECLARATION)
{
var_t *var = stmt->u.var;
if (var->stgclass == STG_NONE && var->type->type == RPC_FC_FUNCTION)
{
check_function_attrs(var->name, var->type->attrs);
func_list = append_func(func_list, make_func(var));
}
}
}
return func_list;
}
static char *gen_name(void)
{
static const char format[] = "__WIDL_%s_generated_name_%08lX";
......@@ -2466,12 +2442,12 @@ static void check_remoting_fields(const var_t *var, type_t *type)
}
/* checks that arguments for a function make sense for marshalling and unmarshalling */
static void check_remoting_args(const func_t *func)
static void check_remoting_args(const var_t *func)
{
const char *funcname = func->def->name;
const char *funcname = func->name;
const var_t *arg;
if (func->args) LIST_FOR_EACH_ENTRY( arg, func->args, const var_t, entry )
if (func->type->details.function->args) LIST_FOR_EACH_ENTRY( arg, func->type->details.function->args, const var_t, entry )
{
int ptr_level = 0;
const type_t *type = arg->type;
......@@ -2506,11 +2482,11 @@ static void check_remoting_args(const func_t *func)
}
}
check_field_common(func->def->type, funcname, arg);
check_field_common(func->type, funcname, arg);
}
}
static void add_explicit_handle_if_necessary(func_t *func)
static void add_explicit_handle_if_necessary(var_t *func)
{
const var_t* explicit_handle_var;
const var_t* explicit_generic_handle_var = NULL;
......@@ -2532,7 +2508,7 @@ static void add_explicit_handle_if_necessary(func_t *func)
var_t *idl_handle = make_var(xstrdup("IDL_handle"));
idl_handle->attrs = append_attr(NULL, make_attr(ATTR_IN));
idl_handle->type = find_type_or_error("handle_t", 0);
function_add_head_arg(func, idl_handle);
type_function_add_head_arg(func->type, idl_handle);
}
}
}
......@@ -2540,18 +2516,21 @@ static void add_explicit_handle_if_necessary(func_t *func)
static void check_functions(const type_t *iface, int is_inside_library)
{
if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE) && iface->funcs)
const statement_t *stmt;
if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE))
{
func_t *func;
LIST_FOR_EACH_ENTRY( func, iface->funcs, func_t, entry )
STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts )
{
var_t *func = stmt->u.var;
add_explicit_handle_if_necessary(func);
}
}
if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL))
{
const func_t *func;
if (iface->funcs) LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry )
STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts )
{
if (!is_attr(func->def->attrs, ATTR_LOCAL))
const var_t *func = stmt->u.var;
if (!is_attr(func->attrs, ATTR_LOCAL))
check_remoting_args(func);
}
}
......@@ -2581,10 +2560,11 @@ static void check_all_user_types(const statement_list_t *stmts)
else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP &&
!is_local(stmt->u.type->attrs))
{
const func_t *f;
const func_list_t *fs = stmt->u.type->funcs;
if (fs) LIST_FOR_EACH_ENTRY(f, fs, const func_t, entry)
check_for_additional_prototype_types(f->args);
const statement_t *stmt_func;
STATEMENTS_FOR_EACH_FUNC(stmt_func, stmt->u.type->details.iface->stmts) {
const var_t *func = stmt_func->u.var;
check_for_additional_prototype_types(func->type->details.function->args);
}
}
}
}
......
......@@ -50,20 +50,19 @@ static void print_server(const char *format, ...)
static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
{
const func_t *func;
const statement_t *stmt;
const var_t *var;
const var_t* explicit_handle_var;
if (!iface->funcs) return;
LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry )
STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts )
{
const var_t *def = func->def;
const var_t *func = stmt->u.var;
int has_full_pointer = is_full_pointer_function(func);
/* check for a defined binding handle */
explicit_handle_var = get_explicit_handle_var(func);
print_server("struct __frame_%s_%s\n{\n", iface->name, get_name(def));
print_server("struct __frame_%s_%s\n{\n", iface->name, get_name(func));
indent++;
print_server("__DECL_EXCEPTION_FRAME\n");
print_server("MIDL_STUB_MESSAGE _StubMsg;\n");
......@@ -74,8 +73,8 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
indent--;
print_server("};\n\n");
print_server("static void __finally_%s_%s(", iface->name, get_name(def));
fprintf(server," struct __frame_%s_%s *__frame )\n{\n", iface->name, get_name(def));
print_server("static void __finally_%s_%s(", iface->name, get_name(func));
fprintf(server," struct __frame_%s_%s *__frame )\n{\n", iface->name, get_name(func));
indent++;
write_remoting_arguments(server, indent, func, "__frame->", PASS_OUT, PHASE_FREE);
......@@ -86,12 +85,12 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
indent--;
print_server("}\n\n");
print_server("void __RPC_STUB %s_%s( PRPC_MESSAGE _pRpcMessage )\n", iface->name, get_name(def));
print_server("void __RPC_STUB %s_%s( PRPC_MESSAGE _pRpcMessage )\n", iface->name, get_name(func));
/* write the functions body */
fprintf(server, "{\n");
indent++;
print_server("struct __frame_%s_%s __f, * const __frame = &__f;\n", iface->name, get_name(def));
print_server("struct __frame_%s_%s __f, * const __frame = &__f;\n", iface->name, get_name(func));
if (has_out_arg_or_return(func)) print_server("RPC_STATUS _Status;\n");
fprintf(server, "\n");
......@@ -102,7 +101,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
print_server("&%s_StubDesc);\n", iface->name);
indent--;
fprintf(server, "\n");
print_server( "RpcExceptionInit( __server_filter, __finally_%s_%s );\n", iface->name, get_name(def));
print_server( "RpcExceptionInit( __server_filter, __finally_%s_%s );\n", iface->name, get_name(func));
write_parameters_init(server, indent, func, "__frame->");
......@@ -122,7 +121,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
if (has_full_pointer)
write_full_pointer_init(server, indent, func, TRUE);
if (func->args)
if (type_get_function_args(func->type))
{
print_server("if ((_pRpcMessage->DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n");
indent++;
......@@ -160,15 +159,15 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
print_server("__frame->_RetVal = ");
else
print_server("");
fprintf(server, "%s%s", prefix_server, get_name(def));
fprintf(server, "%s%s", prefix_server, get_name(func));
if (func->args)
if (type_get_function_args(func->type))
{
int first_arg = 1;
fprintf(server, "(\n");
indent++;
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
{
if (first_arg)
first_arg = 0;
......@@ -229,7 +228,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
print_server("RpcFinally\n");
print_server("{\n");
indent++;
print_server("__finally_%s_%s( __frame );\n", iface->name, get_name(def));
print_server("__finally_%s_%s( __frame );\n", iface->name, get_name(func));
indent--;
print_server("}\n");
print_server("RpcEndFinally\n");
......@@ -251,16 +250,16 @@ static void write_dispatchtable(type_t *iface)
{
unsigned long ver = get_attrv(iface->attrs, ATTR_VERSION);
unsigned long method_count = 0;
const func_t *func;
const statement_t *stmt;
print_server("static RPC_DISPATCH_FUNCTION %s_table[] =\n", iface->name);
print_server("{\n");
indent++;
if (iface->funcs) LIST_FOR_EACH_ENTRY( func, iface->funcs, const func_t, entry )
STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts )
{
var_t *def = func->def;
print_server("%s_%s,\n", iface->name, get_name(def));
var_t *func = stmt->u.var;
print_server("%s_%s,\n", iface->name, get_name(func));
method_count++;
}
print_server("0\n");
......@@ -417,7 +416,7 @@ static void write_server_stmts(const statement_list_t *stmts, int expr_eval_rout
fprintf(server, " */\n");
fprintf(server, "\n");
if (iface->funcs)
if (statements_has_func(iface->details.iface->stmts))
{
write_serverinterfacedecl(iface);
write_stubdescdecl(iface);
......
......@@ -43,14 +43,14 @@ void write_procformatstring(FILE *file, const statement_list_t *stmts, type_pred
void write_typeformatstring(FILE *file, const statement_list_t *stmts, type_pred_t pred);
void print_phase_basetype(FILE *file, int indent, const char *local_var_prefix, enum remoting_phase phase,
enum pass pass, const var_t *var, const char *varname);
void write_remoting_arguments(FILE *file, int indent, const func_t *func, const char *local_var_prefix,
void write_remoting_arguments(FILE *file, int indent, const var_t *func, const char *local_var_prefix,
enum pass pass, enum remoting_phase phase);
size_t get_size_procformatstring_type(const char *name, const type_t *type, const attr_list_t *attrs);
size_t get_size_procformatstring_func(const func_t *func);
size_t get_size_procformatstring_func(const var_t *func);
size_t get_size_procformatstring(const statement_list_t *stmts, type_pred_t pred);
size_t get_size_typeformatstring(const statement_list_t *stmts, type_pred_t pred);
void assign_stub_out_args( FILE *file, int indent, const func_t *func, const char *local_var_prefix );
void declare_stub_args( FILE *file, int indent, const func_t *func );
void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char *local_var_prefix );
void declare_stub_args( FILE *file, int indent, const var_t *func );
int write_expr_eval_routines(FILE *file, const char *iface);
void write_expr_eval_routine_list(FILE *file, const char *iface);
void write_user_quad_list(FILE *file);
......@@ -58,11 +58,11 @@ void write_endpoints( FILE *f, const char *prefix, const str_list_t *list );
void write_exceptions( FILE *file );
size_t type_memsize(const type_t *t, unsigned int *align);
int decl_indirect(const type_t *t);
void write_parameters_init(FILE *file, int indent, const func_t *func, const char *local_var_prefix);
void write_parameters_init(FILE *file, int indent, const var_t *func, const char *local_var_prefix);
void print(FILE *file, int indent, const char *format, va_list ap);
int get_padding(const var_list_t *fields);
int is_user_type(const type_t *t);
expr_t *get_size_is_expr(const type_t *t, const char *name);
int is_full_pointer_function(const func_t *func);
void write_full_pointer_init(FILE *file, int indent, const func_t *func, int is_server);
void write_full_pointer_free(FILE *file, int indent, const func_t *func);
int is_full_pointer_function(const var_t *func);
void write_full_pointer_init(FILE *file, int indent, const var_t *func, int is_server);
void write_full_pointer_free(FILE *file, int indent, const var_t *func);
......@@ -34,6 +34,7 @@ type_t *type_new_function(var_list_t *args)
type_t *t = make_type(RPC_FC_FUNCTION, NULL);
t->details.function = xmalloc(sizeof(*t->details.function));
t->details.function->args = args;
t->details.function->idx = -1;
return t;
}
......@@ -47,19 +48,22 @@ type_t *type_new_pointer(type_t *ref, attr_list_t *attrs)
static int compute_method_indexes(type_t *iface)
{
int idx;
func_t *f;
statement_t *stmt;
if (!iface->details.iface)
return 0;
if (iface->ref)
idx = compute_method_indexes(iface->ref);
else
idx = 0;
if (!iface->funcs)
return idx;
LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry )
if (! is_callas(f->def->attrs))
f->idx = idx++;
STATEMENTS_FOR_EACH_FUNC( stmt, iface->details.iface->stmts )
{
var_t *func = stmt->u.var;
if (!is_callas(func->attrs))
func->type->details.function->idx = idx++;
}
return idx;
}
......@@ -68,10 +72,9 @@ void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stm
{
iface->ref = inherit;
iface->details.iface = xmalloc(sizeof(*iface->details.iface));
iface->funcs = gen_function_list(stmts);
iface->details.iface->disp_props = NULL;
iface->details.iface->disp_methods = NULL;
iface->stmts = stmts;
iface->details.iface->stmts = stmts;
iface->defined = TRUE;
compute_method_indexes(iface);
}
......@@ -81,10 +84,9 @@ void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *me
iface->ref = find_type("IDispatch", 0);
if (!iface->ref) error_loc("IDispatch is undefined\n");
iface->details.iface = xmalloc(sizeof(*iface->details.iface));
iface->funcs = NULL;
iface->details.iface->disp_props = props;
iface->details.iface->disp_methods = methods;
iface->stmts = NULL;
iface->details.iface->stmts = NULL;
iface->defined = TRUE;
compute_method_indexes(iface);
}
......@@ -94,3 +96,11 @@ void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface)
type_dispinterface_define(dispiface, iface->details.iface->disp_props,
iface->details.iface->disp_methods);
}
void type_module_define(type_t *module, statement_list_t *stmts)
{
if (module->details.module) error_loc("multiple definition error\n");
module->details.module = xmalloc(sizeof(*module->details.module));
module->details.module->stmts = stmts;
module->defined = TRUE;
}
......@@ -29,6 +29,7 @@ type_t *type_new_pointer(type_t *ref, attr_list_t *attrs);
void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts);
void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods);
void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
void type_module_define(type_t *module, statement_list_t *stmts);
static inline var_list_t *type_struct_get_fields(const type_t *type)
{
......
......@@ -273,14 +273,22 @@ struct enumeration_details
struct func_details
{
var_list_t *args;
int idx;
};
struct iface_details
{
statement_list_t *stmts;
func_list_t *disp_methods;
var_list_t *disp_props;
};
struct module_details
{
statement_list_t *stmts;
func_list_t *funcs;
};
struct _type_t {
const char *name;
enum type_kind kind;
......@@ -293,9 +301,8 @@ struct _type_t {
struct enumeration_details *enumeration;
struct func_details *function;
struct iface_details *iface;
struct module_details *module;
} details;
func_list_t *funcs; /* interfaces and modules */
statement_list_t *stmts; /* interfaces and modules */
ifref_list_t *ifaces; /* coclasses */
unsigned long dim; /* array dimension */
expr_t *size_is, *length_is;
......@@ -339,8 +346,6 @@ struct _declarator_t {
struct _func_t {
var_t *def;
var_list_t *args;
int idx;
/* parser-internal */
struct list entry;
......@@ -442,9 +447,31 @@ type_t *make_type(unsigned char type, type_t *ref);
void init_loc_info(loc_info_t *);
static inline type_t *get_func_return_type(const func_t *func)
static inline type_t *get_func_return_type(const var_t *func)
{
return func->type->ref;
}
static inline var_list_t *type_get_function_args(const type_t *func_type)
{
return func->def->type->ref;
return func_type->details.function->args;
}
#define STATEMENTS_FOR_EACH_FUNC(stmt, stmts) \
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry ) \
if (stmt->type == STMT_DECLARATION && stmt->u.var->stgclass == STG_NONE && \
stmt->u.var->type->type == RPC_FC_FUNCTION)
static inline int statements_has_func(const statement_list_t *stmts)
{
const statement_t *stmt;
int has_func = 0;
STATEMENTS_FOR_EACH_FUNC(stmt, stmts)
{
has_func = 1;
break;
}
return has_func;
}
#endif
......@@ -1261,7 +1261,7 @@ static HRESULT set_custdata(msft_typelib_t *typelib, REFGUID guid,
return S_OK;
}
static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int index)
static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, var_t *func, int index)
{
int offset, name_offset;
int *typedata, typedata_size;
......@@ -1292,13 +1292,13 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int
break;
}
if (is_local( func->def->attrs )) {
if (is_local( func->attrs )) {
chat("add_func_desc: skipping local function\n");
return S_FALSE;
}
if (func->args)
LIST_FOR_EACH_ENTRY( arg, func->args, var_t, entry )
if (type_get_function_args(func->type))
LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), var_t, entry )
{
num_params++;
if (arg->attrs) LIST_FOR_EACH_ENTRY( attr, arg->attrs, const attr_t, entry ) {
......@@ -1311,9 +1311,9 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int
chat("add_func_desc: num of params %d\n", num_params);
name_offset = ctl2_alloc_name(typeinfo->typelib, func->def->name);
name_offset = ctl2_alloc_name(typeinfo->typelib, func->name);
if (func->def->attrs) LIST_FOR_EACH_ENTRY( attr, func->def->attrs, const attr_t, entry ) {
if (func->attrs) LIST_FOR_EACH_ENTRY( attr, func->attrs, const attr_t, entry ) {
expr_t *expr = attr->u.pval;
switch(attr->type) {
case ATTR_BINDABLE:
......@@ -1434,7 +1434,7 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int
/* fill out the basic type information */
typedata[0] = typedata_size | (index << 16);
encode_var(typeinfo->typelib, get_func_return_type(func), func->def, &typedata[1], NULL, NULL, &decoded_size);
encode_var(typeinfo->typelib, get_func_return_type(func), func, &typedata[1], NULL, NULL, &decoded_size);
typedata[2] = funcflags;
typedata[3] = ((52 /*sizeof(FUNCDESC)*/ + decoded_size) << 16) | typeinfo->typeinfo->cbSizeVft;
typedata[4] = (next_idx << 16) | (callconv << 8) | (invokekind << 3) | funckind;
......@@ -1460,10 +1460,10 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int
warning("unknown number of optional attrs\n");
}
if (func->args)
if (type_get_function_args(func->type))
{
i = 0;
LIST_FOR_EACH_ENTRY( arg, func->args, var_t, entry )
LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), var_t, entry )
{
int paramflags = 0;
int *paramdata = typedata + 6 + extra_attr + (num_defaults ? num_params : 0) + i * 3;
......@@ -1567,10 +1567,10 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, const func_t *func, int
if(typeinfo->typekind == TKIND_MODULE)
namedata[9] |= 0x20;
if (func->args)
if (type_get_function_args(func->type))
{
i = 0;
LIST_FOR_EACH_ENTRY( arg, func->args, var_t, entry )
LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), var_t, entry )
{
/* don't give the last arg of a [propput*] func a name */
if(i != num_params - 1 || (invokekind != 0x4 /* INVOKE_PROPERTYPUT */ && invokekind != 0x8 /* INVOKE_PROPERTYPUTREF */))
......@@ -1965,9 +1965,10 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte
add_dispatch(typelib);
msft_typeinfo->typeinfo->cImplTypes = 1;
/* count the no of funcs, as the variable indices come after the funcs */
if (dispinterface->funcs)
LIST_FOR_EACH_ENTRY( func, dispinterface->funcs, const func_t, entry ) idx++;
/* count the no of methods, as the variable indices come after the funcs */
if (dispinterface->details.iface->disp_methods)
LIST_FOR_EACH_ENTRY( func, dispinterface->details.iface->disp_methods, const func_t, entry )
idx++;
if (type_dispiface_get_props(dispinterface))
LIST_FOR_EACH_ENTRY( var, type_dispiface_get_props(dispinterface), var_t, entry )
......@@ -1977,7 +1978,7 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte
{
idx = 0;
LIST_FOR_EACH_ENTRY( func, type_dispiface_get_methods(dispinterface), const func_t, entry )
if(add_func_desc(msft_typeinfo, func, idx) == S_OK)
if(add_func_desc(msft_typeinfo, func->def, idx) == S_OK)
idx++;
}
}
......@@ -1985,7 +1986,7 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte
static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface)
{
int idx = 0;
const func_t *func;
const statement_t *stmt_func;
type_t *ref;
msft_typeinfo_t *msft_typeinfo;
importinfo_t *ref_importinfo = NULL;
......@@ -2027,17 +2028,19 @@ 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++;
if (ref->funcs)
LIST_FOR_EACH_ENTRY( func, ref->funcs, const func_t, entry )
if (!is_local(func->def->attrs)) num_funcs++;
STATEMENTS_FOR_EACH_FUNC( stmt_func, ref->details.iface->stmts ) {
var_t *func = stmt_func->u.var;
if (!is_local(func->attrs)) num_funcs++;
}
}
msft_typeinfo->typeinfo->datatype2 = num_funcs << 16 | num_parents;
msft_typeinfo->typeinfo->cbSizeVft = num_funcs * 4;
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++;
STATEMENTS_FOR_EACH_FUNC( stmt_func, interface->details.iface->stmts ) {
var_t *func = stmt_func->u.var;
if(add_func_desc(msft_typeinfo, func, idx) == S_OK)
idx++;
}
}
static void add_structure_typeinfo(msft_typelib_t *typelib, type_t *structure)
......@@ -2173,7 +2176,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;
const func_t *func;
const statement_t *stmt;
msft_typeinfo_t *msft_typeinfo;
if (-1 < module->typelib_idx)
......@@ -2183,10 +2186,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 (module->funcs)
LIST_FOR_EACH_ENTRY( func, module->funcs, const func_t, entry )
if(add_func_desc(msft_typeinfo, func, idx) == S_OK)
idx++;
STATEMENTS_FOR_EACH_FUNC( stmt, module->details.module->stmts ) {
var_t *func = stmt->u.var;
if(add_func_desc(msft_typeinfo, func, idx) == S_OK)
idx++;
}
msft_typeinfo->typeinfo->size = idx;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment