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)) {
|
|
|
|
printf (" +%s\n", name);
|
|
|
|
Hash_Add (processed_types, (void *) name);
|
|
|
|
[queue addObject: self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 05:24:39 +00:00
|
|
|
-(void) forEachFieldCall: (varfunc) func
|
|
|
|
{
|
|
|
|
qfot_struct_t *strct =&type.strct;
|
|
|
|
|
|
|
|
for (int i = 0; i < strct.num_fields; i++) {
|
|
|
|
func (&strct.fields[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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];
|
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
|
|
|
|
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]);
|
|
|
|
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
|
|
|
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (header_file, "int parse_%s (const plfield_t *field,"
|
|
|
|
" const plitem_t *item, void *data, plitem_t *messages,"
|
|
|
|
" void *context);\n",
|
2020-12-23 13:13:50 +00:00
|
|
|
[self outname]);
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "int parse_%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",
|
2020-12-23 13:13:50 +00:00
|
|
|
[self outname]);
|
2020-07-05 05:59:56 +00:00
|
|
|
fprintf (output_file, "{\n");
|
|
|
|
fprintf (output_file,
|
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",
|
2020-12-23 13:13:50 +00:00
|
|
|
[self outname]);
|
2020-07-05 05:59:56 +00:00
|
|
|
fprintf (output_file, "}\n");
|
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]);
|
|
|
|
fprintf (output_file, "\t\"%s\",\n", [self outname]);
|
|
|
|
fprintf (output_file, "\tsizeof (%s),\n", [self outname]);
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "\tcexpr_struct_binops,\n");
|
|
|
|
fprintf (output_file, "\t0,\n");
|
2020-12-23 13:13:50 +00:00
|
|
|
fprintf (output_file, "\t&%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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
-(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
|
|
|
|
{
|
|
|
|
return "QFDictionary";
|
|
|
|
}
|
|
|
|
|
|
|
|
-(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
|