From 461bb9f434e8ff5085f643bb2d67634a1ab998c3 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 26 Feb 2023 20:36:53 +0900 Subject: [PATCH] [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. --- .../renderer/vulkan/vkgen/vkfieldcustom.r | 3 ++- libs/video/renderer/vulkan/vkgen/vkgen.r | 1 + libs/video/renderer/vulkan/vkgen/vkstruct.h | 5 +++++ libs/video/renderer/vulkan/vkgen/vkstruct.r | 21 +++++++++++++++---- libs/video/renderer/vulkan/vkgen/vktype.h | 2 ++ libs/video/renderer/vulkan/vkgen/vktype.r | 4 ++++ 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldcustom.r b/libs/video/renderer/vulkan/vkgen/vkfieldcustom.r index 2f11e0987..2473a91db 100644 --- a/libs/video/renderer/vulkan/vkgen/vkfieldcustom.r +++ b/libs/video/renderer/vulkan/vkgen/vkfieldcustom.r @@ -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]; diff --git a/libs/video/renderer/vulkan/vkgen/vkgen.r b/libs/video/renderer/vulkan/vkgen/vkgen.r index c938bbc5e..2f69d871a 100644 --- a/libs/video/renderer/vulkan/vkgen/vkgen.r +++ b/libs/video/renderer/vulkan/vkgen/vkgen.r @@ -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; ) { diff --git a/libs/video/renderer/vulkan/vkgen/vkstruct.h b/libs/video/renderer/vulkan/vkgen/vkstruct.h index 095c22629..f2c86db29 100644 --- a/libs/video/renderer/vulkan/vkgen/vkstruct.h +++ b/libs/video/renderer/vulkan/vkgen/vkstruct.h @@ -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; diff --git a/libs/video/renderer/vulkan/vkgen/vkstruct.r b/libs/video/renderer/vulkan/vkgen/vkstruct.r index 0194aaeaa..ab37159ca 100644 --- a/libs/video/renderer/vulkan/vkgen/vkstruct.r +++ b/libs/video/renderer/vulkan/vkgen/vkstruct.r @@ -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"]; diff --git a/libs/video/renderer/vulkan/vkgen/vktype.h b/libs/video/renderer/vulkan/vkgen/vktype.h index 66cab0d24..ed3965639 100644 --- a/libs/video/renderer/vulkan/vkgen/vktype.h +++ b/libs/video/renderer/vulkan/vkgen/vktype.h @@ -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; diff --git a/libs/video/renderer/vulkan/vkgen/vktype.r b/libs/video/renderer/vulkan/vkgen/vktype.r index d7d2a9a95..935279a76 100644 --- a/libs/video/renderer/vulkan/vkgen/vktype.r +++ b/libs/video/renderer/vulkan/vkgen/vktype.r @@ -110,6 +110,10 @@ static string get_type_key (void *type, void *unused) } } +-(void) initParse:(PLItem *)parse +{ +} + -(Type *) resolveType { return self;