2 * Format String Generator for IDL Compiler
4 * Copyright 2005-2006 Eric Kohl
5 * Copyright 2005-2006 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
41 #include "wine/list.h"
46 static const func_t
*current_func
;
47 static const type_t
*current_structure
;
49 /* name of the structure variable for structure callbacks */
50 #define STRUCT_EXPR_EVAL_VAR "pS"
52 static struct list expr_eval_routines
= LIST_INIT(expr_eval_routines
);
54 struct expr_eval_routine
57 const type_t
*structure
;
58 size_t structure_size
;
62 static size_t type_memsize(const type_t
*t
, const array_dims_t
*array
, unsigned int *align
);
63 static size_t fields_memsize(const var_list_t
*fields
, unsigned int *align
);
64 static size_t write_struct_tfs(FILE *file
, type_t
*type
, const char *name
,
65 unsigned int *typestring_offset
);
66 const char *string_of_type(unsigned char type
)
70 case RPC_FC_BYTE
: return "FC_BYTE";
71 case RPC_FC_CHAR
: return "FC_CHAR";
72 case RPC_FC_SMALL
: return "FC_SMALL";
73 case RPC_FC_USMALL
: return "FC_USMALL";
74 case RPC_FC_WCHAR
: return "FC_WCHAR";
75 case RPC_FC_SHORT
: return "FC_SHORT";
76 case RPC_FC_USHORT
: return "FC_USHORT";
77 case RPC_FC_LONG
: return "FC_LONG";
78 case RPC_FC_ULONG
: return "FC_ULONG";
79 case RPC_FC_FLOAT
: return "FC_FLOAT";
80 case RPC_FC_HYPER
: return "FC_HYPER";
81 case RPC_FC_DOUBLE
: return "FC_DOUBLE";
82 case RPC_FC_ENUM16
: return "FC_ENUM16";
83 case RPC_FC_ENUM32
: return "FC_ENUM32";
84 case RPC_FC_IGNORE
: return "FC_IGNORE";
85 case RPC_FC_ERROR_STATUS_T
: return "FC_ERROR_STATUS_T";
86 case RPC_FC_RP
: return "FC_RP";
87 case RPC_FC_UP
: return "FC_UP";
88 case RPC_FC_OP
: return "FC_OP";
89 case RPC_FC_FP
: return "FC_FP";
91 error("string_of_type: unknown type 0x%02x\n", type
);
96 static int is_struct(unsigned char type
)
103 case RPC_FC_CPSTRUCT
:
104 case RPC_FC_CVSTRUCT
:
105 case RPC_FC_BOGUS_STRUCT
:
112 static int compare_expr(const expr_t
*a
, const expr_t
*b
)
116 if (a
->type
!= b
->type
)
117 return a
->type
- b
->type
;
124 return a
->u
.lval
- b
->u
.lval
;
125 case EXPR_IDENTIFIER
:
126 return strcmp(a
->u
.sval
, b
->u
.sval
);
128 ret
= compare_expr(a
->ref
, b
->ref
);
131 ret
= compare_expr(a
->u
.ext
, b
->u
.ext
);
134 return compare_expr(a
->ext2
, b
->ext2
);
143 ret
= compare_expr(a
->ref
, b
->ref
);
146 return compare_expr(a
->u
.ext
, b
->u
.ext
);
152 return compare_expr(a
->ref
, b
->ref
);
159 #define WRITE_FCTYPE(file, fctype, typestring_offset) \
162 fprintf(file, "/* %2u */\n", typestring_offset); \
163 print_file((file), 2, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
167 static int print_file(FILE *file
, int indent
, const char *format
, ...)
174 va_start(va
, format
);
175 for (i
= 0; i
< indent
; i
++)
177 r
= vfprintf(file
, format
, va
);
182 static void write_formatdesc(FILE *f
, int indent
, const char *str
)
184 print_file(f
, indent
, "typedef struct _MIDL_%s_FORMAT_STRING\n", str
);
185 print_file(f
, indent
, "{\n");
186 print_file(f
, indent
+ 1, "short Pad;\n");
187 print_file(f
, indent
+ 1, "unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str
);
188 print_file(f
, indent
, "} MIDL_%s_FORMAT_STRING;\n", str
);
189 print_file(f
, indent
, "\n");
192 void write_formatstringsdecl(FILE *f
, int indent
, ifref_list_t
*ifaces
, int for_objects
)
194 print_file(f
, indent
, "#define TYPE_FORMAT_STRING_SIZE %d\n",
195 get_size_typeformatstring(ifaces
, for_objects
));
197 print_file(f
, indent
, "#define PROC_FORMAT_STRING_SIZE %d\n",
198 get_size_procformatstring(ifaces
, for_objects
));
201 write_formatdesc(f
, indent
, "TYPE");
202 write_formatdesc(f
, indent
, "PROC");
204 print_file(f
, indent
, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
205 print_file(f
, indent
, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
206 print_file(f
, indent
, "\n");
209 static int is_user_derived(const var_t
*v
)
211 const type_t
*type
= v
->type
;
213 if (v
->attrs
&& is_attr( v
->attrs
, ATTR_WIREMARSHAL
)) return 1;
217 if (type
->attrs
&& is_attr( type
->attrs
, ATTR_WIREMARSHAL
)) return 1;
223 static inline int is_base_type(unsigned char type
)
242 case RPC_FC_ERROR_STATUS_T
:
243 case RPC_FC_BIND_PRIMITIVE
:
251 static size_t write_procformatstring_var(FILE *file
, int indent
,
252 const var_t
*var
, int is_return
)
255 const type_t
*type
= var
->type
;
257 int is_in
= is_attr(var
->attrs
, ATTR_IN
);
258 int is_out
= is_attr(var
->attrs
, ATTR_OUT
);
260 if (!is_in
&& !is_out
) is_in
= TRUE
;
262 if (!var
->array
&& is_base_type(type
->type
))
265 print_file(file
, indent
, "0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
267 print_file(file
, indent
, "0x4e, /* FC_IN_PARAM_BASETYPE */\n");
269 if (is_base_type(type
->type
))
271 print_file(file
, indent
, "0x%02x, /* %s */\n", type
->type
, string_of_type(type
->type
));
272 size
= 2; /* includes param type prefix */
274 else if (type
->type
== RPC_FC_BIND_PRIMITIVE
)
276 print_file(file
, indent
, "0x%02x, /* FC_IGNORE */\n", RPC_FC_IGNORE
);
277 size
= 2; /* includes param type prefix */
281 error("Unknown/unsupported type: %s (0x%02x)\n", var
->name
, type
->type
);
288 print_file(file
, indent
, "0x52, /* FC_RETURN_PARAM */\n");
289 else if (is_in
&& is_out
)
290 print_file(file
, indent
, "0x50, /* FC_IN_OUT_PARAM */\n");
292 print_file(file
, indent
, "0x51, /* FC_OUT_PARAM */\n");
294 print_file(file
, indent
, "0x4d, /* FC_IN_PARAM */\n");
296 print_file(file
, indent
, "0x01,\n");
297 print_file(file
, indent
, "NdrFcShort(0x%x),\n", type
->typestring_offset
);
298 size
= 4; /* includes param type prefix */
303 void write_procformatstring(FILE *file
, const ifref_list_t
*ifaces
, int for_objects
)
305 const ifref_t
*iface
;
309 print_file(file
, indent
, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
310 print_file(file
, indent
, "{\n");
312 print_file(file
, indent
, "0,\n");
313 print_file(file
, indent
, "{\n");
316 if (ifaces
) LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
318 if (for_objects
!= is_object(iface
->iface
->attrs
) || is_local(iface
->iface
->attrs
))
321 if (iface
->iface
->funcs
)
324 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
326 if (is_local(func
->def
->attrs
)) continue;
327 /* emit argument data */
330 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
331 write_procformatstring_var(file
, indent
, var
, FALSE
);
334 /* emit return value data */
336 if (is_void(var
->type
))
338 print_file(file
, indent
, "0x5b, /* FC_END */\n");
339 print_file(file
, indent
, "0x5c, /* FC_PAD */\n");
342 write_procformatstring_var(file
, indent
, var
, TRUE
);
347 print_file(file
, indent
, "0x0\n");
349 print_file(file
, indent
, "}\n");
351 print_file(file
, indent
, "};\n");
352 print_file(file
, indent
, "\n");
355 static int write_base_type(FILE *file
, const type_t
*type
, unsigned int *typestring_offset
)
357 if (is_base_type(type
->type
))
359 print_file(file
, 2, "0x%02x,\t/* %s */\n", type
->type
, string_of_type(type
->type
));
360 *typestring_offset
+= 1;
367 /* write conformance / variance descriptor */
368 static size_t write_conf_or_var_desc(FILE *file
, const func_t
*func
, const type_t
*structure
, const expr_list_t
*expr_list
)
370 unsigned char operator_type
= 0;
371 const char *operator_string
= "no operators";
372 const expr_t
*expr
, *subexpr
;
373 unsigned char correlation_type
;
375 if (!file
) return 4; /* optimisation for sizing pass */
377 if (list_count(expr_list
) > 1)
378 error("write_conf_or_var_desc: multi-dimensional arrays not supported yet\n");
380 expr
= subexpr
= LIST_ENTRY( list_head(expr_list
), const expr_t
, entry
);
384 if (expr
->cval
> UCHAR_MAX
* (USHRT_MAX
+ 1) + USHRT_MAX
)
385 error("write_conf_or_var_desc: constant value %ld is greater than "
386 "the maximum constant size of %d\n", expr
->cval
,
387 UCHAR_MAX
* (USHRT_MAX
+ 1) + USHRT_MAX
);
389 print_file(file
, 2, "0x%x, /* Corr desc: constant, val = %ld */\n",
390 RPC_FC_CONSTANT_CONFORMANCE
, expr
->cval
);
391 print_file(file
, 2, "0x%x,\n", expr
->cval
& ~USHRT_MAX
);
392 print_file(file
, 2, "NdrFcShort(0x%x),\n", expr
->cval
& USHRT_MAX
);
397 switch (subexpr
->type
)
400 subexpr
= subexpr
->ref
;
401 operator_type
= RPC_FC_DEREFERENCE
;
402 operator_string
= "FC_DEREFERENCE";
405 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 2))
407 subexpr
= subexpr
->ref
;
408 operator_type
= RPC_FC_DIV_2
;
409 operator_string
= "FC_DIV_2";
413 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 2))
415 subexpr
= subexpr
->ref
;
416 operator_type
= RPC_FC_MULT_2
;
417 operator_string
= "FC_MULT_2";
421 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 1))
423 subexpr
= subexpr
->ref
;
424 operator_type
= RPC_FC_SUB_1
;
425 operator_string
= "FC_SUB_1";
429 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 1))
431 subexpr
= subexpr
->ref
;
432 operator_type
= RPC_FC_ADD_1
;
433 operator_string
= "FC_ADD_1";
440 if (subexpr
->type
== EXPR_IDENTIFIER
)
442 const type_t
*correlation_variable
= NULL
;
443 unsigned char correlation_variable_type
;
444 unsigned char param_type
= 0;
445 const char *param_type_string
= NULL
;
453 if (structure
->fields
) LIST_FOR_EACH_ENTRY( var
, structure
->fields
, const var_t
, entry
)
455 unsigned int align
= 0;
456 offset
-= type_memsize(var
->type
, var
->array
, &align
);
457 /* FIXME: take alignment into account */
458 if (!strcmp(var
->name
, subexpr
->u
.sval
))
460 correlation_variable
= var
->type
;
464 if (!correlation_variable
)
465 error("write_conf_or_var_desc: couldn't find variable %s in structure\n",
468 correlation_type
= RPC_FC_NORMAL_CONFORMANCE
;
474 offset
= sizeof(void *);
475 if (func
->args
) LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
477 if (!strcmp(var
->name
, subexpr
->u
.sval
))
479 correlation_variable
= var
->type
;
482 /* FIXME: not all stack variables are sizeof(void *) */
483 offset
+= sizeof(void *);
485 if (!correlation_variable
)
486 error("write_conf_or_var_desc: couldn't find variable %s in function\n",
489 correlation_type
= RPC_FC_TOP_LEVEL_CONFORMANCE
;
492 correlation_variable_type
= correlation_variable
->type
;
494 switch (correlation_variable_type
)
498 param_type
= RPC_FC_SMALL
;
499 param_type_string
= "FC_SMALL";
503 param_type
= RPC_FC_USMALL
;
504 param_type_string
= "FC_USMALL";
508 param_type
= RPC_FC_SHORT
;
509 param_type_string
= "FC_SHORT";
512 param_type
= RPC_FC_USHORT
;
513 param_type_string
= "FC_USHORT";
516 param_type
= RPC_FC_LONG
;
517 param_type_string
= "FC_LONG";
520 param_type
= RPC_FC_ULONG
;
521 param_type_string
= "FC_ULONG";
527 if (sizeof(void *) == 4) /* FIXME */
529 param_type
= RPC_FC_LONG
;
530 param_type_string
= "FC_LONG";
534 param_type
= RPC_FC_HYPER
;
535 param_type_string
= "FC_HYPER";
539 error("write_conf_or_var_desc: conformance variable type not supported 0x%x\n",
540 correlation_variable_type
);
543 print_file(file
, 2, "0x%x, /* Corr desc: %s%s */\n",
544 correlation_type
| param_type
,
545 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "parameter, " : "",
547 print_file(file
, 2, "0x%x, /* %s */\n", operator_type
, operator_string
);
548 print_file(file
, 2, "NdrFcShort(0x%x), /* %soffset = %d */\n",
550 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "x86 stack size / " : "",
555 unsigned int callback_offset
= 0;
559 struct expr_eval_routine
*eval
;
562 LIST_FOR_EACH_ENTRY(eval
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
564 if (!strcmp(eval
->structure
->name
, structure
->name
) &&
565 !compare_expr(eval
->expr
, expr
))
575 unsigned int align
= 0;
576 eval
= xmalloc(sizeof(*eval
));
577 eval
->structure
= structure
;
578 eval
->structure_size
= fields_memsize(structure
->fields
, &align
);
580 list_add_tail(&expr_eval_routines
, &eval
->entry
);
583 correlation_type
= RPC_FC_NORMAL_CONFORMANCE
;
587 error("write_conf_or_var_desc: top-level callback conformance unimplemented\n");
588 correlation_type
= RPC_FC_TOP_LEVEL_CONFORMANCE
;
591 if (callback_offset
> USHRT_MAX
)
592 error("Maximum number of callback routines reached\n");
594 print_file(file
, 2, "0x%x, /* Corr desc: %s */\n",
596 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "parameter" : "");
597 print_file(file
, 2, "0x%x, /* %s */\n", RPC_FC_CALLBACK
, "FC_CALLBACK");
598 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", callback_offset
, callback_offset
);
603 static size_t fields_memsize(const var_list_t
*fields
, unsigned int *align
)
608 if (!fields
) return 0;
609 LIST_FOR_EACH_ENTRY( v
, fields
, const var_t
, entry
)
610 size
+= type_memsize(v
->type
, v
->array
, align
);
615 static size_t get_array_size( const array_dims_t
*array
)
620 if (!array
) return 0;
622 LIST_FOR_EACH_ENTRY( dim
, array
, expr_t
, entry
)
624 if (!dim
->is_const
) return 0;
631 static size_t type_memsize(const type_t
*t
, const array_dims_t
*array
, unsigned int *align
)
637 size
= sizeof(void *);
638 if (size
> *align
) *align
= size
;
640 else switch (t
->type
)
647 if (size
> *align
) *align
= size
;
654 if (size
> *align
) *align
= size
;
658 case RPC_FC_ERROR_STATUS_T
:
662 if (size
> *align
) *align
= size
;
667 if (size
> *align
) *align
= size
;
670 case RPC_FC_CVSTRUCT
:
671 case RPC_FC_CPSTRUCT
:
674 case RPC_FC_BOGUS_STRUCT
:
675 case RPC_FC_ENCAPSULATED_UNION
:
676 case RPC_FC_NON_ENCAPSULATED_UNION
:
677 size
= fields_memsize(t
->fields
, align
);
680 error("type_memsize: Unknown type %d\n", t
->type
);
684 if (array
) size
*= get_array_size( array
);
688 static size_t write_nonsimple_pointer(FILE *file
, const type_t
*type
, size_t offset
)
690 short absoff
= type
->ref
->typestring_offset
;
691 short reloff
= absoff
- (offset
+ 2);
692 int ptr_attr
= is_ptr(type
->ref
) ? 0x10 : 0x0;
694 print_file(file
, 2, "0x%02x, 0x%x,\t/* %s */\n",
695 type
->type
, ptr_attr
, string_of_type(type
->type
));
696 print_file(file
, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%hd) */\n",
697 reloff
, reloff
, absoff
);
701 static size_t write_simple_pointer(FILE *file
, const type_t
*type
)
703 print_file(file
, 2, "0x%02x, 0x8,\t/* %s [simple_pointer] */\n",
704 type
->type
, string_of_type(type
->type
));
705 print_file(file
, 2, "0x%02x,\t/* %s */\n", type
->ref
->type
,
706 string_of_type(type
->ref
->type
));
707 print_file(file
, 2, "0x5c,\t/* FC_PAD */\n");
711 static size_t write_pointer_tfs(FILE *file
, type_t
*type
, size_t *typestring_offset
)
713 size_t offset
= *typestring_offset
;
715 print_file(file
, 0, "/* %d */\n", offset
);
716 type
->typestring_offset
= offset
;
718 if (type
->ref
->typestring_offset
)
719 *typestring_offset
+= write_nonsimple_pointer(file
, type
, offset
);
720 else if (is_base_type(type
->ref
->type
))
721 *typestring_offset
+= write_simple_pointer(file
, type
);
726 static int has_known_tfs(const type_t
*type
)
728 return type
->typestring_offset
|| is_base_type(type
->type
);
731 static int write_pointers(FILE *file
, const attr_list_t
*attrs
,
732 type_t
*type
, const char *name
,
733 const array_dims_t
*array
, int level
,
734 unsigned int *typestring_offset
)
738 /* don't generate a pointer for first-level arrays since we want to
739 * descend into them to write their pointers, not stop here */
740 if ((level
== 0 || !is_ptr(type
)) && is_array_type(attrs
, type
, array
))
742 return write_pointers(file
, NULL
, type
, name
, NULL
, level
+ 1, typestring_offset
);
744 else if (is_ptr(type
))
746 type_t
*ref
= type
->ref
;
748 if (!has_known_tfs(ref
))
752 write_pointers(file
, attrs
, ref
, name
, array
, level
+ 1,
755 else if (is_struct(ref
->type
))
757 write_struct_tfs(file
, ref
, name
, typestring_offset
);
761 error("write_pointers: type format string unknown for %s (0x%02x)\n",
766 /* top-level pointers are handled by write_pointer_description */
768 write_pointer_tfs(file
, type
, typestring_offset
);
772 else if (is_struct(type
->type
))
774 int pointers_written
= 0;
777 LIST_FOR_EACH_ENTRY( v
, type
->fields
, const var_t
, entry
)
778 pointers_written
+= write_pointers(file
, v
->attrs
, v
->type
,
783 return pointers_written
;
788 static size_t write_pointer_description(FILE *file
, const attr_list_t
*attrs
,
789 type_t
*type
, size_t mem_offset
,
790 const array_dims_t
*array
, int level
,
791 size_t *typestring_offset
)
794 unsigned int align
= 0;
796 /* don't generate a pointer for first-level arrays since we want to
797 * descend into them to write their pointers, not stop here */
798 if ((level
== 0 || !is_ptr(type
)) && is_array_type(attrs
, type
, array
))
800 write_pointer_description(file
, NULL
, type
, mem_offset
, NULL
,
801 level
+ 1, typestring_offset
);
803 else if (is_ptr(type
))
805 print_file(file
, 2, "0x46,\t/* FC_NO_REPEAT */\n");
806 print_file(file
, 2, "0x5c,\t/* FC_PAD */\n");
807 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", mem_offset
, mem_offset
);
808 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", mem_offset
, mem_offset
);
809 *typestring_offset
+= 6;
811 if (has_known_tfs(type
->ref
))
812 write_pointer_tfs(file
, type
, typestring_offset
);
814 error("write_pointer_description: type format string unknown\n");
816 else if (level
== 0 && is_struct(type
->type
))
820 LIST_FOR_EACH_ENTRY( v
, type
->fields
, const var_t
, entry
)
822 += write_pointer_description(file
, v
->attrs
, v
->type
,
823 mem_offset
, v
->array
,
829 return type_memsize(type
, array
, &align
);
832 static size_t write_string_tfs(FILE *file
, const attr_list_t
*attrs
,
833 const type_t
*type
, const array_dims_t
*array
,
834 const char *name
, unsigned int *typestring_offset
)
836 const expr_list_t
*size_is
= get_attrp(attrs
, ATTR_SIZEIS
);
837 int has_size
= is_non_void(size_is
);
838 size_t start_offset
= *typestring_offset
;
839 unsigned char flags
= 0;
845 pointer_type
= type
->type
;
849 pointer_type
= get_attrv(attrs
, ATTR_POINTERTYPE
);
852 pointer_type
= RPC_FC_RP
;
854 if (!get_attrp(attrs
, ATTR_SIZEIS
))
855 flags
|= RPC_FC_P_SIMPLEPOINTER
;
859 if ((rtype
!= RPC_FC_BYTE
) && (rtype
!= RPC_FC_CHAR
) && (rtype
!= RPC_FC_WCHAR
))
861 error("write_string_tfs: Unimplemented for type 0x%x of name: %s\n", rtype
, name
);
865 print_file(file
, 2,"0x%x, 0x%x, /* %s%s */\n",
867 pointer_type
== RPC_FC_FP
? "FC_FP" : (pointer_type
== RPC_FC_UP
? "FC_UP" : "FC_RP"),
868 (flags
& RPC_FC_P_SIMPLEPOINTER
) ? " [simple_pointer]" : "");
869 *typestring_offset
+= 2;
871 if (!(flags
& RPC_FC_P_SIMPLEPOINTER
))
873 print_file(file
, 2, "NdrFcShort(0x2),\n");
874 *typestring_offset
+= 2;
877 if (array
&& !is_conformant_array(array
))
879 /* FIXME: multi-dimensional array */
880 const expr_t
*dim
= LIST_ENTRY( list_head( array
), expr_t
, entry
);
881 if (dim
->cval
> USHRT_MAX
)
882 error("array size for parameter %s exceeds %d bytes by %ld bytes\n",
883 name
, USHRT_MAX
, dim
->cval
- USHRT_MAX
);
885 if (rtype
== RPC_FC_CHAR
)
886 WRITE_FCTYPE(file
, FC_CSTRING
, *typestring_offset
);
888 WRITE_FCTYPE(file
, FC_WSTRING
, *typestring_offset
);
889 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
890 *typestring_offset
+= 2;
892 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", dim
->cval
, dim
->cval
);
893 *typestring_offset
+= 2;
899 if (rtype
== RPC_FC_CHAR
)
900 WRITE_FCTYPE(file
, FC_C_CSTRING
, *typestring_offset
);
902 WRITE_FCTYPE(file
, FC_C_WSTRING
, *typestring_offset
);
903 print_file(file
, 2, "0x%x, /* FC_STRING_SIZED */\n", RPC_FC_STRING_SIZED
);
904 *typestring_offset
+= 2;
906 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
, NULL
, size_is
);
912 if (rtype
== RPC_FC_CHAR
)
913 WRITE_FCTYPE(file
, FC_C_CSTRING
, *typestring_offset
);
915 WRITE_FCTYPE(file
, FC_C_WSTRING
, *typestring_offset
);
916 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
917 *typestring_offset
+= 2;
923 static size_t write_array_tfs(FILE *file
, const attr_list_t
*attrs
,
924 type_t
*type
, const array_dims_t
*array
,
925 const char *name
, unsigned int *typestring_offset
)
927 const expr_list_t
*length_is
= get_attrp(attrs
, ATTR_LENGTHIS
);
928 const expr_list_t
*size_is
= get_attrp(attrs
, ATTR_SIZEIS
);
929 int has_length
= is_non_void(length_is
);
930 int has_size
= is_non_void(size_is
) || is_conformant_array(array
);
932 int pointer_type
= get_attrv(attrs
, ATTR_POINTERTYPE
);
934 pointer_type
= RPC_FC_RP
;
936 print_file(file
, 2, "0x%x, 0x00, /* %s */\n",
938 pointer_type
== RPC_FC_FP
? "FC_FP" : (pointer_type
== RPC_FC_UP
? "FC_UP" : "FC_RP"));
939 print_file(file
, 2, "NdrFcShort(0x2),\n");
940 *typestring_offset
+= 4;
942 if (array
&& list_count(array
) > 1) /* multi-dimensional array */
944 error("write_array_tfs: Multi-dimensional arrays not implemented yet (param %s)\n", name
);
949 const expr_t
*dim
= array
? LIST_ENTRY( list_head( array
), expr_t
, entry
) : NULL
;
952 if (write_pointers(file
, attrs
, type
, name
, array
, 0, typestring_offset
) > 0)
955 start_offset
= *typestring_offset
;
957 if (!has_length
&& !has_size
)
960 unsigned int align
= 0;
961 size_t size
= type_memsize(type
, array
, &align
);
962 if (size
< USHRT_MAX
)
964 WRITE_FCTYPE(file
, FC_SMFARRAY
, *typestring_offset
);
966 print_file(file
, 2, "0x%02x,\n", align
- 1);
968 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", size
, size
);
969 *typestring_offset
+= 4;
973 WRITE_FCTYPE(file
, FC_LGFARRAY
, *typestring_offset
);
975 print_file(file
, 2, "0x%02x,\n", align
- 1);
977 print_file(file
, 2, "NdrFcLong(0x%x), /* %d */\n", size
, size
);
978 *typestring_offset
+= 6;
983 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
984 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
985 *typestring_offset
+= 2;
986 write_pointer_description(file
, attrs
, type
, 0, array
, 0, typestring_offset
);
987 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
988 *typestring_offset
+= 1;
991 if (!write_base_type( file
, type
, typestring_offset
))
993 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
994 *typestring_offset
+= 1;
996 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
997 *typestring_offset
+= 1;
1001 else if (has_length
&& !has_size
)
1004 unsigned int align
= 0;
1005 size_t element_size
= type_memsize(type
, NULL
, &align
);
1006 size_t elements
= dim
->cval
;
1007 size_t total_size
= element_size
* elements
;
1009 if (total_size
< USHRT_MAX
)
1011 WRITE_FCTYPE(file
, FC_SMVARRAY
, *typestring_offset
);
1013 print_file(file
, 2, "0x%02x,\n", align
- 1);
1015 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", total_size
, total_size
);
1016 /* number of elements */
1017 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", elements
, elements
);
1018 *typestring_offset
+= 6;
1022 WRITE_FCTYPE(file
, FC_LGVARRAY
, *typestring_offset
);
1024 print_file(file
, 2, "0x%02x,\n", align
- 1);
1026 print_file(file
, 2, "NdrFcLong(0x%x), /* %d */\n", total_size
, total_size
);
1027 /* number of elements */
1028 print_file(file
, 2, "NdrFcLong(0x%x), /* %d */\n", elements
, elements
);
1029 *typestring_offset
+= 10;
1032 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", element_size
, element_size
);
1033 *typestring_offset
+= 2;
1035 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
1041 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1042 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1043 *typestring_offset
+= 2;
1044 write_pointer_description(file
, attrs
, type
, 0, array
, 0, typestring_offset
);
1045 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1046 *typestring_offset
+= 1;
1049 if (!write_base_type( file
, type
, typestring_offset
))
1051 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
1052 *typestring_offset
+= 1;
1054 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1055 *typestring_offset
+= 1;
1057 return start_offset
;
1059 else if (!has_length
&& has_size
)
1061 /* conformant array */
1062 unsigned int align
= 0;
1063 size_t element_size
= type_memsize(type
, NULL
, &align
);
1065 WRITE_FCTYPE(file
, FC_CARRAY
, *typestring_offset
);
1067 print_file(file
, 2, "0x%02x,\n", align
- 1);
1069 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", element_size
, element_size
);
1070 *typestring_offset
+= 4;
1072 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
1074 size_is
? size_is
: array
);
1078 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1079 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1080 *typestring_offset
+= 2;
1081 write_pointer_description(file
, attrs
, type
, 0, array
, 0, typestring_offset
);
1082 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1083 *typestring_offset
+= 1;
1086 if (!write_base_type( file
, type
, typestring_offset
))
1088 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
1089 *typestring_offset
+= 1;
1091 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1092 *typestring_offset
+= 1;
1094 return start_offset
;
1098 /* conformant varying array */
1099 unsigned int align
= 0;
1100 size_t element_size
= type_memsize(type
, NULL
, &align
);
1102 WRITE_FCTYPE(file
, FC_CVARRAY
, *typestring_offset
);
1104 print_file(file
, 2, "0x%02x,\n", align
- 1);
1106 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", element_size
, element_size
);
1107 *typestring_offset
+= 4;
1109 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
1111 size_is
? size_is
: array
);
1112 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
1118 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1119 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1120 *typestring_offset
+= 2;
1121 write_pointer_description(file
, attrs
, type
, 0, array
, 0, typestring_offset
);
1122 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1123 *typestring_offset
+= 1;
1126 if (!write_base_type( file
, type
, typestring_offset
))
1128 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
1129 *typestring_offset
+= 1;
1131 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1132 *typestring_offset
+= 1;
1134 return start_offset
;
1139 static const var_t
*find_array_or_string_in_struct(const type_t
*type
)
1141 const var_t
*last_field
= LIST_ENTRY( list_tail(type
->fields
), const var_t
, entry
);
1143 if (is_array_type(last_field
->attrs
, last_field
->type
, last_field
->array
))
1146 assert((last_field
->type
->type
== RPC_FC_CSTRUCT
) ||
1147 (last_field
->type
->type
== RPC_FC_CPSTRUCT
) ||
1148 (last_field
->type
->type
== RPC_FC_CVSTRUCT
));
1150 return find_array_or_string_in_struct(last_field
->type
);
1153 static void write_struct_members(FILE *file
, const type_t
*type
, unsigned int *typestring_offset
)
1157 if (type
->fields
) LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1159 unsigned char rtype
= field
->type
->type
;
1162 write_array_tfs( file
, field
->attrs
, field
->type
, field
->array
,
1163 field
->name
, typestring_offset
);
1164 else if (is_ptr( field
->type
))
1166 /* pointers are handled in detail earlier, here just treat them like longs */
1167 print_file( file
, 2, "0x8,\t/* FC_LONG */\n" );
1168 *typestring_offset
+= 1;
1170 else if (!write_base_type( file
, field
->type
, typestring_offset
))
1171 error("Unsupported member type 0x%x\n", rtype
);
1174 if (!(*typestring_offset
% 2))
1176 print_file(file
, 2, "0x%x,\t\t/* FC_PAD */\n", RPC_FC_PAD
);
1177 *typestring_offset
+= 1;
1180 print_file(file
, 2, "0x%x,\t\t/* FC_END */\n", RPC_FC_END
);
1181 *typestring_offset
+= 1;
1184 static size_t write_struct_tfs(FILE *file
, type_t
*type
,
1185 const char *name
, unsigned int *typestring_offset
)
1187 unsigned int total_size
;
1189 size_t start_offset
;
1190 size_t array_offset
;
1192 unsigned int align
= 0;
1197 case RPC_FC_PSTRUCT
:
1198 total_size
= type_memsize(type
, NULL
, &align
);
1200 if (total_size
> USHRT_MAX
)
1201 error("structure size for %s exceeds %d bytes by %d bytes\n",
1202 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
1204 if (type
->type
== RPC_FC_PSTRUCT
)
1205 write_pointers(file
, NULL
, type
, name
, NULL
, 0, typestring_offset
);
1207 start_offset
= *typestring_offset
;
1208 type
->typestring_offset
= start_offset
;
1209 if (type
->type
== RPC_FC_STRUCT
)
1210 WRITE_FCTYPE(file
, FC_STRUCT
, *typestring_offset
);
1212 WRITE_FCTYPE(file
, FC_PSTRUCT
, *typestring_offset
);
1214 print_file(file
, 2, "0x%02x,\n", align
- 1);
1216 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", total_size
, total_size
);
1217 *typestring_offset
+= 4;
1219 if (type
->type
== RPC_FC_PSTRUCT
)
1221 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1222 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1223 *typestring_offset
+= 2;
1224 write_pointer_description(file
, NULL
, type
, 0, NULL
, 0, typestring_offset
);
1225 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1226 *typestring_offset
+= 1;
1230 write_struct_members(file
, type
, typestring_offset
);
1231 return start_offset
;
1232 case RPC_FC_CSTRUCT
:
1233 case RPC_FC_CPSTRUCT
:
1234 total_size
= type_memsize(type
, NULL
, &align
);
1236 if (total_size
> USHRT_MAX
)
1237 error("structure size for %s exceeds %d bytes by %d bytes\n",
1238 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
1240 array
= find_array_or_string_in_struct(type
);
1241 current_structure
= type
;
1242 array_offset
= write_array_tfs(file
, array
->attrs
, array
->type
,
1243 array
->array
, array
->name
,
1245 current_structure
= NULL
;
1247 if (type
->type
== RPC_FC_CPSTRUCT
)
1248 write_pointers(file
, NULL
, type
, name
, NULL
, 0, typestring_offset
);
1250 start_offset
= *typestring_offset
;
1251 type
->typestring_offset
= start_offset
;
1252 if (type
->type
== RPC_FC_CSTRUCT
)
1253 WRITE_FCTYPE(file
, FC_CSTRUCT
, *typestring_offset
);
1255 WRITE_FCTYPE(file
, FC_CPSTRUCT
, *typestring_offset
);
1257 print_file(file
, 2, "0x%02x,\n", align
- 1);
1259 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", total_size
, total_size
);
1260 *typestring_offset
+= 4;
1261 print_file(file
, 2, "NdrFcShort(0x%x), /* offset = %d (%u) */\n",
1262 array_offset
- *typestring_offset
,
1263 array_offset
- *typestring_offset
,
1265 *typestring_offset
+= 2;
1267 if (type
->type
== RPC_FC_CPSTRUCT
)
1269 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1270 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1271 *typestring_offset
+= 2;
1272 write_pointer_description(file
, NULL
, type
, 0, NULL
, 0, typestring_offset
);
1273 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1274 *typestring_offset
+= 1;
1277 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1278 *typestring_offset
+= 1;
1280 return start_offset
;
1281 case RPC_FC_CVSTRUCT
:
1282 total_size
= type_memsize(type
, NULL
, &align
);
1284 if (total_size
> USHRT_MAX
)
1285 error("structure size for %s exceeds %d bytes by %d bytes\n",
1286 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
1288 array
= find_array_or_string_in_struct(type
);
1289 current_structure
= type
;
1290 if (is_attr(array
->attrs
, ATTR_STRING
))
1291 array_offset
= write_string_tfs(file
, array
->attrs
, array
->type
,
1292 array
->array
, array
->name
,
1295 array_offset
= write_array_tfs(file
, array
->attrs
, array
->type
,
1296 array
->array
, array
->name
,
1298 current_structure
= NULL
;
1300 has_pointers
= write_pointers(file
, NULL
, type
, name
, NULL
, 0, typestring_offset
);
1302 start_offset
= *typestring_offset
;
1303 type
->typestring_offset
= start_offset
;
1304 WRITE_FCTYPE(file
, FC_CVSTRUCT
, *typestring_offset
);
1306 print_file(file
, 2, "0x%02x,\n", align
- 1);
1308 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", total_size
, total_size
);
1309 *typestring_offset
+= 4;
1310 print_file(file
, 2, "NdrFcShort(0x%x), /* offset = %d (%u) */\n",
1311 array_offset
- *typestring_offset
,
1312 array_offset
- *typestring_offset
,
1314 *typestring_offset
+= 2;
1318 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1319 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1320 *typestring_offset
+= 2;
1321 write_pointer_description(file
, NULL
, type
, 0, NULL
, 0, typestring_offset
);
1322 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1323 *typestring_offset
+= 1;
1326 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1327 *typestring_offset
+= 1;
1329 return start_offset
;
1331 error("write_struct_tfs: Unimplemented for type 0x%x\n", type
->type
);
1332 return *typestring_offset
;
1336 static size_t write_pointer_only_tfs(FILE *file
, const attr_list_t
*attrs
, int pointer_type
,
1337 unsigned char flags
, size_t offset
,
1338 unsigned int *typeformat_offset
)
1340 size_t start_offset
= *typeformat_offset
;
1341 short reloff
= offset
- (*typeformat_offset
+ 2);
1342 int in_attr
, out_attr
;
1343 in_attr
= is_attr(attrs
, ATTR_IN
);
1344 out_attr
= is_attr(attrs
, ATTR_OUT
);
1345 if (!in_attr
&& !out_attr
) in_attr
= 1;
1347 if (out_attr
&& !in_attr
&& pointer_type
== RPC_FC_RP
)
1350 print_file(file
, 2, "0x%x, 0x%x,\t\t/* %s",
1353 string_of_type(pointer_type
));
1357 fprintf(file
, " [allocated_on_stack]");
1359 fprintf(file
, " [pointer_deref]");
1360 fprintf(file
, " */\n");
1363 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", reloff
, offset
);
1364 *typeformat_offset
+= 4;
1366 return start_offset
;
1369 static size_t write_union_tfs(FILE *file
, const attr_list_t
*attrs
,
1370 const type_t
*type
, const char *name
,
1371 unsigned int *typeformat_offset
)
1373 error("write_union_tfs: Unimplemented\n");
1374 return *typeformat_offset
;
1377 static size_t write_ip_tfs(FILE *file
, const func_t
*func
, const type_t
*type
, const var_t
*var
,
1378 unsigned int *typeformat_offset
)
1381 size_t start_offset
= *typeformat_offset
;
1382 const var_t
*iid
= get_attrp(var
->attrs
, ATTR_IIDIS
);
1387 expr_list_t expr_list
;
1389 expr
.type
= EXPR_IDENTIFIER
;
1391 expr
.u
.sval
= iid
->name
;
1392 expr
.is_const
= FALSE
;
1393 list_init( &expr_list
);
1394 list_add_head( &expr_list
, &expr
.entry
);
1395 print_file(file
, 2, "0x2f, /* FC_IP */\n");
1396 print_file(file
, 2, "0x5c, /* FC_PAD */\n");
1397 *typeformat_offset
+= write_conf_or_var_desc(file
, func
, NULL
, &expr_list
) + 2;
1401 const type_t
*base
= is_ptr(type
) ? type
->ref
: type
;
1402 const UUID
*uuid
= get_attrp(base
->attrs
, ATTR_UUID
);
1405 error("%s: interface %s missing UUID\n", __FUNCTION__
, base
->name
);
1407 print_file(file
, 2, "0x2f,\t/* FC_IP */\n");
1408 print_file(file
, 2, "0x5a,\t/* FC_CONSTANT_IID */\n");
1409 print_file(file
, 2, "NdrFcLong(0x%08lx),\n", uuid
->Data1
);
1410 print_file(file
, 2, "NdrFcShort(0x%04x),\n", uuid
->Data2
);
1411 print_file(file
, 2, "NdrFcShort(0x%04x),\n", uuid
->Data3
);
1412 for (i
= 0; i
< 8; ++i
)
1413 print_file(file
, 2, "0x%02x,\n", uuid
->Data4
[i
]);
1416 fprintf(file
, "\n");
1418 *typeformat_offset
+= 18;
1420 return start_offset
;
1423 static int get_ptr_attr(const type_t
*t
, int def_type
)
1427 int ptr_attr
= get_attrv(t
->attrs
, ATTR_POINTERTYPE
);
1430 if (t
->kind
!= TKIND_ALIAS
)
1436 static size_t write_typeformatstring_var(FILE *file
, int indent
, const func_t
*func
,
1437 type_t
*type
, const var_t
*var
,
1438 unsigned int *typeformat_offset
)
1443 if (type
== var
->type
) /* top-level pointers */
1445 int pointer_attr
= get_attrv(var
->attrs
, ATTR_POINTERTYPE
);
1446 if (pointer_attr
!= 0 && !is_ptr(type
))
1447 error("'%s': pointer attribute applied to non-pointer type\n", var
->name
);
1449 if (pointer_attr
== 0)
1450 pointer_attr
= get_ptr_attr(type
, RPC_FC_RP
);
1452 pointer_type
= pointer_attr
;
1455 pointer_type
= get_ptr_attr(type
, RPC_FC_UP
);
1457 if (((last_ptr(type
) && var
->array
== NULL
)
1458 || (!is_ptr(type
) && var
->array
!= NULL
))
1459 && is_ptrchain_attr(var
, ATTR_STRING
))
1461 return write_string_tfs(file
, var
->attrs
, type
, var
->array
, var
->name
, typeformat_offset
);
1464 if (is_array_type(var
->attrs
, type
, var
->array
))
1465 return write_array_tfs(file
, var
->attrs
, type
, var
->array
, var
->name
, typeformat_offset
);
1469 /* basic types don't need a type format string */
1470 if (is_base_type(type
->type
))
1476 case RPC_FC_PSTRUCT
:
1477 case RPC_FC_CSTRUCT
:
1478 case RPC_FC_CPSTRUCT
:
1479 case RPC_FC_CVSTRUCT
:
1480 case RPC_FC_BOGUS_STRUCT
:
1481 return write_struct_tfs(file
, type
, var
->name
, typeformat_offset
);
1482 case RPC_FC_ENCAPSULATED_UNION
:
1483 case RPC_FC_NON_ENCAPSULATED_UNION
:
1484 return write_union_tfs(file
, var
->attrs
, type
, var
->name
, typeformat_offset
);
1486 case RPC_FC_BIND_PRIMITIVE
:
1490 error("write_typeformatstring_var: Unsupported type 0x%x for variable %s\n", type
->type
, var
->name
);
1493 else if (last_ptr(type
))
1495 size_t start_offset
= *typeformat_offset
;
1496 int in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1497 int out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1498 const type_t
*base
= type
->ref
;
1500 if (base
->type
== RPC_FC_IP
)
1502 return write_ip_tfs(file
, func
, type
, var
, typeformat_offset
);
1505 /* special case for pointers to base types */
1506 if (is_base_type(base
->type
))
1508 print_file(file
, indent
, "0x%x, 0x%x, /* %s %s[simple_pointer] */\n",
1509 pointer_type
, (!in_attr
&& out_attr
) ? 0x0C : 0x08,
1510 string_of_type(pointer_type
),
1511 (!in_attr
&& out_attr
) ? "[allocated_on_stack] " : "");
1512 print_file(file
, indent
, "0x%02x, /* %s */\n", base
->type
, string_of_type(base
->type
));
1513 print_file(file
, indent
, "0x5c, /* FC_PAD */\n");
1514 *typeformat_offset
+= 4;
1515 return start_offset
;
1519 assert(is_ptr(type
));
1521 offset
= write_typeformatstring_var(file
, indent
, func
, type
->ref
, var
, typeformat_offset
);
1523 fprintf(file
, "/* %2u */\n", *typeformat_offset
);
1524 return write_pointer_only_tfs(file
, var
->attrs
, pointer_type
,
1525 !last_ptr(type
) ? 0x10 : 0,
1526 offset
, typeformat_offset
);
1529 static void clear_tfsoff(type_t
*type
)
1533 type
->typestring_offset
= 0;
1535 if (type
->kind
== TKIND_ALIAS
)
1537 else if (is_ptr(type
))
1544 LIST_FOR_EACH_ENTRY( v
, type
->fields
, var_t
, entry
)
1545 clear_tfsoff(v
->type
);
1553 static void clear_all_tfsoffs(const ifref_list_t
*ifaces
)
1555 const ifref_t
* iface
;
1560 LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
1561 if (iface
->iface
->funcs
)
1562 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
1564 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1565 clear_tfsoff(var
->type
);
1568 static size_t process_tfs(FILE *file
, const ifref_list_t
*ifaces
, int for_objects
)
1571 const ifref_t
*iface
;
1572 size_t typeformat_offset
= 2;
1574 if (ifaces
) LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
1576 if (for_objects
!= is_object(iface
->iface
->attrs
) || is_local(iface
->iface
->attrs
))
1579 if (iface
->iface
->funcs
)
1582 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
1584 if (is_local(func
->def
->attrs
)) continue;
1586 current_func
= func
;
1588 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1589 var
->type
->typestring_offset
1590 = write_typeformatstring_var(file
, 2, func
, var
->type
,
1591 var
, &typeformat_offset
);
1596 return typeformat_offset
+ 1;
1600 void write_typeformatstring(FILE *file
, const ifref_list_t
*ifaces
, int for_objects
)
1604 print_file(file
, indent
, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
1605 print_file(file
, indent
, "{\n");
1607 print_file(file
, indent
, "0,\n");
1608 print_file(file
, indent
, "{\n");
1610 print_file(file
, indent
, "NdrFcShort(0x0),\n");
1612 clear_all_tfsoffs(ifaces
);
1613 process_tfs(file
, ifaces
, for_objects
);
1615 print_file(file
, indent
, "0x0\n");
1617 print_file(file
, indent
, "}\n");
1619 print_file(file
, indent
, "};\n");
1620 print_file(file
, indent
, "\n");
1623 static unsigned int get_required_buffer_size_type(
1624 const type_t
*type
, const array_dims_t
*array
,
1625 const char *name
, unsigned int *alignment
)
1652 case RPC_FC_ERROR_STATUS_T
:
1664 case RPC_FC_BIND_PRIMITIVE
:
1668 case RPC_FC_PSTRUCT
:
1671 if (!type
->fields
) return 0;
1672 LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1674 unsigned int alignment
;
1675 size
+= get_required_buffer_size_type(
1676 field
->type
, field
->array
, field
->name
,
1683 if (is_base_type( type
->ref
->type
) || type
->ref
->type
== RPC_FC_STRUCT
)
1684 size
= get_required_buffer_size_type( type
->ref
, NULL
, name
, alignment
);
1688 error("get_required_buffer_size: Unknown/unsupported type: %s (0x%02x)\n", name
, type
->type
);
1691 if (array
) size
*= get_array_size( array
);
1696 static unsigned int get_required_buffer_size(const var_t
*var
, unsigned int *alignment
, enum pass pass
)
1698 expr_list_t
*size_is
= get_attrp(var
->attrs
, ATTR_SIZEIS
);
1699 int has_size
= is_non_void(size_is
);
1700 int in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1701 int out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1703 if (!in_attr
&& !out_attr
)
1708 if (pass
== PASS_OUT
)
1710 if (out_attr
&& is_ptr(var
->type
))
1712 type_t
*type
= var
->type
;
1714 if (type
->type
== RPC_FC_STRUCT
)
1717 unsigned int size
= 36;
1719 if (!type
->fields
) return size
;
1720 LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1723 size
+= get_required_buffer_size_type(
1724 field
->type
, field
->array
, field
->name
,
1734 if ((!out_attr
|| in_attr
) && !has_size
&& !is_attr(var
->attrs
, ATTR_STRING
) && !var
->array
)
1736 if (is_ptr(var
->type
))
1738 type_t
*type
= var
->type
;
1740 if (is_base_type(type
->type
))
1744 else if (type
->type
== RPC_FC_STRUCT
)
1746 unsigned int size
= 36;
1749 if (!type
->fields
) return size
;
1750 LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1753 size
+= get_required_buffer_size_type(
1754 field
->type
, field
->array
, field
->name
,
1762 return get_required_buffer_size_type(var
->type
, var
->array
, var
->name
, alignment
);
1766 static unsigned int get_function_buffer_size( const func_t
*func
, enum pass pass
)
1769 unsigned int total_size
= 0, alignment
;
1773 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1775 total_size
+= get_required_buffer_size(var
, &alignment
, pass
);
1776 total_size
+= alignment
;
1780 if (pass
== PASS_OUT
&& !is_void(func
->def
->type
))
1782 total_size
+= get_required_buffer_size(func
->def
, &alignment
, PASS_RETURN
);
1783 total_size
+= alignment
;
1788 static void print_phase_function(FILE *file
, int indent
, const char *type
,
1789 enum remoting_phase phase
,
1790 const char *varname
, unsigned int type_offset
)
1792 const char *function
;
1795 case PHASE_BUFFERSIZE
:
1796 function
= "BufferSize";
1799 function
= "Marshall";
1801 case PHASE_UNMARSHAL
:
1802 function
= "Unmarshall";
1812 print_file(file
, indent
, "Ndr%s%s(\n", type
, function
);
1814 print_file(file
, indent
, "&_StubMsg,\n");
1815 print_file(file
, indent
, "%s%s,\n",
1816 (phase
== PHASE_UNMARSHAL
) ? "(unsigned char **)&" : "(unsigned char *)",
1818 print_file(file
, indent
, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]%s\n",
1819 type_offset
, (phase
== PHASE_UNMARSHAL
) ? "," : ");");
1820 if (phase
== PHASE_UNMARSHAL
)
1821 print_file(file
, indent
, "0);\n");
1825 void print_phase_basetype(FILE *file
, int indent
, enum remoting_phase phase
,
1826 enum pass pass
, const var_t
*var
,
1827 const char *varname
)
1829 type_t
*type
= var
->type
;
1831 unsigned int alignment
= 0;
1832 unsigned char rtype
;
1834 /* no work to do for other phases, buffer sizing is done elsewhere */
1835 if (phase
!= PHASE_MARSHAL
&& phase
!= PHASE_UNMARSHAL
)
1838 rtype
= is_ptr(type
) ? type
->ref
->type
: type
->type
;
1860 case RPC_FC_ERROR_STATUS_T
:
1872 case RPC_FC_BIND_PRIMITIVE
:
1873 /* no marshalling needed */
1877 error("print_phase_basetype: Unsupported type: %s (0x%02x, ptr_level: 0)\n", var
->name
, rtype
);
1881 print_file(file
, indent
, "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + %u) & ~0x%x);\n",
1882 alignment
- 1, alignment
- 1);
1884 if (phase
== PHASE_MARSHAL
)
1886 print_file(file
, indent
, "*(");
1887 write_type(file
, is_ptr(type
) ? type
->ref
: type
);
1889 fprintf(file
, " *)_StubMsg.Buffer = *");
1891 fprintf(file
, " *)_StubMsg.Buffer = ");
1892 fprintf(file
, varname
);
1893 fprintf(file
, ";\n");
1895 else if (phase
== PHASE_UNMARSHAL
)
1897 if (pass
== PASS_IN
|| pass
== PASS_RETURN
)
1898 print_file(file
, indent
, "");
1900 print_file(file
, indent
, "*");
1901 fprintf(file
, varname
);
1902 if (pass
== PASS_IN
&& is_ptr(type
))
1903 fprintf(file
, " = (");
1905 fprintf(file
, " = *(");
1906 write_type(file
, is_ptr(type
) ? type
->ref
: type
);
1907 fprintf(file
, " *)_StubMsg.Buffer;\n");
1910 print_file(file
, indent
, "_StubMsg.Buffer += sizeof(");
1911 write_type(file
, var
->type
);
1912 fprintf(file
, ");\n");
1915 /* returns whether the MaxCount, Offset or ActualCount members need to be
1916 * filled in for the specified phase */
1917 static inline int is_size_needed_for_phase(enum remoting_phase phase
)
1919 return (phase
!= PHASE_UNMARSHAL
);
1922 void write_remoting_arguments(FILE *file
, int indent
, const func_t
*func
,
1923 enum pass pass
, enum remoting_phase phase
)
1925 const expr_list_t
*length_is
;
1926 const expr_list_t
*size_is
;
1927 int in_attr
, out_attr
, has_length
, has_size
, pointer_type
;
1933 if (phase
== PHASE_BUFFERSIZE
)
1935 unsigned int size
= get_function_buffer_size( func
, pass
);
1936 print_file(file
, indent
, "_StubMsg.BufferLength = %u;\n", size
);
1939 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1941 const type_t
*type
= var
->type
;
1942 unsigned char rtype
;
1943 size_t start_offset
= type
->typestring_offset
;
1945 length_is
= get_attrp(var
->attrs
, ATTR_LENGTHIS
);
1946 size_is
= get_attrp(var
->attrs
, ATTR_SIZEIS
);
1947 has_length
= is_non_void(length_is
);
1948 has_size
= is_non_void(size_is
) || (var
->array
&& is_conformant_array(var
->array
));
1950 pointer_type
= get_attrv(var
->attrs
, ATTR_POINTERTYPE
);
1952 pointer_type
= RPC_FC_RP
;
1954 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1955 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1956 if (!in_attr
&& !out_attr
)
1962 if (!in_attr
) continue;
1965 if (!out_attr
) continue;
1973 if (is_user_derived( var
))
1975 print_phase_function(file
, indent
, "UserMarshal", phase
, var
->name
, start_offset
);
1977 else if (is_string_type(var
->attrs
, var
->type
, var
->array
))
1979 if (var
->array
&& !is_conformant_array(var
->array
))
1980 print_phase_function(file
, indent
, "NonConformantString", phase
, var
->name
, start_offset
);
1983 if (size_is
&& is_size_needed_for_phase(phase
))
1985 const expr_t
*size
= LIST_ENTRY( list_head(size_is
), const expr_t
, entry
);
1986 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
1987 write_expr(file
, size
, 1);
1988 fprintf(file
, ";\n");
1991 if ((phase
== PHASE_FREE
) || (pointer_type
== RPC_FC_UP
))
1992 print_phase_function(file
, indent
, "Pointer", phase
, var
->name
, start_offset
);
1994 print_phase_function(file
, indent
, "ConformantString", phase
, var
->name
,
1995 start_offset
+ (has_size
? 4 : 2));
1998 else if (is_array_type(var
->attrs
, var
->type
, var
->array
))
2000 const char *array_type
;
2002 if (var
->array
&& list_count(var
->array
) > 1) /* multi-dimensional array */
2003 array_type
= "ComplexArray";
2006 if (!has_length
&& !has_size
)
2007 array_type
= "FixedArray";
2008 else if (has_length
&& !has_size
)
2010 if (is_size_needed_for_phase(phase
))
2012 const expr_t
*length
= LIST_ENTRY( list_head(length_is
), const expr_t
, entry
);
2013 print_file(file
, indent
, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
2014 print_file(file
, indent
, "_StubMsg.ActualCount = (unsigned long)");
2015 write_expr(file
, length
, 1);
2016 fprintf(file
, ";\n\n");
2018 array_type
= "VaryingArray";
2020 else if (!has_length
&& has_size
)
2022 if (is_size_needed_for_phase(phase
) && phase
!= PHASE_FREE
)
2024 const expr_t
*size
= LIST_ENTRY( list_head(size_is
? size_is
: var
->array
),
2025 const expr_t
, entry
);
2026 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
2027 write_expr(file
, size
, 1);
2028 fprintf(file
, ";\n\n");
2030 array_type
= "ConformantArray";
2034 if (is_size_needed_for_phase(phase
))
2036 const expr_t
*length
= LIST_ENTRY( list_head(length_is
), const expr_t
, entry
);
2037 const expr_t
*size
= LIST_ENTRY( list_head(size_is
? size_is
: var
->array
),
2038 const expr_t
, entry
);
2039 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
2040 write_expr(file
, size
, 1);
2041 fprintf(file
, ";\n");
2042 print_file(file
, indent
, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
2043 print_file(file
, indent
, "_StubMsg.ActualCount = (unsigned long)");
2044 write_expr(file
, length
, 1);
2045 fprintf(file
, ";\n\n");
2047 array_type
= "ConformantVaryingArray";
2051 if (!in_attr
&& phase
== PHASE_FREE
)
2053 print_file(file
, indent
, "if (%s)\n", var
->name
);
2055 print_file(file
, indent
, "_StubMsg.pfnFree(%s);\n", var
->name
);
2057 else if (phase
!= PHASE_FREE
)
2059 if (pointer_type
== RPC_FC_UP
)
2060 print_phase_function(file
, indent
, "Pointer", phase
, var
->name
, start_offset
);
2062 print_phase_function(file
, indent
, array_type
, phase
, var
->name
, start_offset
);
2065 else if (!is_ptr(var
->type
) && is_base_type(rtype
))
2067 print_phase_basetype(file
, indent
, phase
, pass
, var
, var
->name
);
2069 else if (!is_ptr(var
->type
))
2074 case RPC_FC_PSTRUCT
:
2075 print_phase_function(file
, indent
, "SimpleStruct", phase
, var
->name
, start_offset
);
2077 case RPC_FC_CSTRUCT
:
2078 case RPC_FC_CPSTRUCT
:
2079 print_phase_function(file
, indent
, "ConformantStruct", phase
, var
->name
, start_offset
);
2081 case RPC_FC_CVSTRUCT
:
2082 print_phase_function(file
, indent
, "ConformantVaryingStruct", phase
, var
->name
, start_offset
);
2084 case RPC_FC_BOGUS_STRUCT
:
2085 print_phase_function(file
, indent
, "ComplexStruct", phase
, var
->name
, start_offset
);
2088 if (is_base_type( var
->type
->ref
->type
))
2090 print_phase_basetype(file
, indent
, phase
, pass
, var
, var
->name
);
2092 else if (var
->type
->ref
->type
== RPC_FC_STRUCT
)
2094 if (phase
!= PHASE_BUFFERSIZE
&& phase
!= PHASE_FREE
)
2095 print_phase_function(file
, indent
, "SimpleStruct", phase
, var
->name
, start_offset
+ 4);
2100 if ((iid
= get_attrp( var
->attrs
, ATTR_IIDIS
)))
2101 print_file( file
, indent
, "_StubMsg.MaxCount = (unsigned long)%s;\n", iid
->name
);
2102 print_phase_function(file
, indent
, "Pointer", phase
, var
->name
, start_offset
);
2106 error("write_remoting_arguments: Unsupported type: %s (0x%02x)\n", var
->name
, rtype
);
2111 if (last_ptr(var
->type
) && (pointer_type
== RPC_FC_RP
) && is_base_type(rtype
))
2113 print_phase_basetype(file
, indent
, phase
, pass
, var
, var
->name
);
2115 else if (last_ptr(var
->type
) && (pointer_type
== RPC_FC_RP
) && (rtype
== RPC_FC_STRUCT
))
2117 if (phase
!= PHASE_BUFFERSIZE
&& phase
!= PHASE_FREE
)
2118 print_phase_function(file
, indent
, "SimpleStruct", phase
, var
->name
, start_offset
+ 4);
2123 if ((iid
= get_attrp( var
->attrs
, ATTR_IIDIS
)))
2124 print_file( file
, indent
, "_StubMsg.MaxCount = (unsigned long)%s;\n", iid
->name
);
2125 print_phase_function(file
, indent
, "Pointer", phase
, var
->name
, start_offset
);
2128 fprintf(file
, "\n");
2133 size_t get_size_procformatstring_var(const var_t
*var
)
2135 return write_procformatstring_var(NULL
, 0, var
, FALSE
);
2139 size_t get_size_procformatstring_func(const func_t
*func
)
2144 /* argument list size */
2146 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2147 size
+= get_size_procformatstring_var(var
);
2149 /* return value size */
2150 if (is_void(func
->def
->type
))
2151 size
+= 2; /* FC_END and FC_PAD */
2153 size
+= get_size_procformatstring_var(func
->def
);
2158 size_t get_size_procformatstring(const ifref_list_t
*ifaces
, int for_objects
)
2160 const ifref_t
*iface
;
2164 if (ifaces
) LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
2166 if (for_objects
!= is_object(iface
->iface
->attrs
) || is_local(iface
->iface
->attrs
))
2169 if (iface
->iface
->funcs
)
2170 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
2171 if (!is_local(func
->def
->attrs
))
2172 size
+= get_size_procformatstring_func( func
);
2177 size_t get_size_typeformatstring(const ifref_list_t
*ifaces
, int for_objects
)
2179 return process_tfs(NULL
, ifaces
, for_objects
);
2182 static void write_struct_expr(FILE *h
, const expr_t
*e
, int brackets
,
2183 const var_list_t
*fields
, const char *structvar
)
2189 fprintf(h
, "%lu", e
->u
.lval
);
2192 fprintf(h
, "0x%lx", e
->u
.lval
);
2194 case EXPR_TRUEFALSE
:
2196 fprintf(h
, "FALSE");
2200 case EXPR_IDENTIFIER
:
2203 LIST_FOR_EACH_ENTRY( field
, fields
, const var_t
, entry
)
2204 if (!strcmp(e
->u
.sval
, field
->name
))
2206 fprintf(h
, "%s->%s", structvar
, e
->u
.sval
);
2210 if (&field
->entry
== fields
) error("no field found for identifier %s\n", e
->u
.sval
);
2215 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2219 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2223 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2227 write_type(h
, e
->u
.tref
);
2229 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2232 fprintf(h
, "sizeof(");
2233 write_type(h
, e
->u
.tref
);
2244 if (brackets
) fprintf(h
, "(");
2245 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2247 case EXPR_SHL
: fprintf(h
, " << "); break;
2248 case EXPR_SHR
: fprintf(h
, " >> "); break;
2249 case EXPR_MUL
: fprintf(h
, " * "); break;
2250 case EXPR_DIV
: fprintf(h
, " / "); break;
2251 case EXPR_ADD
: fprintf(h
, " + "); break;
2252 case EXPR_SUB
: fprintf(h
, " - "); break;
2253 case EXPR_AND
: fprintf(h
, " & "); break;
2254 case EXPR_OR
: fprintf(h
, " | "); break;
2257 write_struct_expr(h
, e
->u
.ext
, 1, fields
, structvar
);
2258 if (brackets
) fprintf(h
, ")");
2261 if (brackets
) fprintf(h
, "(");
2262 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2264 write_struct_expr(h
, e
->u
.ext
, 1, fields
, structvar
);
2266 write_struct_expr(h
, e
->ext2
, 1, fields
, structvar
);
2267 if (brackets
) fprintf(h
, ")");
2273 void declare_stub_args( FILE *file
, int indent
, const func_t
*func
)
2275 int in_attr
, out_attr
;
2277 const var_t
*def
= func
->def
;
2280 /* declare return value '_RetVal' */
2281 if (!is_void(def
->type
))
2283 print_file(file
, indent
, "");
2284 write_type(file
, def
->type
);
2285 fprintf(file
, " _RetVal;\n");
2291 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2293 const expr_list_t
*size_is
= get_attrp(var
->attrs
, ATTR_SIZEIS
);
2294 int has_size
= is_non_void(size_is
);
2295 int is_string
= is_attr(var
->attrs
, ATTR_STRING
);
2297 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
2298 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
2299 if (!out_attr
&& !in_attr
)
2302 if (!in_attr
&& !has_size
&& !is_string
)
2304 print_file(file
, indent
, "");
2305 write_type(file
, var
->type
->ref
);
2306 fprintf(file
, " _W%u;\n", i
++);
2309 print_file(file
, indent
, "");
2310 write_type(file
, var
->type
);
2313 fprintf(file
, "( *");
2314 write_name(file
, var
);
2315 fprintf(file
, " )");
2317 write_name(file
, var
);
2318 write_array(file
, var
->array
, 0);
2319 fprintf(file
, ";\n");
2324 void assign_stub_out_args( FILE *file
, int indent
, const func_t
*func
)
2326 int in_attr
, out_attr
;
2329 const expr_list_t
*size_is
;
2335 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2337 int is_string
= is_attr(var
->attrs
, ATTR_STRING
);
2338 size_is
= get_attrp(var
->attrs
, ATTR_SIZEIS
);
2339 has_size
= is_non_void(size_is
);
2340 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
2341 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
2342 if (!out_attr
&& !in_attr
)
2347 print_file(file
, indent
, "");
2348 write_name(file
, var
);
2353 unsigned int size
, align
= 0;
2354 type_t
*type
= var
->type
;
2356 fprintf(file
, " = NdrAllocate(&_StubMsg, ");
2357 LIST_FOR_EACH_ENTRY( expr
, size_is
, const expr_t
, entry
)
2359 if (expr
->type
== EXPR_VOID
) continue;
2360 write_expr( file
, expr
, 1 );
2361 fprintf(file
, " * ");
2363 size
= type_memsize(type
, NULL
, &align
);
2364 fprintf(file
, "%u);\n", size
);
2366 else if (!is_string
)
2368 fprintf(file
, " = &_W%u;\n", i
);
2369 if (is_ptr(var
->type
) && !last_ptr(var
->type
))
2370 print_file(file
, indent
, "_W%u = 0;\n", i
);
2378 fprintf(file
, "\n");
2382 int write_expr_eval_routines(FILE *file
, const char *iface
)
2385 struct expr_eval_routine
*eval
;
2386 unsigned short callback_offset
= 0;
2388 LIST_FOR_EACH_ENTRY(eval
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
2392 print_file(file
, indent
, "static void __RPC_USER %s_%sExprEval_%04u(PMIDL_STUB_MESSAGE pStubMsg)\n",
2393 iface
, eval
->structure
->name
, callback_offset
);
2394 print_file(file
, indent
, "{\n");
2396 print_file(file
, indent
, "struct %s *" STRUCT_EXPR_EVAL_VAR
" = (struct %s *)(pStubMsg->StackTop - %u);\n",
2397 eval
->structure
->name
, eval
->structure
->name
, eval
->structure_size
);
2398 fprintf(file
, "\n");
2399 print_file(file
, indent
, "pStubMsg->Offset = 0;\n"); /* FIXME */
2400 print_file(file
, indent
, "pStubMsg->MaxCount = (unsigned long)");
2401 write_struct_expr(file
, eval
->expr
, 1, eval
->structure
->fields
, STRUCT_EXPR_EVAL_VAR
);
2402 fprintf(file
, ";\n");
2404 print_file(file
, indent
, "}\n\n");
2410 void write_expr_eval_routine_list(FILE *file
, const char *iface
)
2412 struct expr_eval_routine
*eval
;
2413 struct expr_eval_routine
*cursor
;
2414 unsigned short callback_offset
= 0;
2416 fprintf(file
, "static const EXPR_EVAL ExprEvalRoutines[] =\n");
2417 fprintf(file
, "{\n");
2419 LIST_FOR_EACH_ENTRY_SAFE(eval
, cursor
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
2421 print_file(file
, 1, "%s_%sExprEval_%04u,\n",
2422 iface
, eval
->structure
->name
, callback_offset
);
2425 list_remove(&eval
->entry
);
2429 fprintf(file
, "};\n\n");
2433 void write_endpoints( FILE *f
, const char *prefix
, const str_list_t
*list
)
2435 const struct str_list_entry_t
*endpoint
;
2438 /* this should be an array of RPC_PROTSEQ_ENDPOINT but we want const strings */
2439 print_file( f
, 0, "static const unsigned char * %s__RpcProtseqEndpoint[][2] =\n{\n", prefix
);
2440 LIST_FOR_EACH_ENTRY( endpoint
, list
, const struct str_list_entry_t
, entry
)
2442 print_file( f
, 1, "{ (const unsigned char *)\"" );
2443 for (p
= endpoint
->str
; *p
&& *p
!= ':'; p
++)
2445 if (*p
== '"' || *p
== '\\') fputc( '\\', f
);
2448 if (!*p
) goto error
;
2449 if (p
[1] != '[') goto error
;
2451 fprintf( f
, "\", (const unsigned char *)\"" );
2452 for (p
+= 2; *p
&& *p
!= ']'; p
++)
2454 if (*p
== '"' || *p
== '\\') fputc( '\\', f
);
2457 if (*p
!= ']') goto error
;
2458 fprintf( f
, "\" },\n" );
2460 print_file( f
, 0, "};\n\n" );
2464 error("Invalid endpoint syntax '%s'\n", endpoint
->str
);