type.H 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. * Author: Ceriel J.H. Jacobs
  6. */
  7. /* T Y P E D E S C R I P T O R S T R U C T U R E */
  8. /* $Id$ */
  9. #include "dbsymtab.h"
  10. struct paramlist { /* structure for parameterlist of a PROCEDURE */
  11. struct paramlist *par_next;
  12. struct def *par_def; /* "df" of parameter */
  13. #define IsVarParam(xpar) ((int) ((xpar)->par_def->df_flags & D_VARPAR))
  14. #define TypeOfParam(xpar) ((xpar)->par_def->df_type)
  15. };
  16. typedef struct paramlist t_param;
  17. /* ALLOCDEF "paramlist" 20 */
  18. struct enume {
  19. struct def *en_enums; /* Definitions of enumeration literals */
  20. arith en_ncst; /* Number of constants */
  21. label en_rck; /* Label of range check descriptor */
  22. #define enm_enums tp_value.tp_enum->en_enums
  23. #define enm_ncst tp_value.tp_enum->en_ncst
  24. #define enm_rck tp_value.tp_enum->en_rck
  25. };
  26. /* ALLOCDEF "enume" 5 */
  27. struct subrange {
  28. arith su_lb, su_ub; /* lower bound and upper bound */
  29. label su_rck; /* label of range check descriptor */
  30. #define sub_lb tp_value.tp_subrange->su_lb
  31. #define sub_ub tp_value.tp_subrange->su_ub
  32. #define sub_rck tp_value.tp_subrange->su_rck
  33. };
  34. /* ALLOCDEF "subrange" 5 */
  35. struct array {
  36. struct type *ar_elem; /* type of elements */
  37. label ar_descr; /* label of array descriptor */
  38. arith ar_elsize; /* size of elements */
  39. arith ar_low; /* lower bound of index */
  40. arith ar_high; /* upper bound of index */
  41. #define arr_elem tp_value.tp_arr->ar_elem
  42. #define arr_descr tp_value.tp_arr->ar_descr
  43. #define arr_elsize tp_value.tp_arr->ar_elsize
  44. #define arr_low tp_value.tp_arr->ar_low
  45. #define arr_high tp_value.tp_arr->ar_high
  46. };
  47. /* ALLOCDEF "array" 5 */
  48. struct record {
  49. struct scope *rc_scope; /* scope of this record */
  50. /* members are in the symbol table */
  51. #define rec_scope tp_value.tp_record.rc_scope
  52. };
  53. struct proc {
  54. struct paramlist *pr_params;
  55. arith pr_nbpar; /* number of bytes parameters accessed */
  56. #define prc_params tp_value.tp_proc.pr_params
  57. #define prc_nbpar tp_value.tp_proc.pr_nbpar
  58. };
  59. struct set {
  60. arith st_low; /* lowerbound of subrange type of set */
  61. unsigned st_sz; /* size of constant set in compiler */
  62. #define set_low tp_value.tp_set.st_low
  63. #define set_sz tp_value.tp_set.st_sz
  64. };
  65. struct type {
  66. struct type *tp_next; /* used with ARRAY, PROCEDURE, POINTER, SET,
  67. SUBRANGE, EQUAL
  68. */
  69. short tp_fund; /* fundamental type or constructor */
  70. #define T_RECORD 0x0001
  71. #define T_ENUMERATION 0x0002
  72. #define T_INTEGER 0x0004
  73. #define T_CARDINAL 0x0008
  74. #define T_EQUAL 0x0010
  75. #define T_REAL 0x0020
  76. #define T_HIDDEN 0x0040
  77. #define T_POINTER 0x0080
  78. #define T_CHAR 0x0100
  79. #define T_WORD 0x0200
  80. #define T_SET 0x0400
  81. #define T_SUBRANGE 0x0800
  82. #define T_PROCEDURE 0x1000
  83. #define T_ARRAY 0x2000
  84. #define T_STRING 0x4000
  85. #define T_INTORCARD (T_INTEGER|T_CARDINAL)
  86. #define T_NOSUB (T_INTORCARD|T_ENUMERATION|T_CHAR)
  87. #define T_NUMERIC (T_INTORCARD|T_REAL)
  88. #define T_INDEX (T_ENUMERATION|T_CHAR|T_SUBRANGE)
  89. #define T_DISCRETE (T_INDEX|T_INTORCARD)
  90. #define T_CONSTRUCTED (T_ARRAY|T_SET|T_RECORD)
  91. #ifdef DBSYMTAB
  92. short tp_dbindex; /* index in debugger symbol table */
  93. #endif
  94. int tp_align; /* alignment requirement of this type */
  95. arith tp_size; /* size of this type */
  96. union {
  97. struct enume *tp_enum;
  98. struct subrange *tp_subrange;
  99. struct array *tp_arr;
  100. struct record tp_record;
  101. struct proc tp_proc;
  102. struct set tp_set;
  103. } tp_value;
  104. };
  105. typedef struct type t_type;
  106. /* ALLOCDEF "type" 50 */
  107. extern t_type
  108. *bool_type,
  109. *char_type,
  110. *int_type,
  111. *card_type,
  112. *longint_type,
  113. *longcard_type,
  114. *real_type,
  115. *longreal_type,
  116. *word_type,
  117. *byte_type,
  118. *address_type,
  119. *intorcard_type,
  120. *longintorcard_type,
  121. *bitset_type,
  122. *void_type,
  123. *std_type,
  124. *error_type; /* All from type.c */
  125. #include "nocross.h"
  126. #ifdef NOCROSS
  127. #include "target_sizes.h"
  128. #define word_align (AL_WORD)
  129. #define short_align (AL_SHORT)
  130. #define int_align (AL_INT)
  131. #define long_align (AL_LONG)
  132. #define float_align (AL_FLOAT)
  133. #define double_align (AL_DOUBLE)
  134. #define pointer_align (AL_POINTER)
  135. #define struct_align (AL_STRUCT)
  136. #define word_size (SZ_WORD)
  137. #define dword_size (2 * SZ_WORD)
  138. #define int_size (SZ_INT)
  139. #define short_size (SZ_SHORT)
  140. #define long_size (SZ_LONG)
  141. #define float_size (SZ_FLOAT)
  142. #define double_size (SZ_DOUBLE)
  143. #define pointer_size (SZ_POINTER)
  144. #define wrd_bits (8*(int)word_size)
  145. #else /* NOCROSS */
  146. extern int
  147. word_align,
  148. short_align,
  149. int_align,
  150. long_align,
  151. float_align,
  152. double_align,
  153. pointer_align,
  154. struct_align; /* All from type.c */
  155. extern arith
  156. word_size,
  157. dword_size,
  158. short_size,
  159. int_size,
  160. long_size,
  161. float_size,
  162. double_size,
  163. pointer_size; /* All from type.c */
  164. extern unsigned int
  165. wrd_bits; /* from cstoper.c */
  166. #endif /* NOCROSS */
  167. extern arith
  168. ret_area_size;
  169. extern arith
  170. align(); /* type.c */
  171. extern t_type
  172. *construct_type(),
  173. *standard_type(),
  174. *set_type(),
  175. *subr_type(),
  176. *proc_type(),
  177. *enum_type(),
  178. *qualified_type(),
  179. *intorcard(),
  180. *RemoveEqual(); /* All from type.c */
  181. #define NULLTYPE ((t_type *) 0)
  182. #define IsConformantArray(tpx) ((tpx)->tp_fund==T_ARRAY && (tpx)->tp_size==0)
  183. #define bounded(tpx) ((tpx)->tp_fund & T_INDEX)
  184. #define complex(tpx) ((tpx)->tp_fund & (T_RECORD|T_ARRAY))
  185. #define WA(sz) (align(sz, (int) word_size))
  186. #ifdef DEBUG
  187. #define ResultType(tpx) (assert((tpx)->tp_fund == T_PROCEDURE),\
  188. (tpx)->tp_next)
  189. #define ParamList(tpx) (assert((tpx)->tp_fund == T_PROCEDURE),\
  190. (tpx)->prc_params)
  191. #define IndexType(tpx) (assert((tpx)->tp_fund == T_ARRAY),\
  192. (tpx)->tp_next)
  193. #define ElementType(tpx) (assert((tpx)->tp_fund == T_SET),\
  194. (tpx)->tp_next)
  195. #define PointedtoType(tpx) (assert((tpx)->tp_fund == T_POINTER),\
  196. (tpx)->tp_next)
  197. #define SubBaseType(tpx) (assert((tpx)->tp_fund == T_SUBRANGE), \
  198. (tpx)->tp_next)
  199. #else /* DEBUG */
  200. #define ResultType(tpx) ((tpx)->tp_next)
  201. #define ParamList(tpx) ((tpx)->prc_params)
  202. #define IndexType(tpx) ((tpx)->tp_next)
  203. #define ElementType(tpx) ((tpx)->tp_next)
  204. #define PointedtoType(tpx) ((tpx)->tp_next)
  205. #define SubBaseType(tpx) ((tpx)->tp_next)
  206. #endif /* DEBUG */
  207. #define BaseType(tpx) ((tpx)->tp_fund == T_SUBRANGE ? (tpx)->tp_next : \
  208. (tpx))
  209. #define IsConstructed(tpx) ((tpx)->tp_fund & T_CONSTRUCTED)
  210. #define TooBigForReturnArea(tpx) ((tpx)->tp_size > ret_area_size)
  211. extern arith full_mask[];
  212. extern arith max_int[];
  213. extern arith min_int[];
  214. #define ufit(n, i) (((n) & ~full_mask[(i)]) == 0)