switches.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Peter Vreman
  4. This unit implements the parsing of the switches like $I-
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit switches;
  19. interface
  20. procedure HandleSwitch(switch,state:char);
  21. function CheckSwitch(switch,state:char):boolean;
  22. implementation
  23. uses globals,verbose,files,systems;
  24. {****************************************************************************
  25. Special functions for some switches
  26. ****************************************************************************}
  27. {$ifndef FPC}
  28. {$F+}
  29. {$endif}
  30. procedure sw_stackcheck;
  31. begin
  32. {$ifdef i386}
  33. if target_info.target=target_Linux then
  34. Message(scan_n_stack_check_global_under_linux);
  35. {$endif}
  36. end;
  37. {$ifndef FPC}
  38. {$F-}
  39. {$endif}
  40. {****************************************************************************
  41. Main Switches Parsing
  42. ****************************************************************************}
  43. type
  44. TSwitchType=(local,unitglobal,programglobal,illegal,unsupported);
  45. SwitchRec=record
  46. typesw : TSwitchType;
  47. setsw : tcswitch;
  48. proc : procedure;
  49. end;
  50. const
  51. SwitchTable:array['A'..'Z'] of SwitchRec=(
  52. {A} (typesw:unsupported; setsw:cs_none; proc:nil),
  53. {B} (typesw:unsupported; setsw:cs_none; proc:nil),
  54. {C} (typesw:illegal; setsw:cs_none; proc:nil),
  55. {D} (typesw:unitglobal; setsw:cs_debuginfo; proc:nil),
  56. {E} (typesw:programglobal; setsw:cs_fp_emulation; proc:nil),
  57. {F} (typesw:unsupported; setsw:cs_none; proc:nil),
  58. {G} (typesw:unsupported; setsw:cs_none; proc:nil),
  59. {H} (typesw:unsupported; setsw:cs_none; proc:nil),
  60. {I} (typesw:local; setsw:cs_iocheck; proc:nil),
  61. {J} (typesw:illegal; setsw:cs_none; proc:nil),
  62. {K} (typesw:unsupported; setsw:cs_none; proc:nil),
  63. {L} (typesw:unsupported; setsw:cs_none; proc:nil),
  64. {M} (typesw:local; setsw:cs_generate_rtti; proc:nil),
  65. {N} (typesw:unsupported; setsw:cs_none; proc:nil),
  66. {O} (typesw:unsupported; setsw:cs_none; proc:nil),
  67. {P} (typesw:unsupported; setsw:cs_none; proc:nil),
  68. {Q} (typesw:local; setsw:cs_check_overflow; proc:nil),
  69. {R} (typesw:local; setsw:cs_rangechecking; proc:nil),
  70. {S} (typesw:local; setsw:cs_check_stack; proc:nil),
  71. {T} (typesw:local; setsw:cs_typed_addresses; proc:nil),
  72. {U} (typesw:illegal; setsw:cs_none; proc:nil),
  73. {V} (typesw:local; setsw:cs_strict_var_strings; proc:nil),
  74. {W} (typesw:unsupported; setsw:cs_none; proc:nil),
  75. {X} (typesw:unitglobal; setsw:cs_extsyntax; proc:nil),
  76. {Y} (typesw:unsupported; setsw:cs_none; proc:nil),
  77. {Z} (typesw:illegal; setsw:cs_none; proc:nil)
  78. );
  79. procedure HandleSwitch(switch,state:char);
  80. begin
  81. switch:=upcase(switch);
  82. { Is the Switch in the letters ? }
  83. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  84. begin
  85. Message(scan_w_illegal_switch);
  86. exit;
  87. end;
  88. { Handle the switch }
  89. with SwitchTable[switch] do
  90. begin
  91. case typesw of
  92. illegal : Message1(scan_w_illegal_switch,'$'+switch);
  93. unsupported : Message1(scan_w_unsupported_switch,'$'+switch);
  94. unitglobal,
  95. programglobal,
  96. local : begin
  97. if (typesw=local) or
  98. ((typesw=unitglobal) and current_module^.in_main) or
  99. ((typesw=programglobal) and current_module^.in_main and (current_module=main_module)) then
  100. begin
  101. if state='+' then
  102. aktswitches:=aktswitches+[setsw]
  103. else
  104. aktswitches:=aktswitches-[setsw];
  105. end
  106. else
  107. Message(scan_w_switch_is_global);
  108. {$ifdef FPC}
  109. if assigned(proc) then
  110. proc();
  111. {$else}
  112. if @proc<>nil then
  113. proc;
  114. {$endif}
  115. end;
  116. end;
  117. end;
  118. end;
  119. function CheckSwitch(switch,state:char):boolean;
  120. var
  121. found : boolean;
  122. begin
  123. switch:=upcase(switch);
  124. { Is the Switch in the letters ? }
  125. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  126. begin
  127. Message(scan_w_illegal_switch);
  128. CheckSwitch:=false;
  129. exit;
  130. end;
  131. { Check the switch }
  132. with SwitchTable[switch] do
  133. begin
  134. found:=(setsw in aktswitches);
  135. if state='-' then
  136. found:=not found;
  137. CheckSwitch:=found;
  138. end;
  139. end;
  140. end.
  141. {
  142. $Log$
  143. Revision 1.5 1998-06-04 23:52:00 peter
  144. * m68k compiles
  145. + .def file creation moved to gendef.pas so it could also be used
  146. for win32
  147. Revision 1.4 1998/05/21 19:33:36 peter
  148. + better procedure directive handling and only one table
  149. Revision 1.3 1998/05/01 07:43:56 florian
  150. + basics for rtti implemented
  151. + switch $m (generate rtti for published sections)
  152. Revision 1.2 1998/04/28 11:45:53 florian
  153. * make it compilable with TP
  154. + small COM problems solved to compile classes.pp
  155. Revision 1.1 1998/04/27 23:13:53 peter
  156. + the new files for the scanner
  157. }