decspecs.c 1.9 KB

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