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 / csym.h < prev    next >
C/C++ Source or Header  |  1996-03-22  |  8KB  |  197 lines

  1. /*
  2.  * Structures for symbol table entries.
  3.  */
  4.  
  5. #define MaybeTrue  1 /* condition might be true at run time */
  6. #define MaybeFalse 2 /* condition might be false at run time */
  7.  
  8. #define MayConvert 1 /* type conversion may convert the value */ 
  9. #define MayDefault 2 /* defaulting type conversion may use default */
  10. #define MayKeep    4 /* conversion may succeed without any actual conversion */
  11.  
  12. struct centry {        /* constant table entry */
  13.    struct centry *blink;    /*   link for bucket chain */
  14.    char *image;            /*   pointer to string image of literal */
  15.    int length;            /*   length of string */
  16.    union {
  17.       unsigned short *cset;    /*   pointer to bit string for cset literal */
  18.       long intgr;        /*   value of integer literal */
  19.       } u;
  20.    uword flag;            /*   type of literal flag */
  21.    char prefix[PrfxSz+1];    /*   unique prefix used in data block name */
  22.    };
  23.  
  24. struct fentry {            /* field table entry */
  25.    struct fentry *blink;    /*   link for bucket chain */
  26.    char *name;            /*   name of field */
  27.    struct par_rec *rlist;    /*   head of list of records */
  28.    };
  29.  
  30. struct lentry {            /* local table entry */
  31.    struct lentry *blink;    /*   link for bucket chain */
  32.    char *name;            /*   name of variable */
  33.    uword flag;            /*   variable flags */
  34.    union {
  35.       struct gentry *global;    /*   for globals: global symbol table entry */
  36.       int index;                /*   type index; run-time descriptor index */
  37.       } val;
  38.    struct lentry *next;        /*   used for linking a class of variables */
  39.    };
  40.  
  41. struct gentry {        /* global table entry */
  42.    struct gentry *blink;     /*   link for bucket chain */
  43.    char *name;             /*   name of variable */
  44.    uword flag;             /*   variable flags */
  45.    union {
  46.       struct implement *builtin; /*   pointer to built-in function */
  47.       struct pentry *proc;     /*   pointer to procedure entry */
  48.       struct rentry *rec;     /*   pointer to record entry */
  49.       } val;
  50.    int index;             /*   index into global array */
  51.    int init_type;                /*   initial type if procedure */
  52.    };
  53.  
  54. /*
  55.  * Structure for list of parent records for a field name.
  56.  */
  57. struct par_rec {
  58.    struct rentry *rec;        /* parent record */
  59.    int offset;            /* field's offset within this record */
  60.    int mark;                    /* used during code generation */
  61.    struct par_rec *next;
  62.    };
  63.  
  64. /*
  65.  * Structure for a procedure.
  66.  */
  67. struct pentry {
  68.    char *name;            /* name of procedure */
  69.    char prefix[PrfxSz+1];    /* prefix to make name unique */
  70.    struct lentry **lhash;    /* hash area for procedure's local table */
  71.    int nargs;            /* number of args */
  72.    struct lentry *args;        /* list of arguments in reverse order */
  73.    int ndynam;                  /* number of dynamic locals */
  74.    struct lentry *dynams;       /* list of dynamics in reverse order */
  75.    int nstatic;                 /* number of statics */
  76.    struct lentry *statics;    /* list of statics in reverse order */
  77.    struct node *tree;        /* syntax tree for procedure */
  78.    int has_coexpr;        /* this procedure contains co-expressions */
  79.    int tnd_loc;            /* number of tended dynamic locals */
  80.    int ret_flag;        /* proc returns, suspends, and/or fails */
  81.    int reachable;               /* this procedure may be executed */
  82.    int iteration;        /* last iteration of type inference performed */
  83.    int arg_lst;            /* for varargs - the type number of the list */
  84.    unsigned int *ret_typ;    /* type returned from procedure */
  85.    struct store *in_store;    /* store at start of procedure */
  86.    struct store *susp_store;    /* store for resumption points of procedure */
  87.    struct store *out_store;    /* store on exiting procedure */
  88.    struct lentry **vartypmap;   /* mapping from var types to symtab entries */
  89.    unsigned int *coexprs;       /* co-expressions in which proc may be called */
  90.    struct pentry *next;
  91.    };
  92.  
  93. /*
  94.  * Structure for a record.
  95.  */
  96. struct rentry {
  97.    char *name;            /* name of record */
  98.    char prefix[PrfxSz+1];    /* prefix to make name unique */
  99.    int frst_fld;        /* offset of variable type of 1st field */
  100.    int nfields;            /* number of fields */
  101.    struct fldname *fields;    /* list of field names in reverse order */
  102.    int rec_num;            /* id number for record */
  103.    struct rentry *next;
  104.    };
  105.  
  106. struct fldname {                /* record field */
  107.    char *name;                  /* field name */
  108.    struct fldname *next;
  109.    };
  110.  
  111. /*
  112.  * Structure used to analyze whether a type_case statement can be in-lined.
  113.  *  Only one type check is supported: the type_case will be implemented
  114.  *  as an "if" statement.
  115.  */
  116. struct case_anlz {
  117.    int n_cases;             /* number of cases actually needed for this use */
  118.    int typcd;               /* for "if" optimization, the type code to check */
  119.    struct il_code *il_then; /* for "if" optimization, the then clause */
  120.    struct il_code *il_else; /* for "if" optimization, the else clause */
  121.    };
  122.  
  123. /*
  124.  * spec_op contains the implementations for operations with do not have
  125.  *  standard unary/binary syntax.
  126.  */
  127. #define ToOp      0  /* index into spec_op of i to j */
  128. #define ToByOp    1  /* index into spec_op of i to j by k */
  129. #define SectOp    2  /* index into spec_op of x[i:j] */
  130. #define SubscOp   3  /* index into spec_op of x[i] */
  131. #define ListOp    4  /* index into spec_op of [e1, e2, ... ] */
  132. #define NumSpecOp 5
  133. extern struct implement *spec_op[NumSpecOp];
  134.  
  135. /*
  136.  * Flag values.
  137.  */
  138.  
  139. #define F_Global        01    /* variable declared global externally */
  140. #define F_Proc            04    /* procedure */
  141. #define F_Record       010    /* record */
  142. #define F_Dynamic       020    /* variable declared local dynamic */
  143. #define F_Static       040    /* variable declared local static */
  144. #define F_Builtin      0100    /* identifier refers to built-in procedure */
  145. #define F_StrInv          0200  /* variable needed for string invocation */
  146. #define F_ImpError      0400    /* procedure has default error */
  147. #define F_Argument     01000    /* variable is a formal parameter */
  148. #define F_IntLit     02000    /* literal is an integer */
  149. #define F_RealLit     04000    /* literal is a real */
  150. #define F_StrLit    010000    /* literal is a string */
  151. #define F_CsetLit    020000    /* literal is a cset */
  152. #define F_Field        040000  /* identifier refers to a record field */
  153. #define F_SmplInv      0100000  /* identifier only used in simple invocation */
  154.  
  155. /*
  156.  * Symbol table region pointers.
  157.  */
  158.  
  159. extern struct implement *bhash[];    /* hash area for built-in func table */
  160. extern struct centry *chash[];        /* hash area for constant table */
  161. extern struct fentry *fhash[];        /* hash area for field table */
  162. extern struct gentry *ghash[];        /* hash area for global table */
  163. extern struct implement *khash[];    /* hash area for keyword table */
  164. extern struct implement *ohash[];    /* hash area for operator table */
  165.  
  166. extern struct pentry *proc_lst; /* procedure list */
  167. extern struct rentry *rec_lst;  /* record list */
  168.  
  169. extern int max_sym; /* max number of parameter symbols in run-time routines */
  170. extern int max_prm; /* max number of parameters for any invocable routine */
  171.  
  172. extern struct symtyps *cur_symtyps; /* maps run-time routine symbols to types */
  173. extern struct pentry *cur_proc; /* procedure currently being translated */
  174.  
  175. /*
  176.  * Hash functions for symbol tables. Note, hash table sizes (xHSize)
  177.  *  are all a power of 2.
  178.  */
  179.  
  180. #define CHasher(x)    (((word)x)&(CHSize-1))     /* constant symbol table */
  181. #define FHasher(x)    (((word)x)&(FHSize-1))     /* field symbol table */
  182. #define GHasher(x)    (((word)x)&(GHSize-1))     /* global symbol table */
  183. #define LHasher(x)    (((word)x)&(LHSize-1))     /* local symbol table */
  184.  
  185. /*
  186.  * flags for implementation entries.
  187.  */
  188. #define ProtoPrint 1  /* a prototype has already been printed */
  189. #define InStrTbl   2  /* operator is in string table */
  190.  
  191. /*
  192.  * Whether an operation can fail may depend on whether error conversion
  193.  *  is allowed. The following macro checks this.
  194.  */
  195. #define MightFail(ret_flag) ((ret_flag & DoesFail) ||\
  196.    (err_conv && (ret_flag & DoesEFail)))
  197.