b818288b810e29349416877d2cf4feeb1a890923
[reactos.git] / reactos / tools / widl / proxy.c
1 /*
2 * IDL Compiler
3 *
4 * Copyright 2002 Ove Kaaven
5 * Copyright 2004 Mike McCormack
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #include <string.h>
31 #include <ctype.h>
32
33 #include "widl.h"
34 #include "utils.h"
35 #include "parser.h"
36 #include "header.h"
37 #include "typegen.h"
38
39 #define END_OF_LIST(list) \
40 do { \
41 if (list) { \
42 while (NEXT_LINK(list)) \
43 list = NEXT_LINK(list); \
44 } \
45 } while(0)
46
47 static FILE* proxy;
48 static int indent = 0;
49
50 /* FIXME: support generation of stubless proxies */
51
52 static void print_proxy( const char *format, ... )
53 {
54 va_list va;
55 va_start( va, format );
56 print( proxy, indent, format, va );
57 va_end( va );
58 }
59
60 static void write_stubdescproto(void)
61 {
62 print_proxy( "static const MIDL_STUB_DESC Object_StubDesc;\n");
63 print_proxy( "\n");
64 }
65
66 static void write_stubdesc(int expr_eval_routines)
67 {
68 print_proxy( "static const MIDL_STUB_DESC Object_StubDesc =\n{\n");
69 indent++;
70 print_proxy( "0,\n");
71 print_proxy( "NdrOleAllocate,\n");
72 print_proxy( "NdrOleFree,\n");
73 print_proxy( "{0}, 0, 0, %s, 0,\n", expr_eval_routines ? "ExprEvalRoutines" : "0");
74 print_proxy( "__MIDL_TypeFormatString.Format,\n");
75 print_proxy( "1, /* -error bounds_check flag */\n");
76 print_proxy( "0x10001, /* Ndr library version */\n");
77 print_proxy( "0,\n");
78 print_proxy( "0x50100a4, /* MIDL Version 5.1.164 */\n");
79 print_proxy( "0,\n");
80 print_proxy("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
81 print_proxy( "0, /* notify & notify_flag routine table */\n");
82 print_proxy( "1, /* Flags */\n");
83 print_proxy( "0, /* Reserved3 */\n");
84 print_proxy( "0, /* Reserved4 */\n");
85 print_proxy( "0 /* Reserved5 */\n");
86 indent--;
87 print_proxy( "};\n");
88 print_proxy( "\n");
89 }
90
91 static void init_proxy(ifref_list_t *ifaces)
92 {
93 if (proxy) return;
94 if(!(proxy = fopen(proxy_name, "w")))
95 error("Could not open %s for output\n", proxy_name);
96 print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
97 print_proxy( "\n");
98 print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
99 print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
100 print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
101 print_proxy( "\n");
102 print_proxy( "#define __midl_proxy\n");
103 print_proxy( "#include \"objbase.h\"\n");
104 print_proxy( "#include \"rpcproxy.h\"\n");
105 print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
106 print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
107 print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
108 print_proxy( "\n");
109 print_proxy( "#include \"%s\"\n", header_name);
110 print_proxy( "\n");
111 write_formatstringsdecl(proxy, indent, ifaces, need_proxy);
112 write_stubdescproto();
113 }
114
115 static void clear_output_vars( const var_list_t *args )
116 {
117 const var_t *arg;
118
119 if (!args) return;
120 LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
121 {
122 if (is_attr(arg->attrs, ATTR_OUT) && !is_attr(arg->attrs, ATTR_IN)) {
123 print_proxy( "if(%s)\n", arg->name );
124 indent++;
125 print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg->name, arg->name );
126 indent--;
127 }
128 }
129 }
130
131 int is_var_ptr(const var_t *v)
132 {
133 return is_ptr(v->type);
134 }
135
136 int cant_be_null(const var_t *v)
137 {
138 /* Search backwards for the most recent pointer attribute. */
139 const attr_list_t *attrs = v->attrs;
140 const type_t *type = v->type;
141
142 if (! attrs && type)
143 {
144 attrs = type->attrs;
145 type = type->ref;
146 }
147
148 while (attrs)
149 {
150 int t = get_attrv(attrs, ATTR_POINTERTYPE);
151
152 if (t == RPC_FC_FP || t == RPC_FC_OP || t == RPC_FC_UP)
153 return 0;
154
155 if (t == RPC_FC_RP)
156 return 1;
157
158 if (type)
159 {
160 attrs = type->attrs;
161 type = type->ref;
162 }
163 else
164 attrs = NULL;
165 }
166
167 return 1; /* Default is RPC_FC_RP. */
168 }
169
170 static void proxy_check_pointers( const var_list_t *args )
171 {
172 const var_t *arg;
173
174 if (!args) return;
175 LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
176 {
177 if (is_var_ptr(arg) && cant_be_null(arg)) {
178 print_proxy( "if(!%s)\n", arg->name );
179 indent++;
180 print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
181 indent--;
182 }
183 }
184 }
185
186 static void free_variable( const var_t *arg )
187 {
188 unsigned int type_offset = arg->type->typestring_offset;
189 expr_t *iid;
190 type_t *type = arg->type;
191 expr_t *size = get_size_is_expr(type, arg->name);
192
193 if (size)
194 {
195 print_proxy( "_StubMsg.MaxCount = " );
196 write_expr(proxy, size, 0);
197 fprintf(proxy, ";\n\n");
198 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
199 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
200 fprintf(proxy, "(void*)%s );\n", arg->name );
201 return;
202 }
203
204 switch( type->type )
205 {
206 case RPC_FC_BYTE:
207 case RPC_FC_CHAR:
208 case RPC_FC_WCHAR:
209 case RPC_FC_SHORT:
210 case RPC_FC_USHORT:
211 case RPC_FC_ENUM16:
212 case RPC_FC_LONG:
213 case RPC_FC_ULONG:
214 case RPC_FC_ENUM32:
215 case RPC_FC_STRUCT:
216 break;
217
218 case RPC_FC_FP:
219 case RPC_FC_IP:
220 iid = get_attrp( arg->attrs, ATTR_IIDIS );
221 if( iid )
222 {
223 print_proxy( "_StubMsg.MaxCount = (unsigned long) " );
224 write_expr(proxy, iid, 1);
225 print_proxy( ";\n\n" );
226 }
227 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
228 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
229 fprintf(proxy, "(void*)%s );\n", arg->name );
230 break;
231
232 default:
233 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
234 }
235 }
236
237 static void proxy_free_variables( var_list_t *args )
238 {
239 const var_t *arg;
240
241 if (!args) return;
242 LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
243 if (is_attr(arg->attrs, ATTR_OUT))
244 {
245 free_variable( arg );
246 fprintf(proxy, "\n");
247 }
248 }
249
250 static void gen_proxy(type_t *iface, const func_t *cur, int idx,
251 unsigned int proc_offset)
252 {
253 var_t *def = cur->def;
254 int has_ret = !is_void(get_func_return_type(cur));
255 int has_full_pointer = is_full_pointer_function(cur);
256
257 indent = 0;
258 write_type_decl_left(proxy, get_func_return_type(cur));
259 print_proxy( " STDMETHODCALLTYPE %s_", iface->name);
260 write_name(proxy, def);
261 print_proxy( "_Proxy(\n");
262 write_args(proxy, cur->args, iface->name, 1, TRUE);
263 print_proxy( ")\n");
264 print_proxy( "{\n");
265 indent ++;
266 /* local variables */
267 if (has_ret) {
268 print_proxy( "" );
269 write_type_decl_left(proxy, get_func_return_type(cur));
270
271 /* Initialize _RetVal properly in order to avoid compiler warnings */
272 if (is_ptr(get_func_return_type(cur)) || is_array(get_func_return_type(cur)))
273 print_proxy(" _RetVal = NULL;\n");
274 else
275 print_proxy(" _RetVal = 0;\n");
276 }
277 print_proxy( "RPC_MESSAGE _RpcMessage;\n" );
278 print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
279 if (has_ret) {
280 if (decl_indirect(get_func_return_type(cur)))
281 print_proxy("void *_p_%s = &%s;\n",
282 "_RetVal", "_RetVal");
283 }
284 print_proxy( "\n");
285
286 if (has_full_pointer)
287 write_full_pointer_init(proxy, indent, cur, FALSE);
288
289 /* FIXME: trace */
290 clear_output_vars( cur->args );
291
292 print_proxy( "RpcTryExcept\n" );
293 print_proxy( "{\n" );
294 indent++;
295 print_proxy( "NdrProxyInitialize(This, &_RpcMessage, &_StubMsg, &Object_StubDesc, %d);\n", idx);
296 proxy_check_pointers( cur->args );
297
298 print_proxy( "RpcTryFinally\n" );
299 print_proxy( "{\n" );
300 indent++;
301
302 write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_BUFFERSIZE);
303
304 print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
305
306 write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_MARSHAL);
307
308 print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
309 fprintf(proxy, "\n");
310 print_proxy( "_StubMsg.BufferStart = _RpcMessage.Buffer;\n" );
311 print_proxy( "_StubMsg.BufferEnd = _StubMsg.BufferStart + _RpcMessage.BufferLength;\n\n" );
312
313 print_proxy("if ((_RpcMessage.DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
314 indent++;
315 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
316 indent--;
317 fprintf(proxy, "\n");
318
319 write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_UNMARSHAL);
320
321 if (has_ret)
322 {
323 if (decl_indirect(get_func_return_type(cur)))
324 print_proxy("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
325 else if (is_ptr(get_func_return_type(cur)) || is_array(get_func_return_type(cur)))
326 print_proxy("%s = 0;\n", "_RetVal");
327 write_remoting_arguments(proxy, indent, cur, PASS_RETURN, PHASE_UNMARSHAL);
328 }
329
330 indent--;
331 print_proxy( "}\n");
332 print_proxy( "RpcFinally\n" );
333 print_proxy( "{\n" );
334 indent++;
335 if (has_full_pointer)
336 write_full_pointer_free(proxy, indent, cur);
337 print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
338 indent--;
339 print_proxy( "}\n");
340 print_proxy( "RpcEndFinally\n" );
341 indent--;
342 print_proxy( "}\n" );
343 print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
344 print_proxy( "{\n" );
345 if (has_ret) {
346 indent++;
347 proxy_free_variables( cur->args );
348 print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
349 indent--;
350 }
351 print_proxy( "}\n" );
352 print_proxy( "RpcEndExcept\n" );
353
354 if (has_ret) {
355 print_proxy( "return _RetVal;\n" );
356 }
357 indent--;
358 print_proxy( "}\n");
359 print_proxy( "\n");
360 }
361
362 static void gen_stub(type_t *iface, const func_t *cur, const char *cas,
363 unsigned int proc_offset)
364 {
365 var_t *def = cur->def;
366 const var_t *arg;
367 int has_ret = !is_void(get_func_return_type(cur));
368 int has_full_pointer = is_full_pointer_function(cur);
369
370 indent = 0;
371 print_proxy( "void __RPC_STUB %s_", iface->name);
372 write_name(proxy, def);
373 print_proxy( "_Stub(\n");
374 indent++;
375 print_proxy( "IRpcStubBuffer* This,\n");
376 print_proxy( "IRpcChannelBuffer *_pRpcChannelBuffer,\n");
377 print_proxy( "PRPC_MESSAGE _pRpcMessage,\n");
378 print_proxy( "DWORD* _pdwStubPhase)\n");
379 indent--;
380 print_proxy( "{\n");
381 indent++;
382 print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface->name, iface->name);
383 print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
384 declare_stub_args( proxy, indent, cur );
385 fprintf(proxy, "\n");
386
387 /* FIXME: trace */
388
389 print_proxy("NdrStubInitialize(_pRpcMessage, &_StubMsg, &Object_StubDesc, _pRpcChannelBuffer);\n");
390 fprintf(proxy, "\n");
391
392 write_parameters_init(proxy, indent, cur);
393
394 print_proxy("RpcTryFinally\n");
395 print_proxy("{\n");
396 indent++;
397 if (has_full_pointer)
398 write_full_pointer_init(proxy, indent, cur, TRUE);
399 print_proxy("if ((_pRpcMessage->DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
400 indent++;
401 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
402 indent--;
403 fprintf(proxy, "\n");
404
405 write_remoting_arguments(proxy, indent, cur, PASS_IN, PHASE_UNMARSHAL);
406 fprintf(proxy, "\n");
407
408 assign_stub_out_args( proxy, indent, cur );
409
410 print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
411 fprintf(proxy, "\n");
412 print_proxy("");
413 if (has_ret) fprintf(proxy, "_RetVal = ");
414 if (cas) fprintf(proxy, "%s_%s_Stub", iface->name, cas);
415 else
416 {
417 fprintf(proxy, "_This->lpVtbl->");
418 write_name(proxy, def);
419 }
420 fprintf(proxy, "(_This");
421
422 if (cur->args)
423 {
424 LIST_FOR_EACH_ENTRY( arg, cur->args, const var_t, entry )
425 {
426 fprintf(proxy, ", ");
427 if (arg->type->declarray)
428 fprintf(proxy, "*");
429 write_name(proxy, arg);
430 }
431 }
432 fprintf(proxy, ");\n");
433 fprintf(proxy, "\n");
434 print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
435 fprintf(proxy, "\n");
436
437 write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_BUFFERSIZE);
438
439 if (!is_void(get_func_return_type(cur)))
440 write_remoting_arguments(proxy, indent, cur, PASS_RETURN, PHASE_BUFFERSIZE);
441
442 print_proxy("NdrStubGetBuffer(This, _pRpcChannelBuffer, &_StubMsg);\n");
443
444 write_remoting_arguments(proxy, indent, cur, PASS_OUT, PHASE_MARSHAL);
445 fprintf(proxy, "\n");
446
447 /* marshall the return value */
448 if (!is_void(get_func_return_type(cur)))
449 write_remoting_arguments(proxy, indent, cur, PASS_RETURN, PHASE_MARSHAL);
450
451 indent--;
452 print_proxy("}\n");
453 print_proxy("RpcFinally\n");
454 print_proxy("{\n");
455
456 write_remoting_arguments(proxy, indent+1, cur, PASS_OUT, PHASE_FREE);
457
458 if (has_full_pointer)
459 write_full_pointer_free(proxy, indent, cur);
460
461 print_proxy("}\n");
462 print_proxy("RpcEndFinally\n");
463
464 print_proxy("_pRpcMessage->BufferLength = _StubMsg.Buffer - (unsigned char *)_pRpcMessage->Buffer;\n");
465 indent--;
466
467 print_proxy("}\n");
468 print_proxy("\n");
469 }
470
471 static int write_proxy_methods(type_t *iface, int skip)
472 {
473 const func_t *cur;
474 int i = 0;
475
476 if (iface->ref) i = write_proxy_methods(iface->ref, iface->ref->ref != NULL);
477 if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
478 var_t *def = cur->def;
479 if (!is_callas(def->attrs)) {
480 if (i) fprintf(proxy, ",\n");
481 print_proxy( "%s%s_", skip ? "0\t/* " : "", iface->name);
482 write_name(proxy, def);
483 fprintf(proxy, "_Proxy%s", skip ? " */" : "");
484 i++;
485 }
486 }
487 return i;
488 }
489
490 static int write_stub_methods(type_t *iface, int skip)
491 {
492 const func_t *cur;
493 int i = 0;
494
495 if (iface->ref) i = write_stub_methods(iface->ref, TRUE);
496 else return i; /* skip IUnknown */
497
498 if (iface->funcs) LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) {
499 var_t *def = cur->def;
500 if (!is_local(def->attrs)) {
501 if (skip)
502 print_proxy("STUB_FORWARDING_FUNCTION,\n");
503 else {
504 if (i) fprintf(proxy,",\n");
505 print_proxy( "%s_", iface->name);
506 write_name(proxy, def);
507 fprintf(proxy, "_Stub");
508 i++;
509 }
510 }
511 }
512 return i;
513 }
514
515 static void write_proxy(type_t *iface, unsigned int *proc_offset)
516 {
517 int midx = -1, stubs;
518 const func_t *cur;
519
520 if (!iface->funcs) return;
521
522 /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
523
524 fprintf(proxy, "/*****************************************************************************\n");
525 fprintf(proxy, " * %s interface\n", iface->name);
526 fprintf(proxy, " */\n");
527 LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry )
528 {
529 const var_t *def = cur->def;
530 if (!is_local(def->attrs)) {
531 const var_t *cas = is_callas(def->attrs);
532 const char *cname = cas ? cas->name : NULL;
533 int idx = cur->idx;
534 if (cname) {
535 const func_t *m;
536 LIST_FOR_EACH_ENTRY( m, iface->funcs, const func_t, entry )
537 if (!strcmp(m->def->name, cname))
538 {
539 idx = m->idx;
540 break;
541 }
542 }
543 gen_proxy(iface, cur, idx, *proc_offset);
544 gen_stub(iface, cur, cname, *proc_offset);
545 *proc_offset += get_size_procformatstring_func( cur );
546 if (midx == -1) midx = idx;
547 else if (midx != idx) error("method index mismatch in write_proxy\n");
548 midx++;
549 }
550 }
551
552 /* proxy vtable */
553 print_proxy( "static const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx, iface->name);
554 print_proxy( "{\n");
555 indent++;
556 print_proxy( "{\n", iface->name);
557 indent++;
558 print_proxy( "&IID_%s,\n", iface->name);
559 indent--;
560 print_proxy( "},\n");
561 print_proxy( "{\n");
562 indent++;
563 write_proxy_methods(iface, FALSE);
564 fprintf(proxy, "\n");
565 indent--;
566 print_proxy( "}\n");
567 indent--;
568 print_proxy( "};\n");
569 fprintf(proxy, "\n\n");
570
571 /* stub vtable */
572 print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface->name);
573 print_proxy( "{\n");
574 indent++;
575 stubs = write_stub_methods(iface, FALSE);
576 fprintf(proxy, "\n");
577 indent--;
578 fprintf(proxy, "};\n");
579 print_proxy( "\n");
580 print_proxy( "static const CInterfaceStubVtbl _%sStubVtbl =\n", iface->name);
581 print_proxy( "{\n");
582 indent++;
583 print_proxy( "{\n");
584 indent++;
585 print_proxy( "&IID_%s,\n", iface->name);
586 print_proxy( "0,\n");
587 print_proxy( "%d,\n", stubs+3);
588 print_proxy( "&%s_table[-3],\n", iface->name);
589 indent--;
590 print_proxy( "},\n", iface->name);
591 print_proxy( "{\n");
592 indent++;
593 print_proxy( "CStdStubBuffer_METHODS\n");
594 indent--;
595 print_proxy( "}\n");
596 indent--;
597 print_proxy( "};\n");
598 print_proxy( "\n");
599 }
600
601 static int does_any_iface(const ifref_list_t *ifaces, type_pred_t pred)
602 {
603 ifref_t *ir;
604
605 if (ifaces)
606 LIST_FOR_EACH_ENTRY(ir, ifaces, ifref_t, entry)
607 if (pred(ir->iface))
608 return TRUE;
609
610 return FALSE;
611 }
612
613 int need_proxy(const type_t *iface)
614 {
615 return is_object(iface->attrs) && !is_local(iface->attrs);
616 }
617
618 int need_stub(const type_t *iface)
619 {
620 return !is_object(iface->attrs) && !is_local(iface->attrs);
621 }
622
623 int need_proxy_file(const ifref_list_t *ifaces)
624 {
625 return does_any_iface(ifaces, need_proxy);
626 }
627
628 int need_stub_files(const ifref_list_t *ifaces)
629 {
630 return does_any_iface(ifaces, need_stub);
631 }
632
633 void write_proxies(ifref_list_t *ifaces)
634 {
635 ifref_t *cur;
636 int expr_eval_routines;
637 char *file_id = proxy_token;
638 int c;
639 unsigned int proc_offset = 0;
640
641 if (!do_proxies) return;
642 if (do_everything && !need_proxy_file(ifaces)) return;
643
644 init_proxy(ifaces);
645 if(!proxy) return;
646
647 if (ifaces)
648 LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
649 if (need_proxy(cur->iface))
650 write_proxy(cur->iface, &proc_offset);
651
652 expr_eval_routines = write_expr_eval_routines(proxy, proxy_token);
653 if (expr_eval_routines)
654 write_expr_eval_routine_list(proxy, proxy_token);
655 write_user_quad_list(proxy);
656 write_stubdesc(expr_eval_routines);
657
658 print_proxy( "#if !defined(__RPC_WIN32__)\n");
659 print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
660 print_proxy( "#endif\n");
661 print_proxy( "\n");
662 write_procformatstring(proxy, ifaces, need_proxy);
663 write_typeformatstring(proxy, ifaces, need_proxy);
664
665 fprintf(proxy, "static const CInterfaceProxyVtbl* const _%s_ProxyVtblList[] =\n", file_id);
666 fprintf(proxy, "{\n");
667 if (ifaces)
668 LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
669 if(cur->iface->ref && cur->iface->funcs && need_proxy(cur->iface))
670 fprintf(proxy, " (const CInterfaceProxyVtbl*)&_%sProxyVtbl,\n", cur->iface->name);
671
672 fprintf(proxy, " 0\n");
673 fprintf(proxy, "};\n");
674 fprintf(proxy, "\n");
675
676 fprintf(proxy, "static const CInterfaceStubVtbl* const _%s_StubVtblList[] =\n", file_id);
677 fprintf(proxy, "{\n");
678 if (ifaces)
679 LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
680 if(cur->iface->ref && cur->iface->funcs && need_proxy(cur->iface))
681 fprintf(proxy, " (const CInterfaceStubVtbl*)&_%sStubVtbl,\n", cur->iface->name);
682 fprintf(proxy, " 0\n");
683 fprintf(proxy, "};\n");
684 fprintf(proxy, "\n");
685
686 fprintf(proxy, "static PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id);
687 fprintf(proxy, "{\n");
688 if (ifaces)
689 LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
690 if(cur->iface->ref && cur->iface->funcs && need_proxy(cur->iface))
691 fprintf(proxy, " \"%s\",\n", cur->iface->name);
692 fprintf(proxy, " 0\n");
693 fprintf(proxy, "};\n");
694 fprintf(proxy, "\n");
695
696 fprintf(proxy, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id, file_id);
697 fprintf(proxy, "\n");
698 fprintf(proxy, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id);
699 fprintf(proxy, "{\n");
700 c = 0;
701 if (ifaces)
702 LIST_FOR_EACH_ENTRY( cur, ifaces, ifref_t, entry )
703 if(cur->iface->ref && cur->iface->funcs && need_proxy(cur->iface))
704 {
705 fprintf(proxy, " if (!_%s_CHECK_IID(%d))\n", file_id, c);
706 fprintf(proxy, " {\n");
707 fprintf(proxy, " *pIndex = %d;\n", c);
708 fprintf(proxy, " return 1;\n");
709 fprintf(proxy, " }\n");
710 c++;
711 }
712 fprintf(proxy, " return 0;\n");
713 fprintf(proxy, "}\n");
714 fprintf(proxy, "\n");
715
716 fprintf(proxy, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id);
717 fprintf(proxy, "{\n");
718 fprintf(proxy, " (const PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id);
719 fprintf(proxy, " (const PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id);
720 fprintf(proxy, " _%s_InterfaceNamesList,\n", file_id);
721 fprintf(proxy, " 0,\n");
722 fprintf(proxy, " &_%s_IID_Lookup,\n", file_id);
723 fprintf(proxy, " %d,\n", c);
724 fprintf(proxy, " 1,\n");
725 fprintf(proxy, " 0,\n");
726 fprintf(proxy, " 0,\n");
727 fprintf(proxy, " 0,\n");
728 fprintf(proxy, " 0\n");
729 fprintf(proxy, "};\n");
730
731 fclose(proxy);
732 }