fix struct parsing and printing

This commit is contained in:
Bill Currie 2003-07-31 06:17:49 +00:00
parent 9f0d4cc746
commit ae8e7553ce

View file

@ -282,7 +282,7 @@ print_type (type_t *type)
printf (" %s", type->s.class->name); printf (" %s", type->s.class->name);
break; break;
case ev_struct: case ev_struct:
printf (" %s %s", pr_type_name[type->type], type->name); printf (" %s %s", pr_type_name[type->type], type->s.strct->name);
break; break;
default: default:
printf(" %s", pr_type_name[type->type]); printf(" %s", pr_type_name[type->type]);
@ -295,6 +295,7 @@ _encode_type (dstring_t *encoding, type_t *type, int level)
{ {
struct_field_t *field; struct_field_t *field;
int i, count; int i, count;
struct_t *strct;
switch (type->type) { switch (type->type) {
case ev_void: case ev_void:
@ -365,9 +366,14 @@ _encode_type (dstring_t *encoding, type_t *type, int level)
case ev_struct: case ev_struct:
case ev_object: case ev_object:
case ev_class: case ev_class:
if (type->type == ev_struct) {
strct = type->s.strct;
} else {
strct = type->s.class->ivars;
}
dstring_appendstr (encoding, "{"); dstring_appendstr (encoding, "{");
if (type->name) { if (strct->name) {
dstring_appendstr (encoding, type->name); dstring_appendstr (encoding, strct->name);
} else if (type->type == ev_object || type->type == ev_class) { } else if (type->type == ev_object || type->type == ev_class) {
dstring_appendstr (encoding, type->s.class->name); dstring_appendstr (encoding, type->s.class->name);
} }
@ -474,7 +480,7 @@ _parse_type (const char **str)
strct = 0; strct = 0;
if (name->str[0]) if (name->str[0])
strct = get_struct (name->str, 0); strct = get_struct (name->str, 0);
if (strct) { if (strct && strct->struct_head) {
dstring_delete (name); dstring_delete (name);
if (**str == '=' || **str == '-') { if (**str == '=' || **str == '-') {
(*str)++; (*str)++;
@ -486,16 +492,25 @@ _parse_type (const char **str)
(*str)++; (*str)++;
return strct->type; return strct->type;
} }
if (**str != '=' && **str != '-') { if (**str != '=' && **str != '-' && **str != '}') {
if (( s = strchr (*str, '}')))
*str = s + 1;
dstring_delete (name); dstring_delete (name);
return 0; return 0;
} }
strct = get_struct (*name->str ? name->str : 0, 1); if (!strct) {
if (**str == '-') strct = get_struct (*name->str ? name->str : 0, 1);
init_struct (strct, new_type (), str_union, 0); init_struct (strct, new_type (), str_none, 0);
else }
init_struct (strct, new_type (), str_struct, 0);
dstring_delete (name); dstring_delete (name);
if (**str == '}') {
(*str)++;
return strct->type;
}
if (**str == '-')
strct->stype = str_union;
else
strct->stype = str_struct;
(*str)++; (*str)++;
while (**str && **str != '}') while (**str && **str != '}')
new_struct_field (strct, _parse_type (str), 0, vis_public); new_struct_field (strct, _parse_type (str), 0, vis_public);