switches.pas 6.4 KB

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