2005-12-08 12:52:13 +01:00
|
|
|
/*
|
|
|
|
* Format String Generator for IDL Compiler
|
|
|
|
*
|
2006-03-23 10:33:08 +01:00
|
|
|
* Copyright 2005-2006 Eric Kohl
|
2006-01-31 12:24:54 +01:00
|
|
|
* Copyright 2005-2006 Robert Shearman
|
2005-12-08 12:52:13 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-12-08 12:52:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <signal.h>
|
2006-01-24 11:07:13 +01:00
|
|
|
#include <limits.h>
|
2005-12-08 12:52:13 +01:00
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
|
|
|
#include "windef.h"
|
2006-01-27 12:53:32 +01:00
|
|
|
#include "wine/list.h"
|
2005-12-08 12:52:13 +01:00
|
|
|
|
|
|
|
#include "widl.h"
|
2005-12-12 12:14:31 +01:00
|
|
|
#include "typegen.h"
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2006-01-24 11:08:20 +01:00
|
|
|
static const func_t *current_func;
|
2006-01-27 12:53:32 +01:00
|
|
|
static const type_t *current_structure;
|
|
|
|
|
|
|
|
static struct list expr_eval_routines = LIST_INIT(expr_eval_routines);
|
|
|
|
struct expr_eval_routine
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
const type_t *structure;
|
2007-10-11 00:29:54 +02:00
|
|
|
unsigned int baseoff;
|
2006-01-27 12:53:32 +01:00
|
|
|
const expr_t *expr;
|
|
|
|
};
|
2006-01-24 11:12:54 +01:00
|
|
|
|
2007-02-06 15:54:58 +01:00
|
|
|
static size_t fields_memsize(const var_list_t *fields, unsigned int *align);
|
2007-05-19 01:53:27 +02:00
|
|
|
static size_t write_struct_tfs(FILE *file, type_t *type, const char *name, unsigned int *tfsoff);
|
2007-05-25 02:48:39 +02:00
|
|
|
static int write_embedded_types(FILE *file, const attr_list_t *attrs, type_t *type,
|
2007-06-12 03:51:41 +02:00
|
|
|
const char *name, int write_ptr, unsigned int *tfsoff);
|
2007-10-11 00:29:54 +02:00
|
|
|
static const var_t *find_array_or_string_in_struct(const type_t *type);
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2007-05-10 05:46:31 +02:00
|
|
|
const char *string_of_type(unsigned char type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RPC_FC_BYTE: return "FC_BYTE";
|
|
|
|
case RPC_FC_CHAR: return "FC_CHAR";
|
|
|
|
case RPC_FC_SMALL: return "FC_SMALL";
|
|
|
|
case RPC_FC_USMALL: return "FC_USMALL";
|
|
|
|
case RPC_FC_WCHAR: return "FC_WCHAR";
|
|
|
|
case RPC_FC_SHORT: return "FC_SHORT";
|
|
|
|
case RPC_FC_USHORT: return "FC_USHORT";
|
|
|
|
case RPC_FC_LONG: return "FC_LONG";
|
|
|
|
case RPC_FC_ULONG: return "FC_ULONG";
|
|
|
|
case RPC_FC_FLOAT: return "FC_FLOAT";
|
|
|
|
case RPC_FC_HYPER: return "FC_HYPER";
|
|
|
|
case RPC_FC_DOUBLE: return "FC_DOUBLE";
|
|
|
|
case RPC_FC_ENUM16: return "FC_ENUM16";
|
|
|
|
case RPC_FC_ENUM32: return "FC_ENUM32";
|
|
|
|
case RPC_FC_IGNORE: return "FC_IGNORE";
|
|
|
|
case RPC_FC_ERROR_STATUS_T: return "FC_ERROR_STATUS_T";
|
|
|
|
case RPC_FC_RP: return "FC_RP";
|
|
|
|
case RPC_FC_UP: return "FC_UP";
|
|
|
|
case RPC_FC_OP: return "FC_OP";
|
|
|
|
case RPC_FC_FP: return "FC_FP";
|
2007-05-19 01:53:27 +02:00
|
|
|
case RPC_FC_ENCAPSULATED_UNION: return "FC_ENCAPSULATED_UNION";
|
|
|
|
case RPC_FC_NON_ENCAPSULATED_UNION: return "FC_NON_ENCAPSULATED_UNION";
|
|
|
|
case RPC_FC_STRUCT: return "FC_STRUCT";
|
|
|
|
case RPC_FC_PSTRUCT: return "FC_PSTRUCT";
|
|
|
|
case RPC_FC_CSTRUCT: return "FC_CSTRUCT";
|
|
|
|
case RPC_FC_CPSTRUCT: return "FC_CPSTRUCT";
|
|
|
|
case RPC_FC_CVSTRUCT: return "FC_CVSTRUCT";
|
|
|
|
case RPC_FC_BOGUS_STRUCT: return "FC_BOGUS_STRUCT";
|
2007-06-06 03:50:31 +02:00
|
|
|
case RPC_FC_SMFARRAY: return "FC_SMFARRAY";
|
|
|
|
case RPC_FC_LGFARRAY: return "FC_LGFARRAY";
|
|
|
|
case RPC_FC_SMVARRAY: return "FC_SMVARRAY";
|
|
|
|
case RPC_FC_LGVARRAY: return "FC_LGVARRAY";
|
|
|
|
case RPC_FC_CARRAY: return "FC_CARRAY";
|
|
|
|
case RPC_FC_CVARRAY: return "FC_CVARRAY";
|
|
|
|
case RPC_FC_BOGUS_ARRAY: return "FC_BOGUS_ARRAY";
|
2007-09-19 00:28:17 +02:00
|
|
|
case RPC_FC_ALIGNM4: return "FC_ALIGNM4";
|
|
|
|
case RPC_FC_ALIGNM8: return "FC_ALIGNM8";
|
2007-09-19 00:28:49 +02:00
|
|
|
case RPC_FC_POINTER: return "FC_POINTER";
|
2007-09-26 20:32:47 +02:00
|
|
|
case RPC_FC_C_CSTRING: return "FC_C_CSTRING";
|
|
|
|
case RPC_FC_C_WSTRING: return "FC_C_WSTRING";
|
|
|
|
case RPC_FC_CSTRING: return "FC_CSTRING";
|
|
|
|
case RPC_FC_WSTRING: return "FC_WSTRING";
|
2007-05-10 05:46:31 +02:00
|
|
|
default:
|
|
|
|
error("string_of_type: unknown type 0x%02x\n", type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-08 02:43:58 +02:00
|
|
|
int is_struct(unsigned char type)
|
2007-05-16 02:48:20 +02:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
case RPC_FC_PSTRUCT:
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
case RPC_FC_BOGUS_STRUCT:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-19 13:05:25 +02:00
|
|
|
static int is_non_complex_struct(const type_t *type)
|
|
|
|
{
|
|
|
|
switch (type->type)
|
|
|
|
{
|
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
case RPC_FC_PSTRUCT:
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-08 02:43:58 +02:00
|
|
|
int is_union(unsigned char type)
|
2007-05-19 01:53:27 +02:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RPC_FC_ENCAPSULATED_UNION:
|
|
|
|
case RPC_FC_NON_ENCAPSULATED_UNION:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
static unsigned short user_type_offset(const char *name)
|
|
|
|
{
|
|
|
|
user_type_t *ut;
|
|
|
|
unsigned short off = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
|
|
|
|
{
|
|
|
|
if (strcmp(name, ut->name) == 0)
|
|
|
|
return off;
|
|
|
|
++off;
|
|
|
|
}
|
|
|
|
error("user_type_offset: couldn't find type (%s)\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-25 02:50:02 +02:00
|
|
|
static void update_tfsoff(type_t *type, unsigned int offset, FILE *file)
|
|
|
|
{
|
|
|
|
type->typestring_offset = offset;
|
|
|
|
if (file) type->tfswrite = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void guard_rec(type_t *type)
|
|
|
|
{
|
|
|
|
/* types that contain references to themselves (like a linked list),
|
|
|
|
need to be shielded from infinite recursion when writing embedded
|
|
|
|
types */
|
|
|
|
if (type->typestring_offset)
|
|
|
|
type->tfswrite = FALSE;
|
|
|
|
else
|
|
|
|
type->typestring_offset = 1;
|
|
|
|
}
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
static type_t *get_user_type(const type_t *t, const char **pname)
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
type_t *ut = get_attrp(t->attrs, ATTR_WIREMARSHAL);
|
|
|
|
if (ut)
|
|
|
|
{
|
|
|
|
if (pname)
|
|
|
|
*pname = t->name;
|
|
|
|
return ut;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t->kind == TKIND_ALIAS)
|
|
|
|
t = t->orig;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-19 00:29:59 +02:00
|
|
|
int is_user_type(const type_t *t)
|
2007-06-14 01:13:04 +02:00
|
|
|
{
|
|
|
|
return get_user_type(t, NULL) != NULL;
|
|
|
|
}
|
|
|
|
|
2007-05-19 01:53:27 +02:00
|
|
|
static int is_embedded_complex(const type_t *type)
|
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
unsigned char tc = type->type;
|
2007-06-15 03:27:19 +02:00
|
|
|
return is_struct(tc) || is_union(tc) || is_array(type) || is_user_type(type)
|
|
|
|
|| (is_ptr(type) && type->ref->type == RPC_FC_IP);
|
2007-05-19 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
static const char *get_context_handle_type_name(const type_t *type)
|
|
|
|
{
|
|
|
|
const type_t *t;
|
|
|
|
for (t = type; is_ptr(t); t = t->ref)
|
|
|
|
if (is_attr(t->attrs, ATTR_CONTEXTHANDLE))
|
|
|
|
return t->name;
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-10-25 03:06:16 +02:00
|
|
|
/* This is actually fairly involved to implement precisely, due to the
|
|
|
|
effects attributes may have and things like that. Right now this is
|
|
|
|
only used for optimization, so just check for a very small set of
|
|
|
|
criteria that guarantee the types are equivalent; assume every thing
|
|
|
|
else is different. */
|
|
|
|
static int compare_type(const type_t *a, const type_t *b)
|
|
|
|
{
|
|
|
|
if (a == b
|
|
|
|
|| (a->name
|
|
|
|
&& b->name
|
|
|
|
&& strcmp(a->name, b->name) == 0))
|
|
|
|
return 0;
|
|
|
|
/* Ordering doesn't need to be implemented yet. */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-31 12:24:11 +01:00
|
|
|
static int compare_expr(const expr_t *a, const expr_t *b)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (a->type != b->type)
|
|
|
|
return a->type - b->type;
|
|
|
|
|
|
|
|
switch (a->type)
|
|
|
|
{
|
|
|
|
case EXPR_NUM:
|
|
|
|
case EXPR_HEXNUM:
|
2006-07-06 13:56:36 +02:00
|
|
|
case EXPR_TRUEFALSE:
|
2006-01-31 12:24:11 +01:00
|
|
|
return a->u.lval - b->u.lval;
|
2007-07-17 13:09:03 +02:00
|
|
|
case EXPR_DOUBLE:
|
|
|
|
return a->u.dval - b->u.dval;
|
2006-01-31 12:24:11 +01:00
|
|
|
case EXPR_IDENTIFIER:
|
|
|
|
return strcmp(a->u.sval, b->u.sval);
|
|
|
|
case EXPR_COND:
|
|
|
|
ret = compare_expr(a->ref, b->ref);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
ret = compare_expr(a->u.ext, b->u.ext);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
return compare_expr(a->ext2, b->ext2);
|
|
|
|
case EXPR_OR:
|
|
|
|
case EXPR_AND:
|
|
|
|
case EXPR_ADD:
|
|
|
|
case EXPR_SUB:
|
|
|
|
case EXPR_MUL:
|
|
|
|
case EXPR_DIV:
|
|
|
|
case EXPR_SHL:
|
|
|
|
case EXPR_SHR:
|
|
|
|
ret = compare_expr(a->ref, b->ref);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
return compare_expr(a->u.ext, b->u.ext);
|
2007-10-25 03:06:16 +02:00
|
|
|
case EXPR_CAST:
|
|
|
|
ret = compare_type(a->u.tref, b->u.tref);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
/* Fall through. */
|
2006-01-31 12:24:11 +01:00
|
|
|
case EXPR_NOT:
|
|
|
|
case EXPR_NEG:
|
|
|
|
case EXPR_PPTR:
|
|
|
|
return compare_expr(a->ref, b->ref);
|
2007-10-25 03:06:16 +02:00
|
|
|
case EXPR_SIZEOF:
|
|
|
|
return compare_type(a->u.tref, b->u.tref);
|
2006-01-31 12:24:11 +01:00
|
|
|
case EXPR_VOID:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-01-31 12:25:54 +01:00
|
|
|
#define WRITE_FCTYPE(file, fctype, typestring_offset) \
|
|
|
|
do { \
|
|
|
|
if (file) \
|
|
|
|
fprintf(file, "/* %2u */\n", typestring_offset); \
|
|
|
|
print_file((file), 2, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
2007-06-15 03:29:33 +02:00
|
|
|
static void print_file(FILE *file, int indent, const char *format, ...)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
2007-06-15 03:29:33 +02:00
|
|
|
print(file, indent, format, va);
|
2005-12-08 12:52:13 +01:00
|
|
|
va_end(va);
|
2007-06-15 03:29:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void print(FILE *file, int indent, const char *format, va_list va)
|
|
|
|
{
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
if (format[0] != '\n')
|
|
|
|
while (0 < indent--)
|
|
|
|
fprintf(file, " ");
|
|
|
|
vfprintf(file, format, va);
|
|
|
|
}
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
|
2007-06-15 03:30:26 +02:00
|
|
|
void write_parameters_init(FILE *file, int indent, const func_t *func)
|
|
|
|
{
|
|
|
|
const var_t *var;
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
|
|
|
{
|
|
|
|
const type_t *t = var->type;
|
|
|
|
const char *n = var->name;
|
|
|
|
if (decl_indirect(t))
|
|
|
|
print_file(file, indent, "MIDL_memset(&%s, 0, sizeof %s);\n", n, n);
|
|
|
|
else if (is_ptr(t) || is_array(t))
|
|
|
|
print_file(file, indent, "%s = 0;\n", n);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(file, "\n");
|
|
|
|
}
|
|
|
|
|
2006-08-17 03:01:56 +02:00
|
|
|
static void write_formatdesc(FILE *f, int indent, const char *str)
|
|
|
|
{
|
|
|
|
print_file(f, indent, "typedef struct _MIDL_%s_FORMAT_STRING\n", str);
|
|
|
|
print_file(f, indent, "{\n");
|
|
|
|
print_file(f, indent + 1, "short Pad;\n");
|
|
|
|
print_file(f, indent + 1, "unsigned char Format[%s_FORMAT_STRING_SIZE];\n", str);
|
|
|
|
print_file(f, indent, "} MIDL_%s_FORMAT_STRING;\n", str);
|
|
|
|
print_file(f, indent, "\n");
|
|
|
|
}
|
|
|
|
|
2007-10-16 03:06:33 +02:00
|
|
|
void write_formatstringsdecl(FILE *f, int indent, ifref_list_t *ifaces, type_pred_t pred)
|
2006-08-17 03:01:56 +02:00
|
|
|
{
|
|
|
|
print_file(f, indent, "#define TYPE_FORMAT_STRING_SIZE %d\n",
|
2007-10-16 03:06:33 +02:00
|
|
|
get_size_typeformatstring(ifaces, pred));
|
2006-08-17 03:01:56 +02:00
|
|
|
|
|
|
|
print_file(f, indent, "#define PROC_FORMAT_STRING_SIZE %d\n",
|
2007-10-16 03:06:33 +02:00
|
|
|
get_size_procformatstring(ifaces, pred));
|
2006-08-17 03:01:56 +02:00
|
|
|
|
|
|
|
fprintf(f, "\n");
|
|
|
|
write_formatdesc(f, indent, "TYPE");
|
|
|
|
write_formatdesc(f, indent, "PROC");
|
|
|
|
fprintf(f, "\n");
|
|
|
|
print_file(f, indent, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString;\n");
|
|
|
|
print_file(f, indent, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString;\n");
|
|
|
|
print_file(f, indent, "\n");
|
|
|
|
}
|
|
|
|
|
2006-01-06 21:06:24 +01:00
|
|
|
static inline int is_base_type(unsigned char type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_USMALL:
|
|
|
|
case RPC_FC_SMALL:
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
case RPC_FC_SHORT:
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_LONG:
|
|
|
|
case RPC_FC_HYPER:
|
|
|
|
case RPC_FC_IGNORE:
|
|
|
|
case RPC_FC_FLOAT:
|
|
|
|
case RPC_FC_DOUBLE:
|
|
|
|
case RPC_FC_ENUM16:
|
|
|
|
case RPC_FC_ENUM32:
|
|
|
|
case RPC_FC_ERROR_STATUS_T:
|
2006-02-07 12:30:55 +01:00
|
|
|
case RPC_FC_BIND_PRIMITIVE:
|
2006-01-06 21:06:24 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
int decl_indirect(const type_t *t)
|
|
|
|
{
|
|
|
|
return is_user_type(t)
|
|
|
|
|| (!is_base_type(t->type)
|
|
|
|
&& !is_ptr(t)
|
|
|
|
&& !is_array(t));
|
|
|
|
}
|
|
|
|
|
2006-01-24 11:05:51 +01:00
|
|
|
static size_t write_procformatstring_var(FILE *file, int indent,
|
2007-05-16 02:45:59 +02:00
|
|
|
const var_t *var, int is_return)
|
2005-12-08 12:53:58 +01:00
|
|
|
{
|
2005-12-26 13:05:29 +01:00
|
|
|
size_t size;
|
2006-01-24 11:05:51 +01:00
|
|
|
const type_t *type = var->type;
|
|
|
|
|
|
|
|
int is_in = is_attr(var->attrs, ATTR_IN);
|
|
|
|
int is_out = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
|
|
|
|
if (!is_in && !is_out) is_in = TRUE;
|
2005-12-26 13:22:32 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (!type->declarray && is_base_type(type->type))
|
2005-12-08 12:53:58 +01:00
|
|
|
{
|
2005-12-26 13:05:55 +01:00
|
|
|
if (is_return)
|
|
|
|
print_file(file, indent, "0x53, /* FC_RETURN_PARAM_BASETYPE */\n");
|
|
|
|
else
|
|
|
|
print_file(file, indent, "0x4e, /* FC_IN_PARAM_BASETYPE */\n");
|
|
|
|
|
2007-05-30 23:42:57 +02:00
|
|
|
if (type->type == RPC_FC_BIND_PRIMITIVE)
|
2007-05-10 05:46:31 +02:00
|
|
|
{
|
2007-05-30 23:42:57 +02:00
|
|
|
print_file(file, indent, "0x%02x, /* FC_IGNORE */\n", RPC_FC_IGNORE);
|
2007-05-10 05:46:31 +02:00
|
|
|
size = 2; /* includes param type prefix */
|
|
|
|
}
|
2007-05-30 23:42:57 +02:00
|
|
|
else if (is_base_type(type->type))
|
2005-12-26 13:05:55 +01:00
|
|
|
{
|
2007-05-30 23:42:57 +02:00
|
|
|
print_file(file, indent, "0x%02x, /* %s */\n", type->type, string_of_type(type->type));
|
2006-02-07 12:30:55 +01:00
|
|
|
size = 2; /* includes param type prefix */
|
2007-05-10 05:46:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-24 11:05:51 +01:00
|
|
|
error("Unknown/unsupported type: %s (0x%02x)\n", var->name, type->type);
|
2005-12-26 13:05:55 +01:00
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (is_return)
|
|
|
|
print_file(file, indent, "0x52, /* FC_RETURN_PARAM */\n");
|
2005-12-26 13:22:32 +01:00
|
|
|
else if (is_in && is_out)
|
2005-12-26 13:07:55 +01:00
|
|
|
print_file(file, indent, "0x50, /* FC_IN_OUT_PARAM */\n");
|
2005-12-26 13:22:32 +01:00
|
|
|
else if (is_out)
|
2005-12-26 13:07:55 +01:00
|
|
|
print_file(file, indent, "0x51, /* FC_OUT_PARAM */\n");
|
2005-12-26 13:06:29 +01:00
|
|
|
else
|
|
|
|
print_file(file, indent, "0x4d, /* FC_IN_PARAM */\n");
|
2005-12-26 13:07:55 +01:00
|
|
|
|
2005-12-26 13:05:55 +01:00
|
|
|
print_file(file, indent, "0x01,\n");
|
2007-05-16 02:45:59 +02:00
|
|
|
print_file(file, indent, "NdrFcShort(0x%x),\n", type->typestring_offset);
|
2005-12-26 13:05:55 +01:00
|
|
|
size = 4; /* includes param type prefix */
|
2005-12-08 12:53:58 +01:00
|
|
|
}
|
2005-12-26 13:05:29 +01:00
|
|
|
return size;
|
2005-12-08 12:53:58 +01:00
|
|
|
}
|
|
|
|
|
2007-10-16 03:06:33 +02:00
|
|
|
void write_procformatstring(FILE *file, const ifref_list_t *ifaces, type_pred_t pred)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2007-01-22 14:21:56 +01:00
|
|
|
const ifref_t *iface;
|
2005-12-08 12:52:13 +01:00
|
|
|
int indent = 0;
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *var;
|
2005-12-08 12:52:13 +01:00
|
|
|
|
|
|
|
print_file(file, indent, "static const MIDL_PROC_FORMAT_STRING __MIDL_ProcFormatString =\n");
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "0,\n");
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
indent++;
|
|
|
|
|
2007-01-22 14:21:56 +01:00
|
|
|
if (ifaces) LIST_FOR_EACH_ENTRY( iface, ifaces, const ifref_t, entry )
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2007-10-16 03:06:33 +02:00
|
|
|
if (!pred(iface->iface))
|
2006-06-01 16:40:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (iface->iface->funcs)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2007-01-22 14:23:08 +01:00
|
|
|
const func_t *func;
|
|
|
|
LIST_FOR_EACH_ENTRY( func, iface->iface->funcs, const func_t, entry )
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2007-01-24 20:06:51 +01:00
|
|
|
if (is_local(func->def->attrs)) continue;
|
2006-06-01 16:40:10 +02:00
|
|
|
/* emit argument data */
|
|
|
|
if (func->args)
|
2005-12-26 13:08:51 +01:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
2007-05-16 02:45:59 +02:00
|
|
|
write_procformatstring_var(file, indent, var, FALSE);
|
2005-12-26 13:08:51 +01:00
|
|
|
}
|
2005-12-26 13:09:36 +01:00
|
|
|
|
2006-06-01 16:40:10 +02:00
|
|
|
/* emit return value data */
|
|
|
|
var = func->def;
|
2007-05-10 05:50:49 +02:00
|
|
|
if (is_void(var->type))
|
2006-06-01 16:40:10 +02:00
|
|
|
{
|
|
|
|
print_file(file, indent, "0x5b, /* FC_END */\n");
|
|
|
|
print_file(file, indent, "0x5c, /* FC_PAD */\n");
|
|
|
|
}
|
|
|
|
else
|
2007-05-16 02:45:59 +02:00
|
|
|
write_procformatstring_var(file, indent, var, TRUE);
|
2005-12-26 13:08:51 +01:00
|
|
|
}
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, indent, "0x0\n");
|
|
|
|
indent--;
|
|
|
|
print_file(file, indent, "}\n");
|
|
|
|
indent--;
|
|
|
|
print_file(file, indent, "};\n");
|
|
|
|
print_file(file, indent, "\n");
|
|
|
|
}
|
|
|
|
|
2007-02-06 15:55:29 +01:00
|
|
|
static int write_base_type(FILE *file, const type_t *type, unsigned int *typestring_offset)
|
|
|
|
{
|
2007-05-10 05:46:31 +02:00
|
|
|
if (is_base_type(type->type))
|
2007-02-06 15:55:29 +01:00
|
|
|
{
|
2007-05-10 05:46:31 +02:00
|
|
|
print_file(file, 2, "0x%02x,\t/* %s */\n", type->type, string_of_type(type->type));
|
|
|
|
*typestring_offset += 1;
|
|
|
|
return 1;
|
2007-02-06 15:55:29 +01:00
|
|
|
}
|
2007-05-10 05:50:49 +02:00
|
|
|
|
2007-02-06 15:55:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-24 11:08:20 +01:00
|
|
|
/* write conformance / variance descriptor */
|
2007-09-13 01:10:01 +02:00
|
|
|
static size_t write_conf_or_var_desc(FILE *file, const type_t *structure,
|
2007-10-11 00:29:54 +02:00
|
|
|
unsigned int baseoff, const type_t *type,
|
|
|
|
const expr_t *expr)
|
2006-01-24 11:08:20 +01:00
|
|
|
{
|
2006-01-24 11:09:03 +01:00
|
|
|
unsigned char operator_type = 0;
|
2007-10-11 00:29:54 +02:00
|
|
|
unsigned char conftype = RPC_FC_NORMAL_CONFORMANCE;
|
|
|
|
const char *conftype_string = "";
|
2006-01-24 11:09:03 +01:00
|
|
|
const char *operator_string = "no operators";
|
2007-06-06 03:50:31 +02:00
|
|
|
const expr_t *subexpr;
|
2006-01-24 11:09:03 +01:00
|
|
|
|
2007-09-18 00:24:14 +02:00
|
|
|
if (!expr)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcLong(0xffffffff),\t/* -1 */\n");
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2007-09-04 18:33:23 +02:00
|
|
|
if (!structure)
|
|
|
|
{
|
|
|
|
/* Top-level conformance calculations are done inline. */
|
|
|
|
print_file (file, 2, "0x%x,\t/* Corr desc: parameter */\n",
|
|
|
|
RPC_FC_TOP_LEVEL_CONFORMANCE);
|
|
|
|
print_file (file, 2, "0x0,\n");
|
|
|
|
print_file (file, 2, "NdrFcShort(0x0),\n");
|
|
|
|
return 4;
|
|
|
|
}
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2006-01-31 18:05:43 +01:00
|
|
|
if (expr->is_const)
|
|
|
|
{
|
|
|
|
if (expr->cval > UCHAR_MAX * (USHRT_MAX + 1) + USHRT_MAX)
|
|
|
|
error("write_conf_or_var_desc: constant value %ld is greater than "
|
|
|
|
"the maximum constant size of %d\n", expr->cval,
|
|
|
|
UCHAR_MAX * (USHRT_MAX + 1) + USHRT_MAX);
|
|
|
|
|
|
|
|
print_file(file, 2, "0x%x, /* Corr desc: constant, val = %ld */\n",
|
|
|
|
RPC_FC_CONSTANT_CONFORMANCE, expr->cval);
|
|
|
|
print_file(file, 2, "0x%x,\n", expr->cval & ~USHRT_MAX);
|
2006-03-31 13:44:39 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\n", expr->cval & USHRT_MAX);
|
2006-01-31 18:05:43 +01:00
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2007-10-11 00:29:54 +02:00
|
|
|
if (is_ptr(type) || (is_array(type) && !type->declarray))
|
|
|
|
{
|
|
|
|
conftype = RPC_FC_POINTER_CONFORMANCE;
|
|
|
|
conftype_string = "field pointer, ";
|
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
subexpr = expr;
|
2006-01-24 11:09:03 +01:00
|
|
|
switch (subexpr->type)
|
|
|
|
{
|
|
|
|
case EXPR_PPTR:
|
|
|
|
subexpr = subexpr->ref;
|
|
|
|
operator_type = RPC_FC_DEREFERENCE;
|
|
|
|
operator_string = "FC_DEREFERENCE";
|
|
|
|
break;
|
|
|
|
case EXPR_DIV:
|
|
|
|
if (subexpr->u.ext->is_const && (subexpr->u.ext->cval == 2))
|
|
|
|
{
|
|
|
|
subexpr = subexpr->ref;
|
|
|
|
operator_type = RPC_FC_DIV_2;
|
|
|
|
operator_string = "FC_DIV_2";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPR_MUL:
|
|
|
|
if (subexpr->u.ext->is_const && (subexpr->u.ext->cval == 2))
|
|
|
|
{
|
|
|
|
subexpr = subexpr->ref;
|
|
|
|
operator_type = RPC_FC_MULT_2;
|
|
|
|
operator_string = "FC_MULT_2";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPR_SUB:
|
|
|
|
if (subexpr->u.ext->is_const && (subexpr->u.ext->cval == 1))
|
|
|
|
{
|
|
|
|
subexpr = subexpr->ref;
|
|
|
|
operator_type = RPC_FC_SUB_1;
|
|
|
|
operator_string = "FC_SUB_1";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPR_ADD:
|
|
|
|
if (subexpr->u.ext->is_const && (subexpr->u.ext->cval == 1))
|
|
|
|
{
|
|
|
|
subexpr = subexpr->ref;
|
|
|
|
operator_type = RPC_FC_ADD_1;
|
|
|
|
operator_string = "FC_ADD_1";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (subexpr->type == EXPR_IDENTIFIER)
|
2006-01-24 11:08:20 +01:00
|
|
|
{
|
2006-01-24 11:12:54 +01:00
|
|
|
const type_t *correlation_variable = NULL;
|
2006-08-09 23:20:35 +02:00
|
|
|
unsigned char correlation_variable_type;
|
2006-01-24 11:12:54 +01:00
|
|
|
unsigned char param_type = 0;
|
2007-09-04 18:33:23 +02:00
|
|
|
size_t offset = 0;
|
|
|
|
const var_t *var;
|
2006-01-24 11:12:54 +01:00
|
|
|
|
2007-09-04 18:33:23 +02:00
|
|
|
if (structure->fields) LIST_FOR_EACH_ENTRY( var, structure->fields, const var_t, entry )
|
2006-01-24 11:12:54 +01:00
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
unsigned int align = 0;
|
|
|
|
/* FIXME: take alignment into account */
|
|
|
|
if (var->name && !strcmp(var->name, subexpr->u.sval))
|
2006-01-24 11:12:54 +01:00
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
correlation_variable = var->type;
|
|
|
|
break;
|
2006-01-24 11:08:20 +01:00
|
|
|
}
|
2007-09-04 18:33:23 +02:00
|
|
|
offset += type_memsize(var->type, &align);
|
2006-01-24 11:12:54 +01:00
|
|
|
}
|
2007-09-04 18:33:23 +02:00
|
|
|
if (!correlation_variable)
|
|
|
|
error("write_conf_or_var_desc: couldn't find variable %s in structure\n",
|
|
|
|
subexpr->u.sval);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2007-09-04 18:33:23 +02:00
|
|
|
offset -= baseoff;
|
2006-08-30 02:19:21 +02:00
|
|
|
correlation_variable_type = correlation_variable->type;
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2006-08-09 23:20:35 +02:00
|
|
|
switch (correlation_variable_type)
|
2006-01-24 11:12:54 +01:00
|
|
|
{
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_SMALL:
|
|
|
|
param_type = RPC_FC_SMALL;
|
|
|
|
break;
|
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_USMALL:
|
|
|
|
param_type = RPC_FC_USMALL;
|
|
|
|
break;
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_SHORT:
|
2007-06-26 03:27:24 +02:00
|
|
|
case RPC_FC_ENUM16:
|
2006-01-24 11:12:54 +01:00
|
|
|
param_type = RPC_FC_SHORT;
|
|
|
|
break;
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
param_type = RPC_FC_USHORT;
|
|
|
|
break;
|
|
|
|
case RPC_FC_LONG:
|
2007-06-26 03:27:24 +02:00
|
|
|
case RPC_FC_ENUM32:
|
2006-01-24 11:12:54 +01:00
|
|
|
param_type = RPC_FC_LONG;
|
|
|
|
break;
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
param_type = RPC_FC_ULONG;
|
|
|
|
break;
|
2007-02-06 16:00:41 +01:00
|
|
|
case RPC_FC_RP:
|
|
|
|
case RPC_FC_UP:
|
|
|
|
case RPC_FC_OP:
|
|
|
|
case RPC_FC_FP:
|
|
|
|
if (sizeof(void *) == 4) /* FIXME */
|
|
|
|
param_type = RPC_FC_LONG;
|
|
|
|
else
|
|
|
|
param_type = RPC_FC_HYPER;
|
|
|
|
break;
|
2006-01-24 11:12:54 +01:00
|
|
|
default:
|
|
|
|
error("write_conf_or_var_desc: conformance variable type not supported 0x%x\n",
|
2006-08-09 23:20:35 +02:00
|
|
|
correlation_variable_type);
|
2006-01-24 11:08:20 +01:00
|
|
|
}
|
2006-01-24 11:12:54 +01:00
|
|
|
|
2007-10-11 00:29:54 +02:00
|
|
|
print_file(file, 2, "0x%x, /* Corr desc: %s%s */\n",
|
|
|
|
conftype | param_type, conftype_string, string_of_type(param_type));
|
2006-01-24 11:12:54 +01:00
|
|
|
print_file(file, 2, "0x%x, /* %s */\n", operator_type, operator_string);
|
2007-09-04 18:33:23 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* offset = %d */\n",
|
|
|
|
offset, offset);
|
2006-01-24 11:08:20 +01:00
|
|
|
}
|
|
|
|
else
|
2006-01-27 12:53:32 +01:00
|
|
|
{
|
|
|
|
unsigned int callback_offset = 0;
|
2007-09-04 18:33:23 +02:00
|
|
|
struct expr_eval_routine *eval;
|
|
|
|
int found = 0;
|
2006-01-27 12:53:32 +01:00
|
|
|
|
2007-09-04 18:33:23 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(eval, &expr_eval_routines, struct expr_eval_routine, entry)
|
2006-01-27 12:53:32 +01:00
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
if (!strcmp (eval->structure->name, structure->name)
|
|
|
|
&& !compare_expr (eval->expr, expr))
|
2006-01-31 12:24:11 +01:00
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
found = 1;
|
|
|
|
break;
|
2006-01-31 12:24:11 +01:00
|
|
|
}
|
2007-09-04 18:33:23 +02:00
|
|
|
callback_offset++;
|
2006-01-27 12:53:32 +01:00
|
|
|
}
|
2007-09-04 18:33:23 +02:00
|
|
|
|
|
|
|
if (!found)
|
2006-01-27 12:53:32 +01:00
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
eval = xmalloc (sizeof(*eval));
|
|
|
|
eval->structure = structure;
|
2007-10-11 00:29:54 +02:00
|
|
|
eval->baseoff = baseoff;
|
2007-09-04 18:33:23 +02:00
|
|
|
eval->expr = expr;
|
|
|
|
list_add_tail (&expr_eval_routines, &eval->entry);
|
2006-01-27 12:53:32 +01:00
|
|
|
}
|
|
|
|
|
2006-01-31 12:24:11 +01:00
|
|
|
if (callback_offset > USHRT_MAX)
|
|
|
|
error("Maximum number of callback routines reached\n");
|
|
|
|
|
2007-10-11 00:29:54 +02:00
|
|
|
print_file(file, 2, "0x%x, /* Corr desc: %s */\n", conftype, conftype_string);
|
2006-01-27 12:53:32 +01:00
|
|
|
print_file(file, 2, "0x%x, /* %s */\n", RPC_FC_CALLBACK, "FC_CALLBACK");
|
2006-03-31 13:44:39 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %u */\n", callback_offset, callback_offset);
|
2006-01-27 12:53:32 +01:00
|
|
|
}
|
2006-01-24 11:08:20 +01:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2007-02-06 15:54:58 +01:00
|
|
|
static size_t fields_memsize(const var_list_t *fields, unsigned int *align)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
2007-09-04 20:04:37 +02:00
|
|
|
int have_align = FALSE;
|
2006-01-24 11:07:13 +01:00
|
|
|
size_t size = 0;
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *v;
|
|
|
|
|
|
|
|
if (!fields) return 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, fields, const var_t, entry )
|
2007-09-04 20:04:37 +02:00
|
|
|
{
|
|
|
|
unsigned int falign = 0;
|
|
|
|
size_t fsize = type_memsize(v->type, &falign);
|
|
|
|
if (!have_align)
|
|
|
|
{
|
|
|
|
*align = falign;
|
|
|
|
have_align = TRUE;
|
|
|
|
}
|
|
|
|
size = (size + (falign - 1)) & ~(falign - 1);
|
|
|
|
size += fsize;
|
|
|
|
}
|
2007-01-22 14:26:12 +01:00
|
|
|
|
2007-09-04 20:04:37 +02:00
|
|
|
size = (size + (*align - 1)) & ~(*align - 1);
|
2006-01-24 11:07:13 +01:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2007-05-19 01:53:27 +02:00
|
|
|
static size_t union_memsize(const var_list_t *fields, unsigned int *pmaxa)
|
|
|
|
{
|
|
|
|
size_t size, maxs = 0;
|
|
|
|
unsigned int align = *pmaxa;
|
|
|
|
const var_t *v;
|
|
|
|
|
|
|
|
if (fields) LIST_FOR_EACH_ENTRY( v, fields, const var_t, entry )
|
|
|
|
{
|
|
|
|
/* we could have an empty default field with NULL type */
|
|
|
|
if (v->type)
|
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
size = type_memsize(v->type, &align);
|
2007-05-19 01:53:27 +02:00
|
|
|
if (maxs < size) maxs = size;
|
|
|
|
if (*pmaxa < align) *pmaxa = align;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return maxs;
|
|
|
|
}
|
|
|
|
|
2007-09-14 03:04:32 +02:00
|
|
|
int get_padding(const var_list_t *fields)
|
|
|
|
{
|
|
|
|
unsigned short offset = 0;
|
|
|
|
int salign = -1;
|
|
|
|
const var_t *f;
|
|
|
|
|
|
|
|
if (!fields)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(f, fields, const var_t, entry)
|
|
|
|
{
|
|
|
|
type_t *ft = f->type;
|
|
|
|
unsigned int align = 0;
|
|
|
|
size_t size = type_memsize(ft, &align);
|
|
|
|
if (salign == -1)
|
|
|
|
salign = align;
|
|
|
|
offset = (offset + (align - 1)) & ~(align - 1);
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((offset + (salign - 1)) & ~(salign - 1)) - offset;
|
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
size_t type_memsize(const type_t *t, unsigned int *align)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
|
|
|
size_t size = 0;
|
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
if (t->declarray && is_conformant_array(t))
|
|
|
|
{
|
|
|
|
type_memsize(t->ref, align);
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
else if (is_ptr(t) || is_conformant_array(t))
|
2007-02-06 15:54:58 +01:00
|
|
|
{
|
|
|
|
size = sizeof(void *);
|
|
|
|
if (size > *align) *align = size;
|
|
|
|
}
|
|
|
|
else switch (t->type)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_USMALL:
|
|
|
|
case RPC_FC_SMALL:
|
|
|
|
size = 1;
|
2007-02-06 15:54:58 +01:00
|
|
|
if (size > *align) *align = size;
|
2006-01-24 11:07:13 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
case RPC_FC_SHORT:
|
|
|
|
case RPC_FC_ENUM16:
|
|
|
|
size = 2;
|
2007-02-06 15:54:58 +01:00
|
|
|
if (size > *align) *align = size;
|
2006-01-24 11:07:13 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_LONG:
|
|
|
|
case RPC_FC_ERROR_STATUS_T:
|
|
|
|
case RPC_FC_ENUM32:
|
|
|
|
case RPC_FC_FLOAT:
|
|
|
|
size = 4;
|
2007-02-06 15:54:58 +01:00
|
|
|
if (size > *align) *align = size;
|
2006-01-24 11:07:13 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_HYPER:
|
|
|
|
case RPC_FC_DOUBLE:
|
|
|
|
size = 8;
|
2007-02-06 15:54:58 +01:00
|
|
|
if (size > *align) *align = size;
|
2006-01-24 11:07:13 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_PSTRUCT:
|
|
|
|
case RPC_FC_BOGUS_STRUCT:
|
2007-05-19 01:53:27 +02:00
|
|
|
size = fields_memsize(t->fields, align);
|
|
|
|
break;
|
2006-01-24 11:07:13 +01:00
|
|
|
case RPC_FC_ENCAPSULATED_UNION:
|
|
|
|
case RPC_FC_NON_ENCAPSULATED_UNION:
|
2007-05-19 01:53:27 +02:00
|
|
|
size = union_memsize(t->fields, align);
|
2006-01-24 11:07:13 +01:00
|
|
|
break;
|
2007-06-06 03:50:31 +02:00
|
|
|
case RPC_FC_SMFARRAY:
|
|
|
|
case RPC_FC_LGFARRAY:
|
|
|
|
case RPC_FC_SMVARRAY:
|
|
|
|
case RPC_FC_LGVARRAY:
|
|
|
|
case RPC_FC_BOGUS_ARRAY:
|
2007-06-06 03:52:24 +02:00
|
|
|
size = t->dim * type_memsize(t->ref, align);
|
2007-06-06 03:50:31 +02:00
|
|
|
break;
|
2006-01-24 11:07:13 +01:00
|
|
|
default:
|
2006-03-31 13:44:16 +02:00
|
|
|
error("type_memsize: Unknown type %d\n", t->type);
|
2006-01-24 11:07:13 +01:00
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2007-05-21 08:55:43 +02:00
|
|
|
static unsigned int write_nonsimple_pointer(FILE *file, const type_t *type, size_t offset)
|
2007-05-10 05:50:49 +02:00
|
|
|
{
|
|
|
|
short absoff = type->ref->typestring_offset;
|
|
|
|
short reloff = absoff - (offset + 2);
|
2007-05-12 02:27:40 +02:00
|
|
|
int ptr_attr = is_ptr(type->ref) ? 0x10 : 0x0;
|
|
|
|
|
|
|
|
print_file(file, 2, "0x%02x, 0x%x,\t/* %s */\n",
|
|
|
|
type->type, ptr_attr, string_of_type(type->type));
|
2007-05-10 05:50:49 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%hd) */\n",
|
|
|
|
reloff, reloff, absoff);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2007-09-26 20:32:47 +02:00
|
|
|
static unsigned char conf_string_type_of_char_type(unsigned char t)
|
|
|
|
{
|
|
|
|
switch (t)
|
|
|
|
{
|
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
return RPC_FC_C_CSTRING;
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
return RPC_FC_C_WSTRING;
|
|
|
|
}
|
|
|
|
|
2007-10-18 17:10:45 +02:00
|
|
|
error("string_type_of_char_type: unrecognized type %d\n", t);
|
2007-09-26 20:32:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-21 08:55:43 +02:00
|
|
|
static unsigned int write_simple_pointer(FILE *file, const type_t *type)
|
2007-05-10 05:50:49 +02:00
|
|
|
{
|
2007-09-26 20:32:47 +02:00
|
|
|
unsigned char fc
|
|
|
|
= is_string_type(type->attrs, type)
|
|
|
|
? conf_string_type_of_char_type(type->ref->type)
|
|
|
|
: type->ref->type;
|
2007-05-10 05:50:49 +02:00
|
|
|
print_file(file, 2, "0x%02x, 0x8,\t/* %s [simple_pointer] */\n",
|
|
|
|
type->type, string_of_type(type->type));
|
2007-09-26 20:32:47 +02:00
|
|
|
print_file(file, 2, "0x%02x,\t/* %s */\n", fc, string_of_type(fc));
|
2007-05-10 05:50:49 +02:00
|
|
|
print_file(file, 2, "0x5c,\t/* FC_PAD */\n");
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2007-10-03 06:40:13 +02:00
|
|
|
static void print_start_tfs_comment(FILE *file, type_t *t, unsigned int tfsoff)
|
|
|
|
{
|
|
|
|
print_file(file, 0, "/* %u (", tfsoff);
|
|
|
|
write_type_decl(file, t, NULL);
|
|
|
|
print_file(file, 0, ") */\n");
|
|
|
|
}
|
|
|
|
|
2007-05-21 08:55:43 +02:00
|
|
|
static size_t write_pointer_tfs(FILE *file, type_t *type, unsigned int *typestring_offset)
|
2007-05-16 02:48:20 +02:00
|
|
|
{
|
2007-05-21 08:55:43 +02:00
|
|
|
unsigned int offset = *typestring_offset;
|
2007-05-16 02:48:20 +02:00
|
|
|
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, offset);
|
2007-05-25 02:50:02 +02:00
|
|
|
update_tfsoff(type, offset, file);
|
2007-05-16 02:48:20 +02:00
|
|
|
|
|
|
|
if (type->ref->typestring_offset)
|
|
|
|
*typestring_offset += write_nonsimple_pointer(file, type, offset);
|
|
|
|
else if (is_base_type(type->ref->type))
|
|
|
|
*typestring_offset += write_simple_pointer(file, type);
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2007-05-25 02:50:02 +02:00
|
|
|
static int processed(const type_t *type)
|
2007-05-16 02:48:20 +02:00
|
|
|
{
|
2007-05-25 02:50:02 +02:00
|
|
|
return type->typestring_offset && !type->tfswrite;
|
2007-05-16 02:48:20 +02:00
|
|
|
}
|
|
|
|
|
2007-10-20 00:30:12 +02:00
|
|
|
static int user_type_has_variable_size(const type_t *t)
|
|
|
|
{
|
|
|
|
if (is_ptr(t))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
switch (t->type)
|
|
|
|
{
|
|
|
|
case RPC_FC_PSTRUCT:
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* Note: Since this only applies to user types, we can't have a conformant
|
|
|
|
array here, and strings should get filed under pointer in this case. */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
static void write_user_tfs(FILE *file, type_t *type, unsigned int *tfsoff)
|
|
|
|
{
|
2007-06-14 01:15:41 +02:00
|
|
|
unsigned int start, absoff, flags;
|
2007-06-14 01:13:04 +02:00
|
|
|
unsigned int align = 0, ualign = 0;
|
|
|
|
const char *name;
|
|
|
|
type_t *utype = get_user_type(type, &name);
|
2007-10-20 00:30:12 +02:00
|
|
|
size_t usize = user_type_has_variable_size(utype) ? 0 : type_memsize(utype, &ualign);
|
2007-06-14 01:13:04 +02:00
|
|
|
size_t size = type_memsize(type, &align);
|
|
|
|
unsigned short funoff = user_type_offset(name);
|
|
|
|
short reloff;
|
|
|
|
|
|
|
|
guard_rec(type);
|
|
|
|
|
|
|
|
if (is_base_type(utype->type))
|
|
|
|
{
|
|
|
|
absoff = *tfsoff;
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, utype, absoff);
|
2007-06-14 01:13:04 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", utype->type, string_of_type(utype->type));
|
|
|
|
print_file(file, 2, "0x5c,\t/* FC_PAD */\n");
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!processed(utype))
|
|
|
|
write_embedded_types(file, NULL, utype, utype->name, TRUE, tfsoff);
|
|
|
|
absoff = utype->typestring_offset;
|
|
|
|
}
|
|
|
|
|
2007-06-14 01:15:41 +02:00
|
|
|
if (utype->type == RPC_FC_RP)
|
|
|
|
flags = 0x40;
|
|
|
|
else if (utype->type == RPC_FC_UP)
|
|
|
|
flags = 0x80;
|
|
|
|
else
|
|
|
|
flags = 0;
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
start = *tfsoff;
|
|
|
|
update_tfsoff(type, start, file);
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, start);
|
2007-06-14 01:13:04 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* FC_USER_MARSHAL */\n", RPC_FC_USER_MARSHAL);
|
2007-06-14 01:15:41 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* Alignment= %d, Flags= %02x */\n",
|
|
|
|
flags | (align - 1), align - 1, flags);
|
2007-06-14 01:13:04 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Function offset= %hu */\n", funoff, funoff);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%lx),\t/* %lu */\n", size, size);
|
2007-10-20 00:30:12 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%lx),\t/* %lu */\n", usize, usize);
|
2007-06-14 01:13:04 +02:00
|
|
|
*tfsoff += 8;
|
|
|
|
reloff = absoff - *tfsoff;
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%lu) */\n", reloff, reloff, absoff);
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
|
|
|
|
2007-09-19 00:28:49 +02:00
|
|
|
static void write_member_type(FILE *file, const type_t *cont,
|
|
|
|
const attr_list_t *attrs, const type_t *type,
|
2007-06-12 03:51:41 +02:00
|
|
|
unsigned int *corroff, unsigned int *tfsoff)
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
2007-10-11 00:29:54 +02:00
|
|
|
if (is_embedded_complex(type) && !is_conformant_array(type))
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
2007-06-12 03:51:41 +02:00
|
|
|
size_t absoff;
|
|
|
|
short reloff;
|
|
|
|
|
2007-09-19 00:28:49 +02:00
|
|
|
if (is_union(type->type) && is_attr(attrs, ATTR_SWITCHIS))
|
2007-06-12 03:51:41 +02:00
|
|
|
{
|
|
|
|
absoff = *corroff;
|
|
|
|
*corroff += 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
absoff = type->typestring_offset;
|
|
|
|
}
|
|
|
|
reloff = absoff - (*tfsoff + 2);
|
2007-06-06 03:50:31 +02:00
|
|
|
|
|
|
|
print_file(file, 2, "0x4c,\t/* FC_EMBEDDED_COMPLEX */\n");
|
|
|
|
/* FIXME: actually compute necessary padding */
|
|
|
|
print_file(file, 2, "0x0,\t/* FIXME: padding */\n");
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%lu) */\n",
|
|
|
|
reloff, reloff, absoff);
|
|
|
|
*tfsoff += 4;
|
|
|
|
}
|
2007-10-11 00:29:54 +02:00
|
|
|
else if (is_ptr(type) || is_conformant_array(type))
|
2007-06-15 03:27:19 +02:00
|
|
|
{
|
2007-09-19 00:28:49 +02:00
|
|
|
unsigned char fc = (cont->type == RPC_FC_BOGUS_STRUCT
|
|
|
|
? RPC_FC_POINTER
|
|
|
|
: RPC_FC_LONG);
|
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", fc, string_of_type(fc));
|
2007-06-15 03:27:19 +02:00
|
|
|
*tfsoff += 1;
|
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else if (!write_base_type(file, type, tfsoff))
|
|
|
|
error("Unsupported member type 0x%x\n", type->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_end(FILE *file, unsigned int *tfsoff)
|
|
|
|
{
|
|
|
|
if (*tfsoff % 2 == 0)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x,\t\t/* FC_PAD */\n", RPC_FC_PAD);
|
|
|
|
*tfsoff += 1;
|
|
|
|
}
|
|
|
|
print_file(file, 2, "0x%x,\t\t/* FC_END */\n", RPC_FC_END);
|
|
|
|
*tfsoff += 1;
|
|
|
|
}
|
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
static void write_descriptors(FILE *file, type_t *type, unsigned int *tfsoff)
|
|
|
|
{
|
|
|
|
unsigned int offset = 0;
|
|
|
|
var_list_t *fs = type->fields;
|
|
|
|
var_t *f;
|
|
|
|
|
|
|
|
if (fs) LIST_FOR_EACH_ENTRY(f, fs, var_t, entry)
|
|
|
|
{
|
|
|
|
unsigned int align = 0;
|
|
|
|
type_t *ft = f->type;
|
|
|
|
if (is_union(ft->type) && is_attr(f->attrs, ATTR_SWITCHIS))
|
|
|
|
{
|
|
|
|
unsigned int absoff = ft->typestring_offset;
|
|
|
|
short reloff = absoff - (*tfsoff + 6);
|
|
|
|
print_file(file, 0, "/* %d */\n", *tfsoff);
|
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", ft->type, string_of_type(ft->type));
|
|
|
|
print_file(file, 2, "0x%x,\t/* FIXME: always FC_LONG */\n", RPC_FC_LONG);
|
2007-10-11 00:29:54 +02:00
|
|
|
write_conf_or_var_desc(file, current_structure, offset, ft,
|
2007-06-12 03:51:41 +02:00
|
|
|
get_attrp(f->attrs, ATTR_SWITCHIS));
|
|
|
|
print_file(file, 2, "NdrFcShort(%hd),\t/* Offset= %hd (%u) */\n",
|
|
|
|
reloff, reloff, absoff);
|
|
|
|
*tfsoff += 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: take alignment into account */
|
|
|
|
offset += type_memsize(ft, &align);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-19 13:05:25 +02:00
|
|
|
static int write_no_repeat_pointer_descriptions(
|
2007-06-21 01:51:23 +02:00
|
|
|
FILE *file, type_t *type,
|
2007-06-19 13:05:25 +02:00
|
|
|
size_t *offset_in_memory, size_t *offset_in_buffer,
|
|
|
|
unsigned int *typestring_offset)
|
2006-02-03 18:51:17 +01:00
|
|
|
{
|
2007-06-19 13:05:25 +02:00
|
|
|
int written = 0;
|
|
|
|
unsigned int align;
|
2006-02-03 18:51:17 +01:00
|
|
|
|
2007-10-11 00:29:54 +02:00
|
|
|
if (is_ptr(type) || (!type->declarray && is_conformant_array(type)))
|
2006-02-03 18:51:17 +01:00
|
|
|
{
|
2007-06-19 13:05:25 +02:00
|
|
|
print_file(file, 2, "0x%02x, /* FC_NO_REPEAT */\n", RPC_FC_NO_REPEAT);
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_PAD */\n", RPC_FC_PAD);
|
|
|
|
|
|
|
|
/* pointer instance */
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Memory offset = %d */\n", *offset_in_memory, *offset_in_memory);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Buffer offset = %d */\n", *offset_in_buffer, *offset_in_buffer);
|
2007-05-16 02:48:20 +02:00
|
|
|
*typestring_offset += 6;
|
2006-02-03 18:51:17 +01:00
|
|
|
|
2007-10-11 00:29:54 +02:00
|
|
|
if (is_ptr(type))
|
2007-05-16 02:48:20 +02:00
|
|
|
write_pointer_tfs(file, type, typestring_offset);
|
2007-05-10 05:50:49 +02:00
|
|
|
else
|
2007-10-11 00:29:54 +02:00
|
|
|
{
|
|
|
|
unsigned absoff = type->typestring_offset;
|
|
|
|
short reloff = absoff - (*typestring_offset + 2);
|
|
|
|
/* FIXME: get pointer attributes from field */
|
|
|
|
print_file(file, 2, "0x%02x, 0x0,\t/* %s */\n", RPC_FC_UP, "FC_UP");
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
|
|
|
|
reloff, reloff, absoff);
|
|
|
|
*typestring_offset += 4;
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
|
|
|
|
align = 0;
|
|
|
|
*offset_in_memory += type_memsize(type, &align);
|
|
|
|
/* FIXME: is there a case where these two are different? */
|
|
|
|
align = 0;
|
|
|
|
*offset_in_buffer += type_memsize(type, &align);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_non_complex_struct(type))
|
|
|
|
{
|
|
|
|
const var_t *v;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
|
|
|
|
written += write_no_repeat_pointer_descriptions(
|
2007-06-21 01:51:23 +02:00
|
|
|
file, v->type,
|
2007-06-19 13:05:25 +02:00
|
|
|
offset_in_memory, offset_in_buffer, typestring_offset);
|
2007-05-10 05:50:49 +02:00
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
align = 0;
|
|
|
|
*offset_in_memory += type_memsize(type, &align);
|
|
|
|
/* FIXME: is there a case where these two are different? */
|
|
|
|
align = 0;
|
|
|
|
*offset_in_buffer += type_memsize(type, &align);
|
|
|
|
}
|
|
|
|
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int write_pointer_description_offsets(
|
|
|
|
FILE *file, const attr_list_t *attrs, type_t *type,
|
|
|
|
size_t *offset_in_memory, size_t *offset_in_buffer,
|
|
|
|
unsigned int *typestring_offset)
|
|
|
|
{
|
|
|
|
int written = 0;
|
|
|
|
unsigned int align;
|
|
|
|
|
2007-06-26 03:22:57 +02:00
|
|
|
if (is_ptr(type) && type->ref->type != RPC_FC_IP)
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
|
|
|
if (offset_in_memory && offset_in_buffer)
|
|
|
|
{
|
|
|
|
/* pointer instance */
|
|
|
|
/* FIXME: sometimes from end of structure, sometimes from beginning */
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Memory offset = %d */\n", *offset_in_memory, *offset_in_memory);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Buffer offset = %d */\n", *offset_in_buffer, *offset_in_buffer);
|
|
|
|
|
|
|
|
align = 0;
|
|
|
|
*offset_in_memory += type_memsize(type, &align);
|
|
|
|
/* FIXME: is there a case where these two are different? */
|
|
|
|
align = 0;
|
|
|
|
*offset_in_buffer += type_memsize(type, &align);
|
|
|
|
}
|
|
|
|
*typestring_offset += 4;
|
|
|
|
|
|
|
|
if (processed(type->ref) || is_base_type(type->ref->type))
|
|
|
|
write_pointer_tfs(file, type, typestring_offset);
|
|
|
|
else
|
|
|
|
error("write_pointer_description_offsets: type format string unknown\n");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array(type))
|
2006-02-03 18:51:17 +01:00
|
|
|
{
|
2007-06-19 13:05:25 +02:00
|
|
|
return write_pointer_description_offsets(
|
|
|
|
file, attrs, type->ref, offset_in_memory, offset_in_buffer,
|
|
|
|
typestring_offset);
|
|
|
|
}
|
|
|
|
else if (is_non_complex_struct(type))
|
|
|
|
{
|
|
|
|
/* otherwise search for interesting fields to parse */
|
|
|
|
const var_t *v;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
|
2007-05-10 05:50:49 +02:00
|
|
|
{
|
2007-06-19 13:05:25 +02:00
|
|
|
written += write_pointer_description_offsets(
|
|
|
|
file, v->attrs, v->type, offset_in_memory, offset_in_buffer,
|
|
|
|
typestring_offset);
|
2007-05-10 05:50:49 +02:00
|
|
|
}
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
align = 0;
|
|
|
|
if (offset_in_memory)
|
|
|
|
*offset_in_memory += type_memsize(type, &align);
|
|
|
|
/* FIXME: is there a case where these two are different? */
|
|
|
|
align = 0;
|
|
|
|
if (offset_in_buffer)
|
|
|
|
*offset_in_buffer += type_memsize(type, &align);
|
|
|
|
}
|
2006-02-03 18:51:17 +01:00
|
|
|
|
2007-06-19 13:05:25 +02:00
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: if file is NULL return value is number of pointers to write, else
|
|
|
|
* it is the number of type format characters written */
|
|
|
|
static int write_fixed_array_pointer_descriptions(
|
|
|
|
FILE *file, const attr_list_t *attrs, type_t *type,
|
|
|
|
size_t *offset_in_memory, size_t *offset_in_buffer,
|
|
|
|
unsigned int *typestring_offset)
|
|
|
|
{
|
|
|
|
unsigned int align;
|
|
|
|
int pointer_count = 0;
|
|
|
|
|
|
|
|
if (type->type == RPC_FC_SMFARRAY || type->type == RPC_FC_LGFARRAY)
|
|
|
|
{
|
|
|
|
unsigned int temp = 0;
|
|
|
|
/* unfortunately, this needs to be done in two passes to avoid
|
|
|
|
* writing out redundant FC_FIXED_REPEAT descriptions */
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
|
|
|
NULL, attrs, type->ref, NULL, NULL, &temp);
|
|
|
|
if (pointer_count > 0)
|
|
|
|
{
|
|
|
|
unsigned int increment_size;
|
|
|
|
size_t offset_of_array_pointer_mem = 0;
|
|
|
|
size_t offset_of_array_pointer_buf = 0;
|
|
|
|
|
|
|
|
align = 0;
|
|
|
|
increment_size = type_memsize(type->ref, &align);
|
|
|
|
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_FIXED_REPEAT */\n", RPC_FC_FIXED_REPEAT);
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_PAD */\n", RPC_FC_PAD);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Iterations = %d */\n", type->dim, type->dim);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Increment = %d */\n", increment_size, increment_size);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Offset to array = %d */\n", *offset_in_memory, *offset_in_memory);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Number of pointers = %d */\n", pointer_count, pointer_count);
|
|
|
|
*typestring_offset += 10;
|
|
|
|
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
|
|
|
file, attrs, type, &offset_of_array_pointer_mem,
|
|
|
|
&offset_of_array_pointer_buf, typestring_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (is_struct(type->type))
|
|
|
|
{
|
|
|
|
const var_t *v;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
|
|
|
|
{
|
|
|
|
pointer_count += write_fixed_array_pointer_descriptions(
|
|
|
|
file, v->attrs, v->type, offset_in_memory, offset_in_buffer,
|
|
|
|
typestring_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
align = 0;
|
|
|
|
if (offset_in_memory)
|
|
|
|
*offset_in_memory += type_memsize(type, &align);
|
|
|
|
/* FIXME: is there a case where these two are different? */
|
|
|
|
align = 0;
|
|
|
|
if (offset_in_buffer)
|
|
|
|
*offset_in_buffer += type_memsize(type, &align);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pointer_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: if file is NULL return value is number of pointers to write, else
|
|
|
|
* it is the number of type format characters written */
|
|
|
|
static int write_conformant_array_pointer_descriptions(
|
|
|
|
FILE *file, const attr_list_t *attrs, type_t *type,
|
2007-10-11 00:29:54 +02:00
|
|
|
size_t offset_in_memory, unsigned int *typestring_offset)
|
2007-06-19 13:05:25 +02:00
|
|
|
{
|
|
|
|
unsigned int align;
|
|
|
|
int pointer_count = 0;
|
|
|
|
|
|
|
|
if (is_conformant_array(type) && !type->length_is)
|
|
|
|
{
|
|
|
|
unsigned int temp = 0;
|
|
|
|
/* unfortunately, this needs to be done in two passes to avoid
|
|
|
|
* writing out redundant FC_VARIABLE_REPEAT descriptions */
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
|
|
|
NULL, attrs, type->ref, NULL, NULL, &temp);
|
|
|
|
if (pointer_count > 0)
|
|
|
|
{
|
|
|
|
unsigned int increment_size;
|
2007-10-11 00:29:54 +02:00
|
|
|
size_t offset_of_array_pointer_mem = offset_in_memory;
|
|
|
|
size_t offset_of_array_pointer_buf = offset_in_memory;
|
2007-06-19 13:05:25 +02:00
|
|
|
|
|
|
|
align = 0;
|
|
|
|
increment_size = type_memsize(type->ref, &align);
|
|
|
|
|
|
|
|
if (increment_size > USHRT_MAX)
|
|
|
|
error("array size of %u bytes is too large\n", increment_size);
|
|
|
|
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_VARIABLE_REPEAT */\n", RPC_FC_VARIABLE_REPEAT);
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_FIXED_OFFSET */\n", RPC_FC_FIXED_OFFSET);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Increment = %d */\n", increment_size, increment_size);
|
2007-10-11 00:29:54 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Offset to array = %d */\n", offset_in_memory, offset_in_memory);
|
2007-06-19 13:05:25 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Number of pointers = %d */\n", pointer_count, pointer_count);
|
|
|
|
*typestring_offset += 8;
|
|
|
|
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
|
|
|
file, attrs, type->ref, &offset_of_array_pointer_mem,
|
|
|
|
&offset_of_array_pointer_buf, typestring_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pointer_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: if file is NULL return value is number of pointers to write, else
|
|
|
|
* it is the number of type format characters written */
|
|
|
|
static int write_varying_array_pointer_descriptions(
|
|
|
|
FILE *file, const attr_list_t *attrs, type_t *type,
|
|
|
|
size_t *offset_in_memory, size_t *offset_in_buffer,
|
|
|
|
unsigned int *typestring_offset)
|
|
|
|
{
|
|
|
|
unsigned int align;
|
|
|
|
int pointer_count = 0;
|
|
|
|
|
|
|
|
/* FIXME: do varying array searching here, but pointer searching in write_pointer_description_offsets */
|
|
|
|
|
|
|
|
if (is_array(type) && type->length_is)
|
|
|
|
{
|
|
|
|
unsigned int temp = 0;
|
|
|
|
/* unfortunately, this needs to be done in two passes to avoid
|
|
|
|
* writing out redundant FC_VARIABLE_REPEAT descriptions */
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
|
|
|
NULL, attrs, type->ref, NULL, NULL, &temp);
|
|
|
|
if (pointer_count > 0)
|
|
|
|
{
|
|
|
|
unsigned int increment_size;
|
|
|
|
size_t offset_of_array_pointer_mem = 0;
|
|
|
|
size_t offset_of_array_pointer_buf = 0;
|
|
|
|
|
|
|
|
align = 0;
|
|
|
|
increment_size = type_memsize(type->ref, &align);
|
|
|
|
|
|
|
|
if (increment_size > USHRT_MAX)
|
|
|
|
error("array size of %u bytes is too large\n", increment_size);
|
|
|
|
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_VARIABLE_REPEAT */\n", RPC_FC_VARIABLE_REPEAT);
|
|
|
|
print_file(file, 2, "0x%02x, /* FC_VARIABLE_OFFSET */\n", RPC_FC_VARIABLE_OFFSET);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Increment = %d */\n", increment_size, increment_size);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Offset to array = %d */\n", *offset_in_memory, *offset_in_memory);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* Number of pointers = %d */\n", pointer_count, pointer_count);
|
|
|
|
*typestring_offset += 8;
|
|
|
|
|
|
|
|
pointer_count = write_pointer_description_offsets(
|
|
|
|
file, attrs, type, &offset_of_array_pointer_mem,
|
|
|
|
&offset_of_array_pointer_buf, typestring_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (is_struct(type->type))
|
|
|
|
{
|
|
|
|
const var_t *v;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
|
|
|
|
{
|
|
|
|
pointer_count += write_varying_array_pointer_descriptions(
|
|
|
|
file, v->attrs, v->type, offset_in_memory, offset_in_buffer,
|
|
|
|
typestring_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
align = 0;
|
|
|
|
if (offset_in_memory)
|
|
|
|
*offset_in_memory += type_memsize(type, &align);
|
|
|
|
/* FIXME: is there a case where these two are different? */
|
|
|
|
align = 0;
|
|
|
|
if (offset_in_buffer)
|
|
|
|
*offset_in_buffer += type_memsize(type, &align);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pointer_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_pointer_description(FILE *file, type_t *type,
|
|
|
|
unsigned int *typestring_offset)
|
|
|
|
{
|
|
|
|
size_t offset_in_buffer;
|
|
|
|
size_t offset_in_memory;
|
|
|
|
|
|
|
|
/* pass 1: search for single instance of a pointer (i.e. don't descend
|
|
|
|
* into arrays) */
|
2007-10-11 00:29:54 +02:00
|
|
|
if (!is_array(type))
|
|
|
|
{
|
|
|
|
offset_in_memory = 0;
|
|
|
|
offset_in_buffer = 0;
|
|
|
|
write_no_repeat_pointer_descriptions(
|
|
|
|
file, type,
|
|
|
|
&offset_in_memory, &offset_in_buffer, typestring_offset);
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
|
|
|
|
/* pass 2: search for pointers in fixed arrays */
|
|
|
|
offset_in_memory = 0;
|
|
|
|
offset_in_buffer = 0;
|
|
|
|
write_fixed_array_pointer_descriptions(
|
|
|
|
file, NULL, type,
|
|
|
|
&offset_in_memory, &offset_in_buffer, typestring_offset);
|
|
|
|
|
|
|
|
/* pass 3: search for pointers in conformant only arrays (but don't descend
|
|
|
|
* into conformant varying or varying arrays) */
|
2007-10-11 00:29:54 +02:00
|
|
|
if ((!type->declarray || !current_structure) && is_conformant_array(type))
|
|
|
|
write_conformant_array_pointer_descriptions(
|
|
|
|
file, NULL, type, 0, typestring_offset);
|
|
|
|
else if (type->type == RPC_FC_CPSTRUCT)
|
|
|
|
{
|
|
|
|
unsigned int align = 0;
|
|
|
|
type_t *carray = find_array_or_string_in_struct(type)->type;
|
|
|
|
write_conformant_array_pointer_descriptions(
|
|
|
|
file, NULL, carray,
|
|
|
|
type_memsize(type, &align),
|
|
|
|
typestring_offset);
|
|
|
|
}
|
2007-06-19 13:05:25 +02:00
|
|
|
|
|
|
|
/* pass 4: search for pointers in varying arrays */
|
|
|
|
offset_in_memory = 0;
|
|
|
|
offset_in_buffer = 0;
|
|
|
|
write_varying_array_pointer_descriptions(
|
|
|
|
file, NULL, type,
|
|
|
|
&offset_in_memory, &offset_in_buffer, typestring_offset);
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
|
|
|
|
2007-11-02 23:24:08 +01:00
|
|
|
int is_declptr(const type_t *t)
|
2007-09-05 00:46:30 +02:00
|
|
|
{
|
|
|
|
return is_ptr(t) || (is_conformant_array(t) && !t->declarray);
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
static size_t write_string_tfs(FILE *file, const attr_list_t *attrs,
|
2007-09-17 10:46:22 +02:00
|
|
|
type_t *type,
|
2006-06-13 14:13:49 +02:00
|
|
|
const char *name, unsigned int *typestring_offset)
|
2006-01-24 11:06:32 +01:00
|
|
|
{
|
2006-01-31 18:07:20 +01:00
|
|
|
size_t start_offset = *typestring_offset;
|
2006-08-09 23:20:35 +02:00
|
|
|
unsigned char rtype;
|
|
|
|
|
2007-09-17 10:46:22 +02:00
|
|
|
update_tfsoff(type, start_offset, file);
|
|
|
|
|
2007-09-05 00:46:30 +02:00
|
|
|
if (is_declptr(type))
|
2006-09-08 01:57:16 +02:00
|
|
|
{
|
2007-09-05 00:46:30 +02:00
|
|
|
unsigned char flag = is_conformant_array(type) ? 0 : RPC_FC_P_SIMPLEPOINTER;
|
|
|
|
int pointer_type = is_ptr(type) ? type->type : get_attrv(attrs, ATTR_POINTERTYPE);
|
|
|
|
if (!pointer_type)
|
|
|
|
pointer_type = RPC_FC_RP;
|
|
|
|
print_file(file, 2,"0x%x, 0x%x,\t/* %s%s */\n",
|
|
|
|
pointer_type, flag, string_of_type(pointer_type),
|
|
|
|
flag ? " [simple_pointer]" : "");
|
|
|
|
*typestring_offset += 2;
|
|
|
|
if (!flag)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcShort(0x2),\n");
|
|
|
|
*typestring_offset += 2;
|
|
|
|
}
|
|
|
|
rtype = type->ref->type;
|
2006-09-08 01:57:16 +02:00
|
|
|
}
|
|
|
|
else
|
2007-09-17 10:46:22 +02:00
|
|
|
rtype = type->ref->type;
|
2006-03-31 13:45:16 +02:00
|
|
|
|
2006-08-09 23:20:35 +02:00
|
|
|
if ((rtype != RPC_FC_BYTE) && (rtype != RPC_FC_CHAR) && (rtype != RPC_FC_WCHAR))
|
2006-01-24 11:07:39 +01:00
|
|
|
{
|
2006-08-09 23:20:35 +02:00
|
|
|
error("write_string_tfs: Unimplemented for type 0x%x of name: %s\n", rtype, name);
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:39 +01:00
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (type->declarray && !is_conformant_array(type))
|
2006-01-24 11:07:39 +01:00
|
|
|
{
|
2007-01-22 14:31:40 +01:00
|
|
|
/* FIXME: multi-dimensional array */
|
2007-06-06 03:50:31 +02:00
|
|
|
if (0xffffuL < type->dim)
|
|
|
|
error("array size for parameter %s exceeds %u bytes by %lu bytes\n",
|
|
|
|
name, 0xffffu, type->dim - 0xffffu);
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2006-08-09 23:20:35 +02:00
|
|
|
if (rtype == RPC_FC_CHAR)
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_CSTRING, *typestring_offset);
|
2006-01-24 11:07:39 +01:00
|
|
|
else
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_WSTRING, *typestring_offset);
|
2006-01-24 11:07:39 +01:00
|
|
|
print_file(file, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %d */\n", type->dim, type->dim);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:39 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else if (type->size_is)
|
2006-01-24 11:07:39 +01:00
|
|
|
{
|
2007-06-12 03:51:41 +02:00
|
|
|
unsigned int align = 0;
|
|
|
|
|
2006-08-09 23:20:35 +02:00
|
|
|
if (rtype == RPC_FC_CHAR)
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_C_CSTRING, *typestring_offset);
|
2006-01-24 11:07:39 +01:00
|
|
|
else
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_C_WSTRING, *typestring_offset);
|
2006-01-24 11:08:20 +01:00
|
|
|
print_file(file, 2, "0x%x, /* FC_STRING_SIZED */\n", RPC_FC_STRING_SIZED);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
*typestring_offset += write_conf_or_var_desc(
|
2007-09-13 01:10:01 +02:00
|
|
|
file, current_structure,
|
2007-06-12 03:51:41 +02:00
|
|
|
(type->declarray && current_structure
|
|
|
|
? type_memsize(current_structure, &align)
|
|
|
|
: 0),
|
2007-10-11 00:29:54 +02:00
|
|
|
type, type->size_is);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-05 00:46:30 +02:00
|
|
|
if (rtype == RPC_FC_WCHAR)
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_C_WSTRING, *typestring_offset);
|
2007-09-05 00:46:30 +02:00
|
|
|
else
|
|
|
|
WRITE_FCTYPE(file, FC_C_CSTRING, *typestring_offset);
|
2006-01-24 11:08:20 +01:00
|
|
|
print_file(file, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:39 +01:00
|
|
|
}
|
2006-01-24 11:06:32 +01:00
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
static size_t write_array_tfs(FILE *file, const attr_list_t *attrs, type_t *type,
|
2006-06-13 14:13:49 +02:00
|
|
|
const char *name, unsigned int *typestring_offset)
|
2006-01-24 11:06:32 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
const expr_t *length_is = type->length_is;
|
|
|
|
const expr_t *size_is = type->size_is;
|
|
|
|
unsigned int align = 0;
|
|
|
|
size_t size;
|
2006-02-03 18:51:17 +01:00
|
|
|
size_t start_offset;
|
2007-06-06 03:50:31 +02:00
|
|
|
int has_pointer;
|
2006-04-05 00:07:03 +02:00
|
|
|
int pointer_type = get_attrv(attrs, ATTR_POINTERTYPE);
|
2007-09-19 00:29:59 +02:00
|
|
|
unsigned int baseoff
|
|
|
|
= type->declarray && current_structure
|
|
|
|
? type_memsize(current_structure, &align)
|
|
|
|
: 0;
|
|
|
|
|
2006-04-05 00:07:03 +02:00
|
|
|
if (!pointer_type)
|
|
|
|
pointer_type = RPC_FC_RP;
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
has_pointer = FALSE;
|
2007-06-12 03:51:41 +02:00
|
|
|
if (write_embedded_types(file, attrs, type->ref, name, FALSE, typestring_offset))
|
2007-06-06 03:50:31 +02:00
|
|
|
has_pointer = TRUE;
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-09-27 02:34:25 +02:00
|
|
|
align = 0;
|
2007-11-06 02:23:26 +01:00
|
|
|
size = type_memsize((is_conformant_array(type) ? type->ref : type), &align);
|
2006-02-03 18:51:17 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
start_offset = *typestring_offset;
|
|
|
|
update_tfsoff(type, start_offset, file);
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, start_offset);
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, 2, "0x%02x,\t/* %s */\n", type->type, string_of_type(type->type));
|
|
|
|
print_file(file, 2, "0x%x,\t/* %d */\n", align - 1, align - 1);
|
|
|
|
*typestring_offset += 2;
|
2006-02-03 18:51:17 +01:00
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
align = 0;
|
2007-06-06 03:50:31 +02:00
|
|
|
if (type->type != RPC_FC_BOGUS_ARRAY)
|
|
|
|
{
|
|
|
|
unsigned char tc = type->type;
|
2006-02-03 18:51:17 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (tc == RPC_FC_LGFARRAY || tc == RPC_FC_LGVARRAY)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, 2, "NdrFcLong(0x%x),\t/* %lu */\n", size, size);
|
|
|
|
*typestring_offset += 4;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\t/* %lu */\n", size, size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (is_conformant_array(type))
|
|
|
|
*typestring_offset
|
2007-09-13 01:10:01 +02:00
|
|
|
+= write_conf_or_var_desc(file, current_structure, baseoff,
|
2007-10-11 00:29:54 +02:00
|
|
|
type, size_is);
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (type->type == RPC_FC_SMVARRAY || type->type == RPC_FC_LGVARRAY)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
unsigned int elalign = 0;
|
|
|
|
size_t elsize = type_memsize(type->ref, &elalign);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (type->type == RPC_FC_LGVARRAY)
|
2006-02-03 18:51:17 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, 2, "NdrFcLong(0x%x),\t/* %lu */\n", type->dim, type->dim);
|
|
|
|
*typestring_offset += 4;
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else
|
2007-02-06 15:55:29 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\t/* %lu */\n", type->dim, type->dim);
|
|
|
|
*typestring_offset += 2;
|
2007-02-06 15:55:29 +01:00
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\t/* %lu */\n", elsize, elsize);
|
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (length_is)
|
|
|
|
*typestring_offset
|
2007-09-13 01:10:01 +02:00
|
|
|
+= write_conf_or_var_desc(file, current_structure, baseoff,
|
2007-10-11 00:29:54 +02:00
|
|
|
type, length_is);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2007-10-11 00:29:54 +02:00
|
|
|
if (has_pointer && (!type->declarray || !current_structure))
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP);
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD);
|
|
|
|
*typestring_offset += 2;
|
2007-06-21 01:51:23 +02:00
|
|
|
write_pointer_description(file, type, typestring_offset);
|
2006-03-31 13:44:27 +02:00
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
2007-02-06 15:55:29 +01:00
|
|
|
*typestring_offset += 1;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
|
2007-09-19 00:28:49 +02:00
|
|
|
write_member_type(file, type, NULL, type->ref, NULL, typestring_offset);
|
2007-06-06 03:50:31 +02:00
|
|
|
write_end(file, typestring_offset);
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else
|
2007-09-19 00:29:59 +02:00
|
|
|
{
|
|
|
|
unsigned int dim = size_is ? 0 : type->dim;
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\t/* %u */\n", dim, dim);
|
|
|
|
*typestring_offset += 2;
|
|
|
|
*typestring_offset
|
|
|
|
+= write_conf_or_var_desc(file, current_structure, baseoff,
|
2007-10-11 00:29:54 +02:00
|
|
|
type, size_is);
|
2007-09-19 00:29:59 +02:00
|
|
|
*typestring_offset
|
|
|
|
+= write_conf_or_var_desc(file, current_structure, baseoff,
|
2007-10-11 00:29:54 +02:00
|
|
|
type, length_is);
|
2007-09-19 00:29:59 +02:00
|
|
|
write_member_type(file, type, NULL, type->ref, NULL, typestring_offset);
|
|
|
|
write_end(file, typestring_offset);
|
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
|
|
|
|
return start_offset;
|
2006-01-24 11:06:32 +01:00
|
|
|
}
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2006-01-24 11:14:59 +01:00
|
|
|
static const var_t *find_array_or_string_in_struct(const type_t *type)
|
2006-01-24 11:13:49 +01:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *last_field = LIST_ENTRY( list_tail(type->fields), const var_t, entry );
|
2007-06-06 03:52:24 +02:00
|
|
|
const type_t *ft = last_field->type;
|
2007-01-22 14:26:12 +01:00
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
if (ft->declarray && is_conformant_array(ft))
|
2006-01-24 11:13:49 +01:00
|
|
|
return last_field;
|
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
if (ft->type == RPC_FC_CSTRUCT || ft->type == RPC_FC_CPSTRUCT || ft->type == RPC_FC_CVSTRUCT)
|
|
|
|
return find_array_or_string_in_struct(last_field->type);
|
|
|
|
else
|
|
|
|
return NULL;
|
2006-01-24 11:13:49 +01:00
|
|
|
}
|
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
static void write_struct_members(FILE *file, const type_t *type,
|
|
|
|
unsigned int *corroff, unsigned int *typestring_offset)
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *field;
|
2007-09-04 20:04:37 +02:00
|
|
|
unsigned short offset = 0;
|
2007-09-14 03:04:32 +02:00
|
|
|
int salign = -1;
|
|
|
|
int padding;
|
2006-04-09 14:38:57 +02:00
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
if (type->fields) LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
|
2007-06-06 03:52:24 +02:00
|
|
|
{
|
|
|
|
type_t *ft = field->type;
|
|
|
|
if (!ft->declarray || !is_conformant_array(ft))
|
2007-09-04 20:04:37 +02:00
|
|
|
{
|
|
|
|
unsigned int align = 0;
|
|
|
|
size_t size = type_memsize(ft, &align);
|
2007-09-14 03:04:32 +02:00
|
|
|
if (salign == -1)
|
|
|
|
salign = align;
|
2007-09-04 20:04:37 +02:00
|
|
|
if ((align - 1) & offset)
|
|
|
|
{
|
|
|
|
unsigned char fc = 0;
|
|
|
|
switch (align)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
fc = RPC_FC_ALIGNM4;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
fc = RPC_FC_ALIGNM8;
|
|
|
|
break;
|
|
|
|
default:
|
2007-10-03 06:38:31 +02:00
|
|
|
error("write_struct_members: cannot align type %d\n", ft->type);
|
2007-09-04 20:04:37 +02:00
|
|
|
}
|
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", fc, string_of_type(fc));
|
|
|
|
offset = (offset + (align - 1)) & ~(align - 1);
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
2007-09-19 00:28:49 +02:00
|
|
|
write_member_type(file, type, field->attrs, field->type, corroff,
|
|
|
|
typestring_offset);
|
2007-09-04 20:04:37 +02:00
|
|
|
offset += size;
|
|
|
|
}
|
2007-06-06 03:52:24 +02:00
|
|
|
}
|
2006-04-09 14:38:57 +02:00
|
|
|
|
2007-09-14 03:04:32 +02:00
|
|
|
padding = ((offset + (salign - 1)) & ~(salign - 1)) - offset;
|
|
|
|
if (padding)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x,\t/* FC_STRUCTPAD%d */\n",
|
|
|
|
RPC_FC_STRUCTPAD1 + padding - 1,
|
|
|
|
padding);
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
write_end(file, typestring_offset);
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
static size_t write_struct_tfs(FILE *file, type_t *type,
|
2007-06-06 03:52:24 +02:00
|
|
|
const char *name, unsigned int *tfsoff)
|
2006-01-24 11:10:59 +01:00
|
|
|
{
|
2007-06-12 03:51:41 +02:00
|
|
|
const type_t *save_current_structure = current_structure;
|
2006-06-13 14:13:49 +02:00
|
|
|
unsigned int total_size;
|
2006-01-24 11:13:49 +01:00
|
|
|
const var_t *array;
|
2006-01-31 18:07:20 +01:00
|
|
|
size_t start_offset;
|
2006-01-31 18:08:03 +01:00
|
|
|
size_t array_offset;
|
2007-06-12 03:51:41 +02:00
|
|
|
int has_pointers = 0;
|
2007-02-06 15:54:58 +01:00
|
|
|
unsigned int align = 0;
|
2007-06-12 03:51:41 +02:00
|
|
|
unsigned int corroff;
|
|
|
|
var_t *f;
|
2006-01-24 11:13:49 +01:00
|
|
|
|
2007-05-25 02:50:02 +02:00
|
|
|
guard_rec(type);
|
2007-06-12 03:51:41 +02:00
|
|
|
current_structure = type;
|
2007-05-25 02:50:02 +02:00
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
total_size = type_memsize(type, &align);
|
|
|
|
if (total_size > USHRT_MAX)
|
|
|
|
error("structure size for %s exceeds %d bytes by %d bytes\n",
|
|
|
|
name, USHRT_MAX, total_size - USHRT_MAX);
|
2006-01-24 11:14:59 +01:00
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
if (type->fields) LIST_FOR_EACH_ENTRY(f, type->fields, var_t, entry)
|
|
|
|
has_pointers |= write_embedded_types(file, f->attrs, f->type, f->name,
|
|
|
|
FALSE, tfsoff);
|
2006-01-24 11:14:59 +01:00
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
array = find_array_or_string_in_struct(type);
|
|
|
|
if (array && !processed(array->type))
|
|
|
|
array_offset
|
|
|
|
= is_attr(array->attrs, ATTR_STRING)
|
|
|
|
? write_string_tfs(file, array->attrs, array->type, array->name, tfsoff)
|
|
|
|
: write_array_tfs(file, array->attrs, array->type, array->name, tfsoff);
|
2007-06-12 03:51:41 +02:00
|
|
|
|
|
|
|
corroff = *tfsoff;
|
|
|
|
write_descriptors(file, type, tfsoff);
|
2006-01-31 18:08:03 +01:00
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
start_offset = *tfsoff;
|
|
|
|
update_tfsoff(type, start_offset, file);
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, start_offset);
|
2007-06-06 03:52:24 +02:00
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", type->type, string_of_type(type->type));
|
|
|
|
print_file(file, 2, "0x%x,\t/* %d */\n", align - 1, align - 1);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\t/* %d */\n", total_size, total_size);
|
|
|
|
*tfsoff += 4;
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
if (array)
|
|
|
|
{
|
|
|
|
unsigned int absoff = array->type->typestring_offset;
|
|
|
|
short reloff = absoff - *tfsoff;
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%lu) */\n",
|
|
|
|
reloff, reloff, absoff);
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
|
|
|
else if (type->type == RPC_FC_BOGUS_STRUCT)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcShort(0x0),\n");
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2007-06-06 03:52:24 +02:00
|
|
|
if (type->type == RPC_FC_BOGUS_STRUCT)
|
|
|
|
{
|
2007-09-19 00:28:49 +02:00
|
|
|
/* On the sizing pass, type->ptrdesc may be zero, but it's ok as
|
|
|
|
nothing is written to file yet. On the actual writing pass,
|
|
|
|
this will have been updated. */
|
2007-09-20 02:04:09 +02:00
|
|
|
unsigned int absoff = type->ptrdesc ? type->ptrdesc : *tfsoff;
|
|
|
|
short reloff = absoff - *tfsoff;
|
2007-09-19 00:28:49 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
|
2007-09-20 02:04:09 +02:00
|
|
|
reloff, reloff, absoff);
|
2007-06-06 03:52:24 +02:00
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
2007-06-19 13:11:05 +02:00
|
|
|
else if ((type->type == RPC_FC_PSTRUCT) ||
|
|
|
|
(type->type == RPC_FC_CPSTRUCT) ||
|
|
|
|
(type->type == RPC_FC_CVSTRUCT && has_pointers))
|
2007-06-06 03:52:24 +02:00
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP);
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD);
|
|
|
|
*tfsoff += 2;
|
2007-06-21 01:51:23 +02:00
|
|
|
write_pointer_description(file, type, tfsoff);
|
2007-06-06 03:52:24 +02:00
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
|
|
|
*tfsoff += 1;
|
|
|
|
}
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
write_struct_members(file, type, &corroff, tfsoff);
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2007-09-19 00:28:49 +02:00
|
|
|
if (type->type == RPC_FC_BOGUS_STRUCT)
|
|
|
|
{
|
|
|
|
const var_list_t *fs = type->fields;
|
|
|
|
const var_t *f;
|
|
|
|
|
|
|
|
type->ptrdesc = *tfsoff;
|
|
|
|
if (fs) LIST_FOR_EACH_ENTRY(f, fs, const var_t, entry)
|
|
|
|
{
|
|
|
|
type_t *ft = f->type;
|
|
|
|
if (is_ptr(ft))
|
|
|
|
write_pointer_tfs(file, ft, tfsoff);
|
2007-10-18 03:06:26 +02:00
|
|
|
else if (!ft->declarray && is_conformant_array(ft))
|
|
|
|
{
|
|
|
|
unsigned int absoff = ft->typestring_offset;
|
|
|
|
short reloff = absoff - (*tfsoff + 2);
|
|
|
|
int ptr_type = get_attrv(f->attrs, ATTR_POINTERTYPE);
|
|
|
|
/* FIXME: We need to store pointer attributes for arrays
|
|
|
|
so we don't lose pointer_default info. */
|
|
|
|
if (ptr_type == 0)
|
|
|
|
ptr_type = RPC_FC_UP;
|
|
|
|
print_file(file, 0, "/* %d */\n", *tfsoff);
|
|
|
|
print_file(file, 2, "0x%x, 0x0,\t/* %s */\n", ptr_type,
|
|
|
|
string_of_type(ptr_type));
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
|
|
|
|
reloff, reloff, absoff);
|
|
|
|
*tfsoff += 4;
|
|
|
|
}
|
2007-09-19 00:28:49 +02:00
|
|
|
}
|
2007-09-20 02:04:09 +02:00
|
|
|
if (type->ptrdesc == *tfsoff)
|
|
|
|
type->ptrdesc = 0;
|
2007-09-19 00:28:49 +02:00
|
|
|
}
|
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
current_structure = save_current_structure;
|
2007-06-06 03:52:24 +02:00
|
|
|
return start_offset;
|
2006-01-24 11:10:59 +01:00
|
|
|
}
|
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
static size_t write_pointer_only_tfs(FILE *file, const attr_list_t *attrs, int pointer_type,
|
|
|
|
unsigned char flags, size_t offset,
|
|
|
|
unsigned int *typeformat_offset)
|
2006-02-07 12:30:07 +01:00
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
size_t start_offset = *typeformat_offset;
|
|
|
|
short reloff = offset - (*typeformat_offset + 2);
|
2006-04-09 14:38:57 +02:00
|
|
|
int in_attr, out_attr;
|
|
|
|
in_attr = is_attr(attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(attrs, ATTR_OUT);
|
|
|
|
if (!in_attr && !out_attr) in_attr = 1;
|
2006-02-07 12:30:07 +01:00
|
|
|
|
2006-04-09 14:38:57 +02:00
|
|
|
if (out_attr && !in_attr && pointer_type == RPC_FC_RP)
|
|
|
|
flags |= 0x04;
|
|
|
|
|
2006-09-08 01:57:16 +02:00
|
|
|
print_file(file, 2, "0x%x, 0x%x,\t\t/* %s",
|
2006-02-07 12:30:07 +01:00
|
|
|
pointer_type,
|
2006-04-09 14:38:57 +02:00
|
|
|
flags,
|
2007-05-16 02:48:20 +02:00
|
|
|
string_of_type(pointer_type));
|
2006-09-08 01:57:16 +02:00
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
if (flags & 0x04)
|
|
|
|
fprintf(file, " [allocated_on_stack]");
|
|
|
|
if (flags & 0x10)
|
|
|
|
fprintf(file, " [pointer_deref]");
|
|
|
|
fprintf(file, " */\n");
|
|
|
|
}
|
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\t/* %d */\n", reloff, offset);
|
2006-02-07 12:30:07 +01:00
|
|
|
*typeformat_offset += 4;
|
2007-05-10 05:50:49 +02:00
|
|
|
|
|
|
|
return start_offset;
|
2006-02-07 12:30:07 +01:00
|
|
|
}
|
|
|
|
|
2007-05-23 09:36:08 +02:00
|
|
|
static void write_branch_type(FILE *file, const type_t *t, unsigned int *tfsoff)
|
2006-01-24 11:10:59 +01:00
|
|
|
{
|
2007-06-15 03:28:03 +02:00
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcShort(0x0),\t/* No type */\n");
|
|
|
|
}
|
|
|
|
else if (is_base_type(t->type))
|
2007-05-19 01:53:27 +02:00
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcShort(0x80%02x),\t/* Simple arm type: %s */\n",
|
|
|
|
t->type, string_of_type(t->type));
|
|
|
|
}
|
|
|
|
else if (t->typestring_offset)
|
|
|
|
{
|
2007-05-25 02:48:39 +02:00
|
|
|
short reloff = t->typestring_offset - *tfsoff;
|
2007-05-19 01:53:27 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\t/* Offset= %d (%d) */\n",
|
|
|
|
reloff, reloff, t->typestring_offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error("write_branch_type: type unimplemented (0x%x)\n", t->type);
|
|
|
|
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
|
|
|
|
2007-06-12 03:51:41 +02:00
|
|
|
static size_t write_union_tfs(FILE *file, type_t *type, unsigned int *tfsoff)
|
2007-05-19 01:53:27 +02:00
|
|
|
{
|
2007-05-23 09:36:08 +02:00
|
|
|
unsigned int align = 0;
|
|
|
|
unsigned int start_offset;
|
2007-06-06 03:50:31 +02:00
|
|
|
size_t size = type_memsize(type, &align);
|
2007-06-15 03:28:03 +02:00
|
|
|
var_list_t *fields;
|
2007-05-19 01:53:27 +02:00
|
|
|
size_t nbranch = 0;
|
|
|
|
type_t *deftype = NULL;
|
|
|
|
short nodeftype = 0xffff;
|
|
|
|
var_t *f;
|
|
|
|
|
2007-05-25 02:50:02 +02:00
|
|
|
guard_rec(type);
|
|
|
|
|
2007-06-15 03:28:03 +02:00
|
|
|
if (type->type == RPC_FC_ENCAPSULATED_UNION)
|
|
|
|
{
|
|
|
|
const var_t *uv = LIST_ENTRY(list_tail(type->fields), const var_t, entry);
|
|
|
|
fields = uv->type->fields;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fields = type->fields;
|
|
|
|
|
2007-05-19 01:53:27 +02:00
|
|
|
if (fields) LIST_FOR_EACH_ENTRY(f, fields, var_t, entry)
|
|
|
|
{
|
|
|
|
expr_list_t *cases = get_attrp(f->attrs, ATTR_CASE);
|
|
|
|
if (cases)
|
|
|
|
nbranch += list_count(cases);
|
2007-06-12 03:51:41 +02:00
|
|
|
if (f->type)
|
|
|
|
write_embedded_types(file, f->attrs, f->type, f->name, TRUE, tfsoff);
|
2007-05-19 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
start_offset = *tfsoff;
|
2007-05-25 02:50:02 +02:00
|
|
|
update_tfsoff(type, start_offset, file);
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, start_offset);
|
2007-06-15 03:28:03 +02:00
|
|
|
if (type->type == RPC_FC_ENCAPSULATED_UNION)
|
|
|
|
{
|
|
|
|
const var_t *sv = LIST_ENTRY(list_head(type->fields), const var_t, entry);
|
|
|
|
const type_t *st = sv->type;
|
|
|
|
|
2007-06-26 03:27:24 +02:00
|
|
|
switch (st->type)
|
|
|
|
{
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_SMALL:
|
|
|
|
case RPC_FC_USMALL:
|
|
|
|
case RPC_FC_SHORT:
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
case RPC_FC_LONG:
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_ENUM16:
|
|
|
|
case RPC_FC_ENUM32:
|
|
|
|
print_file(file, 2, "0x%x,\t/* %s */\n", type->type, string_of_type(type->type));
|
|
|
|
print_file(file, 2, "0x%x,\t/* Switch type= %s */\n",
|
|
|
|
0x40 | st->type, string_of_type(st->type));
|
|
|
|
*tfsoff += 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("union switch type must be an integer, char, or enum\n");
|
|
|
|
}
|
2007-06-15 03:28:03 +02:00
|
|
|
}
|
2007-05-19 01:53:27 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\t/* %d */\n", size, size);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\t/* %d */\n", nbranch, nbranch);
|
|
|
|
*tfsoff += 4;
|
|
|
|
|
|
|
|
if (fields) LIST_FOR_EACH_ENTRY(f, fields, var_t, entry)
|
|
|
|
{
|
|
|
|
type_t *ft = f->type;
|
|
|
|
expr_list_t *cases = get_attrp(f->attrs, ATTR_CASE);
|
|
|
|
int deflt = is_attr(f->attrs, ATTR_DEFAULT);
|
|
|
|
expr_t *c;
|
|
|
|
|
|
|
|
if (cases == NULL && !deflt)
|
|
|
|
error("union field %s with neither case nor default attribute\n", f->name);
|
|
|
|
|
|
|
|
if (cases) LIST_FOR_EACH_ENTRY(c, cases, expr_t, entry)
|
|
|
|
{
|
|
|
|
/* MIDL doesn't check for duplicate cases, even though that seems
|
|
|
|
like a reasonable thing to do, it just dumps them to the TFS
|
|
|
|
like we're going to do here. */
|
|
|
|
print_file(file, 2, "NdrFcLong(0x%x),\t/* %d */\n", c->cval, c->cval);
|
|
|
|
*tfsoff += 4;
|
|
|
|
write_branch_type(file, ft, tfsoff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MIDL allows multiple default branches, even though that seems
|
|
|
|
illogical, it just chooses the last one, which is what we will
|
|
|
|
do. */
|
|
|
|
if (deflt)
|
|
|
|
{
|
|
|
|
deftype = ft;
|
|
|
|
nodeftype = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deftype)
|
|
|
|
{
|
|
|
|
write_branch_type(file, deftype, tfsoff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x),\n", nodeftype);
|
|
|
|
*tfsoff += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return start_offset;
|
2006-01-24 11:10:59 +01:00
|
|
|
}
|
|
|
|
|
2007-09-13 01:10:01 +02:00
|
|
|
static size_t write_ip_tfs(FILE *file, const attr_list_t *attrs, type_t *type,
|
|
|
|
unsigned int *typeformat_offset)
|
2006-08-18 03:09:20 +02:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t start_offset = *typeformat_offset;
|
2007-06-15 03:27:19 +02:00
|
|
|
const var_t *iid = get_attrp(attrs, ATTR_IIDIS);
|
2006-08-18 03:09:20 +02:00
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
if (iid)
|
|
|
|
{
|
|
|
|
expr_t expr;
|
|
|
|
|
|
|
|
expr.type = EXPR_IDENTIFIER;
|
|
|
|
expr.ref = NULL;
|
|
|
|
expr.u.sval = iid->name;
|
|
|
|
expr.is_const = FALSE;
|
|
|
|
print_file(file, 2, "0x2f, /* FC_IP */\n");
|
|
|
|
print_file(file, 2, "0x5c, /* FC_PAD */\n");
|
2007-10-11 00:29:54 +02:00
|
|
|
*typeformat_offset
|
|
|
|
+= write_conf_or_var_desc(file, NULL, 0, type, &expr) + 2;
|
2007-02-06 16:00:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
const type_t *base = is_ptr(type) ? type->ref : type;
|
2007-02-06 16:00:41 +01:00
|
|
|
const UUID *uuid = get_attrp(base->attrs, ATTR_UUID);
|
2006-08-18 03:09:20 +02:00
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
if (! uuid)
|
|
|
|
error("%s: interface %s missing UUID\n", __FUNCTION__, base->name);
|
2006-08-18 03:09:20 +02:00
|
|
|
|
2007-06-15 03:27:19 +02:00
|
|
|
update_tfsoff(type, start_offset, file);
|
2007-10-03 06:40:13 +02:00
|
|
|
print_start_tfs_comment(file, type, start_offset);
|
2007-02-06 16:00:41 +01:00
|
|
|
print_file(file, 2, "0x2f,\t/* FC_IP */\n");
|
|
|
|
print_file(file, 2, "0x5a,\t/* FC_CONSTANT_IID */\n");
|
|
|
|
print_file(file, 2, "NdrFcLong(0x%08lx),\n", uuid->Data1);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%04x),\n", uuid->Data2);
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%04x),\n", uuid->Data3);
|
|
|
|
for (i = 0; i < 8; ++i)
|
|
|
|
print_file(file, 2, "0x%02x,\n", uuid->Data4[i]);
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
fprintf(file, "\n");
|
2006-08-18 03:09:20 +02:00
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
*typeformat_offset += 18;
|
|
|
|
}
|
2006-08-18 03:09:20 +02:00
|
|
|
return start_offset;
|
|
|
|
}
|
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
static size_t write_contexthandle_tfs(FILE *file, const type_t *type,
|
|
|
|
const var_t *var,
|
|
|
|
unsigned int *typeformat_offset)
|
|
|
|
{
|
|
|
|
size_t start_offset = *typeformat_offset;
|
|
|
|
unsigned char flags = 0x08 /* strict */;
|
|
|
|
|
|
|
|
if (is_ptr(type))
|
|
|
|
{
|
|
|
|
flags |= 0x80;
|
|
|
|
if (type->type != RPC_FC_RP)
|
|
|
|
flags |= 0x01;
|
|
|
|
}
|
|
|
|
if (is_attr(var->attrs, ATTR_IN))
|
|
|
|
flags |= 0x40;
|
|
|
|
if (is_attr(var->attrs, ATTR_OUT))
|
|
|
|
flags |= 0x20;
|
|
|
|
|
|
|
|
WRITE_FCTYPE(file, FC_BIND_CONTEXT, *typeformat_offset);
|
|
|
|
print_file(file, 2, "0x%x,\t/* Context flags: ", flags);
|
|
|
|
if (((flags & 0x21) != 0x21) && (flags & 0x01))
|
|
|
|
print_file(file, 0, "can't be null, ");
|
|
|
|
if (flags & 0x02)
|
|
|
|
print_file(file, 0, "serialize, ");
|
|
|
|
if (flags & 0x04)
|
|
|
|
print_file(file, 0, "no serialize, ");
|
|
|
|
if (flags & 0x08)
|
|
|
|
print_file(file, 0, "strict, ");
|
|
|
|
if ((flags & 0x21) == 0x20)
|
|
|
|
print_file(file, 0, "out, ");
|
|
|
|
if ((flags & 0x21) == 0x21)
|
|
|
|
print_file(file, 0, "return, ");
|
|
|
|
if (flags & 0x40)
|
|
|
|
print_file(file, 0, "in, ");
|
|
|
|
if (flags & 0x80)
|
|
|
|
print_file(file, 0, "via ptr, ");
|
|
|
|
print_file(file, 0, "*/\n");
|
|
|
|
print_file(file, 2, "0, /* FIXME: rundown routine index*/\n");
|
|
|
|
print_file(file, 2, "0, /* FIXME: param num */\n");
|
|
|
|
*typeformat_offset += 4;
|
|
|
|
|
|
|
|
return start_offset;
|
|
|
|
}
|
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
static size_t write_typeformatstring_var(FILE *file, int indent, const func_t *func,
|
2007-05-10 05:50:49 +02:00
|
|
|
type_t *type, const var_t *var,
|
|
|
|
unsigned int *typeformat_offset)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
size_t offset;
|
2006-03-31 13:46:43 +02:00
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
if (is_context_handle(type))
|
|
|
|
return write_contexthandle_tfs(file, type, var, typeformat_offset);
|
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
if (is_user_type(type))
|
|
|
|
{
|
|
|
|
write_user_tfs(file, type, typeformat_offset);
|
|
|
|
return type->typestring_offset;
|
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if ((last_ptr(type) || last_array(type)) && is_ptrchain_attr(var, ATTR_STRING))
|
|
|
|
return write_string_tfs(file, var->attrs, type, var->name, typeformat_offset);
|
2006-09-08 01:57:16 +02:00
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (is_array(type))
|
2007-09-26 20:32:08 +02:00
|
|
|
{
|
2007-10-03 06:41:04 +02:00
|
|
|
int ptr_type;
|
2007-09-26 20:32:08 +02:00
|
|
|
size_t off;
|
|
|
|
off = write_array_tfs(file, var->attrs, type, var->name, typeformat_offset);
|
2007-10-03 06:41:04 +02:00
|
|
|
ptr_type = get_attrv(var->attrs, ATTR_POINTERTYPE);
|
2007-11-02 23:24:08 +01:00
|
|
|
/* Top level pointers to conformant arrays may be handled specially
|
|
|
|
since we can bypass the pointer, but if the array is burried
|
|
|
|
beneath another pointer (e.g., "[size_is(,n)] int **p" then we
|
|
|
|
always need to write the pointer. */
|
|
|
|
if (!ptr_type && var->type != type)
|
|
|
|
/* FIXME: This should use pointer_default, but the information
|
|
|
|
isn't kept around for arrays. */
|
|
|
|
ptr_type = RPC_FC_UP;
|
2007-10-03 06:41:04 +02:00
|
|
|
if (ptr_type && ptr_type != RPC_FC_RP)
|
2007-09-26 20:32:08 +02:00
|
|
|
{
|
|
|
|
unsigned int absoff = type->typestring_offset;
|
|
|
|
short reloff = absoff - (*typeformat_offset + 2);
|
|
|
|
off = *typeformat_offset;
|
|
|
|
print_file(file, 0, "/* %d */\n", off);
|
2007-10-03 06:41:04 +02:00
|
|
|
print_file(file, 2, "0x%x, 0x0,\t/* %s */\n", ptr_type,
|
|
|
|
string_of_type(ptr_type));
|
2007-09-26 20:32:08 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%hx),\t/* Offset= %hd (%u) */\n",
|
|
|
|
reloff, reloff, absoff);
|
|
|
|
*typeformat_offset += 4;
|
|
|
|
}
|
|
|
|
return off;
|
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
if (!is_ptr(type))
|
|
|
|
{
|
|
|
|
/* basic types don't need a type format string */
|
|
|
|
if (is_base_type(type->type))
|
|
|
|
return 0;
|
2006-01-24 11:09:53 +01:00
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
switch (type->type)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
case RPC_FC_PSTRUCT:
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
case RPC_FC_BOGUS_STRUCT:
|
|
|
|
return write_struct_tfs(file, type, var->name, typeformat_offset);
|
|
|
|
case RPC_FC_ENCAPSULATED_UNION:
|
|
|
|
case RPC_FC_NON_ENCAPSULATED_UNION:
|
2007-06-12 03:51:41 +02:00
|
|
|
return write_union_tfs(file, type, typeformat_offset);
|
2007-05-10 05:50:49 +02:00
|
|
|
case RPC_FC_IGNORE:
|
|
|
|
case RPC_FC_BIND_PRIMITIVE:
|
|
|
|
/* nothing to do */
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
error("write_typeformatstring_var: Unsupported type 0x%x for variable %s\n", type->type, var->name);
|
2006-01-24 11:06:32 +01:00
|
|
|
}
|
2007-05-10 05:50:49 +02:00
|
|
|
}
|
|
|
|
else if (last_ptr(type))
|
|
|
|
{
|
|
|
|
size_t start_offset = *typeformat_offset;
|
|
|
|
int in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
int out_attr = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
const type_t *base = type->ref;
|
2006-08-18 03:09:20 +02:00
|
|
|
|
2007-10-25 03:05:48 +02:00
|
|
|
if (base->type == RPC_FC_IP
|
|
|
|
|| (base->type == 0
|
|
|
|
&& is_attr(var->attrs, ATTR_IIDIS)))
|
2007-05-10 05:50:49 +02:00
|
|
|
{
|
2007-09-13 01:10:01 +02:00
|
|
|
return write_ip_tfs(file, var->attrs, type, typeformat_offset);
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
2006-01-24 11:11:29 +01:00
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
/* special case for pointers to base types */
|
|
|
|
if (is_base_type(base->type))
|
2006-09-08 01:57:16 +02:00
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
print_file(file, indent, "0x%x, 0x%x, /* %s %s[simple_pointer] */\n",
|
2007-10-03 06:41:04 +02:00
|
|
|
type->type, (!in_attr && out_attr) ? 0x0C : 0x08,
|
|
|
|
string_of_type(type->type),
|
2007-05-10 05:50:49 +02:00
|
|
|
(!in_attr && out_attr) ? "[allocated_on_stack] " : "");
|
|
|
|
print_file(file, indent, "0x%02x, /* %s */\n", base->type, string_of_type(base->type));
|
|
|
|
print_file(file, indent, "0x5c, /* FC_PAD */\n");
|
|
|
|
*typeformat_offset += 4;
|
|
|
|
return start_offset;
|
2006-09-08 01:57:16 +02:00
|
|
|
}
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
2007-05-10 05:50:49 +02:00
|
|
|
|
|
|
|
assert(is_ptr(type));
|
|
|
|
|
|
|
|
offset = write_typeformatstring_var(file, indent, func, type->ref, var, typeformat_offset);
|
|
|
|
if (file)
|
|
|
|
fprintf(file, "/* %2u */\n", *typeformat_offset);
|
2007-10-03 06:41:04 +02:00
|
|
|
return write_pointer_only_tfs(file, var->attrs, type->type,
|
2007-05-10 05:50:49 +02:00
|
|
|
!last_ptr(type) ? 0x10 : 0,
|
|
|
|
offset, typeformat_offset);
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
|
|
|
|
2007-05-25 02:48:39 +02:00
|
|
|
static int write_embedded_types(FILE *file, const attr_list_t *attrs, type_t *type,
|
2007-06-12 03:51:41 +02:00
|
|
|
const char *name, int write_ptr, unsigned int *tfsoff)
|
2007-05-19 01:53:27 +02:00
|
|
|
{
|
2007-05-25 02:48:39 +02:00
|
|
|
int retmask = 0;
|
2007-05-19 01:53:27 +02:00
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
if (is_user_type(type))
|
|
|
|
{
|
|
|
|
write_user_tfs(file, type, tfsoff);
|
|
|
|
}
|
|
|
|
else if (is_ptr(type))
|
2007-05-25 02:48:39 +02:00
|
|
|
{
|
|
|
|
type_t *ref = type->ref;
|
|
|
|
|
2007-10-25 03:05:48 +02:00
|
|
|
if (ref->type == RPC_FC_IP
|
|
|
|
|| (ref->type == 0
|
|
|
|
&& is_attr(attrs, ATTR_IIDIS)))
|
2007-06-15 03:27:19 +02:00
|
|
|
{
|
2007-09-13 01:10:01 +02:00
|
|
|
write_ip_tfs(file, attrs, type, tfsoff);
|
2007-06-15 03:27:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!processed(ref) && !is_base_type(ref->type))
|
|
|
|
retmask |= write_embedded_types(file, NULL, ref, name, TRUE, tfsoff);
|
2007-05-25 02:48:39 +02:00
|
|
|
|
2007-06-15 03:27:19 +02:00
|
|
|
if (write_ptr)
|
|
|
|
write_pointer_tfs(file, type, tfsoff);
|
2007-05-25 02:48:39 +02:00
|
|
|
|
2007-06-15 03:27:19 +02:00
|
|
|
retmask |= 1;
|
|
|
|
}
|
2007-05-25 02:48:39 +02:00
|
|
|
}
|
2007-09-17 10:46:01 +02:00
|
|
|
else if (last_array(type) && is_attr(attrs, ATTR_STRING))
|
|
|
|
{
|
|
|
|
write_string_tfs(file, attrs, type, name, tfsoff);
|
|
|
|
}
|
2007-06-06 03:52:24 +02:00
|
|
|
else if (type->declarray && is_conformant_array(type))
|
|
|
|
; /* conformant arrays and strings are handled specially */
|
2007-06-06 03:50:31 +02:00
|
|
|
else if (is_array(type))
|
|
|
|
{
|
2007-06-06 03:52:24 +02:00
|
|
|
write_array_tfs(file, attrs, type, name, tfsoff);
|
2007-10-11 00:29:54 +02:00
|
|
|
if (is_conformant_array(type))
|
|
|
|
retmask |= 1;
|
2007-06-06 03:50:31 +02:00
|
|
|
}
|
2007-06-12 03:51:41 +02:00
|
|
|
else if (is_struct(type->type))
|
|
|
|
{
|
|
|
|
if (!processed(type))
|
|
|
|
write_struct_tfs(file, type, name, tfsoff);
|
|
|
|
}
|
|
|
|
else if (is_union(type->type))
|
|
|
|
{
|
|
|
|
if (!processed(type))
|
|
|
|
write_union_tfs(file, type, tfsoff);
|
|
|
|
}
|
2007-05-25 02:48:39 +02:00
|
|
|
else if (!is_base_type(type->type))
|
|
|
|
error("write_embedded_types: unknown embedded type for %s (0x%x)\n",
|
|
|
|
name, type->type);
|
|
|
|
|
|
|
|
return retmask;
|
2007-05-19 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
2007-10-16 03:06:33 +02:00
|
|
|
static size_t process_tfs(FILE *file, const ifref_list_t *ifaces, type_pred_t pred)
|
2007-05-16 02:45:59 +02:00
|
|
|
{
|
|
|
|
const var_t *var;
|
|
|
|
const ifref_t *iface;
|
2007-05-21 08:55:43 +02:00
|
|
|
unsigned int typeformat_offset = 2;
|
2005-12-13 11:22:08 +01:00
|
|
|
|
2007-01-22 14:21:56 +01:00
|
|
|
if (ifaces) LIST_FOR_EACH_ENTRY( iface, ifaces, const ifref_t, entry )
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2007-10-16 03:06:33 +02:00
|
|
|
if (!pred(iface->iface))
|
2006-06-01 16:40:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (iface->iface->funcs)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2007-01-22 14:23:08 +01:00
|
|
|
const func_t *func;
|
|
|
|
LIST_FOR_EACH_ENTRY( func, iface->iface->funcs, const func_t, entry )
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2007-01-24 20:06:51 +01:00
|
|
|
if (is_local(func->def->attrs)) continue;
|
2007-05-19 01:52:25 +02:00
|
|
|
|
|
|
|
current_func = func;
|
2006-06-01 16:40:10 +02:00
|
|
|
if (func->args)
|
2007-01-22 14:26:12 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
2007-05-25 02:50:02 +02:00
|
|
|
update_tfsoff(
|
|
|
|
var->type,
|
|
|
|
write_typeformatstring_var(
|
|
|
|
file, 2, func, var->type, var,
|
|
|
|
&typeformat_offset),
|
|
|
|
file);
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-16 02:45:59 +02:00
|
|
|
return typeformat_offset + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-16 03:06:33 +02:00
|
|
|
void write_typeformatstring(FILE *file, const ifref_list_t *ifaces, type_pred_t pred)
|
2007-05-16 02:45:59 +02:00
|
|
|
{
|
|
|
|
int indent = 0;
|
|
|
|
|
|
|
|
print_file(file, indent, "static const MIDL_TYPE_FORMAT_STRING __MIDL_TypeFormatString =\n");
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "0,\n");
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "NdrFcShort(0x0),\n");
|
|
|
|
|
2007-10-09 01:47:28 +02:00
|
|
|
set_all_tfswrite(TRUE);
|
2007-10-16 03:06:33 +02:00
|
|
|
process_tfs(file, ifaces, pred);
|
2007-05-16 02:45:59 +02:00
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
print_file(file, indent, "0x0\n");
|
|
|
|
indent--;
|
|
|
|
print_file(file, indent, "}\n");
|
|
|
|
indent--;
|
|
|
|
print_file(file, indent, "};\n");
|
|
|
|
print_file(file, indent, "\n");
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:22:32 +01:00
|
|
|
static unsigned int get_required_buffer_size_type(
|
2007-06-06 03:50:31 +02:00
|
|
|
const type_t *type, const char *name, unsigned int *alignment)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:20:59 +01:00
|
|
|
*alignment = 0;
|
2007-06-26 03:23:33 +02:00
|
|
|
if (is_user_type(type))
|
|
|
|
{
|
|
|
|
const char *uname;
|
|
|
|
const type_t *utype = get_user_type(type, &uname);
|
2007-09-19 00:29:26 +02:00
|
|
|
return get_required_buffer_size_type(utype, uname, alignment);
|
2007-06-26 03:23:33 +02:00
|
|
|
}
|
2007-09-19 00:29:26 +02:00
|
|
|
else
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:22:32 +01:00
|
|
|
switch (type->type)
|
2005-12-26 13:20:59 +01:00
|
|
|
{
|
2005-12-08 12:52:13 +01:00
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_CHAR:
|
2005-12-26 13:20:59 +01:00
|
|
|
case RPC_FC_USMALL:
|
|
|
|
case RPC_FC_SMALL:
|
2006-03-23 10:39:07 +01:00
|
|
|
*alignment = 4;
|
2007-09-19 00:29:26 +02:00
|
|
|
return 1;
|
2005-12-26 13:20:59 +01:00
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
case RPC_FC_SHORT:
|
2007-06-26 03:24:11 +02:00
|
|
|
case RPC_FC_ENUM16:
|
2006-03-23 10:39:07 +01:00
|
|
|
*alignment = 4;
|
2007-09-19 00:29:26 +02:00
|
|
|
return 2;
|
2005-12-26 13:20:59 +01:00
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_LONG:
|
2007-06-26 03:24:11 +02:00
|
|
|
case RPC_FC_ENUM32:
|
2005-12-08 12:53:58 +01:00
|
|
|
case RPC_FC_FLOAT:
|
|
|
|
case RPC_FC_ERROR_STATUS_T:
|
2005-12-26 13:20:59 +01:00
|
|
|
*alignment = 4;
|
2007-09-19 00:29:26 +02:00
|
|
|
return 4;
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2005-12-08 12:53:58 +01:00
|
|
|
case RPC_FC_HYPER:
|
|
|
|
case RPC_FC_DOUBLE:
|
2005-12-26 13:20:59 +01:00
|
|
|
*alignment = 8;
|
2007-09-19 00:29:26 +02:00
|
|
|
return 8;
|
2005-12-08 12:52:13 +01:00
|
|
|
|
2006-01-31 18:06:17 +01:00
|
|
|
case RPC_FC_IGNORE:
|
|
|
|
case RPC_FC_BIND_PRIMITIVE:
|
|
|
|
return 0;
|
|
|
|
|
2006-01-06 21:06:24 +01:00
|
|
|
case RPC_FC_STRUCT:
|
2007-05-10 05:50:49 +02:00
|
|
|
case RPC_FC_PSTRUCT:
|
2006-01-06 21:06:24 +01:00
|
|
|
{
|
2007-09-19 00:29:26 +02:00
|
|
|
size_t size = 0;
|
2006-01-06 21:06:24 +01:00
|
|
|
const var_t *field;
|
2007-01-22 14:26:12 +01:00
|
|
|
if (!type->fields) return 0;
|
|
|
|
LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
|
2006-01-06 21:06:24 +01:00
|
|
|
{
|
|
|
|
unsigned int alignment;
|
2007-06-06 03:50:31 +02:00
|
|
|
size += get_required_buffer_size_type(field->type, field->name,
|
|
|
|
&alignment);
|
2006-01-06 21:06:24 +01:00
|
|
|
}
|
2007-09-19 00:29:26 +02:00
|
|
|
return size;
|
2006-01-06 21:06:24 +01:00
|
|
|
}
|
|
|
|
|
2007-01-24 20:10:57 +01:00
|
|
|
case RPC_FC_RP:
|
2007-09-19 00:29:26 +02:00
|
|
|
return
|
|
|
|
is_base_type( type->ref->type ) || type->ref->type == RPC_FC_STRUCT
|
|
|
|
? get_required_buffer_size_type( type->ref, name, alignment )
|
|
|
|
: 0;
|
2007-06-06 03:50:31 +02:00
|
|
|
|
|
|
|
case RPC_FC_SMFARRAY:
|
|
|
|
case RPC_FC_LGFARRAY:
|
2007-09-19 00:29:26 +02:00
|
|
|
return type->dim * get_required_buffer_size_type(type->ref, name, alignment);
|
2007-01-24 20:10:57 +01:00
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
2005-12-26 13:20:59 +01:00
|
|
|
}
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-24 20:02:05 +01:00
|
|
|
static unsigned int get_required_buffer_size(const var_t *var, unsigned int *alignment, enum pass pass)
|
2005-12-26 13:22:32 +01:00
|
|
|
{
|
2006-03-29 12:42:29 +02:00
|
|
|
int in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
int out_attr = is_attr(var->attrs, ATTR_OUT);
|
2007-09-28 02:38:27 +02:00
|
|
|
const type_t *t;
|
2006-03-29 12:42:29 +02:00
|
|
|
|
|
|
|
if (!in_attr && !out_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
2006-04-09 14:38:57 +02:00
|
|
|
*alignment = 0;
|
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
for (t = var->type; is_ptr(t); t = t->ref)
|
|
|
|
if (is_attr(t->attrs, ATTR_CONTEXTHANDLE))
|
|
|
|
{
|
|
|
|
*alignment = 4;
|
|
|
|
return 20;
|
|
|
|
}
|
|
|
|
|
2006-04-09 14:38:57 +02:00
|
|
|
if (pass == PASS_OUT)
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
if (out_attr && is_ptr(var->type))
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
|
|
|
type_t *type = var->type;
|
|
|
|
|
2006-04-09 14:38:57 +02:00
|
|
|
if (type->type == RPC_FC_STRUCT)
|
|
|
|
{
|
|
|
|
const var_t *field;
|
|
|
|
unsigned int size = 36;
|
2007-01-22 14:26:12 +01:00
|
|
|
|
|
|
|
if (!type->fields) return size;
|
|
|
|
LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
|
|
|
unsigned int align;
|
|
|
|
size += get_required_buffer_size_type(
|
2007-06-06 03:50:31 +02:00
|
|
|
field->type, field->name, &align);
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
2006-03-29 12:42:29 +02:00
|
|
|
}
|
2006-04-09 14:38:57 +02:00
|
|
|
return 0;
|
2006-03-29 12:42:29 +02:00
|
|
|
}
|
2006-04-09 14:38:57 +02:00
|
|
|
else
|
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
if ((!out_attr || in_attr) && !var->type->size_is
|
|
|
|
&& !is_attr(var->attrs, ATTR_STRING) && !var->type->declarray)
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
if (is_ptr(var->type))
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
|
|
|
type_t *type = var->type;
|
2006-03-29 12:42:29 +02:00
|
|
|
|
2006-04-09 14:38:57 +02:00
|
|
|
if (is_base_type(type->type))
|
|
|
|
{
|
|
|
|
return 25;
|
|
|
|
}
|
|
|
|
else if (type->type == RPC_FC_STRUCT)
|
|
|
|
{
|
|
|
|
unsigned int size = 36;
|
|
|
|
const var_t *field;
|
2007-01-22 14:26:12 +01:00
|
|
|
|
|
|
|
if (!type->fields) return size;
|
|
|
|
LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
|
|
|
unsigned int align;
|
|
|
|
size += get_required_buffer_size_type(
|
2007-06-06 03:50:31 +02:00
|
|
|
field->type, field->name, &align);
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
return get_required_buffer_size_type(var->type, var->name, alignment);
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
2005-12-26 13:22:32 +01:00
|
|
|
}
|
|
|
|
|
2007-01-24 20:02:05 +01:00
|
|
|
static unsigned int get_function_buffer_size( const func_t *func, enum pass pass )
|
|
|
|
{
|
|
|
|
const var_t *var;
|
|
|
|
unsigned int total_size = 0, alignment;
|
|
|
|
|
|
|
|
if (func->args)
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
|
|
|
{
|
|
|
|
total_size += get_required_buffer_size(var, &alignment, pass);
|
|
|
|
total_size += alignment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
if (pass == PASS_OUT && !is_void(func->def->type))
|
2007-01-24 20:02:05 +01:00
|
|
|
{
|
|
|
|
total_size += get_required_buffer_size(func->def, &alignment, PASS_RETURN);
|
|
|
|
total_size += alignment;
|
|
|
|
}
|
|
|
|
return total_size;
|
|
|
|
}
|
|
|
|
|
2006-03-31 13:47:35 +02:00
|
|
|
static void print_phase_function(FILE *file, int indent, const char *type,
|
|
|
|
enum remoting_phase phase,
|
2007-06-14 01:13:04 +02:00
|
|
|
const var_t *var, unsigned int type_offset)
|
2006-02-07 12:32:24 +01:00
|
|
|
{
|
2006-03-31 13:47:35 +02:00
|
|
|
const char *function;
|
2006-02-07 12:32:24 +01:00
|
|
|
switch (phase)
|
|
|
|
{
|
|
|
|
case PHASE_BUFFERSIZE:
|
2006-03-31 13:47:35 +02:00
|
|
|
function = "BufferSize";
|
|
|
|
break;
|
2006-02-07 12:32:24 +01:00
|
|
|
case PHASE_MARSHAL:
|
2006-03-31 13:47:35 +02:00
|
|
|
function = "Marshall";
|
|
|
|
break;
|
2006-02-07 12:32:24 +01:00
|
|
|
case PHASE_UNMARSHAL:
|
2006-03-31 13:47:35 +02:00
|
|
|
function = "Unmarshall";
|
|
|
|
break;
|
2006-02-07 12:32:24 +01:00
|
|
|
case PHASE_FREE:
|
2006-03-31 13:47:35 +02:00
|
|
|
function = "Free";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return;
|
2006-02-07 12:32:24 +01:00
|
|
|
}
|
2006-03-31 13:47:35 +02:00
|
|
|
|
|
|
|
print_file(file, indent, "Ndr%s%s(\n", type, function);
|
|
|
|
indent++;
|
2006-03-31 13:55:05 +02:00
|
|
|
print_file(file, indent, "&_StubMsg,\n");
|
2007-06-14 01:13:04 +02:00
|
|
|
print_file(file, indent, "%s%s%s%s,\n",
|
|
|
|
(phase == PHASE_UNMARSHAL) ? "(unsigned char **)" : "(unsigned char *)",
|
|
|
|
(phase == PHASE_UNMARSHAL || decl_indirect(var->type)) ? "&" : "",
|
|
|
|
(phase == PHASE_UNMARSHAL && decl_indirect(var->type)) ? "_p_" : "",
|
|
|
|
var->name);
|
2006-03-31 13:47:35 +02:00
|
|
|
print_file(file, indent, "(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%d]%s\n",
|
|
|
|
type_offset, (phase == PHASE_UNMARSHAL) ? "," : ");");
|
|
|
|
if (phase == PHASE_UNMARSHAL)
|
|
|
|
print_file(file, indent, "0);\n");
|
|
|
|
indent--;
|
2006-02-07 12:32:24 +01:00
|
|
|
}
|
|
|
|
|
2006-03-31 13:48:24 +02:00
|
|
|
void print_phase_basetype(FILE *file, int indent, enum remoting_phase phase,
|
|
|
|
enum pass pass, const var_t *var,
|
|
|
|
const char *varname)
|
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
type_t *type = var->type;
|
2006-03-31 13:48:24 +02:00
|
|
|
unsigned int size;
|
|
|
|
unsigned int alignment = 0;
|
2006-08-09 23:20:35 +02:00
|
|
|
unsigned char rtype;
|
2006-03-31 13:48:24 +02:00
|
|
|
|
|
|
|
/* no work to do for other phases, buffer sizing is done elsewhere */
|
|
|
|
if (phase != PHASE_MARSHAL && phase != PHASE_UNMARSHAL)
|
|
|
|
return;
|
|
|
|
|
2007-05-10 05:50:49 +02:00
|
|
|
rtype = is_ptr(type) ? type->ref->type : type->type;
|
2006-03-31 13:48:24 +02:00
|
|
|
|
2006-08-09 23:20:35 +02:00
|
|
|
switch (rtype)
|
2006-03-31 13:48:24 +02:00
|
|
|
{
|
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_SMALL:
|
|
|
|
case RPC_FC_USMALL:
|
|
|
|
size = 1;
|
|
|
|
alignment = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
case RPC_FC_SHORT:
|
2007-06-26 03:24:11 +02:00
|
|
|
case RPC_FC_ENUM16:
|
2006-03-31 13:48:24 +02:00
|
|
|
size = 2;
|
|
|
|
alignment = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_LONG:
|
2007-06-26 03:24:11 +02:00
|
|
|
case RPC_FC_ENUM32:
|
2006-03-31 13:48:24 +02:00
|
|
|
case RPC_FC_FLOAT:
|
|
|
|
case RPC_FC_ERROR_STATUS_T:
|
|
|
|
size = 4;
|
|
|
|
alignment = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_HYPER:
|
|
|
|
case RPC_FC_DOUBLE:
|
|
|
|
size = 8;
|
|
|
|
alignment = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_IGNORE:
|
|
|
|
case RPC_FC_BIND_PRIMITIVE:
|
|
|
|
/* no marshalling needed */
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
2006-08-09 23:20:35 +02:00
|
|
|
error("print_phase_basetype: Unsupported type: %s (0x%02x, ptr_level: 0)\n", var->name, rtype);
|
2006-03-31 13:48:24 +02:00
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, indent, "_StubMsg.Buffer = (unsigned char *)(((long)_StubMsg.Buffer + %u) & ~0x%x);\n",
|
|
|
|
alignment - 1, alignment - 1);
|
|
|
|
|
|
|
|
if (phase == PHASE_MARSHAL)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "*(");
|
2007-10-03 06:39:38 +02:00
|
|
|
write_type_decl(file, is_ptr(type) ? type->ref : type, NULL);
|
2007-05-10 05:50:49 +02:00
|
|
|
if (is_ptr(type))
|
2006-03-31 13:48:24 +02:00
|
|
|
fprintf(file, " *)_StubMsg.Buffer = *");
|
|
|
|
else
|
|
|
|
fprintf(file, " *)_StubMsg.Buffer = ");
|
2007-10-18 03:05:37 +02:00
|
|
|
fprintf(file, "%s", varname);
|
2006-03-31 13:48:24 +02:00
|
|
|
fprintf(file, ";\n");
|
|
|
|
}
|
|
|
|
else if (phase == PHASE_UNMARSHAL)
|
|
|
|
{
|
|
|
|
if (pass == PASS_IN || pass == PASS_RETURN)
|
|
|
|
print_file(file, indent, "");
|
|
|
|
else
|
|
|
|
print_file(file, indent, "*");
|
2007-10-18 03:05:37 +02:00
|
|
|
fprintf(file, "%s", varname);
|
2007-05-10 05:50:49 +02:00
|
|
|
if (pass == PASS_IN && is_ptr(type))
|
2006-03-31 13:48:24 +02:00
|
|
|
fprintf(file, " = (");
|
|
|
|
else
|
|
|
|
fprintf(file, " = *(");
|
2007-10-03 06:39:38 +02:00
|
|
|
write_type_decl(file, is_ptr(type) ? type->ref : type, NULL);
|
2006-03-31 13:48:24 +02:00
|
|
|
fprintf(file, " *)_StubMsg.Buffer;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, indent, "_StubMsg.Buffer += sizeof(");
|
2007-10-03 06:39:38 +02:00
|
|
|
write_type_decl(file, var->type, NULL);
|
2006-03-31 13:48:24 +02:00
|
|
|
fprintf(file, ");\n");
|
|
|
|
}
|
|
|
|
|
2006-03-31 13:47:08 +02:00
|
|
|
/* returns whether the MaxCount, Offset or ActualCount members need to be
|
|
|
|
* filled in for the specified phase */
|
|
|
|
static inline int is_size_needed_for_phase(enum remoting_phase phase)
|
|
|
|
{
|
|
|
|
return (phase != PHASE_UNMARSHAL);
|
|
|
|
}
|
|
|
|
|
2007-09-13 01:08:43 +02:00
|
|
|
static int needs_freeing(const attr_list_t *attrs, const type_t *t, int out)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
(is_user_type(t)
|
|
|
|
|| (is_ptr(t)
|
|
|
|
&& (t->ref->type == RPC_FC_IP
|
|
|
|
|| is_ptr(t->ref))))
|
|
|
|
|| (out && (is_string_type(attrs, t)
|
|
|
|
|| is_array(t)));
|
|
|
|
}
|
|
|
|
|
2007-11-02 23:25:26 +01:00
|
|
|
expr_t *get_size_is_expr(const type_t *t, const char *name)
|
|
|
|
{
|
|
|
|
expr_t *x = NULL;
|
|
|
|
|
|
|
|
for ( ; is_ptr(t) || is_array(t); t = t->ref)
|
|
|
|
if (t->size_is)
|
|
|
|
{
|
|
|
|
if (!x)
|
|
|
|
x = t->size_is;
|
|
|
|
else
|
|
|
|
error("%s: multidimensional conformant"
|
|
|
|
" arrays not supported at the top level\n",
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2006-02-07 12:32:24 +01:00
|
|
|
void write_remoting_arguments(FILE *file, int indent, const func_t *func,
|
2007-05-16 02:45:59 +02:00
|
|
|
enum pass pass, enum remoting_phase phase)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
int in_attr, out_attr, pointer_type;
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *var;
|
2005-12-08 12:52:13 +01:00
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
2007-01-24 20:02:05 +01:00
|
|
|
if (phase == PHASE_BUFFERSIZE)
|
|
|
|
{
|
|
|
|
unsigned int size = get_function_buffer_size( func, pass );
|
|
|
|
print_file(file, indent, "_StubMsg.BufferLength = %u;\n", size);
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2006-03-31 13:45:16 +02:00
|
|
|
const type_t *type = var->type;
|
2006-08-09 23:20:35 +02:00
|
|
|
unsigned char rtype;
|
2007-05-16 02:45:59 +02:00
|
|
|
size_t start_offset = type->typestring_offset;
|
2006-08-09 23:20:35 +02:00
|
|
|
|
2006-03-29 12:42:29 +02:00
|
|
|
pointer_type = get_attrv(var->attrs, ATTR_POINTERTYPE);
|
|
|
|
if (!pointer_type)
|
|
|
|
pointer_type = RPC_FC_RP;
|
2005-12-26 13:14:28 +01:00
|
|
|
|
2006-03-29 12:42:29 +02:00
|
|
|
in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(var->attrs, ATTR_OUT);
|
2005-12-26 13:14:28 +01:00
|
|
|
if (!in_attr && !out_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
2007-09-13 01:08:43 +02:00
|
|
|
if (phase == PHASE_FREE)
|
2005-12-26 13:14:28 +01:00
|
|
|
{
|
2007-09-13 01:08:43 +02:00
|
|
|
if (!needs_freeing(var->attrs, type, out_attr))
|
|
|
|
continue;
|
2005-12-26 13:14:28 +01:00
|
|
|
}
|
2007-09-13 01:08:43 +02:00
|
|
|
else
|
|
|
|
switch (pass)
|
|
|
|
{
|
|
|
|
case PASS_IN:
|
|
|
|
if (!in_attr) continue;
|
|
|
|
break;
|
|
|
|
case PASS_OUT:
|
|
|
|
if (!out_attr) continue;
|
|
|
|
break;
|
|
|
|
case PASS_RETURN:
|
|
|
|
break;
|
|
|
|
}
|
2005-12-26 13:14:28 +01:00
|
|
|
|
2006-08-30 02:19:21 +02:00
|
|
|
rtype = type->type;
|
2006-03-31 13:45:16 +02:00
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
if (is_context_handle(type))
|
|
|
|
{
|
|
|
|
if (phase == PHASE_MARSHAL)
|
|
|
|
{
|
|
|
|
if (pass == PASS_IN)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "NdrClientContextMarshall(\n");
|
|
|
|
print_file(file, indent + 1, "&_StubMsg,\n");
|
|
|
|
print_file(file, indent + 1, "(NDR_CCONTEXT)%s%s,\n", is_ptr(type) ? "*" : "", var->name);
|
|
|
|
print_file(file, indent + 1, "%s);\n", in_attr && out_attr ? "1" : "0");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_file(file, indent, "NdrServerContextMarshall(\n");
|
|
|
|
print_file(file, indent + 1, "&_StubMsg,\n");
|
|
|
|
print_file(file, indent + 1, "(NDR_SCONTEXT)%s,\n", var->name);
|
|
|
|
print_file(file, indent + 1, "(NDR_RUNDOWN)%s_rundown);\n", get_context_handle_type_name(var->type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (phase == PHASE_UNMARSHAL)
|
|
|
|
{
|
|
|
|
if (pass == PASS_OUT)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "NdrClientContextUnmarshall(\n");
|
|
|
|
print_file(file, indent + 1, "&_StubMsg,\n");
|
|
|
|
print_file(file, indent + 1, "(NDR_CCONTEXT *)%s,\n", var->name);
|
|
|
|
print_file(file, indent + 1, "_Handle);\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
print_file(file, indent, "%s = NdrServerContextUnmarshall(&_StubMsg);\n", var->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (is_user_type(var->type))
|
2007-01-26 11:59:58 +01:00
|
|
|
{
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "UserMarshal", phase, var, start_offset);
|
2007-01-26 11:59:58 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else if (is_string_type(var->attrs, var->type))
|
2006-01-24 11:09:53 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
if (is_array(type) && !is_conformant_array(type))
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "NonConformantString", phase, var, start_offset);
|
2006-01-24 11:10:08 +01:00
|
|
|
else
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
if (type->size_is && is_size_needed_for_phase(phase))
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
|
|
|
print_file(file, indent, "_StubMsg.MaxCount = (unsigned long)");
|
2007-06-06 03:50:31 +02:00
|
|
|
write_expr(file, type->size_is, 1);
|
2006-03-29 12:42:29 +02:00
|
|
|
fprintf(file, ";\n");
|
|
|
|
}
|
|
|
|
|
2006-04-20 22:28:41 +02:00
|
|
|
if ((phase == PHASE_FREE) || (pointer_type == RPC_FC_UP))
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "Pointer", phase, var, start_offset);
|
2006-03-29 12:42:29 +02:00
|
|
|
else
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "ConformantString", phase, var,
|
2007-06-06 03:50:31 +02:00
|
|
|
start_offset + (type->size_is ? 4 : 2));
|
2006-03-29 12:42:29 +02:00
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
else if (is_array(type))
|
2006-01-24 11:09:53 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
unsigned char tc = type->type;
|
2007-09-20 02:05:38 +02:00
|
|
|
const char *array_type = "FixedArray";
|
2007-11-02 23:24:08 +01:00
|
|
|
|
2007-11-02 23:25:26 +01:00
|
|
|
/* We already have the size_is expression since it's at the
|
|
|
|
top level, but do checks for multidimensional conformant
|
|
|
|
arrays. When we handle them, we'll need to extend this
|
|
|
|
function to return a list, and then we'll actually use
|
|
|
|
the return value. */
|
|
|
|
get_size_is_expr(type, var->name);
|
2006-01-24 11:09:53 +01:00
|
|
|
|
2007-09-20 02:05:38 +02:00
|
|
|
if (tc == RPC_FC_SMVARRAY || tc == RPC_FC_LGVARRAY)
|
2006-01-24 11:09:53 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
if (is_size_needed_for_phase(phase))
|
2006-01-24 11:09:53 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, indent, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
|
|
|
|
print_file(file, indent, "_StubMsg.ActualCount = (unsigned long)");
|
|
|
|
write_expr(file, type->length_is, 1);
|
|
|
|
fprintf(file, ";\n\n");
|
2006-01-24 11:09:53 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
array_type = "VaryingArray";
|
|
|
|
}
|
|
|
|
else if (tc == RPC_FC_CARRAY)
|
|
|
|
{
|
|
|
|
if (is_size_needed_for_phase(phase) && phase != PHASE_FREE)
|
2006-01-24 11:09:53 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
print_file(file, indent, "_StubMsg.MaxCount = (unsigned long)");
|
|
|
|
write_expr(file, type->size_is, 1);
|
|
|
|
fprintf(file, ";\n\n");
|
2006-01-24 11:09:53 +01:00
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
array_type = "ConformantArray";
|
|
|
|
}
|
2007-09-20 02:05:38 +02:00
|
|
|
else if (tc == RPC_FC_CVARRAY || tc == RPC_FC_BOGUS_ARRAY)
|
2007-06-06 03:50:31 +02:00
|
|
|
{
|
|
|
|
if (is_size_needed_for_phase(phase))
|
2006-01-24 11:09:53 +01:00
|
|
|
{
|
2007-09-20 02:05:38 +02:00
|
|
|
if (type->size_is)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "_StubMsg.MaxCount = (unsigned long)");
|
|
|
|
write_expr(file, type->size_is, 1);
|
|
|
|
fprintf(file, ";\n");
|
|
|
|
}
|
|
|
|
if (type->length_is)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
|
|
|
|
print_file(file, indent, "_StubMsg.ActualCount = (unsigned long)");
|
|
|
|
write_expr(file, type->length_is, 1);
|
|
|
|
fprintf(file, ";\n\n");
|
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
}
|
2007-09-20 02:05:38 +02:00
|
|
|
array_type = (tc == RPC_FC_BOGUS_ARRAY
|
|
|
|
? "ComplexArray"
|
|
|
|
: "ConformantVaryingArray");
|
2006-01-24 11:09:53 +01:00
|
|
|
}
|
|
|
|
|
2006-04-05 00:07:03 +02:00
|
|
|
if (!in_attr && phase == PHASE_FREE)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "if (%s)\n", var->name);
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "_StubMsg.pfnFree(%s);\n", var->name);
|
|
|
|
}
|
|
|
|
else if (phase != PHASE_FREE)
|
2006-04-15 11:09:42 +02:00
|
|
|
{
|
2007-09-26 20:32:08 +02:00
|
|
|
const char *t = pointer_type == RPC_FC_RP ? array_type : "Pointer";
|
|
|
|
print_phase_function(file, indent, t, phase, var, start_offset);
|
2006-04-15 11:09:42 +02:00
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
}
|
2007-05-10 05:50:49 +02:00
|
|
|
else if (!is_ptr(var->type) && is_base_type(rtype))
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2006-03-31 13:48:24 +02:00
|
|
|
print_phase_basetype(file, indent, phase, pass, var, var->name);
|
2005-12-26 13:09:36 +01:00
|
|
|
}
|
2007-05-10 05:50:49 +02:00
|
|
|
else if (!is_ptr(var->type))
|
2005-12-26 13:12:03 +01:00
|
|
|
{
|
2006-08-09 23:20:35 +02:00
|
|
|
switch (rtype)
|
2005-12-26 13:12:03 +01:00
|
|
|
{
|
2006-01-24 11:09:53 +01:00
|
|
|
case RPC_FC_STRUCT:
|
2007-05-10 05:50:49 +02:00
|
|
|
case RPC_FC_PSTRUCT:
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "SimpleStruct", phase, var, start_offset);
|
2006-01-24 11:09:53 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "ConformantStruct", phase, var, start_offset);
|
2006-01-24 11:09:53 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_CVSTRUCT:
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "ConformantVaryingStruct", phase, var, start_offset);
|
2006-01-24 11:09:53 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_BOGUS_STRUCT:
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "ComplexStruct", phase, var, start_offset);
|
2007-01-24 20:10:57 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_RP:
|
|
|
|
if (is_base_type( var->type->ref->type ))
|
|
|
|
{
|
|
|
|
print_phase_basetype(file, indent, phase, pass, var, var->name);
|
|
|
|
}
|
|
|
|
else if (var->type->ref->type == RPC_FC_STRUCT)
|
|
|
|
{
|
|
|
|
if (phase != PHASE_BUFFERSIZE && phase != PHASE_FREE)
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "SimpleStruct", phase, var, start_offset + 4);
|
2007-01-24 20:10:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const var_t *iid;
|
|
|
|
if ((iid = get_attrp( var->attrs, ATTR_IIDIS )))
|
|
|
|
print_file( file, indent, "_StubMsg.MaxCount = (unsigned long)%s;\n", iid->name );
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "Pointer", phase, var, start_offset);
|
2007-01-24 20:10:57 +01:00
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
break;
|
|
|
|
default:
|
2007-05-10 05:50:49 +02:00
|
|
|
error("write_remoting_arguments: Unsupported type: %s (0x%02x)\n", var->name, rtype);
|
2005-12-26 13:12:03 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-26 13:09:36 +01:00
|
|
|
else
|
|
|
|
{
|
2007-05-10 05:50:49 +02:00
|
|
|
if (last_ptr(var->type) && (pointer_type == RPC_FC_RP) && is_base_type(rtype))
|
2006-03-24 17:40:17 +01:00
|
|
|
{
|
2006-03-31 13:48:24 +02:00
|
|
|
print_phase_basetype(file, indent, phase, pass, var, var->name);
|
2006-03-24 17:40:17 +01:00
|
|
|
}
|
2007-05-10 05:50:49 +02:00
|
|
|
else if (last_ptr(var->type) && (pointer_type == RPC_FC_RP) && (rtype == RPC_FC_STRUCT))
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
|
|
|
if (phase != PHASE_BUFFERSIZE && phase != PHASE_FREE)
|
2007-06-14 01:13:04 +02:00
|
|
|
print_phase_function(file, indent, "SimpleStruct", phase, var, start_offset + 4);
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
2006-03-31 13:46:43 +02:00
|
|
|
else
|
2006-03-24 17:40:17 +01:00
|
|
|
{
|
2007-01-24 20:10:07 +01:00
|
|
|
const var_t *iid;
|
2007-11-02 23:25:26 +01:00
|
|
|
expr_t *sx = get_size_is_expr(type, var->name);
|
2007-11-02 23:24:08 +01:00
|
|
|
|
2007-01-24 20:10:07 +01:00
|
|
|
if ((iid = get_attrp( var->attrs, ATTR_IIDIS )))
|
|
|
|
print_file( file, indent, "_StubMsg.MaxCount = (unsigned long)%s;\n", iid->name );
|
2007-11-02 23:24:08 +01:00
|
|
|
else if (sx)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "_StubMsg.MaxCount = (unsigned long) ");
|
|
|
|
write_expr(file, sx, 1);
|
|
|
|
fprintf(file, ";\n\n");
|
|
|
|
}
|
2007-09-13 01:08:04 +02:00
|
|
|
if (var->type->ref->type == RPC_FC_IP)
|
|
|
|
print_phase_function(file, indent, "InterfacePointer", phase, var, start_offset);
|
|
|
|
else
|
|
|
|
print_phase_function(file, indent, "Pointer", phase, var, start_offset);
|
2006-03-24 17:40:17 +01:00
|
|
|
}
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
fprintf(file, "\n");
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-26 13:05:29 +01:00
|
|
|
|
|
|
|
|
2006-01-24 11:05:51 +01:00
|
|
|
size_t get_size_procformatstring_var(const var_t *var)
|
2005-12-26 13:05:29 +01:00
|
|
|
{
|
2007-05-16 02:45:59 +02:00
|
|
|
return write_procformatstring_var(NULL, 0, var, FALSE);
|
2005-12-26 13:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-24 20:05:22 +01:00
|
|
|
size_t get_size_procformatstring_func(const func_t *func)
|
|
|
|
{
|
|
|
|
const var_t *var;
|
|
|
|
size_t size = 0;
|
|
|
|
|
|
|
|
/* argument list size */
|
|
|
|
if (func->args)
|
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
|
|
|
size += get_size_procformatstring_var(var);
|
|
|
|
|
|
|
|
/* return value size */
|
2007-05-10 05:50:49 +02:00
|
|
|
if (is_void(func->def->type))
|
2007-01-24 20:05:22 +01:00
|
|
|
size += 2; /* FC_END and FC_PAD */
|
|
|
|
else
|
|
|
|
size += get_size_procformatstring_var(func->def);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2007-10-16 03:06:33 +02:00
|
|
|
size_t get_size_procformatstring(const ifref_list_t *ifaces, type_pred_t pred)
|
2006-03-23 10:33:08 +01:00
|
|
|
{
|
2007-01-22 14:21:56 +01:00
|
|
|
const ifref_t *iface;
|
2006-03-23 10:33:08 +01:00
|
|
|
size_t size = 1;
|
2007-01-22 14:23:08 +01:00
|
|
|
const func_t *func;
|
2006-03-23 10:33:08 +01:00
|
|
|
|
2007-01-22 14:21:56 +01:00
|
|
|
if (ifaces) LIST_FOR_EACH_ENTRY( iface, ifaces, const ifref_t, entry )
|
2006-03-23 10:33:08 +01:00
|
|
|
{
|
2007-10-16 03:06:33 +02:00
|
|
|
if (!pred(iface->iface))
|
2006-06-01 16:40:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (iface->iface->funcs)
|
2007-01-22 14:23:08 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( func, iface->iface->funcs, const func_t, entry )
|
2007-01-24 20:05:22 +01:00
|
|
|
if (!is_local(func->def->attrs))
|
|
|
|
size += get_size_procformatstring_func( func );
|
2006-03-23 10:33:08 +01:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2007-10-16 03:06:33 +02:00
|
|
|
size_t get_size_typeformatstring(const ifref_list_t *ifaces, type_pred_t pred)
|
2006-03-23 10:33:08 +01:00
|
|
|
{
|
2007-10-09 01:47:28 +02:00
|
|
|
set_all_tfswrite(FALSE);
|
2007-10-16 03:06:33 +02:00
|
|
|
return process_tfs(NULL, ifaces, pred);
|
2006-03-23 10:33:08 +01:00
|
|
|
}
|
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
static void write_struct_expr(FILE *h, const expr_t *e, int brackets,
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_list_t *fields, const char *structvar)
|
2006-01-27 12:53:32 +01:00
|
|
|
{
|
|
|
|
switch (e->type) {
|
|
|
|
case EXPR_VOID:
|
|
|
|
break;
|
|
|
|
case EXPR_NUM:
|
2007-02-26 16:06:21 +01:00
|
|
|
fprintf(h, "%lu", e->u.lval);
|
2006-01-27 12:53:32 +01:00
|
|
|
break;
|
|
|
|
case EXPR_HEXNUM:
|
|
|
|
fprintf(h, "0x%lx", e->u.lval);
|
|
|
|
break;
|
2007-07-17 13:09:03 +02:00
|
|
|
case EXPR_DOUBLE:
|
|
|
|
fprintf(h, "%#.15g", e->u.dval);
|
|
|
|
break;
|
2006-07-06 13:56:36 +02:00
|
|
|
case EXPR_TRUEFALSE:
|
|
|
|
if (e->u.lval == 0)
|
|
|
|
fprintf(h, "FALSE");
|
|
|
|
else
|
|
|
|
fprintf(h, "TRUE");
|
|
|
|
break;
|
2006-01-27 12:53:32 +01:00
|
|
|
case EXPR_IDENTIFIER:
|
|
|
|
{
|
|
|
|
const var_t *field;
|
2007-01-22 14:26:12 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
|
2006-01-27 12:53:32 +01:00
|
|
|
if (!strcmp(e->u.sval, field->name))
|
|
|
|
{
|
|
|
|
fprintf(h, "%s->%s", structvar, e->u.sval);
|
|
|
|
break;
|
|
|
|
}
|
2007-01-22 14:26:12 +01:00
|
|
|
|
|
|
|
if (&field->entry == fields) error("no field found for identifier %s\n", e->u.sval);
|
2006-01-27 12:53:32 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EXPR_NEG:
|
|
|
|
fprintf(h, "-");
|
|
|
|
write_struct_expr(h, e->ref, 1, fields, structvar);
|
|
|
|
break;
|
|
|
|
case EXPR_NOT:
|
|
|
|
fprintf(h, "~");
|
|
|
|
write_struct_expr(h, e->ref, 1, fields, structvar);
|
|
|
|
break;
|
|
|
|
case EXPR_PPTR:
|
|
|
|
fprintf(h, "*");
|
|
|
|
write_struct_expr(h, e->ref, 1, fields, structvar);
|
|
|
|
break;
|
|
|
|
case EXPR_CAST:
|
|
|
|
fprintf(h, "(");
|
2007-10-03 06:39:38 +02:00
|
|
|
write_type_decl(h, e->u.tref, NULL);
|
2006-01-27 12:53:32 +01:00
|
|
|
fprintf(h, ")");
|
|
|
|
write_struct_expr(h, e->ref, 1, fields, structvar);
|
|
|
|
break;
|
|
|
|
case EXPR_SIZEOF:
|
|
|
|
fprintf(h, "sizeof(");
|
2007-10-03 06:39:38 +02:00
|
|
|
write_type_decl(h, e->u.tref, NULL);
|
2006-01-27 12:53:32 +01:00
|
|
|
fprintf(h, ")");
|
|
|
|
break;
|
|
|
|
case EXPR_SHL:
|
|
|
|
case EXPR_SHR:
|
|
|
|
case EXPR_MUL:
|
|
|
|
case EXPR_DIV:
|
|
|
|
case EXPR_ADD:
|
|
|
|
case EXPR_SUB:
|
|
|
|
case EXPR_AND:
|
|
|
|
case EXPR_OR:
|
|
|
|
if (brackets) fprintf(h, "(");
|
|
|
|
write_struct_expr(h, e->ref, 1, fields, structvar);
|
|
|
|
switch (e->type) {
|
|
|
|
case EXPR_SHL: fprintf(h, " << "); break;
|
|
|
|
case EXPR_SHR: fprintf(h, " >> "); break;
|
|
|
|
case EXPR_MUL: fprintf(h, " * "); break;
|
|
|
|
case EXPR_DIV: fprintf(h, " / "); break;
|
|
|
|
case EXPR_ADD: fprintf(h, " + "); break;
|
|
|
|
case EXPR_SUB: fprintf(h, " - "); break;
|
|
|
|
case EXPR_AND: fprintf(h, " & "); break;
|
|
|
|
case EXPR_OR: fprintf(h, " | "); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
write_struct_expr(h, e->u.ext, 1, fields, structvar);
|
|
|
|
if (brackets) fprintf(h, ")");
|
|
|
|
break;
|
|
|
|
case EXPR_COND:
|
|
|
|
if (brackets) fprintf(h, "(");
|
|
|
|
write_struct_expr(h, e->ref, 1, fields, structvar);
|
|
|
|
fprintf(h, " ? ");
|
|
|
|
write_struct_expr(h, e->u.ext, 1, fields, structvar);
|
|
|
|
fprintf(h, " : ");
|
|
|
|
write_struct_expr(h, e->ext2, 1, fields, structvar);
|
|
|
|
if (brackets) fprintf(h, ")");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-24 19:59:16 +01:00
|
|
|
|
|
|
|
void declare_stub_args( FILE *file, int indent, const func_t *func )
|
|
|
|
{
|
|
|
|
int in_attr, out_attr;
|
|
|
|
int i = 0;
|
|
|
|
const var_t *def = func->def;
|
|
|
|
const var_t *var;
|
|
|
|
|
|
|
|
/* declare return value '_RetVal' */
|
2007-05-10 05:50:49 +02:00
|
|
|
if (!is_void(def->type))
|
2007-01-24 19:59:16 +01:00
|
|
|
{
|
|
|
|
print_file(file, indent, "");
|
2007-10-03 06:39:38 +02:00
|
|
|
write_type_decl_left(file, def->type);
|
2007-01-24 19:59:16 +01:00
|
|
|
fprintf(file, " _RetVal;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
|
|
|
{
|
|
|
|
int is_string = is_attr(var->attrs, ATTR_STRING);
|
|
|
|
|
|
|
|
in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
if (!out_attr && !in_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
if (is_context_handle(var->type))
|
|
|
|
print_file(file, indent, "NDR_SCONTEXT %s;\n", var->name);
|
|
|
|
else
|
2007-01-24 19:59:16 +01:00
|
|
|
{
|
2007-09-28 02:38:27 +02:00
|
|
|
if (!in_attr && !var->type->size_is && !is_string)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "");
|
2007-10-03 06:39:38 +02:00
|
|
|
write_type_decl(file, var->type->ref, "_W%u", i++);
|
2007-09-28 02:38:27 +02:00
|
|
|
fprintf(file, ";\n");
|
|
|
|
}
|
|
|
|
|
2007-01-24 19:59:16 +01:00
|
|
|
print_file(file, indent, "");
|
2007-10-03 06:39:38 +02:00
|
|
|
write_type_decl_left(file, var->type);
|
2007-09-28 02:38:27 +02:00
|
|
|
fprintf(file, " ");
|
|
|
|
if (var->type->declarray) {
|
|
|
|
fprintf(file, "( *");
|
|
|
|
write_name(file, var);
|
|
|
|
fprintf(file, " )");
|
|
|
|
} else
|
|
|
|
write_name(file, var);
|
|
|
|
write_type_right(file, var->type, FALSE);
|
2007-06-06 03:50:31 +02:00
|
|
|
fprintf(file, ";\n");
|
2007-01-24 19:59:16 +01:00
|
|
|
|
2007-09-28 02:38:27 +02:00
|
|
|
if (decl_indirect(var->type))
|
|
|
|
print_file(file, indent, "void *_p_%s = &%s;\n",
|
|
|
|
var->name, var->name);
|
|
|
|
}
|
2007-01-24 19:59:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void assign_stub_out_args( FILE *file, int indent, const func_t *func )
|
|
|
|
{
|
|
|
|
int in_attr, out_attr;
|
|
|
|
int i = 0, sep = 0;
|
|
|
|
const var_t *var;
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
|
|
|
{
|
|
|
|
int is_string = is_attr(var->attrs, ATTR_STRING);
|
|
|
|
in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
out_attr = is_attr(var->attrs, ATTR_OUT);
|
|
|
|
if (!out_attr && !in_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
|
|
|
if (!in_attr)
|
|
|
|
{
|
|
|
|
print_file(file, indent, "");
|
|
|
|
write_name(file, var);
|
|
|
|
|
2007-06-06 03:50:31 +02:00
|
|
|
if (var->type->size_is)
|
2007-01-24 19:59:16 +01:00
|
|
|
{
|
2007-02-06 15:54:58 +01:00
|
|
|
unsigned int size, align = 0;
|
2007-01-24 19:59:16 +01:00
|
|
|
type_t *type = var->type;
|
|
|
|
|
|
|
|
fprintf(file, " = NdrAllocate(&_StubMsg, ");
|
2007-06-06 03:50:31 +02:00
|
|
|
for ( ; type->size_is ; type = type->ref)
|
2007-02-06 15:59:24 +01:00
|
|
|
{
|
2007-06-06 03:50:31 +02:00
|
|
|
write_expr(file, type->size_is, TRUE);
|
2007-02-06 15:59:24 +01:00
|
|
|
fprintf(file, " * ");
|
|
|
|
}
|
2007-06-06 03:50:31 +02:00
|
|
|
size = type_memsize(type, &align);
|
2007-02-06 15:59:24 +01:00
|
|
|
fprintf(file, "%u);\n", size);
|
2007-01-24 19:59:16 +01:00
|
|
|
}
|
|
|
|
else if (!is_string)
|
|
|
|
{
|
|
|
|
fprintf(file, " = &_W%u;\n", i);
|
2007-05-10 05:50:49 +02:00
|
|
|
if (is_ptr(var->type) && !last_ptr(var->type))
|
2007-01-24 19:59:16 +01:00
|
|
|
print_file(file, indent, "_W%u = 0;\n", i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sep = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sep)
|
|
|
|
fprintf(file, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
int write_expr_eval_routines(FILE *file, const char *iface)
|
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
static const char *var_name = "pS";
|
2006-01-27 12:53:32 +01:00
|
|
|
int result = 0;
|
|
|
|
struct expr_eval_routine *eval;
|
|
|
|
unsigned short callback_offset = 0;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(eval, &expr_eval_routines, struct expr_eval_routine, entry)
|
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
const char *name = eval->structure->name;
|
|
|
|
const var_list_t *fields = eval->structure->fields;
|
2006-01-27 12:53:32 +01:00
|
|
|
result = 1;
|
2007-09-04 18:33:23 +02:00
|
|
|
|
|
|
|
print_file(file, 0, "static void __RPC_USER %s_%sExprEval_%04u(PMIDL_STUB_MESSAGE pStubMsg)\n",
|
|
|
|
iface, name, callback_offset);
|
|
|
|
print_file(file, 0, "{\n");
|
|
|
|
print_file (file, 1, "%s *%s = (%s *)(pStubMsg->StackTop - %u);\n",
|
2007-10-11 00:29:54 +02:00
|
|
|
name, var_name, name, eval->baseoff);
|
2007-09-04 18:33:23 +02:00
|
|
|
print_file(file, 1, "pStubMsg->Offset = 0;\n"); /* FIXME */
|
|
|
|
print_file(file, 1, "pStubMsg->MaxCount = (unsigned long)");
|
|
|
|
write_struct_expr(file, eval->expr, 1, fields, var_name);
|
2006-01-27 12:53:32 +01:00
|
|
|
fprintf(file, ";\n");
|
2007-09-04 18:33:23 +02:00
|
|
|
print_file(file, 0, "}\n\n");
|
2006-01-27 12:53:32 +01:00
|
|
|
callback_offset++;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_expr_eval_routine_list(FILE *file, const char *iface)
|
|
|
|
{
|
|
|
|
struct expr_eval_routine *eval;
|
|
|
|
struct expr_eval_routine *cursor;
|
|
|
|
unsigned short callback_offset = 0;
|
|
|
|
|
|
|
|
fprintf(file, "static const EXPR_EVAL ExprEvalRoutines[] =\n");
|
|
|
|
fprintf(file, "{\n");
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(eval, cursor, &expr_eval_routines, struct expr_eval_routine, entry)
|
|
|
|
{
|
2007-09-04 18:33:23 +02:00
|
|
|
const char *name = eval->structure->name;
|
|
|
|
print_file(file, 1, "%s_%sExprEval_%04u,\n", iface, name, callback_offset);
|
2006-01-27 12:53:32 +01:00
|
|
|
callback_offset++;
|
|
|
|
list_remove(&eval->entry);
|
|
|
|
free(eval);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(file, "};\n\n");
|
|
|
|
}
|
2007-02-07 17:55:09 +01:00
|
|
|
|
2007-06-14 01:13:04 +02:00
|
|
|
void write_user_quad_list(FILE *file)
|
|
|
|
{
|
|
|
|
user_type_t *ut;
|
|
|
|
|
|
|
|
if (list_empty(&user_type_list))
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(file, "static const USER_MARSHAL_ROUTINE_QUADRUPLE UserMarshalRoutines[] =\n");
|
|
|
|
fprintf(file, "{\n");
|
|
|
|
LIST_FOR_EACH_ENTRY(ut, &user_type_list, user_type_t, entry)
|
|
|
|
{
|
|
|
|
const char *sep = &ut->entry == list_tail(&user_type_list) ? "" : ",";
|
|
|
|
print_file(file, 1, "{\n");
|
2007-06-14 12:10:45 +02:00
|
|
|
print_file(file, 2, "(USER_MARSHAL_SIZING_ROUTINE)%s_UserSize,\n", ut->name);
|
|
|
|
print_file(file, 2, "(USER_MARSHAL_MARSHALLING_ROUTINE)%s_UserMarshal,\n", ut->name);
|
|
|
|
print_file(file, 2, "(USER_MARSHAL_UNMARSHALLING_ROUTINE)%s_UserUnmarshal,\n", ut->name);
|
|
|
|
print_file(file, 2, "(USER_MARSHAL_FREEING_ROUTINE)%s_UserFree\n", ut->name);
|
2007-06-14 01:13:04 +02:00
|
|
|
print_file(file, 1, "}%s\n", sep);
|
|
|
|
}
|
|
|
|
fprintf(file, "};\n\n");
|
|
|
|
}
|
2007-02-07 17:55:09 +01:00
|
|
|
|
|
|
|
void write_endpoints( FILE *f, const char *prefix, const str_list_t *list )
|
|
|
|
{
|
|
|
|
const struct str_list_entry_t *endpoint;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
/* this should be an array of RPC_PROTSEQ_ENDPOINT but we want const strings */
|
|
|
|
print_file( f, 0, "static const unsigned char * %s__RpcProtseqEndpoint[][2] =\n{\n", prefix );
|
|
|
|
LIST_FOR_EACH_ENTRY( endpoint, list, const struct str_list_entry_t, entry )
|
|
|
|
{
|
|
|
|
print_file( f, 1, "{ (const unsigned char *)\"" );
|
|
|
|
for (p = endpoint->str; *p && *p != ':'; p++)
|
|
|
|
{
|
|
|
|
if (*p == '"' || *p == '\\') fputc( '\\', f );
|
|
|
|
fputc( *p, f );
|
|
|
|
}
|
|
|
|
if (!*p) goto error;
|
|
|
|
if (p[1] != '[') goto error;
|
|
|
|
|
|
|
|
fprintf( f, "\", (const unsigned char *)\"" );
|
|
|
|
for (p += 2; *p && *p != ']'; p++)
|
|
|
|
{
|
|
|
|
if (*p == '"' || *p == '\\') fputc( '\\', f );
|
|
|
|
fputc( *p, f );
|
|
|
|
}
|
|
|
|
if (*p != ']') goto error;
|
|
|
|
fprintf( f, "\" },\n" );
|
|
|
|
}
|
|
|
|
print_file( f, 0, "};\n\n" );
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
error("Invalid endpoint syntax '%s'\n", endpoint->str);
|
|
|
|
}
|