switches.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. {$i defines.inc}
  20. interface
  21. procedure HandleSwitch(switch,state:char);
  22. function CheckSwitch(switch,state:char):boolean;
  23. implementation
  24. uses
  25. globtype,systems,
  26. globals,verbose,fmodule;
  27. {****************************************************************************
  28. Main Switches Parsing
  29. ****************************************************************************}
  30. type
  31. TSwitchType=(ignoredsw,localsw,modulesw,globalsw,illegalsw,unsupportedsw);
  32. SwitchRec=record
  33. typesw : TSwitchType;
  34. setsw : byte;
  35. end;
  36. const
  37. SwitchTable:array['A'..'Z'] of SwitchRec=(
  38. {A} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  39. {B} (typesw:localsw; setsw:ord(cs_full_boolean_eval)),
  40. {C} (typesw:localsw; setsw:ord(cs_do_assertion)),
  41. {D} (typesw:modulesw; setsw:ord(cs_debuginfo)),
  42. {E} (typesw:globalsw; setsw:ord(cs_fp_emulation)),
  43. {F} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  44. {G} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  45. {H} (typesw:localsw; setsw:ord(cs_ansistrings)),
  46. {I} (typesw:localsw; setsw:ord(cs_check_io)),
  47. {J} (typesw:unsupportedsw; setsw:ord(cs_typed_const_not_changeable)),
  48. {K} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  49. {L} (typesw:modulesw; setsw:ord(cs_local_browser)),
  50. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  51. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  52. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  53. {P} (typesw:modulesw; setsw:ord(cs_openstring)),
  54. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  55. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  56. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  57. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  58. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  59. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  60. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  61. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  62. {Y} (typesw:modulesw; setsw:ord(cs_browser)),
  63. {Z} (typesw:illegalsw; setsw:ord(cs_localnone))
  64. );
  65. procedure HandleSwitch(switch,state:char);
  66. begin
  67. switch:=upcase(switch);
  68. { Is the Switch in the letters ? }
  69. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  70. begin
  71. Message(scan_w_illegal_switch);
  72. exit;
  73. end;
  74. { Handle the switch }
  75. with SwitchTable[switch] do
  76. begin
  77. case typesw of
  78. ignoredsw : Message1(scan_n_ignored_switch,'$'+switch);
  79. illegalsw : Message1(scan_w_illegal_switch,'$'+switch);
  80. unsupportedsw : Message1(scan_w_unsupported_switch,'$'+switch);
  81. localsw : begin
  82. if not localswitcheschanged then
  83. nextaktlocalswitches:=aktlocalswitches;
  84. if state='+' then
  85. nextaktlocalswitches:=nextaktlocalswitches+[tlocalswitch(setsw)]
  86. else
  87. nextaktlocalswitches:=nextaktlocalswitches-[tlocalswitch(setsw)];
  88. localswitcheschanged:=true;
  89. { Message for linux which has global checking only }
  90. if (switch='S') and (
  91. {$ifdef i386}
  92. (target_info.target = target_i386_linux)
  93. {$else}
  94. {$ifdef m68k}
  95. (target_info.target = target_m68k_linux)
  96. {$else}
  97. True
  98. {$endif m68k}
  99. {$endif i386}
  100. ) then
  101. Message(scan_n_stack_check_global_under_linux);
  102. end;
  103. modulesw : begin
  104. if current_module.in_global then
  105. begin
  106. if state='+' then
  107. aktmoduleswitches:=aktmoduleswitches+[tmoduleswitch(setsw)]
  108. else
  109. aktmoduleswitches:=aktmoduleswitches-[tmoduleswitch(setsw)];
  110. { can't have local browser when no global browser
  111. moved to end of global section
  112. if (cs_local_browser in aktmoduleswitches) and
  113. not(cs_browser in aktmoduleswitches) then
  114. aktmoduleswitches:=aktmoduleswitches-[cs_local_browser];}
  115. end
  116. else
  117. Message(scan_w_switch_is_global);
  118. end;
  119. globalsw : begin
  120. if current_module.in_global and (current_module=main_module) then
  121. begin
  122. if state='+' then
  123. aktglobalswitches:=aktglobalswitches+[tglobalswitch(setsw)]
  124. else
  125. aktglobalswitches:=aktglobalswitches-[tglobalswitch(setsw)];
  126. end
  127. else
  128. Message(scan_w_switch_is_global);
  129. end;
  130. end;
  131. end;
  132. end;
  133. function CheckSwitch(switch,state:char):boolean;
  134. var
  135. found : boolean;
  136. begin
  137. switch:=upcase(switch);
  138. { Is the Switch in the letters ? }
  139. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  140. begin
  141. Message(scan_w_illegal_switch);
  142. CheckSwitch:=false;
  143. exit;
  144. end;
  145. { Check the switch }
  146. with SwitchTable[switch] do
  147. begin
  148. case typesw of
  149. localsw : found:=(tlocalswitch(setsw) in aktlocalswitches);
  150. modulesw : found:=(tmoduleswitch(setsw) in aktmoduleswitches);
  151. globalsw : found:=(tglobalswitch(setsw) in aktglobalswitches);
  152. else
  153. found:=false;
  154. end;
  155. if state='-' then
  156. found:=not found;
  157. CheckSwitch:=found;
  158. end;
  159. end;
  160. end.
  161. {
  162. $Log$
  163. Revision 1.6 2000-12-25 00:07:29 peter
  164. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  165. tlinkedlist objects)
  166. Revision 1.5 2000/09/24 15:06:28 peter
  167. * use defines.inc
  168. Revision 1.4 2000/09/21 11:30:49 jonas
  169. + support for full boolean evaluation (b+/b-), default remains short
  170. circuit boolean evaluation
  171. Revision 1.3 2000/08/27 16:11:53 peter
  172. * moved some util functions from globals,cobjects to cutils
  173. * splitted files into finput,fmodule
  174. Revision 1.2 2000/07/13 11:32:49 michael
  175. + removed logs
  176. }