2020-07-02 05:24:39 +00:00
|
|
|
#include <hash.h>
|
|
|
|
#include <qfile.h>
|
|
|
|
#include <runtime.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <types.h>
|
|
|
|
#include <Array.h>
|
2020-07-05 05:59:56 +00:00
|
|
|
#include <PropertyList.h>
|
2020-07-02 05:24:39 +00:00
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
#include "vkfielddef.h"
|
2020-07-02 05:24:39 +00:00
|
|
|
#include "vkgen.h"
|
|
|
|
#include "vkstruct.h"
|
|
|
|
|
|
|
|
@implementation Struct
|
|
|
|
|
|
|
|
-(string) name
|
|
|
|
{
|
|
|
|
return str_mid(type.strct.tag, 4);
|
|
|
|
}
|
|
|
|
|
2020-07-03 16:40:02 +00:00
|
|
|
-(void) addToQueue
|
|
|
|
{
|
|
|
|
string name = [self name];
|
|
|
|
if (!Hash_Find (processed_types, name)) {
|
2021-07-06 03:27:21 +00:00
|
|
|
//printf (" +%s\n", name);
|
2020-07-03 16:40:02 +00:00
|
|
|
Hash_Add (processed_types, (void *) name);
|
|
|
|
[queue addObject: self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-04 00:18:57 +00:00
|
|
|
-(void) queueFieldTypes
|
2020-07-02 05:24:39 +00:00
|
|
|
{
|
|
|
|
qfot_struct_t *strct =&type.strct;
|
2021-12-04 00:29:38 +00:00
|
|
|
PLItem *field_dict = [parse getObjectForKey:[self name]];
|
2020-07-02 05:24:39 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < strct.num_fields; i++) {
|
2021-12-04 00:29:38 +00:00
|
|
|
qfot_var_t *var = &strct.fields[i];
|
|
|
|
if (field_dict) {
|
|
|
|
PLItem *item = [field_dict getObjectForKey:var.name];
|
|
|
|
FieldDef *def = [FieldDef fielddef:item
|
|
|
|
struct:self
|
|
|
|
field:var.name];
|
|
|
|
if (![def searchType]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2021-12-04 00:18:57 +00:00
|
|
|
Type *type = [Type findType:var.type];
|
|
|
|
[type addToQueue];
|
2020-07-02 05:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 05:59:56 +00:00
|
|
|
-(qfot_var_t *)findField:(string) fieldName
|
2020-07-02 05:24:39 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < type.strct.num_fields; i++) {
|
|
|
|
qfot_var_t *var = &type.strct.fields[i];
|
2020-07-05 05:59:56 +00:00
|
|
|
if (var.name == fieldName) {
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-01-05 09:26:01 +00:00
|
|
|
-(string)sTypeName
|
|
|
|
{
|
|
|
|
string s = "VK_STRUCTURE_TYPE";
|
|
|
|
string name = str_hold ([self outname]);
|
|
|
|
int length = strlen (name);
|
|
|
|
int start, end, c;
|
|
|
|
for (start = 2; start < length; start = end) {
|
|
|
|
for (end = start + 1; end < length; end++) {
|
|
|
|
c = str_char (name, end);
|
|
|
|
if (c >= 'A' && c <= 'Z') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s += "_" + str_mid (name, start, end);
|
|
|
|
}
|
|
|
|
str_free (name);
|
|
|
|
return str_upper (s);
|
|
|
|
}
|
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
-(void) writeTable
|
2020-07-05 05:59:56 +00:00
|
|
|
{
|
2020-12-23 13:13:50 +00:00
|
|
|
PLItem *field_dict = [parse getObjectForKey:[self name]];
|
2020-12-20 17:12:51 +00:00
|
|
|
PLItem *new_name = [field_dict getObjectForKey:".name"];
|
2020-12-23 13:13:50 +00:00
|
|
|
Array *field_defs = [Array array];
|
2021-01-05 09:26:01 +00:00
|
|
|
int have_sType = 0;
|
2022-05-29 12:53:38 +00:00
|
|
|
int have_pNext = 0;
|
2020-12-20 17:12:51 +00:00
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
if ([parse string] == "skip") {
|
|
|
|
return;
|
|
|
|
}
|
2020-12-20 17:12:51 +00:00
|
|
|
if (new_name) {
|
2020-12-23 13:13:50 +00:00
|
|
|
outname = str_hold ([new_name string]);
|
2020-12-20 17:12:51 +00:00
|
|
|
}
|
2020-07-05 05:59:56 +00:00
|
|
|
|
2021-01-05 09:26:01 +00:00
|
|
|
for (int i = 0; i < type.strct.num_fields; i++) {
|
|
|
|
qfot_var_t *field = &type.strct.fields[i];
|
|
|
|
if (field.name == "sType") {
|
|
|
|
have_sType = 1;
|
|
|
|
}
|
2022-05-29 12:53:38 +00:00
|
|
|
if (field.name == "pNext") {
|
|
|
|
have_pNext = 1;
|
|
|
|
write_symtab = 1;
|
|
|
|
}
|
2021-01-05 09:26:01 +00:00
|
|
|
}
|
2020-12-23 13:13:50 +00:00
|
|
|
if (field_dict) {
|
|
|
|
PLItem *field_keys = [field_dict allKeys];
|
2020-07-05 05:59:56 +00:00
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
for (int i = [field_keys count]; i-- > 0; ) {
|
|
|
|
string field_name = [[field_keys getObjectAtIndex:i] string];
|
2020-07-05 05:59:56 +00:00
|
|
|
|
2020-12-20 17:12:51 +00:00
|
|
|
if (str_mid(field_name, 0, 1) == ".") {
|
|
|
|
continue;
|
|
|
|
}
|
2020-12-23 13:13:50 +00:00
|
|
|
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];
|
2020-07-05 05:59:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < type.strct.num_fields; i++) {
|
|
|
|
qfot_var_t *field = &type.strct.fields[i];
|
|
|
|
if (field.name == "sType" || field.name == "pNext") {
|
|
|
|
continue;
|
|
|
|
}
|
2020-12-23 13:13:50 +00:00
|
|
|
FieldDef *field_def = [FieldDef fielddef:nil
|
|
|
|
struct:self
|
|
|
|
field:field.name];
|
|
|
|
[field_defs addObject: field_def];
|
2020-07-02 05:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-23 13:13:50 +00:00
|
|
|
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]);
|
2022-04-03 02:11:28 +00:00
|
|
|
fprintf (output_file,
|
|
|
|
"\t{\"@inherit\", 0, QFString, parse_inherit, &%s_fields},\n",
|
|
|
|
[self outname]);
|
2022-05-29 12:53:38 +00:00
|
|
|
if (have_pNext) {
|
|
|
|
fprintf (output_file,
|
|
|
|
"\t{\"@next\", field_offset (%s, pNext), "
|
|
|
|
"QFArray, parse_next, 0},", [self outname]);
|
|
|
|
}
|
2020-12-23 13:13:50 +00:00
|
|
|
for (int i = [field_defs count]; i-- > 0; ) {
|
|
|
|
FieldDef *field_def = [field_defs objectAtIndex:i];
|
|
|
|
[field_def writeField];
|
|
|
|
}
|
2020-07-02 05:24:39 +00:00
|
|
|
fprintf (output_file, "\t{ }\n");
|
|
|
|
fprintf (output_file, "};\n");
|
2020-07-05 05:59:56 +00:00
|
|
|
|
2022-05-29 12:53:38 +00:00
|
|
|
fprintf (header_file, "int %s (const plfield_t *field,"
|
2020-12-21 09:38:31 +00:00
|
|
|
" const plitem_t *item, void *data, plitem_t *messages,"
|
|
|
|
" void *context);\n",
|
2022-05-29 12:53:38 +00:00
|
|
|
[self parseFunc]);
|
|
|
|
fprintf (output_file, "int %s (const plfield_t *field,"
|
2020-12-20 17:12:51 +00:00
|
|
|
" const plitem_t *item, void *data, plitem_t *messages,"
|
|
|
|
" void *context)\n",
|
2022-05-29 12:53:38 +00:00
|
|
|
[self parseFunc]);
|
2020-07-05 05:59:56 +00:00
|
|
|
fprintf (output_file, "{\n");
|
2021-01-05 09:26:01 +00:00
|
|
|
if (have_sType) {
|
|
|
|
fprintf (output_file, "\t((%s *) data)->sType", [self outname]);
|
|
|
|
fprintf (output_file, " = %s;\n", [self sTypeName]);
|
|
|
|
}
|
2020-07-05 05:59:56 +00:00
|
|
|
fprintf (output_file,
|
2021-02-14 02:20:54 +00:00
|
|
|
"\tif (PL_Type (item) == QFString\n"
|
|
|
|
"\t\t&& !(item = parse_reference (item, \"%s\", messages, context))) {\n"
|
|
|
|
"\t\treturn 0;\n"
|
|
|
|
"\t}\n"
|
2020-12-24 04:33:37 +00:00
|
|
|
"\treturn PL_ParseStruct (%s_fields, item, data, messages,"
|
2020-12-20 17:12:51 +00:00
|
|
|
" context);\n",
|
2021-02-14 02:20:54 +00:00
|
|
|
[self outname], [self outname]);
|
2020-07-05 05:59:56 +00:00
|
|
|
fprintf (output_file, "}\n");
|
2022-05-29 12:53:38 +00:00
|
|
|
if (have_pNext) {
|
|
|
|
fprintf (output_file, "static parserref_t %s_parser = ",
|
|
|
|
[self outname]);
|
|
|
|
fprintf (output_file, "{\"%s\", %s, sizeof(%s)};\n",
|
|
|
|
[self outname], [self parseFunc], [self outname]);
|
|
|
|
}
|
2020-12-21 09:38:31 +00:00
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
fprintf (output_file, "static exprsym_t %s_symbols[] = {\n", [self outname]);
|
2020-12-21 09:38:31 +00:00
|
|
|
if (field_defs) {
|
|
|
|
PLItem *field_def;
|
|
|
|
qfot_var_t *field;
|
|
|
|
|
|
|
|
for (int i = [field_defs count]; i-- > 0; ) {
|
2020-12-23 13:13:50 +00:00
|
|
|
FieldDef *field_def = [field_defs objectAtIndex:i];
|
|
|
|
[field_def writeSymbol];
|
2020-12-21 09:38:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < type.strct.num_fields; i++) {
|
|
|
|
qfot_var_t *field = &type.strct.fields[i];
|
|
|
|
if (field.name == "sType" || field.name == "pNext") {
|
|
|
|
continue;
|
|
|
|
}
|
2020-12-23 13:13:50 +00:00
|
|
|
Type *field_type = [Type findType: field.type];
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file,
|
|
|
|
"\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n",
|
2020-12-23 13:13:50 +00:00
|
|
|
field.name, [field_type cexprType], [self outname], field.name);
|
2020-12-21 09:38:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf (output_file, "\t{ }\n");
|
|
|
|
fprintf (output_file, "};\n");
|
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
fprintf (output_file, "static exprtab_t %s_symtab = {\n", [self outname]);
|
|
|
|
fprintf (output_file, "\t%s_symbols,\n", [self outname]);
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "};\n");
|
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
fprintf (output_file, "exprtype_t %s_type = {\n", [self outname]);
|
2022-04-24 05:55:35 +00:00
|
|
|
fprintf (output_file, "\t.name = \"%s\",\n", [self outname]);
|
|
|
|
fprintf (output_file, "\t.size = sizeof (%s),\n", [self outname]);
|
|
|
|
fprintf (output_file, "\t.binops = cexpr_struct_binops,\n");
|
|
|
|
fprintf (output_file, "\t.unops = 0,\n");
|
|
|
|
fprintf (output_file, "\t.data = &%s_symtab,\n", [self outname]);
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "};\n");
|
2020-12-23 13:13:50 +00:00
|
|
|
fprintf (output_file, "\n");
|
|
|
|
fprintf (header_file, "extern exprtype_t %s_type;\n", [self outname]);
|
2020-12-21 09:38:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
-(void) writeSymtabInit
|
2020-12-21 09:38:31 +00:00
|
|
|
{
|
2020-12-23 13:13:50 +00:00
|
|
|
PLItem *field_dict = [parse getObjectForKey:[self outname]];
|
2020-12-21 09:38:31 +00:00
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
if ([parse string] == "skip") {
|
|
|
|
return;
|
2020-12-21 09:38:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
fprintf (output_file, "\tcexpr_init_symtab (&%s_symtab, context);\n",
|
|
|
|
[self outname]);
|
|
|
|
}
|
|
|
|
|
2021-01-04 08:26:39 +00:00
|
|
|
-(void) writeSymtabEntry
|
|
|
|
{
|
2022-05-29 12:53:38 +00:00
|
|
|
if (!write_symtab || [parse string] == "skip") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf (output_file,
|
|
|
|
"\tHash_Add (parser_table, &%s_parser);\n",
|
|
|
|
[self outname]);
|
2021-01-04 08:26:39 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
-(string) outname
|
|
|
|
{
|
|
|
|
if (outname) {
|
|
|
|
return outname;
|
|
|
|
}
|
|
|
|
return [self name];
|
2020-12-21 09:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(string) cexprType
|
|
|
|
{
|
2020-12-24 15:17:20 +00:00
|
|
|
return [self outname] + "_type";
|
2020-07-05 05:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(string) parseType
|
|
|
|
{
|
2021-02-14 02:20:54 +00:00
|
|
|
return "QFMultiType | (1 << QFString) | (1 << QFDictionary)";
|
2020-07-05 05:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(string) parseFunc
|
|
|
|
{
|
2020-12-24 15:17:20 +00:00
|
|
|
return "parse_" + [self outname];
|
2020-07-05 05:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(string) parseData
|
|
|
|
{
|
|
|
|
return "0";
|
2020-07-02 05:24:39 +00:00
|
|
|
}
|
|
|
|
@end
|