home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / iconc / ctree.h < prev    next >
C/C++ Source or Header  |  1996-03-22  |  7KB  |  185 lines

  1. /*
  2.  * Structure of a tree node.
  3.  */
  4.  
  5. typedef    struct node    *nodeptr;
  6.  
  7. /*
  8.  * Kinds of fields in syntax tree node.
  9.  */
  10. union field {
  11.    long n_val;         /* integer-valued fields */
  12.    char *n_str;         /* string-valued fields */
  13.    struct lentry *lsym;  /* fields referencing local symbol table entries */ 
  14.    struct centry *csym;  /* fields referencing constant symbol table entries */
  15.    struct implement *ip; /* fields referencing an operation */
  16.    struct pentry *proc;     /* pointer to procedure entry */
  17.    struct rentry *rec;     /* pointer to record entry */
  18.    unsigned int *typ;    /* extra type field */
  19.    nodeptr n_ptr;     /* subtree pointers */
  20.    };
  21.  
  22. /*
  23.  * A store is an array that maps variables types (which are given indexes)
  24.  *  to the types stored within the variables.
  25.  */
  26. struct store {
  27.    struct store *next;
  28.    int perm;               /* flag: whether store stays across iterations */
  29.    unsigned int *types[1]; /* actual size is number of variables */
  30.    };
  31.  
  32. /*
  33.  * Array of parameter types for an operation call.
  34.  */
  35. struct symtyps {
  36.    int nsyms;                /* number of parameter symbols */
  37.    struct symtyps *next;
  38.    unsigned int *types[1];   /* really one for every symbol */
  39.    };
  40.  
  41. /*
  42.  * definitions for maintaining allocation status.
  43.  */
  44. #define NotAlloc 0   /* temp var neither in use nor reserved */
  45. #define InUnse   1   /* temp var currently contains live variable */
  46. /*            n < 0     reserved: must be free by node with postn field = n */
  47.  
  48. #define DescTmp 1    /* allocation of descriptor temporary */
  49. #define CIntTmp 2    /* allocation of C integer temporary */
  50. #define CDblTmp 3    /* allocation of C double temporary */
  51. #define SBuf    4    /* allocation of string buffer */
  52. #define CBuf    5    /* allocation of cset buffer */
  53.  
  54. struct freetmp {     /* list of things to free at a node */
  55.    int kind;         /*   DescTmp, CIntTmp, CDblTmp, SBuf, or CBuf */
  56.    int indx;         /*   index into status array */
  57.    int old;          /*   old status */
  58.    struct freetmp *next;
  59.    };
  60.  
  61. struct node {
  62.    int n_type;            /* node type */
  63.    char *n_file;        /* name of file containing source program */
  64.    int n_line;            /* line number in source program */
  65.    int n_col;            /* column number in source program */
  66.    int flag;
  67.    int *new_types;          /* pntr to array of struct types created here */
  68.    unsigned int *type;        /* type of this expression */
  69.    struct store *store;     /* if needed, store saved between iterations */
  70.    struct symtyps *symtyps; /* for operation in data base: types of arg syms */
  71.    nodeptr lifetime;        /* lifetime of intermediate result */
  72.    int reuse;               /* result may be reused without being recomputed */
  73.    nodeptr intrnl_lftm;     /* lifetime of variables internal to operation */
  74.    int postn;               /* relative position of node in execution order */
  75.    struct freetmp *freetmp; /* temporary variables to free at this point */
  76.    union field n_field[1];  /* node fields */
  77.    };
  78.  
  79. /*
  80.  * NewNode - allocate a parse tree node with "size" fields.
  81.  */
  82. #define NewNode(size) (struct node *)alloc((unsigned int)\
  83.     (sizeof(struct node) + (size-1) * sizeof(union field)))
  84.  
  85. /*
  86.  * Macros to access fields of parse tree nodes.
  87.  */
  88.  
  89. #define Type(t)        t->n_type
  90. #define File(t)        t->n_file
  91. #define Line(t)        t->n_line
  92. #define Col(t)        t->n_col
  93. #define Tree0(t)    t->n_field[0].n_ptr
  94. #define Tree1(t)    t->n_field[1].n_ptr
  95. #define Tree2(t)    t->n_field[2].n_ptr
  96. #define Tree3(t)    t->n_field[3].n_ptr
  97. #define Tree4(t)    t->n_field[4].n_ptr
  98. #define Val0(t)        t->n_field[0].n_val
  99. #define Val1(t)        t->n_field[1].n_val
  100. #define Val2(t)        t->n_field[2].n_val
  101. #define Val3(t)        t->n_field[3].n_val
  102. #define Val4(t)        t->n_field[4].n_val
  103. #define Str0(t)        t->n_field[0].n_str
  104. #define Str1(t)        t->n_field[1].n_str
  105. #define Str2(t)        t->n_field[2].n_str
  106. #define Str3(t)        t->n_field[3].n_str
  107. #define LSym0(t)    t->n_field[0].lsym
  108. #define CSym0(t)    t->n_field[0].csym
  109. #define Impl0(t)    t->n_field[0].ip
  110. #define Impl1(t)    t->n_field[1].ip
  111. #define Rec1(t)        t->n_field[1].rec
  112. #define Proc1(t)    t->n_field[1].proc
  113. #define Typ4(t)        t->n_field[4].typ
  114.  
  115. /*
  116.  * External declarations.
  117.  */
  118.  
  119. extern nodeptr yylval;        /* parser's current token value */
  120. extern struct node tok_loc;     /* "model" token holding current location */
  121.  
  122. /*
  123.  * Node types.
  124.  */
  125.  
  126. #define N_Activat     1        /* activation control structure */
  127. #define N_Alt         2        /* alternation operator */
  128. #define N_Apply         3        /* procedure application */
  129. #define N_Augop         4        /* augmented operator */
  130. #define N_Bar         5        /* generator control structure */
  131. #define N_Break         6        /* break statement */
  132. #define N_Case         7        /* case statement */
  133. #define N_Ccls         8        /* case clause */
  134. #define N_Clist         9        /* list of case clauses */
  135. #define N_Create    10        /* create control structure */
  136. #define N_Cset        11        /* cset literal */
  137. #define N_Elist        12        /* list of expressions */
  138. #define N_Empty        13        /* empty expression or statement */
  139. #define N_Field        14        /* record field reference */
  140. #define N_Id        15        /* identifier token */
  141. #define N_If        16        /* if-then-else statement */
  142. #define N_Int        17        /* integer literal */
  143. #define N_Invok        18        /* invocation */
  144. #define N_InvOp        19        /* invoke operation */
  145. #define N_InvProc    20        /* invoke operation */
  146. #define N_InvRec    21        /* invoke operation */
  147. #define N_Limit        22        /* LIMIT control structure */
  148. #define N_Loop        23        /* while, until, every, or repeat */
  149. #define N_Next        24        /* next statement */
  150. #define N_Not        25        /* not prefix control structure */
  151. #define N_Op        26        /* operator token */
  152. #define N_Proc        27        /* procedure */
  153. #define N_Real        28        /* real literal */
  154. #define N_Res        29        /* reserved word token */
  155. #define N_Ret        30        /* fail, return, or succeed */
  156. #define N_Scan        31        /* scan-using statement */
  157. #define N_Sect        32        /* s[i:j] (section) */
  158. #define N_Slist        33        /* list of statements */
  159. #define N_Str        34        /* string literal */
  160. #define N_SmplAsgn    35        /* simple assignment to named var */ 
  161. #define N_SmplAug    36        /* simple assignment to named var */ 
  162.  
  163. #define AsgnDirect 0  /* rhs of special := can compute directly into var */
  164. #define AsgnCopy   1  /* special := must copy result into var */
  165. #define AsgnDeref  2  /* special := must dereference result into var */
  166.  
  167.  
  168. /*
  169.  * Macros for constructing basic nodes.
  170.  */
  171.  
  172. #define CsetNode(a,b)        i_str_leaf(N_Cset,&tok_loc,a,b) 
  173. #define IdNode(a)        c_str_leaf(N_Id,&tok_loc,a) 
  174. #define IntNode(a)        c_str_leaf(N_Int,&tok_loc,a) 
  175. #define OpNode(a)        int_leaf(N_Op,&tok_loc,a) 
  176. #define RealNode(a)        c_str_leaf(N_Real,&tok_loc,a) 
  177. #define ResNode(a)        int_leaf(N_Res,&tok_loc,a) 
  178. #define StrNode(a,b)        i_str_leaf(N_Str,&tok_loc,a,b) 
  179.  
  180. /*
  181.  * MultiUnary - create subtree from an operator symbol that represents
  182.  *  multiple unary operators.
  183.  */
  184. #define MultiUnary(a,b) multiunary(optab[Val0(a)].tok.t_word, a, b)
  185.