decspecs.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 I O N S P E C I F I E R C H E C K I N G */
  7. #include "nofloat.h"
  8. #include "assert.h"
  9. #include "Lpars.h"
  10. #include "decspecs.h"
  11. #include "arith.h"
  12. #include "type.h"
  13. #include "level.h"
  14. #include "def.h"
  15. #include "noRoption.h"
  16. extern char options[];
  17. extern int level;
  18. extern char *symbol2str();
  19. struct decspecs null_decspecs;
  20. do_decspecs(ds)
  21. register struct decspecs *ds;
  22. {
  23. /* The provisional decspecs ds as obtained from the program
  24. is turned into a legal consistent decspecs.
  25. */
  26. register struct type *tp = ds->ds_type;
  27. ASSERT(level != L_FORMAL1);
  28. if ( level == L_GLOBAL &&
  29. (ds->ds_sc == AUTO || ds->ds_sc == REGISTER)
  30. ) {
  31. warning("no global %s variable allowed",
  32. symbol2str(ds->ds_sc));
  33. ds->ds_sc = GLOBAL;
  34. }
  35. if (level == L_FORMAL2) {
  36. if (ds->ds_sc_given &&
  37. ds->ds_sc != REGISTER){
  38. error("%s formal illegal", symbol2str(ds->ds_sc));
  39. ds->ds_sc = FORMAL;
  40. }
  41. }
  42. /* The tests concerning types require a full knowledge of the
  43. type and will have to be postponed to declare_idf.
  44. */
  45. /* some adjustments as described in RM 8.2 */
  46. if (tp == 0 && ds->ds_size == 0 && ds->ds_unsigned == 0) {
  47. ds->ds_notypegiven = 1;
  48. }
  49. if (tp == 0) {
  50. tp = int_type;
  51. }
  52. switch (ds->ds_size) {
  53. case SHORT:
  54. if (tp == int_type)
  55. tp = short_type;
  56. else
  57. error("short with illegal type");
  58. break;
  59. case LONG:
  60. if (tp == int_type)
  61. tp = long_type;
  62. else
  63. #ifndef NOFLOAT
  64. if (tp == float_type)
  65. tp = double_type;
  66. else
  67. #endif /* NOFLOAT */
  68. error("long with illegal type");
  69. break;
  70. }
  71. if (ds->ds_unsigned) {
  72. switch (tp->tp_fund) {
  73. case CHAR:
  74. #ifndef NOROPTION
  75. if (options['R'])
  76. warning("unsigned char not allowed");
  77. #endif
  78. tp = uchar_type;
  79. break;
  80. case SHORT:
  81. #ifndef NOROPTION
  82. if (options['R'])
  83. warning("unsigned short not allowed");
  84. #endif
  85. tp = ushort_type;
  86. break;
  87. case INT:
  88. tp = uint_type;
  89. break;
  90. case LONG:
  91. #ifndef NOROPTION
  92. if (options['R'])
  93. warning("unsigned long not allowed");
  94. #endif
  95. tp = ulong_type;
  96. break;
  97. default:
  98. error("unsigned with illegal type");
  99. break;
  100. }
  101. }
  102. ds->ds_type = tp;
  103. }