switches.pas 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. {L} (typesw:modulesw; setsw:ord(cs_local_browser)),
  87. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  88. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  89. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  90. {P} (typesw:modulesw; setsw:ord(cs_openstring)),
  91. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  92. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  93. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  94. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  95. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  96. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  97. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  98. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  99. {Y} (typesw:modulesw; setsw:ord(cs_browser)),
  100. {Z} (typesw:localsw; setsw:ord(cs_externally_visible))
  101. );
  102. procedure HandleSwitch(switch,state:char);
  103. var
  104. switchTablePtr: ^SwitchRecTable;
  105. begin
  106. switch:=upcase(switch);
  107. { Is the Switch in the letters ? }
  108. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  109. begin
  110. Message(scan_w_illegal_switch);
  111. exit;
  112. end;
  113. { Select switch table }
  114. if m_mac in aktmodeswitches then
  115. switchTablePtr:= @macSwitchTable
  116. else
  117. switchTablePtr:= @turboSwitchTable;
  118. { Handle the switch }
  119. with switchTablePtr^[switch] do
  120. begin
  121. case typesw of
  122. ignoredsw : Message1(scan_n_ignored_switch,'$'+switch);
  123. illegalsw : Message1(scan_w_illegal_switch,'$'+switch);
  124. unsupportedsw : Message1(scan_w_unsupported_switch,'$'+switch);
  125. localsw : begin
  126. if not localswitcheschanged then
  127. nextaktlocalswitches:=aktlocalswitches;
  128. if state='+' then
  129. include(nextaktlocalswitches,tlocalswitch(setsw))
  130. else
  131. exclude(nextaktlocalswitches,tlocalswitch(setsw));
  132. localswitcheschanged:=true;
  133. end;
  134. modulesw : begin
  135. if current_module.in_global then
  136. begin
  137. if state='+' then
  138. include(aktmoduleswitches,tmoduleswitch(setsw))
  139. else
  140. begin
  141. { Turning off debuginfo when lineinfo is requested
  142. is not possible }
  143. if not((cs_gdb_lineinfo in aktglobalswitches) and
  144. (tmoduleswitch(setsw)=cs_debuginfo)) then
  145. exclude(aktmoduleswitches,tmoduleswitch(setsw));
  146. end;
  147. end
  148. else
  149. Message(scan_w_switch_is_global);
  150. end;
  151. globalsw : begin
  152. if current_module.in_global and (current_module=main_module) then
  153. begin
  154. if state='+' then
  155. include(aktglobalswitches,tglobalswitch(setsw))
  156. else
  157. exclude(aktglobalswitches,tglobalswitch(setsw));
  158. end
  159. else
  160. Message(scan_w_switch_is_global);
  161. end;
  162. end;
  163. end;
  164. end;
  165. function CheckSwitch(switch,state:char):boolean;
  166. var
  167. found : boolean;
  168. switchTablePtr: ^SwitchRecTable;
  169. begin
  170. switch:=upcase(switch);
  171. { Is the Switch in the letters ? }
  172. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  173. begin
  174. Message(scan_w_illegal_switch);
  175. CheckSwitch:=false;
  176. exit;
  177. end;
  178. { Select switch table }
  179. if m_mac in aktmodeswitches then
  180. switchTablePtr:= @macSwitchTable
  181. else
  182. switchTablePtr:= @turboSwitchTable;
  183. { Check the switch }
  184. with switchTablePtr^[switch] do
  185. begin
  186. case typesw of
  187. localsw : found:=(tlocalswitch(setsw) in aktlocalswitches);
  188. modulesw : found:=(tmoduleswitch(setsw) in aktmoduleswitches);
  189. globalsw : found:=(tglobalswitch(setsw) in aktglobalswitches);
  190. else
  191. found:=false;
  192. end;
  193. if state='-' then
  194. found:=not found;
  195. CheckSwitch:=found;
  196. end;
  197. end;
  198. end.
  199. {
  200. $Log$
  201. Revision 1.16 2004-08-27 21:59:26 peter
  202. browser disabled
  203. uf_local_symtable ppu flag when a localsymtable is stored
  204. Revision 1.15 2004/07/14 23:19:22 olle
  205. + added external facilities for macpas
  206. Revision 1.14 2004/06/20 08:55:30 florian
  207. * logs truncated
  208. }