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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
, int ptr_level
, const expr_t
*array
);
63 static size_t fields_memsize(const var_t
*v
);
65 static int compare_expr(const expr_t
*a
, const expr_t
*b
)
69 if (a
->type
!= b
->type
)
70 return a
->type
- b
->type
;
76 return a
->u
.lval
- b
->u
.lval
;
78 return strcmp(a
->u
.sval
, b
->u
.sval
);
80 ret
= compare_expr(a
->ref
, b
->ref
);
83 ret
= compare_expr(a
->u
.ext
, b
->u
.ext
);
86 return compare_expr(a
->ext2
, b
->ext2
);
95 ret
= compare_expr(a
->ref
, b
->ref
);
98 return compare_expr(a
->u
.ext
, b
->u
.ext
);
104 return compare_expr(a
->ref
, b
->ref
);
111 #define WRITE_FCTYPE(file, fctype, typestring_offset) \
114 fprintf(file, "/* %2u */\n", typestring_offset); \
115 print_file((file), 2, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
119 static int print_file(FILE *file
, int indent
, const char *format
, ...)
126 va_start(va
, format
);
127 for (i
= 0; i
< indent
; i
++)
129 r
= vfprintf(file
, format
, va
);
134 static inline int type_has_ref(const type_t
*type
)
136 return (type
->type
== 0 && type
->ref
);
139 static inline int is_base_type(unsigned char type
)
158 case RPC_FC_ERROR_STATUS_T
:
159 case RPC_FC_BIND_PRIMITIVE
:
167 static size_t write_procformatstring_var(FILE *file
, int indent
,
168 const var_t
*var
, int is_return
, unsigned int *type_offset
)
171 int ptr_level
= var
->ptr_level
;
172 const type_t
*type
= var
->type
;
174 int is_in
= is_attr(var
->attrs
, ATTR_IN
);
175 int is_out
= is_attr(var
->attrs
, ATTR_OUT
);
177 if (!is_in
&& !is_out
) is_in
= TRUE
;
179 if (ptr_level
== 0 && type_has_ref(type
))
182 if (ptr_level
== 0 && !var
->array
&& is_base_type(type
->type
))
185 print_file(file
, indent
, "0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
187 print_file(file
, indent
, "0x4e, /* FC_IN_PARAM_BASETYPE */\n");
191 #define CASE_BASETYPE(fctype) \
193 print_file(file, indent, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
194 size = 2; /* includes param type prefix */ \
197 CASE_BASETYPE(FC_BYTE
);
198 CASE_BASETYPE(FC_CHAR
);
199 CASE_BASETYPE(FC_WCHAR
);
200 CASE_BASETYPE(FC_USHORT
);
201 CASE_BASETYPE(FC_SHORT
);
202 CASE_BASETYPE(FC_ULONG
);
203 CASE_BASETYPE(FC_LONG
);
204 CASE_BASETYPE(FC_HYPER
);
205 CASE_BASETYPE(FC_IGNORE
);
206 CASE_BASETYPE(FC_USMALL
);
207 CASE_BASETYPE(FC_SMALL
);
208 CASE_BASETYPE(FC_FLOAT
);
209 CASE_BASETYPE(FC_DOUBLE
);
210 CASE_BASETYPE(FC_ERROR_STATUS_T
);
213 case RPC_FC_BIND_PRIMITIVE
:
214 print_file(file
, indent
, "0x%02x, /* FC_IGNORE */\n", RPC_FC_IGNORE
);
215 size
= 2; /* includes param type prefix */
219 error("Unknown/unsupported type: %s (0x%02x)\n", var
->name
, type
->type
);
226 print_file(file
, indent
, "0x52, /* FC_RETURN_PARAM */\n");
227 else if (is_in
&& is_out
)
228 print_file(file
, indent
, "0x50, /* FC_IN_OUT_PARAM */\n");
230 print_file(file
, indent
, "0x51, /* FC_OUT_PARAM */\n");
232 print_file(file
, indent
, "0x4d, /* FC_IN_PARAM */\n");
234 print_file(file
, indent
, "0x01,\n");
235 print_file(file
, indent
, "NdrFcShort(0x%x),\n", *type_offset
);
236 size
= 4; /* includes param type prefix */
238 *type_offset
+= get_size_typeformatstring_var(var
);
242 void write_procformatstring(FILE *file
, type_t
*iface
)
246 unsigned int type_offset
= 2;
248 print_file(file
, indent
, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
249 print_file(file
, indent
, "{\n");
251 print_file(file
, indent
, "0,\n");
252 print_file(file
, indent
, "{\n");
257 func_t
*func
= iface
->funcs
;
258 while (NEXT_LINK(func
)) func
= NEXT_LINK(func
);
259 for (; func
; func
= PREV_LINK(func
))
261 /* emit argument data */
265 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
268 write_procformatstring_var(file
, indent
, var
, FALSE
,
271 var
= PREV_LINK(var
);
275 /* emit return value data */
277 if (is_void(var
->type
, NULL
))
279 print_file(file
, indent
, "0x5b, /* FC_END */\n");
280 print_file(file
, indent
, "0x5c, /* FC_PAD */\n");
283 write_procformatstring_var(file
, indent
, var
, TRUE
,
288 print_file(file
, indent
, "0x0\n");
290 print_file(file
, indent
, "}\n");
292 print_file(file
, indent
, "};\n");
293 print_file(file
, indent
, "\n");
296 /* write conformance / variance descriptor */
297 static size_t write_conf_or_var_desc(FILE *file
, const func_t
*func
, const type_t
*structure
, const expr_t
*expr
)
299 unsigned char operator_type
= 0;
300 const char *operator_string
= "no operators";
301 const expr_t
*subexpr
= expr
;
302 unsigned char correlation_type
;
304 if (!file
) return 4; /* optimisation for sizing pass */
308 if (expr
->cval
> UCHAR_MAX
* (USHRT_MAX
+ 1) + USHRT_MAX
)
309 error("write_conf_or_var_desc: constant value %ld is greater than "
310 "the maximum constant size of %d\n", expr
->cval
,
311 UCHAR_MAX
* (USHRT_MAX
+ 1) + USHRT_MAX
);
313 print_file(file
, 2, "0x%x, /* Corr desc: constant, val = %ld */\n",
314 RPC_FC_CONSTANT_CONFORMANCE
, expr
->cval
);
315 print_file(file
, 2, "0x%x,\n", expr
->cval
& ~USHRT_MAX
);
316 print_file(file
, 2, "NdrFcShort(0x%x),\n", expr
->cval
& USHRT_MAX
);
321 switch (subexpr
->type
)
324 subexpr
= subexpr
->ref
;
325 operator_type
= RPC_FC_DEREFERENCE
;
326 operator_string
= "FC_DEREFERENCE";
329 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 2))
331 subexpr
= subexpr
->ref
;
332 operator_type
= RPC_FC_DIV_2
;
333 operator_string
= "FC_DIV_2";
337 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 2))
339 subexpr
= subexpr
->ref
;
340 operator_type
= RPC_FC_MULT_2
;
341 operator_string
= "FC_MULT_2";
345 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 1))
347 subexpr
= subexpr
->ref
;
348 operator_type
= RPC_FC_SUB_1
;
349 operator_string
= "FC_SUB_1";
353 if (subexpr
->u
.ext
->is_const
&& (subexpr
->u
.ext
->cval
== 1))
355 subexpr
= subexpr
->ref
;
356 operator_type
= RPC_FC_ADD_1
;
357 operator_string
= "FC_ADD_1";
364 if (subexpr
->type
== EXPR_IDENTIFIER
)
366 const type_t
*correlation_variable
= NULL
;
367 unsigned char param_type
= 0;
368 const char *param_type_string
= NULL
;
375 for (offset
= 0, var
= structure
->fields
; var
; var
= NEXT_LINK(var
))
377 offset
-= type_memsize(var
->type
, var
->ptr_level
, var
->array
);
378 if (!strcmp(var
->name
, subexpr
->u
.sval
))
380 correlation_variable
= var
->type
;
384 if (!correlation_variable
)
385 error("write_conf_or_var_desc: couldn't find variable %s in structure\n",
388 correlation_type
= RPC_FC_NORMAL_CONFORMANCE
;
392 const var_t
*var
= func
->args
;
394 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
395 /* FIXME: not all stack variables are sizeof(void *) */
396 for (offset
= 0; var
; offset
+= sizeof(void *), var
= PREV_LINK(var
))
398 if (!strcmp(var
->name
, subexpr
->u
.sval
))
400 correlation_variable
= var
->type
;
404 if (!correlation_variable
)
405 error("write_conf_or_var_desc: couldn't find variable %s in function\n",
408 correlation_type
= RPC_FC_TOP_LEVEL_CONFORMANCE
;
411 while (type_has_ref(correlation_variable
))
412 correlation_variable
= correlation_variable
->ref
;
414 switch (correlation_variable
->type
)
418 param_type
= RPC_FC_SMALL
;
419 param_type_string
= "FC_SMALL";
423 param_type
= RPC_FC_USMALL
;
424 param_type_string
= "FC_USMALL";
428 param_type
= RPC_FC_SHORT
;
429 param_type_string
= "FC_SHORT";
432 param_type
= RPC_FC_USHORT
;
433 param_type_string
= "FC_USHORT";
436 param_type
= RPC_FC_LONG
;
437 param_type_string
= "FC_LONG";
440 param_type
= RPC_FC_ULONG
;
441 param_type_string
= "FC_ULONG";
444 error("write_conf_or_var_desc: conformance variable type not supported 0x%x\n",
445 correlation_variable
->type
);
448 print_file(file
, 2, "0x%x, /* Corr desc: %s%s */\n",
449 correlation_type
| param_type
,
450 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "parameter, " : "",
452 print_file(file
, 2, "0x%x, /* %s */\n", operator_type
, operator_string
);
453 print_file(file
, 2, "NdrFcShort(0x%x), /* %soffset = %d */\n",
455 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "x86 stack size / " : "",
460 unsigned int callback_offset
= 0;
464 struct expr_eval_routine
*eval
;
467 LIST_FOR_EACH_ENTRY(eval
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
469 if (!strcmp(eval
->structure
->name
, structure
->name
) &&
470 !compare_expr(eval
->expr
, expr
))
480 eval
= xmalloc(sizeof(*eval
));
481 eval
->structure
= structure
;
482 eval
->structure_size
= fields_memsize(structure
->fields
);
484 list_add_tail(&expr_eval_routines
, &eval
->entry
);
487 correlation_type
= RPC_FC_NORMAL_CONFORMANCE
;
491 error("write_conf_or_var_desc: top-level callback conformance unimplemented\n");
492 correlation_type
= RPC_FC_TOP_LEVEL_CONFORMANCE
;
495 if (callback_offset
> USHRT_MAX
)
496 error("Maximum number of callback routines reached\n");
498 print_file(file
, 2, "0x%x, /* Corr desc: %s */\n",
500 correlation_type
== RPC_FC_TOP_LEVEL_CONFORMANCE
? "parameter" : "");
501 print_file(file
, 2, "0x%x, /* %s */\n", RPC_FC_CALLBACK
, "FC_CALLBACK");
502 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", callback_offset
, callback_offset
);
507 static size_t fields_memsize(const var_t
*v
)
510 const var_t
*first
= v
;
512 while (NEXT_LINK(v
)) v
= NEXT_LINK(v
);
514 size
+= type_memsize(v
->type
, v
->ptr_level
, v
->array
);
515 if (v
== first
) break;
521 static size_t type_memsize(const type_t
*t
, int ptr_level
, const expr_t
*array
)
526 return sizeof(void *);
529 return type_memsize(t
->ref
, 0 /* FIXME */, NULL
);
547 case RPC_FC_ERROR_STATUS_T
:
557 case RPC_FC_CVSTRUCT
:
558 case RPC_FC_CPSTRUCT
:
561 case RPC_FC_BOGUS_STRUCT
:
562 case RPC_FC_ENCAPSULATED_UNION
:
563 case RPC_FC_NON_ENCAPSULATED_UNION
:
564 size
= fields_memsize(t
->fields
);
567 error("type_memsize: Unknown type %d\n", t
->type
);
582 size_t get_type_memsize(const type_t
*type
)
584 return type_memsize(type
, 0, NULL
);
587 static int write_pointers(FILE *file
, const attr_t
*attrs
,
588 const type_t
*type
, int ptr_level
,
589 const expr_t
*array
, int level
,
590 size_t *typestring_offset
)
592 int pointers_written
= 0;
595 /* don't generate a pointer for first-level arrays since we want to
596 * descend into them to write their pointers, not stop here */
597 if ((level
== 0 || ptr_level
== 0) && is_array_type(attrs
, ptr_level
, array
))
599 return write_pointers(file
, NULL
, type
, 0, NULL
, level
+ 1, typestring_offset
);
604 /* FIXME: only general algorithm implemented, not the actual writing */
605 error("write_pointers: Writing type format string for pointer is unimplemented\n");
609 /* FIXME: search through all refs for pointers too */
610 while(type_has_ref(type
))
615 /* note: don't descend into complex structures or unions since these
616 * will always be generated as a separate type */
618 case RPC_FC_CVSTRUCT
:
619 case RPC_FC_CPSTRUCT
:
624 while (NEXT_LINK(v
)) v
= NEXT_LINK(v
);
625 for (; v
; v
= PREV_LINK(v
))
626 pointers_written
+= write_pointers(file
, v
->attrs
, v
->type
,
627 v
->ptr_level
, v
->array
,
638 return pointers_written
;
641 static size_t write_pointer_description(FILE *file
, const attr_t
*attrs
,
642 const type_t
*type
, int ptr_level
,
643 const expr_t
*array
, int level
,
644 size_t typestring_offset
)
649 /* don't generate a pointer for first-level arrays since we want to
650 * descend into them to write their pointers, not stop here */
651 if ((level
== 0 || ptr_level
== 0) && is_array_type(attrs
, ptr_level
, array
))
653 return write_pointer_description(file
, NULL
, type
, 0, NULL
,
654 level
+ 1, typestring_offset
);
659 /* FIXME: only general algorithm implemented, not the actual writing */
660 error("write_pointer_description: Writing pointer description is unimplemented\n");
664 /* FIXME: search through all refs for pointers too */
668 /* note: don't descend into complex structures or unions since these
669 * will always be generated as a separate type */
671 case RPC_FC_CVSTRUCT
:
672 case RPC_FC_CPSTRUCT
:
677 while (NEXT_LINK(v
)) v
= NEXT_LINK(v
);
678 for (; v
; v
= PREV_LINK(v
))
679 size
+= write_pointer_description(file
, v
->attrs
, v
->type
,
680 v
->ptr_level
, v
->array
,
694 static size_t write_string_tfs(FILE *file
, const attr_t
*attrs
,
695 const type_t
*type
, const expr_t
*array
,
696 const char *name
, size_t *typestring_offset
)
698 const expr_t
*size_is
= get_attrp(attrs
, ATTR_SIZEIS
);
699 int has_size
= size_is
&& (size_is
->type
!= EXPR_VOID
);
700 size_t start_offset
= *typestring_offset
;
701 unsigned char flags
= 0;
702 int pointer_type
= get_attrv(attrs
, ATTR_POINTERTYPE
);
704 pointer_type
= RPC_FC_RP
;
706 if (!get_attrp(attrs
, ATTR_SIZEIS
))
707 flags
|= RPC_FC_P_SIMPLEPOINTER
;
709 while (type_has_ref(type
))
712 if ((type
->type
!= RPC_FC_BYTE
) && (type
->type
!= RPC_FC_CHAR
) && (type
->type
!= RPC_FC_WCHAR
))
714 error("write_string_tfs: Unimplemented for type 0x%x of name: %s\n", type
->type
, name
);
718 print_file(file
, 2,"0x%x, 0x%x, /* %s%s */\n",
720 pointer_type
== RPC_FC_FP
? "FC_FP" : (pointer_type
== RPC_FC_UP
? "FC_UP" : "FC_RP"),
721 (flags
& RPC_FC_P_SIMPLEPOINTER
) ? " [simple_pointer]" : "");
722 *typestring_offset
+= 2;
724 if (!(flags
& RPC_FC_P_SIMPLEPOINTER
))
726 print_file(file
, 2, "NdrFcShort(0x2);\n");
727 *typestring_offset
+= 2;
730 if (array
&& array
->is_const
)
732 if (array
->cval
> USHRT_MAX
)
733 error("array size for parameter %s exceeds %d bytes by %ld bytes\n",
734 name
, USHRT_MAX
, array
->cval
- USHRT_MAX
);
736 if (type
->type
== RPC_FC_CHAR
)
737 WRITE_FCTYPE(file
, FC_CSTRING
, *typestring_offset
);
739 WRITE_FCTYPE(file
, FC_WSTRING
, *typestring_offset
);
740 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
741 *typestring_offset
+= 2;
743 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", array
->cval
, array
->cval
);
744 *typestring_offset
+= 2;
750 if (type
->type
== RPC_FC_CHAR
)
751 WRITE_FCTYPE(file
, FC_C_CSTRING
, *typestring_offset
);
753 WRITE_FCTYPE(file
, FC_C_WSTRING
, *typestring_offset
);
754 print_file(file
, 2, "0x%x, /* FC_STRING_SIZED */\n", RPC_FC_STRING_SIZED
);
755 *typestring_offset
+= 2;
757 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
, NULL
, size_is
);
763 if (type
->type
== RPC_FC_CHAR
)
764 WRITE_FCTYPE(file
, FC_C_CSTRING
, *typestring_offset
);
766 WRITE_FCTYPE(file
, FC_C_WSTRING
, *typestring_offset
);
767 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
768 *typestring_offset
+= 2;
774 static size_t write_array_tfs(FILE *file
, const attr_t
*attrs
,
775 const type_t
*type
, const expr_t
*array
,
776 const char *name
, size_t *typestring_offset
)
778 const expr_t
*length_is
= get_attrp(attrs
, ATTR_LENGTHIS
);
779 const expr_t
*size_is
= get_attrp(attrs
, ATTR_SIZEIS
);
780 int has_length
= length_is
&& (length_is
->type
!= EXPR_VOID
);
781 int has_size
= (size_is
&& (size_is
->type
!= EXPR_VOID
)) || !array
->is_const
;
784 if (array
&& NEXT_LINK(array
)) /* multi-dimensional array */
786 error("write_array_tfs: Multi-dimensional arrays not implemented yet (param %s)\n", name
);
791 size_t pointer_start_offset
= *typestring_offset
;
794 if (write_pointers(file
, attrs
, type
, 0, array
, 0, typestring_offset
) > 0)
797 start_offset
= *typestring_offset
;
799 if (!has_length
&& !has_size
)
802 size_t size
= type_memsize(type
, 0, array
);
803 if (size
< USHRT_MAX
)
805 WRITE_FCTYPE(file
, FC_SMFARRAY
, *typestring_offset
);
807 print_file(file
, 2, "0x%x, /* 0 */\n", 0);
809 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", size
, size
);
810 *typestring_offset
+= 4;
814 WRITE_FCTYPE(file
, FC_LGFARRAY
, *typestring_offset
);
816 print_file(file
, 2, "0x%x, /* 0 */\n", 0);
818 print_file(file
, 2, "NdrFcLong(0x%x), /* %d */\n", size
, size
);
819 *typestring_offset
+= 6;
824 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
825 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
826 *typestring_offset
+= 2;
827 *typestring_offset
= write_pointer_description(file
, attrs
,
828 type
, 0, array
, 0, pointer_start_offset
);
829 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
830 *typestring_offset
+= 1;
833 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
834 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
835 *typestring_offset
+= 2;
839 else if (has_length
&& !has_size
)
842 size_t element_size
= type_memsize(type
, 0, NULL
);
843 size_t elements
= array
->cval
;
844 size_t total_size
= element_size
* elements
;
846 if (total_size
< USHRT_MAX
)
848 WRITE_FCTYPE(file
, FC_SMVARRAY
, *typestring_offset
);
850 print_file(file
, 2, "0x%x, /* 0 */\n", 0);
852 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", total_size
, total_size
);
853 /* number of elements */
854 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", elements
, elements
);
855 *typestring_offset
+= 6;
859 WRITE_FCTYPE(file
, FC_LGVARRAY
, *typestring_offset
);
861 print_file(file
, 2, "0x%x, /* 0 */\n", 0);
863 print_file(file
, 2, "NdrFcLong(0x%x), /* %d */\n", total_size
, total_size
);
864 /* number of elements */
865 print_file(file
, 2, "NdrFcLong(0x%x), /* %d */\n", elements
, elements
);
866 *typestring_offset
+= 10;
869 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", element_size
, element_size
);
870 *typestring_offset
+= 2;
872 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
878 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
879 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
880 *typestring_offset
+= 2;
881 *typestring_offset
+= write_pointer_description(file
, attrs
,
882 type
, 0, array
, 0, pointer_start_offset
);
883 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
884 *typestring_offset
+= 1;
887 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
888 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
889 *typestring_offset
+= 2;
893 else if (!has_length
&& has_size
)
895 /* conformant array */
896 size_t element_size
= type_memsize(type
, 0, NULL
);
898 WRITE_FCTYPE(file
, FC_CARRAY
, *typestring_offset
);
900 print_file(file
, 2, "0x%x, /* 0 */\n", 0);
902 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", element_size
, element_size
);
903 *typestring_offset
+= 4;
905 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
907 size_is
? size_is
: array
);
911 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
912 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
913 *typestring_offset
+= 2;
914 *typestring_offset
+= write_pointer_description(file
, attrs
,
915 type
, 0, array
, 0, pointer_start_offset
);
916 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
917 *typestring_offset
+= 1;
920 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
921 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
922 *typestring_offset
+= 2;
928 /* conformant varying array */
929 size_t element_size
= type_memsize(type
, 0, NULL
);
931 WRITE_FCTYPE(file
, FC_CVARRAY
, *typestring_offset
);
933 print_file(file
, 2, "0x%x, /* 0 */\n", 0);
935 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", element_size
, element_size
);
936 *typestring_offset
+= 4;
938 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
940 size_is
? size_is
: array
);
941 *typestring_offset
+= write_conf_or_var_desc(file
, current_func
,
947 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
948 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
949 *typestring_offset
+= 2;
950 *typestring_offset
+= write_pointer_description(file
, attrs
,
951 type
, 0, array
, 0, pointer_start_offset
);
952 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
953 *typestring_offset
+= 1;
956 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
957 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
958 *typestring_offset
+= 2;
965 static const var_t
*find_array_or_string_in_struct(const type_t
*type
)
967 /* last field is the first in the fields linked list */
968 const var_t
*last_field
= type
->fields
;
969 if (is_array_type(last_field
->attrs
, last_field
->ptr_level
, last_field
->array
))
972 assert((last_field
->type
->type
== RPC_FC_CSTRUCT
) ||
973 (last_field
->type
->type
== RPC_FC_CPSTRUCT
) ||
974 (last_field
->type
->type
== RPC_FC_CVSTRUCT
));
976 return find_array_or_string_in_struct(last_field
->type
);
979 static size_t write_struct_tfs(FILE *file
, const type_t
*type
,
980 const char *name
, size_t *typestring_offset
)
986 size_t pointer_offset
;
992 total_size
= type_memsize(type
, 0, NULL
);
994 if (total_size
> USHRT_MAX
)
995 error("structure size for parameter %s exceeds %d bytes by %d bytes\n",
996 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
998 if (type
->type
== RPC_FC_PSTRUCT
)
1000 pointer_offset
= *typestring_offset
;
1001 write_pointers(file
, NULL
, type
, 0, NULL
, 0, typestring_offset
);
1003 else pointer_offset
= 0; /* silence warning */
1005 start_offset
= *typestring_offset
;
1006 if (type
->type
== RPC_FC_STRUCT
)
1007 WRITE_FCTYPE(file
, FC_STRUCT
, *typestring_offset
);
1009 WRITE_FCTYPE(file
, FC_PSTRUCT
, *typestring_offset
);
1011 print_file(file
, 2, "0x0,\n");
1013 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", total_size
, total_size
);
1014 *typestring_offset
+= 4;
1016 if (type
->type
== RPC_FC_PSTRUCT
)
1018 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1019 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1020 *typestring_offset
+= 2;
1021 *typestring_offset
+= write_pointer_description(file
, NULL
,
1022 type
, 0, NULL
, 0, pointer_offset
);
1023 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1024 *typestring_offset
+= 1;
1028 print_file(file
, 2, "0x0, /* FIXME: write out conversion data */\n");
1029 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1031 *typestring_offset
+= 2;
1032 return start_offset
;
1033 case RPC_FC_CSTRUCT
:
1034 case RPC_FC_CPSTRUCT
:
1035 total_size
= type_memsize(type
, 0, NULL
);
1037 if (total_size
> USHRT_MAX
)
1038 error("structure size for parameter %s exceeds %d bytes by %d bytes\n",
1039 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
1041 array
= find_array_or_string_in_struct(type
);
1042 current_structure
= type
;
1043 array_offset
= write_array_tfs(file
, array
->attrs
, array
->type
,
1044 array
->array
, array
->name
,
1046 current_structure
= NULL
;
1048 if (type
->type
== RPC_FC_CPSTRUCT
)
1050 pointer_offset
= *typestring_offset
;
1051 write_pointers(file
, NULL
, type
, 0, NULL
, 0, typestring_offset
);
1053 else pointer_offset
= 0; /* silence warning */
1055 start_offset
= *typestring_offset
;
1056 if (type
->type
== RPC_FC_CSTRUCT
)
1057 WRITE_FCTYPE(file
, FC_CSTRUCT
, *typestring_offset
);
1059 WRITE_FCTYPE(file
, FC_CPSTRUCT
, *typestring_offset
);
1061 print_file(file
, 2, "0x0,\n");
1063 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", total_size
, total_size
);
1064 *typestring_offset
+= 4;
1065 print_file(file
, 2, "NdrFcShort(0x%x), /* offset = %d (%u) */\n",
1066 array_offset
- *typestring_offset
,
1067 array_offset
- *typestring_offset
,
1069 *typestring_offset
+= 2;
1071 if (type
->type
== RPC_FC_CPSTRUCT
)
1073 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1074 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1075 *typestring_offset
+= 2;
1076 *typestring_offset
+= write_pointer_description(file
, NULL
,
1077 type
, 0, NULL
, 0, pointer_offset
);
1078 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1079 *typestring_offset
+= 1;
1082 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1083 *typestring_offset
+= 1;
1085 return start_offset
;
1086 case RPC_FC_CVSTRUCT
:
1087 total_size
= type_memsize(type
, 0, NULL
);
1089 if (total_size
> USHRT_MAX
)
1090 error("structure size for parameter %s exceeds %d bytes by %d bytes\n",
1091 name
, USHRT_MAX
, total_size
- USHRT_MAX
);
1093 array
= find_array_or_string_in_struct(type
);
1094 current_structure
= type
;
1095 if (is_attr(array
->attrs
, ATTR_STRING
))
1096 array_offset
= write_string_tfs(file
, array
->attrs
, array
->type
,
1097 array
->array
, array
->name
,
1100 array_offset
= write_array_tfs(file
, array
->attrs
, array
->type
,
1101 array
->array
, array
->name
,
1103 current_structure
= NULL
;
1105 pointer_offset
= *typestring_offset
;
1106 if (!write_pointers(file
, NULL
, type
, 0, NULL
, 0, typestring_offset
))
1109 start_offset
= *typestring_offset
;
1110 WRITE_FCTYPE(file
, FC_CVSTRUCT
, *typestring_offset
);
1112 print_file(file
, 2, "0x0,\n");
1114 print_file(file
, 2, "NdrFcShort(0x%x), /* %u */\n", total_size
, total_size
);
1115 *typestring_offset
+= 4;
1116 print_file(file
, 2, "NdrFcShort(0x%x), /* offset = %d (%u) */\n",
1117 array_offset
- *typestring_offset
,
1118 array_offset
- *typestring_offset
,
1120 *typestring_offset
+= 2;
1122 if (pointer_offset
!= 0)
1124 print_file(file
, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP
);
1125 print_file(file
, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD
);
1126 *typestring_offset
+= 2;
1127 *typestring_offset
+= write_pointer_description(file
, NULL
,
1128 type
, 0, NULL
, 0, pointer_offset
);
1129 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1130 *typestring_offset
+= 1;
1133 print_file(file
, 2, "0x%x, /* FC_END */\n", RPC_FC_END
);
1134 *typestring_offset
+= 1;
1136 return start_offset
;
1138 error("write_struct_tfs: Unimplemented for type 0x%x\n", type
->type
);
1139 return *typestring_offset
;
1143 static void write_pointer_only_tfs(FILE *file
, const attr_t
*attrs
, size_t offset
, size_t *typeformat_offset
)
1145 int pointer_type
= get_attrv(attrs
, ATTR_POINTERTYPE
);
1146 if (!pointer_type
) pointer_type
= RPC_FC_RP
;
1148 print_file(file
, 2, "0x%x, 0x00, /* %s */\n",
1150 pointer_type
== RPC_FC_FP
? "FC_FP" : (pointer_type
== RPC_FC_UP
? "FC_UP" : "FC_RP"));
1151 print_file(file
, 2, "NdrFcShort(0x%x), /* %d */\n", offset
, offset
);
1152 *typeformat_offset
+= 4;
1155 static size_t write_union_tfs(FILE *file
, const attr_t
*attrs
,
1156 const type_t
*type
, const char *name
,
1157 size_t *typeformat_offset
)
1159 error("write_union_tfs: Unimplemented\n");
1160 return *typeformat_offset
;
1163 static size_t write_typeformatstring_var(FILE *file
, int indent
,
1164 const var_t
*var
, size_t *typeformat_offset
)
1166 const type_t
*type
= var
->type
;
1167 int ptr_level
= var
->ptr_level
;
1169 chat("write_typeformatstring_var: %s\n", var
->name
);
1173 chat("write_typeformatstring: type->type = 0x%x, type->name = %s, ptr_level = %d\n", type
->type
, type
->name
, ptr_level
);
1175 if (is_string_type(var
->attrs
, ptr_level
, var
->array
))
1176 return write_string_tfs(file
, var
->attrs
, type
, var
->array
, var
->name
, typeformat_offset
);
1178 if (is_array_type(var
->attrs
, ptr_level
, var
->array
))
1179 return write_array_tfs(file
, var
->attrs
, type
, var
->array
, var
->name
, typeformat_offset
);
1183 /* follow reference if the type has one */
1184 if (type_has_ref(type
))
1187 /* FIXME: get new ptr_level from type */
1191 /* basic types don't need a type format string */
1192 if (is_base_type(type
->type
))
1198 case RPC_FC_PSTRUCT
:
1199 case RPC_FC_CSTRUCT
:
1200 case RPC_FC_CPSTRUCT
:
1201 case RPC_FC_CVSTRUCT
:
1202 case RPC_FC_BOGUS_STRUCT
:
1203 return write_struct_tfs(file
, type
, var
->name
, typeformat_offset
);
1204 case RPC_FC_ENCAPSULATED_UNION
:
1205 case RPC_FC_NON_ENCAPSULATED_UNION
:
1206 return write_union_tfs(file
, var
->attrs
, type
, var
->name
, typeformat_offset
);
1208 case RPC_FC_BIND_PRIMITIVE
:
1212 error("write_typeformatstring_var: Unsupported type 0x%x for variable %s\n", type
->type
, var
->name
);
1215 else if (ptr_level
== 1 && !type_has_ref(type
))
1217 size_t start_offset
= *typeformat_offset
;
1218 int in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1219 int out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1220 int pointer_type
= get_attrv(var
->attrs
, ATTR_POINTERTYPE
);
1221 if (!pointer_type
) pointer_type
= RPC_FC_RP
;
1223 /* special case for pointers to base types */
1226 #define CASE_BASETYPE(fctype) \
1227 case RPC_##fctype: \
1228 print_file(file, indent, "0x%x, 0x%x, /* %s %s[simple_pointer] */\n", \
1230 (!in_attr && out_attr) ? 0x0C : 0x08, \
1231 pointer_type == RPC_FC_FP ? "FC_FP" : (pointer_type == RPC_FC_UP ? "FC_UP" : "FC_RP"), \
1232 (!in_attr && out_attr) ? "[allocated_on_stack] " : ""); \
1233 print_file(file, indent, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
1234 print_file(file, indent, "0x5c, /* FC_PAD */\n"); \
1235 *typeformat_offset += 4; \
1237 CASE_BASETYPE(FC_BYTE
);
1238 CASE_BASETYPE(FC_CHAR
);
1239 CASE_BASETYPE(FC_SMALL
);
1240 CASE_BASETYPE(FC_USMALL
);
1241 CASE_BASETYPE(FC_WCHAR
);
1242 CASE_BASETYPE(FC_SHORT
);
1243 CASE_BASETYPE(FC_USHORT
);
1244 CASE_BASETYPE(FC_LONG
);
1245 CASE_BASETYPE(FC_ULONG
);
1246 CASE_BASETYPE(FC_FLOAT
);
1247 CASE_BASETYPE(FC_HYPER
);
1248 CASE_BASETYPE(FC_DOUBLE
);
1249 CASE_BASETYPE(FC_ENUM16
);
1250 CASE_BASETYPE(FC_ENUM32
);
1251 CASE_BASETYPE(FC_IGNORE
);
1252 CASE_BASETYPE(FC_ERROR_STATUS_T
);
1258 assert(ptr_level
> 0);
1261 fprintf(file
, "/* %2u */\n", *typeformat_offset
);
1262 write_pointer_only_tfs(file
, var
->attrs
, 2, typeformat_offset
);
1269 void write_typeformatstring(FILE *file
, type_t
*iface
)
1273 size_t typeformat_offset
;
1275 print_file(file
, indent
, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
1276 print_file(file
, indent
, "{\n");
1278 print_file(file
, indent
, "0,\n");
1279 print_file(file
, indent
, "{\n");
1281 print_file(file
, indent
, "NdrFcShort(0x0),\n");
1282 typeformat_offset
= 2;
1286 func_t
*func
= iface
->funcs
;
1287 while (NEXT_LINK(func
)) func
= NEXT_LINK(func
);
1288 for (; func
; func
= PREV_LINK(func
))
1290 current_func
= func
;
1294 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
1297 write_typeformatstring_var(file
, indent
, var
,
1298 &typeformat_offset
);
1299 var
= PREV_LINK(var
);
1305 print_file(file
, indent
, "0x0\n");
1307 print_file(file
, indent
, "}\n");
1309 print_file(file
, indent
, "};\n");
1310 print_file(file
, indent
, "\n");
1313 static unsigned int get_required_buffer_size_type(
1314 const type_t
*type
, int ptr_level
, const expr_t
*array
,
1315 const char *name
, unsigned int *alignment
)
1318 if (ptr_level
== 0 && !array
&& !type_has_ref(type
))
1338 case RPC_FC_ERROR_STATUS_T
:
1348 case RPC_FC_BIND_PRIMITIVE
:
1355 for (field
= type
->fields
; field
; field
= NEXT_LINK(field
))
1357 unsigned int alignment
;
1358 size
+= get_required_buffer_size_type(
1359 field
->type
, field
->ptr_level
, field
->array
, field
->name
,
1366 error("get_required_buffer_size: Unknown/unsupported type: %s (0x%02x)\n", name
, type
->type
);
1370 if (ptr_level
== 0 && type_has_ref(type
))
1371 return get_required_buffer_size_type(type
->ref
, 0 /* FIXME */, array
, name
, alignment
);
1375 unsigned int get_required_buffer_size(const var_t
*var
, unsigned int *alignment
)
1377 int in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1378 int out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1380 if (!in_attr
&& !out_attr
)
1383 if ((!out_attr
|| in_attr
) && !is_attr(var
->attrs
, ATTR_STRING
) && !var
->array
)
1385 if (var
->ptr_level
> 0 || (var
->ptr_level
== 0 && type_has_ref(var
->type
)))
1387 type_t
*type
= var
->type
;
1388 while (type
->type
== 0 && type
->ref
)
1391 if (is_base_type(type
->type
))
1396 return get_required_buffer_size_type(var
->type
, var
->ptr_level
, var
->array
, var
->name
, alignment
);
1399 static inline const char *function_from_phase(enum remoting_phase phase
)
1403 case PHASE_BUFFERSIZE
:
1404 return "BufferSize";
1407 case PHASE_UNMARSHAL
:
1408 return "Unmarshall";
1415 /* returns whether the MaxCount, Offset or ActualCount members need to be
1416 * filled in for the specified phase */
1417 static inline int is_size_needed_for_phase(enum remoting_phase phase
)
1419 return (phase
!= PHASE_UNMARSHAL
);
1422 void write_remoting_arguments(FILE *file
, int indent
, const func_t
*func
,
1423 unsigned int *type_offset
, enum pass pass
,
1424 enum remoting_phase phase
)
1426 const expr_t
*length_is
;
1427 const expr_t
*size_is
;
1428 int in_attr
, out_attr
, has_length
, has_size
, pointer_type
;
1435 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
1436 for (; var
; *type_offset
+= get_size_typeformatstring_var(var
), var
= PREV_LINK(var
))
1438 const type_t
*type
= var
->type
;
1439 length_is
= get_attrp(var
->attrs
, ATTR_LENGTHIS
);
1440 size_is
= get_attrp(var
->attrs
, ATTR_SIZEIS
);
1441 has_length
= length_is
&& (length_is
->type
!= EXPR_VOID
);
1442 has_size
= (size_is
&& (size_is
->type
!= EXPR_VOID
)) || (var
->array
&& !var
->array
->is_const
);
1444 pointer_type
= get_attrv(var
->attrs
, ATTR_POINTERTYPE
);
1446 pointer_type
= RPC_FC_RP
;
1448 in_attr
= is_attr(var
->attrs
, ATTR_IN
);
1449 out_attr
= is_attr(var
->attrs
, ATTR_OUT
);
1450 if (!in_attr
&& !out_attr
)
1467 while (type_has_ref(type
))
1470 if (is_string_type(var
->attrs
, var
->ptr_level
, var
->array
))
1472 if (var
->array
&& var
->array
->is_const
)
1473 print_file(file
, indent
,
1474 "NdrNonConformantString%s(&_StubMsg, (unsigned char *)%s, &__MIDL_TypeFormatString.Format[%d]);\n",
1475 function_from_phase(phase
), var
->name
, *type_offset
);
1478 if (size_is
&& is_size_needed_for_phase(phase
))
1480 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
1481 write_expr(file
, size_is
, 1);
1482 fprintf(file
, ";\n");
1485 if (phase
== PHASE_FREE
)
1487 print_file(file
, indent
, "NdrPointerFree(\n");
1489 print_file(file
, indent
, "&_StubMsg,\n");
1490 print_file(file
, indent
, "(unsigned char *)%s,\n", var
->name
);
1491 print_file(file
, indent
, "&__MIDL_TypeFormatString.Format[%d]);\n",
1497 print_file(file
, indent
, "NdrConformantString%s(\n", function_from_phase(phase
));
1499 print_file(file
, indent
, "(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
1500 print_file(file
, indent
, "(unsigned char *)%s,\n", var
->name
);
1501 print_file(file
, indent
, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]%s\n",
1502 *type_offset
+ (has_size
? 4 : 2),
1503 (phase
== PHASE_MARSHAL
) ? ");" : ",");
1504 if (phase
== PHASE_UNMARSHAL
)
1505 print_file(file
, indent
, "(unsigned char)0);\n");
1510 else if (is_array_type(var
->attrs
, var
->ptr_level
, var
->array
))
1512 const char *array_type
;
1514 if (var
->array
&& NEXT_LINK(var
->array
)) /* multi-dimensional array */
1515 array_type
= "ComplexArray";
1518 if (!has_length
&& !has_size
)
1519 array_type
= "FixedArray";
1520 else if (has_length
&& !has_size
)
1522 if (is_size_needed_for_phase(phase
))
1524 print_file(file
, indent
, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
1525 print_file(file
, indent
, "_StubMsg.ActualCount = (unsigned long)");
1526 write_expr(file
, length_is
, 1);
1527 fprintf(file
, ";\n\n");
1529 array_type
= "VaryingArray";
1531 else if (!has_length
&& has_size
)
1533 if (is_size_needed_for_phase(phase
))
1535 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
1536 write_expr(file
, size_is
? size_is
: var
->array
, 1);
1537 fprintf(file
, ";\n\n");
1539 array_type
= "ConformantArray";
1543 if (is_size_needed_for_phase(phase
))
1545 print_file(file
, indent
, "_StubMsg.MaxCount = (unsigned long)");
1546 write_expr(file
, size_is
? size_is
: var
->array
, 1);
1547 fprintf(file
, ";\n");
1548 print_file(file
, indent
, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
1549 print_file(file
, indent
, "_StubMsg.ActualCount = (unsigned long)");
1550 write_expr(file
, length_is
, 1);
1551 fprintf(file
, ";\n\n");
1553 array_type
= "ConformantVaryingArray";
1557 print_file(file
, indent
,
1558 "Ndr%s%s(&_StubMsg, (unsigned char *)%s, &__MIDL_TypeFormatString.Format[%d]);\n",
1559 array_type
, function_from_phase(phase
), var
->name
,
1562 else if (var
->ptr_level
== 0 && is_base_type(type
->type
))
1565 unsigned int alignment
= 0;
1586 case RPC_FC_ERROR_STATUS_T
:
1598 case RPC_FC_BIND_PRIMITIVE
:
1599 /* no marshalling needed */
1603 error("write_remoting_arguments: Unsupported type: %s (0x%02x, ptr_level: 0)\n", var
->name
, type
->type
);
1607 if (phase
== PHASE_MARSHAL
|| phase
== PHASE_UNMARSHAL
)
1609 print_file(file
, indent
, "_StubMsg.Buffer += (unsigned char *)(((long)_StubMsg.Buffer + %u) & ~0x%x);\n",
1610 alignment
- 1, alignment
- 1);
1612 if (phase
== PHASE_MARSHAL
)
1614 print_file(file
, indent
, "*(");
1615 write_type(file
, var
->type
, var
, var
->tname
);
1616 fprintf(file
, " *)_StubMsg.Buffer = ");
1617 write_name(file
, var
);
1618 fprintf(file
, ";\n");
1620 else if (phase
== PHASE_UNMARSHAL
)
1622 print_file(file
, indent
, "");
1623 write_name(file
, var
);
1624 fprintf(file
, " = *(");
1625 write_type(file
, var
->type
, var
, var
->tname
);
1626 fprintf(file
, " *)_StubMsg.Buffer;\n");
1629 error("write_remoting_arguments: Unimplemented for base types for phase %d\n", phase
);
1631 print_file(file
, indent
, "_StubMsg.Buffer += sizeof(");
1632 write_type(file
, var
->type
, var
, var
->tname
);
1633 fprintf(file
, ");\n");
1636 else if (var
->ptr_level
== 0)
1638 const char *ndrtype
;
1643 ndrtype
= "SimpleStruct";
1645 case RPC_FC_CSTRUCT
:
1646 case RPC_FC_CPSTRUCT
:
1647 ndrtype
= "ConformantStruct";
1649 case RPC_FC_CVSTRUCT
:
1650 ndrtype
= "ConformantVaryingStruct";
1652 case RPC_FC_BOGUS_STRUCT
:
1653 ndrtype
= "ComplexStruct";
1656 error("write_remoting_arguments: Unsupported type: %s (0x%02x, ptr_level: %d)\n",
1657 var
->name
, type
->type
, var
->ptr_level
);
1661 print_file(file
, indent
,
1662 "Ndr%s%s(&_StubMsg, (unsigned char *)%s, &__MIDL_TypeFormatString.Format[%d]);\n",
1663 ndrtype
, function_from_phase(phase
), var
->name
, *type_offset
);
1667 if ((var
->ptr_level
== 1) && (pointer_type
== RPC_FC_RP
) && is_base_type(type
->type
))
1688 case RPC_FC_ERROR_STATUS_T
:
1698 case RPC_FC_BIND_PRIMITIVE
:
1699 /* no marshalling needed */
1703 error("write_remoting_arguments: Unsupported type: %s (0x%02x, ptr_level: 1)\n", var
->name
, type
->type
);
1707 print_file(file
, indent
,
1708 "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + %u) & ~0x%x);\n",
1709 size
- 1, size
- 1);
1711 if (phase
== PHASE_MARSHAL
)
1713 print_file(file
, indent
, "*(");
1714 write_type(file
, var
->type
, NULL
, var
->tname
);
1715 fprintf(file
, " *)_StubMsg.Buffer = *");
1716 write_name(file
, var
);
1717 fprintf(file
, ";\n");
1719 else if (phase
== PHASE_UNMARSHAL
)
1721 print_file(file
, indent
, (pass
== PASS_IN
) ? "" : "*");
1722 write_name(file
, var
);
1723 fprintf(file
, (pass
== PASS_IN
) ? " = (" : " = *(");
1724 write_type(file
, var
->type
, NULL
, var
->tname
);
1725 fprintf(file
, " *)_StubMsg.Buffer;\n");
1728 print_file(file
, indent
, "_StubMsg.Buffer += sizeof(");
1729 write_type(file
, var
->type
, NULL
, var
->tname
);
1730 fprintf(file
, ");\n");
1734 print_file(file
, indent
, "NdrPointer%s(\n", function_from_phase(phase
));
1736 print_file(file
, indent
, "(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
1737 print_file(file
, indent
, "(unsigned char *)%s,\n", var
->name
);
1738 print_file(file
, indent
, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]%s\n",
1739 *type_offset
, (phase
== PHASE_MARSHAL
) ? ");" : ",");
1740 if (phase
== PHASE_UNMARSHAL
)
1741 print_file(file
, indent
, "(unsigned char *)0);\n");
1745 fprintf(file
, "\n");
1750 size_t get_size_procformatstring_var(const var_t
*var
)
1752 unsigned int type_offset
= 2;
1753 return write_procformatstring_var(NULL
, 0, var
, FALSE
, &type_offset
);
1757 size_t get_size_typeformatstring_var(const var_t
*var
)
1759 size_t type_offset
= 0;
1760 write_typeformatstring_var(NULL
, 0, var
, &type_offset
);
1764 size_t get_size_procformatstring(const type_t
*iface
)
1772 func
= iface
->funcs
;
1773 while (NEXT_LINK(func
)) func
= NEXT_LINK(func
);
1776 /* argument list size */
1780 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
1783 size
+= get_size_procformatstring_var(var
);
1784 var
= PREV_LINK(var
);
1788 /* return value size */
1789 size
+= 2; /* FIXME: determine real size */
1790 func
= PREV_LINK(func
);
1796 size_t get_size_typeformatstring(const type_t
*iface
)
1804 func
= iface
->funcs
;
1805 while (NEXT_LINK(func
)) func
= NEXT_LINK(func
);
1808 /* argument list size */
1812 while (NEXT_LINK(var
)) var
= NEXT_LINK(var
);
1815 size
+= get_size_typeformatstring_var(var
);
1816 var
= PREV_LINK(var
);
1820 func
= PREV_LINK(func
);
1826 static void write_struct_expr(FILE *h
, const expr_t
*e
, int brackets
,
1827 const var_t
*fields
, const char *structvar
)
1833 fprintf(h
, "%ld", e
->u
.lval
);
1836 fprintf(h
, "0x%lx", e
->u
.lval
);
1838 case EXPR_IDENTIFIER
:
1841 for (field
= fields
; field
; field
= NEXT_LINK(field
))
1843 if (!strcmp(e
->u
.sval
, field
->name
))
1845 fprintf(h
, "%s->%s", structvar
, e
->u
.sval
);
1849 if (!field
) error("no field found for identifier %s\n", e
->u
.sval
);
1854 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
1858 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
1862 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
1866 write_type(h
, e
->u
.tref
->ref
, NULL
, e
->u
.tref
->name
);
1868 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
1871 fprintf(h
, "sizeof(");
1872 write_type(h
, e
->u
.tref
->ref
, NULL
, e
->u
.tref
->name
);
1883 if (brackets
) fprintf(h
, "(");
1884 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
1886 case EXPR_SHL
: fprintf(h
, " << "); break;
1887 case EXPR_SHR
: fprintf(h
, " >> "); break;
1888 case EXPR_MUL
: fprintf(h
, " * "); break;
1889 case EXPR_DIV
: fprintf(h
, " / "); break;
1890 case EXPR_ADD
: fprintf(h
, " + "); break;
1891 case EXPR_SUB
: fprintf(h
, " - "); break;
1892 case EXPR_AND
: fprintf(h
, " & "); break;
1893 case EXPR_OR
: fprintf(h
, " | "); break;
1896 write_struct_expr(h
, e
->u
.ext
, 1, fields
, structvar
);
1897 if (brackets
) fprintf(h
, ")");
1900 if (brackets
) fprintf(h
, "(");
1901 write_struct_expr(h
, e
->ref
, 1, fields
, structvar
);
1903 write_struct_expr(h
, e
->u
.ext
, 1, fields
, structvar
);
1905 write_struct_expr(h
, e
->ext2
, 1, fields
, structvar
);
1906 if (brackets
) fprintf(h
, ")");
1911 int write_expr_eval_routines(FILE *file
, const char *iface
)
1914 struct expr_eval_routine
*eval
;
1915 unsigned short callback_offset
= 0;
1917 LIST_FOR_EACH_ENTRY(eval
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
1921 print_file(file
, indent
, "static void __RPC_USER %s_%sExprEval_%04u(PMIDL_STUB_MESSAGE pStubMsg)\n",
1922 iface
, eval
->structure
->name
, callback_offset
);
1923 print_file(file
, indent
, "{\n");
1925 print_file(file
, indent
, "struct %s *" STRUCT_EXPR_EVAL_VAR
" = (struct %s *)(pStubMsg->StackTop - %u);\n",
1926 eval
->structure
->name
, eval
->structure
->name
, eval
->structure_size
);
1927 fprintf(file
, "\n");
1928 print_file(file
, indent
, "pStubMsg->Offset = 0;\n"); /* FIXME */
1929 print_file(file
, indent
, "pStubMsg->MaxCount = (unsigned long)");
1930 write_struct_expr(file
, eval
->expr
, 1, eval
->structure
->fields
, STRUCT_EXPR_EVAL_VAR
);
1931 fprintf(file
, ";\n");
1933 print_file(file
, indent
, "}\n\n");
1939 void write_expr_eval_routine_list(FILE *file
, const char *iface
)
1941 struct expr_eval_routine
*eval
;
1942 struct expr_eval_routine
*cursor
;
1943 unsigned short callback_offset
= 0;
1945 fprintf(file
, "static const EXPR_EVAL ExprEvalRoutines[] =\n");
1946 fprintf(file
, "{\n");
1948 LIST_FOR_EACH_ENTRY_SAFE(eval
, cursor
, &expr_eval_routines
, struct expr_eval_routine
, entry
)
1950 print_file(file
, 1, "%s_%sExprEval_%04u,\n",
1951 iface
, eval
->structure
->name
, callback_offset
);
1954 list_remove(&eval
->entry
);
1958 fprintf(file
, "};\n\n");