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";
90 case RPC_FC_BIND_PRIMITIVE
: return "FC_BIND_PRIMITIVE";
92 error("string_of_type: unknown type 0x%02x\n", type
);
97 static int is_struct(unsigned char type
)
104 case RPC_FC_CPSTRUCT
:
105 case RPC_FC_CVSTRUCT
:
106 case RPC_FC_BOGUS_STRUCT
:
113 static int compare_expr(const expr_t
*a
, const expr_t
*b
)
117 if (a
->type
!= b
->type
)
118 return a
->type
- b
->type
;
125 return a
->u
.lval
- b
->u
.lval
;
126 case EXPR_IDENTIFIER
:
127 return strcmp(a
->u
.sval
, b
->u
.sval
);
129 ret
= compare_expr(a
->ref
, b
->ref
);
132 ret
= compare_expr(a
->u
.ext
, b
->u
.ext
);
135 return compare_expr(a
->ext2
, b
->ext2
);
144 ret
= compare_expr(a
->ref
, b
->ref
);
147 return compare_expr(a
->u
.ext
, b
->u
.ext
);
153 return compare_expr(a
->ref
, b
->ref
);
160 #define WRITE_FCTYPE(file, fctype, typestring_offset) \
163 fprintf(file, "/* %2u */\n", typestring_offset); \
164 print_file((file), 2, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
168 static int print_file(FILE *file
, int indent
, const char *format
, ...)
175 va_start(va
, format
);
176 for (i
= 0; i
< indent
; i
++)
178 r
= vfprintf(file
, format
, va
);
183 static void write_formatdesc(FILE *f
, int indent
, const char *str
)
185 print_file(f
, indent
, "typedef struct _MIDL_%s_FORMAT_STRING\n", str
);
186 print_file(f
, indent
, "{\n");
187 print_file(f
, indent
+ 1, "short Pad;\n");
188 print_file(f
, indent
+ 1, "unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str
);
189 print_file(f
, indent
, "} MIDL_%s_FORMAT_STRING;\n", str
);
190 print_file(f
, indent
, "\n");
193 void write_formatstringsdecl(FILE *f
, int indent
, ifref_list_t
*ifaces
, int for_objects
)
195 print_file(f
, indent
, "#define TYPE_FORMAT_STRING_SIZE %d\n",
196 get_size_typeformatstring(ifaces
, for_objects
));
198 print_file(f
, indent
, "#define PROC_FORMAT_STRING_SIZE %d\n",
199 get_size_procformatstring(ifaces
, for_objects
));
202 write_formatdesc(f
, indent
, "TYPE");
203 write_formatdesc(f
, indent
, "PROC");
205 print_file(f
, indent
, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
206 print_file(f
, indent
, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
207 print_file(f
, indent
, "\n");
210 static int is_user_derived(const var_t
*v
)
212 const type_t
*type
= v
->type
;
214 if (v
->attrs
&& is_attr( v
->attrs
, ATTR_WIREMARSHAL
)) return 1;
218 if (type
->attrs
&& is_attr( type
->attrs
, ATTR_WIREMARSHAL
)) return 1;
224 static inline int is_base_type(unsigned char type
)
243 case RPC_FC_ERROR_STATUS_T
:
244 case RPC_FC_BIND_PRIMITIVE
:
252 static size_t write_procformatstring_var(FILE *file
, int indent
,
253 const var_t
*var
, int is_return
)
256 const type_t
*type
= var
->type
;
258 int is_in
= is_attr(var
->attrs
, ATTR_IN
);
259 int is_out
= is_attr(var
->attrs
, ATTR_OUT
);
261 if (!is_in
&& !is_out
) is_in
= TRUE
;
263 if (!var
->array
&& is_base_type(type
->type
))
266 print_file(file
, indent
, "0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
268 print_file(file
, indent
, "0x4e, /* FC_IN_PARAM_BASETYPE */\n");
270 if (is_base_type(type
->type
))
272 print_file(file
, indent
, "0x%02x, /* %s */\n", type
->type
, string_of_type(type
->type
));
273 size
= 2; /* includes param type prefix */
275 else if (type
->type
== RPC_FC_BIND_PRIMITIVE
)
277 print_file(file
, indent
, "0x%02x, /* FC_IGNORE */\n", RPC_FC_IGNORE
);
278 size
= 2; /* includes param type prefix */
282 error("Unknown/unsupported type: %s (0x%02x)\n", var
->name
, type
->type
);
289 print_file(file
, indent
, "0x52, /* FC_RETURN_PARAM */\n");
290 else if (is_in
&& is_out
)
291 print_file(file
, indent
, "0x50, /* FC_IN_OUT_PARAM */\n");
293 print_file(file
, indent
, "0x51, /* FC_OUT_PARAM */\n");
295 print_file(file
, indent
, "0x4d, /* FC_IN_PARAM */\n");
297 print_file(file
, indent
, "0x01,\n");
298 print_file(file
, indent
, "NdrFcShort(0x%x),\n", type
->typestring_offset
);
299 size
= 4; /* includes param type prefix */
304 void write_procformatstring(FILE *file
, const ifref_list_t
*ifaces
, int for_objects
)
306 const ifref_t
*iface
;
310 print_file(file
, indent
, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
311 print_file(file
, indent
, "{\n");
313 print_file(file
, indent
, "0,\n");
314 print_file(file
, indent
, "{\n");
317 if (ifaces
) LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
319 if (for_objects
!= is_object(iface
->iface
->attrs
) || is_local(iface
->iface
->attrs
))
322 if (iface
->iface
->funcs
)
325 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
327 if (is_local(func
->def
->attrs
)) continue;
328 /* emit argument data */
331 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
332 write_procformatstring_var(file
, indent
, var
, FALSE
);
335 /* emit return value data */
337 if (is_void(var
->type
))
339 print_file(file
, indent
, "0x5b, /* FC_END */\n");
340 print_file(file
, indent
, "0x5c, /* FC_PAD */\n");
343 write_procformatstring_var(file
, indent
, var
, TRUE
);
348 print_file(file
, indent
, "0x0\n");
350 print_file(file
, indent
, "}\n");
352 print_file(file
, indent
, "};\n");
353 print_file(file
, indent
, "\n");
356 static int write_base_type(FILE *file
, const type_t
*type
, unsigned int *typestring_offset
)
358 if (is_base_type(type
->type
))
360 print_file(file
, 2, "0x%02x,\t/* %s */\n", type
->type
, string_of_type(type
->type
));
361 *typestring_offset
+= 1;
368 /* write conformance / variance descriptor */
369 static size_t write_conf_or_var_desc(FILE *file
, const func_t
*func
, const type_t
*structure
, const expr_list_t
*expr_list
)
371 unsigned char operator_type
= 0;
372 const char *operator_string
= "no operators";
373 const expr_t
*expr
, *subexpr
;
374 unsigned char correlation_type
;
376 if (!file
) return 4; /* optimisation for sizing pass */
378 if (list_count(expr_list
) > 1)
379 error("write_conf_or_var_desc: multi-dimensional arrays not supported yet\n");
381 expr
= subexpr
= LIST_ENTRY( list_head(expr_list
), const expr_t
, entry
);
385 if (expr
->cval
> UCHAR_MAX
* (USHRT_MAX
+ 1) + USHRT_MAX
)
386 error("write_conf_or_var_desc: constant value %ld is greater than "
387 "the maximum constant size of %d\n", expr
->cval
,
388 UCHAR_MAX
* (USHRT_MAX
+ 1) + USHRT_MAX
);
390 print_file(file
, 2, "0x%x, /* Corr desc: constant, val = %ld */\n",
391 RPC_FC_CONSTANT_CONFORMANCE
, expr
->cval
);
392 print_file(file
, 2, "0x%x,\n", expr
->cval
& ~USHRT_MAX
);
393 print_file(file
, 2, "NdrFcShort(0x%x),\n", expr
->cval
& USHRT_MAX
);
398 switch (subexpr
->type
)
401 subexpr
= subexpr
->ref
;
402 operator_type
= RPC_FC_DEREFERENCE
;
403 operator_string
= "FC_DEREFERENCE";
406 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 2))
408 subexpr
= subexpr
->ref
;
409 operator_type
= RPC_FC_DIV_2
;
410 operator_string
= "FC_DIV_2";
414 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 2))
416 subexpr
= subexpr
->ref
;
417 operator_type
= RPC_FC_MULT_2
;
418 operator_string
= "FC_MULT_2";
422 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 1))
424 subexpr
= subexpr
->ref
;
425 operator_type
= RPC_FC_SUB_1
;
426 operator_string
= "FC_SUB_1";
430 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 1))
432 subexpr
= subexpr
->ref
;
433 operator_type
= RPC_FC_ADD_1
;
434 operator_string
= "FC_ADD_1";
441 if (subexpr
->type
== EXPR_IDENTIFIER
)
443 const type_t
*correlation_variable
= NULL
;
444 unsigned char correlation_variable_type
;
445 unsigned char param_type
= 0;
446 const char *param_type_string
= NULL
;
454 if (structure
->fields
) LIST_FOR_EACH_ENTRY( var
, structure
->fields
, const var_t
, entry
)
456 unsigned int align
= 0;
457 offset
-= type_memsize(var
->type
, var
->array
, &align
);
458 /* FIXME: take alignment into account */
459 if (!strcmp(var
->name
, subexpr
->u
.sval
))
461 correlation_variable
= var
->type
;
465 if (!correlation_variable
)
466 error("write_conf_or_var_desc: couldn't find variable %s in structure\n",
469 correlation_type
= RPC_FC_NORMAL_CONFORMANCE
;
475 offset
= sizeof(void *);
476 if (func
->args
) LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
478 if (!strcmp(var
->name
, subexpr
->u
.sval
))
480 correlation_variable
= var
->type
;
483 /* FIXME: not all stack variables are sizeof(void *) */
484 offset
+= sizeof(void *);
486 if (!correlation_variable
)
487 error("write_conf_or_var_desc: couldn't find variable %s in function\n",
490 correlation_type
= RPC_FC_TOP_LEVEL_CONFORMANCE
;
493 correlation_variable_type
= correlation_variable
->type
;
495 switch (correlation_variable_type
)
499 param_type
= RPC_FC_SMALL
;
500 param_type_string
= "FC_SMALL";
504 param_type
= RPC_FC_USMALL
;
505 param_type_string
= "FC_USMALL";
509 param_type
= RPC_FC_SHORT
;
510 param_type_string
= "FC_SHORT";
513 param_type
= RPC_FC_USHORT
;
514 param_type_string
= "FC_USHORT";
517 param_type
= RPC_FC_LONG
;
518 param_type_string
= "FC_LONG";
521 param_type
= RPC_FC_ULONG
;
522 param_type_string
= "FC_ULONG";
528 if (sizeof(void *) == 4) /* FIXME */
530 param_type
= RPC_FC_LONG
;
531 param_type_string
= "FC_LONG";
535 param_type
= RPC_FC_HYPER
;
536 param_type_string
= "FC_HYPER";
540 error("write_conf_or_var_desc: conformance variable type not supported 0x%x\n",
541 correlation_variable_type
);
544 print_file(file
, 2, "0x%x, /* Corr desc: %s%s */\n",
545 correlation_type
| param_type
,
546 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "parameter, " : "",
548 print_file(file
, 2, "0x%x, /* %s */\n", operator_type
, operator_string
);
549 print_file(file
, 2, "NdrFcShort(0x%x), /* %soffset = %d */\n",
551 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "x86 stack size / " : "",
556 unsigned int callback_offset
= 0;
560 struct expr_eval_routine
*eval
;
563 LIST_FOR_EACH_ENTRY(eval
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
565 if (!strcmp(eval
->structure
->name
, structure
->name
) &&
566 !compare_expr(eval
->expr
, expr
))
576 unsigned int align
= 0;
577 eval
= xmalloc(sizeof(*eval
));
578 eval
->structure
= structure
;
579 eval
->structure_size
= fields_memsize(structure
->fields
, &align
);
581 list_add_tail(&expr_eval_routines
, &eval
->entry
);
584 correlation_type
= RPC_FC_NORMAL_CONFORMANCE
;
588 error("write_conf_or_var_desc: top-level callback conformance unimplemented\n");
589 correlation_type
= RPC_FC_TOP_LEVEL_CONFORMANCE
;
592 if (callback_offset
> USHRT_MAX
)
593 error("Maximum number of callback routines reached\n");
595 print_file(file
, 2, "0x%x, /* Corr desc: %s */\n",
597 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "parameter" : "");
598 print_file(file
, 2, "0x%x, /* %s */\n", RPC_FC_CALLBACK
, "FC_CALLBACK");
599 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", callback_offset
, callback_offset
);
604 static size_t fields_memsize(const var_list_t
*fields
, unsigned int *align
)
609 if (!fields
) return 0;
610 LIST_FOR_EACH_ENTRY( v
, fields
, const var_t
, entry
)
611 size
+= type_memsize(v
->type
, v
->array
, align
);
616 static size_t get_array_size( const array_dims_t
*array
)
621 if (!array
) return 0;
623 LIST_FOR_EACH_ENTRY( dim
, array
, expr_t
, entry
)
625 if (!dim
->is_const
) return 0;
632 static size_t type_memsize(const type_t
*t
, const array_dims_t
*array
, unsigned int *align
)
638 size
= sizeof(void *);
639 if (size
> *align
) *align
= size
;
641 else switch (t
->type
)
648 if (size
> *align
) *align
= size
;
655 if (size
> *align
) *align
= size
;
659 case RPC_FC_ERROR_STATUS_T
:
663 if (size
> *align
) *align
= size
;
668 if (size
> *align
) *align
= size
;
671 case RPC_FC_CVSTRUCT
:
672 case RPC_FC_CPSTRUCT
:
675 case RPC_FC_BOGUS_STRUCT
:
676 case RPC_FC_ENCAPSULATED_UNION
:
677 case RPC_FC_NON_ENCAPSULATED_UNION
:
678 size
= fields_memsize(t
->fields
, align
);
681 error("type_memsize: Unknown type %d\n", t
->type
);
685 if (array
) size
*= get_array_size( array
);
689 static size_t write_nonsimple_pointer(FILE *file
, const type_t
*type
, size_t offset
)
691 short absoff
= type
->ref
->typestring_offset
;
692 short reloff
= absoff
- (offset
+ 2);
693 int ptr_attr
= is_ptr(type
->ref
) ? 0x10 : 0x0;
695 print_file(file
, 2, "0x%02x, 0x%x,\t/* %s */\n",
696 type
->type
, ptr_attr
, string_of_type(type
->type
));
697 print_file(file
, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%hd) */\n",
698 reloff
, reloff
, absoff
);
702 static size_t write_simple_pointer(FILE *file
, const type_t
*type
)
704 print_file(file
, 2, "0x%02x, 0x8,\t/* %s [simple_pointer] */\n",
705 type
->type
, string_of_type(type
->type
));
706 print_file(file
, 2, "0x%02x,\t/* %s */\n", type
->ref
->type
,
707 string_of_type(type
->ref
->type
));
708 print_file(file
, 2, "0x5c,\t/* FC_PAD */\n");
712 static size_t write_pointer_tfs(FILE *file
, type_t
*type
, size_t *typestring_offset
)
714 size_t offset
= *typestring_offset
;
716 print_file(file
, 0, "/* %d */\n", offset
);
717 type
->typestring_offset
= offset
;
719 if (type
->ref
->typestring_offset
)
720 *typestring_offset
+= write_nonsimple_pointer(file
, type
, offset
);
721 else if (is_base_type(type
->ref
->type
))
722 *typestring_offset
+= write_simple_pointer(file
, type
);
727 static int has_known_tfs(const type_t
*type
)
729 return type
->typestring_offset
|| is_base_type(type
->type
);
732 static int write_pointers(FILE *file
, const attr_list_t
*attrs
,
733 type_t
*type
, const char *name
,
734 const array_dims_t
*array
, int level
,
735 unsigned int *typestring_offset
)
739 /* don't generate a pointer for first-level arrays since we want to
740 * descend into them to write their pointers, not stop here */
741 if ((level
== 0 || !is_ptr(type
)) && is_array_type(attrs
, type
, array
))
743 return write_pointers(file
, NULL
, type
, name
, NULL
, level
+ 1, typestring_offset
);
745 else if (is_ptr(type
))
747 type_t
*ref
= type
->ref
;
749 if (!has_known_tfs(ref
))
753 write_pointers(file
, attrs
, ref
, name
, array
, level
+ 1,
756 else if (is_struct(ref
->type
))
758 write_struct_tfs(file
, ref
, name
, typestring_offset
);
762 error("write_pointers: type format string unknown for %s (0x%02x)\n",
767 /* top-level pointers are handled by write_pointer_description */
769 write_pointer_tfs(file
, type
, typestring_offset
);
773 else if (is_struct(type
->type
))
775 int pointers_written
= 0;
778 LIST_FOR_EACH_ENTRY( v
, type
->fields
, const var_t
, entry
)
779 pointers_written
+= write_pointers(file
, v
->attrs
, v
->type
,
784 return pointers_written
;
789 static size_t write_pointer_description(FILE *file
, const attr_list_t
*attrs
,
790 type_t
*type
, size_t mem_offset
,
791 const array_dims_t
*array
, int level
,
792 size_t *typestring_offset
)
795 unsigned int align
= 0;
797 /* don't generate a pointer for first-level arrays since we want to
798 * descend into them to write their pointers, not stop here */
799 if ((level
== 0 || !is_ptr(type
)) && is_array_type(attrs
, type
, array
))
801 write_pointer_description(file
, NULL
, type
, mem_offset
, NULL
,
802 level
+ 1, typestring_offset
);
804 else if (is_ptr(type
))
806 print_file(file
, 2, "0x46,\t/* FC_NO_REPEAT */\n");
807 print_file(file
, 2, "0x5c,\t/* FC_PAD */\n");
808 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", mem_offset
, mem_offset
);
809 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", mem_offset
, mem_offset
);
810 *typestring_offset
+= 6;
812 if (has_known_tfs(type
->ref
))
813 write_pointer_tfs(file
, type
, typestring_offset
);
815 error("write_pointer_description: type format string unknown\n");
817 else if (level
== 0 && is_struct(type
->type
))
821 LIST_FOR_EACH_ENTRY( v
, type
->fields
, const var_t
, entry
)
823 += write_pointer_description(file
, v
->attrs
, v
->type
,
824 mem_offset
, v
->array
,
830 return type_memsize(type
, array
, &align
);
833 static size_t write_string_tfs(FILE *file
, const attr_list_t
*attrs
,
834 const type_t
*type
, const array_dims_t
*array
,
835 const char *name
, unsigned int *typestring_offset
)
837 const expr_list_t
*size_is
= get_attrp(attrs
, ATTR_SIZEIS
);
838 int has_size
= is_non_void(size_is
);
839 size_t start_offset
= *typestring_offset
;
840 unsigned char flags
= 0;
846 pointer_type
= type
->type
;
850 pointer_type
= get_attrv(attrs
, ATTR_POINTERTYPE
);
853 pointer_type
= RPC_FC_RP
;
855 if (!get_attrp(attrs
, ATTR_SIZEIS
))
856 flags
|= RPC_FC_P_SIMPLEPOINTER
;
860 if ((rtype
!= RPC_FC_BYTE
) && (rtype
!= RPC_FC_CHAR
) && (rtype
!= RPC_FC_WCHAR
))
862 error("write_string_tfs: Unimplemented for type 0x%x of name: %s\n", rtype
, name
);
866 print_file(file
, 2,"0x%x, 0x%x, /* %s%s */\n",
868 pointer_type
== RPC_FC_FP
? "FC_FP" : (pointer_type
== RPC_FC_UP
? "FC_UP" : "FC_RP"),
869 (flags
& RPC_FC_P_SIMPLEPOINTER
) ? " [simple_pointer]" : "");
870 *typestring_offset
+= 2;
872 if (!(flags
& RPC_FC_P_SIMPLEPOINTER
))
874 print_file(file
, 2, "NdrFcShort(0x2),\n");
875 *typestring_offset
+= 2;
878 if (array
&& !is_conformant_array(array
))
880 /* FIXME: multi-dimensional array */
881 const expr_t
*dim
= LIST_ENTRY( list_head( array
), expr_t
, entry
);
882 if (dim
->cval
> USHRT_MAX
)
883 error("array size for parameter %s exceeds %d bytes by %ld bytes\n",
884 name
, USHRT_MAX
, dim
->cval
- USHRT_MAX
);
886 if (rtype
== RPC_FC_CHAR
)
887 WRITE_FCTYPE(file
, FC_CSTRING
, *typestring_offset
);
889 WRITE_FCTYPE(file
, FC_WSTRING
, *typestring_offset
);
890 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
891 *typestring_offset
+= 2;
893 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", dim
->cval
, dim
->cval
);
894 *typestring_offset
+= 2;
900 if (rtype
== RPC_FC_CHAR
)
901 WRITE_FCTYPE(file
, FC_C_CSTRING
, *typestring_offset
);
903 WRITE_FCTYPE(file
, FC_C_WSTRING
, *typestring_offset
);
904 print_file(file
, 2, "0x%x, /* FC_STRING_SIZED */\n", RPC_FC_STRING_SIZED
);
905 *typestring_offset
+= 2;
907 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
, NULL
, size_is
);
913 if (rtype
== RPC_FC_CHAR
)
914 WRITE_FCTYPE(file
, FC_C_CSTRING
, *typestring_offset
);
916 WRITE_FCTYPE(file
, FC_C_WSTRING
, *typestring_offset
);
917 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
918 *typestring_offset
+= 2;
924 static size_t write_array_tfs(FILE *file
, const attr_list_t
*attrs
,
925 type_t
*type
, const array_dims_t
*array
,
926 const char *name
, unsigned int *typestring_offset
)
928 const expr_list_t
*length_is
= get_attrp(attrs
, ATTR_LENGTHIS
);
929 const expr_list_t
*size_is
= get_attrp(attrs
, ATTR_SIZEIS
);
930 int has_length
= is_non_void(length_is
);
931 int has_size
= is_non_void(size_is
) || is_conformant_array(array
);
933 int pointer_type
= get_attrv(attrs
, ATTR_POINTERTYPE
);
935 pointer_type
= RPC_FC_RP
;
937 print_file(file
, 2, "0x%x, 0x00, /* %s */\n",
939 pointer_type
== RPC_FC_FP
? "FC_FP" : (pointer_type
== RPC_FC_UP
? "FC_UP" : "FC_RP"));
940 print_file(file
, 2, "NdrFcShort(0x2),\n");
941 *typestring_offset
+= 4;
943 if (array
&& list_count(array
) > 1) /* multi-dimensional array */
945 error("write_array_tfs: Multi-dimensional arrays not implemented yet (param %s)\n", name
);
950 const expr_t
*dim
= array
? LIST_ENTRY( list_head( array
), expr_t
, entry
) : NULL
;
953 if (write_pointers(file
, attrs
, type
, name
, array
, 0, typestring_offset
) > 0)
956 start_offset
= *typestring_offset
;
958 if (!has_length
&& !has_size
)
961 unsigned int align
= 0;
962 size_t size
= type_memsize(type
, array
, &align
);
963 if (size
< USHRT_MAX
)
965 WRITE_FCTYPE(file
, FC_SMFARRAY
, *typestring_offset
);
967 print_file(file
, 2, "0x%02x,\n", align
- 1);
969 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", size
, size
);
970 *typestring_offset
+= 4;
974 WRITE_FCTYPE(file
, FC_LGFARRAY
, *typestring_offset
);
976 print_file(file
, 2, "0x%02x,\n", align
- 1);
978 print_file(file
, 2, "NdrFcLong(0x%x), /* %d */\n", size
, size
);
979 *typestring_offset
+= 6;
984 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
985 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
986 *typestring_offset
+= 2;
987 write_pointer_description(file
, attrs
, type
, 0, array
, 0, typestring_offset
);
988 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
989 *typestring_offset
+= 1;
992 if (!write_base_type( file
, type
, typestring_offset
))
994 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
995 *typestring_offset
+= 1;
997 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
998 *typestring_offset
+= 1;
1000 return start_offset
;
1002 else if (has_length
&& !has_size
)
1005 unsigned int align
= 0;
1006 size_t element_size
= type_memsize(type
, NULL
, &align
);
1007 size_t elements
= dim
->cval
;
1008 size_t total_size
= element_size
* elements
;
1010 if (total_size
< USHRT_MAX
)
1012 WRITE_FCTYPE(file
, FC_SMVARRAY
, *typestring_offset
);
1014 print_file(file
, 2, "0x%02x,\n", align
- 1);
1016 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", total_size
, total_size
);
1017 /* number of elements */
1018 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", elements
, elements
);
1019 *typestring_offset
+= 6;
1023 WRITE_FCTYPE(file
, FC_LGVARRAY
, *typestring_offset
);
1025 print_file(file
, 2, "0x%02x,\n", align
- 1);
1027 print_file(file
, 2, "NdrFcLong(0x%x), /* %d */\n", total_size
, total_size
);
1028 /* number of elements */
1029 print_file(file
, 2, "NdrFcLong(0x%x), /* %d */\n", elements
, elements
);
1030 *typestring_offset
+= 10;
1033 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", element_size
, element_size
);
1034 *typestring_offset
+= 2;
1036 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
1042 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1043 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1044 *typestring_offset
+= 2;
1045 write_pointer_description(file
, attrs
, type
, 0, array
, 0, typestring_offset
);
1046 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1047 *typestring_offset
+= 1;
1050 if (!write_base_type( file
, type
, typestring_offset
))
1052 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
1053 *typestring_offset
+= 1;
1055 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1056 *typestring_offset
+= 1;
1058 return start_offset
;
1060 else if (!has_length
&& has_size
)
1062 /* conformant array */
1063 unsigned int align
= 0;
1064 size_t element_size
= type_memsize(type
, NULL
, &align
);
1066 WRITE_FCTYPE(file
, FC_CARRAY
, *typestring_offset
);
1068 print_file(file
, 2, "0x%02x,\n", align
- 1);
1070 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", element_size
, element_size
);
1071 *typestring_offset
+= 4;
1073 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
1075 size_is
? size_is
: array
);
1079 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1080 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1081 *typestring_offset
+= 2;
1082 write_pointer_description(file
, attrs
, type
, 0, array
, 0, typestring_offset
);
1083 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1084 *typestring_offset
+= 1;
1087 if (!write_base_type( file
, type
, typestring_offset
))
1089 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
1090 *typestring_offset
+= 1;
1092 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1093 *typestring_offset
+= 1;
1095 return start_offset
;
1099 /* conformant varying array */
1100 unsigned int align
= 0;
1101 size_t element_size
= type_memsize(type
, NULL
, &align
);
1103 WRITE_FCTYPE(file
, FC_CVARRAY
, *typestring_offset
);
1105 print_file(file
, 2, "0x%02x,\n", align
- 1);
1107 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", element_size
, element_size
);
1108 *typestring_offset
+= 4;
1110 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
1112 size_is
? size_is
: array
);
1113 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
1119 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1120 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1121 *typestring_offset
+= 2;
1122 write_pointer_description(file
, attrs
, type
, 0, array
, 0, typestring_offset
);
1123 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1124 *typestring_offset
+= 1;
1127 if (!write_base_type( file
, type
, typestring_offset
))
1129 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
1130 *typestring_offset
+= 1;
1132 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1133 *typestring_offset
+= 1;
1135 return start_offset
;
1140 static const var_t
*find_array_or_string_in_struct(const type_t
*type
)
1142 const var_t
*last_field
= LIST_ENTRY( list_tail(type
->fields
), const var_t
, entry
);
1144 if (is_array_type(last_field
->attrs
, last_field
->type
, last_field
->array
))
1147 assert((last_field
->type
->type
== RPC_FC_CSTRUCT
) ||
1148 (last_field
->type
->type
== RPC_FC_CPSTRUCT
) ||
1149 (last_field
->type
->type
== RPC_FC_CVSTRUCT
));
1151 return find_array_or_string_in_struct(last_field
->type
);
1154 static void write_struct_members(FILE *file
, const type_t
*type
, unsigned int *typestring_offset
)
1158 if (type
->fields
) LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1160 unsigned char rtype
= field
->type
->type
;
1163 write_array_tfs( file
, field
->attrs
, field
->type
, field
->array
,
1164 field
->name
, typestring_offset
);
1165 else if (is_ptr( field
->type
))
1167 /* pointers are handled in detail earlier, here just treat them like longs */
1168 print_file( file
, 2, "0x8,\t/* FC_LONG */\n" );
1169 *typestring_offset
+= 1;
1171 else if (!write_base_type( file
, field
->type
, typestring_offset
))
1172 error("Unsupported member type 0x%x\n", rtype
);
1175 if (!(*typestring_offset
% 2))
1177 print_file(file
, 2, "0x%x,\t\t/* FC_PAD */\n", RPC_FC_PAD
);
1178 *typestring_offset
+= 1;
1181 print_file(file
, 2, "0x%x,\t\t/* FC_END */\n", RPC_FC_END
);
1182 *typestring_offset
+= 1;
1185 static size_t write_struct_tfs(FILE *file
, type_t
*type
,
1186 const char *name
, unsigned int *typestring_offset
)
1188 unsigned int total_size
;
1190 size_t start_offset
;
1191 size_t array_offset
;
1193 unsigned int align
= 0;
1198 case RPC_FC_PSTRUCT
:
1199 total_size
= type_memsize(type
, NULL
, &align
);
1201 if (total_size
> USHRT_MAX
)
1202 error("structure size for %s exceeds %d bytes by %d bytes\n",
1203 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
1205 if (type
->type
== RPC_FC_PSTRUCT
)
1206 write_pointers(file
, NULL
, type
, name
, NULL
, 0, typestring_offset
);
1208 start_offset
= *typestring_offset
;
1209 type
->typestring_offset
= start_offset
;
1210 if (type
->type
== RPC_FC_STRUCT
)
1211 WRITE_FCTYPE(file
, FC_STRUCT
, *typestring_offset
);
1213 WRITE_FCTYPE(file
, FC_PSTRUCT
, *typestring_offset
);
1215 print_file(file
, 2, "0x%02x,\n", align
- 1);
1217 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", total_size
, total_size
);
1218 *typestring_offset
+= 4;
1220 if (type
->type
== RPC_FC_PSTRUCT
)
1222 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1223 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1224 *typestring_offset
+= 2;
1225 write_pointer_description(file
, NULL
, type
, 0, NULL
, 0, typestring_offset
);
1226 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1227 *typestring_offset
+= 1;
1231 write_struct_members(file
, type
, typestring_offset
);
1232 return start_offset
;
1233 case RPC_FC_CSTRUCT
:
1234 case RPC_FC_CPSTRUCT
:
1235 total_size
= type_memsize(type
, NULL
, &align
);
1237 if (total_size
> USHRT_MAX
)
1238 error("structure size for %s exceeds %d bytes by %d bytes\n",
1239 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
1241 array
= find_array_or_string_in_struct(type
);
1242 current_structure
= type
;
1243 array_offset
= write_array_tfs(file
, array
->attrs
, array
->type
,
1244 array
->array
, array
->name
,
1246 current_structure
= NULL
;
1248 if (type
->type
== RPC_FC_CPSTRUCT
)
1249 write_pointers(file
, NULL
, type
, name
, NULL
, 0, typestring_offset
);
1251 start_offset
= *typestring_offset
;
1252 type
->typestring_offset
= start_offset
;
1253 if (type
->type
== RPC_FC_CSTRUCT
)
1254 WRITE_FCTYPE(file
, FC_CSTRUCT
, *typestring_offset
);
1256 WRITE_FCTYPE(file
, FC_CPSTRUCT
, *typestring_offset
);
1258 print_file(file
, 2, "0x%02x,\n", align
- 1);
1260 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", total_size
, total_size
);
1261 *typestring_offset
+= 4;
1262 print_file(file
, 2, "NdrFcShort(0x%x), /* offset = %d (%u) */\n",
1263 array_offset
- *typestring_offset
,
1264 array_offset
- *typestring_offset
,
1266 *typestring_offset
+= 2;
1268 if (type
->type
== RPC_FC_CPSTRUCT
)
1270 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1271 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1272 *typestring_offset
+= 2;
1273 write_pointer_description(file
, NULL
, type
, 0, NULL
, 0, typestring_offset
);
1274 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1275 *typestring_offset
+= 1;
1278 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1279 *typestring_offset
+= 1;
1281 return start_offset
;
1282 case RPC_FC_CVSTRUCT
:
1283 total_size
= type_memsize(type
, NULL
, &align
);
1285 if (total_size
> USHRT_MAX
)
1286 error("structure size for %s exceeds %d bytes by %d bytes\n",
1287 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
1289 array
= find_array_or_string_in_struct(type
);
1290 current_structure
= type
;
1291 if (is_attr(array
->attrs
, ATTR_STRING
))
1292 array_offset
= write_string_tfs(file
, array
->attrs
, array
->type
,
1293 array
->array
, array
->name
,
1296 array_offset
= write_array_tfs(file
, array
->attrs
, array
->type
,
1297 array
->array
, array
->name
,
1299 current_structure
= NULL
;
1301 has_pointers
= write_pointers(file
, NULL
, type
, name
, NULL
, 0, typestring_offset
);
1303 start_offset
= *typestring_offset
;
1304 type
->typestring_offset
= start_offset
;
1305 WRITE_FCTYPE(file
, FC_CVSTRUCT
, *typestring_offset
);
1307 print_file(file
, 2, "0x%02x,\n", align
- 1);
1309 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", total_size
, total_size
);
1310 *typestring_offset
+= 4;
1311 print_file(file
, 2, "NdrFcShort(0x%x), /* offset = %d (%u) */\n",
1312 array_offset
- *typestring_offset
,
1313 array_offset
- *typestring_offset
,
1315 *typestring_offset
+= 2;
1319 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1320 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1321 *typestring_offset
+= 2;
1322 write_pointer_description(file
, NULL
, type
, 0, NULL
, 0, typestring_offset
);
1323 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1324 *typestring_offset
+= 1;
1327 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1328 *typestring_offset
+= 1;
1330 return start_offset
;
1332 error("write_struct_tfs: Unimplemented for type 0x%x\n", type
->type
);
1333 return *typestring_offset
;
1337 static size_t write_pointer_only_tfs(FILE *file
, const attr_list_t
*attrs
, int pointer_type
,
1338 unsigned char flags
, size_t offset
,
1339 unsigned int *typeformat_offset
)
1341 size_t start_offset
= *typeformat_offset
;
1342 short reloff
= offset
- (*typeformat_offset
+ 2);
1343 int in_attr
, out_attr
;
1344 in_attr
= is_attr(attrs
, ATTR_IN
);
1345 out_attr
= is_attr(attrs
, ATTR_OUT
);
1346 if (!in_attr
&& !out_attr
) in_attr
= 1;
1348 if (out_attr
&& !in_attr
&& pointer_type
== RPC_FC_RP
)
1351 print_file(file
, 2, "0x%x, 0x%x,\t\t/* %s",
1354 string_of_type(pointer_type
));
1358 fprintf(file
, " [allocated_on_stack]");
1360 fprintf(file
, " [pointer_deref]");
1361 fprintf(file
, " */\n");
1364 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", reloff
, offset
);
1365 *typeformat_offset
+= 4;
1367 return start_offset
;
1370 static size_t write_union_tfs(FILE *file
, const attr_list_t
*attrs
,
1371 const type_t
*type
, const char *name
,
1372 unsigned int *typeformat_offset
)
1374 error("write_union_tfs: Unimplemented\n");
1375 return *typeformat_offset
;
1378 static size_t write_ip_tfs(FILE *file
, const func_t
*func
, const type_t
*type
, const var_t
*var
,
1379 unsigned int *typeformat_offset
)
1382 size_t start_offset
= *typeformat_offset
;
1383 const var_t
*iid
= get_attrp(var
->attrs
, ATTR_IIDIS
);
1388 expr_list_t expr_list
;
1390 expr
.type
= EXPR_IDENTIFIER
;
1392 expr
.u
.sval
= iid
->name
;
1393 expr
.is_const
= FALSE
;
1394 list_init( &expr_list
);
1395 list_add_head( &expr_list
, &expr
.entry
);
1396 print_file(file
, 2, "0x2f, /* FC_IP */\n");
1397 print_file(file
, 2, "0x5c, /* FC_PAD */\n");
1398 *typeformat_offset
+= write_conf_or_var_desc(file
, func
, NULL
, &expr_list
) + 2;
1402 const type_t
*base
= is_ptr(type
) ? type
->ref
: type
;
1403 const UUID
*uuid
= get_attrp(base
->attrs
, ATTR_UUID
);
1406 error("%s: interface %s missing UUID\n", __FUNCTION__
, base
->name
);
1408 print_file(file
, 2, "0x2f,\t/* FC_IP */\n");
1409 print_file(file
, 2, "0x5a,\t/* FC_CONSTANT_IID */\n");
1410 print_file(file
, 2, "NdrFcLong(0x%08lx),\n", uuid
->Data1
);
1411 print_file(file
, 2, "NdrFcShort(0x%04x),\n", uuid
->Data2
);
1412 print_file(file
, 2, "NdrFcShort(0x%04x),\n", uuid
->Data3
);
1413 for (i
= 0; i
< 8; ++i
)
1414 print_file(file
, 2, "0x%02x,\n", uuid
->Data4
[i
]);
1417 fprintf(file
, "\n");
1419 *typeformat_offset
+= 18;
1421 return start_offset
;
1424 static int get_ptr_attr(const type_t
*t
, int def_type
)
1428 int ptr_attr
= get_attrv(t
->attrs
, ATTR_POINTERTYPE
);
1431 if (t
->kind
!= TKIND_ALIAS
)
1437 static size_t write_typeformatstring_var(FILE *file
, int indent
, const func_t
*func
,
1438 type_t
*type
, const var_t
*var
,
1439 unsigned int *typeformat_offset
)
1444 if (type
== var
->type
) /* top-level pointers */
1446 int pointer_attr
= get_attrv(var
->attrs
, ATTR_POINTERTYPE
);
1447 if (pointer_attr
!= 0 && !is_ptr(type
))
1448 error("'%s': pointer attribute applied to non-pointer type\n", var
->name
);
1450 if (pointer_attr
== 0)
1451 pointer_attr
= get_ptr_attr(type
, RPC_FC_RP
);
1453 pointer_type
= pointer_attr
;
1456 pointer_type
= get_ptr_attr(type
, RPC_FC_UP
);
1458 if (((last_ptr(type
) && var
->array
== NULL
)
1459 || (!is_ptr(type
) && var
->array
!= NULL
))
1460 && is_ptrchain_attr(var
, ATTR_STRING
))
1462 return write_string_tfs(file
, var
->attrs
, type
, var
->array
, var
->name
, typeformat_offset
);
1465 if (is_array_type(var
->attrs
, type
, var
->array
))
1466 return write_array_tfs(file
, var
->attrs
, type
, var
->array
, var
->name
, typeformat_offset
);
1470 /* basic types don't need a type format string */
1471 if (is_base_type(type
->type
))
1477 case RPC_FC_PSTRUCT
:
1478 case RPC_FC_CSTRUCT
:
1479 case RPC_FC_CPSTRUCT
:
1480 case RPC_FC_CVSTRUCT
:
1481 case RPC_FC_BOGUS_STRUCT
:
1482 return write_struct_tfs(file
, type
, var
->name
, typeformat_offset
);
1483 case RPC_FC_ENCAPSULATED_UNION
:
1484 case RPC_FC_NON_ENCAPSULATED_UNION
:
1485 return write_union_tfs(file
, var
->attrs
, type
, var
->name
, typeformat_offset
);
1487 case RPC_FC_BIND_PRIMITIVE
:
1491 error("write_typeformatstring_var: Unsupported type 0x%x for variable %s\n", type
->type
, var
->name
);
1494 else if (last_ptr(type
))
1496 size_t start_offset
= *typeformat_offset
;
1497 int in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1498 int out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1499 const type_t
*base
= type
->ref
;
1501 if (base
->type
== RPC_FC_IP
)
1503 return write_ip_tfs(file
, func
, type
, var
, typeformat_offset
);
1506 /* special case for pointers to base types */
1507 if (is_base_type(base
->type
))
1509 print_file(file
, indent
, "0x%x, 0x%x, /* %s %s[simple_pointer] */\n",
1510 pointer_type
, (!in_attr
&& out_attr
) ? 0x0C : 0x08,
1511 string_of_type(pointer_type
),
1512 (!in_attr
&& out_attr
) ? "[allocated_on_stack] " : "");
1513 print_file(file
, indent
, "0x%02x, /* %s */\n", base
->type
, string_of_type(base
->type
));
1514 print_file(file
, indent
, "0x5c, /* FC_PAD */\n");
1515 *typeformat_offset
+= 4;
1516 return start_offset
;
1520 assert(is_ptr(type
));
1522 offset
= write_typeformatstring_var(file
, indent
, func
, type
->ref
, var
, typeformat_offset
);
1524 fprintf(file
, "/* %2u */\n", *typeformat_offset
);
1525 return write_pointer_only_tfs(file
, var
->attrs
, pointer_type
,
1526 !last_ptr(type
) ? 0x10 : 0,
1527 offset
, typeformat_offset
);
1530 static void clear_tfsoff(type_t
*type
)
1534 type
->typestring_offset
= 0;
1536 if (type
->kind
== TKIND_ALIAS
)
1538 else if (is_ptr(type
))
1545 LIST_FOR_EACH_ENTRY( v
, type
->fields
, var_t
, entry
)
1546 clear_tfsoff(v
->type
);
1554 static void clear_all_tfsoffs(const ifref_list_t
*ifaces
)
1556 const ifref_t
* iface
;
1561 LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
1562 if (iface
->iface
->funcs
)
1563 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
1565 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1566 clear_tfsoff(var
->type
);
1569 static size_t process_tfs(FILE *file
, const ifref_list_t
*ifaces
, int for_objects
)
1572 const ifref_t
*iface
;
1573 size_t typeformat_offset
= 2;
1575 if (ifaces
) LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
1577 if (for_objects
!= is_object(iface
->iface
->attrs
) || is_local(iface
->iface
->attrs
))
1580 if (iface
->iface
->funcs
)
1583 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
1585 if (is_local(func
->def
->attrs
)) continue;
1587 current_func
= func
;
1589 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1590 var
->type
->typestring_offset
1591 = write_typeformatstring_var(file
, 2, func
, var
->type
,
1592 var
, &typeformat_offset
);
1597 return typeformat_offset
+ 1;
1601 void write_typeformatstring(FILE *file
, const ifref_list_t
*ifaces
, int for_objects
)
1605 print_file(file
, indent
, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
1606 print_file(file
, indent
, "{\n");
1608 print_file(file
, indent
, "0,\n");
1609 print_file(file
, indent
, "{\n");
1611 print_file(file
, indent
, "NdrFcShort(0x0),\n");
1613 clear_all_tfsoffs(ifaces
);
1614 process_tfs(file
, ifaces
, for_objects
);
1616 print_file(file
, indent
, "0x0\n");
1618 print_file(file
, indent
, "}\n");
1620 print_file(file
, indent
, "};\n");
1621 print_file(file
, indent
, "\n");
1624 static unsigned int get_required_buffer_size_type(
1625 const type_t
*type
, const array_dims_t
*array
,
1626 const char *name
, unsigned int *alignment
)
1653 case RPC_FC_ERROR_STATUS_T
:
1665 case RPC_FC_BIND_PRIMITIVE
:
1669 case RPC_FC_PSTRUCT
:
1672 if (!type
->fields
) return 0;
1673 LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1675 unsigned int alignment
;
1676 size
+= get_required_buffer_size_type(
1677 field
->type
, field
->array
, field
->name
,
1684 if (is_base_type( type
->ref
->type
) || type
->ref
->type
== RPC_FC_STRUCT
)
1685 size
= get_required_buffer_size_type( type
->ref
, NULL
, name
, alignment
);
1689 error("get_required_buffer_size: Unknown/unsupported type: %s (0x%02x)\n", name
, type
->type
);
1692 if (array
) size
*= get_array_size( array
);
1697 static unsigned int get_required_buffer_size(const var_t
*var
, unsigned int *alignment
, enum pass pass
)
1699 expr_list_t
*size_is
= get_attrp(var
->attrs
, ATTR_SIZEIS
);
1700 int has_size
= is_non_void(size_is
);
1701 int in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1702 int out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1704 if (!in_attr
&& !out_attr
)
1709 if (pass
== PASS_OUT
)
1711 if (out_attr
&& is_ptr(var
->type
))
1713 type_t
*type
= var
->type
;
1715 if (type
->type
== RPC_FC_STRUCT
)
1718 unsigned int size
= 36;
1720 if (!type
->fields
) return size
;
1721 LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1724 size
+= get_required_buffer_size_type(
1725 field
->type
, field
->array
, field
->name
,
1735 if ((!out_attr
|| in_attr
) && !has_size
&& !is_attr(var
->attrs
, ATTR_STRING
) && !var
->array
)
1737 if (is_ptr(var
->type
))
1739 type_t
*type
= var
->type
;
1741 if (is_base_type(type
->type
))
1745 else if (type
->type
== RPC_FC_STRUCT
)
1747 unsigned int size
= 36;
1750 if (!type
->fields
) return size
;
1751 LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1754 size
+= get_required_buffer_size_type(
1755 field
->type
, field
->array
, field
->name
,
1763 return get_required_buffer_size_type(var
->type
, var
->array
, var
->name
, alignment
);
1767 static unsigned int get_function_buffer_size( const func_t
*func
, enum pass pass
)
1770 unsigned int total_size
= 0, alignment
;
1774 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1776 total_size
+= get_required_buffer_size(var
, &alignment
, pass
);
1777 total_size
+= alignment
;
1781 if (pass
== PASS_OUT
&& !is_void(func
->def
->type
))
1783 total_size
+= get_required_buffer_size(func
->def
, &alignment
, PASS_RETURN
);
1784 total_size
+= alignment
;
1789 static void print_phase_function(FILE *file
, int indent
, const char *type
,
1790 enum remoting_phase phase
,
1791 const char *varname
, unsigned int type_offset
)
1793 const char *function
;
1796 case PHASE_BUFFERSIZE
:
1797 function
= "BufferSize";
1800 function
= "Marshall";
1802 case PHASE_UNMARSHAL
:
1803 function
= "Unmarshall";
1813 print_file(file
, indent
, "Ndr%s%s(\n", type
, function
);
1815 print_file(file
, indent
, "&_StubMsg,\n");
1816 print_file(file
, indent
, "%s%s,\n",
1817 (phase
== PHASE_UNMARSHAL
) ? "(unsigned char **)&" : "(unsigned char *)",
1819 print_file(file
, indent
, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]%s\n",
1820 type_offset
, (phase
== PHASE_UNMARSHAL
) ? "," : ");");
1821 if (phase
== PHASE_UNMARSHAL
)
1822 print_file(file
, indent
, "0);\n");
1826 void print_phase_basetype(FILE *file
, int indent
, enum remoting_phase phase
,
1827 enum pass pass
, const var_t
*var
,
1828 const char *varname
)
1830 type_t
*type
= var
->type
;
1832 unsigned int alignment
= 0;
1833 unsigned char rtype
;
1835 /* no work to do for other phases, buffer sizing is done elsewhere */
1836 if (phase
!= PHASE_MARSHAL
&& phase
!= PHASE_UNMARSHAL
)
1839 rtype
= is_ptr(type
) ? type
->ref
->type
: type
->type
;
1861 case RPC_FC_ERROR_STATUS_T
:
1873 case RPC_FC_BIND_PRIMITIVE
:
1874 /* no marshalling needed */
1878 error("print_phase_basetype: Unsupported type: %s (0x%02x, ptr_level: 0)\n", var
->name
, rtype
);
1882 print_file(file
, indent
, "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + %u) & ~0x%x);\n",
1883 alignment
- 1, alignment
- 1);
1885 if (phase
== PHASE_MARSHAL
)
1887 print_file(file
, indent
, "*(");
1888 write_type(file
, is_ptr(type
) ? type
->ref
: type
);
1890 fprintf(file
, " *)_StubMsg.Buffer = *");
1892 fprintf(file
, " *)_StubMsg.Buffer = ");
1893 fprintf(file
, varname
);
1894 fprintf(file
, ";\n");
1896 else if (phase
== PHASE_UNMARSHAL
)
1898 if (pass
== PASS_IN
|| pass
== PASS_RETURN
)
1899 print_file(file
, indent
, "");
1901 print_file(file
, indent
, "*");
1902 fprintf(file
, varname
);
1903 if (pass
== PASS_IN
&& is_ptr(type
))
1904 fprintf(file
, " = (");
1906 fprintf(file
, " = *(");
1907 write_type(file
, is_ptr(type
) ? type
->ref
: type
);
1908 fprintf(file
, " *)_StubMsg.Buffer;\n");
1911 print_file(file
, indent
, "_StubMsg.Buffer += sizeof(");
1912 write_type(file
, var
->type
);
1913 fprintf(file
, ");\n");
1916 /* returns whether the MaxCount, Offset or ActualCount members need to be
1917 * filled in for the specified phase */
1918 static inline int is_size_needed_for_phase(enum remoting_phase phase
)
1920 return (phase
!= PHASE_UNMARSHAL
);
1923 void write_remoting_arguments(FILE *file
, int indent
, const func_t
*func
,
1924 enum pass pass
, enum remoting_phase phase
)
1926 const expr_list_t
*length_is
;
1927 const expr_list_t
*size_is
;
1928 int in_attr
, out_attr
, has_length
, has_size
, pointer_type
;
1934 if (phase
== PHASE_BUFFERSIZE
)
1936 unsigned int size
= get_function_buffer_size( func
, pass
);
1937 print_file(file
, indent
, "_StubMsg.BufferLength = %u;\n", size
);
1940 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1942 const type_t
*type
= var
->type
;
1943 unsigned char rtype
;
1944 size_t start_offset
= type
->typestring_offset
;
1946 length_is
= get_attrp(var
->attrs
, ATTR_LENGTHIS
);
1947 size_is
= get_attrp(var
->attrs
, ATTR_SIZEIS
);
1948 has_length
= is_non_void(length_is
);
1949 has_size
= is_non_void(size_is
) || (var
->array
&& is_conformant_array(var
->array
));
1951 pointer_type
= get_attrv(var
->attrs
, ATTR_POINTERTYPE
);
1953 pointer_type
= RPC_FC_RP
;
1955 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1956 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1957 if (!in_attr
&& !out_attr
)
1963 if (!in_attr
) continue;
1966 if (!out_attr
) continue;
1974 if (is_user_derived( var
))
1976 print_phase_function(file
, indent
, "UserMarshal", phase
, var
->name
, start_offset
);
1978 else if (is_string_type(var
->attrs
, var
->type
, var
->array
))
1980 if (var
->array
&& !is_conformant_array(var
->array
))
1981 print_phase_function(file
, indent
, "NonConformantString", phase
, var
->name
, start_offset
);
1984 if (size_is
&& is_size_needed_for_phase(phase
))
1986 const expr_t
*size
= LIST_ENTRY( list_head(size_is
), const expr_t
, entry
);
1987 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
1988 write_expr(file
, size
, 1);
1989 fprintf(file
, ";\n");
1992 if ((phase
== PHASE_FREE
) || (pointer_type
== RPC_FC_UP
))
1993 print_phase_function(file
, indent
, "Pointer", phase
, var
->name
, start_offset
);
1995 print_phase_function(file
, indent
, "ConformantString", phase
, var
->name
,
1996 start_offset
+ (has_size
? 4 : 2));
1999 else if (is_array_type(var
->attrs
, var
->type
, var
->array
))
2001 const char *array_type
;
2003 if (var
->array
&& list_count(var
->array
) > 1) /* multi-dimensional array */
2004 array_type
= "ComplexArray";
2007 if (!has_length
&& !has_size
)
2008 array_type
= "FixedArray";
2009 else if (has_length
&& !has_size
)
2011 if (is_size_needed_for_phase(phase
))
2013 const expr_t
*length
= LIST_ENTRY( list_head(length_is
), const expr_t
, entry
);
2014 print_file(file
, indent
, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
2015 print_file(file
, indent
, "_StubMsg.ActualCount = (unsigned long)");
2016 write_expr(file
, length
, 1);
2017 fprintf(file
, ";\n\n");
2019 array_type
= "VaryingArray";
2021 else if (!has_length
&& has_size
)
2023 if (is_size_needed_for_phase(phase
) && phase
!= PHASE_FREE
)
2025 const expr_t
*size
= LIST_ENTRY( list_head(size_is
? size_is
: var
->array
),
2026 const expr_t
, entry
);
2027 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
2028 write_expr(file
, size
, 1);
2029 fprintf(file
, ";\n\n");
2031 array_type
= "ConformantArray";
2035 if (is_size_needed_for_phase(phase
))
2037 const expr_t
*length
= LIST_ENTRY( list_head(length_is
), const expr_t
, entry
);
2038 const expr_t
*size
= LIST_ENTRY( list_head(size_is
? size_is
: var
->array
),
2039 const expr_t
, entry
);
2040 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
2041 write_expr(file
, size
, 1);
2042 fprintf(file
, ";\n");
2043 print_file(file
, indent
, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
2044 print_file(file
, indent
, "_StubMsg.ActualCount = (unsigned long)");
2045 write_expr(file
, length
, 1);
2046 fprintf(file
, ";\n\n");
2048 array_type
= "ConformantVaryingArray";
2052 if (!in_attr
&& phase
== PHASE_FREE
)
2054 print_file(file
, indent
, "if (%s)\n", var
->name
);
2056 print_file(file
, indent
, "_StubMsg.pfnFree(%s);\n", var
->name
);
2058 else if (phase
!= PHASE_FREE
)
2060 if (pointer_type
== RPC_FC_UP
)
2061 print_phase_function(file
, indent
, "Pointer", phase
, var
->name
, start_offset
);
2063 print_phase_function(file
, indent
, array_type
, phase
, var
->name
, start_offset
);
2066 else if (!is_ptr(var
->type
) && is_base_type(rtype
))
2068 print_phase_basetype(file
, indent
, phase
, pass
, var
, var
->name
);
2070 else if (!is_ptr(var
->type
))
2075 case RPC_FC_PSTRUCT
:
2076 print_phase_function(file
, indent
, "SimpleStruct", phase
, var
->name
, start_offset
);
2078 case RPC_FC_CSTRUCT
:
2079 case RPC_FC_CPSTRUCT
:
2080 print_phase_function(file
, indent
, "ConformantStruct", phase
, var
->name
, start_offset
);
2082 case RPC_FC_CVSTRUCT
:
2083 print_phase_function(file
, indent
, "ConformantVaryingStruct", phase
, var
->name
, start_offset
);
2085 case RPC_FC_BOGUS_STRUCT
:
2086 print_phase_function(file
, indent
, "ComplexStruct", phase
, var
->name
, start_offset
);
2089 if (is_base_type( var
->type
->ref
->type
))
2091 print_phase_basetype(file
, indent
, phase
, pass
, var
, var
->name
);
2093 else if (var
->type
->ref
->type
== RPC_FC_STRUCT
)
2095 if (phase
!= PHASE_BUFFERSIZE
&& phase
!= PHASE_FREE
)
2096 print_phase_function(file
, indent
, "SimpleStruct", phase
, var
->name
, start_offset
+ 4);
2101 if ((iid
= get_attrp( var
->attrs
, ATTR_IIDIS
)))
2102 print_file( file
, indent
, "_StubMsg.MaxCount = (unsigned long)%s;\n", iid
->name
);
2103 print_phase_function(file
, indent
, "Pointer", phase
, var
->name
, start_offset
);
2107 error("write_remoting_arguments: Unsupported type: %s (0x%02x)\n", var
->name
, rtype
);
2112 if (last_ptr(var
->type
) && (pointer_type
== RPC_FC_RP
) && is_base_type(rtype
))
2114 print_phase_basetype(file
, indent
, phase
, pass
, var
, var
->name
);
2116 else if (last_ptr(var
->type
) && (pointer_type
== RPC_FC_RP
) && (rtype
== RPC_FC_STRUCT
))
2118 if (phase
!= PHASE_BUFFERSIZE
&& phase
!= PHASE_FREE
)
2119 print_phase_function(file
, indent
, "SimpleStruct", phase
, var
->name
, start_offset
+ 4);
2124 if ((iid
= get_attrp( var
->attrs
, ATTR_IIDIS
)))
2125 print_file( file
, indent
, "_StubMsg.MaxCount = (unsigned long)%s;\n", iid
->name
);
2126 print_phase_function(file
, indent
, "Pointer", phase
, var
->name
, start_offset
);
2129 fprintf(file
, "\n");
2134 size_t get_size_procformatstring_var(const var_t
*var
)
2136 return write_procformatstring_var(NULL
, 0, var
, FALSE
);
2140 size_t get_size_procformatstring_func(const func_t
*func
)
2145 /* argument list size */
2147 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2148 size
+= get_size_procformatstring_var(var
);
2150 /* return value size */
2151 if (is_void(func
->def
->type
))
2152 size
+= 2; /* FC_END and FC_PAD */
2154 size
+= get_size_procformatstring_var(func
->def
);
2159 size_t get_size_procformatstring(const ifref_list_t
*ifaces
, int for_objects
)
2161 const ifref_t
*iface
;
2165 if (ifaces
) LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
2167 if (for_objects
!= is_object(iface
->iface
->attrs
) || is_local(iface
->iface
->attrs
))
2170 if (iface
->iface
->funcs
)
2171 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
2172 if (!is_local(func
->def
->attrs
))
2173 size
+= get_size_procformatstring_func( func
);
2178 size_t get_size_typeformatstring(const ifref_list_t
*ifaces
, int for_objects
)
2180 return process_tfs(NULL
, ifaces
, for_objects
);
2183 static void write_struct_expr(FILE *h
, const expr_t
*e
, int brackets
,
2184 const var_list_t
*fields
, const char *structvar
)
2190 fprintf(h
, "%lu", e
->u
.lval
);
2193 fprintf(h
, "0x%lx", e
->u
.lval
);
2195 case EXPR_TRUEFALSE
:
2197 fprintf(h
, "FALSE");
2201 case EXPR_IDENTIFIER
:
2204 LIST_FOR_EACH_ENTRY( field
, fields
, const var_t
, entry
)
2205 if (!strcmp(e
->u
.sval
, field
->name
))
2207 fprintf(h
, "%s->%s", structvar
, e
->u
.sval
);
2211 if (&field
->entry
== fields
) error("no field found for identifier %s\n", e
->u
.sval
);
2216 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2220 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2224 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2228 write_type(h
, e
->u
.tref
);
2230 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2233 fprintf(h
, "sizeof(");
2234 write_type(h
, e
->u
.tref
);
2245 if (brackets
) fprintf(h
, "(");
2246 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2248 case EXPR_SHL
: fprintf(h
, " << "); break;
2249 case EXPR_SHR
: fprintf(h
, " >> "); break;
2250 case EXPR_MUL
: fprintf(h
, " * "); break;
2251 case EXPR_DIV
: fprintf(h
, " / "); break;
2252 case EXPR_ADD
: fprintf(h
, " + "); break;
2253 case EXPR_SUB
: fprintf(h
, " - "); break;
2254 case EXPR_AND
: fprintf(h
, " & "); break;
2255 case EXPR_OR
: fprintf(h
, " | "); break;
2258 write_struct_expr(h
, e
->u
.ext
, 1, fields
, structvar
);
2259 if (brackets
) fprintf(h
, ")");
2262 if (brackets
) fprintf(h
, "(");
2263 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2265 write_struct_expr(h
, e
->u
.ext
, 1, fields
, structvar
);
2267 write_struct_expr(h
, e
->ext2
, 1, fields
, structvar
);
2268 if (brackets
) fprintf(h
, ")");
2274 void declare_stub_args( FILE *file
, int indent
, const func_t
*func
)
2276 int in_attr
, out_attr
;
2278 const var_t
*def
= func
->def
;
2281 /* declare return value '_RetVal' */
2282 if (!is_void(def
->type
))
2284 print_file(file
, indent
, "");
2285 write_type(file
, def
->type
);
2286 fprintf(file
, " _RetVal;\n");
2292 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2294 const expr_list_t
*size_is
= get_attrp(var
->attrs
, ATTR_SIZEIS
);
2295 int has_size
= is_non_void(size_is
);
2296 int is_string
= is_attr(var
->attrs
, ATTR_STRING
);
2298 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
2299 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
2300 if (!out_attr
&& !in_attr
)
2303 if (!in_attr
&& !has_size
&& !is_string
)
2305 print_file(file
, indent
, "");
2306 write_type(file
, var
->type
->ref
);
2307 fprintf(file
, " _W%u;\n", i
++);
2310 print_file(file
, indent
, "");
2311 write_type(file
, var
->type
);
2314 fprintf(file
, "( *");
2315 write_name(file
, var
);
2316 fprintf(file
, " )");
2318 write_name(file
, var
);
2319 write_array(file
, var
->array
, 0);
2320 fprintf(file
, ";\n");
2325 void assign_stub_out_args( FILE *file
, int indent
, const func_t
*func
)
2327 int in_attr
, out_attr
;
2330 const expr_list_t
*size_is
;
2336 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2338 int is_string
= is_attr(var
->attrs
, ATTR_STRING
);
2339 size_is
= get_attrp(var
->attrs
, ATTR_SIZEIS
);
2340 has_size
= is_non_void(size_is
);
2341 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
2342 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
2343 if (!out_attr
&& !in_attr
)
2348 print_file(file
, indent
, "");
2349 write_name(file
, var
);
2354 unsigned int size
, align
= 0;
2355 type_t
*type
= var
->type
;
2357 fprintf(file
, " = NdrAllocate(&_StubMsg, ");
2358 LIST_FOR_EACH_ENTRY( expr
, size_is
, const expr_t
, entry
)
2360 if (expr
->type
== EXPR_VOID
) continue;
2361 write_expr( file
, expr
, 1 );
2362 fprintf(file
, " * ");
2364 size
= type_memsize(type
, NULL
, &align
);
2365 fprintf(file
, "%u);\n", size
);
2367 else if (!is_string
)
2369 fprintf(file
, " = &_W%u;\n", i
);
2370 if (is_ptr(var
->type
) && !last_ptr(var
->type
))
2371 print_file(file
, indent
, "_W%u = 0;\n", i
);
2379 fprintf(file
, "\n");
2383 int write_expr_eval_routines(FILE *file
, const char *iface
)
2386 struct expr_eval_routine
*eval
;
2387 unsigned short callback_offset
= 0;
2389 LIST_FOR_EACH_ENTRY(eval
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
2393 print_file(file
, indent
, "static void __RPC_USER %s_%sExprEval_%04u(PMIDL_STUB_MESSAGE pStubMsg)\n",
2394 iface
, eval
->structure
->name
, callback_offset
);
2395 print_file(file
, indent
, "{\n");
2397 print_file(file
, indent
, "struct %s *" STRUCT_EXPR_EVAL_VAR
" = (struct %s *)(pStubMsg->StackTop - %u);\n",
2398 eval
->structure
->name
, eval
->structure
->name
, eval
->structure_size
);
2399 fprintf(file
, "\n");
2400 print_file(file
, indent
, "pStubMsg->Offset = 0;\n"); /* FIXME */
2401 print_file(file
, indent
, "pStubMsg->MaxCount = (unsigned long)");
2402 write_struct_expr(file
, eval
->expr
, 1, eval
->structure
->fields
, STRUCT_EXPR_EVAL_VAR
);
2403 fprintf(file
, ";\n");
2405 print_file(file
, indent
, "}\n\n");
2411 void write_expr_eval_routine_list(FILE *file
, const char *iface
)
2413 struct expr_eval_routine
*eval
;
2414 struct expr_eval_routine
*cursor
;
2415 unsigned short callback_offset
= 0;
2417 fprintf(file
, "static const EXPR_EVAL ExprEvalRoutines[] =\n");
2418 fprintf(file
, "{\n");
2420 LIST_FOR_EACH_ENTRY_SAFE(eval
, cursor
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
2422 print_file(file
, 1, "%s_%sExprEval_%04u,\n",
2423 iface
, eval
->structure
->name
, callback_offset
);
2426 list_remove(&eval
->entry
);
2430 fprintf(file
, "};\n\n");
2434 void write_endpoints( FILE *f
, const char *prefix
, const str_list_t
*list
)
2436 const struct str_list_entry_t
*endpoint
;
2439 /* this should be an array of RPC_PROTSEQ_ENDPOINT but we want const strings */
2440 print_file( f
, 0, "static const unsigned char * %s__RpcProtseqEndpoint[][2] =\n{\n", prefix
);
2441 LIST_FOR_EACH_ENTRY( endpoint
, list
, const struct str_list_entry_t
, entry
)
2443 print_file( f
, 1, "{ (const unsigned char *)\"" );
2444 for (p
= endpoint
->str
; *p
&& *p
!= ':'; p
++)
2446 if (*p
== '"' || *p
== '\\') fputc( '\\', f
);
2449 if (!*p
) goto error
;
2450 if (p
[1] != '[') goto error
;
2452 fprintf( f
, "\", (const unsigned char *)\"" );
2453 for (p
+= 2; *p
&& *p
!= ']'; p
++)
2455 if (*p
== '"' || *p
== '\\') fputc( '\\', f
);
2458 if (*p
!= ']') goto error
;
2459 fprintf( f
, "\" },\n" );
2461 print_file( f
, 0, "};\n\n" );
2465 error("Invalid endpoint syntax '%s'\n", endpoint
->str
);