client.c 21 KB

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