2005-02-23 21:31:07 +01:00
|
|
|
/*
|
|
|
|
* IDL Compiler
|
|
|
|
*
|
2006-03-23 10:33:08 +01:00
|
|
|
* Copyright 2005-2006 Eric Kohl
|
2005-02-23 21:31:07 +01: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
|
2005-02-23 21:31:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2019-07-05 23:51:44 +02:00
|
|
|
|
2005-02-23 21:31:07 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
|
|
|
|
|
|
|
#include "widltypes.h"
|
2005-12-08 12:52:13 +01:00
|
|
|
#include "typegen.h"
|
2008-04-22 12:36:38 +02:00
|
|
|
#include "expr.h"
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
static FILE* client;
|
|
|
|
static int indent = 0;
|
|
|
|
|
2009-02-06 14:31:29 +01:00
|
|
|
static void print_client( const char *format, ... ) __attribute__((format (printf, 1, 2)));
|
2007-06-15 03:29:33 +02:00
|
|
|
static void print_client( const char *format, ... )
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
2007-06-15 03:29:33 +02:00
|
|
|
print(client, indent, format, va);
|
2005-02-23 21:31:07 +01:00
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
static void write_client_func_decl( const type_t *iface, const var_t *func )
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV);
|
2019-08-14 04:08:03 +02:00
|
|
|
const var_list_t *args = type_function_get_args(func->declspec.type);
|
2019-08-16 03:13:19 +02:00
|
|
|
const decl_spec_t *rettype = type_function_get_ret(func->declspec.type);
|
2011-06-03 12:27:14 +02:00
|
|
|
|
2011-06-10 13:40:05 +02:00
|
|
|
if (!callconv) callconv = "__cdecl";
|
2011-06-03 12:27:14 +02:00
|
|
|
write_type_decl_left(client, rettype);
|
2011-06-10 13:40:05 +02:00
|
|
|
fprintf(client, " %s ", callconv);
|
2011-06-03 12:27:14 +02:00
|
|
|
fprintf(client, "%s%s(\n", prefix_client, get_name(func));
|
|
|
|
indent++;
|
widl: Output interface C names in method argument list.
This fixes WinRT interface generation where only simple names were used
instead of the C interface names.
With the previous sample idl:
#ifdef __WIDL__
#pragma winrt ns_prefix
#endif
import "wtypes.idl";
namespace Windows {
[object]
interface IFoo {}
[object]
interface IBar { HRESULT DoBar([in] IFoo *foo); }
}
$ widl -o windows.foo.h windows.foo.idl
Generated file diff before/after:
diff --git a/windows.foo.h b/windows.foo.h
index 3790dc7..65151cb 100644
--- a/windows.foo.h
+++ b/windows.foo.h
@@ -123,7 +123,7 @@ typedef struct __x_ABI_CWindows_CIBarVtbl {
/*** IBar methods ***/
HRESULT (STDMETHODCALLTYPE *DoBar)(
__x_ABI_CWindows_CIBar *This,
- IFoo *foo);
+ __x_ABI_CWindows_CIFoo *foo);
END_INTERFACE
} __x_ABI_CWindows_CIBarVtbl;
@@ -138,7 +138,7 @@ interface __x_ABI_CWindows_CIBar {
#define __x_ABI_CWindows_CIBar_DoBar(This,foo) (This)->lpVtbl->DoBar(This,foo)
#else
/*** IBar methods ***/
-static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,IFoo *foo) {
+static FORCEINLINE HRESULT __x_ABI_CWindows_CIBar_DoBar(__x_ABI_CWindows_CIBar* This,__x_ABI_CWindows_CIFoo *foo) {
return This->lpVtbl->DoBar(This,foo);
}
#endif
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-03 14:52:07 +02:00
|
|
|
if (args) write_args(client, args, iface->name, 0, TRUE, NAME_DEFAULT);
|
2011-06-03 12:27:14 +02:00
|
|
|
else
|
|
|
|
print_client("void");
|
|
|
|
fprintf(client, ")\n");
|
|
|
|
indent--;
|
|
|
|
}
|
2007-05-03 14:25:58 +02:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
static void write_function_stub( const type_t *iface, const var_t *func,
|
|
|
|
int method_count, unsigned int proc_offset )
|
|
|
|
{
|
|
|
|
unsigned char explicit_fc, implicit_fc;
|
|
|
|
int has_full_pointer = is_full_pointer_function(func);
|
2019-07-05 23:49:49 +02:00
|
|
|
var_t *retval = type_function_get_retval(func->declspec.type);
|
2011-06-03 12:27:14 +02:00
|
|
|
const var_t *handle_var = get_func_handle_var( iface, func, &explicit_fc, &implicit_fc );
|
2019-07-05 23:49:49 +02:00
|
|
|
int has_ret = !is_void(retval->declspec.type);
|
2011-06-03 12:27:14 +02:00
|
|
|
|
|
|
|
if (is_interpreted_func( iface, func ))
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2011-06-03 12:27:14 +02:00
|
|
|
write_client_func_decl( iface, func );
|
2011-06-09 10:12:48 +02:00
|
|
|
write_client_call_routine( client, iface, func, iface->name, proc_offset );
|
2011-06-03 12:27:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-09-15 18:03:56 +02:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client( "struct __frame_%s%s\n{\n", prefix_client, get_name(func) );
|
|
|
|
indent++;
|
|
|
|
print_client( "__DECL_EXCEPTION_FRAME\n" );
|
|
|
|
print_client("MIDL_STUB_MESSAGE _StubMsg;\n");
|
|
|
|
if (handle_var)
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
if (explicit_fc == FC_BIND_GENERIC)
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("%s %s;\n",
|
|
|
|
get_explicit_generic_handle_type(handle_var)->name, handle_var->name );
|
|
|
|
print_client("RPC_BINDING_HANDLE _Handle;\n");
|
|
|
|
}
|
2008-09-15 18:03:56 +02:00
|
|
|
|
2019-07-05 23:49:49 +02:00
|
|
|
if (has_ret && decl_indirect(retval->declspec.type))
|
2011-06-03 12:27:14 +02:00
|
|
|
{
|
2011-09-17 13:38:15 +02:00
|
|
|
print_client("void *_p_%s;\n", retval->name);
|
2011-06-03 12:27:14 +02:00
|
|
|
}
|
|
|
|
indent--;
|
|
|
|
print_client( "};\n\n" );
|
2008-09-15 18:03:56 +02:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client( "static void __finally_%s%s(", prefix_client, get_name(func) );
|
|
|
|
print_client( " struct __frame_%s%s *__frame )\n{\n", prefix_client, get_name(func) );
|
|
|
|
indent++;
|
2008-09-15 18:03:56 +02:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
if (has_full_pointer)
|
|
|
|
write_full_pointer_free(client, indent, func);
|
2008-09-15 18:03:56 +02:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("NdrFreeBuffer(&__frame->_StubMsg);\n");
|
|
|
|
|
2018-06-13 04:19:11 +02:00
|
|
|
if (explicit_fc == FC_BIND_GENERIC)
|
2011-06-03 12:27:14 +02:00
|
|
|
{
|
|
|
|
fprintf(client, "\n");
|
|
|
|
print_client("if (__frame->_Handle)\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
indent++;
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("%s_unbind(__frame->%s, __frame->_Handle);\n",
|
|
|
|
get_explicit_generic_handle_type(handle_var)->name, handle_var->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
indent--;
|
2011-06-03 12:27:14 +02:00
|
|
|
}
|
|
|
|
indent--;
|
|
|
|
print_client( "}\n\n" );
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
write_client_func_decl( iface, func );
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
/* write the functions body */
|
|
|
|
fprintf(client, "{\n");
|
|
|
|
indent++;
|
|
|
|
print_client( "struct __frame_%s%s __f, * const __frame = &__f;\n", prefix_client, get_name(func) );
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-09-17 13:38:15 +02:00
|
|
|
/* declare return value */
|
2011-06-03 12:27:14 +02:00
|
|
|
if (has_ret)
|
|
|
|
{
|
|
|
|
print_client("%s", "");
|
2019-08-16 03:13:18 +02:00
|
|
|
write_type_decl(client, &retval->declspec, retval->name);
|
2011-09-17 13:38:15 +02:00
|
|
|
fprintf(client, ";\n");
|
2011-06-03 12:27:14 +02:00
|
|
|
}
|
|
|
|
print_client("RPC_MESSAGE _RpcMessage;\n");
|
2008-09-15 18:03:56 +02:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
if (handle_var)
|
|
|
|
{
|
|
|
|
print_client( "__frame->_Handle = 0;\n" );
|
2018-06-13 04:19:11 +02:00
|
|
|
if (explicit_fc == FC_BIND_GENERIC)
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("__frame->%s = %s;\n", handle_var->name, handle_var->name );
|
|
|
|
}
|
2019-07-05 23:49:49 +02:00
|
|
|
if (has_ret && decl_indirect(retval->declspec.type))
|
2011-06-03 12:27:14 +02:00
|
|
|
{
|
2011-09-17 13:38:15 +02:00
|
|
|
print_client("__frame->_p_%s = &%s;\n", retval->name, retval->name);
|
2011-06-03 12:27:14 +02:00
|
|
|
}
|
|
|
|
fprintf(client, "\n");
|
2006-03-29 12:42:29 +02:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client( "RpcExceptionInit( 0, __finally_%s%s );\n", prefix_client, get_name(func) );
|
2008-01-30 23:29:39 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
if (has_full_pointer)
|
|
|
|
write_full_pointer_init(client, indent, func, FALSE);
|
2006-03-29 12:42:29 +02:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
/* check pointers */
|
2011-06-14 12:55:39 +02:00
|
|
|
write_pointer_checks( client, indent, func );
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("RpcTryFinally\n");
|
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("NdrClientInitializeNew(&_RpcMessage, &__frame->_StubMsg, &%s_StubDesc, %d);\n",
|
|
|
|
iface->name, method_count);
|
2008-04-14 11:59:55 +02:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
if (is_attr(func->attrs, ATTR_IDEMPOTENT) || is_attr(func->attrs, ATTR_BROADCAST))
|
|
|
|
{
|
|
|
|
print_client("_RpcMessage.RpcFlags = ( RPC_NCA_FLAGS_DEFAULT ");
|
|
|
|
if (is_attr(func->attrs, ATTR_IDEMPOTENT))
|
|
|
|
fprintf(client, "| RPC_NCA_FLAGS_IDEMPOTENT ");
|
|
|
|
if (is_attr(func->attrs, ATTR_BROADCAST))
|
|
|
|
fprintf(client, "| RPC_NCA_FLAGS_BROADCAST ");
|
|
|
|
fprintf(client, ");\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (explicit_fc)
|
|
|
|
{
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BIND_PRIMITIVE:
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("__frame->_Handle = %s;\n", handle_var->name);
|
|
|
|
fprintf(client, "\n");
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BIND_GENERIC:
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("__frame->_Handle = %s_bind(%s);\n",
|
|
|
|
get_explicit_generic_handle_type(handle_var)->name, handle_var->name);
|
|
|
|
fprintf(client, "\n");
|
|
|
|
break;
|
2018-06-13 04:19:11 +02:00
|
|
|
case FC_BIND_CONTEXT:
|
2011-06-03 12:27:14 +02:00
|
|
|
{
|
|
|
|
/* if the context_handle attribute appears in the chain of types
|
|
|
|
* without pointers being followed, then the context handle must
|
|
|
|
* be direct, otherwise it is a pointer */
|
2019-07-05 23:49:49 +02:00
|
|
|
int is_ch_ptr = !is_aliaschain_attr(handle_var->declspec.type, ATTR_CONTEXTHANDLE);
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("if (%s%s != 0)\n", is_ch_ptr ? "*" : "", handle_var->name);
|
|
|
|
indent++;
|
|
|
|
print_client("__frame->_Handle = NDRCContextBinding(%s%s);\n",
|
|
|
|
is_ch_ptr ? "*" : "", handle_var->name);
|
|
|
|
indent--;
|
|
|
|
if (is_attr(handle_var->attrs, ATTR_IN) && !is_attr(handle_var->attrs, ATTR_OUT))
|
2008-03-26 14:47:30 +01:00
|
|
|
{
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("else\n");
|
2008-03-26 14:47:30 +01:00
|
|
|
indent++;
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);\n");
|
2008-03-26 14:47:30 +01:00
|
|
|
indent--;
|
|
|
|
}
|
2011-06-03 12:27:14 +02:00
|
|
|
fprintf(client, "\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0: /* implicit handle */
|
2011-05-31 13:30:04 +02:00
|
|
|
if (handle_var)
|
2011-06-03 12:27:14 +02:00
|
|
|
{
|
|
|
|
print_client("__frame->_Handle = %s;\n", handle_var->name);
|
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
write_remoting_arguments(client, indent, func, "", PASS_IN, PHASE_BUFFERSIZE);
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("NdrGetBuffer(&__frame->_StubMsg, __frame->_StubMsg.BufferLength, ");
|
|
|
|
if (handle_var)
|
|
|
|
fprintf(client, "__frame->_Handle);\n\n");
|
|
|
|
else
|
|
|
|
fprintf(client,"%s__MIDL_AutoBindHandle);\n\n", iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
/* marshal arguments */
|
|
|
|
write_remoting_arguments(client, indent, func, "", PASS_IN, PHASE_MARSHAL);
|
2005-12-26 13:21:38 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
/* send/receive message */
|
|
|
|
/* print_client("NdrNsSendReceive(\n"); */
|
|
|
|
/* print_client("(unsigned char *)__frame->_StubMsg.Buffer,\n"); */
|
|
|
|
/* print_client("(RPC_BINDING_HANDLE *) &%s__MIDL_AutoBindHandle);\n", iface->name); */
|
|
|
|
print_client("NdrSendReceive(&__frame->_StubMsg, __frame->_StubMsg.Buffer);\n\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("__frame->_StubMsg.BufferStart = _RpcMessage.Buffer;\n");
|
|
|
|
print_client("__frame->_StubMsg.BufferEnd = __frame->_StubMsg.BufferStart + _RpcMessage.BufferLength;\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
if (has_out_arg_or_return(func))
|
|
|
|
{
|
2006-03-24 17:40:17 +01:00
|
|
|
fprintf(client, "\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("if ((_RpcMessage.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
indent++;
|
2011-06-03 12:27:14 +02:00
|
|
|
print_client("NdrConvert(&__frame->_StubMsg, (PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n",
|
|
|
|
proc_offset);
|
2005-02-23 21:31:07 +01:00
|
|
|
indent--;
|
2011-06-03 12:27:14 +02:00
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
/* unmarshall arguments */
|
|
|
|
fprintf(client, "\n");
|
|
|
|
write_remoting_arguments(client, indent, func, "", PASS_OUT, PHASE_UNMARSHAL);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
/* unmarshal return value */
|
|
|
|
if (has_ret)
|
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
if (decl_indirect(retval->declspec.type))
|
2011-09-17 13:38:15 +02:00
|
|
|
print_client("MIDL_memset(&%s, 0, sizeof(%s));\n", retval->name, retval->name);
|
2019-07-05 23:49:49 +02:00
|
|
|
else if (is_ptr(retval->declspec.type) || is_array(retval->declspec.type))
|
2011-09-17 13:38:15 +02:00
|
|
|
print_client("%s = 0;\n", retval->name);
|
2011-06-03 12:27:14 +02:00
|
|
|
write_remoting_arguments(client, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL);
|
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
indent--;
|
|
|
|
print_client("}\n");
|
|
|
|
print_client("RpcFinally\n");
|
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
|
|
|
print_client( "__finally_%s%s( __frame );\n", prefix_client, get_name(func) );
|
|
|
|
indent--;
|
|
|
|
print_client("}\n");
|
|
|
|
print_client("RpcEndFinally\n");
|
|
|
|
|
|
|
|
|
|
|
|
/* emit return code */
|
|
|
|
if (has_ret)
|
|
|
|
{
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(client, "\n");
|
2011-09-17 13:38:15 +02:00
|
|
|
print_client("return %s;\n", retval->name);
|
2011-06-03 12:27:14 +02:00
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
indent--;
|
|
|
|
fprintf(client, "}\n");
|
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
|
|
|
|
2018-11-09 13:51:16 +01:00
|
|
|
static void write_serialize_function(FILE *file, const type_t *type, const type_t *iface,
|
|
|
|
const char *func_name, const char *ret_type)
|
|
|
|
{
|
2018-11-09 13:51:23 +01:00
|
|
|
enum stub_mode mode = get_stub_mode();
|
2019-03-15 19:09:50 +01:00
|
|
|
static int emitted_pickling_info;
|
2018-11-09 13:51:23 +01:00
|
|
|
|
|
|
|
if (iface && !type->typestring_offset)
|
|
|
|
{
|
|
|
|
/* FIXME: Those are mostly basic types. They should be implemented
|
|
|
|
* using NdrMesSimpleType* functions */
|
|
|
|
if (ret_type) warning("Serialization of type %s is not supported\n", type->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-15 19:09:50 +01:00
|
|
|
if (!emitted_pickling_info && iface && mode != MODE_Os)
|
2018-11-09 13:51:23 +01:00
|
|
|
{
|
|
|
|
fprintf(file, "static const MIDL_TYPE_PICKLING_INFO __MIDL_TypePicklingInfo =\n");
|
|
|
|
fprintf(file, "{\n");
|
|
|
|
fprintf(file, " 0x33205054,\n");
|
|
|
|
fprintf(file, " 0x3,\n");
|
|
|
|
fprintf(file, " 0,\n");
|
|
|
|
fprintf(file, " 0,\n");
|
|
|
|
fprintf(file, " 0\n");
|
|
|
|
fprintf(file, "};\n");
|
|
|
|
fprintf(file, "\n");
|
2019-03-15 19:09:50 +01:00
|
|
|
emitted_pickling_info = 1;
|
2018-11-09 13:51:23 +01:00
|
|
|
}
|
|
|
|
|
2018-11-09 13:51:16 +01:00
|
|
|
/* FIXME: Assuming explicit handle */
|
|
|
|
|
|
|
|
fprintf(file, "%s __cdecl %s_%s(handle_t IDL_handle, %s *IDL_type)%s\n",
|
|
|
|
ret_type ? ret_type : "void", type->name, func_name, type->name, iface ? "" : ";");
|
2018-11-09 13:51:23 +01:00
|
|
|
if (!iface) return; /* declaration only */
|
|
|
|
|
|
|
|
fprintf(file, "{\n");
|
|
|
|
fprintf(file, " %sNdrMesType%s%s(\n", ret_type ? "return " : "", func_name,
|
|
|
|
mode != MODE_Os ? "2" : "");
|
|
|
|
fprintf(file, " IDL_handle,\n");
|
|
|
|
if (mode != MODE_Os)
|
|
|
|
fprintf(file, " (MIDL_TYPE_PICKLING_INFO*)&__MIDL_TypePicklingInfo,\n");
|
|
|
|
fprintf(file, " &%s_StubDesc,\n", iface->name);
|
|
|
|
fprintf(file, " (PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%u],\n",
|
|
|
|
type->typestring_offset);
|
|
|
|
fprintf(file, " IDL_type);\n");
|
|
|
|
fprintf(file, "}\n");
|
|
|
|
fprintf(file, "\n");
|
2018-11-09 13:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_serialize_functions(FILE *file, const type_t *type, const type_t *iface)
|
|
|
|
{
|
|
|
|
if (is_attr(type->attrs, ATTR_ENCODE))
|
|
|
|
{
|
|
|
|
write_serialize_function(file, type, iface, "AlignSize", "SIZE_T");
|
|
|
|
write_serialize_function(file, type, iface, "Encode", NULL);
|
|
|
|
}
|
|
|
|
if (is_attr(type->attrs, ATTR_DECODE))
|
|
|
|
{
|
|
|
|
write_serialize_function(file, type, iface, "Decode", NULL);
|
|
|
|
write_serialize_function(file, type, iface, "Free", NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
const var_t *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
|
|
|
int method_count = 0;
|
|
|
|
|
|
|
|
if (!implicit_handle)
|
|
|
|
print_client("static RPC_BINDING_HANDLE %s__MIDL_AutoBindHandle;\n\n", iface->name);
|
|
|
|
|
2018-11-09 13:51:23 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( stmt, type_iface_get_stmts(iface), const statement_t, entry )
|
2011-06-03 12:27:14 +02:00
|
|
|
{
|
2018-11-09 13:51:23 +01:00
|
|
|
switch (stmt->type)
|
|
|
|
{
|
|
|
|
case STMT_DECLARATION:
|
|
|
|
{
|
|
|
|
const var_t *func = stmt->u.var;
|
2019-07-05 23:49:49 +02:00
|
|
|
if (stmt->u.var->declspec.stgclass != STG_NONE
|
|
|
|
|| type_get_type_detect_alias(stmt->u.var->declspec.type) != TYPE_FUNCTION)
|
2018-11-09 13:51:23 +01:00
|
|
|
continue;
|
|
|
|
write_function_stub( iface, func, method_count++, *proc_offset );
|
|
|
|
*proc_offset += get_size_procformatstring_func( iface, func );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STMT_TYPEDEF:
|
|
|
|
{
|
2021-02-17 19:33:33 +01:00
|
|
|
typeref_t *ref;
|
|
|
|
if (stmt->u.type_list) LIST_FOR_EACH_ENTRY(ref, stmt->u.type_list, typeref_t, entry)
|
|
|
|
write_serialize_functions(client, ref->type, iface);
|
2018-11-09 13:51:23 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_stubdescdecl(type_t *iface)
|
|
|
|
{
|
2006-04-16 10:39:37 +02:00
|
|
|
print_client("static const MIDL_STUB_DESC %s_StubDesc;\n", iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
static void write_stubdescriptor(type_t *iface, int expr_eval_routines)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2011-05-31 13:01:32 +02:00
|
|
|
const var_t *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
print_client("static const MIDL_STUB_DESC %s_StubDesc =\n", iface->name);
|
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
2005-12-12 11:51:11 +01:00
|
|
|
print_client("(void *)& %s___RpcClientInterface,\n", iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("MIDL_user_allocate,\n");
|
|
|
|
print_client("MIDL_user_free,\n");
|
2006-03-31 13:46:28 +02:00
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
2005-12-08 12:45:45 +01:00
|
|
|
if (implicit_handle)
|
2011-05-31 13:01:32 +02:00
|
|
|
print_client("&%s,\n", implicit_handle->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
else
|
|
|
|
print_client("&%s__MIDL_AutoBindHandle,\n", iface->name);
|
2006-03-31 13:46:28 +02:00
|
|
|
indent--;
|
|
|
|
print_client("},\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0,\n");
|
2011-05-27 12:07:29 +02:00
|
|
|
if (!list_empty( &generic_handle_list ))
|
|
|
|
print_client("BindingRoutines,\n");
|
|
|
|
else
|
|
|
|
print_client("0,\n");
|
2006-01-27 12:53:32 +01:00
|
|
|
if (expr_eval_routines)
|
|
|
|
print_client("ExprEvalRoutines,\n");
|
|
|
|
else
|
|
|
|
print_client("0,\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0,\n");
|
|
|
|
print_client("__MIDL_TypeFormatString.Format,\n");
|
|
|
|
print_client("1, /* -error bounds_check flag */\n");
|
2011-06-08 12:14:47 +02:00
|
|
|
print_client("0x%x, /* Ndr library version */\n", get_stub_mode() == MODE_Oif ? 0x50002 : 0x10001);
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0,\n");
|
2019-07-05 23:51:44 +02:00
|
|
|
print_client("0x50200ca, /* MIDL Version 5.2.202 */\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0,\n");
|
2007-06-14 01:13:04 +02:00
|
|
|
print_client("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0, /* notify & notify_flag routine table */\n");
|
|
|
|
print_client("1, /* Flags */\n");
|
|
|
|
print_client("0, /* Reserved3 */\n");
|
|
|
|
print_client("0, /* Reserved4 */\n");
|
|
|
|
print_client("0 /* Reserved5 */\n");
|
|
|
|
indent--;
|
|
|
|
print_client("};\n");
|
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_clientinterfacedecl(type_t *iface)
|
|
|
|
{
|
2009-02-06 14:30:38 +01:00
|
|
|
unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION);
|
2022-01-24 12:17:22 +01:00
|
|
|
const uuid_t *uuid = get_attrp(iface->attrs, ATTR_UUID);
|
2007-02-07 17:55:09 +01:00
|
|
|
const str_list_t *endpoints = get_attrp(iface->attrs, ATTR_ENDPOINT);
|
|
|
|
|
|
|
|
if (endpoints) write_endpoints( client, iface->name, endpoints );
|
2005-02-23 21:31:07 +01:00
|
|
|
|
|
|
|
print_client("static const RPC_CLIENT_INTERFACE %s___RpcClientInterface =\n", iface->name );
|
|
|
|
print_client("{\n");
|
|
|
|
indent++;
|
|
|
|
print_client("sizeof(RPC_CLIENT_INTERFACE),\n");
|
2009-02-06 14:31:29 +01:00
|
|
|
print_client("{{0x%08x,0x%04x,0x%04x,{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}},{%d,%d}},\n",
|
2005-02-23 21:31:07 +01:00
|
|
|
uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1],
|
|
|
|
uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6],
|
2007-12-12 15:49:34 +01:00
|
|
|
uuid->Data4[7], MAJORVERSION(ver), MINORVERSION(ver));
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("{{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},\n"); /* FIXME */
|
|
|
|
print_client("0,\n");
|
2007-02-07 17:55:09 +01:00
|
|
|
if (endpoints)
|
|
|
|
{
|
|
|
|
print_client("%u,\n", list_count(endpoints));
|
|
|
|
print_client("(PRPC_PROTSEQ_ENDPOINT)%s__RpcProtseqEndpoint,\n", iface->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_client("0,\n");
|
|
|
|
print_client("0,\n");
|
|
|
|
}
|
2005-02-23 21:31:07 +01:00
|
|
|
print_client("0,\n");
|
|
|
|
print_client("0,\n");
|
|
|
|
print_client("0,\n");
|
|
|
|
indent--;
|
|
|
|
print_client("};\n");
|
2006-04-22 21:52:51 +02:00
|
|
|
if (old_names)
|
2008-12-01 14:39:39 +01:00
|
|
|
print_client("RPC_IF_HANDLE %s_ClientIfHandle DECLSPEC_HIDDEN = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n",
|
2006-04-22 21:52:51 +02:00
|
|
|
iface->name, iface->name);
|
|
|
|
else
|
2008-12-01 14:39:39 +01:00
|
|
|
print_client("RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec DECLSPEC_HIDDEN = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n",
|
2007-12-12 15:49:34 +01:00
|
|
|
prefix_client, iface->name, MAJORVERSION(ver), MINORVERSION(ver), iface->name);
|
2005-02-23 21:31:07 +01:00
|
|
|
fprintf(client, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_implicithandledecl(type_t *iface)
|
|
|
|
{
|
2011-05-31 13:01:32 +02:00
|
|
|
const var_t *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2005-12-08 12:48:44 +01:00
|
|
|
if (implicit_handle)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2019-08-16 03:13:18 +02:00
|
|
|
write_type_decl(client, &implicit_handle->declspec, implicit_handle->name);
|
2011-05-31 13:01:32 +02:00
|
|
|
fprintf(client, ";\n\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void init_client(void)
|
|
|
|
{
|
|
|
|
if (client) return;
|
|
|
|
if (!(client = fopen(client_name, "w")))
|
|
|
|
error("Could not open %s for output\n", client_name);
|
|
|
|
|
2006-08-11 01:51:28 +02:00
|
|
|
print_client("/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
|
2005-04-15 16:09:45 +02:00
|
|
|
print_client("#include <string.h>\n");
|
2011-06-08 12:14:47 +02:00
|
|
|
print_client( "\n");
|
2005-04-15 16:09:45 +02:00
|
|
|
print_client("#include \"%s\"\n", header_name);
|
2008-09-15 14:02:26 +02:00
|
|
|
print_client( "\n");
|
2008-12-01 14:39:39 +01:00
|
|
|
print_client( "#ifndef DECLSPEC_HIDDEN\n");
|
|
|
|
print_client( "#define DECLSPEC_HIDDEN\n");
|
|
|
|
print_client( "#endif\n");
|
|
|
|
print_client( "\n");
|
2005-02-23 21:31:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
static void write_client_ifaces(const statement_list_t *stmts, int expr_eval_routines, unsigned int *proc_offset)
|
|
|
|
{
|
|
|
|
const statement_t *stmt;
|
|
|
|
if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
|
|
|
|
{
|
2009-02-23 14:48:05 +01:00
|
|
|
if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
|
2008-04-24 20:06:28 +02:00
|
|
|
{
|
2018-11-09 13:51:23 +01:00
|
|
|
int needs_stub = 0;
|
2009-01-06 00:33:27 +01:00
|
|
|
const statement_t *stmt2;
|
2008-04-24 20:06:28 +02:00
|
|
|
type_t *iface = stmt->u.type;
|
|
|
|
if (!need_stub(iface))
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(client, "/*****************************************************************************\n");
|
|
|
|
fprintf(client, " * %s interface\n", iface->name);
|
|
|
|
fprintf(client, " */\n");
|
|
|
|
fprintf(client, "\n");
|
|
|
|
|
2018-11-09 13:51:23 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(stmt2, type_iface_get_stmts(iface), const statement_t, entry)
|
2009-01-06 00:33:27 +01:00
|
|
|
{
|
2019-07-05 23:49:49 +02:00
|
|
|
if (stmt2->type == STMT_DECLARATION && stmt2->u.var->declspec.stgclass == STG_NONE &&
|
|
|
|
type_get_type_detect_alias(stmt2->u.var->declspec.type) == TYPE_FUNCTION)
|
2018-11-09 13:51:23 +01:00
|
|
|
{
|
|
|
|
needs_stub = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (stmt2->type == STMT_TYPEDEF)
|
|
|
|
{
|
2021-02-17 19:33:33 +01:00
|
|
|
typeref_t *ref;
|
|
|
|
if (stmt2->u.type_list) LIST_FOR_EACH_ENTRY(ref, stmt2->u.type_list, typeref_t, entry)
|
2018-11-09 13:51:23 +01:00
|
|
|
{
|
2021-02-17 19:33:33 +01:00
|
|
|
if (is_attr(ref->type->attrs, ATTR_ENCODE)
|
|
|
|
|| is_attr(ref->type->attrs, ATTR_DECODE))
|
2018-11-09 13:51:23 +01:00
|
|
|
{
|
|
|
|
needs_stub = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needs_stub)
|
|
|
|
break;
|
|
|
|
}
|
2009-01-06 00:33:27 +01:00
|
|
|
}
|
2018-11-09 13:51:23 +01:00
|
|
|
if (needs_stub)
|
2008-04-24 20:06:28 +02:00
|
|
|
{
|
|
|
|
write_implicithandledecl(iface);
|
|
|
|
|
|
|
|
write_clientinterfacedecl(iface);
|
|
|
|
write_stubdescdecl(iface);
|
|
|
|
write_function_stubs(iface, proc_offset);
|
|
|
|
|
2008-12-26 17:22:25 +01:00
|
|
|
print_client("#if !defined(__RPC_WIN%u__)\n", pointer_size == 8 ? 64 : 32);
|
2008-04-24 20:06:28 +02:00
|
|
|
print_client("#error Invalid build platform for this stub.\n");
|
|
|
|
print_client("#endif\n");
|
|
|
|
|
|
|
|
fprintf(client, "\n");
|
|
|
|
write_stubdescriptor(iface, expr_eval_routines);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 12:07:29 +02:00
|
|
|
static void write_generic_handle_routine_list(void)
|
|
|
|
{
|
|
|
|
generic_handle_t *gh;
|
|
|
|
|
|
|
|
if (list_empty( &generic_handle_list )) return;
|
|
|
|
print_client( "static const GENERIC_BINDING_ROUTINE_PAIR BindingRoutines[] =\n" );
|
|
|
|
print_client( "{\n" );
|
|
|
|
indent++;
|
|
|
|
LIST_FOR_EACH_ENTRY( gh, &generic_handle_list, generic_handle_t, entry )
|
|
|
|
{
|
|
|
|
print_client( "{ (GENERIC_BINDING_ROUTINE)%s_bind, (GENERIC_UNBIND_ROUTINE)%s_unbind },\n",
|
|
|
|
gh->name, gh->name );
|
|
|
|
}
|
|
|
|
indent--;
|
|
|
|
print_client( "};\n\n" );
|
|
|
|
}
|
|
|
|
|
2008-12-26 17:22:25 +01:00
|
|
|
static void write_client_routines(const statement_list_t *stmts)
|
2005-02-23 21:31:07 +01:00
|
|
|
{
|
2006-06-01 16:40:10 +02:00
|
|
|
unsigned int proc_offset = 0;
|
2007-10-27 00:33:13 +02:00
|
|
|
int expr_eval_routines;
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2011-06-03 12:27:14 +02:00
|
|
|
if (need_inline_stubs_file( stmts ))
|
|
|
|
{
|
|
|
|
write_exceptions( client );
|
|
|
|
print_client( "\n");
|
|
|
|
}
|
2010-10-22 19:44:00 +02:00
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
write_formatstringsdecl(client, indent, stmts, need_stub);
|
2007-10-27 00:33:13 +02:00
|
|
|
expr_eval_routines = write_expr_eval_routines(client, client_token);
|
|
|
|
if (expr_eval_routines)
|
|
|
|
write_expr_eval_routine_list(client, client_token);
|
2011-05-27 12:07:29 +02:00
|
|
|
write_generic_handle_routine_list();
|
2007-10-27 00:33:13 +02:00
|
|
|
write_user_quad_list(client);
|
2006-06-01 16:40:10 +02:00
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
write_client_ifaces(stmts, expr_eval_routines, &proc_offset);
|
2005-02-23 21:31:07 +01:00
|
|
|
|
2006-06-01 16:40:10 +02:00
|
|
|
fprintf(client, "\n");
|
|
|
|
|
2008-04-24 20:06:28 +02:00
|
|
|
write_procformatstring(client, stmts, need_stub);
|
|
|
|
write_typeformatstring(client, stmts, need_stub);
|
2008-12-26 17:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_client(const statement_list_t *stmts)
|
|
|
|
{
|
|
|
|
if (!do_client)
|
|
|
|
return;
|
|
|
|
if (do_everything && !need_stub_files(stmts))
|
|
|
|
return;
|
|
|
|
|
|
|
|
init_client();
|
|
|
|
if (!client)
|
|
|
|
return;
|
|
|
|
|
2018-11-14 18:18:17 +01:00
|
|
|
write_client_routines( stmts );
|
2005-02-23 21:31:07 +01:00
|
|
|
fclose(client);
|
|
|
|
}
|