switches.pas 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. {
  2. $Id$
  3. Copyright (c) 1998 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. interface
  20. procedure HandleSwitch(switch,state:char);
  21. function CheckSwitch(switch,state:char):boolean;
  22. implementation
  23. uses
  24. globtype,systems,
  25. globals,verbose,files;
  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. const
  36. SwitchTable:array['A'..'Z'] of SwitchRec=(
  37. {A} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  38. {B} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  39. {C} (typesw:localsw; setsw:ord(cs_do_assertion)),
  40. {D} (typesw:modulesw; setsw:ord(cs_debuginfo)),
  41. {E} (typesw:globalsw; setsw:ord(cs_fp_emulation)),
  42. {F} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  43. {G} (typesw:ignoredsw; setsw:ord(cs_localnone)),
  44. {H} (typesw:localsw; setsw:ord(cs_ansistrings)),
  45. {I} (typesw:localsw; setsw:ord(cs_check_io)),
  46. {J} (typesw:unsupportedsw; setsw:ord(cs_typed_const_not_changeable)),
  47. {K} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  48. {L} (typesw:modulesw; setsw:ord(cs_local_browser)),
  49. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  50. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  51. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  52. {P} (typesw:modulesw; setsw:ord(cs_openstring)),
  53. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  54. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  55. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  56. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  57. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  58. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  59. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  60. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  61. {Y} (typesw:modulesw; setsw:ord(cs_browser)),
  62. {Z} (typesw:illegalsw; setsw:ord(cs_localnone))
  63. );
  64. procedure HandleSwitch(switch,state:char);
  65. begin
  66. switch:=upcase(switch);
  67. { Is the Switch in the letters ? }
  68. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  69. begin
  70. Message(scan_w_illegal_switch);
  71. exit;
  72. end;
  73. { Handle the switch }
  74. with SwitchTable[switch] do
  75. begin
  76. case typesw of
  77. ignoredsw : Message1(scan_n_ignored_switch,'$'+switch);
  78. illegalsw : Message1(scan_w_illegal_switch,'$'+switch);
  79. unsupportedsw : Message1(scan_w_unsupported_switch,'$'+switch);
  80. localsw : begin
  81. if state='+' then
  82. aktlocalswitches:=aktlocalswitches+[tlocalswitch(setsw)]
  83. else
  84. aktlocalswitches:=aktlocalswitches-[tlocalswitch(setsw)];
  85. { Message for linux which has global checking only }
  86. if (switch='S') and (
  87. {$ifdef i386}
  88. (target_info.target = target_i386_linux)
  89. {$else}
  90. {$ifdef m68k}
  91. (target_info.target = target_m68k_linux)
  92. {$else}
  93. True
  94. {$endif m68k}
  95. {$endif i386}
  96. ) then
  97. Message(scan_n_stack_check_global_under_linux);
  98. end;
  99. modulesw : begin
  100. if current_module^.in_global then
  101. begin
  102. if state='+' then
  103. aktmoduleswitches:=aktmoduleswitches+[tmoduleswitch(setsw)]
  104. else
  105. aktmoduleswitches:=aktmoduleswitches-[tmoduleswitch(setsw)];
  106. { can't have local browser when no global browser
  107. moved to end of global section
  108. if (cs_local_browser in aktmoduleswitches) and
  109. not(cs_browser in aktmoduleswitches) then
  110. aktmoduleswitches:=aktmoduleswitches-[cs_local_browser];}
  111. end
  112. else
  113. Message(scan_w_switch_is_global);
  114. end;
  115. globalsw : begin
  116. if current_module^.in_global and (current_module=main_module) then
  117. begin
  118. if state='+' then
  119. aktglobalswitches:=aktglobalswitches+[tglobalswitch(setsw)]
  120. else
  121. aktglobalswitches:=aktglobalswitches-[tglobalswitch(setsw)];
  122. end
  123. else
  124. Message(scan_w_switch_is_global);
  125. end;
  126. end;
  127. end;
  128. end;
  129. function CheckSwitch(switch,state:char):boolean;
  130. var
  131. found : boolean;
  132. begin
  133. switch:=upcase(switch);
  134. { Is the Switch in the letters ? }
  135. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  136. begin
  137. Message(scan_w_illegal_switch);
  138. CheckSwitch:=false;
  139. exit;
  140. end;
  141. { Check the switch }
  142. with SwitchTable[switch] do
  143. begin
  144. case typesw of
  145. localsw : found:=(tlocalswitch(setsw) in aktlocalswitches);
  146. modulesw : found:=(tmoduleswitch(setsw) in aktmoduleswitches);
  147. globalsw : found:=(tglobalswitch(setsw) in aktglobalswitches);
  148. else
  149. found:=false;
  150. end;
  151. if state='-' then
  152. found:=not found;
  153. CheckSwitch:=found;
  154. end;
  155. end;
  156. end.
  157. {
  158. $Log$
  159. Revision 1.23 1999-09-16 11:34:58 pierre
  160. * typo correction
  161. Revision 1.22 1999/08/01 23:35:06 michael
  162. * Alpha changes
  163. Revision 1.21 1999/04/25 22:34:59 pierre
  164. + cs_typed_const_not_changeable added but not implemented yet !
  165. Revision 1.20 1999/02/22 13:07:06 pierre
  166. + -b and -bl options work !
  167. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  168. is not enabled when quitting global section
  169. * local vars and procedures are not yet stored into PPU
  170. Revision 1.19 1999/02/18 13:43:20 peter
  171. * no localbrowser when browser is turned off
  172. Revision 1.18 1998/12/11 00:03:47 peter
  173. + globtype,tokens,version unit splitted from globals
  174. Revision 1.17 1998/11/27 14:50:46 peter
  175. + open strings, $P switch support
  176. Revision 1.16 1998/10/13 16:50:22 pierre
  177. * undid some changes of Peter that made the compiler wrong
  178. for m68k (I had to reinsert some ifdefs)
  179. * removed several memory leaks under m68k
  180. * removed the meory leaks for assembler readers
  181. * cross compiling shoud work again better
  182. ( crosscompiling sysamiga works
  183. but as68k still complain about some code !)
  184. Revision 1.15 1998/10/13 13:10:29 peter
  185. * new style for m68k/i386 infos and enums
  186. Revision 1.14 1998/10/13 08:19:41 pierre
  187. + source_os is now set correctly for cross-processor compilers
  188. (tos contains all target_infos and
  189. we use CPU86 and CPU68 conditionals to
  190. get the source operating system
  191. this only works if you do not undefine
  192. the source target !!)
  193. * several cg68k memory leaks fixed
  194. + started to change the code so that it should be possible to have
  195. a complete compiler (both for m68k and i386 !!)
  196. Revision 1.13 1998/09/22 17:13:52 pierre
  197. + browsing updated and developed
  198. records and objects fields are also stored
  199. Revision 1.12 1998/09/01 12:52:05 peter
  200. + a lot of delphi switches
  201. Revision 1.11 1998/08/18 20:52:21 peter
  202. * renamed in_main to in_global which is more logical
  203. Revision 1.10 1998/08/14 18:14:57 peter
  204. * forgot to check the target for linux for $S switch message
  205. Revision 1.9 1998/08/10 15:47:08 peter
  206. * reinstantited stackcheck note for linux
  207. Revision 1.8 1998/08/10 14:50:27 peter
  208. + localswitches, moduleswitches, globalswitches splitting
  209. Revision 1.7 1998/07/24 22:17:00 florian
  210. * internal error 10 together with array access fixed. I hope
  211. that's the final fix.
  212. Revision 1.6 1998/07/18 17:11:13 florian
  213. + ansi string constants fixed
  214. + switch $H partial implemented
  215. Revision 1.5 1998/06/04 23:52:00 peter
  216. * m68k compiles
  217. + .def file creation moved to gendef.pas so it could also be used
  218. for win32
  219. Revision 1.4 1998/05/21 19:33:36 peter
  220. + better procedure directive handling and only one table
  221. Revision 1.3 1998/05/01 07:43:56 florian
  222. + basics for rtti implemented
  223. + switch $m (generate rtti for published sections)
  224. Revision 1.2 1998/04/28 11:45:53 florian
  225. * make it compilable with TP
  226. + small COM problems solved to compile classes.pp
  227. Revision 1.1 1998/04/27 23:13:53 peter
  228. + the new files for the scanner
  229. }