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 \"objbase.h\"\n");
98 print_proxy( "#include \"rpcproxy.h\"\n");
99 print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
100 print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
101 print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
103 print_proxy( "#include \"%s\"\n", header_name);
105 write_formatstringsdecl(proxy, indent, ifaces, 1);
106 write_stubdescproto();
109 static void clear_output_vars( var_t *arg )
113 if (is_attr(arg->attrs, ATTR_OUT) && !is_attr(arg->attrs, ATTR_IN)) {
114 print_proxy( "if(%s)\n", arg->name );
116 print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg->name, arg->name );
119 arg = PREV_LINK(arg);
123 int is_var_ptr(var_t *v)
125 return v->ptr_level || is_ptr(v->type);
128 int cant_be_null(var_t *v)
130 /* Search backwards for the most recent pointer attribute. */
131 const attr_t *attrs = v->attrs;
132 const type_t *type = v->type;
142 int t = get_attrv(attrs, ATTR_POINTERTYPE);
144 if (t == RPC_FC_FP || t == RPC_FC_OP || t == RPC_FC_UP)
159 return 1; /* Default is RPC_FC_RP. */
162 static int is_user_derived(var_t *v)
164 const attr_t *attrs = v->attrs;
165 const type_t *type = v->type;
175 if (is_attr(attrs, ATTR_WIREMARSHAL))
190 static void proxy_check_pointers( var_t *arg )
194 if (is_var_ptr(arg) && cant_be_null(arg)) {
195 print_proxy( "if(!%s)\n", arg->name );
197 print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
200 arg = PREV_LINK(arg);
204 static void marshall_size_arg( var_t *arg )
207 const type_t *type = arg->type;
210 expr = get_attrp( arg->attrs, ATTR_SIZEIS );
213 print_proxy( "_StubMsg.MaxCount = ", arg->name );
214 write_expr(proxy, expr, 0);
215 fprintf(proxy, ";\n\n");
216 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name );
217 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
221 if (is_user_derived(arg))
223 print_proxy("NdrUserMarshalBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name);
224 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index);
228 if (is_string_type(arg->attrs, arg->ptr_level, arg->array))
230 print_proxy("NdrConformantStringBufferSize( &_StubMsg, (unsigned char*)s, ", arg->name);
231 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index);
238 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 1, arg->name );
245 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 2, arg->name );
251 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 4, arg->name );
255 print_proxy( "NdrSimpleStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg->name );
256 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index );
260 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name );
261 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
264 case RPC_FC_BOGUS_STRUCT:
265 print_proxy( "NdrComplexStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg->name );
266 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index );
272 memset( &temp, 0, sizeof temp );
273 temp.type = type->ref;
274 temp.name = arg->name; /* FIXME */
276 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__, arg->name );
278 marshall_size_arg( &temp );
283 print_proxy( "NdrPointerBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name );
284 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
288 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
292 static void proxy_gen_marshall_size( var_t *arg )
294 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
298 if (is_attr(arg->attrs, ATTR_IN))
300 marshall_size_arg( arg );
301 fprintf(proxy, "\n");
303 arg = PREV_LINK(arg);
307 static void marshall_copy_arg( var_t *arg )
310 type_t *type = arg->type;
313 expr = get_attrp( arg->attrs, ATTR_SIZEIS );
316 print_proxy( "_StubMsg.MaxCount = ", arg->name );
317 write_expr(proxy, expr, 0);
318 fprintf(proxy, ";\n\n");
319 print_proxy( "NdrConformantArrayMarshall( &_StubMsg, (unsigned char*)%s, ", arg->name );
320 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
324 if (is_user_derived(arg))
326 print_proxy("NdrUserMarshalMarshall( &_StubMsg, (unsigned char*)%s, ", arg->name);
327 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index);
331 if (is_string_type(arg->attrs, arg->ptr_level, arg->array))
333 print_proxy("NdrConformantStringMarshall( &_StubMsg, (unsigned char*)s, ", arg->name);
334 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index);
349 write_type(proxy, arg->type, arg, arg->tname);
350 fprintf(proxy, " *)_StubMsg.Buffer = %s;\n", arg->name );
351 print_proxy("_StubMsg.Buffer += sizeof(");
352 write_type(proxy, arg->type, arg, arg->tname);
353 fprintf(proxy, ");\n");
357 /* FIXME: add the format string, and set the index below */
358 print_proxy( "NdrSimpleStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg->name );
359 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
365 case RPC_FC_BOGUS_STRUCT:
366 print_proxy( "NdrComplexStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg->name );
367 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index );
373 memset( &temp, 0, sizeof temp );
374 temp.type = type->ref;
375 temp.name = arg->name; /* FIXME */
377 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__, arg->name );
379 marshall_copy_arg( &temp );
384 print_proxy( "NdrPointerMarshall( &_StubMsg, (unsigned char*)%s, ", arg->name );
385 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
389 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
393 static void gen_marshall_copydata( var_t *arg )
397 if (is_attr(arg->attrs, ATTR_IN))
399 marshall_copy_arg( arg );
400 fprintf(proxy, "\n");
402 arg = PREV_LINK(arg);
406 static void gen_marshall( var_t *arg )
408 /* generated code to determine the size of the buffer required */
409 proxy_gen_marshall_size( arg );
411 /* generated code to allocate the buffer */
412 print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
414 /* generated code to copy the args into the buffer */
415 gen_marshall_copydata( arg );
420 static void unmarshall_copy_arg( var_t *arg )
423 type_t *type = arg->type;
426 expr = get_attrp( arg->attrs, ATTR_SIZEIS );
429 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg->name );
430 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
434 if (is_user_derived(arg))
436 print_proxy("NdrUserMarshalUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg->name);
437 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index);
441 if (is_string_type(arg->attrs, arg->ptr_level, arg->array))
443 print_proxy("NdrConformantStringUnmarshall( &_StubMsg, (unsigned char**)&s, ", arg->name);
444 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index);
458 print_proxy( "%s = *(", arg->name );
459 write_type(proxy, arg->type, arg, arg->tname);
460 fprintf(proxy," *)_StubMsg.Buffer;\n");
461 print_proxy("_StubMsg.Buffer += sizeof(");
462 write_type(proxy, arg->type, arg, arg->tname);
463 fprintf(proxy, ");\n");
467 print_proxy( "NdrSimpleStructUnmarshall(&_StubMsg, (unsigned char**)%s, ", arg->name );
468 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
472 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg->name );
473 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
476 case RPC_FC_BOGUS_STRUCT:
477 print_proxy( "NdrComplexStructUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg->name );
478 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index );
484 memset( &temp, 0, sizeof temp );
485 temp.type = type->ref;
486 temp.name = arg->name; /* FIXME */
488 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__, arg->name );
490 unmarshall_copy_arg( &temp );
495 print_proxy( "NdrPointerUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg->name );
496 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
500 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
504 static void gen_unmarshall( var_t *arg )
508 if (is_attr(arg->attrs, ATTR_OUT))
510 unmarshall_copy_arg( arg );
511 fprintf(proxy, "\n");
513 arg = PREV_LINK(arg);
517 static void free_variable( var_t *arg )
520 int index = 0; /* FIXME */
524 expr = get_attrp( arg->attrs, ATTR_SIZEIS );
527 print_proxy( "_StubMsg.MaxCount = ", arg->name );
528 write_expr(proxy, expr, 0);
529 fprintf(proxy, ";\n\n");
530 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
531 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], ", index );
532 fprintf(proxy, "(void*)%s );\n", arg->name );
553 constraint = get_attrp( arg->attrs, ATTR_IIDIS );
555 print_proxy( "_StubMsg.MaxCount = (unsigned long) ( %s );\n",constraint->name);
556 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
557 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], ", index );
558 fprintf(proxy, "(void*)%s );\n", arg->name );
562 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
566 static void proxy_free_variables( var_t *arg )
570 if (is_attr(arg->attrs, ATTR_OUT))
572 free_variable( arg );
573 fprintf(proxy, "\n");
575 arg = PREV_LINK(arg);
579 static void gen_proxy(type_t *iface, func_t *cur, int idx)
581 var_t *def = cur->def;
582 int has_ret = !is_void(def->type, def);
585 write_type(proxy, def->type, def, def->tname);
586 print_proxy( " STDMETHODCALLTYPE %s_", iface->name);
587 write_name(proxy, def);
588 print_proxy( "_Proxy(\n");
589 write_args(proxy, cur->args, iface->name, 1, TRUE);
593 /* local variables */
596 write_type(proxy, def->type, def, def->tname);
597 print_proxy( " _RetVal;\n");
599 print_proxy( "RPC_MESSAGE _Msg;\n" );
600 print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
604 clear_output_vars( cur->args );
606 print_proxy( "RpcTryExcept\n" );
607 print_proxy( "{\n" );
609 print_proxy( "NdrProxyInitialize(This, &_Msg, &_StubMsg, &Object_StubDesc, %d);\n", idx);
610 proxy_check_pointers( cur->args );
612 print_proxy( "RpcTryFinally\n" );
613 print_proxy( "{\n" );
616 gen_marshall( cur->args );
618 print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
619 fprintf(proxy, "\n");
620 print_proxy("if ((_Msg.DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
622 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
624 fprintf(proxy, "\n");
626 gen_unmarshall( cur->args );
629 * FIXME: We only need to round the buffer up if it could be unaligned...
630 * We should calculate how much buffer we used and output the following
631 * line only if necessary.
633 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
635 print_proxy( "_RetVal = *(" );
636 write_type(proxy, def->type, def, def->tname);
637 fprintf(proxy, " *)_StubMsg.Buffer;\n");
638 print_proxy("_StubMsg.Buffer += sizeof(");
639 write_type(proxy, def->type, def, def->tname);
640 fprintf(proxy, ");\n");
645 print_proxy( "RpcFinally\n" );
646 print_proxy( "{\n" );
648 print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
651 print_proxy( "RpcEndFinally\n" );
653 print_proxy( "}\n" );
654 print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
655 print_proxy( "{\n" );
658 proxy_free_variables( cur->args );
659 print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
662 print_proxy( "}\n" );
663 print_proxy( "RpcEndExcept\n" );
666 print_proxy( "return _RetVal;\n" );
673 static void stub_write_locals( var_t *arg )
678 int outptr = is_attr(arg->attrs, ATTR_OUT)
679 && ! is_attr(arg->attrs, ATTR_IN);
681 /* create a temporary variable to store the output */
684 memset( &temp, 0, sizeof temp );
685 temp.ptr_level = arg->ptr_level - 1; /* dereference once */
687 write_type(proxy, arg->type, &temp, arg->tname);
688 fprintf(proxy, " _M%d;\n",n++);
691 write_type(proxy, arg->type, arg, arg->tname);
693 write_name(proxy, arg);
694 fprintf(proxy, ";\n");
695 arg = PREV_LINK(arg);
699 static void stub_unmarshall( var_t *arg )
704 if (is_attr(arg->attrs, ATTR_IN))
706 unmarshall_copy_arg( arg );
709 else if (is_attr(arg->attrs, ATTR_OUT)) {
710 type_t *type = arg->type;
714 print_proxy("MIDL_memset(");
715 write_name(proxy, arg);
716 fprintf(proxy,", 0, sizeof(");
717 write_type(proxy, arg->type, arg, arg->tname);
718 fprintf(proxy,"));\n");
722 write_name(proxy, arg);
723 fprintf(proxy," = &_M%d;\n", n);
724 print_proxy("MIDL_memset(&_M%d, 0, sizeof _M%d);\n", n, n);
729 arg = PREV_LINK(arg);
733 static void stub_gen_marshall_size( var_t *arg )
735 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
739 if (is_attr(arg->attrs, ATTR_OUT))
740 marshall_size_arg( arg );
741 arg = PREV_LINK(arg);
745 static void stub_gen_marshall_copydata( var_t *arg )
749 if (is_attr(arg->attrs, ATTR_OUT))
750 marshall_copy_arg( arg );
751 arg = PREV_LINK(arg);
755 static void stub_genmarshall( var_t *args )
757 /* FIXME: size buffer */
758 stub_gen_marshall_size( args );
760 print_proxy("NdrStubGetBuffer(This, pRpcChannelBuffer, &_StubMsg);\n");
762 stub_gen_marshall_copydata( args );
765 static void gen_stub(type_t *iface, func_t *cur, const char *cas)
767 var_t *def = cur->def;
769 int has_ret = !is_void(def->type, def);
772 print_proxy( "void __RPC_STUB %s_", iface->name);
773 write_name(proxy, def);
774 print_proxy( "_Stub(\n");
776 print_proxy( "IRpcStubBuffer* This,\n");
777 print_proxy( "IRpcChannelBuffer* pRpcChannelBuffer,\n");
778 print_proxy( "PRPC_MESSAGE _Msg,\n");
779 print_proxy( "DWORD* _pdwStubPhase)\n");
783 /* local variables */
786 write_type(proxy, def->type, def, def->tname);
787 fprintf(proxy, " _RetVal;\n");
789 print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface->name, iface->name);
790 print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
791 stub_write_locals( cur->args );
792 fprintf(proxy, "\n");
796 print_proxy("NdrStubInitialize(_Msg, &_StubMsg, &Object_StubDesc, pRpcChannelBuffer);\n");
797 fprintf(proxy, "\n");
799 print_proxy("RpcTryFinally\n");
802 print_proxy("if ((_Msg->DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
804 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
806 fprintf(proxy, "\n");
808 stub_unmarshall( cur->args );
809 fprintf(proxy, "\n");
811 print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
812 fprintf(proxy, "\n");
814 if (has_ret) fprintf(proxy, "_RetVal = ");
815 fprintf(proxy, "%s_", iface->name);
816 if (cas) fprintf(proxy, "%s_Stub", cas);
817 else write_name(proxy, def);
818 fprintf(proxy, "(_This");
823 fprintf(proxy, ", ");
824 write_name(proxy, arg);
825 arg = PREV_LINK(arg);
828 fprintf(proxy, ");\n");
829 fprintf(proxy, "\n");
830 print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
831 fprintf(proxy, "\n");
833 stub_genmarshall( cur->args );
834 fprintf(proxy, "\n");
838 * FIXME: We only need to round the buffer up if it could be unaligned...
839 * We should calculate how much buffer we used and output the following
840 * line only if necessary.
842 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
845 write_type(proxy, def->type, def, def->tname);
846 fprintf(proxy, " *)_StubMsg.Buffer = _RetVal;\n");
847 print_proxy("_StubMsg.Buffer += sizeof(");
848 write_type(proxy, def->type, def, def->tname);
849 fprintf(proxy, ");\n");
854 print_proxy("RpcFinally\n");
857 print_proxy("RpcEndFinally\n");
859 print_proxy("_Msg->BufferLength = _StubMsg.Buffer - (unsigned char *)_Msg->Buffer;\n");
866 static int write_proxy_methods(type_t *iface)
868 func_t *cur = iface->funcs;
873 if (iface->ref) i = write_proxy_methods(iface->ref);
875 var_t *def = cur->def;
876 if (!is_callas(def->attrs)) {
877 if (i) fprintf(proxy, ",\n");
878 print_proxy( "%s_", iface->name);
879 write_name(proxy, def);
880 fprintf(proxy, "_Proxy");
883 cur = PREV_LINK(cur);
888 static int write_stub_methods(type_t *iface)
890 func_t *cur = iface->funcs;
895 if (iface->ref) i = write_stub_methods(iface->ref);
896 else return i; /* skip IUnknown */
898 var_t *def = cur->def;
899 if (!is_local(def->attrs)) {
900 if (i) fprintf(proxy,",\n");
901 print_proxy( "%s_", iface->name);
902 write_name(proxy, def);
903 fprintf(proxy, "_Stub");
906 cur = PREV_LINK(cur);
911 static void write_proxy(type_t *iface)
913 int midx = -1, stubs;
914 func_t *cur = iface->funcs;
920 /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
922 fprintf(proxy, "/*****************************************************************************\n");
923 fprintf(proxy, " * %s interface\n", iface->name);
924 fprintf(proxy, " */\n");
926 const var_t *def = cur->def;
927 if (!is_local(def->attrs)) {
928 const var_t *cas = is_callas(def->attrs);
929 const char *cname = cas ? cas->name : NULL;
932 const func_t *m = iface->funcs;
933 while (m && strcmp(get_name(m->def), cname))
937 gen_proxy(iface, cur, idx);
938 gen_stub(iface, cur, cname);
939 if (midx == -1) midx = idx;
940 else if (midx != idx) parser_error("method index mismatch in write_proxy");
943 cur = PREV_LINK(cur);
947 print_proxy( "const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx, iface->name);
950 print_proxy( "{\n", iface->name);
952 print_proxy( "&IID_%s,\n", iface->name);
954 print_proxy( "},\n");
957 write_proxy_methods(iface);
958 fprintf(proxy, "\n");
962 print_proxy( "};\n");
963 fprintf(proxy, "\n\n");
966 print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface->name);
969 stubs = write_stub_methods(iface);
970 fprintf(proxy, "\n");
972 fprintf(proxy, "};\n");
974 print_proxy( "const CInterfaceStubVtbl _%sStubVtbl =\n", iface->name);
979 print_proxy( "&IID_%s,\n", iface->name);
980 print_proxy( "0,\n");
981 print_proxy( "%d,\n", stubs+3);
982 print_proxy( "&%s_table[-3],\n", iface->name);
984 print_proxy( "},\n", iface->name);
987 print_proxy( "CStdStubBuffer_METHODS\n");
991 print_proxy( "};\n");
995 void write_proxies(ifref_t *ifaces)
997 ifref_t *lcur = ifaces;
999 char *file_id = proxy_token;
1002 if (!do_proxies) return;
1003 if (do_everything && !ifaces) return;
1011 if (is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
1012 write_proxy(cur->iface);
1013 cur = PREV_LINK(cur);
1018 print_proxy( "#if !defined(__RPC_WIN32__)\n");
1019 print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
1020 print_proxy( "#endif\n");
1022 write_procformatstring(proxy, ifaces, 1);
1023 write_typeformatstring(proxy, ifaces, 1);
1025 fprintf(proxy, "const CInterfaceProxyVtbl* _%s_ProxyVtblList[] =\n", file_id);
1026 fprintf(proxy, "{\n");
1029 if(cur->iface->ref && cur->iface->funcs &&
1030 is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
1031 fprintf(proxy, " (CInterfaceProxyVtbl*)&_%sProxyVtbl,\n", cur->iface->name);
1032 cur = PREV_LINK(cur);
1034 fprintf(proxy, " 0\n");
1035 fprintf(proxy, "};\n");
1036 fprintf(proxy, "\n");
1038 fprintf(proxy, "const CInterfaceStubVtbl* _%s_StubVtblList[] =\n", file_id);
1039 fprintf(proxy, "{\n");
1042 if(cur->iface->ref && cur->iface->funcs &&
1043 is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
1044 fprintf(proxy, " (CInterfaceStubVtbl*)&_%sStubVtbl,\n", cur->iface->name);
1045 cur = PREV_LINK(cur);
1047 fprintf(proxy, " 0\n");
1048 fprintf(proxy, "};\n");
1049 fprintf(proxy, "\n");
1051 fprintf(proxy, "PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id);
1052 fprintf(proxy, "{\n");
1055 if(cur->iface->ref && cur->iface->funcs &&
1056 is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
1057 fprintf(proxy, " \"%s\",\n", cur->iface->name);
1058 cur = PREV_LINK(cur);
1060 fprintf(proxy, " 0\n");
1061 fprintf(proxy, "};\n");
1062 fprintf(proxy, "\n");
1064 fprintf(proxy, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id, file_id);
1065 fprintf(proxy, "\n");
1066 fprintf(proxy, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id);
1067 fprintf(proxy, "{\n");
1073 fprintf(proxy, " if (!_%s_CHECK_IID(%d))\n", file_id, c);
1074 fprintf(proxy, " {\n");
1075 fprintf(proxy, " *pIndex = %d;\n", c);
1076 fprintf(proxy, " return 1;\n");
1077 fprintf(proxy, " }\n");
1080 cur = PREV_LINK(cur);
1082 fprintf(proxy, " return 0;\n");
1083 fprintf(proxy, "}\n");
1084 fprintf(proxy, "\n");
1086 fprintf(proxy, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id);
1087 fprintf(proxy, "{\n");
1088 fprintf(proxy, " (PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id);
1089 fprintf(proxy, " (PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id);
1090 fprintf(proxy, " (const PCInterfaceName*)&_%s_InterfaceNamesList,\n", file_id);
1091 fprintf(proxy, " 0,\n");
1092 fprintf(proxy, " &_%s_IID_Lookup,\n", file_id);
1093 fprintf(proxy, " %d,\n", c);
1094 fprintf(proxy, " 1,\n");
1095 fprintf(proxy, " 0,\n");
1096 fprintf(proxy, " 0,\n");
1097 fprintf(proxy, " 0,\n");
1098 fprintf(proxy, " 0\n");
1099 fprintf(proxy, "};\n");