switches.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. if target_info.target=target_Linux then
  33. Message(scan_n_stack_check_global_under_linux);
  34. end;
  35. {$ifndef FPC}
  36. {$F-}
  37. {$endif}
  38. {****************************************************************************
  39. Main Switches Parsing
  40. ****************************************************************************}
  41. type
  42. TSwitchType=(local,unitglobal,programglobal,illegal,unsupported);
  43. SwitchRec=record
  44. typesw : TSwitchType;
  45. setsw : tcswitch;
  46. proc : procedure;
  47. end;
  48. const
  49. SwitchTable:array['A'..'Z'] of SwitchRec=(
  50. {A} (typesw:unsupported; setsw:cs_none; proc:nil),
  51. {B} (typesw:unsupported; setsw:cs_none; proc:nil),
  52. {C} (typesw:illegal; setsw:cs_none; proc:nil),
  53. {D} (typesw:unitglobal; setsw:cs_debuginfo; proc:nil),
  54. {E} (typesw:programglobal; setsw:cs_fp_emulation; proc:nil),
  55. {F} (typesw:unsupported; setsw:cs_none; proc:nil),
  56. {G} (typesw:unsupported; setsw:cs_none; proc:nil),
  57. {H} (typesw:unsupported; setsw:cs_none; proc:nil),
  58. {I} (typesw:local; setsw:cs_iocheck; proc:nil),
  59. {J} (typesw:illegal; setsw:cs_none; proc:nil),
  60. {K} (typesw:unsupported; setsw:cs_none; proc:nil),
  61. {L} (typesw:unsupported; setsw:cs_none; proc:nil),
  62. {M} (typesw:local; setsw:cs_generate_rtti; proc:nil),
  63. {N} (typesw:unsupported; setsw:cs_none; proc:nil),
  64. {O} (typesw:unsupported; setsw:cs_none; proc:nil),
  65. {P} (typesw:unsupported; setsw:cs_none; proc:nil),
  66. {Q} (typesw:local; setsw:cs_check_overflow; proc:nil),
  67. {R} (typesw:local; setsw:cs_rangechecking; proc:nil),
  68. {S} (typesw:local; setsw:cs_check_stack; proc:nil),
  69. {T} (typesw:local; setsw:cs_typed_addresses; proc:nil),
  70. {U} (typesw:illegal; setsw:cs_none; proc:nil),
  71. {V} (typesw:local; setsw:cs_strict_var_strings; proc:nil),
  72. {W} (typesw:unsupported; setsw:cs_none; proc:nil),
  73. {X} (typesw:unitglobal; setsw:cs_extsyntax; proc:nil),
  74. {Y} (typesw:unsupported; setsw:cs_none; proc:nil),
  75. {Z} (typesw:illegal; setsw:cs_none; proc:nil)
  76. );
  77. procedure HandleSwitch(switch,state:char);
  78. begin
  79. switch:=upcase(switch);
  80. { Is the Switch in the letters ? }
  81. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  82. begin
  83. Message(scan_w_illegal_switch);
  84. exit;
  85. end;
  86. { Handle the switch }
  87. with SwitchTable[switch] do
  88. begin
  89. case typesw of
  90. illegal : Message1(scan_w_illegal_switch,'$'+switch);
  91. unsupported : Message1(scan_w_unsupported_switch,'$'+switch);
  92. unitglobal,
  93. programglobal,
  94. local : begin
  95. if (typesw=local) or
  96. ((typesw=unitglobal) and current_module^.in_main) or
  97. ((typesw=programglobal) and current_module^.in_main and (current_module=main_module)) then
  98. begin
  99. if state='+' then
  100. aktswitches:=aktswitches+[setsw]
  101. else
  102. aktswitches:=aktswitches-[setsw];
  103. end
  104. else
  105. Message(scan_w_switch_is_global);
  106. {$ifdef FPC}
  107. if assigned(proc) then
  108. proc();
  109. {$else}
  110. if @proc<>nil then
  111. proc;
  112. {$endif}
  113. end;
  114. end;
  115. end;
  116. end;
  117. function CheckSwitch(switch,state:char):boolean;
  118. var
  119. found : boolean;
  120. begin
  121. switch:=upcase(switch);
  122. { Is the Switch in the letters ? }
  123. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  124. begin
  125. Message(scan_w_illegal_switch);
  126. CheckSwitch:=false;
  127. exit;
  128. end;
  129. { Check the switch }
  130. with SwitchTable[switch] do
  131. begin
  132. found:=(setsw in aktswitches);
  133. if state='-' then
  134. found:=not found;
  135. CheckSwitch:=found;
  136. end;
  137. end;
  138. end.
  139. {
  140. $Log$
  141. Revision 1.4 1998-05-21 19:33:36 peter
  142. + better procedure directive handling and only one table
  143. Revision 1.3 1998/05/01 07:43:56 florian
  144. + basics for rtti implemented
  145. + switch $m (generate rtti for published sections)
  146. Revision 1.2 1998/04/28 11:45:53 florian
  147. * make it compilable with TP
  148. + small COM problems solved to compile classes.pp
  149. Revision 1.1 1998/04/27 23:13:53 peter
  150. + the new files for the scanner
  151. }