decspecs.c 2.2 KB

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