shithub: mc

Download patch

ref: 5b5cc1147918c95a33f5dc5e436ac640b514f739
parent: 12c5d386081c6ac422234e2f7f4567306403f318
author: Ori Bernstein <[email protected]>
date: Sat Nov 19 08:38:17 EST 2011

Add in type for type constraints

--- a/parse/parse.h
+++ b/parse/parse.h
@@ -1,12 +1,16 @@
 typedef uint32_t        unichar;
 typedef long long       vlong;
 typedef unsigned long long uvlong;
+
 typedef struct Tok Tok;
 typedef struct Node Node;
-typedef struct Type Type;
 typedef struct Stab Stab;
 typedef struct Sym Sym;
 
+typedef struct Type Type;
+typedef struct Cstr Cstr;
+
+
 typedef enum {
 #define O(op) op,
 #include "ops.def"
@@ -77,6 +81,16 @@
     };
 };
 
+struct Cstr {
+    int cid;    /* unique id */
+    /* required members */
+    size_t nreqmemb;
+    Node **reqmemb;
+    /* required functions */
+    size_t nreqfn;
+    Node **reqfn;
+};
+
 struct Node {
     int line;
     int type;
@@ -186,7 +200,10 @@
 Sym  *stget(char *name);
 Sym *mksym(int line, Node *name, Type *ty);
 
-/* type ccreation */
+/* type creation */
+void tyinit(); /* sets up built in types */
+Type *optype(Op o);
+
 Type *mktyvar(int line);
 Type *mktyparam(int line, char *name);
 Type *mktynamed(int line, Node *name);
@@ -198,6 +215,9 @@
 Type *mktyunion(int line, Node **decls, size_t ndecls);
 Type *mktyenum(int line, Node **decls, size_t ndecls);
 
+Cstr *mkcstr(int line, char *name, Node **reqmemb, size_t nreqmemb, Node **reqdecl, size_t nreqdecl); 
+
+int hascstr(Type *t, Cstr *c);
 char *tyfmt(char *buf, size_t len, Type *t);
 char *tystr(Type *t);
 
--- a/parse/type.c
+++ b/parse/type.c
@@ -34,6 +34,10 @@
     {Tybad, NULL}
 };
 
+Type **types;
+int ntypes;
+Cstr **cstr;
+int ncstr;
 
 static int nexttid = 0;
 static Type *mktype(Ty ty)