decspecs.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 error("short with illegal type");
  48. break;
  49. case LONG:
  50. if (tp == int_type)
  51. tp = long_type;
  52. else
  53. if (tp == float_type)
  54. tp = double_type;
  55. else error("long with illegal type");
  56. break;
  57. }
  58. if (ds->ds_unsigned) {
  59. switch (tp->tp_fund) {
  60. case CHAR:
  61. if (options['R'])
  62. warning("unsigned char not allowed");
  63. tp = uchar_type;
  64. break;
  65. case SHORT:
  66. if (options['R'])
  67. warning("unsigned short not allowed");
  68. tp = ushort_type;
  69. break;
  70. case INT:
  71. tp = uint_type;
  72. break;
  73. case LONG:
  74. if (options['R'])
  75. warning("unsigned long not allowed");
  76. tp = ulong_type;
  77. break;
  78. default:
  79. error("unsigned with illegal type");
  80. break;
  81. }
  82. }
  83. ds->ds_type = tp;
  84. }