4 * Copyright 2002 Ove Kaaven
5 * Copyright 2004 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
40 #define END_OF_LIST(list) \
43 while (NEXT_LINK(list)) \
44 list = NEXT_LINK(list); \
49 static int indent
= 0;
51 /* FIXME: support generation of stubless proxies */
53 static int print_proxy( const char *format
, ... )
58 va_start( va
, format
);
59 if ( format
[0] != '\n' )
60 for( i
=0; i
<indent
; i
++ )
61 fprintf( proxy
, " " );
62 r
= vfprintf( proxy
, format
, va
);
68 static type_t
*get_base_type( var_t
*arg
)
70 type_t
*t
= arg
->type
;
71 while( (t
->type
== 0) && t
->ref
)
76 static void write_stubdescproto(void)
78 print_proxy( "extern const MIDL_STUB_DESC Object_StubDesc;\n");
82 static void write_stubdesc(void)
84 print_proxy( "const MIDL_STUB_DESC Object_StubDesc = {\n");
85 print_proxy( " 0,\n");
86 print_proxy( " NdrOleAllocate,\n");
87 print_proxy( " NdrOleFree,\n");
88 print_proxy( " {0}, 0, 0, 0, 0,\n");
89 print_proxy( " 0 /* __MIDL_TypeFormatString.Format */\n");
94 static void write_formatdesc( const char *str
)
96 print_proxy( "typedef struct _MIDL_%s_FORMAT_STRING\n", str
);
99 print_proxy( "short Pad;\n");
100 print_proxy( "unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str
);
102 print_proxy( "} MIDL_%s_FORMAT_STRING;\n", str
);
106 static void write_formatstringsdecl(void)
108 print_proxy( "#define TYPE_FORMAT_STRING_SIZE %d\n",1); /* FIXME */
109 print_proxy( "#define PROC_FORMAT_STRING_SIZE %d\n",1); /* FIXME */
110 fprintf(proxy
, "\n");
111 write_formatdesc( "TYPE" );
112 write_formatdesc( "PROC" );
113 fprintf(proxy
, "\n");
114 print_proxy( "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
115 print_proxy( "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
119 static void write_formatstring( int proc
)
132 print_proxy( "static const MIDL_%s_FORMAT_STRING __MIDL_%sFormatString =\n", t
, n
);
135 print_proxy( "0,\n");
142 print_proxy( "};\n");
146 static void init_proxy(void)
149 if(!(proxy
= fopen(proxy_name
, "w")))
150 error("Could not open %s for output\n", proxy_name
);
151 print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION
, input_name
);
153 print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
154 print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
155 print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
157 print_proxy( "#include \"rpcproxy.h\"\n");
158 print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
159 print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
160 print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
162 print_proxy( "#include \"%s\"\n", header_name
);
164 write_formatstringsdecl();
165 write_stubdescproto();
168 static void clear_output_vars( var_t
*arg
)
172 if (is_attr(arg
->attrs
, ATTR_OUT
) && !is_attr(arg
->attrs
, ATTR_IN
)) {
173 print_proxy( "if(%s)\n", arg
->name
);
175 print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg
->name
, arg
->name
);
178 arg
= PREV_LINK(arg
);
182 int is_pointer(var_t
*arg
)
187 switch (ref_type(arg
->type
))
190 case RPC_FC_C_CSTRING
:
191 case RPC_FC_C_WSTRING
:
201 int cant_be_null(var_t
*v
)
203 /* Search backwards for the most recent pointer attribute. */
204 const attr_t
*attrs
= v
->attrs
;
205 const type_t
*type
= v
->type
;
215 int t
= get_attrv(attrs
, ATTR_POINTERTYPE
);
217 if (t
== RPC_FC_FP
|| t
== RPC_FC_OP
|| t
== RPC_FC_UP
)
232 return 1; /* Default is RPC_FC_RP. */
235 static void proxy_check_pointers( var_t
*arg
)
239 if (is_pointer(arg
) && cant_be_null(arg
)) {
240 print_proxy( "if(!%s)\n", arg
->name
);
242 print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
245 arg
= PREV_LINK(arg
);
249 static void marshall_size_arg( var_t
*arg
)
252 const type_t
*type
= get_base_type(arg
);
255 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
258 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
259 write_expr(proxy
, expr
, 0);
260 fprintf(proxy
, ";\n\n");
261 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
262 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
270 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 1, arg
->name
);
277 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 2, arg
->name
);
283 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 4, arg
->name
);
287 print_proxy( "NdrSimpleStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
288 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
291 case RPC_FC_C_CSTRING
:
292 case RPC_FC_C_WSTRING
:
294 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
295 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
298 case RPC_FC_BOGUS_STRUCT
:
299 print_proxy( "NdrComplexStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
300 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
306 memset( &temp
, 0, sizeof temp
);
307 temp
.type
= type
->ref
;
308 temp
.name
= arg
->name
; /* FIXME */
310 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
312 marshall_size_arg( &temp
);
317 print_proxy( "NdrPointerBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
318 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
322 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
326 static void proxy_gen_marshall_size( var_t
*arg
)
328 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
332 if (is_attr(arg
->attrs
, ATTR_IN
))
334 marshall_size_arg( arg
);
335 fprintf(proxy
, "\n");
337 arg
= PREV_LINK(arg
);
341 static void marshall_copy_arg( var_t
*arg
)
344 type_t
*type
= get_base_type(arg
);
347 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
350 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
351 write_expr(proxy
, expr
, 0);
352 fprintf(proxy
, ";\n\n");
353 print_proxy( "NdrConformantArrayMarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
354 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
370 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
371 fprintf(proxy
, " *)_StubMsg.Buffer = %s;\n", arg
->name
);
372 print_proxy("_StubMsg.Buffer += sizeof(");
373 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
374 fprintf(proxy
, ");\n");
378 /* FIXME: add the format string, and set the index below */
379 print_proxy( "NdrSimpleStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
380 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
383 case RPC_FC_C_CSTRING
:
384 case RPC_FC_C_WSTRING
:
388 case RPC_FC_BOGUS_STRUCT
:
389 print_proxy( "NdrComplexStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
390 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
396 memset( &temp
, 0, sizeof temp
);
397 temp
.type
= type
->ref
;
398 temp
.name
= arg
->name
; /* FIXME */
400 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
402 marshall_copy_arg( &temp
);
407 print_proxy( "NdrPointerMarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
408 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
412 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
416 static void gen_marshall_copydata( var_t
*arg
)
420 if (is_attr(arg
->attrs
, ATTR_IN
))
422 marshall_copy_arg( arg
);
423 fprintf(proxy
, "\n");
425 arg
= PREV_LINK(arg
);
429 static void gen_marshall( var_t
*arg
)
431 /* generated code to determine the size of the buffer required */
432 proxy_gen_marshall_size( arg
);
434 /* generated code to allocate the buffer */
435 print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
437 /* generated code to copy the args into the buffer */
438 gen_marshall_copydata( arg
);
443 static void unmarshall_copy_arg( var_t
*arg
)
446 type_t
*type
= get_base_type(arg
);
449 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
452 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg
->name
);
453 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
468 print_proxy( "%s = *(", arg
->name
);
469 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
470 fprintf(proxy
," *)_StubMsg.Buffer;\n");
471 print_proxy("_StubMsg.Buffer += sizeof(");
472 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
473 fprintf(proxy
, ");\n");
477 print_proxy( "NdrSimpleStructUnmarshall(&_StubMsg, (unsigned char**)%s, ", arg
->name
);
478 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
481 case RPC_FC_C_CSTRING
:
482 case RPC_FC_C_WSTRING
:
484 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg
->name
);
485 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
488 case RPC_FC_BOGUS_STRUCT
:
489 print_proxy( "NdrComplexStructUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg
->name
);
490 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index
);
496 memset( &temp
, 0, sizeof temp
);
497 temp
.type
= type
->ref
;
498 temp
.name
= arg
->name
; /* FIXME */
500 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
502 unmarshall_copy_arg( &temp
);
507 print_proxy( "NdrPointerUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg
->name
);
508 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
512 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
516 static void gen_unmarshall( var_t
*arg
)
520 if (is_attr(arg
->attrs
, ATTR_OUT
))
522 unmarshall_copy_arg( arg
);
523 fprintf(proxy
, "\n");
525 arg
= PREV_LINK(arg
);
529 static void free_variable( var_t
*arg
)
532 int index
= 0; /* FIXME */
536 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
539 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
540 write_expr(proxy
, expr
, 0);
541 fprintf(proxy
, ";\n\n");
542 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
543 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], ", index
);
544 fprintf(proxy
, "(void*)%s );\n", arg
->name
);
548 type
= get_base_type(arg
);
565 constraint
= get_attrp( arg
->attrs
, ATTR_IIDIS
);
567 print_proxy( "_StubMsg.MaxCount = (unsigned long) ( %s );\n",constraint
->name
);
568 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
569 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], ", index
);
570 fprintf(proxy
, "(void*)%s );\n", arg
->name
);
574 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
578 static void proxy_free_variables( var_t
*arg
)
582 if (is_attr(arg
->attrs
, ATTR_OUT
))
584 free_variable( arg
);
585 fprintf(proxy
, "\n");
587 arg
= PREV_LINK(arg
);
591 static void gen_proxy(type_t
*iface
, func_t
*cur
, int idx
)
593 var_t
*def
= cur
->def
;
594 int has_ret
= !is_void(def
->type
, def
);
597 write_type(proxy
, def
->type
, def
, def
->tname
);
598 print_proxy( " STDMETHODCALLTYPE %s_", iface
->name
);
599 write_name(proxy
, def
);
600 print_proxy( "_Proxy(\n");
601 write_args(proxy
, cur
->args
, iface
->name
, 1, TRUE
);
605 /* local variables */
608 write_type(proxy
, def
->type
, def
, def
->tname
);
609 print_proxy( " _RetVal;\n");
611 print_proxy( "RPC_MESSAGE _Msg;\n" );
612 print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
616 clear_output_vars( cur
->args
);
618 print_proxy( "RpcTryExcept\n" );
619 print_proxy( "{\n" );
621 print_proxy( "NdrProxyInitialize(This, &_Msg, &_StubMsg, &Object_StubDesc, %d);\n", idx
);
622 proxy_check_pointers( cur
->args
);
624 print_proxy( "RpcTryFinally\n" );
625 print_proxy( "{\n" );
628 gen_marshall( cur
->args
);
630 print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
631 fprintf(proxy
, "\n");
632 print_proxy("if ((_Msg.DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
634 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
636 fprintf(proxy
, "\n");
638 gen_unmarshall( cur
->args
);
641 * FIXME: We only need to round the buffer up if it could be unaligned...
642 * We should calculate how much buffer we used and output the following
643 * line only if necessary.
645 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
647 print_proxy( "_RetVal = *(" );
648 write_type(proxy
, def
->type
, def
, def
->tname
);
649 fprintf(proxy
, " *)_StubMsg.Buffer;\n");
650 print_proxy("_StubMsg.Buffer += sizeof(");
651 write_type(proxy
, def
->type
, def
, def
->tname
);
652 fprintf(proxy
, ");\n");
657 print_proxy( "RpcFinally\n" );
658 print_proxy( "{\n" );
660 print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
663 print_proxy( "RpcEndFinally\n" );
665 print_proxy( "}\n" );
666 print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
667 print_proxy( "{\n" );
670 proxy_free_variables( cur
->args
);
671 print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
674 print_proxy( "}\n" );
675 print_proxy( "RpcEndExcept\n" );
678 print_proxy( "return _RetVal;\n" );
685 static void stub_write_locals( var_t
*arg
)
690 int outptr
= is_attr(arg
->attrs
, ATTR_OUT
)
691 && ! is_attr(arg
->attrs
, ATTR_IN
);
693 /* create a temporary variable to store the output */
696 memset( &temp
, 0, sizeof temp
);
697 temp
.ptr_level
= arg
->ptr_level
- 1; /* dereference once */
699 write_type(proxy
, arg
->type
, &temp
, arg
->tname
);
700 fprintf(proxy
, " _M%d;\n",n
++);
703 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
705 write_name(proxy
, arg
);
706 fprintf(proxy
, ";\n");
707 arg
= PREV_LINK(arg
);
711 static void stub_unmarshall( var_t
*arg
)
716 if (is_attr(arg
->attrs
, ATTR_IN
))
718 unmarshall_copy_arg( arg
);
721 else if (is_attr(arg
->attrs
, ATTR_OUT
)) {
722 type_t
*type
= get_base_type(arg
);
726 print_proxy("MIDL_memset(");
727 write_name(proxy
, arg
);
728 fprintf(proxy
,", 0, sizeof(");
729 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
730 fprintf(proxy
,"));\n");
734 write_name(proxy
, arg
);
735 fprintf(proxy
," = &_M%d;\n", n
);
736 print_proxy("MIDL_memset(&_M%d, 0, sizeof _M%d);\n", n
, n
);
741 arg
= PREV_LINK(arg
);
745 static void stub_gen_marshall_size( var_t
*arg
)
747 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
751 if (is_attr(arg
->attrs
, ATTR_OUT
))
752 marshall_size_arg( arg
);
753 arg
= PREV_LINK(arg
);
757 static void stub_gen_marshall_copydata( var_t
*arg
)
761 if (is_attr(arg
->attrs
, ATTR_OUT
))
762 marshall_copy_arg( arg
);
763 arg
= PREV_LINK(arg
);
767 static void stub_genmarshall( var_t
*args
)
769 /* FIXME: size buffer */
770 stub_gen_marshall_size( args
);
772 print_proxy("NdrStubGetBuffer(This, pRpcChannelBuffer, &_StubMsg);\n");
774 stub_gen_marshall_copydata( args
);
777 static void gen_stub(type_t
*iface
, func_t
*cur
, const char *cas
)
779 var_t
*def
= cur
->def
;
781 int has_ret
= !is_void(def
->type
, def
);
784 print_proxy( "void __RPC_STUB %s_", iface
->name
);
785 write_name(proxy
, def
);
786 print_proxy( "_Stub(\n");
788 print_proxy( "IRpcStubBuffer* This,\n");
789 print_proxy( "IRpcChannelBuffer* pRpcChannelBuffer,\n");
790 print_proxy( "PRPC_MESSAGE _Msg,\n");
791 print_proxy( "DWORD* _pdwStubPhase)\n");
795 /* local variables */
798 write_type(proxy
, def
->type
, def
, def
->tname
);
799 fprintf(proxy
, " _RetVal;\n");
801 print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface
->name
, iface
->name
);
802 print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
803 stub_write_locals( cur
->args
);
804 fprintf(proxy
, "\n");
808 print_proxy("NdrStubInitialize(_Msg, &_StubMsg, &Object_StubDesc, pRpcChannelBuffer);\n");
809 fprintf(proxy
, "\n");
811 print_proxy("RpcTryFinally\n");
814 print_proxy("if ((_Msg->DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
816 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
818 fprintf(proxy
, "\n");
820 stub_unmarshall( cur
->args
);
821 fprintf(proxy
, "\n");
823 print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
824 fprintf(proxy
, "\n");
826 if (has_ret
) fprintf(proxy
, "_RetVal = ");
827 fprintf(proxy
, "%s_", iface
->name
);
828 if (cas
) fprintf(proxy
, "%s_Stub", cas
);
829 else write_name(proxy
, def
);
830 fprintf(proxy
, "(_This");
835 fprintf(proxy
, ", ");
836 write_name(proxy
, arg
);
837 arg
= PREV_LINK(arg
);
840 fprintf(proxy
, ");\n");
841 fprintf(proxy
, "\n");
842 print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
843 fprintf(proxy
, "\n");
845 stub_genmarshall( cur
->args
);
846 fprintf(proxy
, "\n");
850 * FIXME: We only need to round the buffer up if it could be unaligned...
851 * We should calculate how much buffer we used and output the following
852 * line only if necessary.
854 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
857 write_type(proxy
, def
->type
, def
, def
->tname
);
858 fprintf(proxy
, " *)_StubMsg.Buffer = _RetVal;\n");
859 print_proxy("_StubMsg.Buffer += sizeof(");
860 write_type(proxy
, def
->type
, def
, def
->tname
);
861 fprintf(proxy
, ");\n");
866 print_proxy("RpcFinally\n");
869 print_proxy("RpcEndFinally\n");
871 print_proxy("_Msg->BufferLength = _StubMsg.Buffer - (unsigned char *)_Msg->Buffer;\n");
878 static int write_proxy_methods(type_t
*iface
)
880 func_t
*cur
= iface
->funcs
;
885 if (iface
->ref
) i
= write_proxy_methods(iface
->ref
);
887 var_t
*def
= cur
->def
;
888 if (!is_callas(def
->attrs
)) {
889 if (i
) fprintf(proxy
, ",\n");
890 print_proxy( "%s_", iface
->name
);
891 write_name(proxy
, def
);
892 fprintf(proxy
, "_Proxy");
895 cur
= PREV_LINK(cur
);
900 static int write_stub_methods(type_t
*iface
)
902 func_t
*cur
= iface
->funcs
;
907 if (iface
->ref
) i
= write_stub_methods(iface
->ref
);
908 else return i
; /* skip IUnknown */
910 var_t
*def
= cur
->def
;
911 if (!is_local(def
->attrs
)) {
912 if (i
) fprintf(proxy
,",\n");
913 print_proxy( "%s_", iface
->name
);
914 write_name(proxy
, def
);
915 fprintf(proxy
, "_Stub");
918 cur
= PREV_LINK(cur
);
923 static void write_proxy(type_t
*iface
)
925 int midx
= -1, stubs
;
926 func_t
*cur
= iface
->funcs
;
932 /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
934 fprintf(proxy
, "/*****************************************************************************\n");
935 fprintf(proxy
, " * %s interface\n", iface
->name
);
936 fprintf(proxy
, " */\n");
938 const var_t
*def
= cur
->def
;
939 if (!is_local(def
->attrs
)) {
940 const var_t
*cas
= is_callas(def
->attrs
);
941 const char *cname
= cas
? cas
->name
: NULL
;
944 const func_t
*m
= iface
->funcs
;
945 while (m
&& strcmp(get_name(m
->def
), cname
))
949 gen_proxy(iface
, cur
, idx
);
950 gen_stub(iface
, cur
, cname
);
951 if (midx
== -1) midx
= idx
;
952 else if (midx
!= idx
) yyerror("method index mismatch in write_proxy");
955 cur
= PREV_LINK(cur
);
959 print_proxy( "const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx
, iface
->name
);
962 print_proxy( "{\n", iface
->name
);
964 print_proxy( "&IID_%s,\n", iface
->name
);
966 print_proxy( "},\n");
969 write_proxy_methods(iface
);
970 fprintf(proxy
, "\n");
974 print_proxy( "};\n");
975 fprintf(proxy
, "\n\n");
978 print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface
->name
);
981 stubs
= write_stub_methods(iface
);
982 fprintf(proxy
, "\n");
984 fprintf(proxy
, "};\n");
986 print_proxy( "const CInterfaceStubVtbl _%sStubVtbl =\n", iface
->name
);
991 print_proxy( "&IID_%s,\n", iface
->name
);
992 print_proxy( "0,\n");
993 print_proxy( "%d,\n", stubs
+3);
994 print_proxy( "&%s_table[-3],\n", iface
->name
);
996 print_proxy( "},\n", iface
->name
);
999 print_proxy( "CStdStubBuffer_METHODS\n");
1001 print_proxy( "}\n");
1003 print_proxy( "};\n");
1007 void write_proxies(ifref_t
*ifaces
)
1009 ifref_t
*lcur
= ifaces
;
1011 char *file_id
= proxy_token
;
1014 if (!do_proxies
) return;
1023 if (is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
1024 write_proxy(cur
->iface
);
1025 cur
= PREV_LINK(cur
);
1032 print_proxy( "#if !defined(__RPC_WIN32__)\n");
1033 print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
1034 print_proxy( "#endif\n");
1036 write_formatstring( 1 );
1037 write_formatstring( 0 );
1039 fprintf(proxy
, "const CInterfaceProxyVtbl* _%s_ProxyVtblList[] =\n", file_id
);
1040 fprintf(proxy
, "{\n");
1043 if(cur
->iface
->ref
&& cur
->iface
->funcs
&&
1044 is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
1045 fprintf(proxy
, " (CInterfaceProxyVtbl*)&_%sProxyVtbl,\n", cur
->iface
->name
);
1046 cur
= PREV_LINK(cur
);
1048 fprintf(proxy
, " 0\n");
1049 fprintf(proxy
, "};\n");
1050 fprintf(proxy
, "\n");
1052 fprintf(proxy
, "const CInterfaceStubVtbl* _%s_StubVtblList[] =\n", file_id
);
1053 fprintf(proxy
, "{\n");
1056 if(cur
->iface
->ref
&& cur
->iface
->funcs
&&
1057 is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
1058 fprintf(proxy
, " (CInterfaceStubVtbl*)&_%sStubVtbl,\n", cur
->iface
->name
);
1059 cur
= PREV_LINK(cur
);
1061 fprintf(proxy
, " 0\n");
1062 fprintf(proxy
, "};\n");
1063 fprintf(proxy
, "\n");
1065 fprintf(proxy
, "PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id
);
1066 fprintf(proxy
, "{\n");
1069 if(cur
->iface
->ref
&& cur
->iface
->funcs
&&
1070 is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
1071 fprintf(proxy
, " \"%s\",\n", cur
->iface
->name
);
1072 cur
= PREV_LINK(cur
);
1074 fprintf(proxy
, " 0\n");
1075 fprintf(proxy
, "};\n");
1076 fprintf(proxy
, "\n");
1078 fprintf(proxy
, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id
, file_id
);
1079 fprintf(proxy
, "\n");
1080 fprintf(proxy
, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id
);
1081 fprintf(proxy
, "{\n");
1087 fprintf(proxy
, " if (!_%s_CHECK_IID(%d))\n", file_id
, c
);
1088 fprintf(proxy
, " {\n");
1089 fprintf(proxy
, " *pIndex = %d;\n", c
);
1090 fprintf(proxy
, " return 1;\n");
1091 fprintf(proxy
, " }\n");
1094 cur
= PREV_LINK(cur
);
1096 fprintf(proxy
, " return 0;\n");
1097 fprintf(proxy
, "}\n");
1098 fprintf(proxy
, "\n");
1100 fprintf(proxy
, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id
);
1101 fprintf(proxy
, "{\n");
1102 fprintf(proxy
, " (PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id
);
1103 fprintf(proxy
, " (PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id
);
1104 fprintf(proxy
, " (const PCInterfaceName*)&_%s_InterfaceNamesList,\n", file_id
);
1105 fprintf(proxy
, " 0,\n");
1106 fprintf(proxy
, " &_%s_IID_Lookup,\n", file_id
);
1107 fprintf(proxy
, " %d,\n", c
);
1108 fprintf(proxy
, " 1,\n");
1109 fprintf(proxy
, " 0,\n");
1110 fprintf(proxy
, " 0,\n");
1111 fprintf(proxy
, " 0,\n");
1112 fprintf(proxy
, " 0\n");
1113 fprintf(proxy
, "};\n");