mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 06:10:56 +00:00
[vkgen] Recognize char *
as a string
Ruamoko currently doesn't support `const`, so that's not relevant, but recognizing `char *` (via a hack to work around what looks like a bug with type aliasing) allows strings to be handled without having to use a custom parser. Things are still a little clunky for custom parsers, but this seems to be a good start.
This commit is contained in:
parent
d5cd4f6ede
commit
403c6eea73
11 changed files with 83 additions and 7 deletions
|
@ -17,6 +17,7 @@ vkgen_dat_src= \
|
|||
libs/video/renderer/vulkan/vkgen/vkfieldtype.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkfixedarray.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkgen.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkstring.r \
|
||||
libs/video/renderer/vulkan/vkgen/vkstruct.r \
|
||||
libs/video/renderer/vulkan/vkgen/vktype.r \
|
||||
libs/video/renderer/vulkan/vkgen/vulkan.r
|
||||
|
@ -60,6 +61,7 @@ EXTRA_DIST += \
|
|||
libs/video/renderer/vulkan/vkgen/vkfieldtype.h \
|
||||
libs/video/renderer/vulkan/vkgen/vkfixedarray.h \
|
||||
libs/video/renderer/vulkan/vkgen/vkgen.h \
|
||||
libs/video/renderer/vulkan/vkgen/vkstring.h \
|
||||
libs/video/renderer/vulkan/vkgen/vkstruct.h \
|
||||
libs/video/renderer/vulkan/vkgen/vktype.h
|
||||
|
||||
|
|
|
@ -7,4 +7,4 @@ typedef int int16_t;
|
|||
typedef int int32_t;
|
||||
typedef int int64_t;
|
||||
typedef int size_t;
|
||||
typedef int char;
|
||||
typedef struct char { int x; } char;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "vkfielddef.h"
|
||||
|
||||
@interface StringField: FieldDef
|
||||
+fielddef:(PLItem *)item struct:(Struct *)strct field:(string)fname;
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkfieldstring_h
|
||||
|
|
|
@ -12,10 +12,19 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
value_field = [[item getObjectForKey:"string"] string];
|
||||
value_field = fname;
|
||||
if (item) {
|
||||
value_field = [[item getObjectForKey:"string"] string];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+fielddef:(PLItem *)item struct:(Struct *)strct field:(string)fname
|
||||
{
|
||||
return [[[StringField alloc] init:item struct:strct field:fname]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
-writeParseData
|
||||
{
|
||||
fprintf (output_file, "static parse_string_t parse_%s_%s_data = {\n",
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <qfile.h>
|
||||
#include <types.h>
|
||||
#include <Array.h>
|
||||
#include <PropertyList.h>
|
||||
|
||||
typedef void varfunc (qfot_var_t *var);
|
||||
|
||||
|
|
|
@ -200,7 +200,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") {
|
||||
string name = [obj name];
|
||||
if (name == "char" // char type faked via a struct
|
||||
|| [[parse getObjectForKey:name] string] == "skip") {
|
||||
continue;
|
||||
}
|
||||
[obj queueFieldTypes];
|
||||
|
|
9
libs/video/renderer/vulkan/vkgen/vkstring.h
Normal file
9
libs/video/renderer/vulkan/vkgen/vkstring.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef __renderer_vulkan_vkgen_vkstring_h
|
||||
#define __renderer_vulkan_vkgen_vkstring_h
|
||||
|
||||
#include "vktype.h"
|
||||
|
||||
@interface String: Type
|
||||
@end
|
||||
|
||||
#endif//__renderer_vulkan_vkgen_vkstring_h
|
28
libs/video/renderer/vulkan/vkgen/vkstring.r
Normal file
28
libs/video/renderer/vulkan/vkgen/vkstring.r
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "vkfieldstring.h"
|
||||
#include "vkstring.h"
|
||||
#include "vkgen.h"
|
||||
|
||||
@implementation String
|
||||
|
||||
-(string) name
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
|
||||
-(FieldDef *)fielddef:(Struct *)strct field:(string)fname
|
||||
{
|
||||
return [StringField fielddef:nil struct:strct field:fname];
|
||||
}
|
||||
|
||||
-(string) cexprType
|
||||
{
|
||||
return [self name] + "_type";
|
||||
}
|
||||
|
||||
-(string) parseType
|
||||
{
|
||||
return "QFString";
|
||||
}
|
||||
@end
|
|
@ -124,9 +124,13 @@
|
|||
if (field.name == "sType" || field.name == "pNext") {
|
||||
continue;
|
||||
}
|
||||
FieldDef *field_def = [FieldDef fielddef:nil
|
||||
struct:self
|
||||
field:field.name];
|
||||
Type *field_type = [Type findType: field.type];
|
||||
FieldDef *field_def = [field_type fielddef:self field:field.name];
|
||||
if (!field_def) {
|
||||
field_def = [FieldDef fielddef:nil
|
||||
struct:self
|
||||
field:field.name];
|
||||
}
|
||||
[field_defs addObject: field_def];
|
||||
}
|
||||
}
|
||||
|
@ -197,7 +201,8 @@
|
|||
Type *field_type = [Type findType: field.type];
|
||||
fprintf (output_file,
|
||||
"\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n",
|
||||
field.name, [field_type cexprType], [self outname], field.name);
|
||||
field.name, [field_type cexprType], [self outname],
|
||||
field.name);
|
||||
}
|
||||
}
|
||||
fprintf (output_file, "\t{ }\n");
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
#include <types.h>
|
||||
#include <Object.h>
|
||||
|
||||
@class FieldDef;
|
||||
@class Struct;
|
||||
|
||||
@interface Type: Object
|
||||
{
|
||||
qfot_type_t *type;
|
||||
|
@ -26,6 +29,8 @@
|
|||
-(string) parseFunc;
|
||||
-(string) parseData;
|
||||
|
||||
-(FieldDef *)fielddef:(Struct *)strct field:(string)fname;
|
||||
|
||||
-(int) isPointer;
|
||||
-(Type *) dereference;
|
||||
@end
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "vkenum.h"
|
||||
#include "vkfixedarray.h"
|
||||
#include "vkgen.h"
|
||||
#include "vkstring.h"
|
||||
#include "vkstruct.h"
|
||||
#include "vktype.h"
|
||||
|
||||
|
@ -51,6 +52,14 @@ static string get_type_key (void *type, void *unused)
|
|||
}
|
||||
switch (type.meta) {
|
||||
case ty_basic:
|
||||
if (type.type == ev_ptr) {
|
||||
Type *tgt = [Type findType: type.fldptr.aux_type];
|
||||
|
||||
if (tgt.type.meta == ty_alias
|
||||
&& tgt.type.alias.name == "char") {
|
||||
return [[String alloc] initWithType: type];
|
||||
}
|
||||
}
|
||||
case ty_class:
|
||||
return [[Type alloc] initWithType: type];
|
||||
case ty_array:
|
||||
|
@ -138,6 +147,11 @@ static string get_type_key (void *type, void *unused)
|
|||
return "0";
|
||||
}
|
||||
|
||||
-(FieldDef *)fielddef:(Struct *)strct field:(string)fname
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(int) isPointer
|
||||
{
|
||||
if ((type.meta == ty_basic || type.meta == ty_alias)
|
||||
|
|
Loading…
Reference in a new issue