2005-12-08 12:52:13 +01:00
|
|
|
/*
|
|
|
|
* Format String Generator for IDL Compiler
|
|
|
|
*
|
|
|
|
* Copyright 2005 Eric Kohl
|
|
|
|
* Copyright 2005 Robert Shearman
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
|
|
#include "widl.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "header.h"
|
|
|
|
#include "windef.h"
|
|
|
|
|
|
|
|
#include "widl.h"
|
2005-12-12 12:14:31 +01:00
|
|
|
#include "typegen.h"
|
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;
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:22:32 +01:00
|
|
|
static inline int type_has_ref(const type_t *type)
|
|
|
|
{
|
|
|
|
return (type->type == 0 && type->ref);
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
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
|
|
|
|
|
|
|
if (ptr_level == 0 && type_has_ref(type))
|
2006-01-24 11:05:51 +01:00
|
|
|
type = type->ref;
|
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
|
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
|
|
|
}
|
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
void write_procformatstring(FILE *file, type_t *iface)
|
|
|
|
{
|
|
|
|
int indent = 0;
|
|
|
|
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++;
|
|
|
|
|
2005-12-26 13:08:51 +01:00
|
|
|
if (iface->funcs)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:08:51 +01:00
|
|
|
func_t *func = iface->funcs;
|
|
|
|
while (NEXT_LINK(func)) func = NEXT_LINK(func);
|
|
|
|
for (; func; func = PREV_LINK(func))
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:08:51 +01:00
|
|
|
/* emit argument data */
|
|
|
|
if (func->args)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:08:51 +01:00
|
|
|
var = func->args;
|
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
|
|
|
while (var)
|
|
|
|
{
|
2006-01-24 11:05:51 +01:00
|
|
|
write_procformatstring_var(file, indent, var, FALSE,
|
|
|
|
&type_offset);
|
2005-12-26 13:22:32 +01:00
|
|
|
|
2005-12-26 13:08:51 +01:00
|
|
|
var = PREV_LINK(var);
|
|
|
|
}
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
2005-12-26 13:09:36 +01:00
|
|
|
|
2005-12-26 13:08:51 +01: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
|
2006-01-24 11:05:51 +01:00
|
|
|
write_procformatstring_var(file, indent, var, TRUE,
|
|
|
|
&type_offset);
|
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 size_t write_typeformatstring_type(FILE *file, int indent,
|
|
|
|
const type_t *type, int ptr_level, const expr_t *array, const char *name)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2005-12-26 13:22:32 +01:00
|
|
|
if (ptr_level == 0 && type_has_ref(type))
|
|
|
|
return write_typeformatstring_type(file, indent,
|
|
|
|
type->ref, 0 /* FIXME */, array, name);
|
2005-12-13 11:22:08 +01:00
|
|
|
|
|
|
|
/* basic types don't need a type format string */
|
2006-01-06 21:06:24 +01:00
|
|
|
if (ptr_level == 0 && !array && is_base_type(type->type))
|
2005-12-26 13:05:29 +01:00
|
|
|
return 0;
|
2005-12-13 11:22:08 +01:00
|
|
|
|
2005-12-26 13:22:32 +01:00
|
|
|
if ((ptr_level == 1 && !type_has_ref(type)) ||
|
|
|
|
(ptr_level == 0 && array && !NEXT_LINK(array)))
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2005-12-26 13:22:32 +01:00
|
|
|
switch (type->type)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
|
|
|
#define CASE_BASETYPE(fctype) \
|
|
|
|
case RPC_##fctype: \
|
|
|
|
print_file(file, indent, "0x11, 0x08, /* FC_RP [simple_pointer] */\n"); \
|
2005-12-26 13:22:32 +01:00
|
|
|
print_file(file, indent, "0x%02x, /* " #fctype " */\n", RPC_##fctype); \
|
2005-12-13 11:22:08 +01:00
|
|
|
print_file(file, indent, "0x5c, /* FC_PAD */\n"); \
|
2005-12-26 13:05:29 +01:00
|
|
|
return 4
|
2005-12-13 11:22:08 +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:
|
2005-12-26 13:22:32 +01:00
|
|
|
error("write_typeformatstring_var: Unknown/unsupported type: %s (0x%02x)\n", name, type->type);
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-26 13:22:32 +01:00
|
|
|
error("write_typeformatstring_var: Pointer level %d not supported for variable %s\n", ptr_level, name);
|
2005-12-26 13:05:29 +01:00
|
|
|
return 0;
|
2005-12-13 11:22:08 +01:00
|
|
|
}
|
|
|
|
|
2005-12-26 13:05:29 +01:00
|
|
|
|
2005-12-13 11:22:08 +01:00
|
|
|
void write_typeformatstring(FILE *file, type_t *iface)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
|
|
|
int indent = 0;
|
2005-12-13 11:22:08 +01:00
|
|
|
var_t *var;
|
|
|
|
|
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");
|
2005-12-13 11:22:08 +01:00
|
|
|
|
2005-12-26 13:08:51 +01:00
|
|
|
if (iface->funcs)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2005-12-26 13:08:51 +01:00
|
|
|
func_t *func = iface->funcs;
|
|
|
|
while (NEXT_LINK(func)) func = NEXT_LINK(func);
|
|
|
|
for (; func; func = PREV_LINK(func))
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2005-12-26 13:08:51 +01:00
|
|
|
if (func->args)
|
2005-12-13 11:22:08 +01:00
|
|
|
{
|
2005-12-26 13:08:51 +01:00
|
|
|
var = func->args;
|
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
|
|
|
while (var)
|
|
|
|
{
|
2005-12-26 13:22:32 +01:00
|
|
|
write_typeformatstring_type(file, indent, var->type,
|
|
|
|
var->ptr_level, var->array, var->name);
|
2005-12-26 13:08:51 +01:00
|
|
|
var = PREV_LINK(var);
|
|
|
|
}
|
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(
|
|
|
|
const type_t *type, int ptr_level, const expr_t *array,
|
|
|
|
const char *name, unsigned int *alignment)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:20:59 +01:00
|
|
|
*alignment = 0;
|
2005-12-26 13:22:32 +01:00
|
|
|
if (ptr_level == 0 && !array && !type_has_ref(type))
|
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:
|
|
|
|
return 1;
|
|
|
|
|
2005-12-08 12:52:13 +01:00
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
case RPC_FC_SHORT:
|
2005-12-26 13:20:59 +01:00
|
|
|
*alignment = 2;
|
|
|
|
return 2;
|
|
|
|
|
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;
|
2005-12-08 12:52:13 +01:00
|
|
|
return 4;
|
|
|
|
|
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;
|
2005-12-08 12:52:13 +01:00
|
|
|
return 8;
|
|
|
|
|
2006-01-06 21:06:24 +01:00
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
{
|
|
|
|
size_t size = 0;
|
|
|
|
const var_t *field;
|
|
|
|
for (field = type->fields; field; field = NEXT_LINK(field))
|
|
|
|
{
|
|
|
|
unsigned int alignment;
|
|
|
|
size += get_required_buffer_size_type(
|
|
|
|
field->type, field->ptr_level, field->array, field->name,
|
|
|
|
&alignment);
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
2005-12-26 13:22:32 +01:00
|
|
|
if (ptr_level == 0 && type_has_ref(type))
|
|
|
|
return get_required_buffer_size_type(type->ref, 0 /* FIXME */, array, name, alignment);
|
2005-12-26 13:20:59 +01:00
|
|
|
return 0;
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
|
2005-12-26 13:22:32 +01:00
|
|
|
unsigned int get_required_buffer_size(const var_t *var, unsigned int *alignment)
|
|
|
|
{
|
|
|
|
return get_required_buffer_size_type(var->type, var->ptr_level, var->array, var->name, alignment);
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:14:28 +01:00
|
|
|
void marshall_arguments(FILE *file, int indent, func_t *func,
|
|
|
|
unsigned int *type_offset, enum pass pass)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
|
|
|
unsigned int last_size = 0;
|
|
|
|
var_t *var;
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var = func->args;
|
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
2005-12-26 13:12:46 +01:00
|
|
|
for (; var; *type_offset += get_size_typeformatstring_var(var), var = PREV_LINK(var))
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:14:28 +01: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;
|
|
|
|
|
|
|
|
switch (pass)
|
|
|
|
{
|
|
|
|
case PASS_IN:
|
|
|
|
if (!in_attr)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case PASS_OUT:
|
|
|
|
if (!out_attr)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case PASS_RETURN:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:13:04 +01:00
|
|
|
if (var->ptr_level == 0 && !var->array)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:09:36 +01:00
|
|
|
unsigned int size;
|
|
|
|
unsigned int alignment = 0;
|
|
|
|
switch (var->type->type)
|
|
|
|
{
|
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_SMALL:
|
|
|
|
case RPC_FC_USMALL:
|
|
|
|
size = 1;
|
|
|
|
alignment = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
case RPC_FC_SHORT:
|
|
|
|
size = 2;
|
|
|
|
if (last_size != 0 && last_size < 2)
|
|
|
|
alignment = (2 - last_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_LONG:
|
|
|
|
case RPC_FC_FLOAT:
|
|
|
|
case RPC_FC_ERROR_STATUS_T:
|
|
|
|
size = 4;
|
|
|
|
if (last_size != 0 && last_size < 4)
|
|
|
|
alignment = (4 - last_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_HYPER:
|
|
|
|
case RPC_FC_DOUBLE:
|
|
|
|
size = 8;
|
|
|
|
if (last_size != 0 && last_size < 4)
|
|
|
|
alignment = (4 - last_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-12-26 13:12:03 +01:00
|
|
|
error("marshall_arguments: Unsupported type: %s (0x%02x, ptr_level: 0)\n", var->name, var->type->type);
|
2005-12-26 13:09:36 +01:00
|
|
|
size = 0;
|
|
|
|
}
|
2005-12-08 12:53:58 +01:00
|
|
|
|
2005-12-26 13:09:36 +01:00
|
|
|
if (alignment != 0)
|
|
|
|
print_file(file, indent, "_StubMsg.Buffer += %u;\n", alignment);
|
2005-12-08 12:53:58 +01:00
|
|
|
|
2005-12-26 13:09:36 +01:00
|
|
|
print_file(file, indent, "*(");
|
|
|
|
write_type(file, var->type, var, var->tname);
|
|
|
|
fprintf(file, " *)_StubMsg.Buffer = ");
|
|
|
|
write_name(file, var);
|
|
|
|
fprintf(file, ";\n");
|
|
|
|
fprintf(file, "_StubMsg.Buffer += sizeof(");
|
|
|
|
write_type(file, var->type, var, var->tname);
|
|
|
|
fprintf(file, ");\n");
|
2005-12-08 12:53:58 +01:00
|
|
|
|
2005-12-26 13:09:36 +01:00
|
|
|
last_size = size;
|
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
else if ((var->ptr_level == 1 && !var->array) ||
|
|
|
|
(var->ptr_level == 0 && var->array))
|
2005-12-26 13:12:03 +01:00
|
|
|
{
|
|
|
|
if (is_attr(var->attrs, ATTR_STRING))
|
|
|
|
{
|
|
|
|
switch (var->type->type)
|
|
|
|
{
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
print_file(file, indent,
|
|
|
|
"NdrConformantStringMarshall(&_StubMsg, (unsigned char *)%s, &__MIDL_TypeFormatString.Format[%d]);\n",
|
|
|
|
var->name, *type_offset);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("marshall_arguments: Unsupported [string] type: %s (0x%02x, ptr_level: 1)\n", var->name, var->type->type);
|
|
|
|
}
|
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
else if (var->array)
|
|
|
|
{
|
|
|
|
const expr_t *length_is = get_attrp(var->attrs, ATTR_LENGTHIS);
|
|
|
|
const expr_t *size_is = get_attrp(var->attrs, ATTR_SIZEIS);
|
|
|
|
const char *array_type;
|
|
|
|
int has_length = length_is && (length_is->type != EXPR_VOID);
|
|
|
|
int has_size = size_is && (size_is->type != EXPR_VOID) && !var->array->is_const;
|
|
|
|
|
|
|
|
if (NEXT_LINK(var->array)) /* multi-dimensional array */
|
|
|
|
array_type = "ComplexArray";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!has_length && !has_size)
|
|
|
|
array_type = "FixedArray";
|
|
|
|
else if (has_length && !has_size)
|
2005-12-31 13:19:13 +01:00
|
|
|
{
|
|
|
|
print_file(file, indent, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
|
|
|
|
print_file(file, indent, "_StubMsg.ActualCount = (unsigned long)");
|
|
|
|
write_expr(file, length_is, 1);
|
|
|
|
fprintf(file, ";\n\n");
|
2005-12-26 13:13:41 +01:00
|
|
|
array_type = "VaryingArray";
|
2005-12-31 13:19:13 +01:00
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
else if (!has_length && has_size)
|
2005-12-31 13:19:13 +01:00
|
|
|
{
|
|
|
|
print_file(file, indent, "_StubMsg.MaxCount = (unsigned long)");
|
|
|
|
write_expr(file, size_is ? size_is : var->array, 1);
|
|
|
|
fprintf(file, ";\n\n");
|
2005-12-26 13:13:41 +01:00
|
|
|
array_type = "ConformantArray";
|
2005-12-31 13:19:13 +01:00
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
else
|
2005-12-31 13:19:13 +01:00
|
|
|
{
|
|
|
|
print_file(file, indent, "_StubMsg.MaxCount = (unsigned long)");
|
|
|
|
write_expr(file, size_is ? size_is : var->array, 1);
|
|
|
|
fprintf(file, ";\n");
|
|
|
|
print_file(file, indent, "_StubMsg.Offset = (unsigned long)0;\n"); /* FIXME */
|
|
|
|
print_file(file, indent, "_StubMsg.ActualCount = (unsigned long)");
|
|
|
|
write_expr(file, length_is, 1);
|
|
|
|
fprintf(file, ";\n\n");
|
2005-12-26 13:13:41 +01:00
|
|
|
array_type = "ConformantVaryingArray";
|
2005-12-31 13:19:13 +01:00
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, indent,
|
|
|
|
"Ndr%sMarshall(&_StubMsg, (unsigned char *)%s, &__MIDL_TypeFormatString.Format[%d]);\n",
|
|
|
|
array_type, var->name, *type_offset);
|
|
|
|
}
|
2005-12-26 13:12:03 +01:00
|
|
|
else
|
|
|
|
{
|
2005-12-26 13:22:05 +01:00
|
|
|
const char *ndrtype;
|
|
|
|
|
2005-12-26 13:12:03 +01:00
|
|
|
switch (var->type->type)
|
|
|
|
{
|
2005-12-26 13:22:05 +01:00
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
ndrtype = "SimpleStruct";
|
|
|
|
break;
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
ndrtype = "ConformantStruct";
|
|
|
|
break;
|
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
ndrtype = "ConformantVaryingStruct";
|
|
|
|
break;
|
|
|
|
case RPC_FC_BOGUS_STRUCT:
|
|
|
|
ndrtype = "ComplexStruct";
|
|
|
|
break;
|
2005-12-26 13:12:03 +01:00
|
|
|
default:
|
2005-12-26 13:22:05 +01:00
|
|
|
error("marshall_arguments: Unsupported type: %s (0x%02x, ptr_level: %d)\n",
|
|
|
|
var->name, var->type->type, var->ptr_level);
|
|
|
|
ndrtype = NULL;
|
2005-12-26 13:12:03 +01:00
|
|
|
}
|
2005-12-26 13:22:05 +01:00
|
|
|
|
|
|
|
print_file(file, indent,
|
|
|
|
"Ndr%sMarshall(&_StubMsg, (unsigned char *)%s, &__MIDL_TypeFormatString.Format[%d]);\n",
|
|
|
|
ndrtype, var->name, *type_offset);
|
2005-12-26 13:12:03 +01:00
|
|
|
}
|
|
|
|
last_size = 1;
|
|
|
|
}
|
2005-12-26 13:09:36 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error("marshall_arguments: Pointer level %d not supported for variable %s\n", var->ptr_level, var->name);
|
2005-12-26 13:12:03 +01:00
|
|
|
last_size = 1;
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
fprintf(file, "\n");
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:14:28 +01:00
|
|
|
void unmarshall_arguments(FILE *file, int indent, func_t *func,
|
|
|
|
unsigned int *type_offset, enum pass pass)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
|
|
|
unsigned int last_size = 0;
|
|
|
|
var_t *var;
|
|
|
|
|
|
|
|
if (!func->args)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var = func->args;
|
|
|
|
while (NEXT_LINK(var)) var = NEXT_LINK(var);
|
2005-12-26 13:12:46 +01:00
|
|
|
for (; var; *type_offset += get_size_typeformatstring_var(var), var = PREV_LINK(var))
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:14:28 +01: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;
|
|
|
|
|
|
|
|
switch (pass)
|
|
|
|
{
|
|
|
|
case PASS_IN:
|
|
|
|
if (!in_attr)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case PASS_OUT:
|
|
|
|
if (!out_attr)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case PASS_RETURN:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-12-26 13:13:04 +01:00
|
|
|
if (var->ptr_level == 0 && !var->array)
|
2005-12-08 12:52:13 +01:00
|
|
|
{
|
2005-12-26 13:09:36 +01:00
|
|
|
unsigned int size;
|
|
|
|
unsigned int alignment = 0;
|
2005-12-08 12:53:58 +01:00
|
|
|
|
2005-12-26 13:09:36 +01:00
|
|
|
switch (var->type->type)
|
|
|
|
{
|
|
|
|
case RPC_FC_BYTE:
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_SMALL:
|
|
|
|
case RPC_FC_USMALL:
|
|
|
|
size = 1;
|
|
|
|
alignment = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
case RPC_FC_USHORT:
|
|
|
|
case RPC_FC_SHORT:
|
|
|
|
size = 2;
|
|
|
|
if (last_size != 0 && last_size < 2)
|
|
|
|
alignment = (2 - last_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_ULONG:
|
|
|
|
case RPC_FC_LONG:
|
|
|
|
case RPC_FC_FLOAT:
|
|
|
|
case RPC_FC_ERROR_STATUS_T:
|
|
|
|
size = 4;
|
|
|
|
if (last_size != 0 && last_size < 4)
|
|
|
|
alignment = (4 - last_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RPC_FC_HYPER:
|
|
|
|
case RPC_FC_DOUBLE:
|
|
|
|
size = 8;
|
|
|
|
if (last_size != 0 && last_size < 4)
|
|
|
|
alignment = (4 - last_size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-12-26 13:12:03 +01:00
|
|
|
error("unmarshall_arguments: Unsupported type: %s (0x%02x, ptr_level: 0)\n", var->name, var->type->type);
|
2005-12-26 13:09:36 +01:00
|
|
|
size = 0;
|
|
|
|
}
|
2005-12-08 12:53:58 +01:00
|
|
|
|
2005-12-26 13:09:36 +01:00
|
|
|
if (alignment != 0)
|
|
|
|
print_file(file, indent, "_StubMsg.Buffer += %u;\n", alignment);
|
2005-12-08 12:53:58 +01:00
|
|
|
|
2005-12-26 13:09:36 +01:00
|
|
|
print_file(file, indent, "");
|
|
|
|
write_name(file, var);
|
|
|
|
fprintf(file, " = *(");
|
|
|
|
write_type(file, var->type, var, var->tname);
|
|
|
|
fprintf(file, " *)_StubMsg.Buffer;\n");
|
|
|
|
fprintf(file, "_StubMsg.Buffer += sizeof(");
|
|
|
|
write_type(file, var->type, var, var->tname);
|
|
|
|
fprintf(file, ");\n");
|
2005-12-08 12:53:58 +01:00
|
|
|
|
2005-12-26 13:09:36 +01:00
|
|
|
last_size = size;
|
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
else if ((var->ptr_level == 1 && !var->array) ||
|
|
|
|
(var->ptr_level == 0 && var->array))
|
2005-12-26 13:12:03 +01:00
|
|
|
{
|
|
|
|
if (is_attr(var->attrs, ATTR_STRING))
|
|
|
|
{
|
|
|
|
switch (var->type->type)
|
|
|
|
{
|
|
|
|
case RPC_FC_CHAR:
|
|
|
|
case RPC_FC_WCHAR:
|
|
|
|
print_file(file, indent,
|
|
|
|
"NdrConformantStringUnmarshall(&_StubMsg, (unsigned char *)%s, &__MIDL_TypeFormatString.Format[%d], 0);\n",
|
|
|
|
var->name, *type_offset);
|
|
|
|
break;
|
|
|
|
default:
|
2005-12-26 13:13:41 +01:00
|
|
|
error("unmarshall_arguments: Unsupported [string] type: %s (0x%02x, ptr_level: %d)\n",
|
|
|
|
var->name, var->type->type, var->ptr_level);
|
2005-12-26 13:12:03 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
else if (var->array)
|
|
|
|
{
|
|
|
|
const expr_t *length_is = get_attrp(var->attrs, ATTR_LENGTHIS);
|
|
|
|
const expr_t *size_is = get_attrp(var->attrs, ATTR_SIZEIS);
|
|
|
|
const char *array_type;
|
|
|
|
int has_length = length_is && (length_is->type != EXPR_VOID);
|
|
|
|
int has_size = size_is && (size_is->type != EXPR_VOID) && !var->array->is_const;
|
|
|
|
|
|
|
|
if (NEXT_LINK(var->array)) /* multi-dimensional array */
|
|
|
|
array_type = "ComplexArray";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!has_length && !has_size)
|
|
|
|
array_type = "FixedArray";
|
|
|
|
else if (has_length && !has_size)
|
|
|
|
array_type = "VaryingArray";
|
|
|
|
else if (!has_length && has_size)
|
|
|
|
array_type = "ConformantArray";
|
|
|
|
else
|
|
|
|
array_type = "ConformantVaryingArray";
|
|
|
|
}
|
|
|
|
|
|
|
|
print_file(file, indent,
|
|
|
|
"Ndr%sUnmarshall(&_StubMsg, (unsigned char *)%s, &__MIDL_TypeFormatString.Format[%d], 0);\n",
|
|
|
|
array_type, var->name, *type_offset);
|
|
|
|
}
|
2005-12-26 13:12:03 +01:00
|
|
|
else
|
|
|
|
{
|
2005-12-26 13:22:05 +01:00
|
|
|
const char *ndrtype;
|
|
|
|
|
2005-12-26 13:12:03 +01:00
|
|
|
switch (var->type->type)
|
|
|
|
{
|
2005-12-26 13:22:05 +01:00
|
|
|
case RPC_FC_STRUCT:
|
|
|
|
ndrtype = "SimpleStruct";
|
|
|
|
break;
|
|
|
|
case RPC_FC_CSTRUCT:
|
|
|
|
case RPC_FC_CPSTRUCT:
|
|
|
|
ndrtype = "ConformantStruct";
|
|
|
|
break;
|
|
|
|
case RPC_FC_CVSTRUCT:
|
|
|
|
ndrtype = "ConformantVaryingStruct";
|
|
|
|
break;
|
|
|
|
case RPC_FC_BOGUS_STRUCT:
|
|
|
|
ndrtype = "ComplexStruct";
|
|
|
|
break;
|
2005-12-26 13:12:03 +01:00
|
|
|
default:
|
2005-12-26 13:13:41 +01:00
|
|
|
error("unmarshall_arguments: Unsupported type: %s (0x%02x, ptr_level: %d)\n",
|
|
|
|
var->name, var->type->type, var->ptr_level);
|
2005-12-26 13:22:05 +01:00
|
|
|
ndrtype = NULL;
|
2005-12-26 13:12:03 +01:00
|
|
|
}
|
2005-12-26 13:22:05 +01:00
|
|
|
|
|
|
|
print_file(file, indent,
|
|
|
|
"Ndr%sUnmarshall(&_StubMsg, (unsigned char *)%s, &__MIDL_TypeFormatString.Format[%d], 0);\n",
|
|
|
|
ndrtype, var->name, *type_offset);
|
2005-12-26 13:12:03 +01:00
|
|
|
}
|
|
|
|
last_size = 1;
|
|
|
|
}
|
2005-12-26 13:09:36 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error("unmarshall_arguments: Pointer level %d not supported for variable %s\n", var->ptr_level, var->name);
|
2005-12-26 13:12:03 +01:00
|
|
|
last_size = 1;
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
2005-12-26 13:13:41 +01:00
|
|
|
fprintf(file, "\n");
|
2005-12-08 12:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-26 13:05:29 +01:00
|
|
|
|
|
|
|
|
2006-01-24 11:05:51 +01:00
|
|
|
size_t get_size_procformatstring_var(const var_t *var)
|
2005-12-26 13:05:29 +01:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2005-12-26 13:22:32 +01:00
|
|
|
return write_typeformatstring_type(NULL, 0, var->type, var->ptr_level,
|
|
|
|
var->array, var->name);
|
2005-12-26 13:05:29 +01:00
|
|
|
}
|