switches.pas 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman
  3. This unit implements the parsing of the switches like $I-
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit switches;
  18. {$i fpcdefs.inc}
  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. SwitchRecTable = array['A'..'Z'] of SwitchRec;
  36. const
  37. turboSwitchTable: SwitchRecTable =(
  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:modulesw; 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:localsw; setsw:ord(cs_typed_const_writable)),
  48. {K} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  49. {$ifdef supportbrowser}
  50. {L} (typesw:modulesw; setsw:ord(cs_local_browser)),
  51. {$else supportbrowser}
  52. {L} (typesw:modulesw; setsw:ord(cs_localnone)),
  53. {$endif supportbrowser}
  54. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  55. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  56. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  57. {P} (typesw:modulesw; setsw:ord(cs_openstring)),
  58. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  59. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  60. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  61. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  62. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  63. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  64. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  65. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  66. {$ifdef supportbrowser}
  67. {Y} (typesw:modulesw; setsw:ord(cs_browser)),
  68. {$else supportbrowser}
  69. {Y} (typesw:modulesw; setsw:ord(cs_localnone)),
  70. {$endif supportbrowser}
  71. {Z} (typesw:illegalsw; setsw:ord(cs_localnone))
  72. );
  73. macSwitchTable: SwitchRecTable =(
  74. {A} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  75. {B} (typesw:localsw; setsw:ord(cs_full_boolean_eval)),
  76. {C} (typesw:localsw; setsw:ord(cs_do_assertion)),
  77. {D} (typesw:modulesw; setsw:ord(cs_debuginfo)),
  78. {E} (typesw:modulesw; setsw:ord(cs_fp_emulation)),
  79. {F} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  80. {G} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  81. {H} (typesw:localsw; setsw:ord(cs_ansistrings)),
  82. {I} (typesw:localsw; setsw:ord(cs_check_io)),
  83. {J} (typesw:localsw; setsw:ord(cs_external_var)),
  84. {K} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  85. {$ifdef supportbrowser}
  86. {L} (typesw:modulesw; setsw:ord(cs_local_browser)),
  87. {$else supportbrowser}
  88. {L} (typesw:modulesw; setsw:ord(cs_localnone)),
  89. {$endif supportbrowser}
  90. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  91. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  92. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  93. {P} (typesw:modulesw; setsw:ord(cs_openstring)),
  94. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  95. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  96. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  97. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  98. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  99. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  100. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  101. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  102. {$ifdef supportbrowser}
  103. {Y} (typesw:modulesw; setsw:ord(cs_browser)),
  104. {$else supportbrowser}
  105. {Y} (typesw:modulesw; setsw:ord(cs_localnone)),
  106. {$endif supportbrowser}
  107. {Z} (typesw:localsw; setsw:ord(cs_externally_visible))
  108. );
  109. procedure HandleSwitch(switch,state:char);
  110. var
  111. switchTablePtr: ^SwitchRecTable;
  112. begin
  113. switch:=upcase(switch);
  114. { Is the Switch in the letters ? }
  115. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  116. begin
  117. Message(scan_w_illegal_switch);
  118. exit;
  119. end;
  120. { Select switch table }
  121. if m_mac in aktmodeswitches then
  122. switchTablePtr:= @macSwitchTable
  123. else
  124. switchTablePtr:= @turboSwitchTable;
  125. { Handle the switch }
  126. with switchTablePtr^[switch] do
  127. begin
  128. case typesw of
  129. ignoredsw : Message1(scan_n_ignored_switch,'$'+switch);
  130. illegalsw : Message1(scan_w_illegal_switch,'$'+switch);
  131. unsupportedsw : Message1(scan_w_unsupported_switch,'$'+switch);
  132. localsw : begin
  133. if not localswitcheschanged then
  134. nextaktlocalswitches:=aktlocalswitches;
  135. if state='+' then
  136. include(nextaktlocalswitches,tlocalswitch(setsw))
  137. else
  138. exclude(nextaktlocalswitches,tlocalswitch(setsw));
  139. localswitcheschanged:=true;
  140. end;
  141. modulesw : begin
  142. if current_module.in_global then
  143. begin
  144. if state='+' then
  145. include(aktmoduleswitches,tmoduleswitch(setsw))
  146. else
  147. begin
  148. { Turning off debuginfo when lineinfo is requested
  149. is not possible }
  150. if not((cs_gdb_lineinfo in aktglobalswitches) and
  151. (tmoduleswitch(setsw)=cs_debuginfo)) then
  152. exclude(aktmoduleswitches,tmoduleswitch(setsw));
  153. end;
  154. end
  155. else
  156. Message(scan_w_switch_is_global);
  157. end;
  158. globalsw : begin
  159. if current_module.in_global and (current_module=main_module) then
  160. begin
  161. if state='+' then
  162. include(aktglobalswitches,tglobalswitch(setsw))
  163. else
  164. exclude(aktglobalswitches,tglobalswitch(setsw));
  165. end
  166. else
  167. Message(scan_w_switch_is_global);
  168. end;
  169. end;
  170. end;
  171. end;
  172. function CheckSwitch(switch,state:char):boolean;
  173. var
  174. found : boolean;
  175. switchTablePtr: ^SwitchRecTable;
  176. begin
  177. switch:=upcase(switch);
  178. { Is the Switch in the letters ? }
  179. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  180. begin
  181. Message(scan_w_illegal_switch);
  182. CheckSwitch:=false;
  183. exit;
  184. end;
  185. { Select switch table }
  186. if m_mac in aktmodeswitches then
  187. switchTablePtr:= @macSwitchTable
  188. else
  189. switchTablePtr:= @turboSwitchTable;
  190. { Check the switch }
  191. with switchTablePtr^[switch] do
  192. begin
  193. case typesw of
  194. localsw : found:=(tlocalswitch(setsw) in aktlocalswitches);
  195. modulesw : found:=(tmoduleswitch(setsw) in aktmoduleswitches);
  196. globalsw : found:=(tglobalswitch(setsw) in aktglobalswitches);
  197. else
  198. found:=false;
  199. end;
  200. if state='-' then
  201. found:=not found;
  202. CheckSwitch:=found;
  203. end;
  204. end;
  205. end.