declarator.c 2.1 KB

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