switches.pas 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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 fpcdefs.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. SwitchRecTable = array['A'..'Z'] of SwitchRec;
  37. const
  38. turboSwitchTable: SwitchRecTable =(
  39. {A} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  40. {B} (typesw:localsw; setsw:ord(cs_full_boolean_eval)),
  41. {C} (typesw:localsw; setsw:ord(cs_do_assertion)),
  42. {D} (typesw:modulesw; setsw:ord(cs_debuginfo)),
  43. {E} (typesw:modulesw; setsw:ord(cs_fp_emulation)),
  44. {F} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  45. {G} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  46. {H} (typesw:localsw; setsw:ord(cs_ansistrings)),
  47. {I} (typesw:localsw; setsw:ord(cs_check_io)),
  48. {J} (typesw:localsw; setsw:ord(cs_typed_const_writable)),
  49. {K} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  50. {$ifdef supportbrowser}
  51. {L} (typesw:modulesw; setsw:ord(cs_local_browser)),
  52. {$else supportbrowser}
  53. {L} (typesw:modulesw; setsw:ord(cs_localnone)),
  54. {$endif supportbrowser}
  55. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  56. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  57. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  58. {P} (typesw:modulesw; setsw:ord(cs_openstring)),
  59. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  60. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  61. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  62. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  63. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  64. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  65. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  66. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  67. {$ifdef supportbrowser}
  68. {Y} (typesw:modulesw; setsw:ord(cs_browser)),
  69. {$else supportbrowser}
  70. {Y} (typesw:modulesw; setsw:ord(cs_localnone)),
  71. {$endif supportbrowser}
  72. {Z} (typesw:illegalsw; setsw:ord(cs_localnone))
  73. );
  74. macSwitchTable: SwitchRecTable =(
  75. {A} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  76. {B} (typesw:localsw; setsw:ord(cs_full_boolean_eval)),
  77. {C} (typesw:localsw; setsw:ord(cs_do_assertion)),
  78. {D} (typesw:modulesw; setsw:ord(cs_debuginfo)),
  79. {E} (typesw:modulesw; setsw:ord(cs_fp_emulation)),
  80. {F} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  81. {G} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  82. {H} (typesw:localsw; setsw:ord(cs_ansistrings)),
  83. {I} (typesw:localsw; setsw:ord(cs_check_io)),
  84. {J} (typesw:localsw; setsw:ord(cs_external_var)),
  85. {K} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  86. {$ifdef supportbrowser}
  87. {L} (typesw:modulesw; setsw:ord(cs_local_browser)),
  88. {$else supportbrowser}
  89. {L} (typesw:modulesw; setsw:ord(cs_localnone)),
  90. {$endif supportbrowser}
  91. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  92. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  93. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  94. {P} (typesw:modulesw; setsw:ord(cs_openstring)),
  95. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  96. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  97. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  98. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  99. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  100. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  101. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  102. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  103. {$ifdef supportbrowser}
  104. {Y} (typesw:modulesw; setsw:ord(cs_browser)),
  105. {$else supportbrowser}
  106. {Y} (typesw:modulesw; setsw:ord(cs_localnone)),
  107. {$endif supportbrowser}
  108. {Z} (typesw:localsw; setsw:ord(cs_externally_visible))
  109. );
  110. procedure HandleSwitch(switch,state:char);
  111. var
  112. switchTablePtr: ^SwitchRecTable;
  113. begin
  114. switch:=upcase(switch);
  115. { Is the Switch in the letters ? }
  116. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  117. begin
  118. Message(scan_w_illegal_switch);
  119. exit;
  120. end;
  121. { Select switch table }
  122. if m_mac in aktmodeswitches then
  123. switchTablePtr:= @macSwitchTable
  124. else
  125. switchTablePtr:= @turboSwitchTable;
  126. { Handle the switch }
  127. with switchTablePtr^[switch] do
  128. begin
  129. case typesw of
  130. ignoredsw : Message1(scan_n_ignored_switch,'$'+switch);
  131. illegalsw : Message1(scan_w_illegal_switch,'$'+switch);
  132. unsupportedsw : Message1(scan_w_unsupported_switch,'$'+switch);
  133. localsw : begin
  134. if not localswitcheschanged then
  135. nextaktlocalswitches:=aktlocalswitches;
  136. if state='+' then
  137. include(nextaktlocalswitches,tlocalswitch(setsw))
  138. else
  139. exclude(nextaktlocalswitches,tlocalswitch(setsw));
  140. localswitcheschanged:=true;
  141. end;
  142. modulesw : begin
  143. if current_module.in_global then
  144. begin
  145. if state='+' then
  146. include(aktmoduleswitches,tmoduleswitch(setsw))
  147. else
  148. begin
  149. { Turning off debuginfo when lineinfo is requested
  150. is not possible }
  151. if not((cs_gdb_lineinfo in aktglobalswitches) and
  152. (tmoduleswitch(setsw)=cs_debuginfo)) then
  153. exclude(aktmoduleswitches,tmoduleswitch(setsw));
  154. end;
  155. end
  156. else
  157. Message(scan_w_switch_is_global);
  158. end;
  159. globalsw : begin
  160. if current_module.in_global and (current_module=main_module) then
  161. begin
  162. if state='+' then
  163. include(aktglobalswitches,tglobalswitch(setsw))
  164. else
  165. exclude(aktglobalswitches,tglobalswitch(setsw));
  166. end
  167. else
  168. Message(scan_w_switch_is_global);
  169. end;
  170. end;
  171. end;
  172. end;
  173. function CheckSwitch(switch,state:char):boolean;
  174. var
  175. found : boolean;
  176. switchTablePtr: ^SwitchRecTable;
  177. begin
  178. switch:=upcase(switch);
  179. { Is the Switch in the letters ? }
  180. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  181. begin
  182. Message(scan_w_illegal_switch);
  183. CheckSwitch:=false;
  184. exit;
  185. end;
  186. { Select switch table }
  187. if m_mac in aktmodeswitches then
  188. switchTablePtr:= @macSwitchTable
  189. else
  190. switchTablePtr:= @turboSwitchTable;
  191. { Check the switch }
  192. with switchTablePtr^[switch] do
  193. begin
  194. case typesw of
  195. localsw : found:=(tlocalswitch(setsw) in aktlocalswitches);
  196. modulesw : found:=(tmoduleswitch(setsw) in aktmoduleswitches);
  197. globalsw : found:=(tglobalswitch(setsw) in aktglobalswitches);
  198. else
  199. found:=false;
  200. end;
  201. if state='-' then
  202. found:=not found;
  203. CheckSwitch:=found;
  204. end;
  205. end;
  206. end.
  207. {
  208. $Log$
  209. Revision 1.18 2005-02-14 17:13:07 peter
  210. * truncate log
  211. Revision 1.17 2005/01/04 18:39:06 olle
  212. * made macpas switches in sync with turbo switches
  213. }