2
0

dirparse.pas 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements some support functions for the parsing of directives
  4. and option strings
  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 dirparse;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,
  23. systems;
  24. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  25. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  26. function UpdateWpoStr(s: string; var a: twpoptimizerswitches): boolean;
  27. function UpdateDebugStr(s:string;var a:tdebugswitches):boolean;
  28. function UpdateTargetSwitchStr(s: string; var a: ttargetswitches; global: boolean): boolean;
  29. implementation
  30. uses
  31. globals,
  32. cutils,
  33. symtable;
  34. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  35. var
  36. tok : string;
  37. vstr : string;
  38. l : longint;
  39. code : integer;
  40. b : talignmentinfo;
  41. begin
  42. UpdateAlignmentStr:=true;
  43. uppervar(s);
  44. fillchar(b,sizeof(b),0);
  45. repeat
  46. tok:=GetToken(s,'=');
  47. if tok='' then
  48. break;
  49. vstr:=GetToken(s,',');
  50. val(vstr,l,code);
  51. if tok='PROC' then
  52. b.procalign:=l
  53. else if tok='JUMP' then
  54. b.jumpalign:=l
  55. else if tok='LOOP' then
  56. b.loopalign:=l
  57. else if tok='CONSTMIN' then
  58. begin
  59. b.constalignmin:=l;
  60. if l>b.constalignmax then
  61. b.constalignmax:=l;
  62. end
  63. else if tok='CONSTMAX' then
  64. b.constalignmax:=l
  65. else if tok='VARMIN' then
  66. begin
  67. b.varalignmin:=l;
  68. if l>b.varalignmax then
  69. b.varalignmax:=l;
  70. end
  71. else if tok='VARMAX' then
  72. b.varalignmax:=l
  73. else if tok='LOCALMIN' then
  74. begin
  75. b.localalignmin:=l;
  76. if l>b.localalignmax then
  77. b.localalignmax:=l;
  78. end
  79. else if tok='LOCALMAX' then
  80. b.localalignmax:=l
  81. else if tok='RECORDMIN' then
  82. begin
  83. b.recordalignmin:=l;
  84. if l>b.recordalignmax then
  85. b.recordalignmax:=l;
  86. end
  87. else if tok='RECORDMAX' then
  88. b.recordalignmax:=l
  89. else { Error }
  90. UpdateAlignmentStr:=false;
  91. until false;
  92. Result:=Result and UpdateAlignment(a,b);
  93. end;
  94. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  95. var
  96. tok : string;
  97. doset,
  98. found : boolean;
  99. opt : toptimizerswitch;
  100. begin
  101. result:=true;
  102. uppervar(s);
  103. repeat
  104. tok:=GetToken(s,',');
  105. if tok='' then
  106. break;
  107. if Copy(tok,1,2)='NO' then
  108. begin
  109. delete(tok,1,2);
  110. doset:=false;
  111. end
  112. else
  113. doset:=true;
  114. found:=false;
  115. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  116. begin
  117. if OptimizerSwitchStr[opt]=tok then
  118. begin
  119. found:=true;
  120. break;
  121. end;
  122. end;
  123. if found then
  124. begin
  125. if doset then
  126. include(a,opt)
  127. else
  128. exclude(a,opt);
  129. end
  130. else
  131. result:=false;
  132. until false;
  133. end;
  134. function UpdateWpoStr(s: string; var a: twpoptimizerswitches): boolean;
  135. var
  136. tok : string;
  137. doset,
  138. found : boolean;
  139. opt : twpoptimizerswitch;
  140. begin
  141. result:=true;
  142. uppervar(s);
  143. repeat
  144. tok:=GetToken(s,',');
  145. if tok='' then
  146. break;
  147. if Copy(tok,1,2)='NO' then
  148. begin
  149. delete(tok,1,2);
  150. doset:=false;
  151. end
  152. else
  153. doset:=true;
  154. found:=false;
  155. if (tok = 'ALL') then
  156. begin
  157. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  158. if doset then
  159. include(a,opt)
  160. else
  161. exclude(a,opt);
  162. end
  163. else
  164. begin
  165. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  166. begin
  167. if WPOptimizerSwitchStr[opt]=tok then
  168. begin
  169. found:=true;
  170. break;
  171. end;
  172. end;
  173. if found then
  174. begin
  175. if doset then
  176. include(a,opt)
  177. else
  178. exclude(a,opt);
  179. end
  180. else
  181. result:=false;
  182. end;
  183. until false;
  184. end;
  185. function UpdateDebugStr(s:string;var a:tdebugswitches):boolean;
  186. var
  187. tok : string;
  188. doset,
  189. found : boolean;
  190. opt : tdebugswitch;
  191. begin
  192. result:=true;
  193. uppervar(s);
  194. repeat
  195. tok:=GetToken(s,',');
  196. if tok='' then
  197. break;
  198. if Copy(tok,1,2)='NO' then
  199. begin
  200. delete(tok,1,2);
  201. doset:=false;
  202. end
  203. else
  204. doset:=true;
  205. found:=false;
  206. for opt:=low(tdebugswitch) to high(tdebugswitch) do
  207. begin
  208. if DebugSwitchStr[opt]=tok then
  209. begin
  210. found:=true;
  211. break;
  212. end;
  213. end;
  214. if found then
  215. begin
  216. if doset then
  217. include(a,opt)
  218. else
  219. exclude(a,opt);
  220. end
  221. else
  222. result:=false;
  223. until false;
  224. end;
  225. function UpdateTargetSwitchStr(s: string; var a: ttargetswitches; global: boolean): boolean;
  226. var
  227. tok,
  228. value : string;
  229. setstr: string[2];
  230. equalspos: longint;
  231. doset,
  232. gotvalue,
  233. found : boolean;
  234. opt : ttargetswitch;
  235. begin
  236. result:=true;
  237. value:='';
  238. repeat
  239. tok:=GetToken(s,',');
  240. if tok='' then
  241. break;
  242. setstr:=upper(copy(tok,length(tok),1));
  243. if setstr='-' then
  244. begin
  245. setlength(tok,length(tok)-1);
  246. doset:=false;
  247. end
  248. else
  249. doset:=true;
  250. { value specified? }
  251. gotvalue:=false;
  252. equalspos:=pos('=',tok);
  253. if equalspos<>0 then
  254. begin
  255. value:=copy(tok,equalspos+1,length(tok));
  256. delete(tok,equalspos,length(tok));
  257. gotvalue:=true;
  258. end;
  259. found:=false;
  260. uppervar(tok);
  261. for opt:=low(ttargetswitch) to high(ttargetswitch) do
  262. begin
  263. if TargetSwitchStr[opt].name=tok then
  264. begin
  265. found:=true;
  266. break;
  267. end;
  268. end;
  269. if found then
  270. begin
  271. if not global and
  272. TargetSwitchStr[opt].isglobal then
  273. result:=false
  274. else if not TargetSwitchStr[opt].hasvalue then
  275. begin
  276. if gotvalue then
  277. result:=false;
  278. if (TargetSwitchStr[opt].define<>'') and (doset xor (opt in a)) then
  279. if doset then
  280. def_system_macro(TargetSwitchStr[opt].define)
  281. else
  282. undef_system_macro(TargetSwitchStr[opt].define);
  283. if doset then
  284. include(a,opt)
  285. else
  286. exclude(a,opt)
  287. end
  288. else
  289. begin
  290. if not gotvalue or
  291. not doset then
  292. result:=false
  293. else
  294. begin
  295. case opt of
  296. ts_auto_getter_prefix:
  297. prop_auto_getter_prefix:=value;
  298. ts_auto_setter_predix:
  299. prop_auto_setter_prefix:=value;
  300. else
  301. begin
  302. writeln('Internalerror 2012053001');
  303. halt(1);
  304. end;
  305. end;
  306. end;
  307. end;
  308. end
  309. else
  310. result:=false;
  311. until false;
  312. end;
  313. end.