2002-07-16 03:20:45 +00:00
|
|
|
/*
|
|
|
|
* IDL Compiler
|
|
|
|
*
|
|
|
|
* Copyright 2002 Ove Kaaven
|
2004-09-06 20:25:39 +00:00
|
|
|
* Copyright 2004 Mike McCormack
|
2002-07-16 03:20:45 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-16 03:20:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2005-08-03 21:25:10 +00:00
|
|
|
#include "wine/port.h"
|
2002-07-16 03:20:45 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-17 18:28:43 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-07-16 03:20:45 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
2006-08-17 01:27:47 +00:00
|
|
|
#include "typegen.h"
|
2008-04-22 10:36:38 +00:00
|
|
|
#include "expr.h"
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2004-09-13 18:05:47 +00:00
|
|
|
#define END_OF_LIST(list) \
|
|
|
|
do { \
|
|
|
|
if (list) { \
|
|
|
|
while (NEXT_LINK(list)) \
|
|
|
|
list = NEXT_LINK(list); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2004-01-07 04:21:27 +00:00
|
|
|
static FILE* proxy;
|
2004-09-06 20:25:39 +00:00
|
|
|
static int indent = 0;
|
2004-01-07 04:21:27 +00:00
|
|
|
|
2002-07-16 03:20:45 +00:00
|
|
|
/* FIXME: support generation of stubless proxies */
|
|
|
|
|
2007-06-15 01:29:33 +00:00
|
|
|
static void print_proxy( const char *format, ... )
|
2004-09-06 20:25:39 +00:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start( va, format );
|
2007-06-15 01:29:33 +00:00
|
|
|
print( proxy, indent, format, va );
|
2004-09-06 20:25:39 +00:00
|
|
|
va_end( va );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_stubdescproto(void)
|
|
|
|
{
|
2007-01-26 11:08:51 +00:00
|
|
|
print_proxy( "static const MIDL_STUB_DESC Object_StubDesc;\n");
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy( "\n");
|
|
|
|
}
|
|
|
|
|
2007-10-26 22:33:13 +00:00
|
|
|
static void write_stubdesc(int expr_eval_routines)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2007-01-26 11:08:51 +00:00
|
|
|
print_proxy( "static const MIDL_STUB_DESC Object_StubDesc =\n{\n");
|
|
|
|
indent++;
|
|
|
|
print_proxy( "0,\n");
|
|
|
|
print_proxy( "NdrOleAllocate,\n");
|
|
|
|
print_proxy( "NdrOleFree,\n");
|
2007-10-26 22:33:13 +00:00
|
|
|
print_proxy( "{0}, 0, 0, %s, 0,\n", expr_eval_routines ? "ExprEvalRoutines" : "0");
|
2007-01-26 11:08:51 +00:00
|
|
|
print_proxy( "__MIDL_TypeFormatString.Format,\n");
|
|
|
|
print_proxy( "1, /* -error bounds_check flag */\n");
|
|
|
|
print_proxy( "0x10001, /* Ndr library version */\n");
|
|
|
|
print_proxy( "0,\n");
|
|
|
|
print_proxy( "0x50100a4, /* MIDL Version 5.1.164 */\n");
|
|
|
|
print_proxy( "0,\n");
|
2007-06-13 23:13:04 +00:00
|
|
|
print_proxy("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
|
2007-01-26 11:08:51 +00:00
|
|
|
print_proxy( "0, /* notify & notify_flag routine table */\n");
|
|
|
|
print_proxy( "1, /* Flags */\n");
|
|
|
|
print_proxy( "0, /* Reserved3 */\n");
|
|
|
|
print_proxy( "0, /* Reserved4 */\n");
|
|
|
|
print_proxy( "0 /* Reserved5 */\n");
|
|
|
|
indent--;
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy( "};\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
}
|
|
|
|
|
2008-04-24 18:06:28 +00:00
|
|
|
static void init_proxy(const statement_list_t *stmts)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
|
|
|
if (proxy) return;
|
2004-10-11 19:54:37 +00:00
|
|
|
if(!(proxy = fopen(proxy_name, "w")))
|
|
|
|
error("Could not open %s for output\n", proxy_name);
|
2006-08-10 23:51:28 +00:00
|
|
|
print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
|
2004-09-08 19:01:42 +00:00
|
|
|
print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
|
|
|
|
print_proxy( "\n");
|
2007-01-26 11:09:03 +00:00
|
|
|
print_proxy( "#define __midl_proxy\n");
|
2007-01-19 12:17:17 +00:00
|
|
|
print_proxy( "#include \"objbase.h\"\n");
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy( "#include \"rpcproxy.h\"\n");
|
|
|
|
print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
|
|
|
|
print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
|
|
|
|
print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#include \"%s\"\n", header_name);
|
|
|
|
print_proxy( "\n");
|
2008-12-01 13:39:39 +00:00
|
|
|
print_proxy( "#ifndef DECLSPEC_HIDDEN\n");
|
|
|
|
print_proxy( "#define DECLSPEC_HIDDEN\n");
|
|
|
|
print_proxy( "#endif\n");
|
|
|
|
print_proxy( "\n");
|
2008-09-15 12:05:26 +00:00
|
|
|
write_exceptions( proxy );
|
2008-07-03 10:59:37 +00:00
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "struct __proxy_frame\n");
|
|
|
|
print_proxy( "{\n");
|
2008-11-15 07:53:38 +00:00
|
|
|
print_proxy( " __DECL_EXCEPTION_FRAME\n");
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy( " MIDL_STUB_MESSAGE _StubMsg;\n");
|
|
|
|
print_proxy( " void *This;\n");
|
2008-07-03 10:59:37 +00:00
|
|
|
print_proxy( "};\n");
|
|
|
|
print_proxy( "\n");
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy("static int __proxy_filter( struct __proxy_frame *__frame )\n");
|
|
|
|
print_proxy( "{\n");
|
|
|
|
print_proxy( " return (__frame->_StubMsg.dwStubPhase != PROXY_SENDRECEIVE);\n");
|
|
|
|
print_proxy( "}\n");
|
2008-07-03 10:59:37 +00:00
|
|
|
print_proxy( "\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 13:26:12 +00:00
|
|
|
static void clear_output_vars( const var_list_t *args )
|
2004-09-02 20:07:07 +00:00
|
|
|
{
|
2007-01-22 13:26:12 +00:00
|
|
|
const var_t *arg;
|
|
|
|
|
|
|
|
if (!args) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
|
|
|
|
{
|
2004-09-06 20:25:39 +00:00
|
|
|
if (is_attr(arg->attrs, ATTR_OUT) && !is_attr(arg->attrs, ATTR_IN)) {
|
|
|
|
print_proxy( "if(%s)\n", arg->name );
|
2004-09-08 19:01:42 +00:00
|
|
|
indent++;
|
2006-08-14 23:45:56 +00:00
|
|
|
print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg->name, arg->name );
|
2004-09-08 19:01:42 +00:00
|
|
|
indent--;
|
2004-09-02 20:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 13:26:12 +00:00
|
|
|
int is_var_ptr(const var_t *v)
|
2004-09-13 18:05:47 +00:00
|
|
|
{
|
2007-05-10 03:50:49 +00:00
|
|
|
return is_ptr(v->type);
|
2004-09-13 18:05:47 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 13:26:12 +00:00
|
|
|
int cant_be_null(const var_t *v)
|
2006-08-12 00:33:40 +00:00
|
|
|
{
|
|
|
|
/* Search backwards for the most recent pointer attribute. */
|
2007-01-22 13:20:36 +00:00
|
|
|
const attr_list_t *attrs = v->attrs;
|
2006-08-12 00:33:40 +00:00
|
|
|
const type_t *type = v->type;
|
|
|
|
|
2008-08-26 19:05:17 +00:00
|
|
|
/* context handles have their own checking so they can be null for the
|
|
|
|
* purposes of null ref pointer checking */
|
|
|
|
if (is_aliaschain_attr(type, ATTR_CONTEXTHANDLE))
|
|
|
|
return 0;
|
|
|
|
|
2008-12-30 18:48:43 +00:00
|
|
|
if (is_user_type(type))
|
|
|
|
return 0;
|
|
|
|
|
2009-01-05 23:34:58 +00:00
|
|
|
if (!attrs && is_ptr(type))
|
2006-08-12 00:33:40 +00:00
|
|
|
{
|
|
|
|
attrs = type->attrs;
|
2009-01-05 23:34:58 +00:00
|
|
|
type = type_pointer_get_ref(type);
|
2006-08-12 00:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (attrs)
|
|
|
|
{
|
|
|
|
int t = get_attrv(attrs, ATTR_POINTERTYPE);
|
|
|
|
|
|
|
|
if (t == RPC_FC_FP || t == RPC_FC_OP || t == RPC_FC_UP)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (t == RPC_FC_RP)
|
|
|
|
return 1;
|
|
|
|
|
2009-01-05 23:34:58 +00:00
|
|
|
if (is_ptr(type))
|
2006-08-12 00:33:40 +00:00
|
|
|
{
|
|
|
|
attrs = type->attrs;
|
2009-01-05 23:34:58 +00:00
|
|
|
type = type_pointer_get_ref(type);
|
2006-08-12 00:33:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
attrs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1; /* Default is RPC_FC_RP. */
|
|
|
|
}
|
|
|
|
|
2008-11-28 11:55:59 +00:00
|
|
|
static int need_delegation(const type_t *iface)
|
|
|
|
{
|
|
|
|
return iface->ref && iface->ref->ref && iface->ref->ignore;
|
|
|
|
}
|
|
|
|
|
2009-01-01 10:25:39 +00:00
|
|
|
static int get_delegation_indirect(const type_t *iface, const type_t ** delegate_to)
|
|
|
|
{
|
|
|
|
const type_t * cur_iface;
|
|
|
|
for (cur_iface = iface; cur_iface != NULL; cur_iface = cur_iface->ref)
|
|
|
|
if (need_delegation(cur_iface))
|
|
|
|
{
|
|
|
|
if(delegate_to)
|
|
|
|
*delegate_to = cur_iface->ref;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int need_delegation_indirect(const type_t *iface)
|
|
|
|
{
|
|
|
|
return get_delegation_indirect(iface, NULL);
|
|
|
|
}
|
|
|
|
|
2007-01-22 13:26:12 +00:00
|
|
|
static void proxy_check_pointers( const var_list_t *args )
|
2004-09-13 18:05:47 +00:00
|
|
|
{
|
2007-01-22 13:26:12 +00:00
|
|
|
const var_t *arg;
|
|
|
|
|
|
|
|
if (!args) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
|
|
|
|
{
|
2006-08-29 21:27:27 +00:00
|
|
|
if (is_var_ptr(arg) && cant_be_null(arg)) {
|
2004-09-13 18:05:47 +00:00
|
|
|
print_proxy( "if(!%s)\n", arg->name );
|
|
|
|
indent++;
|
|
|
|
print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
|
|
|
|
indent--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 14:46:01 +00:00
|
|
|
static void free_variable( const var_t *arg, const char *local_var_prefix )
|
2004-09-20 19:11:16 +00:00
|
|
|
{
|
2007-05-21 06:55:43 +00:00
|
|
|
unsigned int type_offset = arg->type->typestring_offset;
|
2007-12-10 13:30:48 +00:00
|
|
|
expr_t *iid;
|
2007-11-02 22:25:26 +00:00
|
|
|
type_t *type = arg->type;
|
|
|
|
expr_t *size = get_size_is_expr(type, arg->name);
|
2004-09-10 19:34:14 +00:00
|
|
|
|
2007-11-02 22:25:26 +00:00
|
|
|
if (size)
|
2004-09-20 19:11:16 +00:00
|
|
|
{
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy( "__frame->_StubMsg.MaxCount = " );
|
2008-09-15 14:46:01 +00:00
|
|
|
write_expr(proxy, size, 0, 1, NULL, NULL, local_var_prefix);
|
2004-09-20 19:11:16 +00:00
|
|
|
fprintf(proxy, ";\n\n");
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy( "NdrClearOutParameters( &__frame->_StubMsg, ");
|
2007-02-06 17:01:43 +00:00
|
|
|
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
|
2004-09-20 19:11:16 +00:00
|
|
|
fprintf(proxy, "(void*)%s );\n", arg->name );
|
|
|
|
return;
|
|
|
|
}
|
2004-09-10 19:34:14 +00:00
|
|
|
|
2004-09-20 19:11:16 +00:00
|
|
|
switch( type->type )
|
|
|
|
{
|
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_SHORT:
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
case RPC_FC_ENUM16:
|
|
|
|
case RPC_FC_LONG:
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_ENUM32:
|
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_FP:
|
|
|
|
case RPC_FC_IP:
|
2007-12-10 13:30:48 +00:00
|
|
|
iid = get_attrp( arg->attrs, ATTR_IIDIS );
|
|
|
|
if( iid )
|
|
|
|
{
|
2008-12-15 19:08:39 +00:00
|
|
|
print_proxy( "__frame->_StubMsg.MaxCount = (ULONG_PTR) " );
|
2008-09-15 14:46:01 +00:00
|
|
|
write_expr(proxy, iid, 1, 1, NULL, NULL, local_var_prefix);
|
2007-12-10 13:30:48 +00:00
|
|
|
print_proxy( ";\n\n" );
|
|
|
|
}
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy( "NdrClearOutParameters( &__frame->_StubMsg, ");
|
2007-02-06 17:01:43 +00:00
|
|
|
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
|
2004-09-20 19:11:16 +00:00
|
|
|
fprintf(proxy, "(void*)%s );\n", arg->name );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 14:46:01 +00:00
|
|
|
static void proxy_free_variables( var_list_t *args, const char *local_var_prefix )
|
2004-09-20 19:11:16 +00:00
|
|
|
{
|
2007-01-22 13:26:12 +00:00
|
|
|
const var_t *arg;
|
|
|
|
|
|
|
|
if (!args) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
|
|
|
|
if (is_attr(arg->attrs, ATTR_OUT))
|
2004-09-20 19:11:16 +00:00
|
|
|
{
|
2008-09-15 14:46:01 +00:00
|
|
|
free_variable( arg, local_var_prefix );
|
2004-09-20 19:11:16 +00:00
|
|
|
fprintf(proxy, "\n");
|
2004-09-10 19:34:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
static void gen_proxy(type_t *iface, const var_t *func, int idx,
|
2007-05-16 00:45:59 +00:00
|
|
|
unsigned int proc_offset)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2009-01-05 23:33:27 +00:00
|
|
|
int has_ret = !is_void(get_func_return_type(func));
|
|
|
|
int has_full_pointer = is_full_pointer_function(func);
|
|
|
|
const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
|
2008-04-11 10:01:36 +00:00
|
|
|
if (!callconv) callconv = "";
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2004-09-06 20:25:39 +00:00
|
|
|
indent = 0;
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy( "static void __finally_%s_%s_Proxy( struct __proxy_frame *__frame )\n",
|
2009-01-05 23:33:27 +00:00
|
|
|
iface->name, get_name(func) );
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
2009-01-05 23:33:27 +00:00
|
|
|
if (has_full_pointer) write_full_pointer_free(proxy, indent, func);
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy( "NdrProxyFreeBuffer( __frame->This, &__frame->_StubMsg );\n" );
|
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
write_type_decl_left(proxy, get_func_return_type(func));
|
|
|
|
print_proxy( " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(func));
|
|
|
|
write_args(proxy, type_get_function_args(func->type), iface->name, 1, TRUE);
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy( ")\n");
|
|
|
|
print_proxy( "{\n");
|
|
|
|
indent ++;
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy( "struct __proxy_frame __f, * const __frame = &__f;\n" );
|
2002-07-16 03:20:45 +00:00
|
|
|
/* local variables */
|
|
|
|
if (has_ret) {
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy( "" );
|
2009-01-05 23:33:27 +00:00
|
|
|
write_type_decl_left(proxy, get_func_return_type(func));
|
2004-09-10 19:34:14 +00:00
|
|
|
print_proxy( " _RetVal;\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
2007-01-26 11:04:40 +00:00
|
|
|
print_proxy( "RPC_MESSAGE _RpcMessage;\n" );
|
2007-12-10 14:24:11 +00:00
|
|
|
if (has_ret) {
|
2009-01-05 23:33:27 +00:00
|
|
|
if (decl_indirect(get_func_return_type(func)))
|
2007-12-10 14:24:11 +00:00
|
|
|
print_proxy("void *_p_%s = &%s;\n",
|
|
|
|
"_RetVal", "_RetVal");
|
|
|
|
}
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy( "\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
print_proxy( "RpcExceptionInit( __proxy_filter, __finally_%s_%s_Proxy );\n", iface->name, get_name(func) );
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy( "__frame->This = This;\n" );
|
|
|
|
|
2008-01-30 22:29:39 +00:00
|
|
|
if (has_full_pointer)
|
2009-01-05 23:33:27 +00:00
|
|
|
write_full_pointer_init(proxy, indent, func, FALSE);
|
2008-01-30 22:29:39 +00:00
|
|
|
|
2002-07-16 03:20:45 +00:00
|
|
|
/* FIXME: trace */
|
2009-01-05 23:33:27 +00:00
|
|
|
clear_output_vars( type_get_function_args(func->type) );
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2004-09-08 19:01:42 +00:00
|
|
|
print_proxy( "RpcTryExcept\n" );
|
|
|
|
print_proxy( "{\n" );
|
2004-09-06 20:25:39 +00:00
|
|
|
indent++;
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy( "NdrProxyInitialize(This, &_RpcMessage, &__frame->_StubMsg, &Object_StubDesc, %d);\n", idx);
|
2009-01-05 23:33:27 +00:00
|
|
|
proxy_check_pointers( type_get_function_args(func->type) );
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy( "RpcTryFinally\n" );
|
2004-09-08 19:01:42 +00:00
|
|
|
print_proxy( "{\n" );
|
2004-09-06 20:25:39 +00:00
|
|
|
indent++;
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
write_remoting_arguments(proxy, indent, func, "", PASS_IN, PHASE_BUFFERSIZE);
|
2007-01-26 11:00:42 +00:00
|
|
|
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy( "NdrProxyGetBuffer(This, &__frame->_StubMsg);\n" );
|
2007-01-26 11:00:42 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
write_remoting_arguments(proxy, indent, func, "", PASS_IN, PHASE_MARSHAL);
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy( "NdrProxySendReceive(This, &__frame->_StubMsg);\n" );
|
2004-09-10 19:34:14 +00:00
|
|
|
fprintf(proxy, "\n");
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy( "__frame->_StubMsg.BufferStart = _RpcMessage.Buffer;\n" );
|
|
|
|
print_proxy( "__frame->_StubMsg.BufferEnd = __frame->_StubMsg.BufferStart + _RpcMessage.BufferLength;\n\n" );
|
2007-01-26 11:04:40 +00:00
|
|
|
|
|
|
|
print_proxy("if ((_RpcMessage.DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
|
2004-09-10 19:34:14 +00:00
|
|
|
indent++;
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy("NdrConvert( &__frame->_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
|
2004-09-10 19:34:14 +00:00
|
|
|
indent--;
|
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
write_remoting_arguments(proxy, indent, func, "", PASS_OUT, PHASE_UNMARSHAL);
|
2007-01-26 11:00:42 +00:00
|
|
|
|
|
|
|
if (has_ret)
|
2007-12-10 14:24:11 +00:00
|
|
|
{
|
2009-01-05 23:33:27 +00:00
|
|
|
if (decl_indirect(get_func_return_type(func)))
|
2007-12-10 14:24:11 +00:00
|
|
|
print_proxy("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
|
2009-01-05 23:33:27 +00:00
|
|
|
else if (is_ptr(get_func_return_type(func)) || is_array(get_func_return_type(func)))
|
2007-12-10 14:24:11 +00:00
|
|
|
print_proxy("%s = 0;\n", "_RetVal");
|
2009-01-05 23:33:27 +00:00
|
|
|
write_remoting_arguments(proxy, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL);
|
2007-12-10 14:24:11 +00:00
|
|
|
}
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2004-09-06 20:25:39 +00:00
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy( "RpcFinally\n" );
|
2004-09-08 19:01:42 +00:00
|
|
|
print_proxy( "{\n" );
|
2004-09-06 20:25:39 +00:00
|
|
|
indent++;
|
2009-01-05 23:33:27 +00:00
|
|
|
print_proxy( "__finally_%s_%s_Proxy( __frame );\n", iface->name, get_name(func) );
|
2004-09-06 20:25:39 +00:00
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
|
|
|
print_proxy( "RpcEndFinally\n" );
|
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n" );
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy( "RpcExcept(__frame->_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy( "{\n" );
|
|
|
|
if (has_ret) {
|
|
|
|
indent++;
|
2009-01-05 23:33:27 +00:00
|
|
|
proxy_free_variables( type_get_function_args(func->type), "" );
|
2004-09-10 19:34:14 +00:00
|
|
|
print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
|
2004-09-06 20:25:39 +00:00
|
|
|
indent--;
|
|
|
|
}
|
|
|
|
print_proxy( "}\n" );
|
|
|
|
print_proxy( "RpcEndExcept\n" );
|
2002-07-16 03:20:45 +00:00
|
|
|
|
|
|
|
if (has_ret) {
|
2004-09-10 19:34:14 +00:00
|
|
|
print_proxy( "return _RetVal;\n" );
|
2004-09-06 20:25:39 +00:00
|
|
|
}
|
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
}
|
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
static void gen_stub(type_t *iface, const var_t *func, const char *cas,
|
2007-05-16 00:45:59 +00:00
|
|
|
unsigned int proc_offset)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2007-01-22 13:26:12 +00:00
|
|
|
const var_t *arg;
|
2009-01-05 23:33:27 +00:00
|
|
|
int has_ret = !is_void(get_func_return_type(func));
|
|
|
|
int has_full_pointer = is_full_pointer_function(func);
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2004-09-06 20:25:39 +00:00
|
|
|
indent = 0;
|
2009-01-05 23:33:27 +00:00
|
|
|
print_proxy( "struct __frame_%s_%s_Stub\n{\n", iface->name, get_name(func));
|
2008-09-15 16:03:44 +00:00
|
|
|
indent++;
|
|
|
|
print_proxy( "__DECL_EXCEPTION_FRAME\n" );
|
|
|
|
print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n");
|
|
|
|
print_proxy( "%s * _This;\n", iface->name );
|
2009-01-05 23:33:27 +00:00
|
|
|
declare_stub_args( proxy, indent, func );
|
2008-09-15 16:03:44 +00:00
|
|
|
indent--;
|
|
|
|
print_proxy( "};\n\n" );
|
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
print_proxy( "static void __finally_%s_%s_Stub(", iface->name, get_name(func) );
|
|
|
|
print_proxy( " struct __frame_%s_%s_Stub *__frame )\n{\n", iface->name, get_name(func) );
|
2008-09-15 16:03:44 +00:00
|
|
|
indent++;
|
2009-01-05 23:33:27 +00:00
|
|
|
write_remoting_arguments(proxy, indent, func, "__frame->", PASS_OUT, PHASE_FREE);
|
2008-09-15 16:03:44 +00:00
|
|
|
if (has_full_pointer)
|
2009-01-05 23:33:27 +00:00
|
|
|
write_full_pointer_free(proxy, indent, func);
|
2008-09-15 16:03:44 +00:00
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n\n" );
|
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
print_proxy( "void __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(func));
|
2004-09-06 20:25:39 +00:00
|
|
|
indent++;
|
|
|
|
print_proxy( "IRpcStubBuffer* This,\n");
|
2007-01-26 11:04:40 +00:00
|
|
|
print_proxy( "IRpcChannelBuffer *_pRpcChannelBuffer,\n");
|
|
|
|
print_proxy( "PRPC_MESSAGE _pRpcMessage,\n");
|
2004-09-09 19:18:10 +00:00
|
|
|
print_proxy( "DWORD* _pdwStubPhase)\n");
|
2004-09-06 20:25:39 +00:00
|
|
|
indent--;
|
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
2008-09-15 16:03:44 +00:00
|
|
|
print_proxy( "struct __frame_%s_%s_Stub __f, * const __frame = &__f;\n\n",
|
2009-01-05 23:33:27 +00:00
|
|
|
iface->name, get_name(func) );
|
2008-09-15 16:03:44 +00:00
|
|
|
|
|
|
|
print_proxy("__frame->_This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n\n", iface->name);
|
2002-07-16 03:20:45 +00:00
|
|
|
|
|
|
|
/* FIXME: trace */
|
|
|
|
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy("NdrStubInitialize(_pRpcMessage, &__frame->_StubMsg, &Object_StubDesc, _pRpcChannelBuffer);\n");
|
2004-09-06 20:25:39 +00:00
|
|
|
fprintf(proxy, "\n");
|
2009-01-05 23:33:27 +00:00
|
|
|
print_proxy( "RpcExceptionInit( 0, __finally_%s_%s_Stub );\n", iface->name, get_name(func) );
|
2004-09-06 20:25:39 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
write_parameters_init(proxy, indent, func, "__frame->");
|
2007-01-26 11:03:02 +00:00
|
|
|
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy("RpcTryFinally\n");
|
2004-09-08 19:01:42 +00:00
|
|
|
print_proxy("{\n");
|
|
|
|
indent++;
|
2008-01-30 22:29:39 +00:00
|
|
|
if (has_full_pointer)
|
2009-01-05 23:33:27 +00:00
|
|
|
write_full_pointer_init(proxy, indent, func, TRUE);
|
2007-01-26 11:04:40 +00:00
|
|
|
print_proxy("if ((_pRpcMessage->DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
|
2004-09-10 19:34:14 +00:00
|
|
|
indent++;
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy("NdrConvert( &__frame->_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
|
2004-09-10 19:34:14 +00:00
|
|
|
indent--;
|
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
write_remoting_arguments(proxy, indent, func, "__frame->", PASS_IN, PHASE_UNMARSHAL);
|
2004-09-09 19:18:10 +00:00
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
assign_stub_out_args( proxy, indent, func, "__frame->" );
|
2007-01-26 11:00:42 +00:00
|
|
|
|
2004-09-09 19:18:10 +00:00
|
|
|
print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
|
|
|
|
fprintf(proxy, "\n");
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy("");
|
2008-09-15 16:03:44 +00:00
|
|
|
if (has_ret) fprintf(proxy, "__frame->_RetVal = ");
|
2007-01-26 11:09:14 +00:00
|
|
|
if (cas) fprintf(proxy, "%s_%s_Stub", iface->name, cas);
|
2009-01-05 23:33:27 +00:00
|
|
|
else fprintf(proxy, "__frame->_This->lpVtbl->%s", get_name(func));
|
2008-09-15 16:03:44 +00:00
|
|
|
fprintf(proxy, "(__frame->_This");
|
2007-01-22 13:26:12 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
if (type_get_function_args(func->type))
|
2007-01-22 13:26:12 +00:00
|
|
|
{
|
2009-01-05 23:33:27 +00:00
|
|
|
LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), const var_t, entry )
|
2008-09-15 16:03:44 +00:00
|
|
|
fprintf(proxy, ", %s__frame->%s", arg->type->declarray ? "*" : "", arg->name);
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
fprintf(proxy, ");\n");
|
2004-09-09 19:18:10 +00:00
|
|
|
fprintf(proxy, "\n");
|
|
|
|
print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
|
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
write_remoting_arguments(proxy, indent, func, "__frame->", PASS_OUT, PHASE_BUFFERSIZE);
|
2007-01-26 11:00:42 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
if (!is_void(get_func_return_type(func)))
|
|
|
|
write_remoting_arguments(proxy, indent, func, "__frame->", PASS_RETURN, PHASE_BUFFERSIZE);
|
2008-04-02 11:55:34 +00:00
|
|
|
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy("NdrStubGetBuffer(This, _pRpcChannelBuffer, &__frame->_StubMsg);\n");
|
2007-01-26 11:00:42 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
write_remoting_arguments(proxy, indent, func, "__frame->", PASS_OUT, PHASE_MARSHAL);
|
2004-09-09 19:18:10 +00:00
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2008-04-02 11:55:34 +00:00
|
|
|
/* marshall the return value */
|
2009-01-05 23:33:27 +00:00
|
|
|
if (!is_void(get_func_return_type(func)))
|
|
|
|
write_remoting_arguments(proxy, indent, func, "__frame->", PASS_RETURN, PHASE_MARSHAL);
|
2004-09-08 19:01:42 +00:00
|
|
|
|
|
|
|
indent--;
|
|
|
|
print_proxy("}\n");
|
2008-09-15 12:05:26 +00:00
|
|
|
print_proxy("RpcFinally\n");
|
2004-09-08 19:01:42 +00:00
|
|
|
print_proxy("{\n");
|
2008-09-15 16:03:44 +00:00
|
|
|
indent++;
|
2009-01-05 23:33:27 +00:00
|
|
|
print_proxy( "__finally_%s_%s_Stub( __frame );\n", iface->name, get_name(func) );
|
2008-09-15 16:03:44 +00:00
|
|
|
indent--;
|
2004-09-08 19:01:42 +00:00
|
|
|
print_proxy("}\n");
|
|
|
|
print_proxy("RpcEndFinally\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2008-09-15 12:02:26 +00:00
|
|
|
print_proxy("_pRpcMessage->BufferLength = __frame->_StubMsg.Buffer - (unsigned char *)_pRpcMessage->Buffer;\n");
|
2004-09-06 20:25:39 +00:00
|
|
|
indent--;
|
2002-07-16 03:20:45 +00:00
|
|
|
|
2004-09-06 20:25:39 +00:00
|
|
|
print_proxy("}\n");
|
|
|
|
print_proxy("\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 13:51:17 +00:00
|
|
|
static int count_methods(type_t *iface)
|
|
|
|
{
|
2009-01-05 23:33:27 +00:00
|
|
|
const statement_t *stmt;
|
2008-12-01 13:51:17 +00:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (iface->ref) count = count_methods(iface->ref);
|
2009-01-05 23:33:27 +00:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
|
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
if (!is_callas(func->attrs)) count++;
|
|
|
|
}
|
2008-12-01 13:51:17 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2008-09-02 16:01:53 +00:00
|
|
|
static int write_proxy_methods(type_t *iface, int skip)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2009-01-05 23:33:27 +00:00
|
|
|
const statement_t *stmt;
|
2002-07-16 03:20:45 +00:00
|
|
|
int i = 0;
|
2004-09-13 18:05:47 +00:00
|
|
|
|
2008-11-28 11:55:59 +00:00
|
|
|
if (iface->ref) i = write_proxy_methods(iface->ref, need_delegation(iface));
|
2009-01-05 23:33:27 +00:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
|
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
if (!is_callas(func->attrs)) {
|
2004-09-10 19:34:14 +00:00
|
|
|
if (i) fprintf(proxy, ",\n");
|
2009-01-05 23:33:27 +00:00
|
|
|
if (skip) print_proxy( "0 /* %s_%s_Proxy */", iface->name, get_name(func));
|
|
|
|
else print_proxy( "%s_%s_Proxy", iface->name, get_name(func));
|
2002-07-16 03:20:45 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2008-09-02 16:01:53 +00:00
|
|
|
static int write_stub_methods(type_t *iface, int skip)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2009-01-05 23:33:27 +00:00
|
|
|
const statement_t *stmt;
|
2002-07-16 03:20:45 +00:00
|
|
|
int i = 0;
|
2004-09-13 18:05:47 +00:00
|
|
|
|
2008-12-08 14:11:26 +00:00
|
|
|
if (iface->ref) i = write_stub_methods(iface->ref, need_delegation(iface));
|
2002-07-16 03:20:45 +00:00
|
|
|
else return i; /* skip IUnknown */
|
2007-01-22 13:23:08 +00:00
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
|
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
if (!is_local(func->attrs)) {
|
2004-09-10 19:34:14 +00:00
|
|
|
if (i) fprintf(proxy,",\n");
|
2008-09-02 16:01:53 +00:00
|
|
|
if (skip) print_proxy("STUB_FORWARDING_FUNCTION");
|
2009-01-05 23:33:27 +00:00
|
|
|
else print_proxy( "%s_%s_Stub", iface->name, get_name(func));
|
2002-07-16 03:20:45 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2007-05-16 00:45:59 +00:00
|
|
|
static void write_proxy(type_t *iface, unsigned int *proc_offset)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2008-12-01 13:51:17 +00:00
|
|
|
int midx = -1, count;
|
2009-01-05 23:33:27 +00:00
|
|
|
const statement_t *stmt;
|
|
|
|
int first_func = 1;
|
2002-07-16 03:20:45 +00:00
|
|
|
|
|
|
|
/* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
|
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
|
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
if (first_func) {
|
|
|
|
fprintf(proxy, "/*****************************************************************************\n");
|
|
|
|
fprintf(proxy, " * %s interface\n", iface->name);
|
|
|
|
fprintf(proxy, " */\n");
|
|
|
|
first_func = 0;
|
|
|
|
}
|
|
|
|
if (!is_local(func->attrs)) {
|
|
|
|
const var_t *cas = is_callas(func->attrs);
|
2005-12-26 12:11:33 +00:00
|
|
|
const char *cname = cas ? cas->name : NULL;
|
2009-01-05 23:33:27 +00:00
|
|
|
int idx = func->type->details.function->idx;
|
2002-07-16 03:20:45 +00:00
|
|
|
if (cname) {
|
2009-01-05 23:33:27 +00:00
|
|
|
const statement_t *stmt2;
|
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt2, iface->details.iface->stmts) {
|
|
|
|
const var_t *m = stmt2->u.var;
|
|
|
|
if (!strcmp(m->name, cname))
|
2007-01-22 13:23:08 +00:00
|
|
|
{
|
2009-01-05 23:33:27 +00:00
|
|
|
idx = m->type->details.function->idx;
|
2007-01-22 13:23:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-01-05 23:33:27 +00:00
|
|
|
}
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
2009-01-05 23:33:27 +00:00
|
|
|
gen_proxy(iface, func, idx, *proc_offset);
|
|
|
|
gen_stub(iface, func, cname, *proc_offset);
|
|
|
|
*proc_offset += get_size_procformatstring_func( func );
|
2002-07-16 03:20:45 +00:00
|
|
|
if (midx == -1) midx = idx;
|
2007-10-24 03:18:18 +00:00
|
|
|
else if (midx != idx) error("method index mismatch in write_proxy\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
midx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-05 23:33:27 +00:00
|
|
|
/* interface didn't have any methods - search in inherited interfaces */
|
|
|
|
if (midx == -1) {
|
|
|
|
const type_t *inherit_iface;
|
|
|
|
for (inherit_iface = iface->ref; inherit_iface; inherit_iface = inherit_iface->ref) {
|
|
|
|
STATEMENTS_FOR_EACH_FUNC(stmt, inherit_iface->details.iface->stmts) {
|
|
|
|
const var_t *func = stmt->u.var;
|
|
|
|
int idx = func->type->details.function->idx;
|
|
|
|
if (idx + 1 > midx) midx = idx + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 13:51:17 +00:00
|
|
|
count = count_methods(iface);
|
|
|
|
if (midx != -1 && midx != count) error("invalid count %u/%u\n", count, midx);
|
|
|
|
|
2002-07-16 03:20:45 +00:00
|
|
|
/* proxy vtable */
|
2008-12-01 13:51:17 +00:00
|
|
|
print_proxy( "static const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", count, iface->name);
|
2004-09-21 20:04:47 +00:00
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
|
|
|
print_proxy( "{\n", iface->name);
|
|
|
|
indent++;
|
|
|
|
print_proxy( "&IID_%s,\n", iface->name);
|
|
|
|
indent--;
|
|
|
|
print_proxy( "},\n");
|
2004-09-10 19:34:14 +00:00
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
2008-09-02 16:01:53 +00:00
|
|
|
write_proxy_methods(iface, FALSE);
|
2004-09-21 20:04:47 +00:00
|
|
|
fprintf(proxy, "\n");
|
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
2004-09-10 19:34:14 +00:00
|
|
|
indent--;
|
|
|
|
print_proxy( "};\n");
|
2004-09-21 20:04:47 +00:00
|
|
|
fprintf(proxy, "\n\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
|
|
|
|
/* stub vtable */
|
2004-09-10 19:34:14 +00:00
|
|
|
print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface->name);
|
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
2008-12-01 13:51:17 +00:00
|
|
|
write_stub_methods(iface, FALSE);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(proxy, "\n");
|
2004-09-10 19:34:14 +00:00
|
|
|
indent--;
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(proxy, "};\n");
|
2004-09-10 19:34:14 +00:00
|
|
|
print_proxy( "\n");
|
2008-12-01 10:30:05 +00:00
|
|
|
print_proxy( "static %sCInterfaceStubVtbl _%sStubVtbl =\n",
|
2009-01-01 10:25:39 +00:00
|
|
|
need_delegation_indirect(iface) ? "" : "const ", iface->name);
|
2004-09-21 20:04:47 +00:00
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
|
|
|
print_proxy( "{\n");
|
2004-09-10 19:34:14 +00:00
|
|
|
indent++;
|
2004-09-21 20:04:47 +00:00
|
|
|
print_proxy( "&IID_%s,\n", iface->name);
|
|
|
|
print_proxy( "0,\n");
|
2008-12-01 13:51:17 +00:00
|
|
|
print_proxy( "%d,\n", count);
|
2004-09-21 20:04:47 +00:00
|
|
|
print_proxy( "&%s_table[-3],\n", iface->name);
|
|
|
|
indent--;
|
|
|
|
print_proxy( "},\n", iface->name);
|
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
2009-01-01 10:25:39 +00:00
|
|
|
print_proxy( "CStdStubBuffer_%s\n", need_delegation_indirect(iface) ? "DELEGATING_METHODS" : "METHODS");
|
2004-09-21 20:04:47 +00:00
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
2004-09-10 19:34:14 +00:00
|
|
|
indent--;
|
|
|
|
print_proxy( "};\n");
|
|
|
|
print_proxy( "\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
}
|
|
|
|
|
2008-04-24 18:06:28 +00:00
|
|
|
static int does_any_iface(const statement_list_t *stmts, type_pred_t pred)
|
2007-10-16 01:06:33 +00:00
|
|
|
{
|
2008-04-24 18:06:28 +00:00
|
|
|
const statement_t *stmt;
|
2007-10-16 01:06:33 +00:00
|
|
|
|
2008-04-24 18:06:28 +00:00
|
|
|
if (stmts)
|
|
|
|
LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
|
|
|
|
{
|
|
|
|
if (stmt->type == STMT_LIBRARY)
|
|
|
|
{
|
|
|
|
if (does_any_iface(stmt->u.lib->stmts, pred))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
|
|
|
|
{
|
|
|
|
if (pred(stmt->u.type))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2007-10-16 01:06:33 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int need_proxy(const type_t *iface)
|
|
|
|
{
|
|
|
|
return is_object(iface->attrs) && !is_local(iface->attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
int need_stub(const type_t *iface)
|
|
|
|
{
|
|
|
|
return !is_object(iface->attrs) && !is_local(iface->attrs);
|
|
|
|
}
|
|
|
|
|
2008-04-24 18:06:28 +00:00
|
|
|
int need_proxy_file(const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
return does_any_iface(stmts, need_proxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
int need_stub_files(const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
return does_any_iface(stmts, need_stub);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_proxy_stmts(const statement_list_t *stmts, unsigned int *proc_offset)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
|
|
|
if (stmt->type == STMT_LIBRARY)
|
|
|
|
write_proxy_stmts(stmt->u.lib->stmts, proc_offset);
|
|
|
|
else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
|
|
|
|
{
|
|
|
|
if (need_proxy(stmt->u.type))
|
|
|
|
write_proxy(stmt->u.type, proc_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 15:25:45 +00:00
|
|
|
static int cmp_iid( const void *ptr1, const void *ptr2 )
|
2007-10-16 01:06:33 +00:00
|
|
|
{
|
2008-12-01 15:25:45 +00:00
|
|
|
const type_t * const *iface1 = ptr1;
|
|
|
|
const type_t * const *iface2 = ptr2;
|
|
|
|
const UUID *uuid1 = get_attrp( (*iface1)->attrs, ATTR_UUID );
|
|
|
|
const UUID *uuid2 = get_attrp( (*iface2)->attrs, ATTR_UUID );
|
|
|
|
return memcmp( uuid1, uuid2, sizeof(UUID) );
|
2007-10-16 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 15:25:45 +00:00
|
|
|
static void build_iface_list( const statement_list_t *stmts, type_t **ifaces[], int *count )
|
2008-11-28 11:55:59 +00:00
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
|
|
|
|
if (!stmts) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
|
|
|
if (stmt->type == STMT_LIBRARY)
|
2008-12-01 15:25:45 +00:00
|
|
|
build_iface_list(stmt->u.lib->stmts, ifaces, count);
|
2008-11-28 11:55:59 +00:00
|
|
|
else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
|
|
|
|
{
|
|
|
|
type_t *iface = stmt->u.type;
|
2008-12-01 13:51:17 +00:00
|
|
|
if (iface->ref && need_proxy(iface))
|
2008-11-28 11:55:59 +00:00
|
|
|
{
|
2008-12-01 15:25:45 +00:00
|
|
|
*ifaces = xrealloc( *ifaces, (*count + 1) * sizeof(*ifaces) );
|
|
|
|
(*ifaces)[(*count)++] = iface;
|
2008-11-28 11:55:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 15:25:45 +00:00
|
|
|
static type_t **sort_interfaces( const statement_list_t *stmts, int *count )
|
2007-10-16 01:06:33 +00:00
|
|
|
{
|
2008-12-01 15:25:45 +00:00
|
|
|
type_t **ifaces = NULL;
|
|
|
|
|
|
|
|
*count = 0;
|
|
|
|
build_iface_list( stmts, &ifaces, count );
|
|
|
|
qsort( ifaces, *count, sizeof(*ifaces), cmp_iid );
|
|
|
|
return ifaces;
|
2007-10-16 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2008-12-26 16:22:25 +00:00
|
|
|
static void write_proxy_routines(const statement_list_t *stmts)
|
2002-07-16 03:20:45 +00:00
|
|
|
{
|
2007-10-26 22:33:13 +00:00
|
|
|
int expr_eval_routines;
|
2007-05-16 00:45:59 +00:00
|
|
|
unsigned int proc_offset = 0;
|
2008-12-26 16:20:53 +00:00
|
|
|
|
|
|
|
write_formatstringsdecl(proxy, indent, stmts, need_proxy);
|
|
|
|
write_stubdescproto();
|
2008-04-24 18:06:28 +00:00
|
|
|
write_proxy_stmts(stmts, &proc_offset);
|
2004-01-07 04:21:27 +00:00
|
|
|
|
2007-10-26 22:33:13 +00:00
|
|
|
expr_eval_routines = write_expr_eval_routines(proxy, proxy_token);
|
|
|
|
if (expr_eval_routines)
|
|
|
|
write_expr_eval_routine_list(proxy, proxy_token);
|
2007-06-13 23:13:04 +00:00
|
|
|
write_user_quad_list(proxy);
|
2007-10-26 22:33:13 +00:00
|
|
|
write_stubdesc(expr_eval_routines);
|
2004-09-13 18:05:47 +00:00
|
|
|
|
2008-12-26 16:22:25 +00:00
|
|
|
print_proxy( "#if !defined(__RPC_WIN%u__)\n", pointer_size == 8 ? 64 : 32);
|
2004-09-13 18:05:47 +00:00
|
|
|
print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
|
|
|
|
print_proxy( "#endif\n");
|
|
|
|
print_proxy( "\n");
|
2008-04-24 18:06:28 +00:00
|
|
|
write_procformatstring(proxy, stmts, need_proxy);
|
|
|
|
write_typeformatstring(proxy, stmts, need_proxy);
|
2004-09-13 18:05:47 +00:00
|
|
|
|
2008-12-26 16:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_proxies(const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
char *file_id = proxy_token;
|
|
|
|
int i, count, have_baseiid;
|
|
|
|
type_t **interfaces;
|
2009-01-01 10:25:39 +00:00
|
|
|
const type_t * delegate_to;
|
2008-12-26 16:22:25 +00:00
|
|
|
|
|
|
|
if (!do_proxies) return;
|
|
|
|
if (do_everything && !need_proxy_file(stmts)) return;
|
|
|
|
|
|
|
|
init_proxy(stmts);
|
|
|
|
if(!proxy) return;
|
|
|
|
|
|
|
|
if (do_win32 && do_win64)
|
|
|
|
{
|
|
|
|
fprintf(proxy, "\n#ifndef _WIN64\n\n");
|
|
|
|
pointer_size = 4;
|
|
|
|
write_proxy_routines( stmts );
|
|
|
|
fprintf(proxy, "\n#else /* _WIN64 */\n\n");
|
|
|
|
pointer_size = 8;
|
|
|
|
write_proxy_routines( stmts );
|
|
|
|
fprintf(proxy, "#endif /* _WIN64 */\n\n");
|
|
|
|
}
|
|
|
|
else if (do_win32)
|
|
|
|
{
|
|
|
|
pointer_size = 4;
|
|
|
|
write_proxy_routines( stmts );
|
|
|
|
}
|
|
|
|
else if (do_win64)
|
|
|
|
{
|
|
|
|
pointer_size = 8;
|
|
|
|
write_proxy_routines( stmts );
|
|
|
|
}
|
|
|
|
|
2008-12-01 15:25:45 +00:00
|
|
|
interfaces = sort_interfaces(stmts, &count);
|
2007-01-26 11:09:25 +00:00
|
|
|
fprintf(proxy, "static const CInterfaceProxyVtbl* const _%s_ProxyVtblList[] =\n", file_id);
|
2004-09-08 19:01:42 +00:00
|
|
|
fprintf(proxy, "{\n");
|
2008-12-01 15:25:45 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
fprintf(proxy, " (const CInterfaceProxyVtbl*)&_%sProxyVtbl,\n", interfaces[i]->name);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(proxy, " 0\n");
|
|
|
|
fprintf(proxy, "};\n");
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
2007-01-26 11:09:25 +00:00
|
|
|
fprintf(proxy, "static const CInterfaceStubVtbl* const _%s_StubVtblList[] =\n", file_id);
|
2004-09-08 19:01:42 +00:00
|
|
|
fprintf(proxy, "{\n");
|
2008-12-01 15:25:45 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
fprintf(proxy, " &_%sStubVtbl,\n", interfaces[i]->name);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(proxy, " 0\n");
|
|
|
|
fprintf(proxy, "};\n");
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
2007-01-26 11:09:25 +00:00
|
|
|
fprintf(proxy, "static PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id);
|
2004-09-08 19:01:42 +00:00
|
|
|
fprintf(proxy, "{\n");
|
2008-12-01 15:25:45 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
fprintf(proxy, " \"%s\",\n", interfaces[i]->name);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(proxy, " 0\n");
|
|
|
|
fprintf(proxy, "};\n");
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
2009-01-01 10:25:39 +00:00
|
|
|
if ((have_baseiid = does_any_iface(stmts, need_delegation_indirect)))
|
2008-11-28 11:55:59 +00:00
|
|
|
{
|
|
|
|
fprintf(proxy, "static const IID * _%s_BaseIIDList[] =\n", file_id);
|
|
|
|
fprintf(proxy, "{\n");
|
2008-12-01 15:25:45 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2009-01-01 10:25:39 +00:00
|
|
|
if (get_delegation_indirect(interfaces[i], &delegate_to))
|
|
|
|
fprintf( proxy, " &IID_%s, /* %s */\n", delegate_to->name, interfaces[i]->name );
|
2008-12-01 15:25:45 +00:00
|
|
|
else
|
|
|
|
fprintf( proxy, " 0,\n" );
|
|
|
|
}
|
2008-11-28 11:55:59 +00:00
|
|
|
fprintf(proxy, " 0\n");
|
|
|
|
fprintf(proxy, "};\n");
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
}
|
|
|
|
|
2008-12-01 15:25:45 +00:00
|
|
|
fprintf(proxy, "static int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id);
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(proxy, "{\n");
|
2008-12-01 15:25:45 +00:00
|
|
|
fprintf(proxy, " int low = 0, high = %d;\n", count - 1);
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
fprintf(proxy, " while (low <= high)\n");
|
|
|
|
fprintf(proxy, " {\n");
|
|
|
|
fprintf(proxy, " int pos = (low + high) / 2;\n");
|
|
|
|
fprintf(proxy, " int res = IID_GENERIC_CHECK_IID(_%s, pIID, pos);\n", file_id);
|
|
|
|
fprintf(proxy, " if (!res) { *pIndex = pos; return 1; }\n");
|
|
|
|
fprintf(proxy, " if (res > 0) low = pos + 1;\n");
|
|
|
|
fprintf(proxy, " else high = pos - 1;\n");
|
|
|
|
fprintf(proxy, " }\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(proxy, " return 0;\n");
|
|
|
|
fprintf(proxy, "}\n");
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
2008-12-01 13:39:39 +00:00
|
|
|
fprintf(proxy, "const ExtendedProxyFileInfo %s_ProxyFileInfo DECLSPEC_HIDDEN =\n", file_id);
|
2004-09-08 19:01:42 +00:00
|
|
|
fprintf(proxy, "{\n");
|
2008-12-06 23:49:59 +00:00
|
|
|
fprintf(proxy, " (const PCInterfaceProxyVtblList*)_%s_ProxyVtblList,\n", file_id);
|
|
|
|
fprintf(proxy, " (const PCInterfaceStubVtblList*)_%s_StubVtblList,\n", file_id);
|
2007-01-26 11:09:25 +00:00
|
|
|
fprintf(proxy, " _%s_InterfaceNamesList,\n", file_id);
|
2008-11-28 11:55:59 +00:00
|
|
|
if (have_baseiid) fprintf(proxy, " _%s_BaseIIDList,\n", file_id);
|
|
|
|
else fprintf(proxy, " 0,\n");
|
2008-12-06 23:50:03 +00:00
|
|
|
fprintf(proxy, " _%s_IID_Lookup,\n", file_id);
|
2008-12-01 15:25:45 +00:00
|
|
|
fprintf(proxy, " %d,\n", count);
|
2004-09-08 19:01:42 +00:00
|
|
|
fprintf(proxy, " 1,\n");
|
|
|
|
fprintf(proxy, " 0,\n");
|
|
|
|
fprintf(proxy, " 0,\n");
|
|
|
|
fprintf(proxy, " 0,\n");
|
|
|
|
fprintf(proxy, " 0\n");
|
2002-07-16 03:20:45 +00:00
|
|
|
fprintf(proxy, "};\n");
|
|
|
|
|
|
|
|
fclose(proxy);
|
|
|
|
}
|