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"
41 #define END_OF_LIST(list) \
44 while (NEXT_LINK(list)) \
45 list = NEXT_LINK(list); \
50 static int indent
= 0;
52 /* FIXME: support generation of stubless proxies */
54 static int print_proxy( const char *format
, ... )
59 va_start( va
, format
);
60 if ( format
[0] != '\n' )
61 for( i
=0; i
<indent
; i
++ )
62 fprintf( proxy
, " " );
63 r
= vfprintf( proxy
, format
, va
);
68 static void write_stubdescproto(void)
70 print_proxy( "extern const MIDL_STUB_DESC Object_StubDesc;\n");
74 static void write_stubdesc(void)
76 print_proxy( "const MIDL_STUB_DESC Object_StubDesc = {\n");
77 print_proxy( " 0,\n");
78 print_proxy( " NdrOleAllocate,\n");
79 print_proxy( " NdrOleFree,\n");
80 print_proxy( " {0}, 0, 0, 0, 0,\n");
81 print_proxy( " 0 /* __MIDL_TypeFormatString.Format */\n");
86 static void init_proxy(ifref_t
*ifaces
)
89 if(!(proxy
= fopen(proxy_name
, "w")))
90 error("Could not open %s for output\n", proxy_name
);
91 print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION
, input_name
);
93 print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
94 print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
95 print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
97 print_proxy( "#include \"rpcproxy.h\"\n");
98 print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
99 print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
100 print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
102 print_proxy( "#include \"%s\"\n", header_name
);
104 write_formatstringsdecl(proxy
, indent
, ifaces
, 1);
105 write_stubdescproto();
108 static void clear_output_vars( var_t
*arg
)
112 if (is_attr(arg
->attrs
, ATTR_OUT
) && !is_attr(arg
->attrs
, ATTR_IN
)) {
113 print_proxy( "if(%s)\n", arg
->name
);
115 print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg
->name
, arg
->name
);
118 arg
= PREV_LINK(arg
);
122 int is_var_ptr(var_t
*v
)
124 return v
->ptr_level
|| is_ptr(v
->type
);
127 int cant_be_null(var_t
*v
)
129 /* Search backwards for the most recent pointer attribute. */
130 const attr_t
*attrs
= v
->attrs
;
131 const type_t
*type
= v
->type
;
141 int t
= get_attrv(attrs
, ATTR_POINTERTYPE
);
143 if (t
== RPC_FC_FP
|| t
== RPC_FC_OP
|| t
== RPC_FC_UP
)
158 return 1; /* Default is RPC_FC_RP. */
161 static int is_user_derived(var_t
*v
)
163 const attr_t
*attrs
= v
->attrs
;
164 const type_t
*type
= v
->type
;
174 if (is_attr(attrs
, ATTR_WIREMARSHAL
))
189 static void proxy_check_pointers( var_t
*arg
)
193 if (is_var_ptr(arg
) && cant_be_null(arg
)) {
194 print_proxy( "if(!%s)\n", arg
->name
);
196 print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
199 arg
= PREV_LINK(arg
);
203 static void marshall_size_arg( var_t
*arg
)
206 const type_t
*type
= arg
->type
;
209 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
212 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
213 write_expr(proxy
, expr
, 0);
214 fprintf(proxy
, ";\n\n");
215 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
216 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
220 if (is_user_derived(arg
))
222 print_proxy("NdrUserMarshalBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
223 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
227 if (is_string_type(arg
->attrs
, arg
->ptr_level
, arg
->array
))
229 print_proxy("NdrConformantStringBufferSize( &_StubMsg, (unsigned char*)s, ", arg
->name
);
230 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
237 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 1, arg
->name
);
244 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 2, arg
->name
);
250 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 4, arg
->name
);
254 print_proxy( "NdrSimpleStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
255 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
259 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
260 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
263 case RPC_FC_BOGUS_STRUCT
:
264 print_proxy( "NdrComplexStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
265 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
271 memset( &temp
, 0, sizeof temp
);
272 temp
.type
= type
->ref
;
273 temp
.name
= arg
->name
; /* FIXME */
275 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
277 marshall_size_arg( &temp
);
282 print_proxy( "NdrPointerBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
283 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
287 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
291 static void proxy_gen_marshall_size( var_t
*arg
)
293 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
297 if (is_attr(arg
->attrs
, ATTR_IN
))
299 marshall_size_arg( arg
);
300 fprintf(proxy
, "\n");
302 arg
= PREV_LINK(arg
);
306 static void marshall_copy_arg( var_t
*arg
)
309 type_t
*type
= arg
->type
;
312 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
315 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
316 write_expr(proxy
, expr
, 0);
317 fprintf(proxy
, ";\n\n");
318 print_proxy( "NdrConformantArrayMarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
319 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
323 if (is_user_derived(arg
))
325 print_proxy("NdrUserMarshalMarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
326 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
330 if (is_string_type(arg
->attrs
, arg
->ptr_level
, arg
->array
))
332 print_proxy("NdrConformantStringMarshall( &_StubMsg, (unsigned char*)s, ", arg
->name
);
333 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
348 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
349 fprintf(proxy
, " *)_StubMsg.Buffer = %s;\n", arg
->name
);
350 print_proxy("_StubMsg.Buffer += sizeof(");
351 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
352 fprintf(proxy
, ");\n");
356 /* FIXME: add the format string, and set the index below */
357 print_proxy( "NdrSimpleStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
358 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
364 case RPC_FC_BOGUS_STRUCT
:
365 print_proxy( "NdrComplexStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
366 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
372 memset( &temp
, 0, sizeof temp
);
373 temp
.type
= type
->ref
;
374 temp
.name
= arg
->name
; /* FIXME */
376 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
378 marshall_copy_arg( &temp
);
383 print_proxy( "NdrPointerMarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
384 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
388 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
392 static void gen_marshall_copydata( var_t
*arg
)
396 if (is_attr(arg
->attrs
, ATTR_IN
))
398 marshall_copy_arg( arg
);
399 fprintf(proxy
, "\n");
401 arg
= PREV_LINK(arg
);
405 static void gen_marshall( var_t
*arg
)
407 /* generated code to determine the size of the buffer required */
408 proxy_gen_marshall_size( arg
);
410 /* generated code to allocate the buffer */
411 print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
413 /* generated code to copy the args into the buffer */
414 gen_marshall_copydata( arg
);
419 static void unmarshall_copy_arg( var_t
*arg
)
422 type_t
*type
= arg
->type
;
425 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
428 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg
->name
);
429 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
433 if (is_user_derived(arg
))
435 print_proxy("NdrUserMarshalUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg
->name
);
436 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index
);
440 if (is_string_type(arg
->attrs
, arg
->ptr_level
, arg
->array
))
442 print_proxy("NdrConformantStringUnmarshall( &_StubMsg, (unsigned char**)&s, ", arg
->name
);
443 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index
);
457 print_proxy( "%s = *(", arg
->name
);
458 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
459 fprintf(proxy
," *)_StubMsg.Buffer;\n");
460 print_proxy("_StubMsg.Buffer += sizeof(");
461 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
462 fprintf(proxy
, ");\n");
466 print_proxy( "NdrSimpleStructUnmarshall(&_StubMsg, (unsigned char**)%s, ", arg
->name
);
467 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
471 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg
->name
);
472 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
475 case RPC_FC_BOGUS_STRUCT
:
476 print_proxy( "NdrComplexStructUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg
->name
);
477 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index
);
483 memset( &temp
, 0, sizeof temp
);
484 temp
.type
= type
->ref
;
485 temp
.name
= arg
->name
; /* FIXME */
487 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
489 unmarshall_copy_arg( &temp
);
494 print_proxy( "NdrPointerUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg
->name
);
495 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
499 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
503 static void gen_unmarshall( var_t
*arg
)
507 if (is_attr(arg
->attrs
, ATTR_OUT
))
509 unmarshall_copy_arg( arg
);
510 fprintf(proxy
, "\n");
512 arg
= PREV_LINK(arg
);
516 static void free_variable( var_t
*arg
)
519 int index
= 0; /* FIXME */
523 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
526 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
527 write_expr(proxy
, expr
, 0);
528 fprintf(proxy
, ";\n\n");
529 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
530 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], ", index
);
531 fprintf(proxy
, "(void*)%s );\n", arg
->name
);
552 constraint
= get_attrp( arg
->attrs
, ATTR_IIDIS
);
554 print_proxy( "_StubMsg.MaxCount = (unsigned long) ( %s );\n",constraint
->name
);
555 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
556 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], ", index
);
557 fprintf(proxy
, "(void*)%s );\n", arg
->name
);
561 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
565 static void proxy_free_variables( var_t
*arg
)
569 if (is_attr(arg
->attrs
, ATTR_OUT
))
571 free_variable( arg
);
572 fprintf(proxy
, "\n");
574 arg
= PREV_LINK(arg
);
578 static void gen_proxy(type_t
*iface
, func_t
*cur
, int idx
)
580 var_t
*def
= cur
->def
;
581 int has_ret
= !is_void(def
->type
, def
);
584 write_type(proxy
, def
->type
, def
, def
->tname
);
585 print_proxy( " STDMETHODCALLTYPE %s_", iface
->name
);
586 write_name(proxy
, def
);
587 print_proxy( "_Proxy(\n");
588 write_args(proxy
, cur
->args
, iface
->name
, 1, TRUE
);
592 /* local variables */
595 write_type(proxy
, def
->type
, def
, def
->tname
);
596 print_proxy( " _RetVal;\n");
598 print_proxy( "RPC_MESSAGE _Msg;\n" );
599 print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
603 clear_output_vars( cur
->args
);
605 print_proxy( "RpcTryExcept\n" );
606 print_proxy( "{\n" );
608 print_proxy( "NdrProxyInitialize(This, &_Msg, &_StubMsg, &Object_StubDesc, %d);\n", idx
);
609 proxy_check_pointers( cur
->args
);
611 print_proxy( "RpcTryFinally\n" );
612 print_proxy( "{\n" );
615 gen_marshall( cur
->args
);
617 print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
618 fprintf(proxy
, "\n");
619 print_proxy("if ((_Msg.DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
621 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
623 fprintf(proxy
, "\n");
625 gen_unmarshall( cur
->args
);
628 * FIXME: We only need to round the buffer up if it could be unaligned...
629 * We should calculate how much buffer we used and output the following
630 * line only if necessary.
632 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
634 print_proxy( "_RetVal = *(" );
635 write_type(proxy
, def
->type
, def
, def
->tname
);
636 fprintf(proxy
, " *)_StubMsg.Buffer;\n");
637 print_proxy("_StubMsg.Buffer += sizeof(");
638 write_type(proxy
, def
->type
, def
, def
->tname
);
639 fprintf(proxy
, ");\n");
644 print_proxy( "RpcFinally\n" );
645 print_proxy( "{\n" );
647 print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
650 print_proxy( "RpcEndFinally\n" );
652 print_proxy( "}\n" );
653 print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
654 print_proxy( "{\n" );
657 proxy_free_variables( cur
->args
);
658 print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
661 print_proxy( "}\n" );
662 print_proxy( "RpcEndExcept\n" );
665 print_proxy( "return _RetVal;\n" );
672 static void stub_write_locals( var_t
*arg
)
677 int outptr
= is_attr(arg
->attrs
, ATTR_OUT
)
678 && ! is_attr(arg
->attrs
, ATTR_IN
);
680 /* create a temporary variable to store the output */
683 memset( &temp
, 0, sizeof temp
);
684 temp
.ptr_level
= arg
->ptr_level
- 1; /* dereference once */
686 write_type(proxy
, arg
->type
, &temp
, arg
->tname
);
687 fprintf(proxy
, " _M%d;\n",n
++);
690 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
692 write_name(proxy
, arg
);
693 fprintf(proxy
, ";\n");
694 arg
= PREV_LINK(arg
);
698 static void stub_unmarshall( var_t
*arg
)
703 if (is_attr(arg
->attrs
, ATTR_IN
))
705 unmarshall_copy_arg( arg
);
708 else if (is_attr(arg
->attrs
, ATTR_OUT
)) {
709 type_t
*type
= arg
->type
;
713 print_proxy("MIDL_memset(");
714 write_name(proxy
, arg
);
715 fprintf(proxy
,", 0, sizeof(");
716 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
717 fprintf(proxy
,"));\n");
721 write_name(proxy
, arg
);
722 fprintf(proxy
," = &_M%d;\n", n
);
723 print_proxy("MIDL_memset(&_M%d, 0, sizeof _M%d);\n", n
, n
);
728 arg
= PREV_LINK(arg
);
732 static void stub_gen_marshall_size( var_t
*arg
)
734 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
738 if (is_attr(arg
->attrs
, ATTR_OUT
))
739 marshall_size_arg( arg
);
740 arg
= PREV_LINK(arg
);
744 static void stub_gen_marshall_copydata( var_t
*arg
)
748 if (is_attr(arg
->attrs
, ATTR_OUT
))
749 marshall_copy_arg( arg
);
750 arg
= PREV_LINK(arg
);
754 static void stub_genmarshall( var_t
*args
)
756 /* FIXME: size buffer */
757 stub_gen_marshall_size( args
);
759 print_proxy("NdrStubGetBuffer(This, pRpcChannelBuffer, &_StubMsg);\n");
761 stub_gen_marshall_copydata( args
);
764 static void gen_stub(type_t
*iface
, func_t
*cur
, const char *cas
)
766 var_t
*def
= cur
->def
;
768 int has_ret
= !is_void(def
->type
, def
);
771 print_proxy( "void __RPC_STUB %s_", iface
->name
);
772 write_name(proxy
, def
);
773 print_proxy( "_Stub(\n");
775 print_proxy( "IRpcStubBuffer* This,\n");
776 print_proxy( "IRpcChannelBuffer* pRpcChannelBuffer,\n");
777 print_proxy( "PRPC_MESSAGE _Msg,\n");
778 print_proxy( "DWORD* _pdwStubPhase)\n");
782 /* local variables */
785 write_type(proxy
, def
->type
, def
, def
->tname
);
786 fprintf(proxy
, " _RetVal;\n");
788 print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface
->name
, iface
->name
);
789 print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
790 stub_write_locals( cur
->args
);
791 fprintf(proxy
, "\n");
795 print_proxy("NdrStubInitialize(_Msg, &_StubMsg, &Object_StubDesc, pRpcChannelBuffer);\n");
796 fprintf(proxy
, "\n");
798 print_proxy("RpcTryFinally\n");
801 print_proxy("if ((_Msg->DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
803 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
805 fprintf(proxy
, "\n");
807 stub_unmarshall( cur
->args
);
808 fprintf(proxy
, "\n");
810 print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
811 fprintf(proxy
, "\n");
813 if (has_ret
) fprintf(proxy
, "_RetVal = ");
814 fprintf(proxy
, "%s_", iface
->name
);
815 if (cas
) fprintf(proxy
, "%s_Stub", cas
);
816 else write_name(proxy
, def
);
817 fprintf(proxy
, "(_This");
822 fprintf(proxy
, ", ");
823 write_name(proxy
, arg
);
824 arg
= PREV_LINK(arg
);
827 fprintf(proxy
, ");\n");
828 fprintf(proxy
, "\n");
829 print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
830 fprintf(proxy
, "\n");
832 stub_genmarshall( cur
->args
);
833 fprintf(proxy
, "\n");
837 * FIXME: We only need to round the buffer up if it could be unaligned...
838 * We should calculate how much buffer we used and output the following
839 * line only if necessary.
841 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
844 write_type(proxy
, def
->type
, def
, def
->tname
);
845 fprintf(proxy
, " *)_StubMsg.Buffer = _RetVal;\n");
846 print_proxy("_StubMsg.Buffer += sizeof(");
847 write_type(proxy
, def
->type
, def
, def
->tname
);
848 fprintf(proxy
, ");\n");
853 print_proxy("RpcFinally\n");
856 print_proxy("RpcEndFinally\n");
858 print_proxy("_Msg->BufferLength = _StubMsg.Buffer - (unsigned char *)_Msg->Buffer;\n");
865 static int write_proxy_methods(type_t
*iface
)
867 func_t
*cur
= iface
->funcs
;
872 if (iface
->ref
) i
= write_proxy_methods(iface
->ref
);
874 var_t
*def
= cur
->def
;
875 if (!is_callas(def
->attrs
)) {
876 if (i
) fprintf(proxy
, ",\n");
877 print_proxy( "%s_", iface
->name
);
878 write_name(proxy
, def
);
879 fprintf(proxy
, "_Proxy");
882 cur
= PREV_LINK(cur
);
887 static int write_stub_methods(type_t
*iface
)
889 func_t
*cur
= iface
->funcs
;
894 if (iface
->ref
) i
= write_stub_methods(iface
->ref
);
895 else return i
; /* skip IUnknown */
897 var_t
*def
= cur
->def
;
898 if (!is_local(def
->attrs
)) {
899 if (i
) fprintf(proxy
,",\n");
900 print_proxy( "%s_", iface
->name
);
901 write_name(proxy
, def
);
902 fprintf(proxy
, "_Stub");
905 cur
= PREV_LINK(cur
);
910 static void write_proxy(type_t
*iface
)
912 int midx
= -1, stubs
;
913 func_t
*cur
= iface
->funcs
;
919 /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
921 fprintf(proxy
, "/*****************************************************************************\n");
922 fprintf(proxy
, " * %s interface\n", iface
->name
);
923 fprintf(proxy
, " */\n");
925 const var_t
*def
= cur
->def
;
926 if (!is_local(def
->attrs
)) {
927 const var_t
*cas
= is_callas(def
->attrs
);
928 const char *cname
= cas
? cas
->name
: NULL
;
931 const func_t
*m
= iface
->funcs
;
932 while (m
&& strcmp(get_name(m
->def
), cname
))
936 gen_proxy(iface
, cur
, idx
);
937 gen_stub(iface
, cur
, cname
);
938 if (midx
== -1) midx
= idx
;
939 else if (midx
!= idx
) parser_error("method index mismatch in write_proxy");
942 cur
= PREV_LINK(cur
);
946 print_proxy( "const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx
, iface
->name
);
949 print_proxy( "{\n", iface
->name
);
951 print_proxy( "&IID_%s,\n", iface
->name
);
953 print_proxy( "},\n");
956 write_proxy_methods(iface
);
957 fprintf(proxy
, "\n");
961 print_proxy( "};\n");
962 fprintf(proxy
, "\n\n");
965 print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface
->name
);
968 stubs
= write_stub_methods(iface
);
969 fprintf(proxy
, "\n");
971 fprintf(proxy
, "};\n");
973 print_proxy( "const CInterfaceStubVtbl _%sStubVtbl =\n", iface
->name
);
978 print_proxy( "&IID_%s,\n", iface
->name
);
979 print_proxy( "0,\n");
980 print_proxy( "%d,\n", stubs
+3);
981 print_proxy( "&%s_table[-3],\n", iface
->name
);
983 print_proxy( "},\n", iface
->name
);
986 print_proxy( "CStdStubBuffer_METHODS\n");
990 print_proxy( "};\n");
994 void write_proxies(ifref_t
*ifaces
)
996 ifref_t
*lcur
= ifaces
;
998 char *file_id
= proxy_token
;
1001 if (!do_proxies
) return;
1010 if (is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
1011 write_proxy(cur
->iface
);
1012 cur
= PREV_LINK(cur
);
1019 print_proxy( "#if !defined(__RPC_WIN32__)\n");
1020 print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
1021 print_proxy( "#endif\n");
1023 write_procformatstring(proxy
, ifaces
, 1);
1024 write_typeformatstring(proxy
, ifaces
, 1);
1026 fprintf(proxy
, "const CInterfaceProxyVtbl* _%s_ProxyVtblList[] =\n", file_id
);
1027 fprintf(proxy
, "{\n");
1030 if(cur
->iface
->ref
&& cur
->iface
->funcs
&&
1031 is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
1032 fprintf(proxy
, " (CInterfaceProxyVtbl*)&_%sProxyVtbl,\n", cur
->iface
->name
);
1033 cur
= PREV_LINK(cur
);
1035 fprintf(proxy
, " 0\n");
1036 fprintf(proxy
, "};\n");
1037 fprintf(proxy
, "\n");
1039 fprintf(proxy
, "const CInterfaceStubVtbl* _%s_StubVtblList[] =\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
, " (CInterfaceStubVtbl*)&_%sStubVtbl,\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
, "PCInterfaceName const _%s_InterfaceNamesList[] =\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
, " \"%s\",\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
, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id
, file_id
);
1066 fprintf(proxy
, "\n");
1067 fprintf(proxy
, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id
);
1068 fprintf(proxy
, "{\n");
1074 fprintf(proxy
, " if (!_%s_CHECK_IID(%d))\n", file_id
, c
);
1075 fprintf(proxy
, " {\n");
1076 fprintf(proxy
, " *pIndex = %d;\n", c
);
1077 fprintf(proxy
, " return 1;\n");
1078 fprintf(proxy
, " }\n");
1081 cur
= PREV_LINK(cur
);
1083 fprintf(proxy
, " return 0;\n");
1084 fprintf(proxy
, "}\n");
1085 fprintf(proxy
, "\n");
1087 fprintf(proxy
, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id
);
1088 fprintf(proxy
, "{\n");
1089 fprintf(proxy
, " (PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id
);
1090 fprintf(proxy
, " (PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id
);
1091 fprintf(proxy
, " (const PCInterfaceName*)&_%s_InterfaceNamesList,\n", file_id
);
1092 fprintf(proxy
, " 0,\n");
1093 fprintf(proxy
, " &_%s_IID_Lookup,\n", file_id
);
1094 fprintf(proxy
, " %d,\n", c
);
1095 fprintf(proxy
, " 1,\n");
1096 fprintf(proxy
, " 0,\n");
1097 fprintf(proxy
, " 0,\n");
1098 fprintf(proxy
, " 0,\n");
1099 fprintf(proxy
, " 0\n");
1100 fprintf(proxy
, "};\n");