declarator.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "botch_free.h"
  8. #include <alloc.h>
  9. #include "arith.h"
  10. #include "type.h"
  11. #include "Lpars.h"
  12. #include "declar.h"
  13. #include "idf.h"
  14. #include "label.h"
  15. #include "expr.h"
  16. #include "sizes.h"
  17. struct declarator null_declarator;
  18. struct type *
  19. declare_type(tp, dc)
  20. struct type *tp;
  21. struct declarator *dc;
  22. {
  23. /* Applies the decl_unary list starting at dc->dc_decl_unary
  24. to the type tp and returns the result.
  25. */
  26. register struct decl_unary *du = dc->dc_decl_unary;
  27. while (du) {
  28. tp = construct_type(du->du_fund, tp, du->du_count);
  29. du = du->next;
  30. }
  31. return tp;
  32. }
  33. add_decl_unary(dc, fund, count, fm)
  34. register struct declarator *dc;
  35. arith count;
  36. struct formal *fm;
  37. {
  38. /* A decl_unary describing a constructor with fundamental
  39. type fund and with size count is inserted in front of the
  40. declarator dc.
  41. */
  42. register struct decl_unary *new = new_decl_unary();
  43. new->next = dc->dc_decl_unary;
  44. new->du_fund = fund;
  45. new->du_count = count;
  46. if (fm) {
  47. if (dc->dc_decl_unary) {
  48. /* paramlist only allowed at first decl_unary */
  49. error("formal parameter list discarded");
  50. }
  51. else {
  52. /* register the parameters */
  53. dc->dc_formal = fm;
  54. }
  55. }
  56. dc->dc_decl_unary = new;
  57. }
  58. remove_declarator(dc)
  59. struct declarator *dc;
  60. {
  61. /* The decl_unary list starting at dc->dc_decl_unary is
  62. removed.
  63. */
  64. register struct decl_unary *du = dc->dc_decl_unary;
  65. while (du) {
  66. struct decl_unary *old_du = du;
  67. du = du->next;
  68. free_decl_unary(old_du);
  69. }
  70. }
  71. reject_params(dc)
  72. register struct declarator *dc;
  73. {
  74. /* The declarator is checked to have no parameters, if it
  75. is a function.
  76. */
  77. if (dc->dc_formal) {
  78. error("non_empty formal parameter pack");
  79. free_formals(dc->dc_formal);
  80. dc->dc_formal = 0;
  81. }
  82. }
  83. check_array_subscript(expr)
  84. register struct expr *expr;
  85. {
  86. arith size = expr->VL_VALUE;
  87. if (size < 0) {
  88. error("array size is negative");
  89. expr->VL_VALUE = (arith)1;
  90. }
  91. else
  92. if (size == 0) {
  93. warning("array size is 0");
  94. }
  95. else
  96. if (size & ~max_unsigned) { /* absolutely ridiculous */
  97. expr_error(expr, "overflow in array size");
  98. expr->VL_VALUE = (arith)1;
  99. }
  100. }