home *** CD-ROM | disk | FTP | other *** search
- /*
- C* -- Header file for node declarations.
-
- source: node.h
- started: June 20, 1986
- version: March 5, 1987
-
- PUBLIC DOMAIN SOFTWARE
-
- The CSTAR program was placed in the public domain on June 15, 1991,
- by its author and sole owner,
-
- Edward K. Ream
- 1617 Monroe Street
- Madison, WI 53711
- (608) 257-0802
-
- CSTAR may be used for any commercial or non-commercial purpose.
-
- See cstar.h or cstar.c for a DISCLAIMER OF WARRANTIES.
- */
-
- /*
- ----- MACROS -----
- */
- struct mst_node {
- struct mst_node * mst_next; /* Pointer to next bucket. */
- int mst_nargs; /* Number of args in text. */
- char * mst_name; /* Pointer to name. */
- char * mst_text; /* Pointer to replacement text. */
- };
-
- /*
- Global "initial undef list" used by the preprocessor.
- */
- struct u_node {
- struct u_node * u_next;
- char * u_name;
- };
-
- /*
- ----- PARSING -----
- */
- #define NODE_HEAD\
- int codetype;\
- struct node * nnext;\
- int nlinno;\
- struct type_node * ncltype
-
- /*
- Global describing the "current scope."
- */
- struct scope_node {
- int s_scope;
- struct scope_node * s_snext;
- struct type_node * s_fntype;
- };
-
- /*
- Define the format of symbol table nodes.
- */
- struct st_node {
- struct st_node * st_next;
- char * st_name;
- char * st_alias;
- struct iblock * st_iniz;
- folded st_offset; /* this is NOT unsigned */
- struct type_node * st_type;
- int st_sclass;
- int st_misc;
- };
-
- /*
- Type is ID_TOK (this is not a st_node, and it replaces id_node
- and const_node)
-
- Note that NODE_HEAD includes the n_cltype field.
- Note that n_cid is a name IN ADDITION to the registers
- designated by the register fields, and a loc_node meant
- to designate a register is to have no n_cid set!
- */
- struct loc_node {
- NODE_HEAD;
- char nmode; /* EA_MODE, etc. */
- char nscflag; /* reg2 usage/scaling indicator */
- struct st_node * ncid; /* symbolic reference, if any */
- folded nconst; /* constant, if any */
- int nreg1; /* register reference */
- int nreg2; /* second register reference */
- };
-
- #define n_mode u.locn.nmode
- #define n_scflag u.locn.nscflag
- #define n_cid u.locn.ncid
- #define n_const u.locn.nconst
- #define n_reg1 u.locn.nreg1
- #define n_reg2 u.locn.nreg2
-
- /*
- Define "type nodes" used to describe a type.
- These nodes are produced when declarations are parsed.
- These nodes are attached to symbol table nodes.
-
- t_typtok: INT_TYPE, CHAR_TYPE, POINTER_TYPE, etc.
-
- t_link: creates the structure (list) which describes a type.
- means array-of, function-returning, pointer-to,
- or element-consisting-of, and is NULL at the base type.
-
- t_list: provides the "backbone" of one of three kinds of lists
- depending on t_typtok:
-
- S_ELEMENT_TYPE: list of elements of a structure.
- U_ELEMENT_TYPE: list of elements of a union.
- D_ELEMENT_TYPE: list of declarations.
-
- t_mclass: modifier bits. NOT storage class.
- Note that CONST and VOLATILE resemble storage class in
- some respects.
-
- t_dim: dimension of arrays, or 1 for other base types.
- For D_ELEMENT_TYPE, as for S_ELEMENT_TYPE.
- For S_ELEMENT_TYPE, the "offset" of the structure element
- from the beginning of the struct.
- For U_ELEMENT_TYPE, the "offset", which is always 0.
-
- t_size: the size of one object in bytes (what sizeof returns).
- t_tsize of an array of 200 longs will be 800.
- t_tsize of a struct may yield surprises because of
- even-boundary padding
- for elements, t_size is zero.
-
- t_parent: pointer to symbol table entry of an ELEMENT
- */
- struct type_node {
- int t_typtok; /* Primary storage type */
- struct type_node * t_link; /* Subtype tree (list) */
- struct type_node * t_list; /* Struct/union/decl list */
- int t_mclass; /* Modifier bits */
- unsigned long t_tdim; /* Dimension/internal offsets */
- unsigned long t_tsize; /* What sizeof() returns */
- struct st_node * t_parent; /* Element name/aggregate tag */
- };
-
- /*
- Define "cons nodes" used to create trees.
- They take their name from "cons cells" in the LISP language.
- The n_next and n_car fields are perfectly symmetrical.
-
- n_type is COMMA_TOK or SEMICOLON_TOK.
- */
- struct cons_node {
- NODE_HEAD;
- struct node * ncar; /* Pointer to second subtree */
- };
-
- #define n_car u.consn.ncar
-
- /*
- Define the node produced by parsing an if statement.
-
- n_type is K_IF.
- */
- struct if_node {
- NODE_HEAD;
- struct node * nibool;
- struct node * nithen;
- struct node * nielse;
- };
-
- #define n_ibool u.ifn.nibool
- #define n_ithen u.ifn.nithen
- #define n_ielse u.ifn.nielse
-
- /*
- Define the node produce by parsing a do statement.
-
- n_type is K_DO.
- */
- struct do_node {
- NODE_HEAD;
- struct node * ndbdy;
- struct node * ndbool;
- };
-
- #define n_dbdy u.don.ndbdy
- #define n_dbool u.don.ndbool
-
- /*
- Define the node produced by parsing a while statement.
-
- n_type is K_WHILE.
- */
- struct while_node {
- NODE_HEAD;
- struct node * nwbdy;
- struct node * nwbool;
- };
-
- #define n_wbdy u.whilen.nwbdy
- #define n_wbool u.whilen.nwbool
-
- /*
- Define the node produced by parsing a for statement.
-
- n_type is K_FOR.
- */
- struct for_node {
- NODE_HEAD;
- struct node * nf1list;
- struct node * nfbool;
- struct node * nf2list;
- struct node * nfbdy;
- };
-
- #define n_f1list u.forn.nf1list
- #define n_fbool u.forn.nfbool
- #define n_f2list u.forn.nf2list
- #define n_fbdy u.forn.nfbdy
-
- /*
- Define the node produced by parsing a switch statement.
-
- n_type is K_SWITCH.
- */
- struct switch_node {
- NODE_HEAD;
- struct node * nsval;
- struct node * nsbdy;
- struct node * nslist;
- struct node * nsdef;
- };
-
- #define n_sval u.switchn.nsval
- #define n_sbdy u.switchn.nsbdy
- #define n_slist u.switchn.nslist
- #define n_sdef u.switchn.nsdef
-
- /*
- Define the node produce by parsing a return statement.
-
- n_type is K_RETURN.
- */
- struct ret_node {
- NODE_HEAD;
- struct node * nrval;
- };
-
- #define n_rval u.retn.nrval
-
- /*
- Define the node produced by parsing a case in a switch.
-
- n_type is K_CASE, K_DEFAULT.
- */
- struct case_node {
- NODE_HEAD;
- long nccon; /* case constant. */
- struct node * nclab; /* ptr to label node. */
- struct node * nclist; /* list of cases. */
- };
-
- #define n_ccon u.casen.nccon
- #define n_clab u.casen.nclab
- #define n_clist u.casen.nclist
-
- /*
- Define the node produced by parsing a break or continue.
-
- n_type is K_BREAK, K_CONTINUE.
- */
- struct bc_node {
- NODE_HEAD;
- struct node * nbcparent; /* Backpointer to parent node. */
- };
-
- #define n_bcparent u.bcn.nbcparent
-
- /*
- Define parse node for goto's and labels.
- n_type is LABEL_TOK or K_GOTO.
-
- NOTE: The PARSE node for a user label is different from
- the CODE node for user and internal labels!!!
- */
- struct plabel_node {
- NODE_HEAD;
- struct node * nplab;
- };
-
- #define n_plab u.plabeln.nplab
-
- /* Type is Z_TOK. */
- struct ztok_node {
- NODE_HEAD;
- int nztype;
- struct node * nzarg1;
- };
-
- #define n_ztype u.ztokn.nztype
- #define n_zarg1 u.ztokn.nzarg1
-
- /* Type is X_TOK ... and CC_TOK?? */
- struct xtok_node {
- NODE_HEAD;
- int nxtype;
- struct node * nxarg1;
- struct node * nxarg2;
- };
-
- #define n_xtype u.xtokn.nxtype
- #define n_xarg1 u.xtokn.nxarg1
- #define n_xarg2 u.xtokn.nxarg2
-
- /*
- CAUTION:
- g2.c (gen_pp) and exp.c (fold2) make some assumptions as
- to similarities between these op_nodes; also, the call_node
- uses the same form and so must also have the flags
-
- Nodes of this form all contain n_oflags, and are meant to
- be the is_argop() subenumeration, which is n-ary ops
- */
-
- /* Type is ternary operator. */
- struct ternop_node {
- NODE_HEAD;
- int noflags;
- struct node * narg1;
- struct node * narg2;
- struct node * narg3;
- };
-
- #define n_oflags u.ternopn.noflags
- #define n_arg1 u.ternopn.narg1
- #define n_arg2 u.ternopn.narg2
- #define n_arg3 u.ternopn.narg3
-
- /* Type is any binary operator. */
- struct binop_node {
- NODE_HEAD;
- int noflags;
- struct node * narg1;
- struct node * narg2;
- };
-
- /* Type is any unary operator. */
- struct unop_node {
- NODE_HEAD;
- int noflags;
- struct node * narg1;
- };
-
- /* Type is CALL_TOK, formally a binop, and actually an n-op */
- struct call_node {
- NODE_HEAD;
- int noflags;
- struct node * narg1; /* expression serving as name */
- struct node * narg2; /* argument list */
- };
-
- /*
- ---------- CODE GENERATION ----------
- */
-
- /*
- Define code nodes:
-
- Please NOTE: the code sometimes uses the fact that
- the c_code field is an alias for the n_type field in parse nodes.
-
- */
- #define CODE_HEADER\
- int codetype;\
- struct node * cnext;\
- struct node * cback
-
- /*
- Code node for machine instructions.
- Keep these with an even number of bytes.
-
- c_code is X_xxx.
- */
- struct code_node {
- CODE_HEADER;
- struct node * carg1; /* loc node for arg 1 */
- struct node * carg2; /* loc node for arg 2 */
- char clen1;
- char clen2;
- };
-
- #define c_arg1 u.coden.carg1
- #define c_arg2 u.coden.carg2
- #define c_len1 u.coden.clen1
- #define c_len2 u.coden.clen2
-
- /*
- Code node for compiler generated labels.
-
- c_code is O_LABEL.
- */
- struct clabel_node {
- CODE_HEADER;
- int cmark;
- int crefcount;
- int clabnum;
- };
-
- #define c_mark u.clabn.cmark
- #define c_refcount u.clabn.crefcount
- #define c_labnum u.clabn.clabnum
-
- /*
- Code node for user generated labels.
-
- c_code is O_ULABEL.
- */
- struct culabel_node {
- CODE_HEADER;
- int cmark;
- int crefcount;
- int clabnum;
- char * clabsym;
- };
-
- #define c_labsym u.culabn.clabsym
-
- /*
- Code node for user-generated literal code.
-
- c_code is O_LITERAL.
- */
- struct lit_node {
- CODE_HEADER;
- char * clit;
- };
-
- #define c_lit u.litn.clit
-
- /*
- Code node for line number flag
-
- c_code is O_LINENUM
- */
- struct line_node {
- CODE_HEADER;
- int clinenum;
- };
- #define c_linenum u.linen.clinenum
-
- /* Define "generic node" */
-
- /* NODE_HEAD fields. Note aliasing of n_type and c_code. */
- #define n_type u.locn.codetype
- #define n_next u.locn.nnext
- #define n_linno u.locn.nlinno
- #define n_cltype u.locn.ncltype
-
- /* CODE_HEADER fields. */
- #define c_code u.coden.codetype
- #define c_next u.coden.cnext
- #define c_back u.coden.cback
-
- /*
- WARNING: struct node must contain ONLY the union.
- The code assumes that one can allocate any struct n mentioned
- in node by calling m?_alloc(sizeof(struct n)).
- */
- struct node {
- union {
- /* Parse nodes. */
- struct loc_node locn;
- struct cons_node consn;
- struct if_node ifn;
- struct do_node don;
- struct while_node whilen;
- struct for_node forn;
- struct switch_node switchn;
- struct ret_node retn;
- struct case_node casen;
- struct bc_node bcn;
- struct plabel_node plabeln;
- struct xtok_node xtokn;
- struct ztok_node ztokn;
- struct ternop_node ternopn;
- struct binop_node binopn;
- struct unop_node unopn;
- struct call_node calln;
-
- /* Code nodes. */
- struct code_node coden;
- struct clabel_node clabn;
- struct culabel_node culabn;
- struct lit_node litn;
- struct line_node linen;
- }u;
- };
-
- /*
- Op node for boolean generation
- */
- struct diop {
- int o_true;
- int o_false;
- };
-
- /*
- Function-body node
- */
- struct fbody {
- struct node * parse;
- struct type_node * locals;
- unsigned long lcl_size;
- char * fname;
- struct type_node * formals;
- unsigned long fml_size;
- struct type_node * ftype;
- int fclass;
- };
-
- /*
- Initializer block
- */
- struct iblock {
- byte itype;
- byte isize;
- struct iblock * ilink;
- unsigned long idim;
- struct {
- long icn;
- char * ipt; /* ekr: 3/7/89 */
- } idata[/* EKR-----0----- */ 2];
- };
-
- /*
- Existence block, from x_exists
- */
- struct x_ex {
- byte xok;
- byte xlen;
- int xopcode;
- };
-
- /* Tokens. */
-
- struct t1_entry_struct {
- char * e_string;
- int e_arg1;
- int e_arg2;
- };
-
- struct t1_tab_struct {
- struct t1_entry_struct * t_entry;
- short t_strlen;
- short t_entries;
- };
-