client.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * IDL Compiler
  3. *
  4. * Copyright 2005-2006 Eric Kohl
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include "config.h"
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <ctype.h>
  25. #include "widl.h"
  26. #include "utils.h"
  27. #include "parser.h"
  28. #include "header.h"
  29. #include "widltypes.h"
  30. #include "typegen.h"
  31. #include "expr.h"
  32. static FILE* client;
  33. static int indent = 0;
  34. static void print_client( const char *format, ... ) __attribute__((format (printf, 1, 2)));
  35. static void print_client( const char *format, ... )
  36. {
  37. va_list va;
  38. va_start(va, format);
  39. print(client, indent, format, va);
  40. va_end(va);
  41. }
  42. static void write_client_func_decl( const type_t *iface, const var_t *func )
  43. {
  44. const char *callconv = get_attrp(func->declspec.type->attrs, ATTR_CALLCONV);
  45. const var_list_t *args = type_function_get_args(func->declspec.type);
  46. const decl_spec_t *rettype = type_function_get_ret(func->declspec.type);
  47. if (!callconv) callconv = "__cdecl";
  48. write_type_decl_left(client, rettype);
  49. fprintf(client, " %s ", callconv);
  50. fprintf(client, "%s%s(\n", prefix_client, get_name(func));
  51. indent++;
  52. if (args) write_args(client, args, iface->name, 0, TRUE, NAME_DEFAULT);
  53. else
  54. print_client("void");
  55. fprintf(client, ")\n");
  56. indent--;
  57. }
  58. static void write_function_stub( const type_t *iface, const var_t *func,
  59. int method_count, unsigned int proc_offset )
  60. {
  61. unsigned char explicit_fc, implicit_fc;
  62. int has_full_pointer = is_full_pointer_function(func);
  63. var_t *retval = type_function_get_retval(func->declspec.type);
  64. const var_t *handle_var = get_func_handle_var( iface, func, &explicit_fc, &implicit_fc );
  65. int has_ret = !is_void(retval->declspec.type);
  66. if (is_interpreted_func( iface, func ))
  67. {
  68. write_client_func_decl( iface, func );
  69. write_client_call_routine( client, iface, func, iface->name, proc_offset );
  70. return;
  71. }
  72. print_client( "struct __frame_%s%s\n{\n", prefix_client, get_name(func) );
  73. indent++;
  74. print_client( "__DECL_EXCEPTION_FRAME\n" );
  75. print_client("MIDL_STUB_MESSAGE _StubMsg;\n");
  76. if (handle_var)
  77. {
  78. if (explicit_fc == FC_BIND_GENERIC)
  79. print_client("%s %s;\n",
  80. get_explicit_generic_handle_type(handle_var)->name, handle_var->name );
  81. print_client("RPC_BINDING_HANDLE _Handle;\n");
  82. }
  83. if (has_ret && decl_indirect(retval->declspec.type))
  84. {
  85. print_client("void *_p_%s;\n", retval->name);
  86. }
  87. indent--;
  88. print_client( "};\n\n" );
  89. print_client( "static void __finally_%s%s(", prefix_client, get_name(func) );
  90. print_client( " struct __frame_%s%s *__frame )\n{\n", prefix_client, get_name(func) );
  91. indent++;
  92. if (has_full_pointer)
  93. write_full_pointer_free(client, indent, func);
  94. print_client("NdrFreeBuffer(&__frame->_StubMsg);\n");
  95. if (explicit_fc == FC_BIND_GENERIC)
  96. {
  97. fprintf(client, "\n");
  98. print_client("if (__frame->_Handle)\n");
  99. indent++;
  100. print_client("%s_unbind(__frame->%s, __frame->_Handle);\n",
  101. get_explicit_generic_handle_type(handle_var)->name, handle_var->name);
  102. indent--;
  103. }
  104. indent--;
  105. print_client( "}\n\n" );
  106. write_client_func_decl( iface, func );
  107. /* write the functions body */
  108. fprintf(client, "{\n");
  109. indent++;
  110. print_client( "struct __frame_%s%s __f, * const __frame = &__f;\n", prefix_client, get_name(func) );
  111. /* declare return value */
  112. if (has_ret)
  113. {
  114. print_client("%s", "");
  115. write_type_decl(client, &retval->declspec, retval->name);
  116. fprintf(client, ";\n");
  117. }
  118. print_client("RPC_MESSAGE _RpcMessage;\n");
  119. if (handle_var)
  120. {
  121. print_client( "__frame->_Handle = 0;\n" );
  122. if (explicit_fc == FC_BIND_GENERIC)
  123. print_client("__frame->%s = %s;\n", handle_var->name, handle_var->name );
  124. }
  125. if (has_ret && decl_indirect(retval->declspec.type))
  126. {
  127. print_client("__frame->_p_%s = &%s;\n", retval->name, retval->name);
  128. }
  129. fprintf(client, "\n");
  130. print_client( "RpcExceptionInit( 0, __finally_%s%s );\n", prefix_client, get_name(func) );
  131. if (has_full_pointer)
  132. write_full_pointer_init(client, indent, func, FALSE);
  133. /* check pointers */
  134. write_pointer_checks( client, indent, func );
  135. print_client("RpcTryFinally\n");
  136. print_client("{\n");
  137. indent++;
  138. print_client("NdrClientInitializeNew(&_RpcMessage, &__frame->_StubMsg, &%s_StubDesc, %d);\n",
  139. iface->name, method_count);
  140. if (is_attr(func->attrs, ATTR_IDEMPOTENT) || is_attr(func->attrs, ATTR_BROADCAST))
  141. {
  142. print_client("_RpcMessage.RpcFlags = ( RPC_NCA_FLAGS_DEFAULT ");
  143. if (is_attr(func->attrs, ATTR_IDEMPOTENT))
  144. fprintf(client, "| RPC_NCA_FLAGS_IDEMPOTENT ");
  145. if (is_attr(func->attrs, ATTR_BROADCAST))
  146. fprintf(client, "| RPC_NCA_FLAGS_BROADCAST ");
  147. fprintf(client, ");\n\n");
  148. }
  149. switch (explicit_fc)
  150. {
  151. case FC_BIND_PRIMITIVE:
  152. print_client("__frame->_Handle = %s;\n", handle_var->name);
  153. fprintf(client, "\n");
  154. break;
  155. case FC_BIND_GENERIC:
  156. print_client("__frame->_Handle = %s_bind(%s);\n",
  157. get_explicit_generic_handle_type(handle_var)->name, handle_var->name);
  158. fprintf(client, "\n");
  159. break;
  160. case FC_BIND_CONTEXT:
  161. {
  162. /* if the context_handle attribute appears in the chain of types
  163. * without pointers being followed, then the context handle must
  164. * be direct, otherwise it is a pointer */
  165. int is_ch_ptr = !is_aliaschain_attr(handle_var->declspec.type, ATTR_CONTEXTHANDLE);
  166. print_client("if (%s%s != 0)\n", is_ch_ptr ? "*" : "", handle_var->name);
  167. indent++;
  168. print_client("__frame->_Handle = NDRCContextBinding(%s%s);\n",
  169. is_ch_ptr ? "*" : "", handle_var->name);
  170. indent--;
  171. if (is_attr(handle_var->attrs, ATTR_IN) && !is_attr(handle_var->attrs, ATTR_OUT))
  172. {
  173. print_client("else\n");
  174. indent++;
  175. print_client("RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT);\n");
  176. indent--;
  177. }
  178. fprintf(client, "\n");
  179. break;
  180. }
  181. case 0: /* implicit handle */
  182. if (handle_var)
  183. {
  184. print_client("__frame->_Handle = %s;\n", handle_var->name);
  185. fprintf(client, "\n");
  186. }
  187. break;
  188. }
  189. write_remoting_arguments(client, indent, func, "", PASS_IN, PHASE_BUFFERSIZE);
  190. print_client("NdrGetBuffer(&__frame->_StubMsg, __frame->_StubMsg.BufferLength, ");
  191. if (handle_var)
  192. fprintf(client, "__frame->_Handle);\n\n");
  193. else
  194. fprintf(client,"%s__MIDL_AutoBindHandle);\n\n", iface->name);
  195. /* marshal arguments */
  196. write_remoting_arguments(client, indent, func, "", PASS_IN, PHASE_MARSHAL);
  197. /* send/receive message */
  198. /* print_client("NdrNsSendReceive(\n"); */
  199. /* print_client("(unsigned char *)__frame->_StubMsg.Buffer,\n"); */
  200. /* print_client("(RPC_BINDING_HANDLE *) &%s__MIDL_AutoBindHandle);\n", iface->name); */
  201. print_client("NdrSendReceive(&__frame->_StubMsg, __frame->_StubMsg.Buffer);\n\n");
  202. print_client("__frame->_StubMsg.BufferStart = _RpcMessage.Buffer;\n");
  203. print_client("__frame->_StubMsg.BufferEnd = __frame->_StubMsg.BufferStart + _RpcMessage.BufferLength;\n");
  204. if (has_out_arg_or_return(func))
  205. {
  206. fprintf(client, "\n");
  207. print_client("if ((_RpcMessage.DataRepresentation & 0x0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION)\n");
  208. indent++;
  209. print_client("NdrConvert(&__frame->_StubMsg, (PFORMAT_STRING)&__MIDL_ProcFormatString.Format[%u]);\n",
  210. proc_offset);
  211. indent--;
  212. }
  213. /* unmarshall arguments */
  214. fprintf(client, "\n");
  215. write_remoting_arguments(client, indent, func, "", PASS_OUT, PHASE_UNMARSHAL);
  216. /* unmarshal return value */
  217. if (has_ret)
  218. {
  219. if (decl_indirect(retval->declspec.type))
  220. print_client("MIDL_memset(&%s, 0, sizeof(%s));\n", retval->name, retval->name);
  221. else if (is_ptr(retval->declspec.type) || is_array(retval->declspec.type))
  222. print_client("%s = 0;\n", retval->name);
  223. write_remoting_arguments(client, indent, func, "", PASS_RETURN, PHASE_UNMARSHAL);
  224. }
  225. indent--;
  226. print_client("}\n");
  227. print_client("RpcFinally\n");
  228. print_client("{\n");
  229. indent++;
  230. print_client( "__finally_%s%s( __frame );\n", prefix_client, get_name(func) );
  231. indent--;
  232. print_client("}\n");
  233. print_client("RpcEndFinally\n");
  234. /* emit return code */
  235. if (has_ret)
  236. {
  237. fprintf(client, "\n");
  238. print_client("return %s;\n", retval->name);
  239. }
  240. indent--;
  241. fprintf(client, "}\n");
  242. fprintf(client, "\n");
  243. }
  244. static void write_serialize_function(FILE *file, const type_t *type, const type_t *iface,
  245. const char *func_name, const char *ret_type)
  246. {
  247. enum stub_mode mode = get_stub_mode();
  248. static int emitted_pickling_info;
  249. if (iface && !type->typestring_offset)
  250. {
  251. /* FIXME: Those are mostly basic types. They should be implemented
  252. * using NdrMesSimpleType* functions */
  253. if (ret_type) warning("Serialization of type %s is not supported\n", type->name);
  254. return;
  255. }
  256. if (!emitted_pickling_info && iface && mode != MODE_Os)
  257. {
  258. fprintf(file, "static const MIDL_TYPE_PICKLING_INFO __MIDL_TypePicklingInfo =\n");
  259. fprintf(file, "{\n");
  260. fprintf(file, " 0x33205054,\n");
  261. fprintf(file, " 0x3,\n");
  262. fprintf(file, " 0,\n");
  263. fprintf(file, " 0,\n");
  264. fprintf(file, " 0\n");
  265. fprintf(file, "};\n");
  266. fprintf(file, "\n");
  267. emitted_pickling_info = 1;
  268. }
  269. /* FIXME: Assuming explicit handle */
  270. fprintf(file, "%s __cdecl %s_%s(handle_t IDL_handle, %s *IDL_type)%s\n",
  271. ret_type ? ret_type : "void", type->name, func_name, type->name, iface ? "" : ";");
  272. if (!iface) return; /* declaration only */
  273. fprintf(file, "{\n");
  274. fprintf(file, " %sNdrMesType%s%s(\n", ret_type ? "return " : "", func_name,
  275. mode != MODE_Os ? "2" : "");
  276. fprintf(file, " IDL_handle,\n");
  277. if (mode != MODE_Os)
  278. fprintf(file, " (MIDL_TYPE_PICKLING_INFO*)&__MIDL_TypePicklingInfo,\n");
  279. fprintf(file, " &%s_StubDesc,\n", iface->name);
  280. fprintf(file, " (PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%u],\n",
  281. type->typestring_offset);
  282. fprintf(file, " IDL_type);\n");
  283. fprintf(file, "}\n");
  284. fprintf(file, "\n");
  285. }
  286. void write_serialize_functions(FILE *file, const type_t *type, const type_t *iface)
  287. {
  288. if (is_attr(type->attrs, ATTR_ENCODE))
  289. {
  290. write_serialize_function(file, type, iface, "AlignSize", "SIZE_T");
  291. write_serialize_function(file, type, iface, "Encode", NULL);
  292. }
  293. if (is_attr(type->attrs, ATTR_DECODE))
  294. {
  295. write_serialize_function(file, type, iface, "Decode", NULL);
  296. write_serialize_function(file, type, iface, "Free", NULL);
  297. }
  298. }
  299. static void write_function_stubs(type_t *iface, unsigned int *proc_offset)
  300. {
  301. const statement_t *stmt;
  302. const var_t *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
  303. int method_count = 0;
  304. if (!implicit_handle)
  305. print_client("static RPC_BINDING_HANDLE %s__MIDL_AutoBindHandle;\n\n", iface->name);
  306. LIST_FOR_EACH_ENTRY( stmt, type_iface_get_stmts(iface), const statement_t, entry )
  307. {
  308. switch (stmt->type)
  309. {
  310. case STMT_DECLARATION:
  311. {
  312. const var_t *func = stmt->u.var;
  313. if (stmt->u.var->declspec.stgclass != STG_NONE
  314. || type_get_type_detect_alias(stmt->u.var->declspec.type) != TYPE_FUNCTION)
  315. continue;
  316. write_function_stub( iface, func, method_count++, *proc_offset );
  317. *proc_offset += get_size_procformatstring_func( iface, func );
  318. break;
  319. }
  320. case STMT_TYPEDEF:
  321. {
  322. typeref_t *ref;
  323. if (stmt->u.type_list) LIST_FOR_EACH_ENTRY(ref, stmt->u.type_list, typeref_t, entry)
  324. write_serialize_functions(client, ref->type, iface);
  325. break;
  326. }
  327. default:
  328. break;
  329. }
  330. }
  331. }
  332. static void write_stubdescdecl(type_t *iface)
  333. {
  334. print_client("static const MIDL_STUB_DESC %s_StubDesc;\n", iface->name);
  335. fprintf(client, "\n");
  336. }
  337. static void write_stubdescriptor(type_t *iface, int expr_eval_routines)
  338. {
  339. const var_t *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
  340. print_client("static const MIDL_STUB_DESC %s_StubDesc =\n", iface->name);
  341. print_client("{\n");
  342. indent++;
  343. print_client("(void *)& %s___RpcClientInterface,\n", iface->name);
  344. print_client("MIDL_user_allocate,\n");
  345. print_client("MIDL_user_free,\n");
  346. print_client("{\n");
  347. indent++;
  348. if (implicit_handle)
  349. print_client("&%s,\n", implicit_handle->name);
  350. else
  351. print_client("&%s__MIDL_AutoBindHandle,\n", iface->name);
  352. indent--;
  353. print_client("},\n");
  354. print_client("0,\n");
  355. if (!list_empty( &generic_handle_list ))
  356. print_client("BindingRoutines,\n");
  357. else
  358. print_client("0,\n");
  359. if (expr_eval_routines)
  360. print_client("ExprEvalRoutines,\n");
  361. else
  362. print_client("0,\n");
  363. print_client("0,\n");
  364. print_client("__MIDL_TypeFormatString.Format,\n");
  365. print_client("1, /* -error bounds_check flag */\n");
  366. print_client("0x%x, /* Ndr library version */\n", get_stub_mode() == MODE_Oif ? 0x50002 : 0x10001);
  367. print_client("0,\n");
  368. print_client("0x50200ca, /* MIDL Version 5.2.202 */\n");
  369. print_client("0,\n");
  370. print_client("%s,\n", list_empty(&user_type_list) ? "0" : "UserMarshalRoutines");
  371. print_client("0, /* notify & notify_flag routine table */\n");
  372. print_client("1, /* Flags */\n");
  373. print_client("0, /* Reserved3 */\n");
  374. print_client("0, /* Reserved4 */\n");
  375. print_client("0 /* Reserved5 */\n");
  376. indent--;
  377. print_client("};\n");
  378. fprintf(client, "\n");
  379. }
  380. static void write_clientinterfacedecl(type_t *iface)
  381. {
  382. unsigned int ver = get_attrv(iface->attrs, ATTR_VERSION);
  383. const UUID *uuid = get_attrp(iface->attrs, ATTR_UUID);
  384. const str_list_t *endpoints = get_attrp(iface->attrs, ATTR_ENDPOINT);
  385. if (endpoints) write_endpoints( client, iface->name, endpoints );
  386. print_client("static const RPC_CLIENT_INTERFACE %s___RpcClientInterface =\n", iface->name );
  387. print_client("{\n");
  388. indent++;
  389. print_client("sizeof(RPC_CLIENT_INTERFACE),\n");
  390. print_client("{{0x%08x,0x%04x,0x%04x,{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x}},{%d,%d}},\n",
  391. uuid->Data1, uuid->Data2, uuid->Data3, uuid->Data4[0], uuid->Data4[1],
  392. uuid->Data4[2], uuid->Data4[3], uuid->Data4[4], uuid->Data4[5], uuid->Data4[6],
  393. uuid->Data4[7], MAJORVERSION(ver), MINORVERSION(ver));
  394. print_client("{{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},\n"); /* FIXME */
  395. print_client("0,\n");
  396. if (endpoints)
  397. {
  398. print_client("%u,\n", list_count(endpoints));
  399. print_client("(PRPC_PROTSEQ_ENDPOINT)%s__RpcProtseqEndpoint,\n", iface->name);
  400. }
  401. else
  402. {
  403. print_client("0,\n");
  404. print_client("0,\n");
  405. }
  406. print_client("0,\n");
  407. print_client("0,\n");
  408. print_client("0,\n");
  409. indent--;
  410. print_client("};\n");
  411. if (old_names)
  412. print_client("RPC_IF_HANDLE %s_ClientIfHandle DECLSPEC_HIDDEN = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n",
  413. iface->name, iface->name);
  414. else
  415. print_client("RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec DECLSPEC_HIDDEN = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n",
  416. prefix_client, iface->name, MAJORVERSION(ver), MINORVERSION(ver), iface->name);
  417. fprintf(client, "\n");
  418. }
  419. static void write_implicithandledecl(type_t *iface)
  420. {
  421. const var_t *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
  422. if (implicit_handle)
  423. {
  424. write_type_decl(client, &implicit_handle->declspec, implicit_handle->name);
  425. fprintf(client, ";\n\n");
  426. }
  427. }
  428. static void init_client(void)
  429. {
  430. if (client) return;
  431. if (!(client = fopen(client_name, "w")))
  432. error("Could not open %s for output\n", client_name);
  433. print_client("/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", PACKAGE_VERSION, input_name);
  434. print_client("#include <string.h>\n");
  435. print_client( "\n");
  436. print_client("#include \"%s\"\n", header_name);
  437. print_client( "\n");
  438. print_client( "#ifndef DECLSPEC_HIDDEN\n");
  439. print_client( "#define DECLSPEC_HIDDEN\n");
  440. print_client( "#endif\n");
  441. print_client( "\n");
  442. }
  443. static void write_client_ifaces(const statement_list_t *stmts, int expr_eval_routines, unsigned int *proc_offset)
  444. {
  445. const statement_t *stmt;
  446. if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, const statement_t, entry )
  447. {
  448. if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
  449. {
  450. int needs_stub = 0;
  451. const statement_t *stmt2;
  452. type_t *iface = stmt->u.type;
  453. if (!need_stub(iface))
  454. return;
  455. fprintf(client, "/*****************************************************************************\n");
  456. fprintf(client, " * %s interface\n", iface->name);
  457. fprintf(client, " */\n");
  458. fprintf(client, "\n");
  459. LIST_FOR_EACH_ENTRY(stmt2, type_iface_get_stmts(iface), const statement_t, entry)
  460. {
  461. if (stmt2->type == STMT_DECLARATION && stmt2->u.var->declspec.stgclass == STG_NONE &&
  462. type_get_type_detect_alias(stmt2->u.var->declspec.type) == TYPE_FUNCTION)
  463. {
  464. needs_stub = 1;
  465. break;
  466. }
  467. if (stmt2->type == STMT_TYPEDEF)
  468. {
  469. typeref_t *ref;
  470. if (stmt2->u.type_list) LIST_FOR_EACH_ENTRY(ref, stmt2->u.type_list, typeref_t, entry)
  471. {
  472. if (is_attr(ref->type->attrs, ATTR_ENCODE)
  473. || is_attr(ref->type->attrs, ATTR_DECODE))
  474. {
  475. needs_stub = 1;
  476. break;
  477. }
  478. }
  479. if (needs_stub)
  480. break;
  481. }
  482. }
  483. if (needs_stub)
  484. {
  485. write_implicithandledecl(iface);
  486. write_clientinterfacedecl(iface);
  487. write_stubdescdecl(iface);
  488. write_function_stubs(iface, proc_offset);
  489. print_client("#if !defined(__RPC_WIN%u__)\n", pointer_size == 8 ? 64 : 32);
  490. print_client("#error Invalid build platform for this stub.\n");
  491. print_client("#endif\n");
  492. fprintf(client, "\n");
  493. write_stubdescriptor(iface, expr_eval_routines);
  494. }
  495. }
  496. }
  497. }
  498. static void write_generic_handle_routine_list(void)
  499. {
  500. generic_handle_t *gh;
  501. if (list_empty( &generic_handle_list )) return;
  502. print_client( "static const GENERIC_BINDING_ROUTINE_PAIR BindingRoutines[] =\n" );
  503. print_client( "{\n" );
  504. indent++;
  505. LIST_FOR_EACH_ENTRY( gh, &generic_handle_list, generic_handle_t, entry )
  506. {
  507. print_client( "{ (GENERIC_BINDING_ROUTINE)%s_bind, (GENERIC_UNBIND_ROUTINE)%s_unbind },\n",
  508. gh->name, gh->name );
  509. }
  510. indent--;
  511. print_client( "};\n\n" );
  512. }
  513. static void write_client_routines(const statement_list_t *stmts)
  514. {
  515. unsigned int proc_offset = 0;
  516. int expr_eval_routines;
  517. if (need_inline_stubs_file( stmts ))
  518. {
  519. write_exceptions( client );
  520. print_client( "\n");
  521. }
  522. write_formatstringsdecl(client, indent, stmts, need_stub);
  523. expr_eval_routines = write_expr_eval_routines(client, client_token);
  524. if (expr_eval_routines)
  525. write_expr_eval_routine_list(client, client_token);
  526. write_generic_handle_routine_list();
  527. write_user_quad_list(client);
  528. write_client_ifaces(stmts, expr_eval_routines, &proc_offset);
  529. fprintf(client, "\n");
  530. write_procformatstring(client, stmts, need_stub);
  531. write_typeformatstring(client, stmts, need_stub);
  532. }
  533. void write_client(const statement_list_t *stmts)
  534. {
  535. if (!do_client)
  536. return;
  537. if (do_everything && !need_stub_files(stmts))
  538. return;
  539. init_client();
  540. if (!client)
  541. return;
  542. write_client_routines( stmts );
  543. fclose(client);
  544. }