2 * Format String Generator for IDL Compiler
4 * Copyright 2005 Eric Kohl
5 * Copyright 2005 Robert Shearman
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
43 static int print_file(FILE *file, int indent, const char *format, ...)
49 for (i = 0; i < indent; i++)
51 r = vfprintf(file, format, va);
56 static void write_procformatstring_var(FILE *file, int indent, var_t *var)
58 switch(var->type->type)
60 #define CASE_BASETYPE(fctype) \
62 print_file(file, indent, "0x%02x, /* " #fctype " */\n", var->type->type); \
65 CASE_BASETYPE(FC_BYTE);
66 CASE_BASETYPE(FC_CHAR);
67 CASE_BASETYPE(FC_WCHAR);
68 CASE_BASETYPE(FC_USHORT);
69 CASE_BASETYPE(FC_SHORT);
70 CASE_BASETYPE(FC_ULONG);
71 CASE_BASETYPE(FC_LONG);
72 CASE_BASETYPE(FC_HYPER);
73 CASE_BASETYPE(FC_IGNORE);
74 CASE_BASETYPE(FC_SMALL);
75 CASE_BASETYPE(FC_FLOAT);
76 CASE_BASETYPE(FC_DOUBLE);
79 error("Unknown/unsupported type: %s (0x%02x)\n", var->name, var->type->type);
83 void write_procformatstring(FILE *file, type_t *iface)
86 func_t *func = iface->funcs;
89 print_file(file, indent, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
90 print_file(file, indent, "{\n");
92 print_file(file, indent, "0,\n");
93 print_file(file, indent, "{\n");
96 while (NEXT_LINK(func)) func = NEXT_LINK(func);
99 /* emit argument data */
103 while (NEXT_LINK(var)) var = NEXT_LINK(var);
106 print_file(file, indent, "0x4e, /* FC_IN_PARAM_BASETYPE */\n");
107 write_procformatstring_var(file, indent, var);
108 var = PREV_LINK(var);
112 /* emit return value data */
114 if (is_void(var->type, NULL))
116 print_file(file, indent, "0x5b, /* FC_END */\n");
117 print_file(file, indent, "0x5c, /* FC_PAD */\n");
121 print_file(file, indent, "0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
122 write_procformatstring_var(file, indent, var);
125 func = PREV_LINK(func);
128 print_file(file, indent, "0x0\n");
130 print_file(file, indent, "}\n");
132 print_file(file, indent, "};\n");
133 print_file(file, indent, "\n");
137 void write_typeformatstring(FILE *file)
140 print_file(file, indent, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
141 print_file(file, indent, "{\n");
143 print_file(file, indent, "0,\n");
144 print_file(file, indent, "{\n");
146 print_file(file, indent, "NdrFcShort(0x0),\n");
147 print_file(file, indent, "0x0\n");
149 print_file(file, indent, "}\n");
151 print_file(file, indent, "};\n");
152 print_file(file, indent, "\n");
156 unsigned int get_required_buffer_size(type_t *type)
169 case RPC_FC_ERROR_STATUS_T:
177 error("Unknown/unsupported type: %s (0x%02x)\n", type->name, type->type);
182 void marshall_arguments(FILE *file, int indent, func_t *func)
184 unsigned int alignment;
186 unsigned int last_size = 0;
193 while (NEXT_LINK(var)) var = NEXT_LINK(var);
197 switch (var->type->type)
209 if (last_size != 0 && last_size < 2)
210 alignment = (2 - last_size);
216 case RPC_FC_ERROR_STATUS_T:
218 if (last_size != 0 && last_size < 4)
219 alignment = (4 - last_size);
225 if (last_size != 0 && last_size < 4)
226 alignment = (4 - last_size);
231 error("Unknown/unsupported type: %s (0x%02x)\n", var->name, var->type->type);
235 print_file(file, indent, "_StubMsg.Buffer += %u;\n", alignment);
237 print_file(file, indent, "*((");
238 write_type(file, var->type, var, var->tname);
239 fprintf(file, " *)_StubMsg.Buffer)++ = ");
240 write_name(file, var);
241 fprintf(file, ";\n");
246 var = PREV_LINK(var);
250 void unmarshall_arguments(FILE *file, int indent, func_t *func)
252 unsigned int alignment;
254 unsigned int last_size = 0;
261 while (NEXT_LINK(var)) var = NEXT_LINK(var);
265 switch (var->type->type)
277 if (last_size != 0 && last_size < 2)
278 alignment = (2 - last_size);
284 case RPC_FC_ERROR_STATUS_T:
286 if (last_size != 0 && last_size < 4)
287 alignment = (4 - last_size);
293 if (last_size != 0 && last_size < 4)
294 alignment = (4 - last_size);
299 error("Unknown/unsupported type: %s (0x%02x)\n", var->name, var->type->type);
303 print_file(file, indent, "_StubMsg.Buffer += %u;\n", alignment);
305 print_file(file, indent, "");
306 write_name(file, var);
307 fprintf(file, " = *((");
308 write_type(file, var->type, var, var->tname);
309 fprintf(file, " *)_StubMsg.Buffer)++;\n");
314 var = PREV_LINK(var);