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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 #define END_OF_LIST(list) \
42 while (NEXT_LINK(list)) \
43 list = NEXT_LINK(list); \
48 static int indent
= 0;
50 /* FIXME: support generation of stubless proxies */
52 static int print_proxy( const char *format
, ... )
57 va_start( va
, format
);
58 for( i
=0; i
<indent
; i
++ )
59 fprintf( proxy
, " " );
60 r
= vfprintf( proxy
, format
, va
);
66 static type_t
*get_base_type( var_t
*arg
)
68 type_t
*t
= arg
->type
;
69 while( (t
->type
== 0) && t
->ref
)
74 static void write_stubdescproto(void)
76 print_proxy( "extern const MIDL_STUB_DESC Object_StubDesc;\n");
80 static void write_stubdesc(void)
82 print_proxy( "const MIDL_STUB_DESC Object_StubDesc = {\n");
83 print_proxy( " 0,\n");
84 print_proxy( " NdrOleAllocate,\n");
85 print_proxy( " NdrOleFree,\n");
86 print_proxy( " {0}, 0, 0, 0, 0,\n");
87 print_proxy( " 0 /* __MIDL_TypeFormatString.Format */\n");
92 static void write_formatdesc( const char *str
)
94 print_proxy( "typedef struct _MIDL_%s_FORMAT_STRING\n", str
);
97 print_proxy( "short Pad;\n");
98 print_proxy( "unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str
);
100 print_proxy( "} MIDL_%s_FORMAT_STRING;\n", str
);
104 static void write_formatstringsdecl(void)
106 print_proxy( "#define TYPE_FORMAT_STRING_SIZE %d\n",1); /* FIXME */
107 print_proxy( "#define PROC_FORMAT_STRING_SIZE %d\n",1); /* FIXME */
108 fprintf(proxy
, "\n");
109 write_formatdesc( "TYPE" );
110 write_formatdesc( "PROC" );
111 fprintf(proxy
, "\n");
112 print_proxy( "extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
113 print_proxy( "extern const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
117 static void write_formatstring( int proc
)
130 print_proxy( "static const MIDL_%s_FORMAT_STRING __MIDL_%sFormatString =\n", t
, n
);
133 print_proxy( "0,\n");
140 print_proxy( "};\n");
144 static void init_proxy()
147 if(!(proxy
= fopen(proxy_name
, "w")))
148 error("Could not open %s for output\n", proxy_name
);
149 print_proxy( "/*** Autogenerated by WIDL %s - Do not edit ***/\n", WIDL_FULLVERSION
);
151 print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
152 print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
153 print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
155 print_proxy( "#include \"rpcproxy.h\"\n");
156 print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
157 print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
158 print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
160 print_proxy( "#include \"%s\"\n", header_name
);
162 write_formatstringsdecl();
163 write_stubdescproto();
166 static void clear_output_vars( var_t
*arg
)
170 if (is_attr(arg
->attrs
, ATTR_OUT
) && !is_attr(arg
->attrs
, ATTR_IN
)) {
171 print_proxy( "if(%s)\n", arg
->name
);
173 print_proxy( "MIDL_memset( %s, 0, sizeof( ", arg
->name
);
175 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
176 fprintf( proxy
, " ));\n" );
178 arg
= PREV_LINK(arg
);
182 static int is_pointer(var_t
*arg
)
186 if (arg
->type
->type
== RPC_FC_FP
)
191 static void proxy_check_pointers( var_t
*arg
)
195 if (is_pointer(arg
)) {
196 print_proxy( "if(!%s)\n", arg
->name
);
198 print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
201 arg
= PREV_LINK(arg
);
205 static void marshall_size_arg( var_t
*arg
)
208 type_t
*type
= get_base_type(arg
);
211 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
214 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
215 write_expr(proxy
, expr
);
216 fprintf(proxy
, ";\n\n");
217 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
218 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
226 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 1, arg
->name
);
233 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 2, arg
->name
);
239 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 4, arg
->name
);
243 print_proxy( "NdrSimpleStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
244 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
247 case RPC_FC_C_CSTRING
:
248 case RPC_FC_C_WSTRING
:
250 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
251 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
254 case RPC_FC_BOGUS_STRUCT
:
255 print_proxy( "NdrComplexStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
256 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
262 memset( &temp
, 0, sizeof temp
);
263 temp
.type
= type
->ref
;
264 temp
.name
= arg
->name
; /* FIXME */
266 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
268 marshall_size_arg( &temp
);
273 print_proxy( "NdrPointerBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
274 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
278 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
282 static void proxy_gen_marshall_size( var_t
*arg
)
284 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
288 if (is_attr(arg
->attrs
, ATTR_IN
))
290 marshall_size_arg( arg
);
291 fprintf(proxy
, "\n");
293 arg
= PREV_LINK(arg
);
297 static void marshall_copy_arg( var_t
*arg
)
300 type_t
*type
= get_base_type(arg
);
303 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
306 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
307 write_expr(proxy
, expr
);
308 fprintf(proxy
, ";\n\n");
309 print_proxy( "NdrConformantArrayMarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
310 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
326 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
327 fprintf(proxy
,"*)_StubMsg.Buffer)++ = %s;\n", arg
->name
);
331 /* FIXME: add the format string, and set the index below */
332 print_proxy( "NdrSimpleStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
333 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
336 case RPC_FC_C_CSTRING
:
337 case RPC_FC_C_WSTRING
:
341 case RPC_FC_BOGUS_STRUCT
:
342 print_proxy( "NdrComplexStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
343 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
349 memset( &temp
, 0, sizeof temp
);
350 temp
.type
= type
->ref
;
351 temp
.name
= arg
->name
; /* FIXME */
353 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
355 marshall_copy_arg( &temp
);
360 print_proxy( "NdrPointerMarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
361 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
365 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
369 static void gen_marshall_copydata( var_t
*arg
)
373 if (is_attr(arg
->attrs
, ATTR_IN
))
375 marshall_copy_arg( arg
);
376 fprintf(proxy
, "\n");
378 arg
= PREV_LINK(arg
);
382 static void gen_marshall( var_t
*arg
)
384 /* generated code to determine the size of the buffer required */
385 proxy_gen_marshall_size( arg
);
387 /* generated code to allocate the buffer */
388 print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
390 /* generated code to copy the args into the buffer */
391 gen_marshall_copydata( arg
);
396 static void unmarshall_copy_arg( var_t
*arg
)
399 type_t
*type
= get_base_type(arg
);
402 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
405 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
406 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
421 print_proxy( "%s = *((", arg
->name
);
422 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
423 fprintf(proxy
,"*)_StubMsg.Buffer)++;\n");
427 print_proxy( "NdrSimpleStructUnmarshall(&_StubMsg, (unsigned char**)%s, ", arg
->name
);
428 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
431 case RPC_FC_C_CSTRING
:
432 case RPC_FC_C_WSTRING
:
434 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
435 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
438 case RPC_FC_BOGUS_STRUCT
:
439 print_proxy( "NdrComplexStructUnmarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
440 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index
);
446 memset( &temp
, 0, sizeof temp
);
447 temp
.type
= type
->ref
;
448 temp
.name
= arg
->name
; /* FIXME */
450 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
452 unmarshall_copy_arg( &temp
);
457 print_proxy( "NdrPointerUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg
->name
);
458 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
462 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
466 static void gen_unmarshall( var_t
*arg
)
470 if (is_attr(arg
->attrs
, ATTR_OUT
))
472 unmarshall_copy_arg( arg
);
473 fprintf(proxy
, "\n");
475 arg
= PREV_LINK(arg
);
479 static void free_variable( var_t
*arg
)
482 int index
= 0; /* FIXME */
486 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
489 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
490 write_expr(proxy
, expr
);
491 fprintf(proxy
, ";\n\n");
492 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
493 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], ", index
);
494 fprintf(proxy
, "(void*)%s );\n", arg
->name
);
498 type
= get_base_type(arg
);
515 constraint
= get_attrp( arg
->attrs
, ATTR_IIDIS
);
517 print_proxy( "_StubMsg.MaxCount = (unsigned long) ( %s );\n",constraint
->name
);
518 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
519 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], ", index
);
520 fprintf(proxy
, "(void*)%s );\n", arg
->name
);
524 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
528 static void proxy_free_variables( var_t
*arg
)
532 if (is_attr(arg
->attrs
, ATTR_OUT
))
534 free_variable( arg
);
535 fprintf(proxy
, "\n");
537 arg
= PREV_LINK(arg
);
541 static void gen_proxy(type_t
*iface
, func_t
*cur
, int idx
)
543 var_t
*def
= cur
->def
;
544 int has_ret
= !is_void(def
->type
, def
);
547 write_type(proxy
, def
->type
, def
, def
->tname
);
548 print_proxy( " STDMETHODCALLTYPE %s_", iface
->name
);
549 write_name(proxy
, def
);
550 print_proxy( "_Proxy(\n");
551 write_args(proxy
, cur
->args
, iface
->name
, 1, TRUE
);
555 /* local variables */
558 write_type(proxy
, def
->type
, def
, def
->tname
);
559 print_proxy( " _RetVal;\n");
561 print_proxy( "RPC_MESSAGE _Msg;\n" );
562 print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
566 clear_output_vars( cur
->args
);
568 print_proxy( "RpcTryExcept\n" );
569 print_proxy( "{\n" );
571 print_proxy( "NdrProxyInitialize(This, &_Msg, &_StubMsg, &Object_StubDesc, %d);\n", idx
);
572 proxy_check_pointers( cur
->args
);
574 print_proxy( "RpcTryFinally\n" );
575 print_proxy( "{\n" );
578 gen_marshall( cur
->args
);
580 print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
581 fprintf(proxy
, "\n");
582 print_proxy("if ((_Msg.DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
584 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
586 fprintf(proxy
, "\n");
588 gen_unmarshall( cur
->args
);
591 * FIXME: We only need to round the buffer up if it could be unaligned...
592 * We should calculate how much buffer we used and output the following
593 * line only if necessary.
595 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
597 print_proxy( "_RetVal = *((" );
598 write_type(proxy
, def
->type
, def
, def
->tname
);
599 fprintf(proxy
, "*)_StubMsg.Buffer)++;\n");
604 print_proxy( "RpcFinally\n" );
605 print_proxy( "{\n" );
607 print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
610 print_proxy( "RpcEndFinally\n" );
612 print_proxy( "}\n" );
613 print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
614 print_proxy( "{\n" );
617 proxy_free_variables( cur
->args
);
618 print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
621 print_proxy( "}\n" );
622 print_proxy( "RpcEndExcept\n" );
625 print_proxy( "return _RetVal;\n" );
632 static void stub_write_locals( var_t
*arg
)
636 int outptr
= is_attr(arg
->attrs
, ATTR_OUT
);
638 /* create a temporary variable to store the output */
641 memset( &temp
, 0, sizeof temp
);
642 temp
.ptr_level
= arg
->ptr_level
- 1; /* dereference once */
644 write_type(proxy
, arg
->type
, &temp
, arg
->tname
);
645 fprintf(proxy
, " _M%d;\n",n
++);
648 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
650 write_name(proxy
, arg
);
651 fprintf(proxy
, ";\n");
652 arg
= NEXT_LINK(arg
);
656 static void stub_unmarshall( var_t
*arg
)
661 if (is_attr(arg
->attrs
, ATTR_IN
))
663 unmarshall_copy_arg( arg
);
666 else if (is_attr(arg
->attrs
, ATTR_OUT
)) {
667 type_t
*type
= get_base_type(arg
);
671 print_proxy("MIDL_memset(");
672 write_name(proxy
, arg
);
673 fprintf(proxy
,", 0, sizeof(");
674 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
675 fprintf(proxy
,"));\n");
679 write_name(proxy
, arg
);
680 fprintf(proxy
," = &_M%d;\n", n
);
681 print_proxy("_M%d = 0;\n", n
++);
685 arg
= PREV_LINK(arg
);
689 static void stub_gen_marshall_size( var_t
*arg
)
691 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
695 if (is_attr(arg
->attrs
, ATTR_OUT
))
696 marshall_size_arg( arg
);
697 arg
= PREV_LINK(arg
);
701 static void stub_gen_marshall_copydata( var_t
*arg
)
705 if (is_attr(arg
->attrs
, ATTR_OUT
))
706 marshall_copy_arg( arg
);
707 arg
= PREV_LINK(arg
);
711 static void stub_genmarshall( var_t
*args
)
713 /* FIXME: size buffer */
714 stub_gen_marshall_size( args
);
716 print_proxy("NdrStubGetBuffer(This, pRpcChannelBuffer, &_StubMsg);\n");
718 stub_gen_marshall_copydata( args
);
721 static void gen_stub(type_t
*iface
, func_t
*cur
, char *cas
)
723 var_t
*def
= cur
->def
;
725 int has_ret
= !is_void(def
->type
, def
);
728 print_proxy( "void __RPC_STUB %s_", iface
->name
);
729 write_name(proxy
, def
);
730 print_proxy( "_Stub(\n");
732 print_proxy( "IRpcStubBuffer* This,\n");
733 print_proxy( "IRpcChannelBuffer* pRpcChannelBuffer,\n");
734 print_proxy( "PRPC_MESSAGE _Msg,\n");
735 print_proxy( "DWORD* _pdwStubPhase)\n");
739 /* local variables */
742 write_type(proxy
, def
->type
, def
, def
->tname
);
743 fprintf(proxy
, " _RetVal;\n");
745 print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface
->name
, iface
->name
);
746 print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
747 stub_write_locals( cur
->args
);
748 fprintf(proxy
, "\n");
752 print_proxy("NdrStubInitialize(_Msg, &_StubMsg, &Object_StubDesc, pRpcChannelBuffer);\n");
753 fprintf(proxy
, "\n");
755 print_proxy("RpcTryFinally\n");
758 print_proxy("if ((_Msg->DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
760 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
762 fprintf(proxy
, "\n");
764 stub_unmarshall( cur
->args
);
765 fprintf(proxy
, "\n");
767 print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
768 fprintf(proxy
, "\n");
770 if (has_ret
) fprintf(proxy
, "_RetVal = ");
771 fprintf(proxy
, "%s_", iface
->name
);
772 if (cas
) fprintf(proxy
, "%s_Stub", cas
);
773 else write_name(proxy
, def
);
774 fprintf(proxy
, "(_This");
779 fprintf(proxy
, ", ");
780 write_name(proxy
, arg
);
781 arg
= PREV_LINK(arg
);
784 fprintf(proxy
, ");\n");
785 fprintf(proxy
, "\n");
786 print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
787 fprintf(proxy
, "\n");
789 stub_genmarshall( cur
->args
);
790 fprintf(proxy
, "\n");
794 * FIXME: We only need to round the buffer up if it could be unaligned...
795 * We should calculate how much buffer we used and output the following
796 * line only if necessary.
798 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
800 print_proxy( "*((" );
801 write_type(proxy
, def
->type
, def
, def
->tname
);
802 fprintf(proxy
, "*)_StubMsg.Buffer)++ = _RetVal;\n");
807 print_proxy("RpcFinally\n");
810 print_proxy("RpcEndFinally\n");
812 print_proxy("_Msg->BufferLength = ((long)_StubMsg.Buffer - (long)_Msg->Buffer);\n");
819 static int write_proxy_methods(type_t
*iface
)
821 func_t
*cur
= iface
->funcs
;
826 if (iface
->ref
) i
= write_proxy_methods(iface
->ref
);
828 var_t
*def
= cur
->def
;
829 if (!is_callas(def
->attrs
)) {
830 if (i
) fprintf(proxy
, ",\n");
831 print_proxy( "%s_", iface
->name
);
832 write_name(proxy
, def
);
833 fprintf(proxy
, "_Proxy");
836 cur
= PREV_LINK(cur
);
841 static int write_stub_methods(type_t
*iface
)
843 func_t
*cur
= iface
->funcs
;
848 if (iface
->ref
) i
= write_stub_methods(iface
->ref
);
849 else return i
; /* skip IUnknown */
851 var_t
*def
= cur
->def
;
852 if (!is_local(def
->attrs
)) {
853 if (i
) fprintf(proxy
,",\n");
854 print_proxy( "%s_", iface
->name
);
855 write_name(proxy
, def
);
856 fprintf(proxy
, "_Stub");
859 cur
= PREV_LINK(cur
);
864 static void write_proxy(type_t
*iface
)
866 int midx
= -1, stubs
;
867 func_t
*cur
= iface
->funcs
;
873 /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
875 fprintf(proxy
, "/*****************************************************************************\n");
876 fprintf(proxy
, " * %s interface\n", iface
->name
);
877 fprintf(proxy
, " */\n");
879 var_t
*def
= cur
->def
;
880 if (!is_local(def
->attrs
)) {
881 var_t
*cas
= is_callas(def
->attrs
);
882 char *cname
= cas
? cas
->name
: NULL
;
885 func_t
*m
= iface
->funcs
;
886 while (m
&& strcmp(get_name(m
->def
), cname
))
890 gen_proxy(iface
, cur
, idx
);
891 gen_stub(iface
, cur
, cname
);
892 if (midx
== -1) midx
= idx
;
893 else if (midx
!= idx
) yyerror("method index mismatch in write_proxy");
896 cur
= PREV_LINK(cur
);
900 print_proxy( "const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx
, iface
->name
);
903 print_proxy( "{\n", iface
->name
);
905 print_proxy( "&IID_%s,\n", iface
->name
);
907 print_proxy( "},\n");
910 write_proxy_methods(iface
);
911 fprintf(proxy
, "\n");
915 print_proxy( "};\n");
916 fprintf(proxy
, "\n\n");
919 print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface
->name
);
922 stubs
= write_stub_methods(iface
);
923 fprintf(proxy
, "\n");
925 fprintf(proxy
, "};\n");
927 print_proxy( "const CInterfaceStubVtbl _%sStubVtbl =\n", iface
->name
);
932 print_proxy( "&IID_%s,\n", iface
->name
);
933 print_proxy( "0,\n");
934 print_proxy( "%d,\n", stubs
+3);
935 print_proxy( "&%s_table[-3],\n", iface
->name
);
937 print_proxy( "},\n", iface
->name
);
940 print_proxy( "CStdStubBuffer_METHODS\n");
944 print_proxy( "};\n");
948 void write_proxies(ifref_t
*ifaces
)
950 ifref_t
*lcur
= ifaces
;
952 char *file_id
= proxy_token
;
955 if (!do_proxies
) return;
964 if (is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
965 write_proxy(cur
->iface
);
966 cur
= PREV_LINK(cur
);
973 print_proxy( "#if !defined(__RPC_WIN32__)\n");
974 print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
975 print_proxy( "#endif\n");
977 write_formatstring( 1 );
978 write_formatstring( 0 );
980 fprintf(proxy
, "const CInterfaceProxyVtbl* _%s_ProxyVtblList[] =\n", file_id
);
981 fprintf(proxy
, "{\n");
984 if(cur
->iface
->ref
&& cur
->iface
->funcs
&&
985 is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
986 fprintf(proxy
, " (CInterfaceProxyVtbl*)&_%sProxyVtbl,\n", cur
->iface
->name
);
987 cur
= PREV_LINK(cur
);
989 fprintf(proxy
, " 0\n");
990 fprintf(proxy
, "};\n");
991 fprintf(proxy
, "\n");
993 fprintf(proxy
, "const CInterfaceStubVtbl* _%s_StubVtblList[] =\n", file_id
);
994 fprintf(proxy
, "{\n");
997 if(cur
->iface
->ref
&& cur
->iface
->funcs
&&
998 is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
999 fprintf(proxy
, " (CInterfaceStubVtbl*)&_%sStubVtbl,\n", cur
->iface
->name
);
1000 cur
= PREV_LINK(cur
);
1002 fprintf(proxy
, " 0\n");
1003 fprintf(proxy
, "};\n");
1004 fprintf(proxy
, "\n");
1006 fprintf(proxy
, "PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id
);
1007 fprintf(proxy
, "{\n");
1010 if(cur
->iface
->ref
&& cur
->iface
->funcs
&&
1011 is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
1012 fprintf(proxy
, " \"%s\",\n", cur
->iface
->name
);
1013 cur
= PREV_LINK(cur
);
1015 fprintf(proxy
, " 0\n");
1016 fprintf(proxy
, "};\n");
1017 fprintf(proxy
, "\n");
1019 fprintf(proxy
, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id
, file_id
);
1020 fprintf(proxy
, "\n");
1021 fprintf(proxy
, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id
);
1022 fprintf(proxy
, "{\n");
1028 fprintf(proxy
, " if (!_%s_CHECK_IID(%d))\n", file_id
, c
);
1029 fprintf(proxy
, " {\n");
1030 fprintf(proxy
, " *pIndex = %d;\n", c
);
1031 fprintf(proxy
, " return 1;\n");
1032 fprintf(proxy
, " }\n");
1035 cur
= PREV_LINK(cur
);
1037 fprintf(proxy
, " return 0;\n");
1038 fprintf(proxy
, "}\n");
1039 fprintf(proxy
, "\n");
1041 fprintf(proxy
, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id
);
1042 fprintf(proxy
, "{\n");
1043 fprintf(proxy
, " (PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id
);
1044 fprintf(proxy
, " (PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id
);
1045 fprintf(proxy
, " (const PCInterfaceName*)&_%s_InterfaceNamesList,\n", file_id
);
1046 fprintf(proxy
, " 0,\n");
1047 fprintf(proxy
, " &_%s_IID_Lookup,\n", file_id
);
1048 fprintf(proxy
, " %d,\n", c
);
1049 fprintf(proxy
, " 1,\n");
1050 fprintf(proxy
, " 0,\n");
1051 fprintf(proxy
, " 0,\n");
1052 fprintf(proxy
, " 0,\n");
1053 fprintf(proxy
, " 0\n");
1054 fprintf(proxy
, "};\n");