widl: Move funcs and stmts fields from type_t structure to module_details and functio...
[wine/dcerpc.git] / tools / widl / proxy.c
blob129f85f908e8e1d4ce84cef9544409fa07ca174b
1 /*
2 * IDL Compiler
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
22 #include "config.h"
23 #include "wine/port.h"
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>
33 #include "widl.h"
34 #include "utils.h"
35 #include "parser.h"
36 #include "header.h"
37 #include "typegen.h"
38 #include "expr.h"
40 #define END_OF_LIST(list) \
41 do { \
42 if (list) { \
43 while (NEXT_LINK(list)) \
44 list = NEXT_LINK(list); \
45 } \
46 } while(0)
48 static FILE* proxy;
49 static int indent = 0;
51 /* FIXME: support generation of stubless proxies */
53 static void print_proxy( const char *format, ... )
55 va_list va;
56 va_start( va, format );
57 print( proxy, indent, format, va );
58 va_end( va );
61 static void write_stubdescproto(void)
63 print_proxy( "static const MIDL_STUB_DESC Object_StubDesc;\n");
64 print_proxy( "\n");
67 static void write_stubdesc(int expr_eval_routines)
69 print_proxy( "static const MIDL_STUB_DESC Object_StubDesc =\n{\n");
70 indent++;
71 print_proxy( "0,\n");
72 print_proxy( "NdrOleAllocate,\n");
73 print_proxy( "NdrOleFree,\n");
74 print_proxy( "{0}, 0, 0, %s, 0,\n", expr_eval_routines ? "ExprEvalRoutines" : "0");
75 print_proxy( "__MIDL_TypeFormatString.Format,\n");
76 print_proxy( "1, /* -error bounds_check flag */\n");
77 print_proxy( "0x10001, /* Ndr library version */\n");
78 print_proxy( "0,\n");
79 print_proxy( "0x50100a4, /* MIDL Version 5.1.164 */\n");
80 print_proxy( "0,\n");
81 print_proxy("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
82 print_proxy( "0, /* notify & notify_flag routine table */\n");
83 print_proxy( "1, /* Flags */\n");
84 print_proxy( "0, /* Reserved3 */\n");
85 print_proxy( "0, /* Reserved4 */\n");
86 print_proxy( "0 /* Reserved5 */\n");
87 indent--;
88 print_proxy( "};\n");
89 print_proxy( "\n");
92 static void init_proxy(const statement_list_t *stmts)
94 if (proxy) return;
95 if(!(proxy = fopen(proxy_name, "w")))
96 error("Could not open %s for output\n", proxy_name);
97 print_proxy( "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
98 print_proxy( "\n");
99 print_proxy( "#ifndef __REDQ_RPCPROXY_H_VERSION__\n");
100 print_proxy( "#define __REQUIRED_RPCPROXY_H_VERSION__ 440\n");
101 print_proxy( "#endif /* __REDQ_RPCPROXY_H_VERSION__ */\n");
102 print_proxy( "\n");
103 print_proxy( "#define __midl_proxy\n");
104 print_proxy( "#include \"objbase.h\"\n");
105 print_proxy( "#include \"rpcproxy.h\"\n");
106 print_proxy( "#ifndef __RPCPROXY_H_VERSION__\n");
107 print_proxy( "#error This code needs a newer version of rpcproxy.h\n");
108 print_proxy( "#endif /* __RPCPROXY_H_VERSION__ */\n");
109 print_proxy( "\n");
110 print_proxy( "#include \"%s\"\n", header_name);
111 print_proxy( "\n");
112 write_formatstringsdecl(proxy, indent, stmts, need_proxy);
113 write_stubdescproto();
116 static void clear_output_vars( const var_list_t *args )
118 const var_t *arg;
120 if (!args) return;
121 LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
123 if (is_attr(arg->attrs, ATTR_OUT) && !is_attr(arg->attrs, ATTR_IN)) {
124 print_proxy( "if(%s)\n", arg->name );
125 indent++;
126 print_proxy( "MIDL_memset( %s, 0, sizeof( *%s ));\n", arg->name, arg->name );
127 indent--;
132 int is_var_ptr(const var_t *v)
134 return is_ptr(v->type);
137 int cant_be_null(const var_t *v)
139 /* Search backwards for the most recent pointer attribute. */
140 const attr_list_t *attrs = v->attrs;
141 const type_t *type = v->type;
143 if (! attrs && type)
145 attrs = type->attrs;
146 type = type->ref;
149 while (attrs)
151 int t = get_attrv(attrs, ATTR_POINTERTYPE);
153 if (t == RPC_FC_FP || t == RPC_FC_OP || t == RPC_FC_UP)
154 return 0;
156 if (t == RPC_FC_RP)
157 return 1;
159 if (type)
161 attrs = type->attrs;
162 type = type->ref;
164 else
165 attrs = NULL;
168 return 1; /* Default is RPC_FC_RP. */
171 static void proxy_check_pointers( const var_list_t *args )
173 const var_t *arg;
175 if (!args) return;
176 LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
178 if (is_var_ptr(arg) && cant_be_null(arg)) {
179 print_proxy( "if(!%s)\n", arg->name );
180 indent++;
181 print_proxy( "RpcRaiseException(RPC_X_NULL_REF_POINTER);\n");
182 indent--;
187 static void free_variable( const var_t *arg )
189 unsigned int type_offset = arg->type->typestring_offset;
190 expr_t *iid;
191 type_t *type = arg->type;
192 expr_t *size = get_size_is_expr(type, arg->name);
194 if (size)
196 print_proxy( "_StubMsg.MaxCount = " );
197 write_expr(proxy, size, 0, 1, NULL, NULL);
198 fprintf(proxy, ";\n\n");
199 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
200 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
201 fprintf(proxy, "(void*)%s );\n", arg->name );
202 return;
205 switch( type->type )
207 case RPC_FC_BYTE:
208 case RPC_FC_CHAR:
209 case RPC_FC_WCHAR:
210 case RPC_FC_SHORT:
211 case RPC_FC_USHORT:
212 case RPC_FC_ENUM16:
213 case RPC_FC_LONG:
214 case RPC_FC_ULONG:
215 case RPC_FC_ENUM32:
216 case RPC_FC_STRUCT:
217 break;
219 case RPC_FC_FP:
220 case RPC_FC_IP:
221 iid = get_attrp( arg->attrs, ATTR_IIDIS );
222 if( iid )
224 print_proxy( "_StubMsg.MaxCount = (unsigned long) " );
225 write_expr(proxy, iid, 1, 1, NULL, NULL);
226 print_proxy( ";\n\n" );
228 print_proxy( "NdrClearOutParameters( &_StubMsg, ");
229 fprintf(proxy, "&__MIDL_TypeFormatString.Format[%u], ", type_offset );
230 fprintf(proxy, "(void*)%s );\n", arg->name );
231 break;
233 default:
234 print_proxy("/* FIXME: %s code for %s type %d missing */\n", __FUNCTION__, arg->name, type->type );
238 static void proxy_free_variables( var_list_t *args )
240 const var_t *arg;
242 if (!args) return;
243 LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
244 if (is_attr(arg->attrs, ATTR_OUT))
246 free_variable( arg );
247 fprintf(proxy, "\n");
251 static void gen_proxy(type_t *iface, const var_t *func, int idx,
252 unsigned int proc_offset)
254 int has_ret = !is_void(get_func_return_type(func));
255 int has_full_pointer = is_full_pointer_function(func);
256 const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
257 if (!callconv) callconv = "";
259 indent = 0;
260 write_type_decl_left(proxy, get_func_return_type(func));
261 print_proxy( " %s %s_", callconv, iface->name);
262 write_name(proxy, func);
263 print_proxy( "_Proxy(\n");
264 write_args(proxy, type_get_function_args(func->type), iface->name, 1, TRUE);
265 print_proxy( ")\n");
266 print_proxy( "{\n");
267 indent ++;
268 /* local variables */
269 if (has_ret) {
270 print_proxy( "" );
271 write_type_decl_left(proxy, get_func_return_type(func));
272 print_proxy( " _RetVal;\n");
274 print_proxy( "RPC_MESSAGE _RpcMessage;\n" );
275 print_proxy( "MIDL_STUB_MESSAGE _StubMsg;\n" );
276 if (has_ret) {
277 if (decl_indirect(get_func_return_type(func)))
278 print_proxy("void *_p_%s = &%s;\n",
279 "_RetVal", "_RetVal");
281 print_proxy( "\n");
283 if (has_full_pointer)
284 write_full_pointer_init(proxy, indent, func, FALSE);
286 /* FIXME: trace */
287 clear_output_vars( type_get_function_args(func->type) );
289 print_proxy( "RpcTryExcept\n" );
290 print_proxy( "{\n" );
291 indent++;
292 print_proxy( "NdrProxyInitialize(This, &_RpcMessage, &_StubMsg, &Object_StubDesc, %d);\n", idx);
293 proxy_check_pointers( type_get_function_args(func->type) );
295 print_proxy( "RpcTryFinally\n" );
296 print_proxy( "{\n" );
297 indent++;
299 write_remoting_arguments(proxy, indent, func, PASS_IN, PHASE_BUFFERSIZE);
301 print_proxy( "NdrProxyGetBuffer(This, &_StubMsg);\n" );
303 write_remoting_arguments(proxy, indent, func, PASS_IN, PHASE_MARSHAL);
305 print_proxy( "NdrProxySendReceive(This, &_StubMsg);\n" );
306 fprintf(proxy, "\n");
307 print_proxy( "_StubMsg.BufferStart = _RpcMessage.Buffer;\n" );
308 print_proxy( "_StubMsg.BufferEnd = _StubMsg.BufferStart + _RpcMessage.BufferLength;\n\n" );
310 print_proxy("if ((_RpcMessage.DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
311 indent++;
312 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
313 indent--;
314 fprintf(proxy, "\n");
316 write_remoting_arguments(proxy, indent, func, PASS_OUT, PHASE_UNMARSHAL);
318 if (has_ret)
320 if (decl_indirect(get_func_return_type(func)))
321 print_proxy("MIDL_memset(&%s, 0, sizeof(%s));\n", "_RetVal", "_RetVal");
322 else if (is_ptr(get_func_return_type(func)) || is_array(get_func_return_type(func)))
323 print_proxy("%s = 0;\n", "_RetVal");
324 write_remoting_arguments(proxy, indent, func, PASS_RETURN, PHASE_UNMARSHAL);
327 indent--;
328 print_proxy( "}\n");
329 print_proxy( "RpcFinally\n" );
330 print_proxy( "{\n" );
331 indent++;
332 if (has_full_pointer)
333 write_full_pointer_free(proxy, indent, func);
334 print_proxy( "NdrProxyFreeBuffer(This, &_StubMsg);\n" );
335 indent--;
336 print_proxy( "}\n");
337 print_proxy( "RpcEndFinally\n" );
338 indent--;
339 print_proxy( "}\n" );
340 print_proxy( "RpcExcept(_StubMsg.dwStubPhase != PROXY_SENDRECEIVE)\n" );
341 print_proxy( "{\n" );
342 if (has_ret) {
343 indent++;
344 proxy_free_variables( type_get_function_args(func->type) );
345 print_proxy( "_RetVal = NdrProxyErrorHandler(RpcExceptionCode());\n" );
346 indent--;
348 print_proxy( "}\n" );
349 print_proxy( "RpcEndExcept\n" );
351 if (has_ret) {
352 print_proxy( "return _RetVal;\n" );
354 indent--;
355 print_proxy( "}\n");
356 print_proxy( "\n");
359 static void gen_stub(type_t *iface, const var_t *func, const char *cas,
360 unsigned int proc_offset)
362 const var_t *arg;
363 int has_ret = !is_void(get_func_return_type(func));
364 int has_full_pointer = is_full_pointer_function(func);
366 indent = 0;
367 print_proxy( "void __RPC_STUB %s_", iface->name);
368 write_name(proxy, func);
369 print_proxy( "_Stub(\n");
370 indent++;
371 print_proxy( "IRpcStubBuffer* This,\n");
372 print_proxy( "IRpcChannelBuffer *_pRpcChannelBuffer,\n");
373 print_proxy( "PRPC_MESSAGE _pRpcMessage,\n");
374 print_proxy( "DWORD* _pdwStubPhase)\n");
375 indent--;
376 print_proxy( "{\n");
377 indent++;
378 print_proxy("%s * _This = (%s*)((CStdStubBuffer*)This)->pvServerObject;\n", iface->name, iface->name);
379 print_proxy("MIDL_STUB_MESSAGE _StubMsg;\n");
380 declare_stub_args( proxy, indent, func );
381 fprintf(proxy, "\n");
383 /* FIXME: trace */
385 print_proxy("NdrStubInitialize(_pRpcMessage, &_StubMsg, &Object_StubDesc, _pRpcChannelBuffer);\n");
386 fprintf(proxy, "\n");
388 write_parameters_init(proxy, indent, func);
390 print_proxy("RpcTryFinally\n");
391 print_proxy("{\n");
392 indent++;
393 if (has_full_pointer)
394 write_full_pointer_init(proxy, indent, func, TRUE);
395 print_proxy("if ((_pRpcMessage->DataRepresentation & 0xffff) != NDR_LOCAL_DATA_REPRESENTATION)\n");
396 indent++;
397 print_proxy("NdrConvert( &_StubMsg, &__MIDL_ProcFormatString.Format[%u]);\n", proc_offset );
398 indent--;
399 fprintf(proxy, "\n");
401 write_remoting_arguments(proxy, indent, func, PASS_IN, PHASE_UNMARSHAL);
402 fprintf(proxy, "\n");
404 assign_stub_out_args( proxy, indent, func );
406 print_proxy("*_pdwStubPhase = STUB_CALL_SERVER;\n");
407 fprintf(proxy, "\n");
408 print_proxy("");
409 if (has_ret) fprintf(proxy, "_RetVal = ");
410 if (cas) fprintf(proxy, "%s_%s_Stub", iface->name, cas);
411 else
413 fprintf(proxy, "_This->lpVtbl->");
414 write_name(proxy, func);
416 fprintf(proxy, "(_This");
418 if (type_get_function_args(func->type))
420 LIST_FOR_EACH_ENTRY( arg, type_get_function_args(func->type), const var_t, entry )
422 fprintf(proxy, ", ");
423 if (arg->type->declarray)
424 fprintf(proxy, "*");
425 write_name(proxy, arg);
428 fprintf(proxy, ");\n");
429 fprintf(proxy, "\n");
430 print_proxy("*_pdwStubPhase = STUB_MARSHAL;\n");
431 fprintf(proxy, "\n");
433 write_remoting_arguments(proxy, indent, func, PASS_OUT, PHASE_BUFFERSIZE);
435 if (!is_void(get_func_return_type(func)))
436 write_remoting_arguments(proxy, indent, func, PASS_RETURN, PHASE_BUFFERSIZE);
438 print_proxy("NdrStubGetBuffer(This, _pRpcChannelBuffer, &_StubMsg);\n");
440 write_remoting_arguments(proxy, indent, func, PASS_OUT, PHASE_MARSHAL);
441 fprintf(proxy, "\n");
443 /* marshall the return value */
444 if (!is_void(get_func_return_type(func)))
445 write_remoting_arguments(proxy, indent, func, PASS_RETURN, PHASE_MARSHAL);
447 indent--;
448 print_proxy("}\n");
449 print_proxy("RpcFinally\n");
450 print_proxy("{\n");
452 write_remoting_arguments(proxy, indent+1, func, PASS_OUT, PHASE_FREE);
454 if (has_full_pointer)
455 write_full_pointer_free(proxy, indent, func);
457 print_proxy("}\n");
458 print_proxy("RpcEndFinally\n");
460 print_proxy("_pRpcMessage->BufferLength = _StubMsg.Buffer - (unsigned char *)_pRpcMessage->Buffer;\n");
461 indent--;
463 print_proxy("}\n");
464 print_proxy("\n");
467 static int write_proxy_methods(type_t *iface)
469 const statement_t *stmt;
470 int i = 0;
472 if (iface->ref) i = write_proxy_methods(iface->ref);
473 STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
474 const var_t *func = stmt->u.var;
475 if (!is_callas(func->attrs)) {
476 if (i) fprintf(proxy, ",\n");
477 print_proxy( "%s_", iface->name);
478 write_name(proxy, func);
479 fprintf(proxy, "_Proxy");
480 i++;
483 return i;
486 static int write_stub_methods(type_t *iface)
488 const statement_t *stmt;
489 int i = 0;
491 if (iface->ref) i = write_stub_methods(iface->ref);
492 else return i; /* skip IUnknown */
494 STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
495 const var_t *func = stmt->u.var;
496 if (!is_local(func->attrs)) {
497 if (i) fprintf(proxy,",\n");
498 print_proxy( "%s_", iface->name);
499 write_name(proxy, func);
500 fprintf(proxy, "_Stub");
501 i++;
504 return i;
507 static void write_proxy(type_t *iface, unsigned int *proc_offset)
509 int midx = -1, stubs;
510 const statement_t *stmt;
511 int first_func = 1;
513 /* FIXME: check for [oleautomation], shouldn't generate proxies/stubs if specified */
515 STATEMENTS_FOR_EACH_FUNC(stmt, iface->details.iface->stmts) {
516 const var_t *func = stmt->u.var;
517 if (first_func) {
518 fprintf(proxy, "/*****************************************************************************\n");
519 fprintf(proxy, " * %s interface\n", iface->name);
520 fprintf(proxy, " */\n");
521 first_func = 0;
523 if (!is_local(func->attrs)) {
524 const var_t *cas = is_callas(func->attrs);
525 const char *cname = cas ? cas->name : NULL;
526 int idx = func->type->details.function->idx;
527 if (cname) {
528 const statement_t *stmt2;
529 STATEMENTS_FOR_EACH_FUNC(stmt2, iface->details.iface->stmts) {
530 const var_t *m = stmt2->u.var;
531 if (!strcmp(m->name, cname))
533 idx = m->type->details.function->idx;
534 break;
538 gen_proxy(iface, func, idx, *proc_offset);
539 gen_stub(iface, func, cname, *proc_offset);
540 *proc_offset += get_size_procformatstring_func( func );
541 if (midx == -1) midx = idx;
542 else if (midx != idx) error("method index mismatch in write_proxy\n");
543 midx++;
547 /* proxy vtable */
548 print_proxy( "static const CINTERFACE_PROXY_VTABLE(%d) _%sProxyVtbl =\n", midx, iface->name);
549 print_proxy( "{\n");
550 indent++;
551 print_proxy( "{\n", iface->name);
552 indent++;
553 print_proxy( "&IID_%s,\n", iface->name);
554 indent--;
555 print_proxy( "},\n");
556 print_proxy( "{\n");
557 indent++;
558 write_proxy_methods(iface);
559 fprintf(proxy, "\n");
560 indent--;
561 print_proxy( "}\n");
562 indent--;
563 print_proxy( "};\n");
564 fprintf(proxy, "\n\n");
566 /* stub vtable */
567 print_proxy( "static const PRPC_STUB_FUNCTION %s_table[] =\n", iface->name);
568 print_proxy( "{\n");
569 indent++;
570 stubs = write_stub_methods(iface);
571 fprintf(proxy, "\n");
572 indent--;
573 fprintf(proxy, "};\n");
574 print_proxy( "\n");
575 print_proxy( "static const CInterfaceStubVtbl _%sStubVtbl =\n", iface->name);
576 print_proxy( "{\n");
577 indent++;
578 print_proxy( "{\n");
579 indent++;
580 print_proxy( "&IID_%s,\n", iface->name);
581 print_proxy( "0,\n");
582 print_proxy( "%d,\n", stubs+3);
583 print_proxy( "&%s_table[-3],\n", iface->name);
584 indent--;
585 print_proxy( "},\n", iface->name);
586 print_proxy( "{\n");
587 indent++;
588 print_proxy( "CStdStubBuffer_METHODS\n");
589 indent--;
590 print_proxy( "}\n");
591 indent--;
592 print_proxy( "};\n");
593 print_proxy( "\n");
596 static int does_any_iface(const statement_list_t *stmts, type_pred_t pred)
598 const statement_t *stmt;
600 if (stmts)
601 LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
603 if (stmt->type == STMT_LIBRARY)
605 if (does_any_iface(stmt->u.lib->stmts, pred))
606 return TRUE;
608 else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
610 if (pred(stmt->u.type))
611 return TRUE;
615 return FALSE;
618 int need_proxy(const type_t *iface)
620 return is_object(iface->attrs) && !is_local(iface->attrs);
623 int need_stub(const type_t *iface)
625 return !is_object(iface->attrs) && !is_local(iface->attrs);
628 int need_proxy_file(const statement_list_t *stmts)
630 return does_any_iface(stmts, need_proxy);
633 int need_stub_files(const statement_list_t *stmts)
635 return does_any_iface(stmts, need_stub);
638 static void write_proxy_stmts(const statement_list_t *stmts, unsigned int *proc_offset)
640 const statement_t *stmt;
641 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
643 if (stmt->type == STMT_LIBRARY)
644 write_proxy_stmts(stmt->u.lib->stmts, proc_offset);
645 else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
647 if (need_proxy(stmt->u.type))
648 write_proxy(stmt->u.type, proc_offset);
653 static void write_proxy_iface_name_format(const statement_list_t *stmts, const char *format)
655 const statement_t *stmt;
656 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
658 if (stmt->type == STMT_LIBRARY)
659 write_proxy_iface_name_format(stmt->u.lib->stmts, format);
660 else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
662 type_t *iface = stmt->u.type;
663 if (iface->ref && statements_has_func(iface->details.iface->stmts) &&
664 need_proxy(iface))
665 fprintf(proxy, format, iface->name);
670 static void write_iid_lookup(const statement_list_t *stmts, const char *file_id, int *c)
672 const statement_t *stmt;
673 if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
675 if (stmt->type == STMT_LIBRARY)
676 write_iid_lookup(stmt->u.lib->stmts, file_id, c);
677 else if (stmt->type == STMT_TYPE && stmt->u.type->type == RPC_FC_IP)
679 type_t *iface = stmt->u.type;
680 if(iface->ref && statements_has_func(iface->details.iface->stmts) &&
681 need_proxy(iface))
683 fprintf(proxy, " if (!_%s_CHECK_IID(%d))\n", file_id, *c);
684 fprintf(proxy, " {\n");
685 fprintf(proxy, " *pIndex = %d;\n", *c);
686 fprintf(proxy, " return 1;\n");
687 fprintf(proxy, " }\n");
688 (*c)++;
694 void write_proxies(const statement_list_t *stmts)
696 int expr_eval_routines;
697 char *file_id = proxy_token;
698 int c;
699 unsigned int proc_offset = 0;
701 if (!do_proxies) return;
702 if (do_everything && !need_proxy_file(stmts)) return;
704 init_proxy(stmts);
705 if(!proxy) return;
707 write_proxy_stmts(stmts, &proc_offset);
709 expr_eval_routines = write_expr_eval_routines(proxy, proxy_token);
710 if (expr_eval_routines)
711 write_expr_eval_routine_list(proxy, proxy_token);
712 write_user_quad_list(proxy);
713 write_stubdesc(expr_eval_routines);
715 print_proxy( "#if !defined(__RPC_WIN32__)\n");
716 print_proxy( "#error Currently only Wine and WIN32 are supported.\n");
717 print_proxy( "#endif\n");
718 print_proxy( "\n");
719 write_procformatstring(proxy, stmts, need_proxy);
720 write_typeformatstring(proxy, stmts, need_proxy);
722 fprintf(proxy, "static const CInterfaceProxyVtbl* const _%s_ProxyVtblList[] =\n", file_id);
723 fprintf(proxy, "{\n");
724 write_proxy_iface_name_format(stmts, " (const CInterfaceProxyVtbl*)&_%sProxyVtbl,\n");
725 fprintf(proxy, " 0\n");
726 fprintf(proxy, "};\n");
727 fprintf(proxy, "\n");
729 fprintf(proxy, "static const CInterfaceStubVtbl* const _%s_StubVtblList[] =\n", file_id);
730 fprintf(proxy, "{\n");
731 write_proxy_iface_name_format(stmts, " (const CInterfaceStubVtbl*)&_%sStubVtbl,\n");
732 fprintf(proxy, " 0\n");
733 fprintf(proxy, "};\n");
734 fprintf(proxy, "\n");
736 fprintf(proxy, "static PCInterfaceName const _%s_InterfaceNamesList[] =\n", file_id);
737 fprintf(proxy, "{\n");
738 write_proxy_iface_name_format(stmts, " \"%s\",\n");
739 fprintf(proxy, " 0\n");
740 fprintf(proxy, "};\n");
741 fprintf(proxy, "\n");
743 fprintf(proxy, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_%s, pIID, n)\n", file_id, file_id);
744 fprintf(proxy, "\n");
745 fprintf(proxy, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id);
746 fprintf(proxy, "{\n");
747 c = 0;
748 write_iid_lookup(stmts, file_id, &c);
749 fprintf(proxy, " return 0;\n");
750 fprintf(proxy, "}\n");
751 fprintf(proxy, "\n");
753 fprintf(proxy, "const ExtendedProxyFileInfo %s_ProxyFileInfo =\n", file_id);
754 fprintf(proxy, "{\n");
755 fprintf(proxy, " (const PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id);
756 fprintf(proxy, " (const PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id);
757 fprintf(proxy, " _%s_InterfaceNamesList,\n", file_id);
758 fprintf(proxy, " 0,\n");
759 fprintf(proxy, " &_%s_IID_Lookup,\n", file_id);
760 fprintf(proxy, " %d,\n", c);
761 fprintf(proxy, " 1,\n");
762 fprintf(proxy, " 0,\n");
763 fprintf(proxy, " 0,\n");
764 fprintf(proxy, " 0,\n");
765 fprintf(proxy, " 0\n");
766 fprintf(proxy, "};\n");
768 fclose(proxy);