home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / GNU / MAWK11AS.ZIP / SYMTYPE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  4.5 KB  |  183 lines

  1.  
  2. /********************************************
  3. symtype.h
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the AWK programming language.
  8.  
  9. Mawk is distributed without warranty under the terms of
  10. the GNU General Public License, version 2, 1991.
  11. ********************************************/
  12.  
  13. /*$Log:    symtype.h,v $
  14.  * Revision 5.1  91/12/05  07:59:37  brennan
  15.  * 1.1 pre-release
  16.  * 
  17. */
  18.  
  19. /* types related to symbols are defined here */
  20.  
  21. #ifndef  SYMTYPE_H
  22. #define  SYMTYPE_H
  23.  
  24.  
  25. /* struct to hold info about builtins */
  26. typedef struct {
  27. char *name ;
  28. PF_CP  fp ;  /* ptr to function that does the builtin */
  29. unsigned char min_args, max_args ; 
  30. /* info for parser to check correct number of arguments */
  31. } BI_REC ;
  32.  
  33. /*---------------------------
  34.    structures and types for arrays
  35.  *--------------------------*/
  36.  
  37. /* array hash nodes */
  38.  
  39. /* string node */
  40. typedef  struct anode {
  41. struct anode *link , *ilink ;
  42. STRING *sval ;
  43. int     ival ;
  44. CELL   *cp ;
  45. }  ANODE ;
  46.  
  47.  
  48. typedef struct array {
  49. ANODE *link , *ilink ;
  50. } *ARRAY ;
  51.  
  52. #define  CREATE         1
  53. #define  NO_CREATE      0
  54.  
  55. /* note ARRAY is a ptr to a hash table */
  56.  
  57. CELL *PROTO(array_find, (ARRAY,CELL *, int) ) ;
  58. INST *PROTO(array_loop, (INST *, CELL *, CELL *) ) ;
  59. void PROTO(array_delete, (ARRAY, CELL *) ) ;
  60. CELL *PROTO(array_cat, (CELL *, int) ) ;
  61. void PROTO(array_free, (ARRAY) ) ;
  62. void PROTO(load_array, (ARRAY,int)) ;
  63.  
  64. #define new_ARRAY() (ARRAY)memset(zmalloc(A_HASH_PRIME *\
  65.                         sizeof(struct array)),\
  66.                         0 , SIZE_T(A_HASH_PRIME*sizeof(struct array)))
  67.  
  68. extern  ARRAY  Argv ;
  69.  
  70. /* struct to hold the state of an array loop */
  71. typedef struct {
  72. CELL *var ;
  73. ARRAY  A  ;
  74. int index ;   /* A[index]  */
  75. ANODE *ptr ;
  76. } ALOOP_STATE ;
  77.  
  78. int  PROTO( inc_aloop_state, (ALOOP_STATE*)) ;
  79.  
  80. /* for parsing  (i,j) in A  */
  81. typedef  struct {
  82. INST *start ;
  83. int cnt ;
  84. } ARG2_REC ;
  85.  
  86. /*------------------------
  87.   user defined functions
  88.   ------------------------*/
  89.  
  90. typedef  struct fblock {
  91. char *name ;
  92. INST *code  ;
  93. unsigned short nargs ;
  94. char *typev ;  /* array of size nargs holding types */
  95. } FBLOCK ;   /* function block */
  96.  
  97. void  PROTO(add_to_fdump_list, (FBLOCK *) ) ;
  98. void  PROTO( fdump, (void) ) ;
  99.  
  100. /*-------------------------
  101.   elements of the symbol table
  102.   -----------------------*/
  103.  
  104. #define  ST_NONE 0
  105. #define  ST_VAR   1
  106. #define  ST_KEYWORD   2
  107. #define  ST_BUILTIN 3 /* a pointer to a builtin record */
  108. #define  ST_ARRAY   4 /* a void * ptr to a hash table */
  109. #define  ST_FIELD   5  /* a cell ptr to a field */
  110. #define  ST_FUNCT   6
  111. #define  ST_NR      7  /*  NR is special */
  112. #define  ST_ENV     8  /* and so is ENVIRON */
  113. #define  ST_LOCAL_NONE  9
  114. #define  ST_LOCAL_VAR   10
  115. #define  ST_LOCAL_ARRAY 11
  116.  
  117. #define  is_local(stp)   ((stp)->type>=ST_LOCAL_NONE)
  118.  
  119. typedef  struct {
  120. char *name ;
  121. char type ;
  122. unsigned char offset ;  /* offset in stack frame for local vars */
  123. union {
  124. CELL *cp ;
  125. int  kw ;
  126. PF_CP fp ;
  127. BI_REC *bip ;
  128. ARRAY  array ; 
  129. FBLOCK  *fbp ;
  130. } stval ;
  131. }  SYMTAB ;
  132.  
  133.  
  134. /*****************************
  135.  structures for type checking function calls
  136.  ******************************/
  137.  
  138. typedef  struct ca_rec {
  139. struct ca_rec  *link ;
  140. short type ;
  141. short arg_num ;  /* position in callee's stack */
  142. /*---------  this data only set if we'll  need to patch -------*/
  143. /* happens if argument is an ID or type ST_NONE or ST_LOCAL_NONE */
  144.  
  145. int call_offset ;
  146. /* where the type is stored */
  147. SYMTAB  *sym_p ;  /* if type is ST_NONE  */
  148. char *type_p ;  /* if type  is ST_LOCAL_NONE */
  149. }  CA_REC  ; /* call argument record */
  150.  
  151. /* type field of CA_REC matches with ST_ types */
  152. #define   CA_EXPR       ST_LOCAL_VAR
  153. #define   CA_ARRAY      ST_LOCAL_ARRAY
  154.  
  155. typedef  struct fcall {
  156. struct fcall *link ;
  157. FBLOCK  *callee ;
  158. short   call_scope ;
  159. FBLOCK  *call ;  /* only used if call_scope == SCOPE_FUNCT  */
  160. INST    *call_start ; /* computed later as code may be moved */
  161. CA_REC  *arg_list ;
  162. short   arg_cnt_checked ;
  163. unsigned line_no ; /* for error messages */
  164. } FCALL_REC ;
  165.  
  166. extern  FCALL_REC  *resolve_list ;
  167.  
  168. void PROTO(resolve_fcalls, (void) ) ;
  169. void PROTO(check_fcall, (FBLOCK*,int,FBLOCK*,CA_REC*,unsigned) ) ;
  170.  
  171. /* hash.c */
  172. unsigned  PROTO( hash, (char *) ) ;
  173. SYMTAB *PROTO( insert, (char *) ) ;
  174. SYMTAB *PROTO( find, (char *) ) ;
  175. char *PROTO( reverse_find, (int, PTR)) ;
  176. SYMTAB *PROTO( save_id, (char *) ) ;
  177. void    PROTO( restore_ids, (void) ) ;
  178.  
  179. /* error.c */
  180. void  PROTO(type_error, (SYMTAB *) ) ;
  181.  
  182. #endif  /* SYMTYPE_H */
  183.