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 fields_memsize(const var_list_t
*fields
, unsigned int *align
);
63 static size_t write_struct_tfs(FILE *file
, type_t
*type
, const char *name
, unsigned int *tfsoff
);
64 static int write_embedded_types(FILE *file
, const attr_list_t
*attrs
, type_t
*type
,
65 const char *name
, int write_ptr
, unsigned int *tfsoff
);
67 const char *string_of_type(unsigned char type
)
71 case RPC_FC_BYTE
: return "FC_BYTE";
72 case RPC_FC_CHAR
: return "FC_CHAR";
73 case RPC_FC_SMALL
: return "FC_SMALL";
74 case RPC_FC_USMALL
: return "FC_USMALL";
75 case RPC_FC_WCHAR
: return "FC_WCHAR";
76 case RPC_FC_SHORT
: return "FC_SHORT";
77 case RPC_FC_USHORT
: return "FC_USHORT";
78 case RPC_FC_LONG
: return "FC_LONG";
79 case RPC_FC_ULONG
: return "FC_ULONG";
80 case RPC_FC_FLOAT
: return "FC_FLOAT";
81 case RPC_FC_HYPER
: return "FC_HYPER";
82 case RPC_FC_DOUBLE
: return "FC_DOUBLE";
83 case RPC_FC_ENUM16
: return "FC_ENUM16";
84 case RPC_FC_ENUM32
: return "FC_ENUM32";
85 case RPC_FC_IGNORE
: return "FC_IGNORE";
86 case RPC_FC_ERROR_STATUS_T
: return "FC_ERROR_STATUS_T";
87 case RPC_FC_RP
: return "FC_RP";
88 case RPC_FC_UP
: return "FC_UP";
89 case RPC_FC_OP
: return "FC_OP";
90 case RPC_FC_FP
: return "FC_FP";
91 case RPC_FC_ENCAPSULATED_UNION
: return "FC_ENCAPSULATED_UNION";
92 case RPC_FC_NON_ENCAPSULATED_UNION
: return "FC_NON_ENCAPSULATED_UNION";
93 case RPC_FC_STRUCT
: return "FC_STRUCT";
94 case RPC_FC_PSTRUCT
: return "FC_PSTRUCT";
95 case RPC_FC_CSTRUCT
: return "FC_CSTRUCT";
96 case RPC_FC_CPSTRUCT
: return "FC_CPSTRUCT";
97 case RPC_FC_CVSTRUCT
: return "FC_CVSTRUCT";
98 case RPC_FC_BOGUS_STRUCT
: return "FC_BOGUS_STRUCT";
99 case RPC_FC_SMFARRAY
: return "FC_SMFARRAY";
100 case RPC_FC_LGFARRAY
: return "FC_LGFARRAY";
101 case RPC_FC_SMVARRAY
: return "FC_SMVARRAY";
102 case RPC_FC_LGVARRAY
: return "FC_LGVARRAY";
103 case RPC_FC_CARRAY
: return "FC_CARRAY";
104 case RPC_FC_CVARRAY
: return "FC_CVARRAY";
105 case RPC_FC_BOGUS_ARRAY
: return "FC_BOGUS_ARRAY";
107 error("string_of_type: unknown type 0x%02x\n", type
);
112 int is_struct(unsigned char type
)
119 case RPC_FC_CPSTRUCT
:
120 case RPC_FC_CVSTRUCT
:
121 case RPC_FC_BOGUS_STRUCT
:
128 int is_union(unsigned char type
)
132 case RPC_FC_ENCAPSULATED_UNION
:
133 case RPC_FC_NON_ENCAPSULATED_UNION
:
140 static unsigned short user_type_offset(const char *name
)
143 unsigned short off
= 0;
144 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
146 if (strcmp(name
, ut
->name
) == 0)
150 error("user_type_offset: couldn't find type (%s)\n", name
);
154 static void update_tfsoff(type_t
*type
, unsigned int offset
, FILE *file
)
156 type
->typestring_offset
= offset
;
157 if (file
) type
->tfswrite
= FALSE
;
160 static void guard_rec(type_t
*type
)
162 /* types that contain references to themselves (like a linked list),
163 need to be shielded from infinite recursion when writing embedded
165 if (type
->typestring_offset
)
166 type
->tfswrite
= FALSE
;
168 type
->typestring_offset
= 1;
171 static type_t
*get_user_type(const type_t
*t
, const char **pname
)
175 type_t
*ut
= get_attrp(t
->attrs
, ATTR_WIREMARSHAL
);
183 if (t
->kind
== TKIND_ALIAS
)
190 static int is_user_type(const type_t
*t
)
192 return get_user_type(t
, NULL
) != NULL
;
195 static int is_embedded_complex(const type_t
*type
)
197 unsigned char tc
= type
->type
;
198 return is_struct(tc
) || is_union(tc
) || is_array(type
) || is_user_type(type
);
201 static int compare_expr(const expr_t
*a
, const expr_t
*b
)
205 if (a
->type
!= b
->type
)
206 return a
->type
- b
->type
;
213 return a
->u
.lval
- b
->u
.lval
;
214 case EXPR_IDENTIFIER
:
215 return strcmp(a
->u
.sval
, b
->u
.sval
);
217 ret
= compare_expr(a
->ref
, b
->ref
);
220 ret
= compare_expr(a
->u
.ext
, b
->u
.ext
);
223 return compare_expr(a
->ext2
, b
->ext2
);
232 ret
= compare_expr(a
->ref
, b
->ref
);
235 return compare_expr(a
->u
.ext
, b
->u
.ext
);
241 return compare_expr(a
->ref
, b
->ref
);
248 #define WRITE_FCTYPE(file, fctype, typestring_offset) \
251 fprintf(file, "/* %2u */\n", typestring_offset); \
252 print_file((file), 2, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
256 static int print_file(FILE *file
, int indent
, const char *format
, ...)
263 va_start(va
, format
);
264 for (i
= 0; i
< indent
; i
++)
266 r
= vfprintf(file
, format
, va
);
271 static void write_formatdesc(FILE *f
, int indent
, const char *str
)
273 print_file(f
, indent
, "typedef struct _MIDL_%s_FORMAT_STRING\n", str
);
274 print_file(f
, indent
, "{\n");
275 print_file(f
, indent
+ 1, "short Pad;\n");
276 print_file(f
, indent
+ 1, "unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str
);
277 print_file(f
, indent
, "} MIDL_%s_FORMAT_STRING;\n", str
);
278 print_file(f
, indent
, "\n");
281 void write_formatstringsdecl(FILE *f
, int indent
, ifref_list_t
*ifaces
, int for_objects
)
283 print_file(f
, indent
, "#define TYPE_FORMAT_STRING_SIZE %d\n",
284 get_size_typeformatstring(ifaces
, for_objects
));
286 print_file(f
, indent
, "#define PROC_FORMAT_STRING_SIZE %d\n",
287 get_size_procformatstring(ifaces
, for_objects
));
290 write_formatdesc(f
, indent
, "TYPE");
291 write_formatdesc(f
, indent
, "PROC");
293 print_file(f
, indent
, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
294 print_file(f
, indent
, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
295 print_file(f
, indent
, "\n");
298 static inline int is_base_type(unsigned char type
)
317 case RPC_FC_ERROR_STATUS_T
:
318 case RPC_FC_BIND_PRIMITIVE
:
326 int decl_indirect(const type_t
*t
)
328 return is_user_type(t
)
329 || (!is_base_type(t
->type
)
334 static size_t write_procformatstring_var(FILE *file
, int indent
,
335 const var_t
*var
, int is_return
)
338 const type_t
*type
= var
->type
;
340 int is_in
= is_attr(var
->attrs
, ATTR_IN
);
341 int is_out
= is_attr(var
->attrs
, ATTR_OUT
);
343 if (!is_in
&& !is_out
) is_in
= TRUE
;
345 if (!type
->declarray
&& is_base_type(type
->type
))
348 print_file(file
, indent
, "0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
350 print_file(file
, indent
, "0x4e, /* FC_IN_PARAM_BASETYPE */\n");
352 if (type
->type
== RPC_FC_BIND_PRIMITIVE
)
354 print_file(file
, indent
, "0x%02x, /* FC_IGNORE */\n", RPC_FC_IGNORE
);
355 size
= 2; /* includes param type prefix */
357 else if (is_base_type(type
->type
))
359 print_file(file
, indent
, "0x%02x, /* %s */\n", type
->type
, string_of_type(type
->type
));
360 size
= 2; /* includes param type prefix */
364 error("Unknown/unsupported type: %s (0x%02x)\n", var
->name
, type
->type
);
371 print_file(file
, indent
, "0x52, /* FC_RETURN_PARAM */\n");
372 else if (is_in
&& is_out
)
373 print_file(file
, indent
, "0x50, /* FC_IN_OUT_PARAM */\n");
375 print_file(file
, indent
, "0x51, /* FC_OUT_PARAM */\n");
377 print_file(file
, indent
, "0x4d, /* FC_IN_PARAM */\n");
379 print_file(file
, indent
, "0x01,\n");
380 print_file(file
, indent
, "NdrFcShort(0x%x),\n", type
->typestring_offset
);
381 size
= 4; /* includes param type prefix */
386 void write_procformatstring(FILE *file
, const ifref_list_t
*ifaces
, int for_objects
)
388 const ifref_t
*iface
;
392 print_file(file
, indent
, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
393 print_file(file
, indent
, "{\n");
395 print_file(file
, indent
, "0,\n");
396 print_file(file
, indent
, "{\n");
399 if (ifaces
) LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
401 if (for_objects
!= is_object(iface
->iface
->attrs
) || is_local(iface
->iface
->attrs
))
404 if (iface
->iface
->funcs
)
407 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
409 if (is_local(func
->def
->attrs
)) continue;
410 /* emit argument data */
413 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
414 write_procformatstring_var(file
, indent
, var
, FALSE
);
417 /* emit return value data */
419 if (is_void(var
->type
))
421 print_file(file
, indent
, "0x5b, /* FC_END */\n");
422 print_file(file
, indent
, "0x5c, /* FC_PAD */\n");
425 write_procformatstring_var(file
, indent
, var
, TRUE
);
430 print_file(file
, indent
, "0x0\n");
432 print_file(file
, indent
, "}\n");
434 print_file(file
, indent
, "};\n");
435 print_file(file
, indent
, "\n");
438 static int write_base_type(FILE *file
, const type_t
*type
, unsigned int *typestring_offset
)
440 if (is_base_type(type
->type
))
442 print_file(file
, 2, "0x%02x,\t/* %s */\n", type
->type
, string_of_type(type
->type
));
443 *typestring_offset
+= 1;
450 /* write conformance / variance descriptor */
451 static size_t write_conf_or_var_desc(FILE *file
, const func_t
*func
, const type_t
*structure
,
452 unsigned int baseoff
, const expr_t
*expr
)
454 unsigned char operator_type
= 0;
455 const char *operator_string
= "no operators";
456 const expr_t
*subexpr
;
457 unsigned char correlation_type
;
459 if (!file
) return 4; /* optimisation for sizing pass */
463 if (expr
->cval
> UCHAR_MAX
* (USHRT_MAX
+ 1) + USHRT_MAX
)
464 error("write_conf_or_var_desc: constant value %ld is greater than "
465 "the maximum constant size of %d\n", expr
->cval
,
466 UCHAR_MAX
* (USHRT_MAX
+ 1) + USHRT_MAX
);
468 print_file(file
, 2, "0x%x, /* Corr desc: constant, val = %ld */\n",
469 RPC_FC_CONSTANT_CONFORMANCE
, expr
->cval
);
470 print_file(file
, 2, "0x%x,\n", expr
->cval
& ~USHRT_MAX
);
471 print_file(file
, 2, "NdrFcShort(0x%x),\n", expr
->cval
& USHRT_MAX
);
477 switch (subexpr
->type
)
480 subexpr
= subexpr
->ref
;
481 operator_type
= RPC_FC_DEREFERENCE
;
482 operator_string
= "FC_DEREFERENCE";
485 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 2))
487 subexpr
= subexpr
->ref
;
488 operator_type
= RPC_FC_DIV_2
;
489 operator_string
= "FC_DIV_2";
493 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 2))
495 subexpr
= subexpr
->ref
;
496 operator_type
= RPC_FC_MULT_2
;
497 operator_string
= "FC_MULT_2";
501 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 1))
503 subexpr
= subexpr
->ref
;
504 operator_type
= RPC_FC_SUB_1
;
505 operator_string
= "FC_SUB_1";
509 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 1))
511 subexpr
= subexpr
->ref
;
512 operator_type
= RPC_FC_ADD_1
;
513 operator_string
= "FC_ADD_1";
520 if (subexpr
->type
== EXPR_IDENTIFIER
)
522 const type_t
*correlation_variable
= NULL
;
523 unsigned char correlation_variable_type
;
524 unsigned char param_type
= 0;
525 const char *param_type_string
= NULL
;
533 if (structure
->fields
) LIST_FOR_EACH_ENTRY( var
, structure
->fields
, const var_t
, entry
)
535 unsigned int align
= 0;
536 /* FIXME: take alignment into account */
537 if (!strcmp(var
->name
, subexpr
->u
.sval
))
539 correlation_variable
= var
->type
;
542 offset
+= type_memsize(var
->type
, &align
);
544 if (!correlation_variable
)
545 error("write_conf_or_var_desc: couldn't find variable %s in structure\n",
549 correlation_type
= RPC_FC_NORMAL_CONFORMANCE
;
555 offset
= sizeof(void *);
556 if (func
->args
) LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
558 if (!strcmp(var
->name
, subexpr
->u
.sval
))
560 correlation_variable
= var
->type
;
563 /* FIXME: not all stack variables are sizeof(void *) */
564 offset
+= sizeof(void *);
566 if (!correlation_variable
)
567 error("write_conf_or_var_desc: couldn't find variable %s in function\n",
570 correlation_type
= RPC_FC_TOP_LEVEL_CONFORMANCE
;
573 correlation_variable_type
= correlation_variable
->type
;
575 switch (correlation_variable_type
)
579 param_type
= RPC_FC_SMALL
;
580 param_type_string
= "FC_SMALL";
584 param_type
= RPC_FC_USMALL
;
585 param_type_string
= "FC_USMALL";
589 param_type
= RPC_FC_SHORT
;
590 param_type_string
= "FC_SHORT";
593 param_type
= RPC_FC_USHORT
;
594 param_type_string
= "FC_USHORT";
597 param_type
= RPC_FC_LONG
;
598 param_type_string
= "FC_LONG";
601 param_type
= RPC_FC_ULONG
;
602 param_type_string
= "FC_ULONG";
608 if (sizeof(void *) == 4) /* FIXME */
610 param_type
= RPC_FC_LONG
;
611 param_type_string
= "FC_LONG";
615 param_type
= RPC_FC_HYPER
;
616 param_type_string
= "FC_HYPER";
620 error("write_conf_or_var_desc: conformance variable type not supported 0x%x\n",
621 correlation_variable_type
);
624 print_file(file
, 2, "0x%x, /* Corr desc: %s%s */\n",
625 correlation_type
| param_type
,
626 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "parameter, " : "",
628 print_file(file
, 2, "0x%x, /* %s */\n", operator_type
, operator_string
);
629 print_file(file
, 2, "NdrFcShort(0x%x), /* %soffset = %d */\n",
631 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "x86 stack size / " : "",
636 unsigned int callback_offset
= 0;
640 struct expr_eval_routine
*eval
;
643 LIST_FOR_EACH_ENTRY(eval
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
645 if (!strcmp(eval
->structure
->name
, structure
->name
) &&
646 !compare_expr(eval
->expr
, expr
))
656 unsigned int align
= 0;
657 eval
= xmalloc(sizeof(*eval
));
658 eval
->structure
= structure
;
659 eval
->structure_size
= fields_memsize(structure
->fields
, &align
);
661 list_add_tail(&expr_eval_routines
, &eval
->entry
);
664 correlation_type
= RPC_FC_NORMAL_CONFORMANCE
;
668 error("write_conf_or_var_desc: top-level callback conformance unimplemented\n");
669 correlation_type
= RPC_FC_TOP_LEVEL_CONFORMANCE
;
672 if (callback_offset
> USHRT_MAX
)
673 error("Maximum number of callback routines reached\n");
675 print_file(file
, 2, "0x%x, /* Corr desc: %s */\n",
677 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "parameter" : "");
678 print_file(file
, 2, "0x%x, /* %s */\n", RPC_FC_CALLBACK
, "FC_CALLBACK");
679 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", callback_offset
, callback_offset
);
684 static size_t fields_memsize(const var_list_t
*fields
, unsigned int *align
)
689 if (!fields
) return 0;
690 LIST_FOR_EACH_ENTRY( v
, fields
, const var_t
, entry
)
691 size
+= type_memsize(v
->type
, align
);
696 static size_t union_memsize(const var_list_t
*fields
, unsigned int *pmaxa
)
698 size_t size
, maxs
= 0;
699 unsigned int align
= *pmaxa
;
702 if (fields
) LIST_FOR_EACH_ENTRY( v
, fields
, const var_t
, entry
)
704 /* we could have an empty default field with NULL type */
707 size
= type_memsize(v
->type
, &align
);
708 if (maxs
< size
) maxs
= size
;
709 if (*pmaxa
< align
) *pmaxa
= align
;
716 size_t type_memsize(const type_t
*t
, unsigned int *align
)
720 if (t
->declarray
&& is_conformant_array(t
))
722 type_memsize(t
->ref
, align
);
725 else if (is_ptr(t
) || is_conformant_array(t
))
727 size
= sizeof(void *);
728 if (size
> *align
) *align
= size
;
730 else switch (t
->type
)
737 if (size
> *align
) *align
= size
;
744 if (size
> *align
) *align
= size
;
748 case RPC_FC_ERROR_STATUS_T
:
752 if (size
> *align
) *align
= size
;
757 if (size
> *align
) *align
= size
;
760 case RPC_FC_CVSTRUCT
:
761 case RPC_FC_CPSTRUCT
:
764 case RPC_FC_BOGUS_STRUCT
:
765 size
= fields_memsize(t
->fields
, align
);
767 case RPC_FC_ENCAPSULATED_UNION
:
768 case RPC_FC_NON_ENCAPSULATED_UNION
:
769 size
= union_memsize(t
->fields
, align
);
771 case RPC_FC_SMFARRAY
:
772 case RPC_FC_LGFARRAY
:
773 case RPC_FC_SMVARRAY
:
774 case RPC_FC_LGVARRAY
:
775 case RPC_FC_BOGUS_ARRAY
:
776 size
= t
->dim
* type_memsize(t
->ref
, align
);
779 error("type_memsize: Unknown type %d\n", t
->type
);
786 static unsigned int write_nonsimple_pointer(FILE *file
, const type_t
*type
, size_t offset
)
788 short absoff
= type
->ref
->typestring_offset
;
789 short reloff
= absoff
- (offset
+ 2);
790 int ptr_attr
= is_ptr(type
->ref
) ? 0x10 : 0x0;
792 print_file(file
, 2, "0x%02x, 0x%x,\t/* %s */\n",
793 type
->type
, ptr_attr
, string_of_type(type
->type
));
794 print_file(file
, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%hd) */\n",
795 reloff
, reloff
, absoff
);
799 static unsigned int write_simple_pointer(FILE *file
, const type_t
*type
)
801 print_file(file
, 2, "0x%02x, 0x8,\t/* %s [simple_pointer] */\n",
802 type
->type
, string_of_type(type
->type
));
803 print_file(file
, 2, "0x%02x,\t/* %s */\n", type
->ref
->type
,
804 string_of_type(type
->ref
->type
));
805 print_file(file
, 2, "0x5c,\t/* FC_PAD */\n");
809 static size_t write_pointer_tfs(FILE *file
, type_t
*type
, unsigned int *typestring_offset
)
811 unsigned int offset
= *typestring_offset
;
813 print_file(file
, 0, "/* %d */\n", offset
);
814 update_tfsoff(type
, offset
, file
);
816 if (type
->ref
->typestring_offset
)
817 *typestring_offset
+= write_nonsimple_pointer(file
, type
, offset
);
818 else if (is_base_type(type
->ref
->type
))
819 *typestring_offset
+= write_simple_pointer(file
, type
);
824 static int processed(const type_t
*type
)
826 return type
->typestring_offset
&& !type
->tfswrite
;
829 static void write_user_tfs(FILE *file
, type_t
*type
, unsigned int *tfsoff
)
831 unsigned int start
, absoff
, flags
;
832 unsigned int align
= 0, ualign
= 0;
834 type_t
*utype
= get_user_type(type
, &name
);
835 size_t usize
= type_memsize(utype
, &ualign
);
836 size_t size
= type_memsize(type
, &align
);
837 unsigned short funoff
= user_type_offset(name
);
842 if (is_base_type(utype
->type
))
845 print_file(file
, 0, "/* %d */\n", absoff
);
846 print_file(file
, 2, "0x%x,\t/* %s */\n", utype
->type
, string_of_type(utype
->type
));
847 print_file(file
, 2, "0x5c,\t/* FC_PAD */\n");
852 if (!processed(utype
))
853 write_embedded_types(file
, NULL
, utype
, utype
->name
, TRUE
, tfsoff
);
854 absoff
= utype
->typestring_offset
;
857 if (utype
->type
== RPC_FC_RP
)
859 else if (utype
->type
== RPC_FC_UP
)
865 update_tfsoff(type
, start
, file
);
866 print_file(file
, 0, "/* %d */\n", start
);
867 print_file(file
, 2, "0x%x,\t/* FC_USER_MARSHAL */\n", RPC_FC_USER_MARSHAL
);
868 print_file(file
, 2, "0x%x,\t/* Alignment= %d, Flags= %02x */\n",
869 flags
| (align
- 1), align
- 1, flags
);
870 print_file(file
, 2, "NdrFcShort(0x%hx),\t/* Function offset= %hu */\n", funoff
, funoff
);
871 print_file(file
, 2, "NdrFcShort(0x%lx),\t/* %lu */\n", usize
, usize
);
872 print_file(file
, 2, "NdrFcShort(0x%lx),\t/* %lu */\n", size
, size
);
874 reloff
= absoff
- *tfsoff
;
875 print_file(file
, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%lu) */\n", reloff
, reloff
, absoff
);
879 static void write_member_type(FILE *file
, type_t
*type
, const var_t
*field
,
880 unsigned int *corroff
, unsigned int *tfsoff
)
884 print_file(file
, 2, "0x8,\t/* FC_LONG */\n");
887 else if (is_embedded_complex(type
))
892 if (is_union(type
->type
) && is_attr(field
->attrs
, ATTR_SWITCHIS
))
899 absoff
= type
->typestring_offset
;
901 reloff
= absoff
- (*tfsoff
+ 2);
903 print_file(file
, 2, "0x4c,\t/* FC_EMBEDDED_COMPLEX */\n");
904 /* FIXME: actually compute necessary padding */
905 print_file(file
, 2, "0x0,\t/* FIXME: padding */\n");
906 print_file(file
, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%lu) */\n",
907 reloff
, reloff
, absoff
);
910 else if (!write_base_type(file
, type
, tfsoff
))
911 error("Unsupported member type 0x%x\n", type
->type
);
914 static void write_end(FILE *file
, unsigned int *tfsoff
)
916 if (*tfsoff
% 2 == 0)
918 print_file(file
, 2, "0x%x,\t\t/* FC_PAD */\n", RPC_FC_PAD
);
921 print_file(file
, 2, "0x%x,\t\t/* FC_END */\n", RPC_FC_END
);
925 static void write_descriptors(FILE *file
, type_t
*type
, unsigned int *tfsoff
)
927 unsigned int offset
= 0;
928 var_list_t
*fs
= type
->fields
;
931 if (fs
) LIST_FOR_EACH_ENTRY(f
, fs
, var_t
, entry
)
933 unsigned int align
= 0;
934 type_t
*ft
= f
->type
;
935 if (is_union(ft
->type
) && is_attr(f
->attrs
, ATTR_SWITCHIS
))
937 unsigned int absoff
= ft
->typestring_offset
;
938 short reloff
= absoff
- (*tfsoff
+ 6);
939 print_file(file
, 0, "/* %d */\n", *tfsoff
);
940 print_file(file
, 2, "0x%x,\t/* %s */\n", ft
->type
, string_of_type(ft
->type
));
941 print_file(file
, 2, "0x%x,\t/* FIXME: always FC_LONG */\n", RPC_FC_LONG
);
942 write_conf_or_var_desc(file
, current_func
, current_structure
, offset
,
943 get_attrp(f
->attrs
, ATTR_SWITCHIS
));
944 print_file(file
, 2, "NdrFcShort(%hd),\t/* Offset= %hd (%u) */\n",
945 reloff
, reloff
, absoff
);
949 /* FIXME: take alignment into account */
950 offset
+= type_memsize(ft
, &align
);
954 static size_t write_pointer_description(FILE *file
, type_t
*type
, size_t mem_offset
,
955 int level
, unsigned int *typestring_offset
)
958 unsigned int align
= 0;
960 /* don't generate a pointer for first-level arrays since we want to
961 * descend into them to write their pointers, not stop here */
962 if (level
== 0 && is_array(type
))
964 write_pointer_description(file
, type
->ref
, mem_offset
, level
+ 1,
967 else if (is_ptr(type
))
969 print_file(file
, 2, "0x46,\t/* FC_NO_REPEAT */\n");
970 print_file(file
, 2, "0x5c,\t/* FC_PAD */\n");
971 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", mem_offset
, mem_offset
);
972 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", mem_offset
, mem_offset
);
973 *typestring_offset
+= 6;
975 if (processed(type
->ref
) || is_base_type(type
->ref
->type
))
976 write_pointer_tfs(file
, type
, typestring_offset
);
978 error("write_pointer_description: type format string unknown\n");
980 else if (level
== 0 && is_struct(type
->type
))
984 LIST_FOR_EACH_ENTRY( v
, type
->fields
, const var_t
, entry
)
986 += write_pointer_description(file
, v
->type
, mem_offset
,
987 level
+ 1, typestring_offset
);
991 return type_memsize(type
, &align
);
994 static size_t write_string_tfs(FILE *file
, const attr_list_t
*attrs
,
996 const char *name
, unsigned int *typestring_offset
)
998 size_t start_offset
= *typestring_offset
;
999 unsigned char flags
= 0;
1001 unsigned char rtype
;
1005 pointer_type
= type
->type
;
1009 pointer_type
= get_attrv(attrs
, ATTR_POINTERTYPE
);
1012 pointer_type
= RPC_FC_RP
;
1014 if (!get_attrp(attrs
, ATTR_SIZEIS
))
1015 flags
|= RPC_FC_P_SIMPLEPOINTER
;
1019 if ((rtype
!= RPC_FC_BYTE
) && (rtype
!= RPC_FC_CHAR
) && (rtype
!= RPC_FC_WCHAR
))
1021 error("write_string_tfs: Unimplemented for type 0x%x of name: %s\n", rtype
, name
);
1022 return start_offset
;
1025 print_file(file
, 2,"0x%x, 0x%x, /* %s%s */\n",
1026 pointer_type
, flags
,
1027 pointer_type
== RPC_FC_FP
? "FC_FP" : (pointer_type
== RPC_FC_UP
? "FC_UP" : "FC_RP"),
1028 (flags
& RPC_FC_P_SIMPLEPOINTER
) ? " [simple_pointer]" : "");
1029 *typestring_offset
+= 2;
1031 if (!(flags
& RPC_FC_P_SIMPLEPOINTER
))
1033 print_file(file
, 2, "NdrFcShort(0x2),\n");
1034 *typestring_offset
+= 2;
1037 if (type
->declarray
&& !is_conformant_array(type
))
1039 /* FIXME: multi-dimensional array */
1040 if (0xffffuL
< type
->dim
)
1041 error("array size for parameter %s exceeds %u bytes by %lu bytes\n",
1042 name
, 0xffffu
, type
->dim
- 0xffffu
);
1044 if (rtype
== RPC_FC_CHAR
)
1045 WRITE_FCTYPE(file
, FC_CSTRING
, *typestring_offset
);
1047 WRITE_FCTYPE(file
, FC_WSTRING
, *typestring_offset
);
1048 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1049 *typestring_offset
+= 2;
1051 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", type
->dim
, type
->dim
);
1052 *typestring_offset
+= 2;
1054 return start_offset
;
1056 else if (type
->size_is
)
1058 unsigned int align
= 0;
1060 if (rtype
== RPC_FC_CHAR
)
1061 WRITE_FCTYPE(file
, FC_C_CSTRING
, *typestring_offset
);
1063 WRITE_FCTYPE(file
, FC_C_WSTRING
, *typestring_offset
);
1064 print_file(file
, 2, "0x%x, /* FC_STRING_SIZED */\n", RPC_FC_STRING_SIZED
);
1065 *typestring_offset
+= 2;
1067 *typestring_offset
+= write_conf_or_var_desc(
1068 file
, current_func
, current_structure
,
1069 (type
->declarray
&& current_structure
1070 ? type_memsize(current_structure
, &align
)
1074 return start_offset
;
1078 if (rtype
== RPC_FC_CHAR
)
1079 WRITE_FCTYPE(file
, FC_C_CSTRING
, *typestring_offset
);
1081 WRITE_FCTYPE(file
, FC_C_WSTRING
, *typestring_offset
);
1082 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1083 *typestring_offset
+= 2;
1085 return start_offset
;
1089 static size_t write_array_tfs(FILE *file
, const attr_list_t
*attrs
, type_t
*type
,
1090 const char *name
, unsigned int *typestring_offset
)
1092 const expr_t
*length_is
= type
->length_is
;
1093 const expr_t
*size_is
= type
->size_is
;
1094 unsigned int align
= 0;
1096 size_t start_offset
;
1098 int pointer_type
= get_attrv(attrs
, ATTR_POINTERTYPE
);
1100 pointer_type
= RPC_FC_RP
;
1102 has_pointer
= FALSE
;
1103 if (write_embedded_types(file
, attrs
, type
->ref
, name
, FALSE
, typestring_offset
))
1106 size
= type_memsize(type
, &align
);
1107 if (size
== 0) /* conformant array */
1108 size
= type_memsize(type
->ref
, &align
);
1110 start_offset
= *typestring_offset
;
1111 update_tfsoff(type
, start_offset
, file
);
1112 print_file(file
, 0, "/* %lu */\n", start_offset
);
1113 print_file(file
, 2, "0x%02x,\t/* %s */\n", type
->type
, string_of_type(type
->type
));
1114 print_file(file
, 2, "0x%x,\t/* %d */\n", align
- 1, align
- 1);
1115 *typestring_offset
+= 2;
1118 if (type
->type
!= RPC_FC_BOGUS_ARRAY
)
1120 unsigned char tc
= type
->type
;
1121 unsigned int baseoff
1122 = type
->declarray
&& current_structure
1123 ? type_memsize(current_structure
, &align
)
1126 if (tc
== RPC_FC_LGFARRAY
|| tc
== RPC_FC_LGVARRAY
)
1128 print_file(file
, 2, "NdrFcLong(0x%x),\t/* %lu */\n", size
, size
);
1129 *typestring_offset
+= 4;
1133 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %lu */\n", size
, size
);
1134 *typestring_offset
+= 2;
1137 if (is_conformant_array(type
))
1139 += write_conf_or_var_desc(file
, current_func
, current_structure
,
1142 if (type
->type
== RPC_FC_SMVARRAY
|| type
->type
== RPC_FC_LGVARRAY
)
1144 unsigned int elalign
= 0;
1145 size_t elsize
= type_memsize(type
->ref
, &elalign
);
1147 if (type
->type
== RPC_FC_LGVARRAY
)
1149 print_file(file
, 2, "NdrFcLong(0x%x),\t/* %lu */\n", type
->dim
, type
->dim
);
1150 *typestring_offset
+= 4;
1154 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %lu */\n", type
->dim
, type
->dim
);
1155 *typestring_offset
+= 2;
1158 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %lu */\n", elsize
, elsize
);
1159 *typestring_offset
+= 2;
1164 += write_conf_or_var_desc(file
, current_func
, current_structure
,
1165 baseoff
, length_is
);
1169 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1170 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1171 *typestring_offset
+= 2;
1172 write_pointer_description(file
, type
, 0, 0, typestring_offset
);
1173 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1174 *typestring_offset
+= 1;
1177 write_member_type(file
, type
->ref
, NULL
, NULL
, typestring_offset
);
1178 write_end(file
, typestring_offset
);
1181 error("%s: complex arrays unimplemented\n", name
);
1183 return start_offset
;
1186 static const var_t
*find_array_or_string_in_struct(const type_t
*type
)
1188 const var_t
*last_field
= LIST_ENTRY( list_tail(type
->fields
), const var_t
, entry
);
1189 const type_t
*ft
= last_field
->type
;
1191 if (ft
->declarray
&& is_conformant_array(ft
))
1194 if (ft
->type
== RPC_FC_CSTRUCT
|| ft
->type
== RPC_FC_CPSTRUCT
|| ft
->type
== RPC_FC_CVSTRUCT
)
1195 return find_array_or_string_in_struct(last_field
->type
);
1200 static void write_struct_members(FILE *file
, const type_t
*type
,
1201 unsigned int *corroff
, unsigned int *typestring_offset
)
1205 if (type
->fields
) LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1207 type_t
*ft
= field
->type
;
1208 if (!ft
->declarray
|| !is_conformant_array(ft
))
1209 write_member_type(file
, ft
, field
, corroff
, typestring_offset
);
1212 write_end(file
, typestring_offset
);
1215 static size_t write_struct_tfs(FILE *file
, type_t
*type
,
1216 const char *name
, unsigned int *tfsoff
)
1218 const type_t
*save_current_structure
= current_structure
;
1219 unsigned int total_size
;
1221 size_t start_offset
;
1222 size_t array_offset
;
1223 int has_pointers
= 0;
1224 unsigned int align
= 0;
1225 unsigned int corroff
;
1229 current_structure
= type
;
1231 total_size
= type_memsize(type
, &align
);
1232 if (total_size
> USHRT_MAX
)
1233 error("structure size for %s exceeds %d bytes by %d bytes\n",
1234 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
1236 if (type
->fields
) LIST_FOR_EACH_ENTRY(f
, type
->fields
, var_t
, entry
)
1237 has_pointers
|= write_embedded_types(file
, f
->attrs
, f
->type
, f
->name
,
1240 array
= find_array_or_string_in_struct(type
);
1241 if (array
&& !processed(array
->type
))
1243 = is_attr(array
->attrs
, ATTR_STRING
)
1244 ? write_string_tfs(file
, array
->attrs
, array
->type
, array
->name
, tfsoff
)
1245 : write_array_tfs(file
, array
->attrs
, array
->type
, array
->name
, tfsoff
);
1248 write_descriptors(file
, type
, tfsoff
);
1250 start_offset
= *tfsoff
;
1251 update_tfsoff(type
, start_offset
, file
);
1252 print_file(file
, 0, "/* %d */\n", start_offset
);
1253 print_file(file
, 2, "0x%x,\t/* %s */\n", type
->type
, string_of_type(type
->type
));
1254 print_file(file
, 2, "0x%x,\t/* %d */\n", align
- 1, align
- 1);
1255 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", total_size
, total_size
);
1260 unsigned int absoff
= array
->type
->typestring_offset
;
1261 short reloff
= absoff
- *tfsoff
;
1262 print_file(file
, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%lu) */\n",
1263 reloff
, reloff
, absoff
);
1266 else if (type
->type
== RPC_FC_BOGUS_STRUCT
)
1268 print_file(file
, 2, "NdrFcShort(0x0),\n");
1272 if (type
->type
== RPC_FC_BOGUS_STRUCT
)
1275 print_file(file
, 2, "NdrFcShort(0x0),\t/* FIXME: pointer stuff */\n");
1278 else if (has_pointers
)
1280 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1281 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1283 write_pointer_description(file
, type
, 0, 0, tfsoff
);
1284 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1288 write_struct_members(file
, type
, &corroff
, tfsoff
);
1290 current_structure
= save_current_structure
;
1291 return start_offset
;
1294 static size_t write_pointer_only_tfs(FILE *file
, const attr_list_t
*attrs
, int pointer_type
,
1295 unsigned char flags
, size_t offset
,
1296 unsigned int *typeformat_offset
)
1298 size_t start_offset
= *typeformat_offset
;
1299 short reloff
= offset
- (*typeformat_offset
+ 2);
1300 int in_attr
, out_attr
;
1301 in_attr
= is_attr(attrs
, ATTR_IN
);
1302 out_attr
= is_attr(attrs
, ATTR_OUT
);
1303 if (!in_attr
&& !out_attr
) in_attr
= 1;
1305 if (out_attr
&& !in_attr
&& pointer_type
== RPC_FC_RP
)
1308 print_file(file
, 2, "0x%x, 0x%x,\t\t/* %s",
1311 string_of_type(pointer_type
));
1315 fprintf(file
, " [allocated_on_stack]");
1317 fprintf(file
, " [pointer_deref]");
1318 fprintf(file
, " */\n");
1321 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", reloff
, offset
);
1322 *typeformat_offset
+= 4;
1324 return start_offset
;
1327 static void write_branch_type(FILE *file
, const type_t
*t
, unsigned int *tfsoff
)
1329 if (is_base_type(t
->type
))
1331 print_file(file
, 2, "NdrFcShort(0x80%02x),\t/* Simple arm type: %s */\n",
1332 t
->type
, string_of_type(t
->type
));
1334 else if (t
->typestring_offset
)
1336 short reloff
= t
->typestring_offset
- *tfsoff
;
1337 print_file(file
, 2, "NdrFcShort(0x%x),\t/* Offset= %d (%d) */\n",
1338 reloff
, reloff
, t
->typestring_offset
);
1341 error("write_branch_type: type unimplemented (0x%x)\n", t
->type
);
1346 static size_t write_union_tfs(FILE *file
, type_t
*type
, unsigned int *tfsoff
)
1348 unsigned int align
= 0;
1349 unsigned int start_offset
;
1350 size_t size
= type_memsize(type
, &align
);
1351 var_list_t
*fields
= type
->fields
;
1353 type_t
*deftype
= NULL
;
1354 short nodeftype
= 0xffff;
1359 if (fields
) LIST_FOR_EACH_ENTRY(f
, fields
, var_t
, entry
)
1361 expr_list_t
*cases
= get_attrp(f
->attrs
, ATTR_CASE
);
1363 nbranch
+= list_count(cases
);
1365 write_embedded_types(file
, f
->attrs
, f
->type
, f
->name
, TRUE
, tfsoff
);
1368 start_offset
= *tfsoff
;
1369 update_tfsoff(type
, start_offset
, file
);
1370 print_file(file
, 0, "/* %d */\n", start_offset
);
1371 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", size
, size
);
1372 print_file(file
, 2, "NdrFcShort(0x%x),\t/* %d */\n", nbranch
, nbranch
);
1375 if (fields
) LIST_FOR_EACH_ENTRY(f
, fields
, var_t
, entry
)
1377 type_t
*ft
= f
->type
;
1378 expr_list_t
*cases
= get_attrp(f
->attrs
, ATTR_CASE
);
1379 int deflt
= is_attr(f
->attrs
, ATTR_DEFAULT
);
1382 if (cases
== NULL
&& !deflt
)
1383 error("union field %s with neither case nor default attribute\n", f
->name
);
1385 if (cases
) LIST_FOR_EACH_ENTRY(c
, cases
, expr_t
, entry
)
1387 /* MIDL doesn't check for duplicate cases, even though that seems
1388 like a reasonable thing to do, it just dumps them to the TFS
1389 like we're going to do here. */
1390 print_file(file
, 2, "NdrFcLong(0x%x),\t/* %d */\n", c
->cval
, c
->cval
);
1392 write_branch_type(file
, ft
, tfsoff
);
1395 /* MIDL allows multiple default branches, even though that seems
1396 illogical, it just chooses the last one, which is what we will
1407 write_branch_type(file
, deftype
, tfsoff
);
1411 print_file(file
, 2, "NdrFcShort(0x%x),\n", nodeftype
);
1415 return start_offset
;
1418 static size_t write_ip_tfs(FILE *file
, const func_t
*func
, const type_t
*type
, const var_t
*var
,
1419 unsigned int *typeformat_offset
)
1422 size_t start_offset
= *typeformat_offset
;
1423 const var_t
*iid
= get_attrp(var
->attrs
, ATTR_IIDIS
);
1429 expr
.type
= EXPR_IDENTIFIER
;
1431 expr
.u
.sval
= iid
->name
;
1432 expr
.is_const
= FALSE
;
1433 print_file(file
, 2, "0x2f, /* FC_IP */\n");
1434 print_file(file
, 2, "0x5c, /* FC_PAD */\n");
1435 *typeformat_offset
+= write_conf_or_var_desc(file
, func
, NULL
, 0, &expr
) + 2;
1439 const type_t
*base
= is_ptr(type
) ? type
->ref
: type
;
1440 const UUID
*uuid
= get_attrp(base
->attrs
, ATTR_UUID
);
1443 error("%s: interface %s missing UUID\n", __FUNCTION__
, base
->name
);
1445 print_file(file
, 2, "0x2f,\t/* FC_IP */\n");
1446 print_file(file
, 2, "0x5a,\t/* FC_CONSTANT_IID */\n");
1447 print_file(file
, 2, "NdrFcLong(0x%08lx),\n", uuid
->Data1
);
1448 print_file(file
, 2, "NdrFcShort(0x%04x),\n", uuid
->Data2
);
1449 print_file(file
, 2, "NdrFcShort(0x%04x),\n", uuid
->Data3
);
1450 for (i
= 0; i
< 8; ++i
)
1451 print_file(file
, 2, "0x%02x,\n", uuid
->Data4
[i
]);
1454 fprintf(file
, "\n");
1456 *typeformat_offset
+= 18;
1458 return start_offset
;
1461 static int get_ptr_attr(const type_t
*t
, int def_type
)
1465 int ptr_attr
= get_attrv(t
->attrs
, ATTR_POINTERTYPE
);
1468 if (t
->kind
!= TKIND_ALIAS
)
1474 static size_t write_typeformatstring_var(FILE *file
, int indent
, const func_t
*func
,
1475 type_t
*type
, const var_t
*var
,
1476 unsigned int *typeformat_offset
)
1481 if (is_user_type(type
))
1483 write_user_tfs(file
, type
, typeformat_offset
);
1484 return type
->typestring_offset
;
1487 if (type
== var
->type
) /* top-level pointers */
1489 int pointer_attr
= get_attrv(var
->attrs
, ATTR_POINTERTYPE
);
1490 if (pointer_attr
!= 0 && !is_ptr(type
) && !is_array(type
))
1491 error("'%s': pointer attribute applied to non-pointer type\n", var
->name
);
1493 if (pointer_attr
== 0)
1494 pointer_attr
= get_ptr_attr(type
, RPC_FC_RP
);
1496 pointer_type
= pointer_attr
;
1499 pointer_type
= get_ptr_attr(type
, RPC_FC_UP
);
1501 if ((last_ptr(type
) || last_array(type
)) && is_ptrchain_attr(var
, ATTR_STRING
))
1502 return write_string_tfs(file
, var
->attrs
, type
, var
->name
, typeformat_offset
);
1505 return write_array_tfs(file
, var
->attrs
, type
, var
->name
, typeformat_offset
);
1509 /* basic types don't need a type format string */
1510 if (is_base_type(type
->type
))
1516 case RPC_FC_PSTRUCT
:
1517 case RPC_FC_CSTRUCT
:
1518 case RPC_FC_CPSTRUCT
:
1519 case RPC_FC_CVSTRUCT
:
1520 case RPC_FC_BOGUS_STRUCT
:
1521 return write_struct_tfs(file
, type
, var
->name
, typeformat_offset
);
1522 case RPC_FC_ENCAPSULATED_UNION
:
1523 case RPC_FC_NON_ENCAPSULATED_UNION
:
1524 return write_union_tfs(file
, type
, typeformat_offset
);
1526 case RPC_FC_BIND_PRIMITIVE
:
1530 error("write_typeformatstring_var: Unsupported type 0x%x for variable %s\n", type
->type
, var
->name
);
1533 else if (last_ptr(type
))
1535 size_t start_offset
= *typeformat_offset
;
1536 int in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1537 int out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1538 const type_t
*base
= type
->ref
;
1540 if (base
->type
== RPC_FC_IP
)
1542 return write_ip_tfs(file
, func
, type
, var
, typeformat_offset
);
1545 /* special case for pointers to base types */
1546 if (is_base_type(base
->type
))
1548 print_file(file
, indent
, "0x%x, 0x%x, /* %s %s[simple_pointer] */\n",
1549 pointer_type
, (!in_attr
&& out_attr
) ? 0x0C : 0x08,
1550 string_of_type(pointer_type
),
1551 (!in_attr
&& out_attr
) ? "[allocated_on_stack] " : "");
1552 print_file(file
, indent
, "0x%02x, /* %s */\n", base
->type
, string_of_type(base
->type
));
1553 print_file(file
, indent
, "0x5c, /* FC_PAD */\n");
1554 *typeformat_offset
+= 4;
1555 return start_offset
;
1559 assert(is_ptr(type
));
1561 offset
= write_typeformatstring_var(file
, indent
, func
, type
->ref
, var
, typeformat_offset
);
1563 fprintf(file
, "/* %2u */\n", *typeformat_offset
);
1564 return write_pointer_only_tfs(file
, var
->attrs
, pointer_type
,
1565 !last_ptr(type
) ? 0x10 : 0,
1566 offset
, typeformat_offset
);
1569 static void set_tfswrite(type_t
*type
, int val
)
1571 while (type
->tfswrite
!= val
)
1573 type_t
*utype
= get_user_type(type
, NULL
);
1575 type
->tfswrite
= val
;
1578 set_tfswrite(utype
, val
);
1580 if (type
->kind
== TKIND_ALIAS
)
1582 else if (is_ptr(type
) || is_array(type
))
1589 LIST_FOR_EACH_ENTRY( v
, type
->fields
, var_t
, entry
)
1591 set_tfswrite(v
->type
, val
);
1599 static int write_embedded_types(FILE *file
, const attr_list_t
*attrs
, type_t
*type
,
1600 const char *name
, int write_ptr
, unsigned int *tfsoff
)
1604 if (is_user_type(type
))
1606 write_user_tfs(file
, type
, tfsoff
);
1608 else if (is_ptr(type
))
1610 type_t
*ref
= type
->ref
;
1612 if (!processed(ref
) && !is_base_type(ref
->type
))
1613 retmask
|= write_embedded_types(file
, NULL
, ref
, name
, TRUE
, tfsoff
);
1615 /* top-level pointers are handled inline for structures */
1617 write_pointer_tfs(file
, type
, tfsoff
);
1621 else if (type
->declarray
&& is_conformant_array(type
))
1622 ; /* conformant arrays and strings are handled specially */
1623 else if (is_array(type
))
1625 write_array_tfs(file
, attrs
, type
, name
, tfsoff
);
1627 else if (is_struct(type
->type
))
1629 if (!processed(type
))
1630 write_struct_tfs(file
, type
, name
, tfsoff
);
1632 else if (is_union(type
->type
))
1634 if (!processed(type
))
1635 write_union_tfs(file
, type
, tfsoff
);
1637 else if (!is_base_type(type
->type
))
1638 error("write_embedded_types: unknown embedded type for %s (0x%x)\n",
1644 static void set_all_tfswrite(const ifref_list_t
*ifaces
, int val
)
1646 const ifref_t
* iface
;
1651 LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
1652 if (iface
->iface
->funcs
)
1653 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
1655 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1656 set_tfswrite(var
->type
, val
);
1659 static size_t process_tfs(FILE *file
, const ifref_list_t
*ifaces
, int for_objects
)
1662 const ifref_t
*iface
;
1663 unsigned int typeformat_offset
= 2;
1665 if (ifaces
) LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
1667 if (for_objects
!= is_object(iface
->iface
->attrs
) || is_local(iface
->iface
->attrs
))
1670 if (iface
->iface
->funcs
)
1673 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
1675 if (is_local(func
->def
->attrs
)) continue;
1677 current_func
= func
;
1679 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1682 write_typeformatstring_var(
1683 file
, 2, func
, var
->type
, var
,
1684 &typeformat_offset
),
1690 return typeformat_offset
+ 1;
1694 void write_typeformatstring(FILE *file
, const ifref_list_t
*ifaces
, int for_objects
)
1698 print_file(file
, indent
, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
1699 print_file(file
, indent
, "{\n");
1701 print_file(file
, indent
, "0,\n");
1702 print_file(file
, indent
, "{\n");
1704 print_file(file
, indent
, "NdrFcShort(0x0),\n");
1706 set_all_tfswrite(ifaces
, TRUE
);
1707 process_tfs(file
, ifaces
, for_objects
);
1709 print_file(file
, indent
, "0x0\n");
1711 print_file(file
, indent
, "}\n");
1713 print_file(file
, indent
, "};\n");
1714 print_file(file
, indent
, "\n");
1717 static unsigned int get_required_buffer_size_type(
1718 const type_t
*type
, const char *name
, unsigned int *alignment
)
1745 case RPC_FC_ERROR_STATUS_T
:
1757 case RPC_FC_BIND_PRIMITIVE
:
1761 case RPC_FC_PSTRUCT
:
1764 if (!type
->fields
) return 0;
1765 LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1767 unsigned int alignment
;
1768 size
+= get_required_buffer_size_type(field
->type
, field
->name
,
1775 if (is_base_type( type
->ref
->type
) || type
->ref
->type
== RPC_FC_STRUCT
)
1776 size
= get_required_buffer_size_type( type
->ref
, name
, alignment
);
1779 case RPC_FC_SMFARRAY
:
1780 case RPC_FC_LGFARRAY
:
1781 size
= type
->dim
* get_required_buffer_size_type(type
->ref
, name
, alignment
);
1784 case RPC_FC_SMVARRAY
:
1785 case RPC_FC_LGVARRAY
:
1786 get_required_buffer_size_type(type
->ref
, name
, alignment
);
1791 case RPC_FC_CVARRAY
:
1792 get_required_buffer_size_type(type
->ref
, name
, alignment
);
1793 size
= sizeof(void *);
1797 error("get_required_buffer_size: Unknown/unsupported type: %s (0x%02x)\n", name
, type
->type
);
1804 static unsigned int get_required_buffer_size(const var_t
*var
, unsigned int *alignment
, enum pass pass
)
1806 int in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1807 int out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1809 if (!in_attr
&& !out_attr
)
1814 if (pass
== PASS_OUT
)
1816 if (out_attr
&& is_ptr(var
->type
))
1818 type_t
*type
= var
->type
;
1820 if (type
->type
== RPC_FC_STRUCT
)
1823 unsigned int size
= 36;
1825 if (!type
->fields
) return size
;
1826 LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1829 size
+= get_required_buffer_size_type(
1830 field
->type
, field
->name
, &align
);
1839 if ((!out_attr
|| in_attr
) && !var
->type
->size_is
1840 && !is_attr(var
->attrs
, ATTR_STRING
) && !var
->type
->declarray
)
1842 if (is_ptr(var
->type
))
1844 type_t
*type
= var
->type
;
1846 if (is_base_type(type
->type
))
1850 else if (type
->type
== RPC_FC_STRUCT
)
1852 unsigned int size
= 36;
1855 if (!type
->fields
) return size
;
1856 LIST_FOR_EACH_ENTRY( field
, type
->fields
, const var_t
, entry
)
1859 size
+= get_required_buffer_size_type(
1860 field
->type
, field
->name
, &align
);
1867 return get_required_buffer_size_type(var
->type
, var
->name
, alignment
);
1871 static unsigned int get_function_buffer_size( const func_t
*func
, enum pass pass
)
1874 unsigned int total_size
= 0, alignment
;
1878 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
1880 total_size
+= get_required_buffer_size(var
, &alignment
, pass
);
1881 total_size
+= alignment
;
1885 if (pass
== PASS_OUT
&& !is_void(func
->def
->type
))
1887 total_size
+= get_required_buffer_size(func
->def
, &alignment
, PASS_RETURN
);
1888 total_size
+= alignment
;
1893 static void print_phase_function(FILE *file
, int indent
, const char *type
,
1894 enum remoting_phase phase
,
1895 const var_t
*var
, unsigned int type_offset
)
1897 const char *function
;
1900 case PHASE_BUFFERSIZE
:
1901 function
= "BufferSize";
1904 function
= "Marshall";
1906 case PHASE_UNMARSHAL
:
1907 function
= "Unmarshall";
1917 print_file(file
, indent
, "Ndr%s%s(\n", type
, function
);
1919 print_file(file
, indent
, "&_StubMsg,\n");
1920 print_file(file
, indent
, "%s%s%s%s,\n",
1921 (phase
== PHASE_UNMARSHAL
) ? "(unsigned char **)" : "(unsigned char *)",
1922 (phase
== PHASE_UNMARSHAL
|| decl_indirect(var
->type
)) ? "&" : "",
1923 (phase
== PHASE_UNMARSHAL
&& decl_indirect(var
->type
)) ? "_p_" : "",
1925 print_file(file
, indent
, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]%s\n",
1926 type_offset
, (phase
== PHASE_UNMARSHAL
) ? "," : ");");
1927 if (phase
== PHASE_UNMARSHAL
)
1928 print_file(file
, indent
, "0);\n");
1932 void print_phase_basetype(FILE *file
, int indent
, enum remoting_phase phase
,
1933 enum pass pass
, const var_t
*var
,
1934 const char *varname
)
1936 type_t
*type
= var
->type
;
1938 unsigned int alignment
= 0;
1939 unsigned char rtype
;
1941 /* no work to do for other phases, buffer sizing is done elsewhere */
1942 if (phase
!= PHASE_MARSHAL
&& phase
!= PHASE_UNMARSHAL
)
1945 rtype
= is_ptr(type
) ? type
->ref
->type
: type
->type
;
1967 case RPC_FC_ERROR_STATUS_T
:
1979 case RPC_FC_BIND_PRIMITIVE
:
1980 /* no marshalling needed */
1984 error("print_phase_basetype: Unsupported type: %s (0x%02x, ptr_level: 0)\n", var
->name
, rtype
);
1988 print_file(file
, indent
, "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + %u) & ~0x%x);\n",
1989 alignment
- 1, alignment
- 1);
1991 if (phase
== PHASE_MARSHAL
)
1993 print_file(file
, indent
, "*(");
1994 write_type(file
, is_ptr(type
) ? type
->ref
: type
, FALSE
, NULL
);
1996 fprintf(file
, " *)_StubMsg.Buffer = *");
1998 fprintf(file
, " *)_StubMsg.Buffer = ");
1999 fprintf(file
, varname
);
2000 fprintf(file
, ";\n");
2002 else if (phase
== PHASE_UNMARSHAL
)
2004 if (pass
== PASS_IN
|| pass
== PASS_RETURN
)
2005 print_file(file
, indent
, "");
2007 print_file(file
, indent
, "*");
2008 fprintf(file
, varname
);
2009 if (pass
== PASS_IN
&& is_ptr(type
))
2010 fprintf(file
, " = (");
2012 fprintf(file
, " = *(");
2013 write_type(file
, is_ptr(type
) ? type
->ref
: type
, FALSE
, NULL
);
2014 fprintf(file
, " *)_StubMsg.Buffer;\n");
2017 print_file(file
, indent
, "_StubMsg.Buffer += sizeof(");
2018 write_type(file
, var
->type
, FALSE
, NULL
);
2019 fprintf(file
, ");\n");
2022 /* returns whether the MaxCount, Offset or ActualCount members need to be
2023 * filled in for the specified phase */
2024 static inline int is_size_needed_for_phase(enum remoting_phase phase
)
2026 return (phase
!= PHASE_UNMARSHAL
);
2029 void write_remoting_arguments(FILE *file
, int indent
, const func_t
*func
,
2030 enum pass pass
, enum remoting_phase phase
)
2032 int in_attr
, out_attr
, pointer_type
;
2038 if (phase
== PHASE_BUFFERSIZE
)
2040 unsigned int size
= get_function_buffer_size( func
, pass
);
2041 print_file(file
, indent
, "_StubMsg.BufferLength = %u;\n", size
);
2044 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2046 const type_t
*type
= var
->type
;
2047 unsigned char rtype
;
2048 size_t start_offset
= type
->typestring_offset
;
2050 pointer_type
= get_attrv(var
->attrs
, ATTR_POINTERTYPE
);
2052 pointer_type
= RPC_FC_RP
;
2054 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
2055 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
2056 if (!in_attr
&& !out_attr
)
2062 if (!in_attr
) continue;
2065 if (!out_attr
) continue;
2073 if (is_user_type(var
->type
))
2075 print_phase_function(file
, indent
, "UserMarshal", phase
, var
, start_offset
);
2077 else if (is_string_type(var
->attrs
, var
->type
))
2079 if (is_array(type
) && !is_conformant_array(type
))
2080 print_phase_function(file
, indent
, "NonConformantString", phase
, var
, start_offset
);
2083 if (type
->size_is
&& is_size_needed_for_phase(phase
))
2085 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
2086 write_expr(file
, type
->size_is
, 1);
2087 fprintf(file
, ";\n");
2090 if ((phase
== PHASE_FREE
) || (pointer_type
== RPC_FC_UP
))
2091 print_phase_function(file
, indent
, "Pointer", phase
, var
, start_offset
);
2093 print_phase_function(file
, indent
, "ConformantString", phase
, var
,
2094 start_offset
+ (type
->size_is
? 4 : 2));
2097 else if (is_array(type
))
2099 unsigned char tc
= type
->type
;
2100 const char *array_type
;
2102 if (tc
== RPC_FC_SMFARRAY
|| tc
== RPC_FC_LGFARRAY
)
2103 array_type
= "FixedArray";
2104 else if (tc
== RPC_FC_SMVARRAY
|| tc
== RPC_FC_LGVARRAY
)
2106 if (is_size_needed_for_phase(phase
))
2108 print_file(file
, indent
, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
2109 print_file(file
, indent
, "_StubMsg.ActualCount = (unsigned long)");
2110 write_expr(file
, type
->length_is
, 1);
2111 fprintf(file
, ";\n\n");
2113 array_type
= "VaryingArray";
2115 else if (tc
== RPC_FC_CARRAY
)
2117 if (is_size_needed_for_phase(phase
) && phase
!= PHASE_FREE
)
2119 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
2120 write_expr(file
, type
->size_is
, 1);
2121 fprintf(file
, ";\n\n");
2123 array_type
= "ConformantArray";
2125 else if (tc
== RPC_FC_CVARRAY
)
2127 if (is_size_needed_for_phase(phase
))
2129 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
2130 write_expr(file
, type
->size_is
, 1);
2131 fprintf(file
, ";\n");
2132 print_file(file
, indent
, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
2133 print_file(file
, indent
, "_StubMsg.ActualCount = (unsigned long)");
2134 write_expr(file
, type
->length_is
, 1);
2135 fprintf(file
, ";\n\n");
2137 array_type
= "ConformantVaryingArray";
2140 array_type
= "ComplexArray";
2142 if (!in_attr
&& phase
== PHASE_FREE
)
2144 print_file(file
, indent
, "if (%s)\n", var
->name
);
2146 print_file(file
, indent
, "_StubMsg.pfnFree(%s);\n", var
->name
);
2148 else if (phase
!= PHASE_FREE
)
2150 if (pointer_type
== RPC_FC_UP
)
2151 print_phase_function(file
, indent
, "Pointer", phase
, var
, start_offset
);
2153 print_phase_function(file
, indent
, array_type
, phase
, var
, start_offset
);
2156 else if (!is_ptr(var
->type
) && is_base_type(rtype
))
2158 print_phase_basetype(file
, indent
, phase
, pass
, var
, var
->name
);
2160 else if (!is_ptr(var
->type
))
2165 case RPC_FC_PSTRUCT
:
2166 print_phase_function(file
, indent
, "SimpleStruct", phase
, var
, start_offset
);
2168 case RPC_FC_CSTRUCT
:
2169 case RPC_FC_CPSTRUCT
:
2170 print_phase_function(file
, indent
, "ConformantStruct", phase
, var
, start_offset
);
2172 case RPC_FC_CVSTRUCT
:
2173 print_phase_function(file
, indent
, "ConformantVaryingStruct", phase
, var
, start_offset
);
2175 case RPC_FC_BOGUS_STRUCT
:
2176 print_phase_function(file
, indent
, "ComplexStruct", phase
, var
, start_offset
);
2179 if (is_base_type( var
->type
->ref
->type
))
2181 print_phase_basetype(file
, indent
, phase
, pass
, var
, var
->name
);
2183 else if (var
->type
->ref
->type
== RPC_FC_STRUCT
)
2185 if (phase
!= PHASE_BUFFERSIZE
&& phase
!= PHASE_FREE
)
2186 print_phase_function(file
, indent
, "SimpleStruct", phase
, var
, start_offset
+ 4);
2191 if ((iid
= get_attrp( var
->attrs
, ATTR_IIDIS
)))
2192 print_file( file
, indent
, "_StubMsg.MaxCount = (unsigned long)%s;\n", iid
->name
);
2193 print_phase_function(file
, indent
, "Pointer", phase
, var
, start_offset
);
2197 error("write_remoting_arguments: Unsupported type: %s (0x%02x)\n", var
->name
, rtype
);
2202 if (last_ptr(var
->type
) && (pointer_type
== RPC_FC_RP
) && is_base_type(rtype
))
2204 print_phase_basetype(file
, indent
, phase
, pass
, var
, var
->name
);
2206 else if (last_ptr(var
->type
) && (pointer_type
== RPC_FC_RP
) && (rtype
== RPC_FC_STRUCT
))
2208 if (phase
!= PHASE_BUFFERSIZE
&& phase
!= PHASE_FREE
)
2209 print_phase_function(file
, indent
, "SimpleStruct", phase
, var
, start_offset
+ 4);
2214 if ((iid
= get_attrp( var
->attrs
, ATTR_IIDIS
)))
2215 print_file( file
, indent
, "_StubMsg.MaxCount = (unsigned long)%s;\n", iid
->name
);
2216 print_phase_function(file
, indent
, "Pointer", phase
, var
, start_offset
);
2219 fprintf(file
, "\n");
2224 size_t get_size_procformatstring_var(const var_t
*var
)
2226 return write_procformatstring_var(NULL
, 0, var
, FALSE
);
2230 size_t get_size_procformatstring_func(const func_t
*func
)
2235 /* argument list size */
2237 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2238 size
+= get_size_procformatstring_var(var
);
2240 /* return value size */
2241 if (is_void(func
->def
->type
))
2242 size
+= 2; /* FC_END and FC_PAD */
2244 size
+= get_size_procformatstring_var(func
->def
);
2249 size_t get_size_procformatstring(const ifref_list_t
*ifaces
, int for_objects
)
2251 const ifref_t
*iface
;
2255 if (ifaces
) LIST_FOR_EACH_ENTRY( iface
, ifaces
, const ifref_t
, entry
)
2257 if (for_objects
!= is_object(iface
->iface
->attrs
) || is_local(iface
->iface
->attrs
))
2260 if (iface
->iface
->funcs
)
2261 LIST_FOR_EACH_ENTRY( func
, iface
->iface
->funcs
, const func_t
, entry
)
2262 if (!is_local(func
->def
->attrs
))
2263 size
+= get_size_procformatstring_func( func
);
2268 size_t get_size_typeformatstring(const ifref_list_t
*ifaces
, int for_objects
)
2270 set_all_tfswrite(ifaces
, FALSE
);
2271 return process_tfs(NULL
, ifaces
, for_objects
);
2274 static void write_struct_expr(FILE *h
, const expr_t
*e
, int brackets
,
2275 const var_list_t
*fields
, const char *structvar
)
2281 fprintf(h
, "%lu", e
->u
.lval
);
2284 fprintf(h
, "0x%lx", e
->u
.lval
);
2286 case EXPR_TRUEFALSE
:
2288 fprintf(h
, "FALSE");
2292 case EXPR_IDENTIFIER
:
2295 LIST_FOR_EACH_ENTRY( field
, fields
, const var_t
, entry
)
2296 if (!strcmp(e
->u
.sval
, field
->name
))
2298 fprintf(h
, "%s->%s", structvar
, e
->u
.sval
);
2302 if (&field
->entry
== fields
) error("no field found for identifier %s\n", e
->u
.sval
);
2307 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2311 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2315 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2319 write_type(h
, e
->u
.tref
, FALSE
, NULL
);
2321 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2324 fprintf(h
, "sizeof(");
2325 write_type(h
, e
->u
.tref
, FALSE
, NULL
);
2336 if (brackets
) fprintf(h
, "(");
2337 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2339 case EXPR_SHL
: fprintf(h
, " << "); break;
2340 case EXPR_SHR
: fprintf(h
, " >> "); break;
2341 case EXPR_MUL
: fprintf(h
, " * "); break;
2342 case EXPR_DIV
: fprintf(h
, " / "); break;
2343 case EXPR_ADD
: fprintf(h
, " + "); break;
2344 case EXPR_SUB
: fprintf(h
, " - "); break;
2345 case EXPR_AND
: fprintf(h
, " & "); break;
2346 case EXPR_OR
: fprintf(h
, " | "); break;
2349 write_struct_expr(h
, e
->u
.ext
, 1, fields
, structvar
);
2350 if (brackets
) fprintf(h
, ")");
2353 if (brackets
) fprintf(h
, "(");
2354 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
2356 write_struct_expr(h
, e
->u
.ext
, 1, fields
, structvar
);
2358 write_struct_expr(h
, e
->ext2
, 1, fields
, structvar
);
2359 if (brackets
) fprintf(h
, ")");
2365 void declare_stub_args( FILE *file
, int indent
, const func_t
*func
)
2367 int in_attr
, out_attr
;
2369 const var_t
*def
= func
->def
;
2372 /* declare return value '_RetVal' */
2373 if (!is_void(def
->type
))
2375 print_file(file
, indent
, "");
2376 write_type_left(file
, def
->type
);
2377 fprintf(file
, " _RetVal;\n");
2383 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2385 int is_string
= is_attr(var
->attrs
, ATTR_STRING
);
2387 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
2388 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
2389 if (!out_attr
&& !in_attr
)
2392 if (!in_attr
&& !var
->type
->size_is
&& !is_string
)
2394 print_file(file
, indent
, "");
2395 write_type(file
, var
->type
->ref
, FALSE
, "_W%u", i
++);
2396 fprintf(file
, ";\n");
2399 print_file(file
, indent
, "");
2400 write_type_left(file
, var
->type
);
2402 if (var
->type
->declarray
) {
2403 fprintf(file
, "( *");
2404 write_name(file
, var
);
2405 fprintf(file
, " )");
2407 write_name(file
, var
);
2408 write_type_right(file
, var
->type
, FALSE
);
2409 fprintf(file
, ";\n");
2411 if (decl_indirect(var
->type
))
2412 print_file(file
, indent
, "void *_p_%s = &%s;\n",
2413 var
->name
, var
->name
);
2418 void assign_stub_out_args( FILE *file
, int indent
, const func_t
*func
)
2420 int in_attr
, out_attr
;
2427 LIST_FOR_EACH_ENTRY( var
, func
->args
, const var_t
, entry
)
2429 int is_string
= is_attr(var
->attrs
, ATTR_STRING
);
2430 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
2431 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
2432 if (!out_attr
&& !in_attr
)
2437 print_file(file
, indent
, "");
2438 write_name(file
, var
);
2440 if (var
->type
->size_is
)
2442 unsigned int size
, align
= 0;
2443 type_t
*type
= var
->type
;
2445 fprintf(file
, " = NdrAllocate(&_StubMsg, ");
2446 for ( ; type
->size_is
; type
= type
->ref
)
2448 write_expr(file
, type
->size_is
, TRUE
);
2449 fprintf(file
, " * ");
2451 size
= type_memsize(type
, &align
);
2452 fprintf(file
, "%u);\n", size
);
2454 else if (!is_string
)
2456 fprintf(file
, " = &_W%u;\n", i
);
2457 if (is_ptr(var
->type
) && !last_ptr(var
->type
))
2458 print_file(file
, indent
, "_W%u = 0;\n", i
);
2466 fprintf(file
, "\n");
2470 int write_expr_eval_routines(FILE *file
, const char *iface
)
2473 struct expr_eval_routine
*eval
;
2474 unsigned short callback_offset
= 0;
2476 LIST_FOR_EACH_ENTRY(eval
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
2480 print_file(file
, indent
, "static void __RPC_USER %s_%sExprEval_%04u(PMIDL_STUB_MESSAGE pStubMsg)\n",
2481 iface
, eval
->structure
->name
, callback_offset
);
2482 print_file(file
, indent
, "{\n");
2484 print_file(file
, indent
, "struct %s *" STRUCT_EXPR_EVAL_VAR
" = (struct %s *)(pStubMsg->StackTop - %u);\n",
2485 eval
->structure
->name
, eval
->structure
->name
, eval
->structure_size
);
2486 fprintf(file
, "\n");
2487 print_file(file
, indent
, "pStubMsg->Offset = 0;\n"); /* FIXME */
2488 print_file(file
, indent
, "pStubMsg->MaxCount = (unsigned long)");
2489 write_struct_expr(file
, eval
->expr
, 1, eval
->structure
->fields
, STRUCT_EXPR_EVAL_VAR
);
2490 fprintf(file
, ";\n");
2492 print_file(file
, indent
, "}\n\n");
2498 void write_expr_eval_routine_list(FILE *file
, const char *iface
)
2500 struct expr_eval_routine
*eval
;
2501 struct expr_eval_routine
*cursor
;
2502 unsigned short callback_offset
= 0;
2504 fprintf(file
, "static const EXPR_EVAL ExprEvalRoutines[] =\n");
2505 fprintf(file
, "{\n");
2507 LIST_FOR_EACH_ENTRY_SAFE(eval
, cursor
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
2509 print_file(file
, 1, "%s_%sExprEval_%04u,\n",
2510 iface
, eval
->structure
->name
, callback_offset
);
2513 list_remove(&eval
->entry
);
2517 fprintf(file
, "};\n\n");
2520 void write_user_quad_list(FILE *file
)
2524 if (list_empty(&user_type_list
))
2527 fprintf(file
, "static const USER_MARSHAL_ROUTINE_QUADRUPLE UserMarshalRoutines[] =\n");
2528 fprintf(file
, "{\n");
2529 LIST_FOR_EACH_ENTRY(ut
, &user_type_list
, user_type_t
, entry
)
2531 const char *sep
= &ut
->entry
== list_tail(&user_type_list
) ? "" : ",";
2532 print_file(file
, 1, "{\n");
2533 print_file(file
, 2, "%s_UserSize,\n", ut
->name
);
2534 print_file(file
, 2, "%s_UserMarshal,\n", ut
->name
);
2535 print_file(file
, 2, "%s_UserUnmarshal,\n", ut
->name
);
2536 print_file(file
, 2, "%s_UserFree\n", ut
->name
);
2537 print_file(file
, 1, "}%s\n", sep
);
2539 fprintf(file
, "};\n\n");
2542 void write_endpoints( FILE *f
, const char *prefix
, const str_list_t
*list
)
2544 const struct str_list_entry_t
*endpoint
;
2547 /* this should be an array of RPC_PROTSEQ_ENDPOINT but we want const strings */
2548 print_file( f
, 0, "static const unsigned char * %s__RpcProtseqEndpoint[][2] =\n{\n", prefix
);
2549 LIST_FOR_EACH_ENTRY( endpoint
, list
, const struct str_list_entry_t
, entry
)
2551 print_file( f
, 1, "{ (const unsigned char *)\"" );
2552 for (p
= endpoint
->str
; *p
&& *p
!= ':'; p
++)
2554 if (*p
== '"' || *p
== '\\') fputc( '\\', f
);
2557 if (!*p
) goto error
;
2558 if (p
[1] != '[') goto error
;
2560 fprintf( f
, "\", (const unsigned char *)\"" );
2561 for (p
+= 2; *p
&& *p
!= ']'; p
++)
2563 if (*p
== '"' || *p
== '\\') fputc( '\\', f
);
2566 if (*p
!= ']') goto error
;
2567 fprintf( f
, "\" },\n" );
2569 print_file( f
, 0, "};\n\n" );
2573 error("Invalid endpoint syntax '%s'\n", endpoint
->str
);