switches.pas 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. {L} (typesw:modulesw; setsw:ord(cs_local_browser)),
  51. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  52. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  53. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  54. {P} (typesw:modulesw; setsw:ord(cs_openstring)),
  55. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  56. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  57. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  58. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  59. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  60. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  61. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  62. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  63. {Y} (typesw:modulesw; setsw:ord(cs_browser)),
  64. {Z} (typesw:illegalsw; setsw:ord(cs_localnone))
  65. );
  66. macSwitchTable: SwitchRecTable =(
  67. {A} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  68. {B} (typesw:localsw; setsw:ord(cs_full_boolean_eval)),
  69. {C} (typesw:localsw; setsw:ord(cs_do_assertion)),
  70. {D} (typesw:modulesw; setsw:ord(cs_debuginfo)),
  71. {E} (typesw:modulesw; setsw:ord(cs_fp_emulation)),
  72. {F} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  73. {G} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  74. {H} (typesw:localsw; setsw:ord(cs_ansistrings)),
  75. {I} (typesw:localsw; setsw:ord(cs_check_io)),
  76. {J} (typesw:localsw; setsw:ord(cs_external_var)),
  77. {K} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  78. {L} (typesw:modulesw; setsw:ord(cs_local_browser)),
  79. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  80. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  81. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  82. {P} (typesw:modulesw; setsw:ord(cs_openstring)),
  83. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  84. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  85. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  86. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  87. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  88. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  89. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  90. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  91. {Y} (typesw:modulesw; setsw:ord(cs_browser)),
  92. {Z} (typesw:localsw; setsw:ord(cs_externally_visible))
  93. );
  94. procedure HandleSwitch(switch,state:char);
  95. var
  96. switchTablePtr: ^SwitchRecTable;
  97. begin
  98. switch:=upcase(switch);
  99. { Is the Switch in the letters ? }
  100. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  101. begin
  102. Message(scan_w_illegal_switch);
  103. exit;
  104. end;
  105. { Select switch table }
  106. if m_mac in aktmodeswitches then
  107. switchTablePtr:= @macSwitchTable
  108. else
  109. switchTablePtr:= @turboSwitchTable;
  110. { Handle the switch }
  111. with switchTablePtr^[switch] do
  112. begin
  113. case typesw of
  114. ignoredsw : Message1(scan_n_ignored_switch,'$'+switch);
  115. illegalsw : Message1(scan_w_illegal_switch,'$'+switch);
  116. unsupportedsw : Message1(scan_w_unsupported_switch,'$'+switch);
  117. localsw : begin
  118. if not localswitcheschanged then
  119. nextaktlocalswitches:=aktlocalswitches;
  120. if state='+' then
  121. include(nextaktlocalswitches,tlocalswitch(setsw))
  122. else
  123. exclude(nextaktlocalswitches,tlocalswitch(setsw));
  124. localswitcheschanged:=true;
  125. end;
  126. modulesw : begin
  127. if current_module.in_global then
  128. begin
  129. if state='+' then
  130. include(aktmoduleswitches,tmoduleswitch(setsw))
  131. else
  132. begin
  133. { Turning off debuginfo when lineinfo is requested
  134. is not possible }
  135. if not((cs_gdb_lineinfo in aktglobalswitches) and
  136. (tmoduleswitch(setsw)=cs_debuginfo)) then
  137. exclude(aktmoduleswitches,tmoduleswitch(setsw));
  138. end;
  139. end
  140. else
  141. Message(scan_w_switch_is_global);
  142. end;
  143. globalsw : begin
  144. if current_module.in_global and (current_module=main_module) then
  145. begin
  146. if state='+' then
  147. include(aktglobalswitches,tglobalswitch(setsw))
  148. else
  149. exclude(aktglobalswitches,tglobalswitch(setsw));
  150. end
  151. else
  152. Message(scan_w_switch_is_global);
  153. end;
  154. end;
  155. end;
  156. end;
  157. function CheckSwitch(switch,state:char):boolean;
  158. var
  159. found : boolean;
  160. switchTablePtr: ^SwitchRecTable;
  161. begin
  162. switch:=upcase(switch);
  163. { Is the Switch in the letters ? }
  164. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  165. begin
  166. Message(scan_w_illegal_switch);
  167. CheckSwitch:=false;
  168. exit;
  169. end;
  170. { Select switch table }
  171. if m_mac in aktmodeswitches then
  172. switchTablePtr:= @macSwitchTable
  173. else
  174. switchTablePtr:= @turboSwitchTable;
  175. { Check the switch }
  176. with switchTablePtr^[switch] do
  177. begin
  178. case typesw of
  179. localsw : found:=(tlocalswitch(setsw) in aktlocalswitches);
  180. modulesw : found:=(tmoduleswitch(setsw) in aktmoduleswitches);
  181. globalsw : found:=(tglobalswitch(setsw) in aktglobalswitches);
  182. else
  183. found:=false;
  184. end;
  185. if state='-' then
  186. found:=not found;
  187. CheckSwitch:=found;
  188. end;
  189. end;
  190. end.
  191. {
  192. $Log$
  193. Revision 1.15 2004-07-14 23:19:22 olle
  194. + added external facilities for macpas
  195. Revision 1.14 2004/06/20 08:55:30 florian
  196. * logs truncated
  197. }