widl: Only write one procformat string and one typeformat string per file.

This commit is contained in:
Robert Shearman 2006-06-01 15:40:10 +01:00 committed by Alexandre Julliard
parent bae6d23c5c
commit 6f85f989f5
5 changed files with 160 additions and 128 deletions

View File

@ -41,14 +41,6 @@
#include "typelib_struct.h"
#include "typegen.h"
#define END_OF_LIST(list) \
do { \
if (list) { \
while (NEXT_LINK(list)) \
list = NEXT_LINK(list); \
} \
} while(0)
static FILE* client;
static int indent = 0;
@ -120,15 +112,13 @@ static void check_pointers(const func_t *func)
}
}
static void write_function_stubs(type_t *iface)
static void write_function_stubs(type_t *iface, unsigned int *proc_offset, unsigned int *type_offset)
{
const func_t *func = iface->funcs;
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;
unsigned int proc_offset = 0;
unsigned int type_offset = 2;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
@ -219,7 +209,7 @@ static void write_function_stubs(type_t *iface)
print_message_buffer_size(func);
fprintf(client, ";\n");
type_offset_func = type_offset;
type_offset_func = *type_offset;
write_remoting_arguments(client, indent, func, &type_offset_func, PASS_IN, PHASE_BUFFERSIZE);
print_client("NdrGetBuffer(\n");
@ -235,7 +225,7 @@ static void write_function_stubs(type_t *iface)
/* make a copy so we don't increment the type offset twice */
type_offset_func = type_offset;
type_offset_func = *type_offset;
/* marshal arguments */
write_remoting_arguments(client, indent, func, &type_offset_func, PASS_IN, PHASE_MARSHAL);
@ -262,13 +252,13 @@ static void write_function_stubs(type_t *iface)
print_client("NdrConvert(\n");
indent++;
print_client("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
print_client("(PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n", proc_offset);
print_client("(PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n", *proc_offset);
indent -= 2;
}
/* unmarshall arguments */
fprintf(client, "\n");
write_remoting_arguments(client, indent, func, &type_offset, PASS_OUT, PHASE_UNMARSHAL);
write_remoting_arguments(client, indent, func, type_offset, PASS_OUT, PHASE_UNMARSHAL);
/* unmarshal return value */
if (!is_void(def->type, NULL))
@ -425,13 +415,13 @@ static void write_formatdesc( const char *str )
}
static void write_formatstringsdecl(type_t *iface)
static void write_formatstringsdecl(ifref_t *ifaces)
{
print_client("#define TYPE_FORMAT_STRING_SIZE %d\n",
get_size_typeformatstring(iface));
get_size_typeformatstring(ifaces));
print_client("#define PROC_FORMAT_STRING_SIZE %d\n",
get_size_procformatstring(iface));
get_size_procformatstring(ifaces));
fprintf(client, "\n");
write_formatdesc("TYPE");
@ -474,6 +464,8 @@ static void init_client(void)
void write_client(ifref_t *ifaces)
{
unsigned int proc_offset = 0;
unsigned int type_offset = 2;
ifref_t *iface = ifaces;
if (!do_client)
@ -486,6 +478,8 @@ void write_client(ifref_t *ifaces)
if (!client)
return;
write_formatstringsdecl(ifaces);
for (; iface; iface = PREV_LINK(iface))
{
if (is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
@ -500,22 +494,17 @@ void write_client(ifref_t *ifaces)
{
int expr_eval_routines;
write_formatstringsdecl(iface->iface);
write_implicithandledecl(iface->iface);
write_clientinterfacedecl(iface->iface);
write_stubdescdecl(iface->iface);
write_bindinghandledecl(iface->iface);
write_function_stubs(iface->iface);
write_function_stubs(iface->iface, &proc_offset, &type_offset);
print_client("#if !defined(__RPC_WIN32__)\n");
print_client("#error Invalid build platform for this stub.\n");
print_client("#endif\n");
fprintf(client, "\n");
write_procformatstring(client, iface->iface);
write_typeformatstring(client, iface->iface);
fprintf(client, "\n");
@ -526,5 +515,10 @@ void write_client(ifref_t *ifaces)
}
}
fprintf(client, "\n");
write_procformatstring(client, ifaces);
write_typeformatstring(client, ifaces);
fclose(client);
}

View File

@ -42,14 +42,6 @@
#include "typelib_struct.h"
#include "typegen.h"
#define END_OF_LIST(list) \
do { \
if (list) { \
while (NEXT_LINK(list)) \
list = NEXT_LINK(list); \
} \
} while(0)
static FILE* server;
static int indent = 0;
@ -189,15 +181,13 @@ static void assign_out_args(const func_t *func)
}
static void write_function_stubs(type_t *iface)
static void write_function_stubs(type_t *iface, unsigned int *proc_offset, unsigned int *type_offset)
{
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 var_t *var;
const var_t* explicit_handle_var;
unsigned int proc_offset = 0;
unsigned int type_offset = 2;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
@ -289,7 +279,7 @@ static void write_function_stubs(type_t *iface)
fprintf(server, "\n");
/* make a copy so we don't increment the type offset twice */
type_offset_func = type_offset;
type_offset_func = *type_offset;
/* unmarshall arguments */
write_remoting_arguments(server, indent, func, &type_offset_func, PASS_IN, PHASE_UNMARSHAL);
@ -377,7 +367,7 @@ static void write_function_stubs(type_t *iface)
fprintf(server, "\n");
print_server("_StubMsg.BufferLength = %u;\n", buffer_size);
type_offset_func = type_offset;
type_offset_func = *type_offset;
write_remoting_arguments(server, indent, func, &type_offset_func, PASS_OUT, PHASE_BUFFERSIZE);
print_server("_pRpcMessage->BufferLength = _StubMsg.BufferLength;\n");
@ -392,10 +382,10 @@ static void write_function_stubs(type_t *iface)
fprintf(server, "\n");
}
type_offset_func = type_offset;
type_offset_func = *type_offset;
/* marshall arguments */
write_remoting_arguments(server, indent, func, &type_offset, PASS_OUT, PHASE_MARSHAL);
write_remoting_arguments(server, indent, func, type_offset, PASS_OUT, PHASE_MARSHAL);
/* marshall the return value */
if (!is_void(def->type, NULL))
@ -570,13 +560,13 @@ static void write_formatdesc( const char *str )
}
static void write_formatstringsdecl(type_t *iface)
static void write_formatstringsdecl(ifref_t *ifaces)
{
print_server("#define TYPE_FORMAT_STRING_SIZE %d\n",
get_size_typeformatstring(iface));
get_size_typeformatstring(ifaces));
print_server("#define PROC_FORMAT_STRING_SIZE %d\n",
get_size_procformatstring(iface));
get_size_procformatstring(ifaces));
fprintf(server, "\n");
write_formatdesc("TYPE");
@ -605,6 +595,8 @@ static void init_server(void)
void write_server(ifref_t *ifaces)
{
unsigned int proc_offset = 0;
unsigned int type_offset = 2;
ifref_t *iface = ifaces;
if (!do_server)
@ -617,6 +609,8 @@ void write_server(ifref_t *ifaces)
if (!server)
return;
write_formatstringsdecl(ifaces);
for (; iface; iface = PREV_LINK(iface))
{
if (is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
@ -631,19 +625,14 @@ void write_server(ifref_t *ifaces)
{
int expr_eval_routines;
write_formatstringsdecl(iface->iface);
write_serverinterfacedecl(iface->iface);
write_stubdescdecl(iface->iface);
write_function_stubs(iface->iface);
write_function_stubs(iface->iface, &proc_offset, &type_offset);
print_server("#if !defined(__RPC_WIN32__)\n");
print_server("#error Invalid build platform for this stub.\n");
print_server("#endif\n");
fprintf(server, "\n");
write_procformatstring(server, iface->iface);
write_typeformatstring(server, iface->iface);
fprintf(server, "\n");
@ -656,5 +645,10 @@ void write_server(ifref_t *ifaces)
}
}
fprintf(server, "\n");
write_procformatstring(server, ifaces);
write_typeformatstring(server, ifaces);
fclose(server);
}

View File

@ -239,8 +239,9 @@ static size_t write_procformatstring_var(FILE *file, int indent,
return size;
}
void write_procformatstring(FILE *file, type_t *iface)
void write_procformatstring(FILE *file, const ifref_t *ifaces)
{
const ifref_t *iface = ifaces;
int indent = 0;
var_t *var;
unsigned int type_offset = 2;
@ -252,36 +253,44 @@ void write_procformatstring(FILE *file, type_t *iface)
print_file(file, indent, "{\n");
indent++;
if (iface->funcs)
END_OF_LIST(iface);
for (; iface; iface = PREV_LINK(iface))
{
func_t *func = iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
for (; func; func = PREV_LINK(func))
if (is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
continue;
if (iface->iface->funcs)
{
/* emit argument data */
if (func->args)
func_t *func = iface->iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
for (; func; func = PREV_LINK(func))
{
var = func->args;
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
/* emit argument data */
if (func->args)
{
write_procformatstring_var(file, indent, var, FALSE,
&type_offset);
var = func->args;
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
{
write_procformatstring_var(file, indent, var, FALSE,
&type_offset);
var = PREV_LINK(var);
var = PREV_LINK(var);
}
}
}
/* emit return value data */
var = func->def;
if (is_void(var->type, NULL))
{
print_file(file, indent, "0x5b, /* FC_END */\n");
print_file(file, indent, "0x5c, /* FC_PAD */\n");
/* emit return value data */
var = func->def;
if (is_void(var->type, NULL))
{
print_file(file, indent, "0x5b, /* FC_END */\n");
print_file(file, indent, "0x5c, /* FC_PAD */\n");
}
else
write_procformatstring_var(file, indent, var, TRUE,
&type_offset);
}
else
write_procformatstring_var(file, indent, var, TRUE,
&type_offset);
}
}
@ -1337,11 +1346,12 @@ static size_t write_typeformatstring_var(FILE *file, int indent,
}
void write_typeformatstring(FILE *file, type_t *iface)
void write_typeformatstring(FILE *file, const ifref_t *ifaces)
{
int indent = 0;
var_t *var;
size_t typeformat_offset;
const ifref_t *iface = ifaces;
print_file(file, indent, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
print_file(file, indent, "{\n");
@ -1352,22 +1362,30 @@ void write_typeformatstring(FILE *file, type_t *iface)
print_file(file, indent, "NdrFcShort(0x0),\n");
typeformat_offset = 2;
if (iface->funcs)
END_OF_LIST(iface);
for (; iface; iface = PREV_LINK(iface))
{
func_t *func = iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
for (; func; func = PREV_LINK(func))
if (is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
continue;
if (iface->iface->funcs)
{
current_func = func;
if (func->args)
func_t *func = iface->iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
for (; func; func = PREV_LINK(func))
{
var = func->args;
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
current_func = func;
if (func->args)
{
write_typeformatstring_var(file, indent, var,
&typeformat_offset);
var = PREV_LINK(var);
var = func->args;
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
{
write_typeformatstring_var(file, indent, var,
&typeformat_offset);
var = PREV_LINK(var);
}
}
}
}
@ -1842,63 +1860,81 @@ size_t get_size_typeformatstring_var(const var_t *var)
return type_offset;
}
size_t get_size_procformatstring(const type_t *iface)
size_t get_size_procformatstring(const ifref_t *ifaces)
{
const ifref_t *iface = ifaces;
size_t size = 1;
func_t *func;
var_t *var;
if (iface->funcs)
{
func = iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
{
/* argument list size */
if (func->args)
{
var = func->args;
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
{
size += get_size_procformatstring_var(var);
var = PREV_LINK(var);
}
}
END_OF_LIST(iface);
/* return value size */
size += 2; /* FIXME: determine real size */
func = PREV_LINK(func);
for (; iface; iface = PREV_LINK(iface))
{
if (is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
continue;
if (iface->iface->funcs)
{
func = iface->iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
{
/* argument list size */
if (func->args)
{
var = func->args;
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
{
size += get_size_procformatstring_var(var);
var = PREV_LINK(var);
}
}
/* return value size */
size += 2; /* FIXME: determine real size */
func = PREV_LINK(func);
}
}
}
return size;
}
size_t get_size_typeformatstring(const type_t *iface)
size_t get_size_typeformatstring(const ifref_t *ifaces)
{
const ifref_t *iface = ifaces;
size_t size = 3;
func_t *func;
var_t *var;
if (iface->funcs)
{
func = iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
{
/* argument list size */
if (func->args)
{
var = func->args;
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
{
size += get_size_typeformatstring_var(var);
var = PREV_LINK(var);
}
}
END_OF_LIST(iface);
func = PREV_LINK(func);
for (; iface; iface = PREV_LINK(iface))
{
if (is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
continue;
if (iface->iface->funcs)
{
func = iface->iface->funcs;
while (NEXT_LINK(func)) func = NEXT_LINK(func);
while (func)
{
/* argument list size */
if (func->args)
{
var = func->args;
while (NEXT_LINK(var)) var = NEXT_LINK(var);
while (var)
{
size += get_size_typeformatstring_var(var);
var = PREV_LINK(var);
}
}
func = PREV_LINK(func);
}
}
}
return size;

View File

@ -35,15 +35,15 @@ enum remoting_phase
PHASE_FREE
};
void write_procformatstring(FILE *file, type_t *iface);
void write_typeformatstring(FILE *file, type_t *iface);
void write_procformatstring(FILE *file, const ifref_t *ifaces);
void write_typeformatstring(FILE *file, const ifref_t *ifaces);
size_t get_type_memsize(const type_t *type);
unsigned int get_required_buffer_size(const var_t *var, unsigned int *alignment, enum pass pass);
void print_phase_basetype(FILE *file, int indent, 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, unsigned int *type_offset, enum pass pass, enum remoting_phase phase);
size_t get_size_procformatstring_var(const var_t *var);
size_t get_size_typeformatstring_var(const var_t *var);
size_t get_size_procformatstring(const type_t *iface);
size_t get_size_typeformatstring(const type_t *iface);
size_t get_size_procformatstring(const ifref_t *ifaces);
size_t get_size_typeformatstring(const ifref_t *ifaces);
int write_expr_eval_routines(FILE *file, const char *iface);
void write_expr_eval_routine_list(FILE *file, const char *iface);

View File

@ -56,6 +56,14 @@ typedef struct _typelib_t typelib_t;
#define NEXT_LINK(x) ((x)->l_next)
#define PREV_LINK(x) ((x)->l_prev)
#define END_OF_LIST(list) \
do { \
if (list) { \
while (NEXT_LINK(list)) \
list = NEXT_LINK(list); \
} \
} while(0)
enum attr_type
{
ATTR_AGGREGATABLE,