]> git.mdlowis.com Git - proto/obnc.git/commitdiff
segfaults everywhere
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 14 May 2021 21:01:56 +0000 (17:01 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 14 May 2021 21:01:56 +0000 (17:01 -0400)
cerise/inc/cerise.h
cerise/src/grammar.c

index 04ee5da370e7ff672de14bb5ff09821ec8822e80..25d4f671ebe81ac6f54feb9cd10a1eaccc748848 100644 (file)
@@ -77,12 +77,12 @@ typedef struct LexFile {
     char* fpos;
 } LexFile;
 
-struct Symbol;
+struct Type;
 
 typedef struct Field {
     struct Field* next;
     char* name;
-    Type* type;
+    struct Type* type;
     long offset;
     int export : 1;
 } Field;
@@ -93,7 +93,7 @@ typedef struct Type {
         FORM_RECORD,
         FORM_COUNT
     } form;
-    struct Symbol* fields;
+    struct Field* fields;
     struct Type* base;
     int size;
 } Type;
index 811b8d29020c12dd28f281fbbecd1eadcc02e512..8c72c67ff7e6b3d1b6573552e2fc0867931f4645 100644 (file)
@@ -347,16 +347,26 @@ RULE(type)
     {
         item->type = calloc(1, sizeof(Type));
         item->type->form = FORM_RECORD;
-        Symbol head = {0};
-        int nfields = 0;
+
+//        long offset = 0;
+        Field **field = &(item->type->fields);
 
         while (peek(p)->type != END)
         {
+            int nfields = 0;
+            Field* first = NULL;
             do
             {
                 char* name = expect_text(p, IDENT);
                 bool export = accept(p, '*');
-                (void)symbol_addfield(p, &head, name, SYM_FIELD, export);
+                *field = calloc(1, sizeof(Field));
+                (*field)->name = name;
+                (*field)->export = export;
+                field = &((*field)->next);
+                if (!first)
+                {
+                    first = *field;
+                }
                 nfields++;
             }
             while (accept(p, ','));
@@ -366,13 +376,11 @@ RULE(type)
             type(p, &field_type);
 
             /* apply the type to the newly created symbols */
-            Symbol* field = head.desc;
             for (int i = 0; i < nfields; i++)
             {
-                field->type = field_type.type;
-                field = field->next;
+                first->type = field_type.type;
+                first = first->next;
             }
-            item->type->fields = head.desc;
         }
 
         expect(p, END);