switches.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 globals,verbose,files,systems;
  24. {****************************************************************************
  25. Main Switches Parsing
  26. ****************************************************************************}
  27. type
  28. TSwitchType=(localsw,modulesw,globalsw,illegalsw,unsupportedsw);
  29. SwitchRec=record
  30. typesw : TSwitchType;
  31. setsw : byte;
  32. end;
  33. const
  34. SwitchTable:array['A'..'Z'] of SwitchRec=(
  35. {A} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  36. {B} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  37. {C} (typesw:localsw; setsw:ord(cs_do_assertion)),
  38. {D} (typesw:modulesw; setsw:ord(cs_debuginfo)),
  39. {E} (typesw:globalsw; setsw:ord(cs_fp_emulation)),
  40. {F} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  41. {G} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  42. {H} (typesw:localsw; setsw:ord(cs_ansistrings)),
  43. {I} (typesw:localsw; setsw:ord(cs_check_io)),
  44. {J} (typesw:illegalsw; setsw:ord(cs_localnone)),
  45. {K} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  46. {L} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  47. {M} (typesw:localsw; setsw:ord(cs_generate_rtti)),
  48. {N} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  49. {O} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  50. {P} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  51. {Q} (typesw:localsw; setsw:ord(cs_check_overflow)),
  52. {R} (typesw:localsw; setsw:ord(cs_check_range)),
  53. {S} (typesw:localsw; setsw:ord(cs_check_stack)),
  54. {T} (typesw:localsw; setsw:ord(cs_typed_addresses)),
  55. {U} (typesw:illegalsw; setsw:ord(cs_localnone)),
  56. {V} (typesw:localsw; setsw:ord(cs_strict_var_strings)),
  57. {W} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  58. {X} (typesw:modulesw; setsw:ord(cs_extsyntax)),
  59. {Y} (typesw:unsupportedsw; setsw:ord(cs_localnone)),
  60. {Z} (typesw:illegalsw; setsw:ord(cs_localnone))
  61. );
  62. procedure HandleSwitch(switch,state:char);
  63. begin
  64. switch:=upcase(switch);
  65. { Is the Switch in the letters ? }
  66. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  67. begin
  68. Message(scan_w_illegal_switch);
  69. exit;
  70. end;
  71. { Handle the switch }
  72. with SwitchTable[switch] do
  73. begin
  74. case typesw of
  75. illegalsw : Message1(scan_w_illegal_switch,'$'+switch);
  76. unsupportedsw : Message1(scan_w_unsupported_switch,'$'+switch);
  77. localsw : begin
  78. if state='+' then
  79. aktlocalswitches:=aktlocalswitches+[tlocalswitch(setsw)]
  80. else
  81. aktlocalswitches:=aktlocalswitches-[tlocalswitch(setsw)];
  82. end;
  83. modulesw : begin
  84. if current_module^.in_main then
  85. begin
  86. if state='+' then
  87. aktmoduleswitches:=aktmoduleswitches+[tmoduleswitch(setsw)]
  88. else
  89. aktmoduleswitches:=aktmoduleswitches-[tmoduleswitch(setsw)];
  90. end
  91. else
  92. Message(scan_w_switch_is_global);
  93. end;
  94. globalsw : begin
  95. if current_module^.in_main and (current_module=main_module) then
  96. begin
  97. if state='+' then
  98. aktglobalswitches:=aktglobalswitches+[tglobalswitch(setsw)]
  99. else
  100. aktglobalswitches:=aktglobalswitches-[tglobalswitch(setsw)];
  101. end
  102. else
  103. Message(scan_w_switch_is_global);
  104. end;
  105. end;
  106. end;
  107. end;
  108. function CheckSwitch(switch,state:char):boolean;
  109. var
  110. found : boolean;
  111. begin
  112. switch:=upcase(switch);
  113. { Is the Switch in the letters ? }
  114. if not ((switch in ['A'..'Z']) and (state in ['-','+'])) then
  115. begin
  116. Message(scan_w_illegal_switch);
  117. CheckSwitch:=false;
  118. exit;
  119. end;
  120. { Check the switch }
  121. with SwitchTable[switch] do
  122. begin
  123. case typesw of
  124. localsw : found:=(tlocalswitch(setsw) in aktlocalswitches);
  125. modulesw : found:=(tmoduleswitch(setsw) in aktmoduleswitches);
  126. globalsw : found:=(tglobalswitch(setsw) in aktglobalswitches);
  127. else
  128. found:=false;
  129. end;
  130. if state='-' then
  131. found:=not found;
  132. CheckSwitch:=found;
  133. end;
  134. end;
  135. end.
  136. {
  137. $Log$
  138. Revision 1.8 1998-08-10 14:50:27 peter
  139. + localswitches, moduleswitches, globalswitches splitting
  140. Revision 1.7 1998/07/24 22:17:00 florian
  141. * internal error 10 together with array access fixed. I hope
  142. that's the final fix.
  143. Revision 1.6 1998/07/18 17:11:13 florian
  144. + ansi string constants fixed
  145. + switch $H partial implemented
  146. Revision 1.5 1998/06/04 23:52:00 peter
  147. * m68k compiles
  148. + .def file creation moved to gendef.pas so it could also be used
  149. for win32
  150. Revision 1.4 1998/05/21 19:33:36 peter
  151. + better procedure directive handling and only one table
  152. Revision 1.3 1998/05/01 07:43:56 florian
  153. + basics for rtti implemented
  154. + switch $m (generate rtti for published sections)
  155. Revision 1.2 1998/04/28 11:45:53 florian
  156. * make it compilable with TP
  157. + small COM problems solved to compile classes.pp
  158. Revision 1.1 1998/04/27 23:13:53 peter
  159. + the new files for the scanner
  160. }