client.c 21 KB

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