[vkparse] Add support for inheriting objects

It simply parses the referenced plist dictionary (via @inherit =
plist.path;) into the current data block, then allows the data to be
overwritten by the current plist dictionary. This may be a bit iffy for
any allocated resources, so some care must be taken, but it seems to
work nicely.
This commit is contained in:
Bill Currie 2022-04-03 11:11:28 +09:00
parent bbbdc41af3
commit eb4d566801
2 changed files with 21 additions and 0 deletions

View File

@ -130,6 +130,9 @@
[field_def writeParseData];
}
fprintf (output_file, "static plfield_t %s_fields[] = {\n", [self outname]);
fprintf (output_file,
"\t{\"@inherit\", 0, QFString, parse_inherit, &%s_fields},\n",
[self outname]);
for (int i = [field_defs count]; i-- > 0; ) {
FieldDef *field_def = [field_defs objectAtIndex:i];
[field_def writeField];

View File

@ -376,6 +376,24 @@ parse_custom (const plfield_t *field, const plitem_t *item,
return custom->parse (item, offsets, messages, context);
}
static int
parse_inherit (const plfield_t *field, const plitem_t *item,
void *data, plitem_t *messages, void *context)
{
exprctx_t ectx = *((parsectx_t *)context)->ectx;
plitem_t *inheritItem = 0;
exprval_t result = { &cexpr_plitem, &inheritItem };
ectx.result = &result;
const char *inheritstr = PL_String (item);
Sys_MaskPrintf (SYS_vulkan_parse, "parse_inherit: %s\n", inheritstr);
int ret = !cexpr_eval_string (inheritstr, &ectx);
if (ret) {
ret = PL_ParseStruct (field->data, inheritItem, data, messages,
context);
}
return ret;
}
static int
parse_RGBA (const plitem_t *item, void **data,
plitem_t *messages, parsectx_t *context)