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"
44 static int print_file(FILE *file, int indent, const char *format, ...)
50 for (i = 0; i < indent; i++)
52 r = vfprintf(file, format, va);
57 static void write_procformatstring_var(FILE *file, int indent, var_t *var)
59 switch(var->type->type)
61 #define CASE_BASETYPE(fctype) \
63 print_file(file, indent, "0x%02x, /* " #fctype " */\n", var->type->type); \
66 CASE_BASETYPE(FC_BYTE);
67 CASE_BASETYPE(FC_CHAR);
68 CASE_BASETYPE(FC_WCHAR);
69 CASE_BASETYPE(FC_USHORT);
70 CASE_BASETYPE(FC_SHORT);
71 CASE_BASETYPE(FC_ULONG);
72 CASE_BASETYPE(FC_LONG);
73 CASE_BASETYPE(FC_HYPER);
74 CASE_BASETYPE(FC_IGNORE);
75 CASE_BASETYPE(FC_USMALL);
76 CASE_BASETYPE(FC_SMALL);
77 CASE_BASETYPE(FC_FLOAT);
78 CASE_BASETYPE(FC_DOUBLE);
79 CASE_BASETYPE(FC_ERROR_STATUS_T);
82 error("Unknown/unsupported type: %s (0x%02x)\n", var->name, var->type->type);
86 void write_procformatstring(FILE *file, type_t *iface)
89 func_t *func = iface->funcs;
92 print_file(file, indent, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
93 print_file(file, indent, "{\n");
95 print_file(file, indent, "0,\n");
96 print_file(file, indent, "{\n");
99 while (NEXT_LINK(func)) func = NEXT_LINK(func);
102 /* emit argument data */
106 while (NEXT_LINK(var)) var = NEXT_LINK(var);
109 print_file(file, indent, "0x4e, /* FC_IN_PARAM_BASETYPE */\n");
110 write_procformatstring_var(file, indent, var);
111 var = PREV_LINK(var);
115 /* emit return value data */
117 if (is_void(var->type, NULL))
119 print_file(file, indent, "0x5b, /* FC_END */\n");
120 print_file(file, indent, "0x5c, /* FC_PAD */\n");
124 print_file(file, indent, "0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
125 write_procformatstring_var(file, indent, var);
128 func = PREV_LINK(func);
131 print_file(file, indent, "0x0\n");
133 print_file(file, indent, "}\n");
135 print_file(file, indent, "};\n");
136 print_file(file, indent, "\n");
140 static void write_typeformatstring_var(FILE *file, int indent, var_t *var)
142 int ptr_level = var->ptr_level;
144 /* basic types don't need a type format string */
150 switch (var->type->type)
152 #define CASE_BASETYPE(fctype) \
154 print_file(file, indent, "0x11, 0x08, /* FC_RP [simple_pointer] */\n"); \
155 print_file(file, indent, "0x%02x, /* " #fctype " */\n", var->type->type); \
156 print_file(file, indent, "0x5c, /* FC_PAD */\n"); \
158 CASE_BASETYPE(FC_BYTE);
159 CASE_BASETYPE(FC_CHAR);
160 CASE_BASETYPE(FC_SMALL);
161 CASE_BASETYPE(FC_USMALL);
162 CASE_BASETYPE(FC_WCHAR);
163 CASE_BASETYPE(FC_SHORT);
164 CASE_BASETYPE(FC_USHORT);
165 CASE_BASETYPE(FC_LONG);
166 CASE_BASETYPE(FC_ULONG);
167 CASE_BASETYPE(FC_FLOAT);
168 CASE_BASETYPE(FC_HYPER);
169 CASE_BASETYPE(FC_DOUBLE);
170 CASE_BASETYPE(FC_ENUM16);
171 CASE_BASETYPE(FC_ENUM32);
172 CASE_BASETYPE(FC_IGNORE);
173 CASE_BASETYPE(FC_ERROR_STATUS_T);
175 error("write_typeformatstring_var: Unknown/unsupported type: %s (0x%02x)\n", var->name, var->type->type);
180 void write_typeformatstring(FILE *file, type_t *iface)
183 func_t *func = iface->funcs;
186 print_file(file, indent, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
187 print_file(file, indent, "{\n");
189 print_file(file, indent, "0,\n");
190 print_file(file, indent, "{\n");
192 print_file(file, indent, "NdrFcShort(0x0),\n");
194 while (NEXT_LINK(func)) func = NEXT_LINK(func);
200 while (NEXT_LINK(var)) var = NEXT_LINK(var);
203 write_typeformatstring_var(file, indent, var);
204 var = PREV_LINK(var);
207 func = PREV_LINK(func);
210 print_file(file, indent, "0x0\n");
212 print_file(file, indent, "}\n");
214 print_file(file, indent, "};\n");
215 print_file(file, indent, "\n");
219 unsigned int get_required_buffer_size(type_t *type)
234 case RPC_FC_ERROR_STATUS_T:
242 error("Unknown/unsupported type: %s (0x%02x)\n", type->name, type->type);
247 void marshall_arguments(FILE *file, int indent, func_t *func)
249 unsigned int alignment;
251 unsigned int last_size = 0;
258 while (NEXT_LINK(var)) var = NEXT_LINK(var);
262 switch (var->type->type)
276 if (last_size != 0 && last_size < 2)
277 alignment = (2 - last_size);
283 case RPC_FC_ERROR_STATUS_T:
285 if (last_size != 0 && last_size < 4)
286 alignment = (4 - last_size);
292 if (last_size != 0 && last_size < 4)
293 alignment = (4 - last_size);
298 error("Unknown/unsupported type: %s (0x%02x)\n", var->name, var->type->type);
302 print_file(file, indent, "_StubMsg.Buffer += %u;\n", alignment);
304 print_file(file, indent, "*(");
305 write_type(file, var->type, var, var->tname);
306 fprintf(file, " *)_StubMsg.Buffer = ");
307 write_name(file, var);
308 fprintf(file, ";\n");
309 fprintf(file, "_StubMsg.Buffer += sizeof(");
310 write_type(file, var->type, var, var->tname);
311 fprintf(file, ");\n");
316 var = PREV_LINK(var);
320 void unmarshall_arguments(FILE *file, int indent, func_t *func)
322 unsigned int alignment;
324 unsigned int last_size = 0;
331 while (NEXT_LINK(var)) var = NEXT_LINK(var);
335 switch (var->type->type)
349 if (last_size != 0 && last_size < 2)
350 alignment = (2 - last_size);
356 case RPC_FC_ERROR_STATUS_T:
358 if (last_size != 0 && last_size < 4)
359 alignment = (4 - last_size);
365 if (last_size != 0 && last_size < 4)
366 alignment = (4 - last_size);
371 error("Unknown/unsupported type: %s (0x%02x)\n", var->name, var->type->type);
375 print_file(file, indent, "_StubMsg.Buffer += %u;\n", alignment);
377 print_file(file, indent, "");
378 write_name(file, var);
379 fprintf(file, " = *(");
380 write_type(file, var->type, var, var->tname);
381 fprintf(file, " *)_StubMsg.Buffer;\n");
382 fprintf(file, "_StubMsg.Buffer += sizeof(");
383 write_type(file, var->type, var, var->tname);
384 fprintf(file, ");\n");
389 var = PREV_LINK(var);