mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 01:41:10 +00:00
[vulkan] Refactor vkgen struct generation
The addition of data an then string support made keeping track of things in struct's writeTable a nightmare.
This commit is contained in:
parent
e1e2a0e712
commit
017d2c1f44
20 changed files with 499 additions and 177 deletions
|
@ -4,6 +4,12 @@ noinst_PROGRAMS += $(vkgen)
|
|||
vkgen_dat_src= \
|
||||
libs/video/renderer/vulkan/vkgen/vkalias.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkenum.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkfieldarray.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkfieldauto.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkfielddata.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkfielddef.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkfieldsingle.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkfieldstring.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkgen.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkstruct.r \
|
||||
libs/video/renderer/vulkan/vkgen/vktype.r \
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
int prefix_length;
|
||||
}
|
||||
-(void) writeTable;
|
||||
-(void) writeSymtabInit:(PLItem *) parse;
|
||||
-(void) writeSymtabInit;
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkenum_h
|
||||
|
|
|
@ -123,7 +123,7 @@ skip_value(string name)
|
|||
fprintf (header_file, "extern exprenum_t %s_enum;\n", [self name]);
|
||||
}
|
||||
|
||||
-(void) writeSymtabInit:(PLItem *) parse
|
||||
-(void) writeSymtabInit
|
||||
{
|
||||
fprintf (output_file, "\tcexpr_init_symtab (&%s_symtab, context);\n",
|
||||
[self name]);
|
||||
|
|
12
libs/video/renderer/vulkan/vkgen/vkfieldarray.h
Normal file
12
libs/video/renderer/vulkan/vkgen/vkfieldarray.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkfieldarray_h
|
||||
#define __renderer_vulkan_vkgen_vkfieldarray_h
|
||||
|
||||
#include "vkfielddef.h"
|
||||
|
||||
@interface ArrayField: FieldDef
|
||||
{
|
||||
string type;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkfieldarray_h
|
52
libs/video/renderer/vulkan/vkgen/vkfieldarray.r
Normal file
52
libs/video/renderer/vulkan/vkgen/vkfieldarray.r
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include <PropertyList.h>
|
||||
|
||||
#include "vkfieldarray.h"
|
||||
#include "vkgen.h"
|
||||
#include "vktype.h"
|
||||
|
||||
@implementation ArrayField
|
||||
|
||||
-init:(PLItem *) item struct:(Struct *)strct field:(string)fname
|
||||
{
|
||||
self = [super init:item struct:strct field:fname];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
PLItem *desc = [item getObjectForKey:"type"];
|
||||
type = [[desc getObjectAtIndex:1] string];
|
||||
|
||||
value_field = [[item getObjectForKey:"values"] string];
|
||||
size_field = [[item getObjectForKey:"size"] string];
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeParseData
|
||||
{
|
||||
Type *field_type = [[Type lookup: type] dereference];
|
||||
|
||||
fprintf (output_file, "static parse_array_t parse_%s_%s_data = {\n",
|
||||
struct_name, field_name);
|
||||
fprintf (output_file, "\t%s,\n", [field_type parseType]);
|
||||
fprintf (output_file, "\tsizeof (%s),\n", type);
|
||||
fprintf (output_file, "\tparse_%s,\n", type);
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
struct_name, value_field);
|
||||
if (size_field) {
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
struct_name, size_field);
|
||||
} else {
|
||||
fprintf (output_file, "\t-1,\n");
|
||||
}
|
||||
fprintf (output_file, "};\n");
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeField
|
||||
{
|
||||
fprintf (output_file, "\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n",
|
||||
field_name, "QFArray", "array", struct_name, field_name);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
9
libs/video/renderer/vulkan/vkgen/vkfieldauto.h
Normal file
9
libs/video/renderer/vulkan/vkgen/vkfieldauto.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkfieldauto_h
|
||||
#define __renderer_vulkan_vkgen_vkfieldauto_h
|
||||
|
||||
#include "vkfielddef.h"
|
||||
|
||||
@interface AutoField: FieldDef
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkfieldauto_h
|
43
libs/video/renderer/vulkan/vkgen/vkfieldauto.r
Normal file
43
libs/video/renderer/vulkan/vkgen/vkfieldauto.r
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "vkfieldauto.h"
|
||||
#include "vkgen.h"
|
||||
#include "vkstruct.h"
|
||||
|
||||
@implementation AutoField
|
||||
|
||||
-init:(PLItem *) item struct:(Struct *)strct field:(string)fname
|
||||
{
|
||||
self = [super init:item struct:strct field:fname];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
field = [strct findField:field_name];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeParseData
|
||||
{
|
||||
printf("FieldDef: '%s' '%s'\n", struct_name, field_name);
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeField
|
||||
{
|
||||
Type *field_type = [Type findType: field.type];
|
||||
fprintf (output_file, "\t{\"%s\", field_offset (%s, %s), %s, %s, %s},\n",
|
||||
field_name, struct_name, field_name,
|
||||
[field_type parseType], [field_type parseFunc],
|
||||
[field_type parseData]);
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeSymbol
|
||||
{
|
||||
Type *field_type = [Type findType: field.type];
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n",
|
||||
field_name, [field_type cexprType], struct_name, field_name);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
9
libs/video/renderer/vulkan/vkgen/vkfielddata.h
Normal file
9
libs/video/renderer/vulkan/vkgen/vkfielddata.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkfielddata_h
|
||||
#define __renderer_vulkan_vkgen_vkfielddata_h
|
||||
|
||||
#include "vkfielddef.h"
|
||||
|
||||
@interface DataField: FieldDef
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkfielddata_h
|
45
libs/video/renderer/vulkan/vkgen/vkfielddata.r
Normal file
45
libs/video/renderer/vulkan/vkgen/vkfielddata.r
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <PropertyList.h>
|
||||
|
||||
#include "vkfielddata.h"
|
||||
#include "vkgen.h"
|
||||
#include "vkstruct.h"
|
||||
#include "vktype.h"
|
||||
|
||||
@implementation DataField
|
||||
|
||||
-init:(PLItem *) item struct:(Struct *)strct field:(string)fname
|
||||
{
|
||||
self = [super init:item struct:strct field:fname];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
value_field = [[item getObjectForKey:"data"] string];
|
||||
size_field = [[item getObjectForKey:"size"] string];
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeParseData
|
||||
{
|
||||
fprintf (output_file, "static parse_data_t parse_%s_%s_data = {\n",
|
||||
struct_name, field_name);
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
struct_name, value_field);
|
||||
if (size_field) {
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
struct_name, size_field);
|
||||
} else {
|
||||
fprintf (output_file, "\tt-1,\n");
|
||||
}
|
||||
fprintf (output_file, "};\n");
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeField
|
||||
{
|
||||
fprintf (output_file, "\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n",
|
||||
field_name, "QFBinary", "data", struct_name, field_name);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
28
libs/video/renderer/vulkan/vkgen/vkfielddef.h
Normal file
28
libs/video/renderer/vulkan/vkgen/vkfielddef.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkfielddef_h
|
||||
#define __renderer_vulkan_vkgen_vkfielddef_h
|
||||
|
||||
#include <types.h>
|
||||
#include <Object.h>
|
||||
|
||||
@class PLItem;
|
||||
@class Struct;
|
||||
@class Type;
|
||||
|
||||
@interface FieldDef: Object
|
||||
{
|
||||
int line;
|
||||
qfot_var_t *field;
|
||||
string struct_name;
|
||||
string field_name;
|
||||
string value_field;
|
||||
string size_field;
|
||||
}
|
||||
+fielddef:(PLItem *)item struct:(Struct *)strct field:(string)fname;
|
||||
-init:(PLItem *)item struct:(Struct *)strct field:(string)fname;
|
||||
-writeParseData;
|
||||
-writeField;
|
||||
-writeSymbol;
|
||||
-(string) name;
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkfielddef_h
|
95
libs/video/renderer/vulkan/vkgen/vkfielddef.r
Normal file
95
libs/video/renderer/vulkan/vkgen/vkfielddef.r
Normal file
|
@ -0,0 +1,95 @@
|
|||
#include <string.h>
|
||||
#include <PropertyList.h>
|
||||
|
||||
#include "vkfieldarray.h"
|
||||
#include "vkfieldauto.h"
|
||||
#include "vkfielddata.h"
|
||||
#include "vkfielddef.h"
|
||||
#include "vkfieldsingle.h"
|
||||
#include "vkfieldstring.h"
|
||||
#include "vkstruct.h"
|
||||
|
||||
@implementation FieldDef
|
||||
|
||||
+fielddef:(PLItem *)item struct:(Struct *)strct field:(string)fname
|
||||
{
|
||||
string record = [item string];
|
||||
PLItem *type_desc = [item getObjectForKey:"type"];
|
||||
|
||||
if (!item) {
|
||||
record = "auto";
|
||||
}
|
||||
if (!record) {
|
||||
if (item && !type_desc) {
|
||||
return nil;
|
||||
}
|
||||
record = [type_desc string];
|
||||
if (!record) {
|
||||
record = [[type_desc getObjectAtIndex:0] string];
|
||||
}
|
||||
}
|
||||
switch (record) {
|
||||
case "auto":
|
||||
return [[[AutoField alloc] init:item struct:strct field:fname] autorelease];
|
||||
case "string":
|
||||
return [[[StringField alloc] init:item struct:strct field:fname] autorelease];
|
||||
case "data":
|
||||
return [[[DataField alloc] init:item struct:strct field:fname] autorelease];
|
||||
case "single":
|
||||
return [[[SingleField alloc] init:item struct:strct field:fname] autorelease];
|
||||
case "array":
|
||||
return [[[ArrayField alloc] init:item struct:strct field:fname] autorelease];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
-init:(PLItem *)item struct:(Struct *)strct field:(string)fname
|
||||
{
|
||||
self = [super init];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
line = [item line];
|
||||
struct_name = str_hold ([strct outname]);
|
||||
field_name = str_hold (fname);
|
||||
return self;
|
||||
}
|
||||
|
||||
-fromField:(qfot_var_t *)field struct:(Struct *)strct
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
str_free (struct_name);
|
||||
str_free (field_name);
|
||||
}
|
||||
|
||||
-writeParseData
|
||||
{
|
||||
fprintf (output_file, "undefined record type parse: %d\n", line);
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeField
|
||||
{
|
||||
fprintf (output_file, "undefined record type field: %d\n", line);
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeSymbol
|
||||
{
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", 0/*FIXME*/, (void *) field_offset (%s, %s)},\n",
|
||||
field_name, struct_name, value_field);
|
||||
return self;
|
||||
}
|
||||
|
||||
-(string) name
|
||||
{
|
||||
return field_name;
|
||||
}
|
||||
|
||||
@end
|
12
libs/video/renderer/vulkan/vkgen/vkfieldsingle.h
Normal file
12
libs/video/renderer/vulkan/vkgen/vkfieldsingle.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkfieldsingle_h
|
||||
#define __renderer_vulkan_vkgen_vkfieldsingle_h
|
||||
|
||||
#include "vkfielddef.h"
|
||||
|
||||
@interface SingleField: FieldDef
|
||||
{
|
||||
string type;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkfieldsingle_h
|
46
libs/video/renderer/vulkan/vkgen/vkfieldsingle.r
Normal file
46
libs/video/renderer/vulkan/vkgen/vkfieldsingle.r
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include <PropertyList.h>
|
||||
|
||||
#include "vkfieldsingle.h"
|
||||
#include "vkgen.h"
|
||||
#include "vktype.h"
|
||||
|
||||
@implementation SingleField
|
||||
|
||||
-init:(PLItem *) item struct:(Struct *)strct field:(string)fname
|
||||
{
|
||||
self = [super init:item struct:strct field:fname];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
PLItem *desc = [item getObjectForKey:"type"];
|
||||
type = [[desc getObjectAtIndex:1] string];
|
||||
|
||||
value_field = [[item getObjectForKey:"value"] string];
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeParseData
|
||||
{
|
||||
Type *field_type = [[Type lookup: type] dereference];
|
||||
|
||||
fprintf (output_file, "static parse_single_t parse_%s_%s_data = {\n",
|
||||
struct_name, field_name);
|
||||
fprintf (output_file, "\t%s,\n", [field_type parseType]);
|
||||
fprintf (output_file, "\tsizeof (%s),\n", type);
|
||||
fprintf (output_file, "\tparse_%s,\n", type);
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
struct_name, value_field);
|
||||
fprintf (output_file, "};\n");
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeField
|
||||
{
|
||||
string parse_type = [[[Type lookup: type] dereference] parseType];
|
||||
fprintf (output_file, "\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n",
|
||||
field_name, parse_type, "single", struct_name, field_name);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
9
libs/video/renderer/vulkan/vkgen/vkfieldstring.h
Normal file
9
libs/video/renderer/vulkan/vkgen/vkfieldstring.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkfieldstring_h
|
||||
#define __renderer_vulkan_vkgen_vkfieldstring_h
|
||||
|
||||
#include "vkfielddef.h"
|
||||
|
||||
@interface StringField: FieldDef
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkfieldstring_h
|
36
libs/video/renderer/vulkan/vkgen/vkfieldstring.r
Normal file
36
libs/video/renderer/vulkan/vkgen/vkfieldstring.r
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <PropertyList.h>
|
||||
|
||||
#include "vkfieldstring.h"
|
||||
#include "vkgen.h"
|
||||
|
||||
@implementation StringField
|
||||
|
||||
-init:(PLItem *) item struct:(Struct *)strct field:(string)fname
|
||||
{
|
||||
self = [super init:item struct:strct field:fname];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
value_field = [[item getObjectForKey:"string"] string];
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeParseData
|
||||
{
|
||||
fprintf (output_file, "static parse_string_t parse_%s_%s_data = {\n",
|
||||
struct_name, field_name);
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
struct_name, value_field);
|
||||
fprintf (output_file, "};\n");
|
||||
return self;
|
||||
}
|
||||
|
||||
-writeField
|
||||
{
|
||||
fprintf (output_file, "\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n",
|
||||
field_name, "QFString", "string", struct_name, field_name);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
|
@ -12,6 +12,7 @@ void printf (string fmt, ...);
|
|||
void fprintf (QFile file, string format, ...);
|
||||
extern Array *queue;
|
||||
extern Array *output_types;
|
||||
extern PLItem *parse;
|
||||
extern QFile output_file;
|
||||
extern QFile header_file;
|
||||
extern hashtab_t *processed_types;
|
||||
|
|
|
@ -37,6 +37,7 @@ hashtab_t *processed_types;
|
|||
Array *queue;
|
||||
Array *output_types;
|
||||
|
||||
PLItem *parse;
|
||||
QFile output_file;
|
||||
QFile header_file;
|
||||
|
||||
|
@ -147,7 +148,6 @@ main(int argc, string *argv)
|
|||
QFile plist_file;
|
||||
PLItem *plist;
|
||||
PLItem *search;
|
||||
PLItem *parse;
|
||||
|
||||
arp_start ();
|
||||
|
||||
|
@ -199,6 +199,9 @@ main(int argc, string *argv)
|
|||
id obj = [queue objectAtIndex:0];
|
||||
[queue removeObjectAtIndex:0];
|
||||
if ([obj class] == [Struct class]) {
|
||||
if ([[parse getObjectForKey:[obj name]] string] == "skip") {
|
||||
continue;
|
||||
}
|
||||
[obj forEachFieldCall:struct_func];
|
||||
}
|
||||
[output_types addObject:obj];
|
||||
|
@ -235,7 +238,7 @@ main(int argc, string *argv)
|
|||
}
|
||||
|
||||
arp_start ();
|
||||
[obj writeTable:parse];
|
||||
[obj writeTable];
|
||||
arp_end ();
|
||||
}
|
||||
fprintf (output_file, "static void\n");
|
||||
|
@ -247,7 +250,7 @@ main(int argc, string *argv)
|
|||
continue;
|
||||
}
|
||||
arp_start ();
|
||||
[obj writeSymtabInit:parse];
|
||||
[obj writeSymtabInit];
|
||||
arp_end ();
|
||||
}
|
||||
fprintf (output_file, "}\n");
|
||||
|
|
|
@ -10,10 +10,13 @@
|
|||
|
||||
@interface Struct: Type
|
||||
{
|
||||
string outname;
|
||||
}
|
||||
-(void) forEachFieldCall: (varfunc) func;
|
||||
-(void) writeTable: (PLItem *) parse;
|
||||
-(void) writeSymtabInit:(PLItem *) parse;
|
||||
-(qfot_var_t *)findField:(string) fieldName;
|
||||
-(void) writeTable;
|
||||
-(void) writeSymtabInit;
|
||||
-(string) outname;
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkstruct_h
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <Array.h>
|
||||
#include <PropertyList.h>
|
||||
|
||||
#include "vkfielddef.h"
|
||||
#include "vkgen.h"
|
||||
#include "vkstruct.h"
|
||||
|
||||
|
@ -46,122 +47,33 @@
|
|||
return nil;
|
||||
}
|
||||
|
||||
-(void) writeTable: (PLItem *) parse
|
||||
-(void) writeTable
|
||||
{
|
||||
string name = [self name];
|
||||
PLItem *field_dict = [parse getObjectForKey:name];
|
||||
PLItem *field_defs = [field_dict allKeys];
|
||||
Type *field_type;
|
||||
PLItem *field_dict = [parse getObjectForKey:[self name]];
|
||||
PLItem *new_name = [field_dict getObjectForKey:".name"];
|
||||
Array *field_defs = [Array array];
|
||||
|
||||
if ([parse string] == "skip") {
|
||||
return;
|
||||
}
|
||||
if (new_name) {
|
||||
name = [new_name string];
|
||||
outname = str_hold ([new_name string]);
|
||||
}
|
||||
|
||||
if (field_defs) {
|
||||
PLItem *field_def;
|
||||
qfot_var_t *field;
|
||||
if (field_dict) {
|
||||
PLItem *field_keys = [field_dict allKeys];
|
||||
|
||||
for (int i = [field_defs count]; i-- > 0; ) {
|
||||
string field_name = [[field_defs getObjectAtIndex:i] string];
|
||||
field_def = [field_dict getObjectForKey:field_name];
|
||||
PLItem *type_desc = [field_def getObjectForKey:"type"];
|
||||
string type_record;
|
||||
string type_type;
|
||||
string size_field = nil;
|
||||
string value_field = nil;
|
||||
for (int i = [field_keys count]; i-- > 0; ) {
|
||||
string field_name = [[field_keys getObjectAtIndex:i] string];
|
||||
|
||||
if (!type_desc || str_mid(field_name, 0, 1) == ".") {
|
||||
continue;
|
||||
}
|
||||
type_record = [[type_desc getObjectAtIndex:0] string];
|
||||
type_type = [[type_desc getObjectAtIndex:1] string];
|
||||
|
||||
field_type = [[Type lookup: type_type] dereference];
|
||||
fprintf (output_file, "static parse_%s_t parse_%s_%s_data = {\n",
|
||||
type_record, name, field_name);
|
||||
if (type_record == "single") {
|
||||
fprintf (output_file, "\t%s,\n", [field_type parseType]);
|
||||
fprintf (output_file, "\tsizeof (%s),\n", type_type);
|
||||
fprintf (output_file, "\tparse_%s,\n", type_type);
|
||||
value_field = [[field_def getObjectForKey:"value"] string];
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
name, value_field);
|
||||
} else if (type_record == "array") {
|
||||
fprintf (output_file, "\t%s,\n", [field_type parseType]);
|
||||
fprintf (output_file, "\tsizeof (%s),\n", type_type);
|
||||
fprintf (output_file, "\tparse_%s,\n", type_type);
|
||||
value_field = [[field_def getObjectForKey:"values"] string];
|
||||
size_field = [[field_def getObjectForKey:"size"] string];
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
name, value_field);
|
||||
if (size_field) {
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
name, size_field);
|
||||
} else {
|
||||
fprintf (output_file, "\t-1,\n");
|
||||
}
|
||||
} else if (type_record == "data") {
|
||||
value_field = [[field_def getObjectForKey:"data"] string];
|
||||
size_field = [[field_def getObjectForKey:"size"] string];
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
name, value_field);
|
||||
if (size_field) {
|
||||
fprintf (output_file, "\tfield_offset (%s, %s),\n",
|
||||
name, size_field);
|
||||
} else {
|
||||
fprintf (output_file, "\t-1,\n");
|
||||
}
|
||||
} else {
|
||||
fprintf (output_file, "\tno type,\n");
|
||||
}
|
||||
fprintf (output_file, "};\n");
|
||||
}
|
||||
}
|
||||
fprintf (output_file, "static plfield_t %s_fields[] = {\n", name);
|
||||
if (field_defs) {
|
||||
PLItem *field_def;
|
||||
qfot_var_t *field;
|
||||
|
||||
for (int i = [field_defs count]; i-- > 0; ) {
|
||||
string field_name = [[field_defs getObjectAtIndex:i] string];
|
||||
if (str_mid(field_name, 0, 1) == ".") {
|
||||
continue;
|
||||
}
|
||||
field_def = [field_dict getObjectForKey:field_name];
|
||||
if ([field_def string] == "auto") {
|
||||
field = [self findField:field_name];
|
||||
if (!field) {
|
||||
continue;
|
||||
}
|
||||
field_type = [Type findType: field.type];
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", field_offset (%s, %s), %s, %s, %s},\n",
|
||||
field_name, name, field_name,
|
||||
[field_type parseType], [field_type parseFunc],
|
||||
[field_type parseData]);
|
||||
} else {
|
||||
PLItem *type_desc = [field_def getObjectForKey:"type"];
|
||||
string type_record;
|
||||
string type_type;
|
||||
string parseType = "no type";
|
||||
|
||||
type_record = [[type_desc getObjectAtIndex:0] string];
|
||||
type_type = [[type_desc getObjectAtIndex:1] string];
|
||||
|
||||
field_type = [[Type lookup: type_type] dereference];
|
||||
if (type_record == "single") {
|
||||
parseType = [field_type parseType];
|
||||
} else if (type_record == "array") {
|
||||
parseType = "QFArray";
|
||||
} else if (type_record == "data") {
|
||||
parseType = "QFBinary";
|
||||
}
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n",
|
||||
field_name, parseType, type_record,
|
||||
name, field_name);
|
||||
}
|
||||
PLItem *field_item = [field_dict getObjectForKey:field_name];
|
||||
FieldDef *field_def = [FieldDef fielddef:field_item
|
||||
struct:self
|
||||
field:field_name];
|
||||
[field_defs addObject: field_def];
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < type.strct.num_fields; i++) {
|
||||
|
@ -169,76 +81,47 @@
|
|||
if (field.name == "sType" || field.name == "pNext") {
|
||||
continue;
|
||||
}
|
||||
field_type = [Type findType: field.type];
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", field_offset (%s, %s), %s, %s, %s},\n",
|
||||
field.name, name, field.name,
|
||||
[field_type parseType], [field_type parseFunc],
|
||||
[field_type parseData]);
|
||||
FieldDef *field_def = [FieldDef fielddef:nil
|
||||
struct:self
|
||||
field:field.name];
|
||||
[field_defs addObject: field_def];
|
||||
}
|
||||
}
|
||||
for (int i = [field_defs count]; i-- > 0; ) {
|
||||
FieldDef *field_def = [field_defs objectAtIndex:i];
|
||||
[field_def writeParseData];
|
||||
}
|
||||
fprintf (output_file, "static plfield_t %s_fields[] = {\n", [self outname]);
|
||||
for (int i = [field_defs count]; i-- > 0; ) {
|
||||
FieldDef *field_def = [field_defs objectAtIndex:i];
|
||||
[field_def writeField];
|
||||
}
|
||||
fprintf (output_file, "\t{ }\n");
|
||||
fprintf (output_file, "};\n");
|
||||
|
||||
fprintf (header_file, "int parse_%s (const plfield_t *field,"
|
||||
" const plitem_t *item, void *data, plitem_t *messages,"
|
||||
" void *context);\n",
|
||||
name);
|
||||
[self outname]);
|
||||
fprintf (output_file, "int parse_%s (const plfield_t *field,"
|
||||
" const plitem_t *item, void *data, plitem_t *messages,"
|
||||
" void *context)\n",
|
||||
name);
|
||||
[self outname]);
|
||||
fprintf (output_file, "{\n");
|
||||
fprintf (output_file,
|
||||
"\treturn PL_ParseDictionary (%s_fields, item, data, messages,"
|
||||
" context);\n",
|
||||
name);
|
||||
[self outname]);
|
||||
fprintf (output_file, "}\n");
|
||||
|
||||
fprintf (output_file, "static exprsym_t %s_symbols[] = {\n", name);
|
||||
fprintf (output_file, "static exprsym_t %s_symbols[] = {\n", [self outname]);
|
||||
if (field_defs) {
|
||||
PLItem *field_def;
|
||||
qfot_var_t *field;
|
||||
|
||||
for (int i = [field_defs count]; i-- > 0; ) {
|
||||
string field_name = [[field_defs getObjectAtIndex:i] string];
|
||||
field_def = [field_dict getObjectForKey:field_name];
|
||||
PLItem *type_desc = [field_def getObjectForKey:"type"];
|
||||
string type_record;
|
||||
string type_type;
|
||||
string size_field = nil;
|
||||
string value_field = nil;
|
||||
|
||||
if (str_mid(field_name, 0, 1) == ".") {
|
||||
continue;
|
||||
}
|
||||
field_def = [field_dict getObjectForKey:field_name];
|
||||
if ([field_def string] == "auto") {
|
||||
field = [self findField:field_name];
|
||||
if (!field) {
|
||||
continue;
|
||||
}
|
||||
field_type = [Type findType: field.type];
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n",
|
||||
field_name, [field_type cexprType], name, field_name);
|
||||
} else {
|
||||
type_record = [[type_desc getObjectAtIndex:0] string];
|
||||
if (type_record == "single") {
|
||||
value_field = [[field_def getObjectForKey:"value"] string];
|
||||
} else if (type_record == "array") {
|
||||
value_field = [[field_def getObjectForKey:"values"] string];
|
||||
} else if (type_record == "data") {
|
||||
value_field = [[field_def getObjectForKey:"data"] string];
|
||||
}
|
||||
if (!value_field) {
|
||||
value_field = field_name;
|
||||
}
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", 0/*FIXME*/,"
|
||||
" (void *) field_offset (%s, %s)},\n",
|
||||
field_name, name, value_field);
|
||||
}
|
||||
FieldDef *field_def = [field_defs objectAtIndex:i];
|
||||
[field_def writeSymbol];
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < type.strct.num_fields; i++) {
|
||||
|
@ -246,40 +129,48 @@
|
|||
if (field.name == "sType" || field.name == "pNext") {
|
||||
continue;
|
||||
}
|
||||
field_type = [Type findType: field.type];
|
||||
Type *field_type = [Type findType: field.type];
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n",
|
||||
field.name, [field_type cexprType], name, field.name);
|
||||
field.name, [field_type cexprType], [self outname], field.name);
|
||||
}
|
||||
}
|
||||
fprintf (output_file, "\t{ }\n");
|
||||
fprintf (output_file, "};\n");
|
||||
|
||||
fprintf (output_file, "static exprtab_t %s_symtab = {\n", name);
|
||||
fprintf (output_file, "\t%s_symbols,\n", name);
|
||||
fprintf (output_file, "static exprtab_t %s_symtab = {\n", [self outname]);
|
||||
fprintf (output_file, "\t%s_symbols,\n", [self outname]);
|
||||
fprintf (output_file, "};\n");
|
||||
|
||||
fprintf (output_file, "exprtype_t %s_type = {\n", name);
|
||||
fprintf (output_file, "\t\"%s\",\n", name);
|
||||
fprintf (output_file, "\tsizeof (%s),\n", name);
|
||||
fprintf (output_file, "exprtype_t %s_type = {\n", [self outname]);
|
||||
fprintf (output_file, "\t\"%s\",\n", [self outname]);
|
||||
fprintf (output_file, "\tsizeof (%s),\n", [self outname]);
|
||||
fprintf (output_file, "\tcexpr_struct_binops,\n");
|
||||
fprintf (output_file, "\t0,\n");
|
||||
fprintf (output_file, "\t&%s_symtab,\n", name);
|
||||
fprintf (output_file, "\t&%s_symtab,\n", [self outname]);
|
||||
fprintf (output_file, "};\n");
|
||||
fprintf (header_file, "extern exprtype_t %s_type;\n", name);
|
||||
fprintf (output_file, "\n");
|
||||
fprintf (header_file, "extern exprtype_t %s_type;\n", [self outname]);
|
||||
}
|
||||
|
||||
-(void) writeSymtabInit:(PLItem *) parse
|
||||
-(void) writeSymtabInit
|
||||
{
|
||||
string name = [self name];
|
||||
PLItem *field_dict = [parse getObjectForKey:name];
|
||||
PLItem *new_name = [field_dict getObjectForKey:".name"];
|
||||
PLItem *field_dict = [parse getObjectForKey:[self outname]];
|
||||
|
||||
if (new_name) {
|
||||
name = [new_name string];
|
||||
if ([parse string] == "skip") {
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf (output_file, "\tcexpr_init_symtab (&%s_symtab, context);\n", name);
|
||||
fprintf (output_file, "\tcexpr_init_symtab (&%s_symtab, context);\n",
|
||||
[self outname]);
|
||||
}
|
||||
|
||||
-(string) outname
|
||||
{
|
||||
if (outname) {
|
||||
return outname;
|
||||
}
|
||||
return [self name];
|
||||
}
|
||||
|
||||
-(string) cexprType
|
||||
|
|
|
@ -122,6 +122,10 @@ typedef struct parse_data_s {
|
|||
size_t size_offset;
|
||||
} parse_data_t;
|
||||
|
||||
typedef struct parse_string_s {
|
||||
size_t value_offset;
|
||||
} parse_string_t;
|
||||
|
||||
static int parse_uint32_t (const plfield_t *field, const plitem_t *item,
|
||||
void *data, plitem_t *messages, void *context)
|
||||
{
|
||||
|
@ -239,7 +243,7 @@ static int parse_data (const plfield_t *field, const plitem_t *item,
|
|||
const void *bindata = PL_BinaryData (item);
|
||||
size_t binsize = PL_BinarySize (item);
|
||||
|
||||
Sys_Printf ("parse_array: %s %zd %d %p %p %p\n",
|
||||
Sys_Printf ("parse_data: %s %zd %d %p %p %p\n",
|
||||
field->name, field->offset, field->type, field->parser,
|
||||
field->data, data);
|
||||
Sys_Printf (" %zd %zd\n", datad->value_offset, datad->size_offset);
|
||||
|
@ -253,6 +257,24 @@ static int parse_data (const plfield_t *field, const plitem_t *item,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int parse_string (const plfield_t *field, const plitem_t *item,
|
||||
void *data, plitem_t *messages, void *context)
|
||||
{
|
||||
__auto_type string = (parse_string_t *) field->data;
|
||||
__auto_type value = (char **) ((byte *)data + string->value_offset);
|
||||
|
||||
const char *str = PL_BinaryData (item);
|
||||
|
||||
Sys_Printf ("parse_string: %s %zd %d %p %p %p\n",
|
||||
field->name, field->offset, field->type, field->parser,
|
||||
field->data, data);
|
||||
Sys_Printf (" %zd\n", string->value_offset);
|
||||
Sys_Printf (" %s\n", str);
|
||||
|
||||
*value = strdup (str);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#include "libs/video/renderer/vulkan/vkparse.cinc"
|
||||
|
||||
typedef struct qfv_renderpass_s {
|
||||
|
|
Loading…
Reference in a new issue