declarator.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /* $Id$ */
  6. /* D E C L A R A T O R M A N I P U L A T I O N */
  7. #include "debug.h"
  8. #include "botch_free.h"
  9. #include <alloc.h>
  10. #include <flt_arith.h>
  11. #include "arith.h"
  12. #include "type.h"
  13. #include "proto.h"
  14. #include "Lpars.h"
  15. #include "declar.h"
  16. #include "def.h"
  17. #include "idf.h"
  18. #include "label.h"
  19. #include "expr.h"
  20. #include "sizes.h"
  21. #include "level.h"
  22. extern char options[];
  23. struct declarator null_declarator;
  24. struct type *
  25. declare_type(tp, dc)
  26. struct type *tp;
  27. struct declarator *dc;
  28. {
  29. /* Applies the decl_unary list starting at dc->dc_decl_unary
  30. to the type tp and returns the result.
  31. Functions that are declared within a parameter type list
  32. are purely prototypes. Simply add the type list to the
  33. function node.
  34. */
  35. register struct decl_unary *du = dc->dc_decl_unary;
  36. while (du) {
  37. tp = construct_type(du->du_fund, tp, du->du_typequal,
  38. du->du_count, du->du_proto);
  39. du = du->next;
  40. }
  41. return tp;
  42. }
  43. add_decl_unary(dc, fund, qual, count, fm, pl)
  44. register struct declarator *dc;
  45. int qual;
  46. arith count;
  47. struct formal *fm;
  48. struct proto *pl;
  49. {
  50. /* A decl_unary describing a constructor with fundamental
  51. type fund and with size count is inserted in front of the
  52. declarator dc.
  53. */
  54. register struct decl_unary *new = new_decl_unary();
  55. new->next = dc->dc_decl_unary;
  56. new->du_fund = fund;
  57. new->du_count = count;
  58. new->du_typequal = qual;
  59. new->du_proto = pl;
  60. if (fm) {
  61. if (dc->dc_decl_unary) {
  62. /* parameters only allowed at first decl_unary */
  63. error("formal parameters list discarded");
  64. }
  65. else {
  66. /* register the proto */
  67. dc->dc_formal = fm;
  68. }
  69. }
  70. dc->dc_decl_unary = new;
  71. }
  72. remove_declarator(dc)
  73. struct declarator *dc;
  74. {
  75. /* The decl_unary list starting at dc->dc_decl_unary is
  76. removed.
  77. */
  78. register struct decl_unary *du = dc->dc_decl_unary;
  79. while (du) {
  80. struct decl_unary *old_du = du;
  81. du = du->next;
  82. free_decl_unary(old_du);
  83. }
  84. }
  85. reject_params(dc)
  86. register struct declarator *dc;
  87. {
  88. /* The declarator is checked to have no parameters, if it
  89. is an old-style function. If it is a new-style function,
  90. the identifiers are removed. The function is not called in
  91. case of a function definition.
  92. */
  93. register struct decl_unary *du = dc->dc_decl_unary;
  94. int err_given = 0;
  95. if (dc->dc_formal) {
  96. error("non_empty formal parameter pack");
  97. free_formals(dc->dc_formal);
  98. dc->dc_formal = 0;
  99. err_given = 1;
  100. }
  101. while (du) {
  102. if (du->du_fund == FUNCTION) {
  103. if (du->du_proto) remove_proto_idfs(du->du_proto);
  104. else if (! err_given && ! options['o']) {
  105. err_given = 1;
  106. warning("old-fashioned function declaration");
  107. }
  108. }
  109. du = du->next;
  110. }
  111. }
  112. check_array_subscript(expr)
  113. register struct expr *expr;
  114. {
  115. arith size = expr->VL_VALUE;
  116. if (size < 0) {
  117. error("array size is negative");
  118. expr->VL_VALUE = (arith)1;
  119. }
  120. else
  121. if (size == 0) {
  122. strict("array size is 0");
  123. }
  124. else
  125. if (size & ~max_unsigned) { /* absolutely ridiculous */
  126. expr_error(expr, "overflow in array size");
  127. expr->VL_VALUE = (arith)1;
  128. }
  129. }