declarator.c 2.1 KB

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