[vkgen] Make labeled arrays independent of struct order

It turns out labeled arrays don't work if structs aren't declared in the
right order (no idea what that is, though) as the struct might not have
been processed when the labeled array field is initialized. Thus, do a
pro-processing pass to set up any parse data prior to writing the
tables.
This commit is contained in:
Bill Currie 2023-02-26 20:36:53 +09:00
parent b103709bfd
commit 461bb9f434
6 changed files with 31 additions and 5 deletions

View file

@ -19,12 +19,13 @@
pltype = str_hold (parseItemType ([desc getObjectAtIndex:1]));
parser = str_hold ([[desc getObjectAtIndex:2] string]);
fields = [item getObjectForKey:"fields"];
fields = [[item getObjectForKey:"fields"] retain];
return self;
}
-(void)dealloc
{
[fields release];
str_free (pltype);
str_free (parser);
[super dealloc];

View file

@ -226,6 +226,7 @@ main(int argc, string *argv)
arp_start ();
[obj writeForward];
[obj initParse:[parse getObjectForKey:[obj name]]];
arp_end ();
}
for (int i = [output_types count]; i-- > 0; ) {

View file

@ -13,6 +13,11 @@
string outname;
string label_field;
int write_symtab;
int skip;
Array *field_defs;
PLItem *field_dict;
PLItem *only;
}
-(void) queueFieldTypes;
-(qfot_var_t *)findField:(string) fieldName;

View file

@ -15,8 +15,12 @@
-(void) dealloc
{
[field_dict release];
[field_defs release];
[only release];
str_free (outname);
str_free (label_field);
[super dealloc];
}
-(string) name
@ -365,21 +369,23 @@ write_table (Struct *self, PLItem *field_dict, Array *field_defs,
}
}
-(void) writeTable
-(void) initParse:(PLItem *)parse
{
if ([parse string] == "skip") {
skip = 1;
return;
}
PLItem *field_dict = [parse getObjectForKey:[self name]];
field_dict = [parse retain];
PLItem *new_name = [field_dict getObjectForKey:".name"];
if (new_name) {
outname = str_hold ([new_name string]);
}
Array *field_defs = [Array array];
PLItem *only = [field_dict getObjectForKey:".only"];
field_defs = [[Array array] retain];
only = [[field_dict getObjectForKey:".only"] retain];
if (only) {
string field_name = [only string];
qfot_var_t *field = nil;
@ -429,6 +435,13 @@ write_table (Struct *self, PLItem *field_dict, Array *field_defs,
[field_defs addObject: field_def];
}
}
}
-(void) writeTable
{
if (skip) {
return;
}
if ([field_dict getObjectForKey:".type"]) {
PLItem *type = [field_dict getObjectForKey:".type"];

View file

@ -6,6 +6,7 @@
@class FieldDef;
@class Struct;
@class PLItem;
@interface Type: Object
{
@ -21,6 +22,7 @@
-(string) name;
-(void) setAlias: (Type *) alias;
-(void) addToQueue;
-(void) initParse:(PLItem *)parse;
-(Type *) resolveType;
+(Type *) findType: (qfot_type_t *) type;
+(Type *) lookup: (string) name;

View file

@ -110,6 +110,10 @@ static string get_type_key (void *type, void *unused)
}
}
-(void) initParse:(PLItem *)parse
{
}
-(Type *) resolveType
{
return self;