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
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 for( i
=0; i
<indent
; i
++ )
60 fprintf( proxy
, " " );
61 r
= vfprintf( proxy
, format
, va
);
67 static type_t
*get_base_type( var_t
*arg
)
69 type_t
*t
= arg
->type
;
70 while( (t
->type
== 0) && t
->ref
)
75 static void write_stubdescproto(void)
77 print_proxy( "extern const MIDL_STUB_DESC Object_StubDesc;\n");
81 static void write_stubdesc(void)
83 print_proxy( "const MIDL_STUB_DESC Object_StubDesc = {\n");
84 print_proxy( " 0,\n");
85 print_proxy( " NdrOleAllocate,\n");
86 print_proxy( " NdrOleFree,\n");
87 print_proxy( " {0}, 0, 0, 0, 0,\n");
88 print_proxy( " 0 /* __MIDL_TypeFormatString.Format */\n");
93 static void write_formatdesc( const char *str
)
95 print_proxy( "typedef struct _MIDL_%s_FORMAT_STRING\n", str
);
98 print_proxy( "short Pad;\n");
99 print_proxy( "unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str
);
101 print_proxy( "} MIDL_%s_FORMAT_STRING;\n", str
);
105 static void write_formatstringsdecl(void)
107 print_proxy( "#define TYPE_FORMAT_STRING_SIZE %d\n",1); /* FIXME */
108 print_proxy( "#define PROC_FORMAT_STRING_SIZE %d\n",1); /* FIXME */
109 fprintf(proxy
, "\n");
110 write_formatdesc( "TYPE" );
111 write_formatdesc( "PROC" );
112 fprintf(proxy
, "\n");
113 print_proxy( "extern const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
114 print_proxy( "extern const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
118 static void write_formatstring( int proc
)
131 print_proxy( "static const MIDL_%s_FORMAT_STRING __MIDL_%sFormatString =\n", t
, n
);
134 print_proxy( "0,\n");
141 print_proxy( "};\n");
145 static void init_proxy(void)
148 if(!(proxy
= fopen(proxy_name
, "w")))
149 error("Could not open %s for output\n", proxy_name
);
150 print_proxy( "/*** Autogenerated by WIDL %s - Do not edit ***/\n", WIDL_FULLVERSION
);
152 print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
153 print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
154 print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
156 print_proxy( "#include \"rpcproxy.h\"\n");
157 print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
158 print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
159 print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
161 print_proxy( "#include \"%s\"\n", header_name
);
163 write_formatstringsdecl();
164 write_stubdescproto();
167 static void clear_output_vars( var_t
*arg
)
171 if (is_attr(arg
->attrs
, ATTR_OUT
) && !is_attr(arg
->attrs
, ATTR_IN
)) {
172 print_proxy( "if(%s)\n", arg
->name
);
174 print_proxy( "MIDL_memset( %s, 0, sizeof( ", arg
->name
);
176 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
177 fprintf( proxy
, " ));\n" );
179 arg
= PREV_LINK(arg
);
183 static int is_pointer(var_t
*arg
)
187 if (arg
->type
->type
== RPC_FC_FP
)
192 static void proxy_check_pointers( var_t
*arg
)
196 if (is_pointer(arg
)) {
197 print_proxy( "if(!%s)\n", arg
->name
);
199 print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
202 arg
= PREV_LINK(arg
);
206 static void marshall_size_arg( var_t
*arg
)
209 const type_t
*type
= get_base_type(arg
);
212 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
215 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
216 write_expr(proxy
, expr
, 0);
217 fprintf(proxy
, ";\n\n");
218 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
219 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
227 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 1, arg
->name
);
234 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 2, arg
->name
);
240 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 4, arg
->name
);
244 print_proxy( "NdrSimpleStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
245 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
248 case RPC_FC_C_CSTRING
:
249 case RPC_FC_C_WSTRING
:
251 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
252 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
255 case RPC_FC_BOGUS_STRUCT
:
256 print_proxy( "NdrComplexStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
257 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
263 memset( &temp
, 0, sizeof temp
);
264 temp
.type
= type
->ref
;
265 temp
.name
= arg
->name
; /* FIXME */
267 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
269 marshall_size_arg( &temp
);
274 print_proxy( "NdrPointerBufferSize( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
275 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
279 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
283 static void proxy_gen_marshall_size( var_t
*arg
)
285 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
289 if (is_attr(arg
->attrs
, ATTR_IN
))
291 marshall_size_arg( arg
);
292 fprintf(proxy
, "\n");
294 arg
= PREV_LINK(arg
);
298 static void marshall_copy_arg( var_t
*arg
)
301 type_t
*type
= get_base_type(arg
);
304 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
307 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
308 write_expr(proxy
, expr
, 0);
309 fprintf(proxy
, ";\n\n");
310 print_proxy( "NdrConformantArrayMarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
311 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
327 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
328 fprintf(proxy
, " *)_StubMsg.Buffer = %s;\n", arg
->name
);
329 fprintf(proxy
, "_StubMsg.Buffer += sizeof(");
330 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
331 fprintf(proxy
, ");\n");
335 /* FIXME: add the format string, and set the index below */
336 print_proxy( "NdrSimpleStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
337 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
340 case RPC_FC_C_CSTRING
:
341 case RPC_FC_C_WSTRING
:
345 case RPC_FC_BOGUS_STRUCT
:
346 print_proxy( "NdrComplexStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
347 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d] );\n", index
);
353 memset( &temp
, 0, sizeof temp
);
354 temp
.type
= type
->ref
;
355 temp
.name
= arg
->name
; /* FIXME */
357 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
359 marshall_copy_arg( &temp
);
364 print_proxy( "NdrPointerMarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
365 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
369 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
373 static void gen_marshall_copydata( var_t
*arg
)
377 if (is_attr(arg
->attrs
, ATTR_IN
))
379 marshall_copy_arg( arg
);
380 fprintf(proxy
, "\n");
382 arg
= PREV_LINK(arg
);
386 static void gen_marshall( var_t
*arg
)
388 /* generated code to determine the size of the buffer required */
389 proxy_gen_marshall_size( arg
);
391 /* generated code to allocate the buffer */
392 print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
394 /* generated code to copy the args into the buffer */
395 gen_marshall_copydata( arg
);
400 static void unmarshall_copy_arg( var_t
*arg
)
403 type_t
*type
= get_base_type(arg
);
406 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
409 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
410 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
425 print_proxy( "%s = *(", arg
->name
);
426 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
427 fprintf(proxy
," *)_StubMsg.Buffer;\n");
428 fprintf(proxy
, "_StubMsg.Buffer += sizeof(");
429 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
430 fprintf(proxy
, ");\n");
434 print_proxy( "NdrSimpleStructUnmarshall(&_StubMsg, (unsigned char**)%s, ", arg
->name
);
435 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
438 case RPC_FC_C_CSTRING
:
439 case RPC_FC_C_WSTRING
:
441 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char*)%s, ", arg
->name
);
442 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d]);\n", index
);
445 case RPC_FC_BOGUS_STRUCT
:
446 print_proxy( "NdrComplexStructUnmarshall(&_StubMsg, (unsigned char*)%s, ", arg
->name
);
447 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index
);
453 memset( &temp
, 0, sizeof temp
);
454 temp
.type
= type
->ref
;
455 temp
.name
= arg
->name
; /* FIXME */
457 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__
, arg
->name
);
459 unmarshall_copy_arg( &temp
);
464 print_proxy( "NdrPointerUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg
->name
);
465 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index
);
469 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
473 static void gen_unmarshall( var_t
*arg
)
477 if (is_attr(arg
->attrs
, ATTR_OUT
))
479 unmarshall_copy_arg( arg
);
480 fprintf(proxy
, "\n");
482 arg
= PREV_LINK(arg
);
486 static void free_variable( var_t
*arg
)
489 int index
= 0; /* FIXME */
493 expr
= get_attrp( arg
->attrs
, ATTR_SIZEIS
);
496 print_proxy( "_StubMsg.MaxCount = ", arg
->name
);
497 write_expr(proxy
, expr
, 0);
498 fprintf(proxy
, ";\n\n");
499 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
500 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], ", index
);
501 fprintf(proxy
, "(void*)%s );\n", arg
->name
);
505 type
= get_base_type(arg
);
522 constraint
= get_attrp( arg
->attrs
, ATTR_IIDIS
);
524 print_proxy( "_StubMsg.MaxCount = (unsigned long) ( %s );\n",constraint
->name
);
525 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
526 fprintf(proxy
, "&__MIDL_TypeFormatString.Format[%d], ", index
);
527 fprintf(proxy
, "(void*)%s );\n", arg
->name
);
531 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__
, arg
->name
, type
->type
);
535 static void proxy_free_variables( var_t
*arg
)
539 if (is_attr(arg
->attrs
, ATTR_OUT
))
541 free_variable( arg
);
542 fprintf(proxy
, "\n");
544 arg
= PREV_LINK(arg
);
548 static void gen_proxy(type_t
*iface
, func_t
*cur
, int idx
)
550 var_t
*def
= cur
->def
;
551 int has_ret
= !is_void(def
->type
, def
);
554 write_type(proxy
, def
->type
, def
, def
->tname
);
555 print_proxy( " STDMETHODCALLTYPE %s_", iface
->name
);
556 write_name(proxy
, def
);
557 print_proxy( "_Proxy(\n");
558 write_args(proxy
, cur
->args
, iface
->name
, 1, TRUE
);
562 /* local variables */
565 write_type(proxy
, def
->type
, def
, def
->tname
);
566 print_proxy( " _RetVal;\n");
568 print_proxy( "RPC_MESSAGE _Msg;\n" );
569 print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
573 clear_output_vars( cur
->args
);
575 print_proxy( "RpcTryExcept\n" );
576 print_proxy( "{\n" );
578 print_proxy( "NdrProxyInitialize(This, &_Msg, &_StubMsg, &Object_StubDesc, %d);\n", idx
);
579 proxy_check_pointers( cur
->args
);
581 print_proxy( "RpcTryFinally\n" );
582 print_proxy( "{\n" );
585 gen_marshall( cur
->args
);
587 print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
588 fprintf(proxy
, "\n");
589 print_proxy("if ((_Msg.DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
591 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
593 fprintf(proxy
, "\n");
595 gen_unmarshall( cur
->args
);
598 * FIXME: We only need to round the buffer up if it could be unaligned...
599 * We should calculate how much buffer we used and output the following
600 * line only if necessary.
602 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
604 print_proxy( "_RetVal = *(" );
605 write_type(proxy
, def
->type
, def
, def
->tname
);
606 fprintf(proxy
, " *)_StubMsg.Buffer;\n");
607 fprintf(proxy
, "_StubMsg.Buffer += sizeof(");
608 write_type(proxy
, def
->type
, def
, def
->tname
);
609 fprintf(proxy
, ");\n");
614 print_proxy( "RpcFinally\n" );
615 print_proxy( "{\n" );
617 print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
620 print_proxy( "RpcEndFinally\n" );
622 print_proxy( "}\n" );
623 print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
624 print_proxy( "{\n" );
627 proxy_free_variables( cur
->args
);
628 print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
631 print_proxy( "}\n" );
632 print_proxy( "RpcEndExcept\n" );
635 print_proxy( "return _RetVal;\n" );
642 static void stub_write_locals( var_t
*arg
)
646 int outptr
= is_attr(arg
->attrs
, ATTR_OUT
);
648 /* create a temporary variable to store the output */
651 memset( &temp
, 0, sizeof temp
);
652 temp
.ptr_level
= arg
->ptr_level
- 1; /* dereference once */
654 write_type(proxy
, arg
->type
, &temp
, arg
->tname
);
655 fprintf(proxy
, " _M%d;\n",n
++);
658 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
660 write_name(proxy
, arg
);
661 fprintf(proxy
, ";\n");
662 arg
= NEXT_LINK(arg
);
666 static void stub_unmarshall( var_t
*arg
)
671 if (is_attr(arg
->attrs
, ATTR_IN
))
673 unmarshall_copy_arg( arg
);
676 else if (is_attr(arg
->attrs
, ATTR_OUT
)) {
677 type_t
*type
= get_base_type(arg
);
681 print_proxy("MIDL_memset(");
682 write_name(proxy
, arg
);
683 fprintf(proxy
,", 0, sizeof(");
684 write_type(proxy
, arg
->type
, arg
, arg
->tname
);
685 fprintf(proxy
,"));\n");
689 write_name(proxy
, arg
);
690 fprintf(proxy
," = &_M%d;\n", n
);
691 print_proxy("_M%d = 0;\n", n
++);
695 arg
= PREV_LINK(arg
);
699 static void stub_gen_marshall_size( var_t
*arg
)
701 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
705 if (is_attr(arg
->attrs
, ATTR_OUT
))
706 marshall_size_arg( arg
);
707 arg
= PREV_LINK(arg
);
711 static void stub_gen_marshall_copydata( var_t
*arg
)
715 if (is_attr(arg
->attrs
, ATTR_OUT
))
716 marshall_copy_arg( arg
);
717 arg
= PREV_LINK(arg
);
721 static void stub_genmarshall( var_t
*args
)
723 /* FIXME: size buffer */
724 stub_gen_marshall_size( args
);
726 print_proxy("NdrStubGetBuffer(This, pRpcChannelBuffer, &_StubMsg);\n");
728 stub_gen_marshall_copydata( args
);
731 static void gen_stub(type_t
*iface
, func_t
*cur
, const char *cas
)
733 var_t
*def
= cur
->def
;
735 int has_ret
= !is_void(def
->type
, def
);
738 print_proxy( "void __RPC_STUB %s_", iface
->name
);
739 write_name(proxy
, def
);
740 print_proxy( "_Stub(\n");
742 print_proxy( "IRpcStubBuffer* This,\n");
743 print_proxy( "IRpcChannelBuffer* pRpcChannelBuffer,\n");
744 print_proxy( "PRPC_MESSAGE _Msg,\n");
745 print_proxy( "DWORD* _pdwStubPhase)\n");
749 /* local variables */
752 write_type(proxy
, def
->type
, def
, def
->tname
);
753 fprintf(proxy
, " _RetVal;\n");
755 print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface
->name
, iface
->name
);
756 print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
757 stub_write_locals( cur
->args
);
758 fprintf(proxy
, "\n");
762 print_proxy("NdrStubInitialize(_Msg, &_StubMsg, &Object_StubDesc, pRpcChannelBuffer);\n");
763 fprintf(proxy
, "\n");
765 print_proxy("RpcTryFinally\n");
768 print_proxy("if ((_Msg->DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
770 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
772 fprintf(proxy
, "\n");
774 stub_unmarshall( cur
->args
);
775 fprintf(proxy
, "\n");
777 print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
778 fprintf(proxy
, "\n");
780 if (has_ret
) fprintf(proxy
, "_RetVal = ");
781 fprintf(proxy
, "%s_", iface
->name
);
782 if (cas
) fprintf(proxy
, "%s_Stub", cas
);
783 else write_name(proxy
, def
);
784 fprintf(proxy
, "(_This");
789 fprintf(proxy
, ", ");
790 write_name(proxy
, arg
);
791 arg
= PREV_LINK(arg
);
794 fprintf(proxy
, ");\n");
795 fprintf(proxy
, "\n");
796 print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
797 fprintf(proxy
, "\n");
799 stub_genmarshall( cur
->args
);
800 fprintf(proxy
, "\n");
804 * FIXME: We only need to round the buffer up if it could be unaligned...
805 * We should calculate how much buffer we used and output the following
806 * line only if necessary.
808 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
811 write_type(proxy
, def
->type
, def
, def
->tname
);
812 fprintf(proxy
, " *)_StubMsg.Buffer = _RetVal;\n");
813 fprintf(proxy
, "_StubMsg.Buffer += sizeof(");
814 write_type(proxy
, def
->type
, def
, def
->tname
);
815 fprintf(proxy
, ");\n");
820 print_proxy("RpcFinally\n");
823 print_proxy("RpcEndFinally\n");
825 print_proxy("_Msg->BufferLength = ((long)_StubMsg.Buffer - (long)_Msg->Buffer);\n");
832 static int write_proxy_methods(type_t
*iface
)
834 func_t
*cur
= iface
->funcs
;
839 if (iface
->ref
) i
= write_proxy_methods(iface
->ref
);
841 var_t
*def
= cur
->def
;
842 if (!is_callas(def
->attrs
)) {
843 if (i
) fprintf(proxy
, ",\n");
844 print_proxy( "%s_", iface
->name
);
845 write_name(proxy
, def
);
846 fprintf(proxy
, "_Proxy");
849 cur
= PREV_LINK(cur
);
854 static int write_stub_methods(type_t
*iface
)
856 func_t
*cur
= iface
->funcs
;
861 if (iface
->ref
) i
= write_stub_methods(iface
->ref
);
862 else return i
; /* skip IUnknown */
864 var_t
*def
= cur
->def
;
865 if (!is_local(def
->attrs
)) {
866 if (i
) fprintf(proxy
,",\n");
867 print_proxy( "%s_", iface
->name
);
868 write_name(proxy
, def
);
869 fprintf(proxy
, "_Stub");
872 cur
= PREV_LINK(cur
);
877 static void write_proxy(type_t
*iface
)
879 int midx
= -1, stubs
;
880 func_t
*cur
= iface
->funcs
;
886 /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
888 fprintf(proxy
, "/*****************************************************************************\n");
889 fprintf(proxy
, " * %s interface\n", iface
->name
);
890 fprintf(proxy
, " */\n");
892 var_t
*def
= cur
->def
;
893 if (!is_local(def
->attrs
)) {
894 var_t
*cas
= is_callas(def
->attrs
);
895 const char *cname
= cas
? cas
->name
: NULL
;
898 func_t
*m
= iface
->funcs
;
899 while (m
&& strcmp(get_name(m
->def
), cname
))
903 gen_proxy(iface
, cur
, idx
);
904 gen_stub(iface
, cur
, cname
);
905 if (midx
== -1) midx
= idx
;
906 else if (midx
!= idx
) yyerror("method index mismatch in write_proxy");
909 cur
= PREV_LINK(cur
);
913 print_proxy( "const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx
, iface
->name
);
916 print_proxy( "{\n", iface
->name
);
918 print_proxy( "&IID_%s,\n", iface
->name
);
920 print_proxy( "},\n");
923 write_proxy_methods(iface
);
924 fprintf(proxy
, "\n");
928 print_proxy( "};\n");
929 fprintf(proxy
, "\n\n");
932 print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface
->name
);
935 stubs
= write_stub_methods(iface
);
936 fprintf(proxy
, "\n");
938 fprintf(proxy
, "};\n");
940 print_proxy( "const CInterfaceStubVtbl _%sStubVtbl =\n", iface
->name
);
945 print_proxy( "&IID_%s,\n", iface
->name
);
946 print_proxy( "0,\n");
947 print_proxy( "%d,\n", stubs
+3);
948 print_proxy( "&%s_table[-3],\n", iface
->name
);
950 print_proxy( "},\n", iface
->name
);
953 print_proxy( "CStdStubBuffer_METHODS\n");
957 print_proxy( "};\n");
961 void write_proxies(ifref_t
*ifaces
)
963 ifref_t
*lcur
= ifaces
;
965 char *file_id
= proxy_token
;
968 if (!do_proxies
) return;
977 if (is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
978 write_proxy(cur
->iface
);
979 cur
= PREV_LINK(cur
);
986 print_proxy( "#if !defined(__RPC_WIN32__)\n");
987 print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
988 print_proxy( "#endif\n");
990 write_formatstring( 1 );
991 write_formatstring( 0 );
993 fprintf(proxy
, "const CInterfaceProxyVtbl* _%s_ProxyVtblList[] =\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
, " (CInterfaceProxyVtbl*)&_%sProxyVtbl,\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
, "const CInterfaceStubVtbl* _%s_StubVtblList[] =\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
, " (CInterfaceStubVtbl*)&_%sStubVtbl,\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
, "PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id
);
1020 fprintf(proxy
, "{\n");
1023 if(cur
->iface
->ref
&& cur
->iface
->funcs
&&
1024 is_object(cur
->iface
->attrs
) && !is_local(cur
->iface
->attrs
))
1025 fprintf(proxy
, " \"%s\",\n", cur
->iface
->name
);
1026 cur
= PREV_LINK(cur
);
1028 fprintf(proxy
, " 0\n");
1029 fprintf(proxy
, "};\n");
1030 fprintf(proxy
, "\n");
1032 fprintf(proxy
, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id
, file_id
);
1033 fprintf(proxy
, "\n");
1034 fprintf(proxy
, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id
);
1035 fprintf(proxy
, "{\n");
1041 fprintf(proxy
, " if (!_%s_CHECK_IID(%d))\n", file_id
, c
);
1042 fprintf(proxy
, " {\n");
1043 fprintf(proxy
, " *pIndex = %d;\n", c
);
1044 fprintf(proxy
, " return 1;\n");
1045 fprintf(proxy
, " }\n");
1048 cur
= PREV_LINK(cur
);
1050 fprintf(proxy
, " return 0;\n");
1051 fprintf(proxy
, "}\n");
1052 fprintf(proxy
, "\n");
1054 fprintf(proxy
, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id
);
1055 fprintf(proxy
, "{\n");
1056 fprintf(proxy
, " (PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id
);
1057 fprintf(proxy
, " (PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id
);
1058 fprintf(proxy
, " (const PCInterfaceName*)&_%s_InterfaceNamesList,\n", file_id
);
1059 fprintf(proxy
, " 0,\n");
1060 fprintf(proxy
, " &_%s_IID_Lookup,\n", file_id
);
1061 fprintf(proxy
, " %d,\n", c
);
1062 fprintf(proxy
, " 1,\n");
1063 fprintf(proxy
, " 0,\n");
1064 fprintf(proxy
, " 0,\n");
1065 fprintf(proxy
, " 0,\n");
1066 fprintf(proxy
, " 0\n");
1067 fprintf(proxy
, "};\n");