2002-07-16 05:20:45 +02:00
|
|
|
/*
|
|
|
|
* IDL Compiler
|
|
|
|
*
|
|
|
|
* Copyright 2002 Ove Kaaven
|
2004-09-06 22:25:39 +02:00
|
|
|
* Copyright 2004 Mike McCormack
|
2002-07-16 05:20:45 +02: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 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-16 05:20:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2005-08-03 23:25:10 +02:00
|
|
|
#include "wine/port.h"
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-17 20:28:43 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-07-16 05:20:45 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
2006-08-17 03:27:47 +02:00
|
|
|
#include "typegen.h"
|
2008-04-22 12:36:38 +02:00
|
|
|
#include "expr.h"
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2004-09-13 20:05:47 +02:00
|
|
|
#define END_OF_LIST(list) \
|
|
|
|
do { \
|
|
|
|
if (list) { \
|
|
|
|
while (NEXT_LINK(list)) \
|
|
|
|
list = NEXT_LINK(list); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2004-01-07 05:21:27 +01:00
|
|
|
static FILE* proxy;
|
2004-09-06 22:25:39 +02:00
|
|
|
static int indent = 0;
|
2004-01-07 05:21:27 +01:00
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
/* FIXME: support generation of stubless proxies */
|
|
|
|
|
2007-06-15 03:29:33 +02:00
|
|
|
static void print_proxy( const char *format, ... )
|
2004-09-06 22:25:39 +02:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start( va, format );
|
2007-06-15 03:29:33 +02:00
|
|
|
print( proxy, indent, format, va );
|
2004-09-06 22:25:39 +02:00
|
|
|
va_end( va );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_stubdescproto(void)
|
|
|
|
{
|
2007-01-26 12:08:51 +01:00
|
|
|
print_proxy( "static const MIDL_STUB_DESC Object_StubDesc;\n");
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy( "\n");
|
|
|
|
}
|
|
|
|
|
2007-10-27 00:33:13 +02:00
|
|
|
static void write_stubdesc(int expr_eval_routines)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2007-01-26 12:08:51 +01: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-27 00:33:13 +02:00
|
|
|
print_proxy( "{0}, 0, 0, %s, 0,\n", expr_eval_routines ? "ExprEvalRoutines" : "0");
|
2007-01-26 12:08:51 +01: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-14 01:13:04 +02:00
|
|
|
print_proxy("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
|
2007-01-26 12:08:51 +01: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 22:25:39 +02:00
|
|
|
print_proxy( "};\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
}
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
static void init_proxy(const statement_list_t *stmts)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
|
|
|
if (proxy) return;
|
2004-10-11 21:54:37 +02:00
|
|
|
if(!(proxy = fopen(proxy_name, "w")))
|
|
|
|
error("Could not open %s for output\n", proxy_name);
|
2006-08-11 01:51:28 +02:00
|
|
|
print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
|
2004-09-08 21:01:42 +02:00
|
|
|
print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
|
|
|
|
print_proxy( "\n");
|
2007-01-26 12:09:03 +01:00
|
|
|
print_proxy( "#define __midl_proxy\n");
|
2007-01-19 13:17:17 +01:00
|
|
|
print_proxy( "#include \"objbase.h\"\n");
|
2004-09-06 22:25:39 +02: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-07-03 12:59:37 +02:00
|
|
|
print_proxy( "#ifndef USE_COMPILER_EXCEPTIONS\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#include \"wine/exception.h\"\n");
|
|
|
|
print_proxy( "#undef RpcTryExcept\n");
|
|
|
|
print_proxy( "#undef RpcExcept\n");
|
|
|
|
print_proxy( "#undef RpcEndExcept\n");
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy( "#undef RpcTryFinally\n");
|
|
|
|
print_proxy( "#undef RpcFinally\n");
|
|
|
|
print_proxy( "#undef RpcEndFinally\n");
|
2008-07-03 12:59:37 +02:00
|
|
|
print_proxy( "#undef RpcExceptionCode\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "struct __proxy_frame\n");
|
|
|
|
print_proxy( "{\n");
|
|
|
|
print_proxy( " EXCEPTION_REGISTRATION_RECORD frame;\n");
|
|
|
|
print_proxy( " sigjmp_buf jmp;\n");
|
|
|
|
print_proxy( " DWORD code;\n");
|
|
|
|
print_proxy( " MIDL_STUB_MESSAGE *stub;\n");
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy( " void *this;\n");
|
|
|
|
print_proxy( " int fullptr;\n");
|
2008-07-03 12:59:37 +02:00
|
|
|
print_proxy( "};\n");
|
|
|
|
print_proxy( "\n");
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy("static void __proxy_finally_handler( struct __proxy_frame *frame )\n");
|
|
|
|
print_proxy( "{\n");
|
|
|
|
print_proxy( " if (frame->fullptr) NdrFullPointerXlatFree( frame->stub->FullPtrXlatTables );\n");
|
|
|
|
print_proxy( " if (frame->this) NdrProxyFreeBuffer( frame->this, frame->stub );\n" );
|
|
|
|
print_proxy( "}\n\n");
|
2008-07-03 12:59:37 +02:00
|
|
|
print_proxy( "static DWORD __proxy_exception_handler( EXCEPTION_RECORD *record,\n");
|
|
|
|
print_proxy( " EXCEPTION_REGISTRATION_RECORD *frame,\n");
|
|
|
|
print_proxy( " CONTEXT *context,\n");
|
|
|
|
print_proxy( " EXCEPTION_REGISTRATION_RECORD **pdispatcher )\n");
|
|
|
|
print_proxy( "{\n");
|
|
|
|
print_proxy( " struct __proxy_frame *proxy_frame = (struct __proxy_frame *)frame;\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( " if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND | EH_NESTED_CALL))\n");
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy( " {\n" );
|
|
|
|
print_proxy( " if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))\n");
|
|
|
|
print_proxy( " __proxy_finally_handler( proxy_frame );\n");
|
2008-07-03 12:59:37 +02:00
|
|
|
print_proxy( " return ExceptionContinueSearch;\n");
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy( " }\n" );
|
2008-07-03 12:59:37 +02:00
|
|
|
print_proxy( " if (proxy_frame->stub->dwStubPhase == PROXY_SENDRECEIVE)\n");
|
|
|
|
print_proxy( " return ExceptionContinueSearch;\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( " proxy_frame->code = record->ExceptionCode;\n");
|
|
|
|
print_proxy( " __wine_rtl_unwind( frame, record );\n");
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy( " __proxy_finally_handler( proxy_frame );\n");
|
2008-07-03 12:59:37 +02:00
|
|
|
print_proxy( " __wine_pop_frame( frame );\n");
|
|
|
|
print_proxy( " siglongjmp( proxy_frame->jmp, 1 );\n");
|
|
|
|
print_proxy( "}\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#define RpcTryExcept \\\n");
|
|
|
|
print_proxy( " do { \\\n");
|
|
|
|
print_proxy( " struct __proxy_frame __proxy_frame; \\\n");
|
|
|
|
print_proxy( " __proxy_frame.frame.Handler = __proxy_exception_handler; \\\n");
|
|
|
|
print_proxy( " __proxy_frame.stub = &_StubMsg; \\\n");
|
|
|
|
print_proxy( " if (!sigsetjmp( __proxy_frame.jmp, 0 )) \\\n");
|
|
|
|
print_proxy( " { \\\n");
|
|
|
|
print_proxy( " __wine_push_frame( &__proxy_frame.frame ); \\\n");
|
|
|
|
print_proxy( " {\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#define RpcExcept(expr) \\\n");
|
|
|
|
print_proxy( " } \\\n");
|
|
|
|
print_proxy( " __wine_pop_frame( &__proxy_frame.frame ); \\\n");
|
|
|
|
print_proxy( " } \\\n");
|
|
|
|
print_proxy( " else \\\n");
|
|
|
|
print_proxy( " {\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#define RpcEndExcept \\\n");
|
|
|
|
print_proxy( " } \\\n");
|
|
|
|
print_proxy( " } while(0);\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#define RpcExceptionCode() (__proxy_frame.code)\n");
|
|
|
|
print_proxy( "\n");
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy( "#define RpcTryFinallyProxy(ptr) \\\n");
|
|
|
|
print_proxy(" __proxy_frame.this = This; \\\n");
|
|
|
|
print_proxy(" __proxy_frame.fullptr = ptr;\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#define RpcFinallyProxy \\\n");
|
|
|
|
print_proxy(" __proxy_frame.this = 0; \\\n");
|
|
|
|
print_proxy(" __proxy_frame.fullptr = 0;\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#define RpcTryFinallyStub\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#define RpcFinallyStub\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#define RpcEndFinally\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#else /* USE_COMPILER_EXCEPTIONS */\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
print_proxy( "#define RpcTryFinallyProxy(ptr) RpcTryFinally\n");
|
|
|
|
print_proxy( "#define RpcTryFinallyStub RpcTryFinally\n");
|
|
|
|
print_proxy( "#define RpcFinallyProxy RpcFinally\n");
|
|
|
|
print_proxy( "#define RpcFinallyStub RpcFinally\n");
|
|
|
|
print_proxy( "\n");
|
2008-07-03 12:59:37 +02:00
|
|
|
print_proxy( "#endif /* USE_COMPILER_EXCEPTIONS */\n");
|
|
|
|
print_proxy( "\n");
|
2008-04-24 20:06:28 +02:00
|
|
|
write_formatstringsdecl(proxy, indent, stmts, need_proxy);
|
2004-09-06 22:25:39 +02:00
|
|
|
write_stubdescproto();
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
static void clear_output_vars( const var_list_t *args )
|
2004-09-02 22:07:07 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *arg;
|
|
|
|
|
|
|
|
if (!args) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
|
|
|
|
{
|
2004-09-06 22:25:39 +02:00
|
|
|
if (is_attr(arg->attrs, ATTR_OUT) && !is_attr(arg->attrs, ATTR_IN)) {
|
|
|
|
print_proxy( "if(%s)\n", arg->name );
|
2004-09-08 21:01:42 +02:00
|
|
|
indent++;
|
2006-08-15 01:45:56 +02:00
|
|
|
print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg->name, arg->name );
|
2004-09-08 21:01:42 +02:00
|
|
|
indent--;
|
2004-09-02 22:07:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
int is_var_ptr(const var_t *v)
|
2004-09-13 20:05:47 +02:00
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
return is_ptr(v->type);
|
2004-09-13 20:05:47 +02:00
|
|
|
}
|
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
int cant_be_null(const var_t *v)
|
2006-08-12 02:33:40 +02:00
|
|
|
{
|
|
|
|
/* Search backwards for the most recent pointer attribute. */
|
2007-01-22 14:20:36 +01:00
|
|
|
const attr_list_t *attrs = v->attrs;
|
2006-08-12 02:33:40 +02:00
|
|
|
const type_t *type = v->type;
|
|
|
|
|
2008-08-26 21:05:17 +02: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;
|
|
|
|
|
2006-08-12 02:33:40 +02:00
|
|
|
if (! attrs && type)
|
|
|
|
{
|
|
|
|
attrs = type->attrs;
|
|
|
|
type = type->ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
{
|
|
|
|
attrs = type->attrs;
|
|
|
|
type = type->ref;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
attrs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1; /* Default is RPC_FC_RP. */
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
static void proxy_check_pointers( const var_list_t *args )
|
2004-09-13 20:05:47 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *arg;
|
|
|
|
|
|
|
|
if (!args) return;
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
|
|
|
|
{
|
2006-08-29 23:27:27 +02:00
|
|
|
if (is_var_ptr(arg) && cant_be_null(arg)) {
|
2004-09-13 20:05:47 +02:00
|
|
|
print_proxy( "if(!%s)\n", arg->name );
|
|
|
|
indent++;
|
|
|
|
print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
|
|
|
|
indent--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
static void free_variable( const var_t *arg )
|
2004-09-20 21:11:16 +02:00
|
|
|
{
|
2007-05-21 08:55:43 +02:00
|
|
|
unsigned int type_offset = arg->type->typestring_offset;
|
2007-12-10 14:30:48 +01:00
|
|
|
expr_t *iid;
|
2007-11-02 23:25:26 +01:00
|
|
|
type_t *type = arg->type;
|
|
|
|
expr_t *size = get_size_is_expr(type, arg->name);
|
2004-09-10 21:34:14 +02:00
|
|
|
|
2007-11-02 23:25:26 +01:00
|
|
|
if (size)
|
2004-09-20 21:11:16 +02:00
|
|
|
{
|
2007-02-06 18:01:43 +01:00
|
|
|
print_proxy( "_StubMsg.MaxCount = " );
|
2008-04-22 12:37:07 +02:00
|
|
|
write_expr(proxy, size, 0, 1, NULL, NULL);
|
2004-09-20 21:11:16 +02:00
|
|
|
fprintf(proxy, ";\n\n");
|
|
|
|
print_proxy( "NdrClearOutParameters( &_StubMsg, ");
|
2007-02-06 18:01:43 +01:00
|
|
|
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
|
2004-09-20 21:11:16 +02:00
|
|
|
fprintf(proxy, "(void*)%s );\n", arg->name );
|
|
|
|
return;
|
|
|
|
}
|
2004-09-10 21:34:14 +02:00
|
|
|
|
2004-09-20 21:11:16 +02: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 14:30:48 +01:00
|
|
|
iid = get_attrp( arg->attrs, ATTR_IIDIS );
|
|
|
|
if( iid )
|
|
|
|
{
|
|
|
|
print_proxy( "_StubMsg.MaxCount = (unsigned long) " );
|
2008-04-22 12:37:07 +02:00
|
|
|
write_expr(proxy, iid, 1, 1, NULL, NULL);
|
2007-12-10 14:30:48 +01:00
|
|
|
print_proxy( ";\n\n" );
|
|
|
|
}
|
2004-09-20 21:11:16 +02:00
|
|
|
print_proxy( "NdrClearOutParameters( &_StubMsg, ");
|
2007-02-06 18:01:43 +01:00
|
|
|
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
|
2004-09-20 21:11:16 +02: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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
static void proxy_free_variables( var_list_t *args )
|
2004-09-20 21:11:16 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01: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 21:11:16 +02:00
|
|
|
{
|
2007-05-16 02:45:59 +02:00
|
|
|
free_variable( arg );
|
2004-09-20 21:11:16 +02:00
|
|
|
fprintf(proxy, "\n");
|
2004-09-10 21:34:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-26 12:00:42 +01:00
|
|
|
static void gen_proxy(type_t *iface, const func_t *cur, int idx,
|
2007-05-16 02:45:59 +02:00
|
|
|
unsigned int proc_offset)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
|
|
|
var_t *def = cur->def;
|
2008-04-02 13:55:34 +02:00
|
|
|
int has_ret = !is_void(get_func_return_type(cur));
|
2008-01-30 23:29:39 +01:00
|
|
|
int has_full_pointer = is_full_pointer_function(cur);
|
2008-04-11 12:01:36 +02:00
|
|
|
const char *callconv = get_attrp(def->type->attrs, ATTR_CALLCONV);
|
|
|
|
if (!callconv) callconv = "";
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2004-09-06 22:25:39 +02:00
|
|
|
indent = 0;
|
2008-04-02 13:55:34 +02:00
|
|
|
write_type_decl_left(proxy, get_func_return_type(cur));
|
2008-08-30 11:15:04 +02:00
|
|
|
print_proxy( " %s %s_%s_Proxy(\n", callconv, iface->name, get_name(def));
|
2003-09-03 22:16:24 +02:00
|
|
|
write_args(proxy, cur->args, iface->name, 1, TRUE);
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy( ")\n");
|
|
|
|
print_proxy( "{\n");
|
|
|
|
indent ++;
|
2002-07-16 05:20:45 +02:00
|
|
|
/* local variables */
|
|
|
|
if (has_ret) {
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy( "" );
|
2008-04-02 13:55:34 +02:00
|
|
|
write_type_decl_left(proxy, get_func_return_type(cur));
|
2004-09-10 21:34:14 +02:00
|
|
|
print_proxy( " _RetVal;\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
2007-01-26 12:04:40 +01:00
|
|
|
print_proxy( "RPC_MESSAGE _RpcMessage;\n" );
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
|
2007-12-10 15:24:11 +01:00
|
|
|
if (has_ret) {
|
2008-04-02 13:55:34 +02:00
|
|
|
if (decl_indirect(get_func_return_type(cur)))
|
2007-12-10 15:24:11 +01:00
|
|
|
print_proxy("void *_p_%s = &%s;\n",
|
|
|
|
"_RetVal", "_RetVal");
|
|
|
|
}
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy( "\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2008-01-30 23:29:39 +01:00
|
|
|
if (has_full_pointer)
|
|
|
|
write_full_pointer_init(proxy, indent, cur, FALSE);
|
|
|
|
|
2002-07-16 05:20:45 +02:00
|
|
|
/* FIXME: trace */
|
2004-09-02 22:07:07 +02:00
|
|
|
clear_output_vars( cur->args );
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2004-09-08 21:01:42 +02:00
|
|
|
print_proxy( "RpcTryExcept\n" );
|
|
|
|
print_proxy( "{\n" );
|
2004-09-06 22:25:39 +02:00
|
|
|
indent++;
|
2007-01-26 12:04:40 +01:00
|
|
|
print_proxy( "NdrProxyInitialize(This, &_RpcMessage, &_StubMsg, &Object_StubDesc, %d);\n", idx);
|
2004-09-13 20:05:47 +02:00
|
|
|
proxy_check_pointers( cur->args );
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy( "RpcTryFinallyProxy(%d)\n", has_full_pointer );
|
2004-09-08 21:01:42 +02:00
|
|
|
print_proxy( "{\n" );
|
2004-09-06 22:25:39 +02:00
|
|
|
indent++;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_BUFFERSIZE);
|
2007-01-26 12:00:42 +01:00
|
|
|
|
|
|
|
print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
|
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_MARSHAL);
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
|
2004-09-10 21:34:14 +02:00
|
|
|
fprintf(proxy, "\n");
|
2007-01-26 12:04:40 +01:00
|
|
|
print_proxy( "_StubMsg.BufferStart = _RpcMessage.Buffer;\n" );
|
|
|
|
print_proxy( "_StubMsg.BufferEnd = _StubMsg.BufferStart + _RpcMessage.BufferLength;\n\n" );
|
|
|
|
|
|
|
|
print_proxy("if ((_RpcMessage.DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
|
2004-09-10 21:34:14 +02:00
|
|
|
indent++;
|
2007-01-26 12:00:42 +01:00
|
|
|
print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
|
2004-09-10 21:34:14 +02:00
|
|
|
indent--;
|
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_UNMARSHAL);
|
2007-01-26 12:00:42 +01:00
|
|
|
|
|
|
|
if (has_ret)
|
2007-12-10 15:24:11 +01:00
|
|
|
{
|
2008-04-02 13:55:34 +02:00
|
|
|
if (decl_indirect(get_func_return_type(cur)))
|
2007-12-10 15:24:11 +01:00
|
|
|
print_proxy("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
|
2008-04-02 13:55:34 +02:00
|
|
|
else if (is_ptr(get_func_return_type(cur)) || is_array(get_func_return_type(cur)))
|
2007-12-10 15:24:11 +01:00
|
|
|
print_proxy("%s = 0;\n", "_RetVal");
|
|
|
|
write_remoting_arguments(proxy, indent, cur, PASS_RETURN, PHASE_UNMARSHAL);
|
|
|
|
}
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2004-09-06 22:25:39 +02:00
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy( "RpcFinallyProxy\n" );
|
2004-09-08 21:01:42 +02:00
|
|
|
print_proxy( "{\n" );
|
2004-09-06 22:25:39 +02:00
|
|
|
indent++;
|
2008-01-30 23:29:39 +01:00
|
|
|
if (has_full_pointer)
|
|
|
|
write_full_pointer_free(proxy, indent, cur);
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
|
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
|
|
|
print_proxy( "RpcEndFinally\n" );
|
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n" );
|
|
|
|
print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
|
|
|
|
print_proxy( "{\n" );
|
|
|
|
if (has_ret) {
|
|
|
|
indent++;
|
2007-05-16 02:45:59 +02:00
|
|
|
proxy_free_variables( cur->args );
|
2004-09-10 21:34:14 +02:00
|
|
|
print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
|
2004-09-06 22:25:39 +02:00
|
|
|
indent--;
|
|
|
|
}
|
|
|
|
print_proxy( "}\n" );
|
|
|
|
print_proxy( "RpcEndExcept\n" );
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
if (has_ret) {
|
2004-09-10 21:34:14 +02:00
|
|
|
print_proxy( "return _RetVal;\n" );
|
2004-09-06 22:25:39 +02:00
|
|
|
}
|
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
|
|
|
print_proxy( "\n");
|
|
|
|
}
|
|
|
|
|
2007-01-26 12:00:42 +01:00
|
|
|
static void gen_stub(type_t *iface, const func_t *cur, const char *cas,
|
2007-05-16 02:45:59 +02:00
|
|
|
unsigned int proc_offset)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
|
|
|
var_t *def = cur->def;
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *arg;
|
2008-04-02 13:55:34 +02:00
|
|
|
int has_ret = !is_void(get_func_return_type(cur));
|
2008-01-30 23:29:39 +01:00
|
|
|
int has_full_pointer = is_full_pointer_function(cur);
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2004-09-06 22:25:39 +02:00
|
|
|
indent = 0;
|
2008-08-30 11:15:04 +02:00
|
|
|
print_proxy( "void __RPC_STUB %s_%s_Stub(\n", iface->name, get_name(def));
|
2004-09-06 22:25:39 +02:00
|
|
|
indent++;
|
|
|
|
print_proxy( "IRpcStubBuffer* This,\n");
|
2007-01-26 12:04:40 +01:00
|
|
|
print_proxy( "IRpcChannelBuffer *_pRpcChannelBuffer,\n");
|
|
|
|
print_proxy( "PRPC_MESSAGE _pRpcMessage,\n");
|
2004-09-09 21:18:10 +02:00
|
|
|
print_proxy( "DWORD* _pdwStubPhase)\n");
|
2004-09-06 22:25:39 +02:00
|
|
|
indent--;
|
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
2004-09-13 20:05:47 +02:00
|
|
|
print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface->name, iface->name);
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
|
2007-01-26 12:00:42 +01:00
|
|
|
declare_stub_args( proxy, indent, cur );
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
|
|
|
/* FIXME: trace */
|
|
|
|
|
2007-01-26 12:04:40 +01:00
|
|
|
print_proxy("NdrStubInitialize(_pRpcMessage, &_StubMsg, &Object_StubDesc, _pRpcChannelBuffer);\n");
|
2004-09-06 22:25:39 +02:00
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
2007-06-15 03:30:26 +02:00
|
|
|
write_parameters_init(proxy, indent, cur);
|
2007-01-26 12:03:02 +01:00
|
|
|
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy("RpcTryFinallyStub\n");
|
2004-09-08 21:01:42 +02:00
|
|
|
print_proxy("{\n");
|
|
|
|
indent++;
|
2008-01-30 23:29:39 +01:00
|
|
|
if (has_full_pointer)
|
|
|
|
write_full_pointer_init(proxy, indent, cur, TRUE);
|
2007-01-26 12:04:40 +01:00
|
|
|
print_proxy("if ((_pRpcMessage->DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
|
2004-09-10 21:34:14 +02:00
|
|
|
indent++;
|
2007-01-26 12:00:42 +01:00
|
|
|
print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
|
2004-09-10 21:34:14 +02:00
|
|
|
indent--;
|
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_UNMARSHAL);
|
2004-09-09 21:18:10 +02:00
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2007-01-26 12:00:42 +01:00
|
|
|
assign_stub_out_args( proxy, indent, cur );
|
|
|
|
|
2004-09-09 21:18:10 +02:00
|
|
|
print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
|
|
|
|
fprintf(proxy, "\n");
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy("");
|
2004-09-10 21:34:14 +02:00
|
|
|
if (has_ret) fprintf(proxy, "_RetVal = ");
|
2007-01-26 12:09:14 +01:00
|
|
|
if (cas) fprintf(proxy, "%s_%s_Stub", iface->name, cas);
|
2008-08-30 11:15:04 +02:00
|
|
|
else fprintf(proxy, "_This->lpVtbl->%s", get_name(def));
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, "(_This");
|
2007-01-22 14:26:12 +01:00
|
|
|
|
|
|
|
if (cur->args)
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
|
2008-08-30 11:15:04 +02:00
|
|
|
fprintf(proxy, ", %s%s", arg->type->declarray ? "*" : "", get_name(arg));
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
fprintf(proxy, ");\n");
|
2004-09-09 21:18:10 +02:00
|
|
|
fprintf(proxy, "\n");
|
|
|
|
print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
|
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_BUFFERSIZE);
|
2007-01-26 12:00:42 +01:00
|
|
|
|
2008-04-02 13:55:34 +02:00
|
|
|
if (!is_void(get_func_return_type(cur)))
|
|
|
|
write_remoting_arguments(proxy, indent, cur, PASS_RETURN, PHASE_BUFFERSIZE);
|
|
|
|
|
2007-01-26 12:04:40 +01:00
|
|
|
print_proxy("NdrStubGetBuffer(This, _pRpcChannelBuffer, &_StubMsg);\n");
|
2007-01-26 12:00:42 +01:00
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_MARSHAL);
|
2004-09-09 21:18:10 +02:00
|
|
|
fprintf(proxy, "\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2008-04-02 13:55:34 +02:00
|
|
|
/* marshall the return value */
|
|
|
|
if (!is_void(get_func_return_type(cur)))
|
|
|
|
write_remoting_arguments(proxy, indent, cur, PASS_RETURN, PHASE_MARSHAL);
|
2004-09-08 21:01:42 +02:00
|
|
|
|
|
|
|
indent--;
|
|
|
|
print_proxy("}\n");
|
2008-08-30 11:25:22 +02:00
|
|
|
print_proxy("RpcFinallyStub\n");
|
2004-09-08 21:01:42 +02:00
|
|
|
print_proxy("{\n");
|
2007-01-26 12:00:42 +01:00
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
write_remoting_arguments(proxy, indent+1, cur, PASS_OUT, PHASE_FREE);
|
2007-01-26 12:00:42 +01:00
|
|
|
|
2008-01-30 23:29:39 +01:00
|
|
|
if (has_full_pointer)
|
|
|
|
write_full_pointer_free(proxy, indent, cur);
|
|
|
|
|
2004-09-08 21:01:42 +02:00
|
|
|
print_proxy("}\n");
|
|
|
|
print_proxy("RpcEndFinally\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2007-01-26 12:04:40 +01:00
|
|
|
print_proxy("_pRpcMessage->BufferLength = _StubMsg.Buffer - (unsigned char *)_pRpcMessage->Buffer;\n");
|
2004-09-06 22:25:39 +02:00
|
|
|
indent--;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2004-09-06 22:25:39 +02:00
|
|
|
print_proxy("}\n");
|
|
|
|
print_proxy("\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2008-09-02 18:01:53 +02:00
|
|
|
static int write_proxy_methods(type_t *iface, int skip)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2007-01-22 14:23:08 +01:00
|
|
|
const func_t *cur;
|
2002-07-16 05:20:45 +02:00
|
|
|
int i = 0;
|
2004-09-13 20:05:47 +02:00
|
|
|
|
2008-09-02 18:01:53 +02:00
|
|
|
if (iface->ref) i = write_proxy_methods(iface->ref, iface->ref->ref != NULL);
|
2007-01-22 14:23:08 +01:00
|
|
|
if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
|
2002-07-16 05:20:45 +02:00
|
|
|
var_t *def = cur->def;
|
|
|
|
if (!is_callas(def->attrs)) {
|
2004-09-10 21:34:14 +02:00
|
|
|
if (i) fprintf(proxy, ",\n");
|
2008-09-02 18:01:53 +02:00
|
|
|
if (skip) print_proxy( "0 /* %s_%s_Proxy */", iface->name, get_name(def));
|
|
|
|
else print_proxy( "%s_%s_Proxy", iface->name, get_name(def));
|
2002-07-16 05:20:45 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2008-09-02 18:01:53 +02:00
|
|
|
static int write_stub_methods(type_t *iface, int skip)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2007-01-22 14:23:08 +01:00
|
|
|
const func_t *cur;
|
2002-07-16 05:20:45 +02:00
|
|
|
int i = 0;
|
2004-09-13 20:05:47 +02:00
|
|
|
|
2008-09-02 18:01:53 +02:00
|
|
|
if (iface->ref) i = write_stub_methods(iface->ref, TRUE);
|
2002-07-16 05:20:45 +02:00
|
|
|
else return i; /* skip IUnknown */
|
2007-01-22 14:23:08 +01:00
|
|
|
|
|
|
|
if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
|
2002-07-16 05:20:45 +02:00
|
|
|
var_t *def = cur->def;
|
|
|
|
if (!is_local(def->attrs)) {
|
2004-09-10 21:34:14 +02:00
|
|
|
if (i) fprintf(proxy,",\n");
|
2008-09-02 18:01:53 +02:00
|
|
|
if (skip) print_proxy("STUB_FORWARDING_FUNCTION");
|
|
|
|
else print_proxy( "%s_%s_Stub", iface->name, get_name(def));
|
2002-07-16 05:20:45 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
static void write_proxy(type_t *iface, unsigned int *proc_offset)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
|
|
|
int midx = -1, stubs;
|
2007-01-22 14:23:08 +01:00
|
|
|
const func_t *cur;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2007-01-22 14:23:08 +01:00
|
|
|
if (!iface->funcs) return;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
/* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
|
|
|
|
|
|
|
|
fprintf(proxy, "/*****************************************************************************\n");
|
|
|
|
fprintf(proxy, " * %s interface\n", iface->name);
|
|
|
|
fprintf(proxy, " */\n");
|
2007-01-22 14:23:08 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
|
|
|
|
{
|
2006-02-07 12:31:43 +01:00
|
|
|
const var_t *def = cur->def;
|
2002-07-16 05:20:45 +02:00
|
|
|
if (!is_local(def->attrs)) {
|
2006-02-07 12:31:43 +01:00
|
|
|
const var_t *cas = is_callas(def->attrs);
|
2005-12-26 13:11:33 +01:00
|
|
|
const char *cname = cas ? cas->name : NULL;
|
2002-07-16 05:20:45 +02:00
|
|
|
int idx = cur->idx;
|
|
|
|
if (cname) {
|
2007-01-22 14:23:08 +01:00
|
|
|
const func_t *m;
|
|
|
|
LIST_FOR_EACH_ENTRY( m, iface->funcs, const func_t, entry )
|
2007-06-06 03:49:12 +02:00
|
|
|
if (!strcmp(m->def->name, cname))
|
2007-01-22 14:23:08 +01:00
|
|
|
{
|
|
|
|
idx = m->idx;
|
|
|
|
break;
|
|
|
|
}
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
2007-05-16 02:45:59 +02:00
|
|
|
gen_proxy(iface, cur, idx, *proc_offset);
|
|
|
|
gen_stub(iface, cur, cname, *proc_offset);
|
2007-01-26 12:00:42 +01:00
|
|
|
*proc_offset += get_size_procformatstring_func( cur );
|
2002-07-16 05:20:45 +02:00
|
|
|
if (midx == -1) midx = idx;
|
2007-10-24 05:18:18 +02:00
|
|
|
else if (midx != idx) error("method index mismatch in write_proxy\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
midx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* proxy vtable */
|
2007-01-26 12:09:25 +01:00
|
|
|
print_proxy( "static const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx, iface->name);
|
2004-09-21 22:04:47 +02: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 21:34:14 +02:00
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
2008-09-02 18:01:53 +02:00
|
|
|
write_proxy_methods(iface, FALSE);
|
2004-09-21 22:04:47 +02:00
|
|
|
fprintf(proxy, "\n");
|
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
2004-09-10 21:34:14 +02:00
|
|
|
indent--;
|
|
|
|
print_proxy( "};\n");
|
2004-09-21 22:04:47 +02:00
|
|
|
fprintf(proxy, "\n\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
|
|
|
|
/* stub vtable */
|
2004-09-10 21:34:14 +02:00
|
|
|
print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface->name);
|
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
2008-09-02 18:01:53 +02:00
|
|
|
stubs = write_stub_methods(iface, FALSE);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, "\n");
|
2004-09-10 21:34:14 +02:00
|
|
|
indent--;
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, "};\n");
|
2004-09-10 21:34:14 +02:00
|
|
|
print_proxy( "\n");
|
2007-01-26 12:09:25 +01:00
|
|
|
print_proxy( "static const CInterfaceStubVtbl _%sStubVtbl =\n", iface->name);
|
2004-09-21 22:04:47 +02:00
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
|
|
|
print_proxy( "{\n");
|
2004-09-10 21:34:14 +02:00
|
|
|
indent++;
|
2004-09-21 22:04:47 +02:00
|
|
|
print_proxy( "&IID_%s,\n", iface->name);
|
|
|
|
print_proxy( "0,\n");
|
|
|
|
print_proxy( "%d,\n", stubs+3);
|
|
|
|
print_proxy( "&%s_table[-3],\n", iface->name);
|
|
|
|
indent--;
|
|
|
|
print_proxy( "},\n", iface->name);
|
|
|
|
print_proxy( "{\n");
|
|
|
|
indent++;
|
|
|
|
print_proxy( "CStdStubBuffer_METHODS\n");
|
|
|
|
indent--;
|
|
|
|
print_proxy( "}\n");
|
2004-09-10 21:34:14 +02:00
|
|
|
indent--;
|
|
|
|
print_proxy( "};\n");
|
|
|
|
print_proxy( "\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
}
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
static int does_any_iface(const statement_list_t *stmts, type_pred_t pred)
|
2007-10-16 03:06:33 +02:00
|
|
|
{
|
2008-04-24 20:06:28 +02:00
|
|
|
const statement_t *stmt;
|
2007-10-16 03:06:33 +02:00
|
|
|
|
2008-04-24 20:06:28 +02: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 03:06:33 +02: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 20:06:28 +02: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_proxy_iface_name_format(const statement_list_t *stmts, const char *format)
|
2007-10-16 03:06:33 +02:00
|
|
|
{
|
2008-04-24 20:06:28 +02:00
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
|
|
|
if (stmt->type == STMT_LIBRARY)
|
|
|
|
write_proxy_iface_name_format(stmt->u.lib->stmts, format);
|
|
|
|
else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
|
|
|
|
{
|
|
|
|
type_t *iface = stmt->u.type;
|
|
|
|
if (iface->ref && iface->funcs && need_proxy(iface))
|
|
|
|
fprintf(proxy, format, iface->name);
|
|
|
|
}
|
|
|
|
}
|
2007-10-16 03:06:33 +02:00
|
|
|
}
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
static void write_iid_lookup(const statement_list_t *stmts, const char *file_id, int *c)
|
2007-10-16 03:06:33 +02:00
|
|
|
{
|
2008-04-24 20:06:28 +02:00
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
|
|
|
if (stmt->type == STMT_LIBRARY)
|
|
|
|
write_iid_lookup(stmt->u.lib->stmts, file_id, c);
|
|
|
|
else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
|
|
|
|
{
|
|
|
|
type_t *iface = stmt->u.type;
|
|
|
|
if(iface->ref && iface->funcs && need_proxy(iface))
|
|
|
|
{
|
|
|
|
fprintf(proxy, " if (!_%s_CHECK_IID(%d))\n", file_id, *c);
|
|
|
|
fprintf(proxy, " {\n");
|
|
|
|
fprintf(proxy, " *pIndex = %d;\n", *c);
|
|
|
|
fprintf(proxy, " return 1;\n");
|
|
|
|
fprintf(proxy, " }\n");
|
|
|
|
(*c)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-16 03:06:33 +02:00
|
|
|
}
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
void write_proxies(const statement_list_t *stmts)
|
2002-07-16 05:20:45 +02:00
|
|
|
{
|
2007-10-27 00:33:13 +02:00
|
|
|
int expr_eval_routines;
|
2002-12-03 20:12:07 +01:00
|
|
|
char *file_id = proxy_token;
|
2002-07-16 05:20:45 +02:00
|
|
|
int c;
|
2007-05-16 02:45:59 +02:00
|
|
|
unsigned int proc_offset = 0;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2005-01-26 20:40:47 +01:00
|
|
|
if (!do_proxies) return;
|
2008-04-24 20:06:28 +02:00
|
|
|
if (do_everything && !need_proxy_file(stmts)) return;
|
2004-09-13 20:05:47 +02:00
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
init_proxy(stmts);
|
2004-10-11 21:54:37 +02:00
|
|
|
if(!proxy) return;
|
2002-07-16 05:20:45 +02:00
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
write_proxy_stmts(stmts, &proc_offset);
|
2004-01-07 05:21:27 +01:00
|
|
|
|
2007-10-27 00:33:13 +02: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-14 01:13:04 +02:00
|
|
|
write_user_quad_list(proxy);
|
2007-10-27 00:33:13 +02:00
|
|
|
write_stubdesc(expr_eval_routines);
|
2004-09-13 20:05:47 +02:00
|
|
|
|
|
|
|
print_proxy( "#if !defined(__RPC_WIN32__)\n");
|
|
|
|
print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
|
|
|
|
print_proxy( "#endif\n");
|
|
|
|
print_proxy( "\n");
|
2008-04-24 20:06:28 +02:00
|
|
|
write_procformatstring(proxy, stmts, need_proxy);
|
|
|
|
write_typeformatstring(proxy, stmts, need_proxy);
|
2004-09-13 20:05:47 +02:00
|
|
|
|
2007-01-26 12:09:25 +01:00
|
|
|
fprintf(proxy, "static const CInterfaceProxyVtbl* const _%s_ProxyVtblList[] =\n", file_id);
|
2004-09-08 21:01:42 +02:00
|
|
|
fprintf(proxy, "{\n");
|
2008-04-24 20:06:28 +02:00
|
|
|
write_proxy_iface_name_format(stmts, " (const CInterfaceProxyVtbl*)&_%sProxyVtbl,\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, " 0\n");
|
|
|
|
fprintf(proxy, "};\n");
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
2007-01-26 12:09:25 +01:00
|
|
|
fprintf(proxy, "static const CInterfaceStubVtbl* const _%s_StubVtblList[] =\n", file_id);
|
2004-09-08 21:01:42 +02:00
|
|
|
fprintf(proxy, "{\n");
|
2008-04-24 20:06:28 +02:00
|
|
|
write_proxy_iface_name_format(stmts, " (const CInterfaceStubVtbl*)&_%sStubVtbl,\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, " 0\n");
|
|
|
|
fprintf(proxy, "};\n");
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
2007-01-26 12:09:25 +01:00
|
|
|
fprintf(proxy, "static PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id);
|
2004-09-08 21:01:42 +02:00
|
|
|
fprintf(proxy, "{\n");
|
2008-04-24 20:06:28 +02:00
|
|
|
write_proxy_iface_name_format(stmts, " \"%s\",\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, " 0\n");
|
|
|
|
fprintf(proxy, "};\n");
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
2004-09-06 22:25:39 +02:00
|
|
|
fprintf(proxy, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id, file_id);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, "\n");
|
2002-11-12 03:12:35 +01:00
|
|
|
fprintf(proxy, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, "{\n");
|
|
|
|
c = 0;
|
2008-04-24 20:06:28 +02:00
|
|
|
write_iid_lookup(stmts, file_id, &c);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, " return 0;\n");
|
|
|
|
fprintf(proxy, "}\n");
|
|
|
|
fprintf(proxy, "\n");
|
|
|
|
|
2004-09-08 21:01:42 +02:00
|
|
|
fprintf(proxy, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id);
|
|
|
|
fprintf(proxy, "{\n");
|
2007-01-26 12:09:25 +01:00
|
|
|
fprintf(proxy, " (const PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id);
|
|
|
|
fprintf(proxy, " (const PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id);
|
|
|
|
fprintf(proxy, " _%s_InterfaceNamesList,\n", file_id);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, " 0,\n");
|
2002-11-12 03:12:35 +01:00
|
|
|
fprintf(proxy, " &_%s_IID_Lookup,\n", file_id);
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, " %d,\n", c);
|
2004-09-08 21:01:42 +02:00
|
|
|
fprintf(proxy, " 1,\n");
|
|
|
|
fprintf(proxy, " 0,\n");
|
|
|
|
fprintf(proxy, " 0,\n");
|
|
|
|
fprintf(proxy, " 0,\n");
|
|
|
|
fprintf(proxy, " 0\n");
|
2002-07-16 05:20:45 +02:00
|
|
|
fprintf(proxy, "};\n");
|
|
|
|
|
|
|
|
fclose(proxy);
|
|
|
|
}
|