From 680d60678b273f1ff20b013b24954773f76b4e1d Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Fri, 29 May 2020 14:40:50 -0700 Subject: checkin: before fix of stale type pointer bug --- sys/cmd/cc/cc.h | 80 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 39 deletions(-) (limited to 'sys/cmd/cc/cc.h') diff --git a/sys/cmd/cc/cc.h b/sys/cmd/cc/cc.h index ce7eca7..e711770 100644 --- a/sys/cmd/cc/cc.h +++ b/sys/cmd/cc/cc.h @@ -22,7 +22,7 @@ typedef struct Parser Parser; typedef struct Ptr Ptr; typedef struct Name Name; typedef struct Dtor Dtor; -typedef struct Obj Obj; +typedef struct Field Field; typedef struct Node Node; typedef struct Decl Decl; @@ -229,12 +229,13 @@ struct Token enum { - Sobj = iota(0), - Stype = iota(2), - Stag = iota(3), - Senum = iota(4), - Sstmt = iota(5), - Smacro = iota(6), + Svar = iota(1), + Sfunc = iota(2), + Stype = iota(3), + Stag = iota(4), + Senum = iota(5), + Slabl = iota(6), + Smacro = iota(7), }; struct Sym @@ -246,6 +247,7 @@ struct Sym Decl *obj; Type *typ; Stmt *blk; + Expr *val; }; }; @@ -260,7 +262,7 @@ struct SymTab Sym **vals; }; -Sym *define(SymTab *tab, string ident, int kind); +Sym *define(SymTab *tab, string ident, uint32 kind); Sym *lookup(SymTab *tab, string ident); error forget(SymTab *tab, string ident); void forgetall(SymTab *tab); @@ -370,9 +372,8 @@ enum Dfunc, - Dtype, - Dvar, - Dvars, + Dobj, + Dobjs, /* names */ Nident, @@ -578,7 +579,7 @@ struct Name struct { int n; int dots : 1; - Obj *arg; + Field *arg; } call; }; } sfx; @@ -591,22 +592,24 @@ struct Dtor Name *name; }; -struct Decls -{ - Type *type; - Expr *init; - struct Decls *link; -}; - /* final ast node */ -struct Obj +struct Field { uint32 qual; Type *type; string name; }; +struct Decls +{ + string name; + Type *type; + Expr *init; + struct Decls *link; +}; + + struct Decl { struct Node; @@ -620,7 +623,7 @@ struct Decl Expr *init; }; }; - struct Decls vars; + struct Decls objs; }; }; @@ -628,15 +631,16 @@ enum { Tbad, Tbase, - Tarray, + Tdef, Tptr, + Tarray, + Tfunc, }; /* types */ struct Type { uint32 kind; - string ident; Sym *sym; uintptr size; uintptr max; @@ -648,23 +652,25 @@ struct Type Type *base; } ptr; struct { - int len; - Type *elt; + int len; + uint32 qual; + Type *elt; } arr; struct { - int len; - Obj *f; - Expr *x; + int len; + Field *f; + Expr *x; } aggr; struct { - int len; - string *s; - Expr *x; + int len; + string *elt; + Expr *val; } enm; struct { Type *ret; int n; - Type **arg; + int dots : 1; + Field *arg; } func; }; }; @@ -719,6 +725,7 @@ struct StrTab int32 *vals; }; +#if 0 struct TypeSet { int32 n_buckets; @@ -728,6 +735,7 @@ struct TypeSet int32 *flags; Type **keys; }; +#endif /* main data */ struct Compiler @@ -749,13 +757,6 @@ struct Compiler } inc; struct { - struct TypeSet p; // pointer - struct TypeSet a; // array - struct TypeSet f; // funcs - struct TypeSet s; // structs - struct TypeSet u; // unions - struct TypeSet e; // enums - int cap; int len; Type *info; @@ -767,5 +768,6 @@ extern Compiler C; /* cc.c functions */ void init(); int32 intern(byte **str); +Type *type(); #undef iota -- cgit v1.2.1