Dereference type declarations properly.

svn path=/trunk/; revision=21214
This commit is contained in:
Eric Kohl
2006-02-27 18:11:25 +00:00
parent dbba4749db
commit ff7aef148c
3 changed files with 151 additions and 86 deletions
+7
View File
@@ -1,5 +1,12 @@
ChangeLog
2006-02-27 ekohl
tools/widl/client.c
tools/widl/server.c
- Dereference type declarations properly.
2006-02-27 ekohl
tools/widl/client.c
+90 -55
View File
@@ -120,25 +120,34 @@ get_var_type_offset(var_t *var)
unsigned int toffset = 0;
void *sizeis_attr;
int string_attr;
type_t *type;
type = var->type;
if (var->ptr_level == 0)
{
if ((var->type->type == RPC_FC_RP) &&
(var->type->ref->ref->type == RPC_FC_STRUCT))
if (type->type == RPC_FC_RP)
{
var_t *field = var->type->ref->ref->fields;
int tsize = 9;
while (NEXT_LINK(field)) field = NEXT_LINK(field);
while (field)
{
tsize++;
field = PREV_LINK(field);
}
if (tsize % 2)
tsize++;
while (type->ref)
type = type->ref;
toffset += tsize;
if (type->type == RPC_FC_STRUCT)
{
var_t *field = type->fields;
while (NEXT_LINK(field)) field = NEXT_LINK(field);
while (field)
{
tsize++;
field = PREV_LINK(field);
}
if (tsize % 2)
tsize++;
toffset += tsize;
}
}
}
else if (var->ptr_level == 1)
@@ -150,20 +159,20 @@ get_var_type_offset(var_t *var)
{
if (string_attr)
{
if (var->type->type == RPC_FC_BYTE ||
var->type->type == RPC_FC_CHAR ||
var->type->type == RPC_FC_WCHAR)
if (type->type == RPC_FC_BYTE ||
type->type == RPC_FC_CHAR ||
type->type == RPC_FC_WCHAR)
toffset += 10;
}
else
{
if (is_base_type(var->type))
if (is_base_type(type))
toffset += 14;
}
}
else
{
if (is_base_type(var->type))
if (is_base_type(type))
toffset += 4;
}
}
@@ -467,11 +476,12 @@ static void write_typeformatstring(type_t *iface)
return;
}
type = var->type;
if (var->ptr_level == 0)
{
if (!is_base_type(var->type))
if (!is_base_type(type))
{
if (var->type->type == RPC_FC_RP)
if (type->type == RPC_FC_RP)
{
var_t *field;
int tsize = 9;
@@ -480,13 +490,16 @@ static void write_typeformatstring(type_t *iface)
if (!in_attr && out_attr)
flags |= RPC_FC_P_ONSTACK;
while (type->ref)
type = type->ref;
print_client("0x11, 0x%02X, /* FC_RP, [flags] */\n", flags);
print_client("NdrFcShort(0x%02X),\n", 0x02);
print_client("0x%02X,\n", var->type->ref->ref->type);
print_client("0x%02X,\n", type->type);
print_client("0x%02X,\n", 3); /* alignment - 1 */
print_client("NdrFcShort(0x%02X),\n", get_type_size(var->type->ref->ref, 4));
print_client("NdrFcShort(0x%02X),\n", get_type_size(type, 4));
field = var->type->ref->ref->fields;
field = type->fields;
while (NEXT_LINK(field)) field = NEXT_LINK(field);
while (field)
{
@@ -505,7 +518,7 @@ static void write_typeformatstring(type_t *iface)
{
error("%s:%d Unknown/unsupported type 0x%x\n",
__FILE__,__LINE__, var->type->type);
__FILE__,__LINE__, type->type);
return;
}
}
@@ -577,7 +590,7 @@ static void write_typeformatstring(type_t *iface)
print_client("0x5b, /* FC_END */\n");
}
}
else if (is_base_type(var->type))
else if (is_base_type(type))
{
if (out_attr && !in_attr)
{
@@ -600,9 +613,9 @@ static void write_typeformatstring(type_t *iface)
if (string_attr)
{
if (var->type->type == RPC_FC_CHAR)
if (type->type == RPC_FC_CHAR)
print_client("0x%02x, /* FC_C_CSTRING */\n", RPC_FC_C_CSTRING);
else if (var->type->type == RPC_FC_WCHAR)
else if (type->type == RPC_FC_WCHAR)
print_client("0x%02x, /* FC_C_WSTRING */\n", RPC_FC_C_WSTRING);
else
{
@@ -646,6 +659,7 @@ static void print_message_buffer_size(func_t *func, unsigned int *type_offset)
int padding = 0, first_padding = 0;
void *sizeis_attr;
var_t *var;
type_t *type;
print_client("_StubMsg.BufferLength =");
if (func->args)
@@ -675,12 +689,14 @@ static void print_message_buffer_size(func_t *func, unsigned int *type_offset)
string_attr = is_attr(var->attrs, ATTR_STRING);
sizeis_attr = get_attrp(var->attrs, ATTR_SIZEIS);
type = var->type;
if (var->ptr_level == 1)
{
if (string_attr && !sizeis_attr)
{
/* non-sized conformant string */
if (var->type->type == RPC_FC_CHAR || var->type->type == RPC_FC_WCHAR)
if (type->type == RPC_FC_CHAR || type->type == RPC_FC_WCHAR)
{
size = (unique_attr) ? 16 : 12;
alignment = 0;
@@ -697,10 +713,10 @@ static void print_message_buffer_size(func_t *func, unsigned int *type_offset)
else if (!sizeis_attr && !string_attr)
{
/* simple pointers */
if (is_base_type(var->type))
if (is_base_type(type))
{
alignment = 0;
switch (var->type->type)
switch (type->type)
{
case RPC_FC_BYTE:
case RPC_FC_CHAR:
@@ -756,7 +772,7 @@ static void print_message_buffer_size(func_t *func, unsigned int *type_offset)
else
{
alignment = 0;
switch (var->type->type)
switch (type->type)
{
case RPC_FC_BYTE:
case RPC_FC_CHAR:
@@ -818,7 +834,7 @@ static void print_message_buffer_size(func_t *func, unsigned int *type_offset)
if (string_attr && !sizeis_attr)
{
/* non-sized conformant string */
if (var->type->type == RPC_FC_CHAR || var->type->type == RPC_FC_WCHAR)
if (type->type == RPC_FC_CHAR || type->type == RPC_FC_WCHAR)
{
first_padding = 3;
padding = 3;
@@ -868,29 +884,36 @@ static void print_message_buffer_size(func_t *func, unsigned int *type_offset)
string_attr = is_attr(var->attrs, ATTR_STRING);
sizeis_attr = get_attrp(var->attrs, ATTR_SIZEIS);
type = var->type;
if (in_attr)
{
if (var->ptr_level == 0)
{
if (var->type->type == RPC_FC_RP &&
var->type->ref->ref->type == RPC_FC_STRUCT)
if (type->type == RPC_FC_RP)
{
print_client("NdrSimpleStructBufferSize(\n");
indent++;
print_client("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
print_client("(unsigned char __RPC_FAR *)%s,\n", var->name);
print_client("(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%u]);\n",
local_type_offset + 4);
nothing_printed = 1;
indent--;
while (type->ref)
type = type->ref;
if (type->type == RPC_FC_STRUCT)
{
print_client("NdrSimpleStructBufferSize(\n");
indent++;
print_client("(PMIDL_STUB_MESSAGE)&_StubMsg,\n");
print_client("(unsigned char __RPC_FAR *)%s,\n", var->name);
print_client("(PFORMAT_STRING)&__MIDL_TypeFormatString.Format[%u]);\n",
local_type_offset + 4);
nothing_printed = 1;
indent--;
}
}
}
else if (var->ptr_level == 1)
{
if (string_attr)
{
if ((var->type->type == RPC_FC_CHAR ||
var->type->type == RPC_FC_WCHAR))
if ((type->type == RPC_FC_CHAR ||
type->type == RPC_FC_WCHAR))
{
if (ref_attr)
{
@@ -983,6 +1006,7 @@ static void marshall_in_arguments(func_t *func, unsigned int *type_offset)
void *sizeis_attr;
var_t *var;
int default_align = 0;
type_t *type;
if (!func->args)
return;
@@ -998,6 +1022,8 @@ static void marshall_in_arguments(func_t *func, unsigned int *type_offset)
if (!out_attr && !in_attr)
in_attr = 1;
type = var->type;
if (in_attr)
{
if (var->ptr_level > 1)
@@ -1038,7 +1064,7 @@ static void marshall_in_arguments(func_t *func, unsigned int *type_offset)
}
else
if (string_attr &&
(var->type->type == RPC_FC_CHAR || var->type->type == RPC_FC_WCHAR))
(type->type == RPC_FC_CHAR || type->type == RPC_FC_WCHAR))
{
print_client("NdrConformantStringMarshall(\n");
indent++;
@@ -1053,7 +1079,7 @@ static void marshall_in_arguments(func_t *func, unsigned int *type_offset)
else
{
alignment = 0;
switch (var->type->type)
switch (type->type)
{
case RPC_FC_BYTE:
case RPC_FC_CHAR:
@@ -1145,10 +1171,10 @@ static void marshall_in_arguments(func_t *func, unsigned int *type_offset)
}
else
{
if (is_base_type(var->type))
if (is_base_type(type))
{
alignment = 0;
switch (var->type->type)
switch (type->type)
{
case RPC_FC_BYTE:
case RPC_FC_CHAR:
@@ -1218,9 +1244,12 @@ static void marshall_in_arguments(func_t *func, unsigned int *type_offset)
last_size = size;
}
}
else if (var->type->type == RPC_FC_RP)
else if (type->type == RPC_FC_RP)
{
if (var->type->ref->ref->type == RPC_FC_STRUCT)
while (type->ref)
type = type->ref;
if (type->type == RPC_FC_STRUCT)
{
print_client("NdrSimpleStructMarshall(\n");
indent++;
@@ -1255,6 +1284,7 @@ static void unmarshall_out_arguments(func_t *func, unsigned int *type_offset)
var_t *def;
unsigned int local_type_offset = *type_offset;
int default_align = 0;
type_t *type;
def = func->def;
@@ -1275,6 +1305,8 @@ static void unmarshall_out_arguments(func_t *func, unsigned int *type_offset)
if (ptr_attr + ref_attr + unique_attr == 0)
ref_attr = 1;
type = var->type;
if (out_attr)
{
if (var->ptr_level > 1)
@@ -1315,10 +1347,10 @@ static void unmarshall_out_arguments(func_t *func, unsigned int *type_offset)
default_align = 1;
}
}
else if (is_base_type(var->type))
else if (is_base_type(type))
{
alignment = 0;
switch (var->type->type)
switch (type->type)
{
case RPC_FC_BYTE:
case RPC_FC_CHAR:
@@ -1356,7 +1388,7 @@ static void unmarshall_out_arguments(func_t *func, unsigned int *type_offset)
default:
error("%s:%d Unknown/unsupported type 0x%x\n",
__FILE__,__LINE__, var->type->type);
__FILE__,__LINE__, type->type);
return;
}
@@ -1407,9 +1439,12 @@ static void unmarshall_out_arguments(func_t *func, unsigned int *type_offset)
last_size = size;
}
}
else if (var->type->type == RPC_FC_RP)
else if (type->type == RPC_FC_RP)
{
if (var->type->ref->ref->type == RPC_FC_STRUCT)
while (type->ref)
type = type->ref;
if (type->type == RPC_FC_STRUCT)
{
fprintf(client, "\n");
print_client("NdrSimpleStructUnmarshall(\n");
@@ -1427,7 +1462,7 @@ static void unmarshall_out_arguments(func_t *func, unsigned int *type_offset)
else
{
error("%s:%d Unknown/unsupported type 0x%x\n",
__FILE__,__LINE__, var->type->type);
__FILE__,__LINE__, type->type);
return;
}
}
+54 -31
View File
@@ -125,25 +125,34 @@ get_var_type_offset(var_t *var)
unsigned int toffset = 0;
void *sizeis_attr;
int string_attr;
type_t *type;
type = var->type;
if (var->ptr_level == 0)
{
if ((var->type->type == RPC_FC_RP) &&
(var->type->ref->ref->type == RPC_FC_STRUCT))
if (type->type == RPC_FC_RP)
{
var_t *field = var->type->ref->ref->fields;
int tsize = 9;
while (NEXT_LINK(field)) field = NEXT_LINK(field);
while (field)
{
tsize++;
field = PREV_LINK(field);
}
if (tsize % 2)
tsize++;
while (type->ref)
type = type->ref;
toffset += tsize;
if (type->type == RPC_FC_STRUCT)
{
var_t *field = type->fields;
while (NEXT_LINK(field)) field = NEXT_LINK(field);
while (field)
{
tsize++;
field = PREV_LINK(field);
}
if (tsize % 2)
tsize++;
toffset += tsize;
}
}
}
else if (var->ptr_level == 1)
@@ -155,20 +164,20 @@ get_var_type_offset(var_t *var)
{
if (string_attr)
{
if (var->type->type == RPC_FC_BYTE ||
var->type->type == RPC_FC_CHAR ||
var->type->type == RPC_FC_WCHAR)
if (type->type == RPC_FC_BYTE ||
type->type == RPC_FC_CHAR ||
type->type == RPC_FC_WCHAR)
toffset += 10;
}
else
{
if (is_base_type(var->type))
if (is_base_type(type))
toffset += 14;
}
}
else
{
if (is_base_type(var->type))
if (is_base_type(type))
toffset += 4;
}
}
@@ -464,11 +473,12 @@ static void write_typeformatstring(type_t *iface)
return;
}
type = var->type;
if (var->ptr_level == 0)
{
if (!is_base_type(var->type))
if (!is_base_type(type))
{
if (var->type->type == RPC_FC_RP)
if (type->type == RPC_FC_RP)
{
var_t *field;
int tsize = 9;
@@ -477,13 +487,16 @@ static void write_typeformatstring(type_t *iface)
if (!in_attr & out_attr)
flags |= RPC_FC_P_ONSTACK;
while (type->ref)
type = type->ref;
print_server("0x11, 0x%02X, /* FC_RP, [flags] */\n", flags);
print_server("NdrFcShort(0x%02X),\n", 0x02);
print_server("0x%02X,\n", var->type->ref->ref->type);
print_server("0x%02X,\n", type->type);
print_server("0x%02X,\n", 3); /* alignment - 1 */
print_server("NdrFcShort(0x%02X),\n", get_type_size(var->type->ref->ref, 4));
print_server("NdrFcShort(0x%02X),\n", get_type_size(type, 4));
field = var->type->ref->ref->fields;
field = type->fields;
while (NEXT_LINK(field)) field = NEXT_LINK(field);
while (field)
{
@@ -502,7 +515,7 @@ static void write_typeformatstring(type_t *iface)
{
error("%s:%d Unknown/unsupported type 0x%x\n",
__FILE__,__LINE__, var->type->type);
__FILE__,__LINE__, type->type);
return;
}
}
@@ -573,7 +586,7 @@ static void write_typeformatstring(type_t *iface)
print_server("0x5b, /* FC_END */\n");
}
}
else if (is_base_type(var->type))
else if (is_base_type(type))
{
if (out_attr && !in_attr)
{
@@ -992,6 +1005,7 @@ static void unmarshall_in_arguments(func_t *func, unsigned int *type_offset)
int ptr_attr, ref_attr, unique_attr;
void *sizeis_attr;
int default_align = 0;
type_t *type;
if (!func->args)
return;
@@ -1010,6 +1024,8 @@ static void unmarshall_in_arguments(func_t *func, unsigned int *type_offset)
string_attr = is_attr(var->attrs, ATTR_STRING);
sizeis_attr = get_attrp(var->attrs, ATTR_SIZEIS);
type = var->type;
if (in_attr)
{
if (var->ptr_level == 1)
@@ -1024,7 +1040,7 @@ static void unmarshall_in_arguments(func_t *func, unsigned int *type_offset)
{
if (string_attr)
{
if (var->type->type == RPC_FC_CHAR || var->type->type == RPC_FC_WCHAR)
if (type->type == RPC_FC_CHAR || type->type == RPC_FC_WCHAR)
{
print_server("NdrConformantStringUnmarshall(\n");
indent++;
@@ -1054,7 +1070,7 @@ static void unmarshall_in_arguments(func_t *func, unsigned int *type_offset)
else
{
alignment = 0;
switch (var->type->type)
switch (type->type)
{
case RPC_FC_BYTE:
case RPC_FC_CHAR:
@@ -1139,10 +1155,10 @@ static void unmarshall_in_arguments(func_t *func, unsigned int *type_offset)
}
else
{
if (is_base_type(var->type))
if (is_base_type(type))
{
alignment = 0;
switch (var->type->type)
switch (type->type)
{
case RPC_FC_BYTE:
case RPC_FC_CHAR:
@@ -1209,9 +1225,12 @@ static void unmarshall_in_arguments(func_t *func, unsigned int *type_offset)
last_size = size;
}
}
else if (var->type->type == RPC_FC_RP)
else if (type->type == RPC_FC_RP)
{
if (var->type->ref->ref->type == RPC_FC_STRUCT)
while (type->ref)
type = type->ref;
if (type->type == RPC_FC_STRUCT)
{
print_server("NdrSimpleStructUnmarshall(\n");
indent++;
@@ -1641,8 +1660,12 @@ static void write_function_stubs(type_t *iface)
{
if (var->type->type == RPC_FC_RP)
{
type_t *type = var->type;
while (type->ref)
type = type->ref;
print_server("struct ");
write_type(server, NULL, NULL, var->type->ref->ref->name);
write_type(server, NULL, NULL, type->name);
fprintf(server, " _%sW;\n", var->name);
}
else