From 50d3df1fafd26305742373a71022fdc4dd0d0ed4 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Fri, 22 May 2020 16:28:55 -0700 Subject: checkin: going to rework declaration structure to be more transparent --- sys/cmd/cc/cc.h | 143 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 98 insertions(+), 45 deletions(-) (limited to 'sys/cmd/cc/cc.h') diff --git a/sys/cmd/cc/cc.h b/sys/cmd/cc/cc.h index 1412302..0d4c876 100644 --- a/sys/cmd/cc/cc.h +++ b/sys/cmd/cc/cc.h @@ -207,19 +207,22 @@ enum extern byte *tokens[NUM_TOKENS]; /* TODO: store literals in a big val */ +union Val +{ + byte *s; + double f; + vlong i; + uvlong ui; + int32 c; + uint32 uc; + rune r; +}; + struct Token { - uint32 kind; - Pos pos; - union { - byte *s; - double f; - vlong i; - uvlong ui; - int32 c; - uint32 uc; - rune r; - } val; + uint32 kind; + Pos pos; + union Val val; }; enum @@ -321,10 +324,10 @@ enum /* conditional */ Xternary, /* unary prefix ops */ - Xref, Xstar, Xplus, Xminus, Xneg, Xnot, Xsizeof, Xalnof, Xpreinc, Xpredec, + Xref, Xstar, Xplus, Xminus, Xneg, Xnot, Xsizeof, Xalignof, Xpreinc, Xpredec, Xcast, /* unary postfix ops */ - Xpostinc, Xpostdec, Xindex, Xcall, Xsel, Xcmpndlit, + Xpostinc, Xpostdec, Xindex, Xcall, Xselp, Xself, Xcmpdlit, /* binary ops */ Xoror, Xandand, Xor, Xxor, Xand, Xneq, Xeql, Xgt, Xlt, Xgteq, Xlteq, Xlsft, Xrsft, Xadd, Xsub, Xmul, Xdiv, Xmod, @@ -347,11 +350,35 @@ enum }; /* expressions */ +struct Key +{ + /* + * NOTE: bitpacked + * lower 32 -> index into designator array + * upper 32 -> type + */ + uint64 kind; + union { + Expr *x; + string s; + }; +}; + struct Expr { - struct Node; - uint64 type; + struct Node; + Type *type; union { + struct { + uint64 kind; + union Val; + } val; + struct { + int n; + struct Key *key; + Expr *val; + } cmpd; + Expr *x; struct { Expr *l; Expr *r; @@ -361,13 +388,25 @@ struct Expr Expr *t; Expr *e; } cond; + struct { + Expr *x; + union { + Expr *i; + string f; + }; + } idx; + struct { + Expr *fn; + int n; + Expr **arg; + } call; union { Expr *pre; Expr *post; } unary; struct { - uint64 to; - Expr *x; + Type *to; + Expr *x; } cast; struct { Expr *l; @@ -417,33 +456,8 @@ struct Stmt /* declarations */ -struct Ptr -{ - uint64 kind; - Ptr *link; -}; - -struct Name -{ - struct Node; - union { - string ident; - struct Dtor *paren; - }; - union { - Expr *i; - Expr *p; - }; -}; - -struct Dtor -{ - Ptr ptr; - Name name; -}; - -// specifiers /* + * specifiers * the design is the following: * type info is held w/in a 64 bit integer. * the bottom 32 bits are associated to specializations @@ -510,6 +524,31 @@ enum Sbad = -1, }; +struct Ptr +{ + uint64 kind; + Ptr *link; +}; + +struct Name +{ + struct Node; + union { + string ident; + struct Dtor *paren; + }; + union { + Expr *i; + Expr *p; + }; +}; + +struct Dtor +{ + Ptr ptr; + Name name; +}; + struct Decls { union { @@ -538,24 +577,38 @@ struct Decl }; }; +enum +{ + Tbad, + Tbase, + Tarray, + Tptr, +}; + /* types */ struct Type { Sym *sym; string ident; + uint64 kind; uintptr size; uint16 align; union { + Type *ptr; + struct { + int len; + Type *elt; + } arr; struct { int len; Dtor *d; Expr *x; - } su; + } agr; struct { int len; string *s; Expr *x; - } en; + } enm; }; }; -- cgit v1.2.1