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;
|
|
|
|
|
|
|
|
/* name of the structure variable for structure callbacks */
|
|
|
|
#define STRUCT_EXPR_EVAL_VAR "pS"
|
|
|
|
|
|
|
|
static struct list expr_eval_routines = LIST_INIT(expr_eval_routines);
|
|
|
|
|
|
|
|
struct expr_eval_routine
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
const type_t *structure;
|
|
|
|
size_t structure_size;
|
|
|
|
const expr_t *expr;
|
|
|
|
};
|
2006-01-24 11:12:54 +01:00
|
|
|
|
2007-02-06 15:54:58 +01:00
|
|
|
static size_t type_memsize(const type_t *t, int ptr_level, const array_dims_t *array, unsigned int *align);
|
|
|
|
static size_t fields_memsize(const var_list_t *fields, unsigned int *align);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
case EXPR_NOT:
|
|
|
|
case EXPR_NEG:
|
|
|
|
case EXPR_PPTR:
|
|
|
|
case EXPR_CAST:
|
|
|
|
case EXPR_SIZEOF:
|
|
|
|
return compare_expr(a->ref, b->ref);
|
|
|
|
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)
|
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
static int print_file(FILE *file, int indent, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
int i, r;
|
|
|
|
|
2005-12-26 13:05:29 +01:00
|
|
|
if (!file) return 0;
|
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
va_start(va, format);
|
|
|
|
for (i = 0; i < indent; i++)
|
|
|
|
fprintf(file, " ");
|
|
|
|
r = vfprintf(file, format, va);
|
|
|
|
va_end(va);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
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-01-22 14:21:56 +01:00
|
|
|
void write_formatstringsdecl(FILE *f, int indent, ifref_list_t *ifaces, int for_objects)
|
2006-08-17 03:01:56 +02:00
|
|
|
{
|
|
|
|
print_file(f, indent, "#define TYPE_FORMAT_STRING_SIZE %d\n",
|
2006-08-18 03:08:38 +02:00
|
|
|
get_size_typeformatstring(ifaces, for_objects));
|
2006-08-17 03:01:56 +02:00
|
|
|
|
|
|
|
print_file(f, indent, "#define PROC_FORMAT_STRING_SIZE %d\n",
|
2006-08-18 03:08:38 +02:00
|
|
|
get_size_procformatstring(ifaces, for_objects));
|
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");
|
|
|
|
}
|
|
|
|
|
2007-01-26 11:59:58 +01:00
|
|
|
static int is_user_derived(const var_t *v)
|
|
|
|
{
|
|
|
|
const type_t *type = v->type;
|
|
|
|
|
|
|
|
if (v->attrs && is_attr( v->attrs, ATTR_WIREMARSHAL )) return 1;
|
|
|
|
|
|
|
|
while (type)
|
|
|
|
{
|
|
|
|
if (type->attrs && is_attr( type->attrs, ATTR_WIREMARSHAL )) return 1;
|
|
|
|
type = type->ref;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-24 11:05:51 +01:00
|
|
|
static size_t write_procformatstring_var(FILE *file, int indent,
|
|
|
|
const var_t *var, int is_return, unsigned int *type_offset)
|
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
|
|
|
int ptr_level = var->ptr_level;
|
|
|
|
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
|
|
|
|
2006-01-24 11:05:51 +01:00
|
|
|
if (ptr_level == 0 && !var->array && 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");
|
|
|
|
|
2005-12-26 13:22:32 +01:00
|
|
|
switch(type->type)
|
2005-12-26 13:05:55 +01:00
|
|
|
{
|
2005-12-08 12:53:58 +01:00
|
|
|
#define CASE_BASETYPE(fctype) \
|
2005-12-26 13:05:55 +01:00
|
|
|
case RPC_##fctype: \
|
2005-12-26 13:22:32 +01:00
|
|
|
print_file(file, indent, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
|
2005-12-26 13:05:55 +01:00
|
|
|
size = 2; /* includes param type prefix */ \
|
|
|
|
break
|
|
|
|
|
|
|
|
CASE_BASETYPE(FC_BYTE);
|
|
|
|
CASE_BASETYPE(FC_CHAR);
|
|
|
|
CASE_BASETYPE(FC_WCHAR);
|
|
|
|
CASE_BASETYPE(FC_USHORT);
|
|
|
|
CASE_BASETYPE(FC_SHORT);
|
|
|
|
CASE_BASETYPE(FC_ULONG);
|
|
|
|
CASE_BASETYPE(FC_LONG);
|
|
|
|
CASE_BASETYPE(FC_HYPER);
|
|
|
|
CASE_BASETYPE(FC_IGNORE);
|
|
|
|
CASE_BASETYPE(FC_USMALL);
|
|
|
|
CASE_BASETYPE(FC_SMALL);
|
|
|
|
CASE_BASETYPE(FC_FLOAT);
|
|
|
|
CASE_BASETYPE(FC_DOUBLE);
|
|
|
|
CASE_BASETYPE(FC_ERROR_STATUS_T);
|
2005-12-08 12:53:58 +01:00
|
|
|
#undef CASE_BASETYPE
|
2006-02-07 12:30:55 +01:00
|
|
|
|
|
|
|
case RPC_FC_BIND_PRIMITIVE:
|
|
|
|
print_file(file, indent, "0x%02x, /* FC_IGNORE */\n", RPC_FC_IGNORE);
|
|
|
|
size = 2; /* includes param type prefix */
|
|
|
|
break;
|
|
|
|
|
2005-12-26 13:05:55 +01:00
|
|
|
default:
|
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");
|
|
|
|
print_file(file, indent, "NdrFcShort(0x%x),\n", *type_offset);
|
|
|
|
size = 4; /* includes param type prefix */
|
2005-12-08 12:53:58 +01:00
|
|
|
}
|
2006-01-24 11:05:51 +01:00
|
|
|
*type_offset += get_size_typeformatstring_var(var);
|
2005-12-26 13:05:29 +01:00
|
|
|
return size;
|
2005-12-08 12:53:58 +01:00
|
|
|
}
|
|
|
|
|
2007-01-22 14:21:56 +01:00
|
|
|
void write_procformatstring(FILE *file, const ifref_list_t *ifaces, int for_objects)
|
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-26 13:05:55 +01:00
|
|
|
unsigned int type_offset = 2;
|
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
|
|
|
{
|
2006-08-18 03:08:38 +02:00
|
|
|
if (for_objects != is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
|
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 )
|
|
|
|
write_procformatstring_var(file, indent, var, FALSE, &type_offset);
|
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;
|
|
|
|
if (is_void(var->type, NULL))
|
|
|
|
{
|
|
|
|
print_file(file, indent, "0x5b, /* FC_END */\n");
|
|
|
|
print_file(file, indent, "0x5c, /* FC_PAD */\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
write_procformatstring_var(file, indent, var, TRUE,
|
|
|
|
&type_offset);
|
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)
|
|
|
|
{
|
|
|
|
switch (type->type)
|
|
|
|
{
|
|
|
|
#define CASE_BASETYPE(fctype) \
|
|
|
|
case RPC_##fctype: \
|
|
|
|
print_file(file, 2, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
|
|
|
|
*typestring_offset += 1; \
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
CASE_BASETYPE(FC_BYTE);
|
|
|
|
CASE_BASETYPE(FC_CHAR);
|
|
|
|
CASE_BASETYPE(FC_SMALL);
|
|
|
|
CASE_BASETYPE(FC_USMALL);
|
|
|
|
CASE_BASETYPE(FC_WCHAR);
|
|
|
|
CASE_BASETYPE(FC_SHORT);
|
|
|
|
CASE_BASETYPE(FC_USHORT);
|
|
|
|
CASE_BASETYPE(FC_LONG);
|
|
|
|
CASE_BASETYPE(FC_ULONG);
|
|
|
|
CASE_BASETYPE(FC_FLOAT);
|
|
|
|
CASE_BASETYPE(FC_HYPER);
|
|
|
|
CASE_BASETYPE(FC_DOUBLE);
|
|
|
|
CASE_BASETYPE(FC_ENUM16);
|
|
|
|
CASE_BASETYPE(FC_ENUM32);
|
|
|
|
CASE_BASETYPE(FC_IGNORE);
|
|
|
|
CASE_BASETYPE(FC_ERROR_STATUS_T);
|
|
|
|
#undef CASE_BASETYPE
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-24 11:08:20 +01:00
|
|
|
/* write conformance / variance descriptor */
|
2007-02-06 15:59:24 +01:00
|
|
|
static size_t write_conf_or_var_desc(FILE *file, const func_t *func, const type_t *structure, const expr_list_t *expr_list)
|
2006-01-24 11:08:20 +01:00
|
|
|
{
|
2006-01-24 11:09:03 +01:00
|
|
|
unsigned char operator_type = 0;
|
|
|
|
const char *operator_string = "no operators";
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_t *expr, *subexpr;
|
2006-01-27 12:53:32 +01:00
|
|
|
unsigned char correlation_type;
|
2006-01-24 11:09:03 +01:00
|
|
|
|
2006-01-24 11:08:20 +01:00
|
|
|
if (!file) return 4; /* optimisation for sizing pass */
|
|
|
|
|
2007-02-06 15:59:24 +01:00
|
|
|
if (list_count(expr_list) > 1)
|
|
|
|
error("write_conf_or_var_desc: multi-dimensional arrays not supported yet\n");
|
|
|
|
|
|
|
|
expr = subexpr = LIST_ENTRY( list_head(expr_list), const expr_t, entry );
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
const char *param_type_string = NULL;
|
|
|
|
size_t offset;
|
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
if (structure)
|
2006-01-24 11:12:54 +01:00
|
|
|
{
|
|
|
|
const var_t *var;
|
|
|
|
|
2007-01-22 14:26:12 +01:00
|
|
|
offset = 0;
|
|
|
|
if (structure->fields) LIST_FOR_EACH_ENTRY( var, structure->fields, const var_t, entry )
|
2006-01-24 11:12:54 +01:00
|
|
|
{
|
2007-02-06 15:54:58 +01:00
|
|
|
unsigned int align = 0;
|
|
|
|
offset -= type_memsize(var->type, var->ptr_level, var->array, &align);
|
|
|
|
/* FIXME: take alignment into account */
|
2006-01-24 11:12:54 +01:00
|
|
|
if (!strcmp(var->name, subexpr->u.sval))
|
|
|
|
{
|
|
|
|
correlation_variable = var->type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!correlation_variable)
|
|
|
|
error("write_conf_or_var_desc: couldn't find variable %s in structure\n",
|
|
|
|
subexpr->u.sval);
|
|
|
|
|
|
|
|
correlation_type = RPC_FC_NORMAL_CONFORMANCE;
|
|
|
|
}
|
|
|
|
else
|
2006-01-24 11:08:20 +01:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *var;
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
offset = sizeof(void *);
|
2007-01-22 14:26:12 +01:00
|
|
|
if (func->args) LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
2006-01-24 11:08:20 +01:00
|
|
|
{
|
2006-01-24 11:09:03 +01:00
|
|
|
if (!strcmp(var->name, subexpr->u.sval))
|
2006-01-24 11:08:20 +01:00
|
|
|
{
|
2006-01-24 11:12:54 +01:00
|
|
|
correlation_variable = var->type;
|
2006-01-24 11:08:20 +01:00
|
|
|
break;
|
|
|
|
}
|
2007-01-22 14:26:12 +01:00
|
|
|
/* FIXME: not all stack variables are sizeof(void *) */
|
|
|
|
offset += sizeof(void *);
|
2006-01-24 11:08:20 +01:00
|
|
|
}
|
2006-01-24 11:12:54 +01:00
|
|
|
if (!correlation_variable)
|
|
|
|
error("write_conf_or_var_desc: couldn't find variable %s in function\n",
|
2006-01-24 11:09:03 +01:00
|
|
|
subexpr->u.sval);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2006-01-24 11:12:54 +01:00
|
|
|
correlation_type = RPC_FC_TOP_LEVEL_CONFORMANCE;
|
|
|
|
}
|
2006-01-24 11:08:20 +01:00
|
|
|
|
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;
|
|
|
|
param_type_string = "FC_SMALL";
|
|
|
|
break;
|
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_USMALL:
|
|
|
|
param_type = RPC_FC_USMALL;
|
|
|
|
param_type_string = "FC_USMALL";
|
|
|
|
break;
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_SHORT:
|
|
|
|
param_type = RPC_FC_SHORT;
|
|
|
|
param_type_string = "FC_SHORT";
|
|
|
|
break;
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
param_type = RPC_FC_USHORT;
|
|
|
|
param_type_string = "FC_USHORT";
|
|
|
|
break;
|
|
|
|
case RPC_FC_LONG:
|
|
|
|
param_type = RPC_FC_LONG;
|
|
|
|
param_type_string = "FC_LONG";
|
|
|
|
break;
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
param_type = RPC_FC_ULONG;
|
|
|
|
param_type_string = "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;
|
|
|
|
param_type_string = "FC_LONG";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
param_type = RPC_FC_HYPER;
|
|
|
|
param_type_string = "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
|
|
|
|
|
|
|
print_file(file, 2, "0x%x, /* Corr desc: %s%s */\n",
|
|
|
|
correlation_type | param_type,
|
|
|
|
correlation_type == RPC_FC_TOP_LEVEL_CONFORMANCE ? "parameter, " : "",
|
|
|
|
param_type_string);
|
|
|
|
print_file(file, 2, "0x%x, /* %s */\n", operator_type, operator_string);
|
2006-03-31 13:44:39 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %soffset = %d */\n",
|
2006-01-24 11:12:54 +01:00
|
|
|
offset,
|
|
|
|
correlation_type == RPC_FC_TOP_LEVEL_CONFORMANCE ? "x86 stack size / " : "",
|
|
|
|
offset);
|
2006-01-24 11:08:20 +01:00
|
|
|
}
|
|
|
|
else
|
2006-01-27 12:53:32 +01:00
|
|
|
{
|
|
|
|
unsigned int callback_offset = 0;
|
|
|
|
|
|
|
|
if (structure)
|
|
|
|
{
|
2006-01-31 12:24:11 +01:00
|
|
|
struct expr_eval_routine *eval;
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(eval, &expr_eval_routines, struct expr_eval_routine, entry)
|
|
|
|
{
|
|
|
|
if (!strcmp(eval->structure->name, structure->name) &&
|
|
|
|
!compare_expr(eval->expr, expr))
|
|
|
|
{
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
callback_offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
2007-02-06 15:54:58 +01:00
|
|
|
unsigned int align = 0;
|
2006-01-31 12:24:11 +01:00
|
|
|
eval = xmalloc(sizeof(*eval));
|
|
|
|
eval->structure = structure;
|
2007-02-06 15:54:58 +01:00
|
|
|
eval->structure_size = fields_memsize(structure->fields, &align);
|
2006-01-31 12:24:11 +01:00
|
|
|
eval->expr = expr;
|
|
|
|
list_add_tail(&expr_eval_routines, &eval->entry);
|
|
|
|
}
|
2006-01-27 12:53:32 +01:00
|
|
|
|
|
|
|
correlation_type = RPC_FC_NORMAL_CONFORMANCE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-31 18:05:43 +01:00
|
|
|
error("write_conf_or_var_desc: top-level callback conformance unimplemented\n");
|
2006-01-27 12:53:32 +01:00
|
|
|
correlation_type = RPC_FC_TOP_LEVEL_CONFORMANCE;
|
|
|
|
}
|
|
|
|
|
2006-01-31 12:24:11 +01:00
|
|
|
if (callback_offset > USHRT_MAX)
|
|
|
|
error("Maximum number of callback routines reached\n");
|
|
|
|
|
2006-01-27 12:53:32 +01:00
|
|
|
print_file(file, 2, "0x%x, /* Corr desc: %s */\n",
|
|
|
|
correlation_type,
|
|
|
|
correlation_type == RPC_FC_TOP_LEVEL_CONFORMANCE ? "parameter" : "");
|
|
|
|
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
|
|
|
{
|
|
|
|
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-02-06 15:54:58 +01:00
|
|
|
size += type_memsize(v->type, v->ptr_level, v->array, align);
|
2007-01-22 14:26:12 +01:00
|
|
|
|
2006-01-24 11:07:13 +01:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2007-02-06 15:54:58 +01:00
|
|
|
static size_t get_array_size( const array_dims_t *array )
|
|
|
|
{
|
|
|
|
size_t size = 1;
|
|
|
|
const expr_t *dim;
|
|
|
|
|
|
|
|
if (!array) return 0;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( dim, array, expr_t, entry )
|
|
|
|
{
|
|
|
|
if (!dim->is_const) return 0;
|
|
|
|
size *= dim->cval;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t type_memsize(const type_t *t, int ptr_level, const array_dims_t *array, unsigned int *align)
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
|
|
|
size_t size = 0;
|
|
|
|
|
|
|
|
if (ptr_level)
|
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:
|
|
|
|
case RPC_FC_ENCAPSULATED_UNION:
|
|
|
|
case RPC_FC_NON_ENCAPSULATED_UNION:
|
2007-02-06 15:54:58 +01:00
|
|
|
size = fields_memsize(t->fields, align);
|
2006-01-24 11:07:13 +01:00
|
|
|
break;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-02-06 15:54:58 +01:00
|
|
|
if (array) size *= get_array_size( array );
|
2006-01-24 11:07:13 +01:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
static int write_pointers(FILE *file, const attr_list_t *attrs,
|
2006-02-03 18:51:17 +01:00
|
|
|
const type_t *type, int ptr_level,
|
2007-01-22 14:31:40 +01:00
|
|
|
const array_dims_t *array, int level,
|
2006-06-13 14:13:49 +02:00
|
|
|
unsigned int *typestring_offset)
|
2006-02-03 18:51:17 +01:00
|
|
|
{
|
|
|
|
int pointers_written = 0;
|
|
|
|
const var_t *v;
|
|
|
|
|
|
|
|
/* don't generate a pointer for first-level arrays since we want to
|
|
|
|
* descend into them to write their pointers, not stop here */
|
|
|
|
if ((level == 0 || ptr_level == 0) && is_array_type(attrs, ptr_level, array))
|
|
|
|
{
|
|
|
|
return write_pointers(file, NULL, type, 0, NULL, level + 1, typestring_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr_level != 0)
|
|
|
|
{
|
|
|
|
/* FIXME: only general algorithm implemented, not the actual writing */
|
|
|
|
error("write_pointers: Writing type format string for pointer is unimplemented\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type->type)
|
|
|
|
{
|
|
|
|
/* note: don't descend into complex structures or unions since these
|
|
|
|
* will always be generated as a separate type */
|
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_PSTRUCT:
|
2007-01-22 14:26:12 +01:00
|
|
|
if (!type->fields) break;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
|
2006-02-03 18:51:17 +01:00
|
|
|
pointers_written += write_pointers(file, v->attrs, v->type,
|
|
|
|
v->ptr_level, v->array,
|
|
|
|
level + 1,
|
|
|
|
typestring_offset);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pointers_written;
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
static size_t write_pointer_description(FILE *file, const attr_list_t *attrs,
|
2006-02-03 18:51:17 +01:00
|
|
|
const type_t *type, int ptr_level,
|
2007-01-22 14:31:40 +01:00
|
|
|
const array_dims_t *array, int level,
|
2006-02-03 18:51:17 +01:00
|
|
|
size_t typestring_offset)
|
|
|
|
{
|
|
|
|
size_t size = 0;
|
|
|
|
const var_t *v;
|
|
|
|
|
|
|
|
/* don't generate a pointer for first-level arrays since we want to
|
|
|
|
* descend into them to write their pointers, not stop here */
|
|
|
|
if ((level == 0 || ptr_level == 0) && is_array_type(attrs, ptr_level, array))
|
|
|
|
{
|
|
|
|
return write_pointer_description(file, NULL, type, 0, NULL,
|
|
|
|
level + 1, typestring_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr_level != 0)
|
|
|
|
{
|
|
|
|
/* FIXME: only general algorithm implemented, not the actual writing */
|
|
|
|
error("write_pointer_description: Writing pointer description is unimplemented\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: search through all refs for pointers too */
|
|
|
|
|
|
|
|
switch (type->type)
|
|
|
|
{
|
|
|
|
/* note: don't descend into complex structures or unions since these
|
|
|
|
* will always be generated as a separate type */
|
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_PSTRUCT:
|
2007-01-22 14:26:12 +01:00
|
|
|
if (!type->fields) break;
|
|
|
|
LIST_FOR_EACH_ENTRY( v, type->fields, const var_t, entry )
|
2006-02-03 18:51:17 +01:00
|
|
|
size += write_pointer_description(file, v->attrs, v->type,
|
|
|
|
v->ptr_level, v->array,
|
|
|
|
level + 1,
|
|
|
|
typestring_offset);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
static size_t write_string_tfs(FILE *file, const attr_list_t *attrs,
|
2007-01-22 14:31:40 +01:00
|
|
|
const type_t *type, const array_dims_t *array,
|
2006-06-13 14:13:49 +02:00
|
|
|
const char *name, unsigned int *typestring_offset)
|
2006-01-24 11:06:32 +01:00
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_list_t *size_is = get_attrp(attrs, ATTR_SIZEIS);
|
|
|
|
int has_size = is_non_void(size_is);
|
2006-01-31 18:07:20 +01:00
|
|
|
size_t start_offset = *typestring_offset;
|
2006-03-29 12:42:29 +02:00
|
|
|
unsigned char flags = 0;
|
2006-09-08 01:57:16 +02:00
|
|
|
int pointer_type;
|
2006-08-09 23:20:35 +02:00
|
|
|
unsigned char rtype;
|
|
|
|
|
2006-09-08 01:57:16 +02:00
|
|
|
if (is_ptr(type))
|
|
|
|
{
|
|
|
|
pointer_type = type->type;
|
|
|
|
type = type->ref;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pointer_type = get_attrv(attrs, ATTR_POINTERTYPE);
|
|
|
|
|
2006-03-29 12:42:29 +02:00
|
|
|
if (!pointer_type)
|
|
|
|
pointer_type = RPC_FC_RP;
|
|
|
|
|
|
|
|
if (!get_attrp(attrs, ATTR_SIZEIS))
|
|
|
|
flags |= RPC_FC_P_SIMPLEPOINTER;
|
2006-01-24 11:07:39 +01:00
|
|
|
|
2006-08-30 02:19:21 +02:00
|
|
|
rtype = type->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
|
|
|
}
|
|
|
|
|
2006-03-29 12:42:29 +02:00
|
|
|
print_file(file, 2,"0x%x, 0x%x, /* %s%s */\n",
|
|
|
|
pointer_type, flags,
|
|
|
|
pointer_type == RPC_FC_FP ? "FC_FP" : (pointer_type == RPC_FC_UP ? "FC_UP" : "FC_RP"),
|
|
|
|
(flags & RPC_FC_P_SIMPLEPOINTER) ? " [simple_pointer]" : "");
|
|
|
|
*typestring_offset += 2;
|
|
|
|
|
|
|
|
if (!(flags & RPC_FC_P_SIMPLEPOINTER))
|
|
|
|
{
|
2006-04-22 21:51:06 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x2),\n");
|
2006-03-29 12:42:29 +02:00
|
|
|
*typestring_offset += 2;
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:31:40 +01:00
|
|
|
if (array && !is_conformant_array(array))
|
2006-01-24 11:07:39 +01:00
|
|
|
{
|
2007-01-22 14:31:40 +01:00
|
|
|
/* FIXME: multi-dimensional array */
|
|
|
|
const expr_t *dim = LIST_ENTRY( list_head( array ), expr_t, entry );
|
|
|
|
if (dim->cval > USHRT_MAX)
|
2006-01-24 11:07:39 +01:00
|
|
|
error("array size for parameter %s exceeds %d bytes by %ld bytes\n",
|
2007-01-22 14:31:40 +01:00
|
|
|
name, USHRT_MAX, dim->cval - USHRT_MAX);
|
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-01-22 14:31:40 +01:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %d */\n", dim->cval, dim->cval);
|
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
|
|
|
}
|
|
|
|
else if (has_size)
|
|
|
|
{
|
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
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += write_conf_or_var_desc(file, current_func, NULL, 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
|
|
|
|
{
|
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_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-01-22 14:20:36 +01:00
|
|
|
static size_t write_array_tfs(FILE *file, const attr_list_t *attrs,
|
2007-01-22 14:31:40 +01:00
|
|
|
const type_t *type, const array_dims_t *array,
|
2006-06-13 14:13:49 +02:00
|
|
|
const char *name, unsigned int *typestring_offset)
|
2006-01-24 11:06:32 +01:00
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_list_t *length_is = get_attrp(attrs, ATTR_LENGTHIS);
|
|
|
|
const expr_list_t *size_is = get_attrp(attrs, ATTR_SIZEIS);
|
|
|
|
int has_length = is_non_void(length_is);
|
|
|
|
int has_size = is_non_void(size_is) || is_conformant_array(array);
|
2006-02-03 18:51:17 +01:00
|
|
|
size_t start_offset;
|
2006-04-05 00:07:03 +02:00
|
|
|
int pointer_type = get_attrv(attrs, ATTR_POINTERTYPE);
|
|
|
|
if (!pointer_type)
|
|
|
|
pointer_type = RPC_FC_RP;
|
|
|
|
|
|
|
|
print_file(file, 2, "0x%x, 0x00, /* %s */\n",
|
|
|
|
pointer_type,
|
|
|
|
pointer_type == RPC_FC_FP ? "FC_FP" : (pointer_type == RPC_FC_UP ? "FC_UP" : "FC_RP"));
|
|
|
|
print_file(file, 2, "NdrFcShort(0x2),\n");
|
|
|
|
*typestring_offset += 4;
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-01-22 14:31:40 +01:00
|
|
|
if (array && list_count(array) > 1) /* multi-dimensional array */
|
2006-01-24 11:07:13 +01:00
|
|
|
{
|
|
|
|
error("write_array_tfs: Multi-dimensional arrays not implemented yet (param %s)\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-24 20:08:06 +01:00
|
|
|
const expr_t *dim = array ? LIST_ENTRY( list_head( array ), expr_t, entry ) : NULL;
|
2006-02-03 18:51:17 +01:00
|
|
|
size_t pointer_start_offset = *typestring_offset;
|
|
|
|
int has_pointer = 0;
|
|
|
|
|
|
|
|
if (write_pointers(file, attrs, type, 0, array, 0, typestring_offset) > 0)
|
|
|
|
has_pointer = 1;
|
|
|
|
|
|
|
|
start_offset = *typestring_offset;
|
|
|
|
|
2006-01-24 11:07:13 +01:00
|
|
|
if (!has_length && !has_size)
|
|
|
|
{
|
|
|
|
/* fixed array */
|
2007-02-06 15:54:58 +01:00
|
|
|
unsigned int align = 0;
|
|
|
|
size_t size = type_memsize(type, 0, array, &align);
|
2006-01-24 11:07:13 +01:00
|
|
|
if (size < USHRT_MAX)
|
|
|
|
{
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_SMFARRAY, *typestring_offset);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* alignment */
|
2007-02-06 15:54:58 +01:00
|
|
|
print_file(file, 2, "0x%02x,\n", align - 1);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* size */
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %d */\n", size, size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 4;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_LGFARRAY, *typestring_offset);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* alignment */
|
2007-02-06 15:54:58 +01:00
|
|
|
print_file(file, 2, "0x%02x,\n", align - 1);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* size */
|
|
|
|
print_file(file, 2, "NdrFcLong(0x%x), /* %d */\n", size, size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 6;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
|
2006-02-03 18:51:17 +01:00
|
|
|
if (has_pointer)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP);
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD);
|
2006-02-07 12:28:33 +01:00
|
|
|
*typestring_offset += 2;
|
|
|
|
*typestring_offset = write_pointer_description(file, attrs,
|
|
|
|
type, 0, array, 0, pointer_start_offset);
|
2006-02-03 18:51:17 +01:00
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
2006-02-07 12:28:33 +01:00
|
|
|
*typestring_offset += 1;
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-02-06 15:55:29 +01:00
|
|
|
if (!write_base_type( file, type, typestring_offset ))
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x0, /* FIXME: write out conversion data */\n");
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
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
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
else if (has_length && !has_size)
|
|
|
|
{
|
|
|
|
/* varying array */
|
2007-02-06 15:54:58 +01:00
|
|
|
unsigned int align = 0;
|
|
|
|
size_t element_size = type_memsize(type, 0, NULL, &align);
|
2007-01-22 14:31:40 +01:00
|
|
|
size_t elements = dim->cval;
|
2006-01-24 11:07:13 +01:00
|
|
|
size_t total_size = element_size * elements;
|
|
|
|
|
|
|
|
if (total_size < USHRT_MAX)
|
|
|
|
{
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_SMVARRAY, *typestring_offset);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* alignment */
|
2007-02-06 15:54:58 +01:00
|
|
|
print_file(file, 2, "0x%02x,\n", align - 1);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* total size */
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %d */\n", total_size, total_size);
|
|
|
|
/* number of elements */
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %d */\n", elements, elements);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 6;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_LGVARRAY, *typestring_offset);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* alignment */
|
2007-02-06 15:54:58 +01:00
|
|
|
print_file(file, 2, "0x%02x,\n", align - 1);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* total size */
|
|
|
|
print_file(file, 2, "NdrFcLong(0x%x), /* %d */\n", total_size, total_size);
|
|
|
|
/* number of elements */
|
|
|
|
print_file(file, 2, "NdrFcLong(0x%x), /* %d */\n", elements, elements);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 10;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
/* element size */
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %d */\n", element_size, element_size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += write_conf_or_var_desc(file, current_func,
|
|
|
|
current_structure,
|
|
|
|
length_is);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2006-02-03 18:51:17 +01:00
|
|
|
if (has_pointer)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP);
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD);
|
2006-02-07 12:28:33 +01:00
|
|
|
*typestring_offset += 2;
|
|
|
|
*typestring_offset += write_pointer_description(file, attrs,
|
|
|
|
type, 0, array, 0, pointer_start_offset);
|
2006-02-03 18:51:17 +01:00
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
2006-02-07 12:28:33 +01:00
|
|
|
*typestring_offset += 1;
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-02-06 15:55:29 +01:00
|
|
|
if (!write_base_type( file, type, typestring_offset ))
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x0, /* FIXME: write out conversion data */\n");
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
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
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
else if (!has_length && has_size)
|
|
|
|
{
|
|
|
|
/* conformant array */
|
2007-02-06 15:54:58 +01:00
|
|
|
unsigned int align = 0;
|
|
|
|
size_t element_size = type_memsize(type, 0, NULL, &align);
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_CARRAY, *typestring_offset);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* alignment */
|
2007-02-06 15:54:58 +01:00
|
|
|
print_file(file, 2, "0x%02x,\n", align - 1);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* element size */
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %d */\n", element_size, element_size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 4;
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += write_conf_or_var_desc(file, current_func,
|
2006-01-31 18:07:45 +01:00
|
|
|
current_structure,
|
2007-02-06 15:59:24 +01:00
|
|
|
size_is ? size_is : array);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2006-02-03 18:51:17 +01:00
|
|
|
if (has_pointer)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP);
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD);
|
2006-02-07 12:28:33 +01:00
|
|
|
*typestring_offset += 2;
|
|
|
|
*typestring_offset += write_pointer_description(file, attrs,
|
|
|
|
type, 0, array, 0, pointer_start_offset);
|
2006-02-03 18:51:17 +01:00
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
2006-02-07 12:28:33 +01:00
|
|
|
*typestring_offset += 1;
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-02-06 15:55:29 +01:00
|
|
|
if (!write_base_type( file, type, typestring_offset ))
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x0, /* FIXME: write out conversion data */\n");
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
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
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* conformant varying array */
|
2007-02-06 15:54:58 +01:00
|
|
|
unsigned int align = 0;
|
|
|
|
size_t element_size = type_memsize(type, 0, NULL, &align);
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
WRITE_FCTYPE(file, FC_CVARRAY, *typestring_offset);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* alignment */
|
2007-02-06 15:54:58 +01:00
|
|
|
print_file(file, 2, "0x%02x,\n", align - 1);
|
2006-01-24 11:07:13 +01:00
|
|
|
/* element size */
|
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %d */\n", element_size, element_size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 4;
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += write_conf_or_var_desc(file, current_func,
|
2006-01-31 18:07:45 +01:00
|
|
|
current_structure,
|
2007-02-06 15:59:24 +01:00
|
|
|
size_is ? size_is : array);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += write_conf_or_var_desc(file, current_func,
|
|
|
|
current_structure,
|
|
|
|
length_is);
|
2006-01-24 11:08:20 +01:00
|
|
|
|
2006-02-03 18:51:17 +01:00
|
|
|
if (has_pointer)
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PP */\n", RPC_FC_PP);
|
|
|
|
print_file(file, 2, "0x%x, /* FC_PAD */\n", RPC_FC_PAD);
|
2006-02-07 12:28:33 +01:00
|
|
|
*typestring_offset += 2;
|
|
|
|
*typestring_offset += write_pointer_description(file, attrs,
|
|
|
|
type, 0, array, 0, pointer_start_offset);
|
2006-02-03 18:51:17 +01:00
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
2006-02-07 12:28:33 +01:00
|
|
|
*typestring_offset += 1;
|
2006-02-03 18:51:17 +01:00
|
|
|
}
|
2006-01-24 11:07:13 +01:00
|
|
|
|
2007-02-06 15:55:29 +01:00
|
|
|
if (!write_base_type( file, type, typestring_offset ))
|
|
|
|
{
|
|
|
|
print_file(file, 2, "0x0, /* FIXME: write out conversion data */\n");
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
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
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:07:13 +01:00
|
|
|
}
|
|
|
|
}
|
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 );
|
|
|
|
|
2006-01-24 11:13:49 +01:00
|
|
|
if (is_array_type(last_field->attrs, last_field->ptr_level, last_field->array))
|
|
|
|
return last_field;
|
|
|
|
|
|
|
|
assert((last_field->type->type == RPC_FC_CSTRUCT) ||
|
|
|
|
(last_field->type->type == RPC_FC_CPSTRUCT) ||
|
|
|
|
(last_field->type->type == RPC_FC_CVSTRUCT));
|
|
|
|
|
2006-01-24 11:14:59 +01:00
|
|
|
return find_array_or_string_in_struct(last_field->type);
|
2006-01-24 11:13:49 +01:00
|
|
|
}
|
|
|
|
|
2007-02-06 15:55:29 +01:00
|
|
|
static void write_struct_members(FILE *file, const type_t *type, unsigned int *typestring_offset)
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *field;
|
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 )
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
2006-08-30 02:19:21 +02:00
|
|
|
unsigned char rtype = field->type->type;
|
2006-08-09 23:20:35 +02:00
|
|
|
|
2007-02-06 15:55:29 +01:00
|
|
|
if (field->array)
|
|
|
|
write_array_tfs( file, field->attrs, field->type, field->array,
|
|
|
|
field->name, typestring_offset );
|
|
|
|
else if (!write_base_type( file, field->type, typestring_offset ))
|
2006-08-09 23:20:35 +02:00
|
|
|
error("Unsupported member type 0x%x\n", rtype);
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
|
|
|
|
2007-02-06 15:55:29 +01:00
|
|
|
if (!(*typestring_offset % 2))
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
|
|
|
print_file(file, 2, "0x%x,\t\t/* FC_PAD */\n", RPC_FC_PAD);
|
2007-02-06 15:55:29 +01:00
|
|
|
*typestring_offset += 1;
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, 2, "0x%x,\t\t/* FC_END */\n", RPC_FC_END);
|
2007-02-06 15:55:29 +01:00
|
|
|
*typestring_offset += 1;
|
2006-04-09 14:38:57 +02:00
|
|
|
}
|
|
|
|
|
2006-01-31 12:24:54 +01:00
|
|
|
static size_t write_struct_tfs(FILE *file, const type_t *type,
|
2006-06-13 14:13:49 +02:00
|
|
|
const char *name, unsigned int *typestring_offset)
|
2006-01-24 11:10:59 +01:00
|
|
|
{
|
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;
|
2006-02-07 12:28:33 +01:00
|
|
|
size_t pointer_offset;
|
2007-02-06 15:54:58 +01:00
|
|
|
unsigned int align = 0;
|
2006-01-24 11:13:49 +01:00
|
|
|
|
2006-01-24 11:11:29 +01:00
|
|
|
switch (type->type)
|
|
|
|
{
|
|
|
|
case RPC_FC_STRUCT:
|
2006-02-07 12:28:33 +01:00
|
|
|
case RPC_FC_PSTRUCT:
|
2007-02-06 15:54:58 +01:00
|
|
|
total_size = type_memsize(type, 0, NULL, &align);
|
2006-01-24 11:11:29 +01:00
|
|
|
|
|
|
|
if (total_size > USHRT_MAX)
|
|
|
|
error("structure size for parameter %s exceeds %d bytes by %d bytes\n",
|
|
|
|
name, USHRT_MAX, total_size - USHRT_MAX);
|
|
|
|
|
2006-02-07 12:28:33 +01:00
|
|
|
if (type->type == RPC_FC_PSTRUCT)
|
|
|
|
{
|
|
|
|
pointer_offset = *typestring_offset;
|
|
|
|
write_pointers(file, NULL, type, 0, NULL, 0, typestring_offset);
|
|
|
|
}
|
|
|
|
else pointer_offset = 0; /* silence warning */
|
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
start_offset = *typestring_offset;
|
2006-02-07 12:30:23 +01:00
|
|
|
if (type->type == RPC_FC_STRUCT)
|
|
|
|
WRITE_FCTYPE(file, FC_STRUCT, *typestring_offset);
|
|
|
|
else
|
|
|
|
WRITE_FCTYPE(file, FC_PSTRUCT, *typestring_offset);
|
2006-01-24 11:11:29 +01:00
|
|
|
/* alignment */
|
2007-02-06 15:54:58 +01:00
|
|
|
print_file(file, 2, "0x%02x,\n", align - 1);
|
2006-01-24 11:11:29 +01:00
|
|
|
/* total size */
|
2006-03-31 13:44:39 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %u */\n", total_size, total_size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 4;
|
2006-01-24 11:11:29 +01:00
|
|
|
|
2006-02-07 12:28:33 +01:00
|
|
|
if (type->type == RPC_FC_PSTRUCT)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
*typestring_offset += write_pointer_description(file, NULL,
|
|
|
|
type, 0, NULL, 0, pointer_offset);
|
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
|
|
|
|
2006-01-24 11:11:29 +01:00
|
|
|
/* member layout */
|
2007-02-06 15:55:29 +01:00
|
|
|
write_struct_members(file, type, typestring_offset);
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:13:49 +01:00
|
|
|
case RPC_FC_CSTRUCT:
|
2006-02-07 12:28:33 +01:00
|
|
|
case RPC_FC_CPSTRUCT:
|
2007-02-06 15:54:58 +01:00
|
|
|
total_size = type_memsize(type, 0, NULL, &align);
|
2006-01-24 11:13:49 +01:00
|
|
|
|
|
|
|
if (total_size > USHRT_MAX)
|
|
|
|
error("structure size for parameter %s exceeds %d bytes by %d bytes\n",
|
|
|
|
name, USHRT_MAX, total_size - USHRT_MAX);
|
|
|
|
|
2006-01-31 18:08:03 +01:00
|
|
|
array = find_array_or_string_in_struct(type);
|
|
|
|
current_structure = type;
|
2006-02-07 12:30:55 +01:00
|
|
|
array_offset = write_array_tfs(file, array->attrs, array->type,
|
2006-01-31 18:08:03 +01:00
|
|
|
array->array, array->name,
|
|
|
|
typestring_offset);
|
|
|
|
current_structure = NULL;
|
|
|
|
|
2006-02-07 12:28:33 +01:00
|
|
|
if (type->type == RPC_FC_CPSTRUCT)
|
|
|
|
{
|
|
|
|
pointer_offset = *typestring_offset;
|
|
|
|
write_pointers(file, NULL, type, 0, NULL, 0, typestring_offset);
|
|
|
|
}
|
|
|
|
else pointer_offset = 0; /* silence warning */
|
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
start_offset = *typestring_offset;
|
2006-02-07 12:30:23 +01:00
|
|
|
if (type->type == RPC_FC_CSTRUCT)
|
|
|
|
WRITE_FCTYPE(file, FC_CSTRUCT, *typestring_offset);
|
|
|
|
else
|
|
|
|
WRITE_FCTYPE(file, FC_CPSTRUCT, *typestring_offset);
|
2006-01-24 11:13:49 +01:00
|
|
|
/* alignment */
|
2007-02-06 15:54:58 +01:00
|
|
|
print_file(file, 2, "0x%02x,\n", align - 1);
|
2006-01-24 11:13:49 +01:00
|
|
|
/* total size */
|
2006-03-31 13:44:39 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %u */\n", total_size, total_size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 4;
|
2006-03-31 13:44:39 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* offset = %d (%u) */\n",
|
2006-01-31 18:08:03 +01:00
|
|
|
array_offset - *typestring_offset,
|
2006-01-31 18:08:24 +01:00
|
|
|
array_offset - *typestring_offset,
|
|
|
|
array_offset);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-02-07 12:28:33 +01:00
|
|
|
|
|
|
|
if (type->type == RPC_FC_CPSTRUCT)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
*typestring_offset += write_pointer_description(file, NULL,
|
|
|
|
type, 0, NULL, 0, pointer_offset);
|
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
|
|
|
|
2006-03-31 13:44:27 +02:00
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 1;
|
2006-01-24 11:13:49 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:14:59 +01:00
|
|
|
case RPC_FC_CVSTRUCT:
|
2007-02-06 15:54:58 +01:00
|
|
|
total_size = type_memsize(type, 0, NULL, &align);
|
2006-01-24 11:14:59 +01:00
|
|
|
|
|
|
|
if (total_size > USHRT_MAX)
|
|
|
|
error("structure size for parameter %s exceeds %d bytes by %d bytes\n",
|
|
|
|
name, USHRT_MAX, total_size - USHRT_MAX);
|
|
|
|
|
2006-01-31 18:08:03 +01:00
|
|
|
array = find_array_or_string_in_struct(type);
|
|
|
|
current_structure = type;
|
|
|
|
if (is_attr(array->attrs, ATTR_STRING))
|
|
|
|
array_offset = write_string_tfs(file, array->attrs, array->type,
|
|
|
|
array->array, array->name,
|
|
|
|
typestring_offset);
|
|
|
|
else
|
|
|
|
array_offset = write_array_tfs(file, array->attrs, array->type,
|
|
|
|
array->array, array->name,
|
|
|
|
typestring_offset);
|
|
|
|
current_structure = NULL;
|
|
|
|
|
2006-02-07 12:28:33 +01:00
|
|
|
pointer_offset = *typestring_offset;
|
|
|
|
if (!write_pointers(file, NULL, type, 0, NULL, 0, typestring_offset))
|
|
|
|
pointer_offset = 0;
|
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
start_offset = *typestring_offset;
|
|
|
|
WRITE_FCTYPE(file, FC_CVSTRUCT, *typestring_offset);
|
2006-01-24 11:14:59 +01:00
|
|
|
/* alignment */
|
2007-02-06 15:54:58 +01:00
|
|
|
print_file(file, 2, "0x%02x,\n", align - 1);
|
2006-01-24 11:14:59 +01:00
|
|
|
/* total size */
|
2006-03-31 13:44:39 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %u */\n", total_size, total_size);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 4;
|
2006-03-31 13:44:39 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* offset = %d (%u) */\n",
|
2006-01-31 18:08:24 +01:00
|
|
|
array_offset - *typestring_offset,
|
2006-01-31 18:08:03 +01:00
|
|
|
array_offset - *typestring_offset,
|
2006-01-31 18:08:24 +01:00
|
|
|
array_offset);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 2;
|
2006-02-07 12:28:33 +01:00
|
|
|
|
|
|
|
if (pointer_offset != 0)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
*typestring_offset += write_pointer_description(file, NULL,
|
|
|
|
type, 0, NULL, 0, pointer_offset);
|
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
|
|
|
*typestring_offset += 1;
|
|
|
|
}
|
|
|
|
|
2006-03-31 13:44:27 +02:00
|
|
|
print_file(file, 2, "0x%x, /* FC_END */\n", RPC_FC_END);
|
2006-01-31 18:07:20 +01:00
|
|
|
*typestring_offset += 1;
|
2006-01-24 11:14:59 +01:00
|
|
|
|
2006-01-31 18:07:20 +01:00
|
|
|
return start_offset;
|
2006-01-24 11:11:29 +01:00
|
|
|
default:
|
|
|
|
error("write_struct_tfs: Unimplemented for type 0x%x\n", type->type);
|
2006-01-31 18:07:20 +01:00
|
|
|
return *typestring_offset;
|
2006-01-24 11:11:29 +01:00
|
|
|
}
|
2006-01-24 11:10:59 +01:00
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
static void write_pointer_only_tfs(FILE *file, const attr_list_t *attrs, int pointer_type,
|
2006-09-08 01:57:16 +02:00
|
|
|
unsigned char flags, size_t offset,
|
|
|
|
unsigned int *typeformat_offset)
|
2006-02-07 12:30:07 +01:00
|
|
|
{
|
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,
|
2006-09-08 01:57:16 +02:00
|
|
|
pointer_type == RPC_FC_FP ? "FC_FP" : (pointer_type == RPC_FC_UP ? "FC_UP" : "FC_RP"));
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
if (flags & 0x04)
|
|
|
|
fprintf(file, " [allocated_on_stack]");
|
|
|
|
if (flags & 0x10)
|
|
|
|
fprintf(file, " [pointer_deref]");
|
|
|
|
fprintf(file, " */\n");
|
|
|
|
}
|
|
|
|
|
2006-03-31 13:44:39 +02:00
|
|
|
print_file(file, 2, "NdrFcShort(0x%x), /* %d */\n", offset, offset);
|
2006-02-07 12:30:07 +01:00
|
|
|
*typeformat_offset += 4;
|
|
|
|
}
|
|
|
|
|
2007-01-22 14:20:36 +01:00
|
|
|
static size_t write_union_tfs(FILE *file, const attr_list_t *attrs,
|
2006-01-31 12:24:54 +01:00
|
|
|
const type_t *type, const char *name,
|
2006-06-13 14:13:49 +02:00
|
|
|
unsigned int *typeformat_offset)
|
2006-01-24 11:10:59 +01:00
|
|
|
{
|
|
|
|
error("write_union_tfs: Unimplemented\n");
|
2006-01-31 18:07:20 +01:00
|
|
|
return *typeformat_offset;
|
2006-01-24 11:10:59 +01:00
|
|
|
}
|
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
static size_t write_ip_tfs(FILE *file, const func_t *func, const var_t *var,
|
|
|
|
unsigned int *typeformat_offset)
|
2006-08-18 03:09:20 +02:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t start_offset = *typeformat_offset;
|
2007-02-06 16:00:41 +01:00
|
|
|
const var_t *iid = get_attrp(var->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_list_t expr_list;
|
|
|
|
|
|
|
|
expr.type = EXPR_IDENTIFIER;
|
|
|
|
expr.ref = NULL;
|
|
|
|
expr.u.sval = iid->name;
|
|
|
|
expr.is_const = FALSE;
|
|
|
|
list_init( &expr_list );
|
|
|
|
list_add_head( &expr_list, &expr.entry );
|
|
|
|
print_file(file, 2, "0x2f, /* FC_IP */\n");
|
|
|
|
print_file(file, 2, "0x5c, /* FC_PAD */\n");
|
|
|
|
*typeformat_offset += write_conf_or_var_desc(file, func, NULL, &expr_list) + 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const type_t *base = is_ptr(var->type) ? var->type->ref : var->type;
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
|
2006-09-08 01:57:16 +02:00
|
|
|
static int get_ptr_attr(const type_t *t, int def_type)
|
|
|
|
{
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
int ptr_attr = get_attrv(t->attrs, ATTR_POINTERTYPE);
|
|
|
|
if (ptr_attr)
|
|
|
|
return ptr_attr;
|
|
|
|
if (t->kind != TKIND_ALIAS)
|
|
|
|
return def_type;
|
|
|
|
t = t->orig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-06 16:00:41 +01:00
|
|
|
static size_t write_typeformatstring_var(FILE *file, int indent, const func_t *func,
|
2006-06-13 14:13:49 +02:00
|
|
|
const var_t *var, unsigned int *typeformat_offset)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2006-01-24 11:06:10 +01:00
|
|
|
const type_t *type = var->type;
|
2006-09-08 01:57:16 +02:00
|
|
|
int var_ptrs = var->ptr_level, type_ptrs = 0;
|
|
|
|
int is_str = is_attr(var->attrs, ATTR_STRING);
|
2005-12-13 11:22:08 +01:00
|
|
|
|
2006-03-31 13:46:43 +02:00
|
|
|
chat("write_typeformatstring_var: %s\n", var->name);
|
|
|
|
|
2006-01-24 11:06:10 +01:00
|
|
|
while (TRUE)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2006-09-08 01:57:16 +02:00
|
|
|
is_str = is_str || is_attr(type->attrs, ATTR_STRING);
|
|
|
|
if (type->kind == TKIND_ALIAS)
|
|
|
|
type = type->orig;
|
|
|
|
else if (is_ptr(type))
|
|
|
|
{
|
|
|
|
++type_ptrs;
|
|
|
|
type = type->ref;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = var->type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
int ptr_level = var_ptrs + type_ptrs;
|
|
|
|
int pointer_type = 0;
|
|
|
|
|
2006-03-31 13:46:43 +02:00
|
|
|
chat("write_typeformatstring: type->type = 0x%x, type->name = %s, ptr_level = %d\n", type->type, type->name, ptr_level);
|
|
|
|
|
2006-09-08 01:57:16 +02:00
|
|
|
/* var attrs only effect the rightmost pointer */
|
|
|
|
if ((0 < var->ptr_level && var_ptrs == var->ptr_level)
|
|
|
|
|| (var->ptr_level == 0 && type == var->type))
|
|
|
|
{
|
|
|
|
int pointer_attr = get_attrv(var->attrs, ATTR_POINTERTYPE);
|
|
|
|
if (pointer_attr)
|
|
|
|
{
|
|
|
|
if (! ptr_level)
|
2007-02-28 20:44:24 +01:00
|
|
|
error("'%s': pointer attribute applied to non-pointer type\n", var->name);
|
2006-09-08 01:57:16 +02:00
|
|
|
pointer_type = pointer_attr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pointer_type = RPC_FC_RP;
|
|
|
|
}
|
|
|
|
else /* pointers below other pointers default to unique */
|
|
|
|
pointer_type = var_ptrs ? RPC_FC_UP : get_ptr_attr(type, RPC_FC_UP);
|
|
|
|
|
|
|
|
if (is_str && ptr_level + (var->array != NULL) == 1)
|
2006-01-31 12:24:54 +01:00
|
|
|
return write_string_tfs(file, var->attrs, type, var->array, var->name, typeformat_offset);
|
2006-01-24 11:09:53 +01:00
|
|
|
|
|
|
|
if (is_array_type(var->attrs, ptr_level, var->array))
|
2006-01-31 12:24:54 +01:00
|
|
|
return write_array_tfs(file, var->attrs, type, var->array, var->name, typeformat_offset);
|
2006-01-24 11:09:53 +01:00
|
|
|
|
2006-01-24 11:06:32 +01:00
|
|
|
if (ptr_level == 0)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2006-01-24 11:06:32 +01:00
|
|
|
/* basic types don't need a type format string */
|
2006-01-24 11:09:53 +01:00
|
|
|
if (is_base_type(type->type))
|
2006-01-31 18:07:20 +01:00
|
|
|
return 0;
|
2006-01-24 11:10:59 +01:00
|
|
|
|
|
|
|
switch (type->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:
|
2006-01-31 12:24:54 +01:00
|
|
|
return write_struct_tfs(file, type, var->name, typeformat_offset);
|
2006-01-24 11:10:59 +01:00
|
|
|
case RPC_FC_ENCAPSULATED_UNION:
|
|
|
|
case RPC_FC_NON_ENCAPSULATED_UNION:
|
2006-01-31 12:24:54 +01:00
|
|
|
return write_union_tfs(file, var->attrs, type, var->name, typeformat_offset);
|
2006-01-31 18:06:17 +01:00
|
|
|
case RPC_FC_IGNORE:
|
|
|
|
case RPC_FC_BIND_PRIMITIVE:
|
|
|
|
/* nothing to do */
|
|
|
|
return 0;
|
2006-01-24 11:10:59 +01:00
|
|
|
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
|
|
|
}
|
2006-08-30 02:19:21 +02:00
|
|
|
else if (ptr_level == 1)
|
2006-01-24 11:06:10 +01:00
|
|
|
{
|
2006-01-31 18:07:20 +01:00
|
|
|
size_t start_offset = *typeformat_offset;
|
2006-03-24 17:40:17 +01:00
|
|
|
int in_attr = is_attr(var->attrs, ATTR_IN);
|
|
|
|
int out_attr = is_attr(var->attrs, ATTR_OUT);
|
2006-09-08 01:57:16 +02:00
|
|
|
const type_t *base = is_ptr(type) ? type->ref : type;
|
2006-01-24 11:10:42 +01:00
|
|
|
|
2006-09-08 01:57:16 +02:00
|
|
|
if (base->type == RPC_FC_IP)
|
2006-08-18 03:09:20 +02:00
|
|
|
{
|
2007-02-06 16:00:41 +01:00
|
|
|
return write_ip_tfs(file, func, var, typeformat_offset);
|
2006-08-18 03:09:20 +02:00
|
|
|
}
|
|
|
|
|
2006-01-24 11:06:32 +01:00
|
|
|
/* special case for pointers to base types */
|
2006-09-08 01:57:16 +02:00
|
|
|
switch (base->type)
|
2006-01-24 11:06:10 +01:00
|
|
|
{
|
2005-12-13 11:22:08 +01:00
|
|
|
#define CASE_BASETYPE(fctype) \
|
2006-01-24 11:06:10 +01:00
|
|
|
case RPC_##fctype: \
|
2006-03-24 17:40:17 +01:00
|
|
|
print_file(file, indent, "0x%x, 0x%x, /* %s %s[simple_pointer] */\n", \
|
2006-01-24 11:10:42 +01:00
|
|
|
pointer_type, \
|
2006-03-24 17:40:17 +01:00
|
|
|
(!in_attr && out_attr) ? 0x0C : 0x08, \
|
|
|
|
pointer_type == RPC_FC_FP ? "FC_FP" : (pointer_type == RPC_FC_UP ? "FC_UP" : "FC_RP"), \
|
|
|
|
(!in_attr && out_attr) ? "[allocated_on_stack] " : ""); \
|
2006-01-24 11:06:10 +01:00
|
|
|
print_file(file, indent, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
|
|
|
|
print_file(file, indent, "0x5c, /* FC_PAD */\n"); \
|
2006-01-31 18:07:20 +01:00
|
|
|
*typeformat_offset += 4; \
|
|
|
|
return start_offset
|
2006-01-24 11:06:10 +01:00
|
|
|
CASE_BASETYPE(FC_BYTE);
|
|
|
|
CASE_BASETYPE(FC_CHAR);
|
|
|
|
CASE_BASETYPE(FC_SMALL);
|
|
|
|
CASE_BASETYPE(FC_USMALL);
|
|
|
|
CASE_BASETYPE(FC_WCHAR);
|
|
|
|
CASE_BASETYPE(FC_SHORT);
|
|
|
|
CASE_BASETYPE(FC_USHORT);
|
|
|
|
CASE_BASETYPE(FC_LONG);
|
|
|
|
CASE_BASETYPE(FC_ULONG);
|
|
|
|
CASE_BASETYPE(FC_FLOAT);
|
|
|
|
CASE_BASETYPE(FC_HYPER);
|
|
|
|
CASE_BASETYPE(FC_DOUBLE);
|
|
|
|
CASE_BASETYPE(FC_ENUM16);
|
|
|
|
CASE_BASETYPE(FC_ENUM32);
|
|
|
|
CASE_BASETYPE(FC_IGNORE);
|
|
|
|
CASE_BASETYPE(FC_ERROR_STATUS_T);
|
|
|
|
default:
|
2006-01-24 11:11:29 +01:00
|
|
|
break;
|
2006-01-24 11:06:10 +01:00
|
|
|
}
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
2006-01-24 11:11:29 +01:00
|
|
|
|
|
|
|
assert(ptr_level > 0);
|
|
|
|
|
2006-01-31 18:08:24 +01:00
|
|
|
if (file)
|
|
|
|
fprintf(file, "/* %2u */\n", *typeformat_offset);
|
2006-09-08 01:57:16 +02:00
|
|
|
write_pointer_only_tfs(file, var->attrs, pointer_type,
|
|
|
|
1 < ptr_level ? 0x10 : 0,
|
|
|
|
2, typeformat_offset);
|
2006-01-24 11:11:29 +01:00
|
|
|
|
2006-09-08 01:57:16 +02:00
|
|
|
if (var_ptrs)
|
|
|
|
--var_ptrs;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
--type_ptrs;
|
|
|
|
type = type->ref;
|
|
|
|
}
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:05:29 +01:00
|
|
|
|
2007-01-22 14:21:56 +01:00
|
|
|
void write_typeformatstring(FILE *file, const ifref_list_t *ifaces, int for_objects)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
|
|
|
int indent = 0;
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *var;
|
2006-06-13 14:13:49 +02:00
|
|
|
unsigned int typeformat_offset;
|
2007-01-22 14:21:56 +01:00
|
|
|
const ifref_t *iface;
|
2005-12-13 11:22:08 +01:00
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
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");
|
2006-01-31 12:24:54 +01:00
|
|
|
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
|
|
|
{
|
2006-08-18 03:08:38 +02:00
|
|
|
if (for_objects != is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
|
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;
|
2006-06-01 16:40:10 +02:00
|
|
|
current_func = func;
|
|
|
|
if (func->args)
|
2007-01-22 14:26:12 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
2007-02-06 16:00:41 +01:00
|
|
|
write_typeformatstring_var(file, indent, func, var,
|
2006-06-01 16:40:10 +02:00
|
|
|
&typeformat_offset);
|
2005-12-13 11:22:08 +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");
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:22:32 +01:00
|
|
|
static unsigned int get_required_buffer_size_type(
|
2007-01-22 14:31:40 +01:00
|
|
|
const type_t *type, int ptr_level, const array_dims_t *array,
|
2005-12-26 13:22:32 +01:00
|
|
|
const char *name, unsigned int *alignment)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2007-02-06 15:55:49 +01:00
|
|
|
size_t size = 0;
|
|
|
|
|
2005-12-26 13:20:59 +01:00
|
|
|
*alignment = 0;
|
2007-02-06 15:55:49 +01:00
|
|
|
if (ptr_level == 0)
|
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-02-06 15:55:49 +01:00
|
|
|
size = 1;
|
|
|
|
break;
|
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:
|
2006-03-23 10:39:07 +01:00
|
|
|
*alignment = 4;
|
2007-02-06 15:55:49 +01:00
|
|
|
size = 2;
|
|
|
|
break;
|
2005-12-26 13:20:59 +01:00
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_LONG:
|
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-02-06 15:55:49 +01:00
|
|
|
size = 4;
|
|
|
|
break;
|
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-02-06 15:55:49 +01:00
|
|
|
size = 8;
|
|
|
|
break;
|
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:
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
size += get_required_buffer_size_type(
|
|
|
|
field->type, field->ptr_level, field->array, field->name,
|
|
|
|
&alignment);
|
|
|
|
}
|
2007-02-06 15:55:49 +01:00
|
|
|
break;
|
2006-01-06 21:06:24 +01:00
|
|
|
}
|
|
|
|
|
2007-01-24 20:10:57 +01:00
|
|
|
case RPC_FC_RP:
|
|
|
|
if (is_base_type( type->ref->type ) || type->ref->type == RPC_FC_STRUCT)
|
2007-02-06 15:55:49 +01:00
|
|
|
size = get_required_buffer_size_type( type->ref, 0, NULL, name, alignment );
|
|
|
|
break;
|
2007-01-24 20:10:57 +01:00
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
default:
|
2005-12-26 13:22:32 +01:00
|
|
|
error("get_required_buffer_size: Unknown/unsupported type: %s (0x%02x)\n", name, type->type);
|
2005-12-08 12:52:13 +01:00
|
|
|
return 0;
|
2005-12-26 13:20:59 +01:00
|
|
|
}
|
2007-02-06 15:55:49 +01:00
|
|
|
if (array) size *= get_array_size( array );
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
2007-02-06 15:55:49 +01:00
|
|
|
return size;
|
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
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
expr_list_t *size_is = get_attrp(var->attrs, ATTR_SIZEIS);
|
|
|
|
int has_size = is_non_void(size_is);
|
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);
|
|
|
|
|
|
|
|
if (!in_attr && !out_attr)
|
|
|
|
in_attr = 1;
|
|
|
|
|
2006-04-09 14:38:57 +02:00
|
|
|
*alignment = 0;
|
|
|
|
|
|
|
|
if (pass == PASS_OUT)
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
2006-04-09 14:38:57 +02:00
|
|
|
if (out_attr && var->ptr_level > 0)
|
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(
|
|
|
|
field->type, field->ptr_level, field->array, field->name,
|
|
|
|
&align);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
|
|
|
if ((!out_attr || in_attr) && !has_size && !is_attr(var->attrs, ATTR_STRING) && !var->array)
|
|
|
|
{
|
2006-08-30 02:19:21 +02:00
|
|
|
if (var->ptr_level > 0)
|
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(
|
|
|
|
field->type, field->ptr_level, field->array, field->name,
|
|
|
|
&align);
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return get_required_buffer_size_type(var->type, var->ptr_level, var->array, var->name, alignment);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pass == PASS_OUT && !is_void(func->def->type, NULL))
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
const char *varname, 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");
|
2006-03-31 13:47:35 +02:00
|
|
|
print_file(file, indent, "%s%s,\n",
|
|
|
|
(phase == PHASE_UNMARSHAL) ? "(unsigned char **)&" : "(unsigned char *)",
|
|
|
|
varname);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
const type_t *type = var->type;
|
|
|
|
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;
|
|
|
|
|
2006-08-30 02:19:21 +02:00
|
|
|
rtype = 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:
|
|
|
|
size = 2;
|
|
|
|
alignment = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_LONG:
|
|
|
|
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, "*(");
|
|
|
|
write_type(file, var->type, NULL, var->tname);
|
|
|
|
if (var->ptr_level)
|
|
|
|
fprintf(file, " *)_StubMsg.Buffer = *");
|
|
|
|
else
|
|
|
|
fprintf(file, " *)_StubMsg.Buffer = ");
|
|
|
|
fprintf(file, varname);
|
|
|
|
fprintf(file, ";\n");
|
|
|
|
}
|
|
|
|
else if (phase == PHASE_UNMARSHAL)
|
|
|
|
{
|
|
|
|
if (pass == PASS_IN || pass == PASS_RETURN)
|
|
|
|
print_file(file, indent, "");
|
|
|
|
else
|
|
|
|
print_file(file, indent, "*");
|
|
|
|
fprintf(file, varname);
|
|
|
|
if (pass == PASS_IN && var->ptr_level)
|
|
|
|
fprintf(file, " = (");
|
|
|
|
else
|
|
|
|
fprintf(file, " = *(");
|
|
|
|
write_type(file, var->type, NULL, var->tname);
|
|
|
|
fprintf(file, " *)_StubMsg.Buffer;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, indent, "_StubMsg.Buffer += sizeof(");
|
|
|
|
write_type(file, var->type, NULL, var->tname);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-02-07 12:32:24 +01:00
|
|
|
void write_remoting_arguments(FILE *file, int indent, const func_t *func,
|
|
|
|
unsigned int *type_offset, enum pass pass,
|
|
|
|
enum remoting_phase phase)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_list_t *length_is;
|
|
|
|
const expr_list_t *size_is;
|
2006-03-29 12:42:29 +02:00
|
|
|
int in_attr, out_attr, has_length, has_size, 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;
|
|
|
|
|
2006-03-29 12:42:29 +02:00
|
|
|
length_is = get_attrp(var->attrs, ATTR_LENGTHIS);
|
|
|
|
size_is = get_attrp(var->attrs, ATTR_SIZEIS);
|
2007-02-06 15:59:24 +01:00
|
|
|
has_length = is_non_void(length_is);
|
|
|
|
has_size = is_non_void(size_is) || (var->array && is_conformant_array(var->array));
|
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;
|
|
|
|
|
|
|
|
switch (pass)
|
|
|
|
{
|
|
|
|
case PASS_IN:
|
2007-01-22 14:26:12 +01:00
|
|
|
if (!in_attr) goto next;
|
2005-12-26 13:14:28 +01:00
|
|
|
break;
|
|
|
|
case PASS_OUT:
|
2007-01-22 14:26:12 +01:00
|
|
|
if (!out_attr) goto next;
|
2005-12-26 13:14:28 +01:00
|
|
|
break;
|
|
|
|
case PASS_RETURN:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-08-30 02:19:21 +02:00
|
|
|
rtype = type->type;
|
2006-03-31 13:45:16 +02:00
|
|
|
|
2007-01-26 11:59:58 +01:00
|
|
|
if (is_user_derived( var ))
|
|
|
|
{
|
|
|
|
print_phase_function(file, indent, "UserMarshal", phase, var->name, *type_offset);
|
|
|
|
}
|
|
|
|
else if (is_string_type(var->attrs, var->ptr_level, var->array))
|
2006-01-24 11:09:53 +01:00
|
|
|
{
|
2007-01-22 14:31:40 +01:00
|
|
|
if (var->array && !is_conformant_array(var->array))
|
2006-03-31 13:47:35 +02:00
|
|
|
print_phase_function(file, indent, "NonConformantString", phase, var->name, *type_offset);
|
2006-01-24 11:10:08 +01:00
|
|
|
else
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
2006-03-31 13:47:08 +02:00
|
|
|
if (size_is && is_size_needed_for_phase(phase))
|
2006-03-29 12:42:29 +02:00
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_t *size = LIST_ENTRY( list_head(size_is), const expr_t, entry );
|
2006-03-29 12:42:29 +02:00
|
|
|
print_file(file, indent, "_StubMsg.MaxCount = (unsigned long)");
|
2007-02-06 15:59:24 +01:00
|
|
|
write_expr(file, size, 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))
|
2006-03-31 13:47:50 +02:00
|
|
|
print_phase_function(file, indent, "Pointer", phase, var->name, *type_offset);
|
2006-03-29 12:42:29 +02:00
|
|
|
else
|
2006-04-03 17:27:17 +02:00
|
|
|
print_phase_function(file, indent, "ConformantString", phase, var->name,
|
|
|
|
*type_offset + (has_size ? 4 : 2));
|
2006-03-29 12:42:29 +02:00
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
}
|
|
|
|
else if (is_array_type(var->attrs, var->ptr_level, var->array))
|
|
|
|
{
|
|
|
|
const char *array_type;
|
|
|
|
|
2007-01-22 14:31:40 +01:00
|
|
|
if (var->array && list_count(var->array) > 1) /* multi-dimensional array */
|
2006-01-24 11:09:53 +01:00
|
|
|
array_type = "ComplexArray";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!has_length && !has_size)
|
|
|
|
array_type = "FixedArray";
|
|
|
|
else if (has_length && !has_size)
|
|
|
|
{
|
2006-03-31 13:47:08 +02:00
|
|
|
if (is_size_needed_for_phase(phase))
|
2006-02-07 12:32:24 +01:00
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_t *length = LIST_ENTRY( list_head(length_is), const expr_t, entry );
|
2006-02-07 12:32:24 +01:00
|
|
|
print_file(file, indent, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
|
|
|
|
print_file(file, indent, "_StubMsg.ActualCount = (unsigned long)");
|
2007-02-06 15:59:24 +01:00
|
|
|
write_expr(file, length, 1);
|
2006-02-07 12:32:24 +01:00
|
|
|
fprintf(file, ";\n\n");
|
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
array_type = "VaryingArray";
|
|
|
|
}
|
|
|
|
else if (!has_length && has_size)
|
|
|
|
{
|
2006-04-05 00:07:03 +02:00
|
|
|
if (is_size_needed_for_phase(phase) && phase != PHASE_FREE)
|
2006-02-07 12:32:24 +01:00
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_t *size = LIST_ENTRY( list_head(size_is ? size_is : var->array),
|
|
|
|
const expr_t, entry );
|
2006-02-07 12:32:24 +01:00
|
|
|
print_file(file, indent, "_StubMsg.MaxCount = (unsigned long)");
|
2007-02-06 15:59:24 +01:00
|
|
|
write_expr(file, size, 1);
|
2006-02-07 12:32:24 +01:00
|
|
|
fprintf(file, ";\n\n");
|
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
array_type = "ConformantArray";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-31 13:47:08 +02:00
|
|
|
if (is_size_needed_for_phase(phase))
|
2006-02-07 12:32:24 +01:00
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_t *length = LIST_ENTRY( list_head(length_is), const expr_t, entry );
|
|
|
|
const expr_t *size = LIST_ENTRY( list_head(size_is ? size_is : var->array),
|
|
|
|
const expr_t, entry );
|
2006-02-07 12:32:24 +01:00
|
|
|
print_file(file, indent, "_StubMsg.MaxCount = (unsigned long)");
|
2007-02-06 15:59:24 +01:00
|
|
|
write_expr(file, size, 1);
|
2006-02-07 12:32:24 +01:00
|
|
|
fprintf(file, ";\n");
|
|
|
|
print_file(file, indent, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
|
|
|
|
print_file(file, indent, "_StubMsg.ActualCount = (unsigned long)");
|
2007-02-06 15:59:24 +01:00
|
|
|
write_expr(file, length, 1);
|
2006-02-07 12:32:24 +01:00
|
|
|
fprintf(file, ";\n\n");
|
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
array_type = "ConformantVaryingArray";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (pointer_type == RPC_FC_UP)
|
|
|
|
print_phase_function(file, indent, "Pointer", phase, var->name, *type_offset);
|
|
|
|
else
|
|
|
|
print_phase_function(file, indent, array_type, phase, var->name, *type_offset + 4);
|
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
}
|
2006-08-09 23:20:35 +02:00
|
|
|
else if (var->ptr_level == 0 && 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
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
else if (var->ptr_level == 0)
|
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-01-24 20:10:57 +01:00
|
|
|
print_phase_function(file, indent, "SimpleStruct", phase, var->name, *type_offset);
|
2006-01-24 11:09:53 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
2007-01-24 20:10:57 +01:00
|
|
|
print_phase_function(file, indent, "ConformantStruct", phase, var->name, *type_offset);
|
2006-01-24 11:09:53 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_CVSTRUCT:
|
2007-01-24 20:10:57 +01:00
|
|
|
print_phase_function(file, indent, "ConformantVaryingStruct", phase, var->name, *type_offset);
|
2006-01-24 11:09:53 +01:00
|
|
|
break;
|
|
|
|
case RPC_FC_BOGUS_STRUCT:
|
2007-01-24 20:10:57 +01:00
|
|
|
print_phase_function(file, indent, "ComplexStruct", phase, var->name, *type_offset);
|
|
|
|
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)
|
|
|
|
print_phase_function(file, indent, "SimpleStruct", phase, var->name, *type_offset + 4);
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
print_phase_function(file, indent, "Pointer", phase, var->name, *type_offset);
|
|
|
|
}
|
2006-01-24 11:09:53 +01:00
|
|
|
break;
|
|
|
|
default:
|
2006-02-07 12:32:24 +01:00
|
|
|
error("write_remoting_arguments: Unsupported type: %s (0x%02x, ptr_level: %d)\n",
|
2006-08-09 23:20:35 +02:00
|
|
|
var->name, rtype, var->ptr_level);
|
2005-12-26 13:12:03 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-26 13:09:36 +01:00
|
|
|
else
|
|
|
|
{
|
2006-08-09 23:20:35 +02:00
|
|
|
if ((var->ptr_level == 1) && (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
|
|
|
}
|
2006-08-09 23:20:35 +02:00
|
|
|
else if ((var->ptr_level == 1) && (pointer_type == RPC_FC_RP) && (rtype == RPC_FC_STRUCT))
|
2006-04-09 14:38:57 +02:00
|
|
|
{
|
|
|
|
if (phase != PHASE_BUFFERSIZE && phase != PHASE_FREE)
|
|
|
|
print_phase_function(file, indent, "SimpleStruct", phase, var->name, *type_offset + 4);
|
|
|
|
}
|
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;
|
|
|
|
if ((iid = get_attrp( var->attrs, ATTR_IIDIS )))
|
|
|
|
print_file( file, indent, "_StubMsg.MaxCount = (unsigned long)%s;\n", iid->name );
|
2006-03-31 13:47:35 +02:00
|
|
|
print_phase_function(file, indent, "Pointer", phase, var->name, *type_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");
|
2007-01-22 14:26:12 +01:00
|
|
|
next:
|
|
|
|
*type_offset += get_size_typeformatstring_var(var);
|
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
|
|
|
{
|
2005-12-26 13:05:55 +01:00
|
|
|
unsigned int type_offset = 2;
|
2006-01-24 11:05:51 +01:00
|
|
|
return write_procformatstring_var(NULL, 0, var, FALSE, &type_offset);
|
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 */
|
|
|
|
if (is_void(func->def->type, NULL))
|
|
|
|
size += 2; /* FC_END and FC_PAD */
|
|
|
|
else
|
|
|
|
size += get_size_procformatstring_var(func->def);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2006-01-24 11:05:51 +01:00
|
|
|
size_t get_size_typeformatstring_var(const var_t *var)
|
2005-12-26 13:05:29 +01:00
|
|
|
{
|
2006-06-13 14:13:49 +02:00
|
|
|
unsigned int type_offset = 0;
|
2007-02-06 16:00:41 +01:00
|
|
|
write_typeformatstring_var(NULL, 0, NULL, var, &type_offset);
|
2006-01-31 18:07:20 +01:00
|
|
|
return type_offset;
|
2005-12-26 13:05:29 +01:00
|
|
|
}
|
2006-01-27 12:53:32 +01:00
|
|
|
|
2007-01-22 14:21:56 +01:00
|
|
|
size_t get_size_procformatstring(const ifref_list_t *ifaces, int for_objects)
|
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
|
|
|
{
|
2006-08-18 03:08:38 +02:00
|
|
|
if (for_objects != is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
|
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-01-22 14:21:56 +01:00
|
|
|
size_t get_size_typeformatstring(const ifref_list_t *ifaces, int for_objects)
|
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 = 3;
|
2007-01-22 14:23:08 +01:00
|
|
|
const func_t *func;
|
2007-01-22 14:26:12 +01:00
|
|
|
const var_t *var;
|
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
|
|
|
{
|
2006-08-18 03:08:38 +02:00
|
|
|
if (for_objects != is_object(iface->iface->attrs) || is_local(iface->iface->attrs))
|
2006-06-01 16:40:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (iface->iface->funcs)
|
2006-03-23 10:33:08 +01:00
|
|
|
{
|
2007-01-22 14:23:08 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( func, iface->iface->funcs, const func_t, entry )
|
2006-03-23 10:33:08 +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
|
|
|
/* argument list size */
|
|
|
|
if (func->args)
|
2007-01-22 14:26:12 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
2006-06-01 16:40:10 +02:00
|
|
|
size += get_size_typeformatstring_var(var);
|
|
|
|
}
|
2006-03-23 10:33:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
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;
|
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, "(");
|
|
|
|
write_type(h, e->u.tref->ref, NULL, e->u.tref->name);
|
|
|
|
fprintf(h, ")");
|
|
|
|
write_struct_expr(h, e->ref, 1, fields, structvar);
|
|
|
|
break;
|
|
|
|
case EXPR_SIZEOF:
|
|
|
|
fprintf(h, "sizeof(");
|
|
|
|
write_type(h, e->u.tref->ref, NULL, e->u.tref->name);
|
|
|
|
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' */
|
|
|
|
if (!is_void(def->type, NULL))
|
|
|
|
{
|
|
|
|
print_file(file, indent, "");
|
|
|
|
write_type(file, def->type, def, def->tname);
|
|
|
|
fprintf(file, " _RetVal;\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_list_t *size_is = get_attrp(var->attrs, ATTR_SIZEIS);
|
|
|
|
int has_size = is_non_void(size_is);
|
2007-01-24 19:59:16 +01:00
|
|
|
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 && !has_size && !is_string)
|
|
|
|
{
|
|
|
|
int indirection;
|
|
|
|
print_file(file, indent, "");
|
|
|
|
write_type(file, var->type, NULL, var->tname);
|
|
|
|
for (indirection = 0; indirection < var->ptr_level - 1; indirection++)
|
|
|
|
fprintf(file, "*");
|
|
|
|
fprintf(file, " _W%u;\n", i++);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, indent, "");
|
|
|
|
write_type(file, var->type, var, var->tname);
|
|
|
|
fprintf(file, " ");
|
|
|
|
write_name(file, var);
|
|
|
|
write_array(file, var->array, 0);
|
|
|
|
fprintf(file, ";\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_list_t *size_is;
|
2007-01-24 19:59:16 +01:00
|
|
|
int has_size;
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( var, func->args, const var_t, entry )
|
|
|
|
{
|
|
|
|
int is_string = is_attr(var->attrs, ATTR_STRING);
|
|
|
|
size_is = get_attrp(var->attrs, ATTR_SIZEIS);
|
2007-02-06 15:59:24 +01:00
|
|
|
has_size = is_non_void(size_is);
|
2007-01-24 19:59:16 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (has_size)
|
|
|
|
{
|
2007-02-06 15:59:24 +01:00
|
|
|
const expr_t *expr;
|
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-02-06 15:59:24 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( expr, size_is, const expr_t, entry )
|
|
|
|
{
|
|
|
|
if (expr->type == EXPR_VOID) continue;
|
|
|
|
write_expr( file, expr, 1 );
|
|
|
|
fprintf(file, " * ");
|
|
|
|
}
|
2007-02-06 15:54:58 +01:00
|
|
|
size = type_memsize(type, 0, NULL, &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);
|
|
|
|
if (var->ptr_level > 1)
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int indent = 0;
|
|
|
|
result = 1;
|
|
|
|
print_file(file, indent, "static void __RPC_USER %s_%sExprEval_%04u(PMIDL_STUB_MESSAGE pStubMsg)\n",
|
|
|
|
iface, eval->structure->name, callback_offset);
|
|
|
|
print_file(file, indent, "{\n");
|
|
|
|
indent++;
|
|
|
|
print_file(file, indent, "struct %s *" STRUCT_EXPR_EVAL_VAR " = (struct %s *)(pStubMsg->StackTop - %u);\n",
|
|
|
|
eval->structure->name, eval->structure->name, eval->structure_size);
|
|
|
|
fprintf(file, "\n");
|
|
|
|
print_file(file, indent, "pStubMsg->Offset = 0;\n"); /* FIXME */
|
|
|
|
print_file(file, indent, "pStubMsg->MaxCount = (unsigned long)");
|
|
|
|
write_struct_expr(file, eval->expr, 1, eval->structure->fields, STRUCT_EXPR_EVAL_VAR);
|
|
|
|
fprintf(file, ";\n");
|
|
|
|
indent--;
|
|
|
|
print_file(file, indent, "}\n\n");
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
print_file(file, 1, "%s_%sExprEval_%04u,\n",
|
|
|
|
iface, eval->structure->name, callback_offset);
|
|
|
|
|
|
|
|
callback_offset++;
|
|
|
|
list_remove(&eval->entry);
|
|
|
|
free(eval);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|