switches.pas 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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,alignsw);
  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:alignsw; 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. alignsw:
  130. if state='+' then
  131. aktpackrecords:=4
  132. else
  133. aktpackrecords:=1;
  134. ignoredsw :
  135. Message1(scan_n_ignored_switch,'$'+switch);
  136. illegalsw :
  137. Message1(scan_w_illegal_switch,'$'+switch);
  138. unsupportedsw :
  139. Message1(scan_w_unsupported_switch,'$'+switch);
  140. localsw :
  141. begin
  142. if not localswitcheschanged then
  143. nextaktlocalswitches:=aktlocalswitches;
  144. if state='+' then
  145. include(nextaktlocalswitches,tlocalswitch(setsw))
  146. else
  147. exclude(nextaktlocalswitches,tlocalswitch(setsw));
  148. localswitcheschanged:=true;
  149. end;
  150. modulesw :
  151. begin
  152. if current_module.in_global then
  153. begin
  154. if state='+' then
  155. include(aktmoduleswitches,tmoduleswitch(setsw))
  156. else
  157. begin
  158. { Turning off debuginfo when lineinfo is requested
  159. is not possible }
  160. if not((cs_gdb_lineinfo in aktglobalswitches) and
  161. (tmoduleswitch(setsw)=cs_debuginfo)) then
  162. exclude(aktmoduleswitches,tmoduleswitch(setsw));
  163. end;
  164. end
  165. else
  166. Message(scan_w_switch_is_global);
  167. end;
  168. globalsw :
  169. begin
  170. if current_module.in_global and (current_module=main_module) then
  171. begin
  172. if state='+' then
  173. include(aktglobalswitches,tglobalswitch(setsw))
  174. else
  175. exclude(aktglobalswitches,tglobalswitch(setsw));
  176. end
  177. else
  178. Message(scan_w_switch_is_global);
  179. end;
  180. end;
  181. end;
  182. end;
  183. function CheckSwitch(switch,state:char):boolean;
  184. var
  185. found : boolean;
  186. switchTablePtr: ^SwitchRecTable;
  187. begin
  188. switch:=upcase(switch);
  189. { Is the Switch in the letters ? }
  190. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  191. begin
  192. Message(scan_w_illegal_switch);
  193. CheckSwitch:=false;
  194. exit;
  195. end;
  196. { Select switch table }
  197. if m_mac in aktmodeswitches then
  198. switchTablePtr:= @macSwitchTable
  199. else
  200. switchTablePtr:= @turboSwitchTable;
  201. { Check the switch }
  202. with switchTablePtr^[switch] do
  203. begin
  204. case typesw of
  205. localsw : found:=(tlocalswitch(setsw) in aktlocalswitches);
  206. modulesw : found:=(tmoduleswitch(setsw) in aktmoduleswitches);
  207. globalsw : found:=(tglobalswitch(setsw) in aktglobalswitches);
  208. else
  209. found:=false;
  210. end;
  211. if state='-' then
  212. found:=not found;
  213. CheckSwitch:=found;
  214. end;
  215. end;
  216. end.