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 );
69 static type_t *get_base_type( var_t *arg )
71 type_t *t = arg->type;
72 while( (t->type == 0) && t->ref )
77 static void write_stubdescproto(void)
79 print_proxy( "extern const MIDL_STUB_DESC Object_StubDesc;\n");
83 static void write_stubdesc(void)
85 print_proxy( "const MIDL_STUB_DESC Object_StubDesc = {\n");
86 print_proxy( " 0,\n");
87 print_proxy( " NdrOleAllocate,\n");
88 print_proxy( " NdrOleFree,\n");
89 print_proxy( " {0}, 0, 0, 0, 0,\n");
90 print_proxy( " 0 /* __MIDL_TypeFormatString.Format */\n");
95 static void init_proxy(ifref_t *ifaces)
98 if(!(proxy = fopen(proxy_name, "w")))
99 error("Could not open %s for output\n", proxy_name);
100 print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
102 print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
103 print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
104 print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
106 print_proxy( "#include \"rpcproxy.h\"\n");
107 print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
108 print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
109 print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
111 print_proxy( "#include \"%s\"\n", header_name);
113 write_formatstringsdecl(proxy, indent, ifaces);
114 write_stubdescproto();
117 static void clear_output_vars( var_t *arg )
121 if (is_attr(arg->attrs, ATTR_OUT) && !is_attr(arg->attrs, ATTR_IN)) {
122 print_proxy( "if(%s)\n", arg->name );
124 print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg->name, arg->name );
127 arg = PREV_LINK(arg);
131 int is_pointer(var_t *arg)
136 switch (ref_type(arg->type))
139 case RPC_FC_C_CSTRING:
140 case RPC_FC_C_WSTRING:
150 int cant_be_null(var_t *v)
152 /* Search backwards for the most recent pointer attribute. */
153 const attr_t *attrs = v->attrs;
154 const type_t *type = v->type;
164 int t = get_attrv(attrs, ATTR_POINTERTYPE);
166 if (t == RPC_FC_FP || t == RPC_FC_OP || t == RPC_FC_UP)
181 return 1; /* Default is RPC_FC_RP. */
184 static int is_user_derived(var_t *v)
186 const attr_t *attrs = v->attrs;
187 const type_t *type = v->type;
197 if (is_attr(attrs, ATTR_WIREMARSHAL))
212 static void proxy_check_pointers( var_t *arg )
216 if (is_pointer(arg) && cant_be_null(arg)) {
217 print_proxy( "if(!%s)\n", arg->name );
219 print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
222 arg = PREV_LINK(arg);
226 static void marshall_size_arg( var_t *arg )
229 const type_t *type = get_base_type(arg);
232 expr = get_attrp( arg->attrs, ATTR_SIZEIS );
235 print_proxy( "_StubMsg.MaxCount = ", arg->name );
236 write_expr(proxy, expr, 0);
237 fprintf(proxy, ";\n\n");
238 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name );
239 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
243 if (is_user_derived(arg))
245 print_proxy("NdrUserMarshalBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name);
246 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index);
254 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 1, arg->name );
261 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 2, arg->name );
267 print_proxy( "_StubMsg.BufferLength += %d; /* %s */\n", 4, arg->name );
271 print_proxy( "NdrSimpleStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg->name );
272 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index );
275 case RPC_FC_C_CSTRING:
276 case RPC_FC_C_WSTRING:
278 print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name );
279 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
282 case RPC_FC_BOGUS_STRUCT:
283 print_proxy( "NdrComplexStructBufferSize(&_StubMsg, (unsigned char*)%s, ", arg->name );
284 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index );
290 memset( &temp, 0, sizeof temp );
291 temp.type = type->ref;
292 temp.name = arg->name; /* FIXME */
294 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__, arg->name );
296 marshall_size_arg( &temp );
301 print_proxy( "NdrPointerBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name );
302 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
306 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
310 static void proxy_gen_marshall_size( var_t *arg )
312 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
316 if (is_attr(arg->attrs, ATTR_IN))
318 marshall_size_arg( arg );
319 fprintf(proxy, "\n");
321 arg = PREV_LINK(arg);
325 static void marshall_copy_arg( var_t *arg )
328 type_t *type = get_base_type(arg);
331 expr = get_attrp( arg->attrs, ATTR_SIZEIS );
334 print_proxy( "_StubMsg.MaxCount = ", arg->name );
335 write_expr(proxy, expr, 0);
336 fprintf(proxy, ";\n\n");
337 print_proxy( "NdrConformantArrayMarshall( &_StubMsg, (unsigned char*)%s, ", arg->name );
338 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
342 if (is_user_derived(arg))
344 print_proxy("NdrUserMarshalMarshall( &_StubMsg, (unsigned char*)%s, ", arg->name);
345 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index);
361 write_type(proxy, arg->type, arg, arg->tname);
362 fprintf(proxy, " *)_StubMsg.Buffer = %s;\n", arg->name );
363 print_proxy("_StubMsg.Buffer += sizeof(");
364 write_type(proxy, arg->type, arg, arg->tname);
365 fprintf(proxy, ");\n");
369 /* FIXME: add the format string, and set the index below */
370 print_proxy( "NdrSimpleStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg->name );
371 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
374 case RPC_FC_C_CSTRING:
375 case RPC_FC_C_WSTRING:
379 case RPC_FC_BOGUS_STRUCT:
380 print_proxy( "NdrComplexStructMarshall(&_StubMsg, (unsigned char*)%s, ", arg->name );
381 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index );
387 memset( &temp, 0, sizeof temp );
388 temp.type = type->ref;
389 temp.name = arg->name; /* FIXME */
391 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__, arg->name );
393 marshall_copy_arg( &temp );
398 print_proxy( "NdrPointerMarshall( &_StubMsg, (unsigned char*)%s, ", arg->name );
399 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
403 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
407 static void gen_marshall_copydata( var_t *arg )
411 if (is_attr(arg->attrs, ATTR_IN))
413 marshall_copy_arg( arg );
414 fprintf(proxy, "\n");
416 arg = PREV_LINK(arg);
420 static void gen_marshall( var_t *arg )
422 /* generated code to determine the size of the buffer required */
423 proxy_gen_marshall_size( arg );
425 /* generated code to allocate the buffer */
426 print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
428 /* generated code to copy the args into the buffer */
429 gen_marshall_copydata( arg );
434 static void unmarshall_copy_arg( var_t *arg )
437 type_t *type = get_base_type(arg);
440 expr = get_attrp( arg->attrs, ATTR_SIZEIS );
443 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg->name );
444 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
448 if (is_user_derived(arg))
450 print_proxy("NdrUserMarshalUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg->name);
451 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index);
466 print_proxy( "%s = *(", arg->name );
467 write_type(proxy, arg->type, arg, arg->tname);
468 fprintf(proxy," *)_StubMsg.Buffer;\n");
469 print_proxy("_StubMsg.Buffer += sizeof(");
470 write_type(proxy, arg->type, arg, arg->tname);
471 fprintf(proxy, ");\n");
475 print_proxy( "NdrSimpleStructUnmarshall(&_StubMsg, (unsigned char**)%s, ", arg->name );
476 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
479 case RPC_FC_C_CSTRING:
480 case RPC_FC_C_WSTRING:
482 print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg->name );
483 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
486 case RPC_FC_BOGUS_STRUCT:
487 print_proxy( "NdrComplexStructUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg->name );
488 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index );
494 memset( &temp, 0, sizeof temp );
495 temp.type = type->ref;
496 temp.name = arg->name; /* FIXME */
498 print_proxy( "/* FIXME: %s use the right name for %s */\n", __FUNCTION__, arg->name );
500 unmarshall_copy_arg( &temp );
505 print_proxy( "NdrPointerUnmarshall(&_StubMsg, (unsigned char**)&%s, ", arg->name );
506 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
510 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
514 static void gen_unmarshall( var_t *arg )
518 if (is_attr(arg->attrs, ATTR_OUT))
520 unmarshall_copy_arg( arg );
521 fprintf(proxy, "\n");
523 arg = PREV_LINK(arg);
527 static void free_variable( var_t *arg )
530 int index = 0; /* FIXME */
534 expr = get_attrp( arg->attrs, ATTR_SIZEIS );
537 print_proxy( "_StubMsg.MaxCount = ", arg->name );
538 write_expr(proxy, expr, 0);
539 fprintf(proxy, ";\n\n");
540 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
541 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], ", index );
542 fprintf(proxy, "(void*)%s );\n", arg->name );
546 type = get_base_type(arg);
563 constraint = get_attrp( arg->attrs, ATTR_IIDIS );
565 print_proxy( "_StubMsg.MaxCount = (unsigned long) ( %s );\n",constraint->name);
566 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
567 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], ", index );
568 fprintf(proxy, "(void*)%s );\n", arg->name );
572 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
576 static void proxy_free_variables( var_t *arg )
580 if (is_attr(arg->attrs, ATTR_OUT))
582 free_variable( arg );
583 fprintf(proxy, "\n");
585 arg = PREV_LINK(arg);
589 static void gen_proxy(type_t *iface, func_t *cur, int idx)
591 var_t *def = cur->def;
592 int has_ret = !is_void(def->type, def);
595 write_type(proxy, def->type, def, def->tname);
596 print_proxy( " STDMETHODCALLTYPE %s_", iface->name);
597 write_name(proxy, def);
598 print_proxy( "_Proxy(\n");
599 write_args(proxy, cur->args, iface->name, 1, TRUE);
603 /* local variables */
606 write_type(proxy, def->type, def, def->tname);
607 print_proxy( " _RetVal;\n");
609 print_proxy( "RPC_MESSAGE _Msg;\n" );
610 print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
614 clear_output_vars( cur->args );
616 print_proxy( "RpcTryExcept\n" );
617 print_proxy( "{\n" );
619 print_proxy( "NdrProxyInitialize(This, &_Msg, &_StubMsg, &Object_StubDesc, %d);\n", idx);
620 proxy_check_pointers( cur->args );
622 print_proxy( "RpcTryFinally\n" );
623 print_proxy( "{\n" );
626 gen_marshall( cur->args );
628 print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
629 fprintf(proxy, "\n");
630 print_proxy("if ((_Msg.DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
632 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
634 fprintf(proxy, "\n");
636 gen_unmarshall( cur->args );
639 * FIXME: We only need to round the buffer up if it could be unaligned...
640 * We should calculate how much buffer we used and output the following
641 * line only if necessary.
643 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
645 print_proxy( "_RetVal = *(" );
646 write_type(proxy, def->type, def, def->tname);
647 fprintf(proxy, " *)_StubMsg.Buffer;\n");
648 print_proxy("_StubMsg.Buffer += sizeof(");
649 write_type(proxy, def->type, def, def->tname);
650 fprintf(proxy, ");\n");
655 print_proxy( "RpcFinally\n" );
656 print_proxy( "{\n" );
658 print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
661 print_proxy( "RpcEndFinally\n" );
663 print_proxy( "}\n" );
664 print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
665 print_proxy( "{\n" );
668 proxy_free_variables( cur->args );
669 print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
672 print_proxy( "}\n" );
673 print_proxy( "RpcEndExcept\n" );
676 print_proxy( "return _RetVal;\n" );
683 static void stub_write_locals( var_t *arg )
688 int outptr = is_attr(arg->attrs, ATTR_OUT)
689 && ! is_attr(arg->attrs, ATTR_IN);
691 /* create a temporary variable to store the output */
694 memset( &temp, 0, sizeof temp );
695 temp.ptr_level = arg->ptr_level - 1; /* dereference once */
697 write_type(proxy, arg->type, &temp, arg->tname);
698 fprintf(proxy, " _M%d;\n",n++);
701 write_type(proxy, arg->type, arg, arg->tname);
703 write_name(proxy, arg);
704 fprintf(proxy, ";\n");
705 arg = PREV_LINK(arg);
709 static void stub_unmarshall( var_t *arg )
714 if (is_attr(arg->attrs, ATTR_IN))
716 unmarshall_copy_arg( arg );
719 else if (is_attr(arg->attrs, ATTR_OUT)) {
720 type_t *type = get_base_type(arg);
724 print_proxy("MIDL_memset(");
725 write_name(proxy, arg);
726 fprintf(proxy,", 0, sizeof(");
727 write_type(proxy, arg->type, arg, arg->tname);
728 fprintf(proxy,"));\n");
732 write_name(proxy, arg);
733 fprintf(proxy," = &_M%d;\n", n);
734 print_proxy("MIDL_memset(&_M%d, 0, sizeof _M%d);\n", n, n);
739 arg = PREV_LINK(arg);
743 static void stub_gen_marshall_size( var_t *arg )
745 print_proxy( "_StubMsg.BufferLength = 0U;\n" );
749 if (is_attr(arg->attrs, ATTR_OUT))
750 marshall_size_arg( arg );
751 arg = PREV_LINK(arg);
755 static void stub_gen_marshall_copydata( var_t *arg )
759 if (is_attr(arg->attrs, ATTR_OUT))
760 marshall_copy_arg( arg );
761 arg = PREV_LINK(arg);
765 static void stub_genmarshall( var_t *args )
767 /* FIXME: size buffer */
768 stub_gen_marshall_size( args );
770 print_proxy("NdrStubGetBuffer(This, pRpcChannelBuffer, &_StubMsg);\n");
772 stub_gen_marshall_copydata( args );
775 static void gen_stub(type_t *iface, func_t *cur, const char *cas)
777 var_t *def = cur->def;
779 int has_ret = !is_void(def->type, def);
782 print_proxy( "void __RPC_STUB %s_", iface->name);
783 write_name(proxy, def);
784 print_proxy( "_Stub(\n");
786 print_proxy( "IRpcStubBuffer* This,\n");
787 print_proxy( "IRpcChannelBuffer* pRpcChannelBuffer,\n");
788 print_proxy( "PRPC_MESSAGE _Msg,\n");
789 print_proxy( "DWORD* _pdwStubPhase)\n");
793 /* local variables */
796 write_type(proxy, def->type, def, def->tname);
797 fprintf(proxy, " _RetVal;\n");
799 print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface->name, iface->name);
800 print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
801 stub_write_locals( cur->args );
802 fprintf(proxy, "\n");
806 print_proxy("NdrStubInitialize(_Msg, &_StubMsg, &Object_StubDesc, pRpcChannelBuffer);\n");
807 fprintf(proxy, "\n");
809 print_proxy("RpcTryFinally\n");
812 print_proxy("if ((_Msg->DataRepresentation&0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
814 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[0]);\n" );
816 fprintf(proxy, "\n");
818 stub_unmarshall( cur->args );
819 fprintf(proxy, "\n");
821 print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
822 fprintf(proxy, "\n");
824 if (has_ret) fprintf(proxy, "_RetVal = ");
825 fprintf(proxy, "%s_", iface->name);
826 if (cas) fprintf(proxy, "%s_Stub", cas);
827 else write_name(proxy, def);
828 fprintf(proxy, "(_This");
833 fprintf(proxy, ", ");
834 write_name(proxy, arg);
835 arg = PREV_LINK(arg);
838 fprintf(proxy, ");\n");
839 fprintf(proxy, "\n");
840 print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
841 fprintf(proxy, "\n");
843 stub_genmarshall( cur->args );
844 fprintf(proxy, "\n");
848 * FIXME: We only need to round the buffer up if it could be unaligned...
849 * We should calculate how much buffer we used and output the following
850 * line only if necessary.
852 print_proxy( "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + 3) & ~ 0x3);\n");
855 write_type(proxy, def->type, def, def->tname);
856 fprintf(proxy, " *)_StubMsg.Buffer = _RetVal;\n");
857 print_proxy("_StubMsg.Buffer += sizeof(");
858 write_type(proxy, def->type, def, def->tname);
859 fprintf(proxy, ");\n");
864 print_proxy("RpcFinally\n");
867 print_proxy("RpcEndFinally\n");
869 print_proxy("_Msg->BufferLength = _StubMsg.Buffer - (unsigned char *)_Msg->Buffer;\n");
876 static int write_proxy_methods(type_t *iface)
878 func_t *cur = iface->funcs;
883 if (iface->ref) i = write_proxy_methods(iface->ref);
885 var_t *def = cur->def;
886 if (!is_callas(def->attrs)) {
887 if (i) fprintf(proxy, ",\n");
888 print_proxy( "%s_", iface->name);
889 write_name(proxy, def);
890 fprintf(proxy, "_Proxy");
893 cur = PREV_LINK(cur);
898 static int write_stub_methods(type_t *iface)
900 func_t *cur = iface->funcs;
905 if (iface->ref) i = write_stub_methods(iface->ref);
906 else return i; /* skip IUnknown */
908 var_t *def = cur->def;
909 if (!is_local(def->attrs)) {
910 if (i) fprintf(proxy,",\n");
911 print_proxy( "%s_", iface->name);
912 write_name(proxy, def);
913 fprintf(proxy, "_Stub");
916 cur = PREV_LINK(cur);
921 static void write_proxy(type_t *iface)
923 int midx = -1, stubs;
924 func_t *cur = iface->funcs;
930 /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
932 fprintf(proxy, "/*****************************************************************************\n");
933 fprintf(proxy, " * %s interface\n", iface->name);
934 fprintf(proxy, " */\n");
936 const var_t *def = cur->def;
937 if (!is_local(def->attrs)) {
938 const var_t *cas = is_callas(def->attrs);
939 const char *cname = cas ? cas->name : NULL;
942 const func_t *m = iface->funcs;
943 while (m && strcmp(get_name(m->def), cname))
947 gen_proxy(iface, cur, idx);
948 gen_stub(iface, cur, cname);
949 if (midx == -1) midx = idx;
950 else if (midx != idx) yyerror("method index mismatch in write_proxy");
953 cur = PREV_LINK(cur);
957 print_proxy( "const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx, iface->name);
960 print_proxy( "{\n", iface->name);
962 print_proxy( "&IID_%s,\n", iface->name);
964 print_proxy( "},\n");
967 write_proxy_methods(iface);
968 fprintf(proxy, "\n");
972 print_proxy( "};\n");
973 fprintf(proxy, "\n\n");
976 print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface->name);
979 stubs = write_stub_methods(iface);
980 fprintf(proxy, "\n");
982 fprintf(proxy, "};\n");
984 print_proxy( "const CInterfaceStubVtbl _%sStubVtbl =\n", iface->name);
989 print_proxy( "&IID_%s,\n", iface->name);
990 print_proxy( "0,\n");
991 print_proxy( "%d,\n", stubs+3);
992 print_proxy( "&%s_table[-3],\n", iface->name);
994 print_proxy( "},\n", iface->name);
997 print_proxy( "CStdStubBuffer_METHODS\n");
1001 print_proxy( "};\n");
1005 void write_proxies(ifref_t *ifaces)
1007 ifref_t *lcur = ifaces;
1009 char *file_id = proxy_token;
1012 if (!do_proxies) return;
1021 if (is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
1022 write_proxy(cur->iface);
1023 cur = PREV_LINK(cur);
1030 print_proxy( "#if !defined(__RPC_WIN32__)\n");
1031 print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
1032 print_proxy( "#endif\n");
1034 write_procformatstring(proxy, ifaces);
1035 write_typeformatstring(proxy, ifaces);
1037 fprintf(proxy, "const CInterfaceProxyVtbl* _%s_ProxyVtblList[] =\n", file_id);
1038 fprintf(proxy, "{\n");
1041 if(cur->iface->ref && cur->iface->funcs &&
1042 is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
1043 fprintf(proxy, " (CInterfaceProxyVtbl*)&_%sProxyVtbl,\n", cur->iface->name);
1044 cur = PREV_LINK(cur);
1046 fprintf(proxy, " 0\n");
1047 fprintf(proxy, "};\n");
1048 fprintf(proxy, "\n");
1050 fprintf(proxy, "const CInterfaceStubVtbl* _%s_StubVtblList[] =\n", file_id);
1051 fprintf(proxy, "{\n");
1054 if(cur->iface->ref && cur->iface->funcs &&
1055 is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
1056 fprintf(proxy, " (CInterfaceStubVtbl*)&_%sStubVtbl,\n", cur->iface->name);
1057 cur = PREV_LINK(cur);
1059 fprintf(proxy, " 0\n");
1060 fprintf(proxy, "};\n");
1061 fprintf(proxy, "\n");
1063 fprintf(proxy, "PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id);
1064 fprintf(proxy, "{\n");
1067 if(cur->iface->ref && cur->iface->funcs &&
1068 is_object(cur->iface->attrs) && !is_local(cur->iface->attrs))
1069 fprintf(proxy, " \"%s\",\n", cur->iface->name);
1070 cur = PREV_LINK(cur);
1072 fprintf(proxy, " 0\n");
1073 fprintf(proxy, "};\n");
1074 fprintf(proxy, "\n");
1076 fprintf(proxy, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id, file_id);
1077 fprintf(proxy, "\n");
1078 fprintf(proxy, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id);
1079 fprintf(proxy, "{\n");
1085 fprintf(proxy, " if (!_%s_CHECK_IID(%d))\n", file_id, c);
1086 fprintf(proxy, " {\n");
1087 fprintf(proxy, " *pIndex = %d;\n", c);
1088 fprintf(proxy, " return 1;\n");
1089 fprintf(proxy, " }\n");
1092 cur = PREV_LINK(cur);
1094 fprintf(proxy, " return 0;\n");
1095 fprintf(proxy, "}\n");
1096 fprintf(proxy, "\n");
1098 fprintf(proxy, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id);
1099 fprintf(proxy, "{\n");
1100 fprintf(proxy, " (PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id);
1101 fprintf(proxy, " (PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id);
1102 fprintf(proxy, " (const PCInterfaceName*)&_%s_InterfaceNamesList,\n", file_id);
1103 fprintf(proxy, " 0,\n");
1104 fprintf(proxy, " &_%s_IID_Lookup,\n", file_id);
1105 fprintf(proxy, " %d,\n", c);
1106 fprintf(proxy, " 1,\n");
1107 fprintf(proxy, " 0,\n");
1108 fprintf(proxy, " 0,\n");
1109 fprintf(proxy, " 0,\n");
1110 fprintf(proxy, " 0\n");
1111 fprintf(proxy, "};\n");