nset.pas 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Type checking and register allocation for set/case nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nset;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,constexp,
  22. node,globtype,globals,
  23. aasmbase,ncon,nflw,symtype;
  24. type
  25. TLabelType = (ltOrdinal, ltConstString);
  26. pcaselabel = ^tcaselabel;
  27. tcaselabel = record
  28. { unique blockid }
  29. blockid : longint;
  30. { left and right tree node }
  31. less,
  32. greater : pcaselabel;
  33. labellabel : TAsmLabel;
  34. { range type }
  35. case label_type : TLabelType of
  36. ltOrdinal:
  37. (
  38. _low,
  39. _high : TConstExprInt;
  40. );
  41. ltConstString:
  42. (
  43. _low_str,
  44. _high_str : tstringconstnode;
  45. );
  46. end;
  47. pcaseblock = ^tcaseblock;
  48. tcaseblock = record
  49. { label (only used in pass_generate_code) }
  50. blocklabel : tasmlabel;
  51. {$ifdef WASM}
  52. BlockBr : Integer;
  53. {$endif WASM}
  54. { shortcut - set to true if blocklabel isn't actually unique to the
  55. case block due to one of the following conditions:
  56. - if the node contains a jump, then the label is set to that jump's destination,
  57. - if the node is empty, the label is set to the end label. }
  58. shortcut: Boolean;
  59. statementlabel : tlabelnode;
  60. { instructions }
  61. statement : tnode;
  62. end;
  63. tsetelementnode = class(tbinarynode)
  64. constructor create(l,r : tnode);virtual;
  65. function pass_typecheck:tnode;override;
  66. function pass_1 : tnode;override;
  67. end;
  68. tsetelementnodeclass = class of tsetelementnode;
  69. tinnode = class(tbinopnode)
  70. constructor create(l,r : tnode);virtual;reintroduce;
  71. function pass_typecheck:tnode;override;
  72. function simplify(forinline : boolean):tnode;override;
  73. function pass_1 : tnode;override;
  74. end;
  75. tinnodeclass = class of tinnode;
  76. trangenode = class(tbinarynode)
  77. constructor create(l,r : tnode);virtual;
  78. function pass_typecheck:tnode;override;
  79. function pass_1 : tnode;override;
  80. end;
  81. trangenodeclass = class of trangenode;
  82. tcasenode = class(tunarynode)
  83. strict private
  84. { Number of labels }
  85. flabelcnt: cardinal;
  86. { Number of individual values checked, counting each value in a range
  87. individually (e.g. 0..2 counts as 3). }
  88. flabelcoverage: qword;
  89. fcountsuptodate: boolean;
  90. function getlabelcnt: cardinal;
  91. function getlabelcoverage: qword;
  92. procedure updatecoverage;
  93. procedure checkordinalcoverage;
  94. public
  95. blocks : TFPList;
  96. elseblock : tnode;
  97. constructor create(l:tnode);virtual;
  98. destructor destroy;override;
  99. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  100. procedure ppuwrite(ppufile:tcompilerppufile);override;
  101. procedure buildderefimpl;override;
  102. procedure derefimpl;override;
  103. function dogetcopy : tnode;override;
  104. procedure printnodetree(var t:text);override;
  105. {$ifdef DEBUG_NODE_XML}
  106. procedure XMLPrintNodeTree(var t:text); override;
  107. {$endif DEBUG_NODE_XML}
  108. procedure insertintolist(l : tnodelist);override;
  109. function pass_typecheck:tnode;override;
  110. function pass_1 : tnode;override;
  111. function simplify(forinline:boolean):tnode;override;
  112. function docompare(p: tnode): boolean; override;
  113. procedure addlabel(blockid:longint;const l,h : TConstExprInt); overload;
  114. procedure addlabel(blockid:longint;l,h : tstringconstnode); overload;
  115. procedure addblock(blockid:longint;instr:tnode);
  116. procedure addelseblock(instr:tnode);
  117. property labelcnt: cardinal read getlabelcnt;
  118. { returns one less than the covered case range, so that it
  119. does not overflow for a fully covered qword range }
  120. property labelcoverage: qword read getlabelcoverage;
  121. protected
  122. flabels : pcaselabel;
  123. public
  124. property labels: pcaselabel read flabels;
  125. end;
  126. tcasenodeclass = class of tcasenode;
  127. var
  128. csetelementnode : tsetelementnodeclass = tsetelementnode;
  129. cinnode : tinnodeclass = tinnode;
  130. crangenode : trangenodeclass = trangenode;
  131. ccasenode : tcasenodeclass = tcasenode;
  132. { searches the highest label }
  133. function case_get_max(root : pcaselabel) : tconstexprint;
  134. { searches the lowest label }
  135. function case_get_min(root : pcaselabel) : tconstexprint;
  136. implementation
  137. uses
  138. verbose,cutils,
  139. symconst,symdef,symsym,symtable,defutil,defcmp,
  140. htypechk,pass_1,
  141. nadd,nbas,ncal,ncnv,nld,nutils,
  142. cgbase;
  143. {*****************************************************************************
  144. TSETELEMENTNODE
  145. *****************************************************************************}
  146. constructor tsetelementnode.create(l,r : tnode);
  147. begin
  148. inherited create(setelementn,l,r);
  149. end;
  150. function tsetelementnode.pass_typecheck:tnode;
  151. begin
  152. result:=nil;
  153. typecheckpass(left);
  154. if assigned(right) then
  155. typecheckpass(right);
  156. set_varstate(left,vs_read,[vsf_must_be_valid]);
  157. if codegenerror then
  158. exit;
  159. resultdef:=left.resultdef;
  160. end;
  161. function tsetelementnode.pass_1 : tnode;
  162. begin
  163. result:=nil;
  164. firstpass(left);
  165. if assigned(right) then
  166. firstpass(right);
  167. if codegenerror then
  168. exit;
  169. expectloc:=left.expectloc;
  170. end;
  171. {*****************************************************************************
  172. TINNODE
  173. *****************************************************************************}
  174. constructor tinnode.create(l,r : tnode);
  175. begin
  176. inherited create(inn,l,r);
  177. end;
  178. function tinnode.pass_typecheck:tnode;
  179. var
  180. t : tnode;
  181. function createsetconst(psd : tsetdef) : pconstset;
  182. var
  183. pcs : pconstset;
  184. i : longint;
  185. begin
  186. new(pcs);
  187. case psd.elementdef.typ of
  188. enumdef :
  189. begin
  190. for i := 0 to tenumdef(psd.elementdef).symtable.SymList.Count - 1 do
  191. begin
  192. include(pcs^,tenumsym(tenumdef(psd.elementdef).symtable.SymList[i]).value);
  193. end;
  194. end;
  195. orddef :
  196. begin
  197. for i:=int64(torddef(psd.elementdef).low) to int64(torddef(psd.elementdef).high) do
  198. include(pcs^,i);
  199. end;
  200. else
  201. internalerror(2019050516);
  202. end;
  203. createsetconst:=pcs;
  204. end;
  205. begin
  206. result:=nil;
  207. resultdef:=pasbool1type;
  208. typecheckpass(right);
  209. set_varstate(right,vs_read,[vsf_must_be_valid]);
  210. if codegenerror then
  211. exit;
  212. { Convert array constructor first to set }
  213. if is_array_constructor(right.resultdef) then
  214. begin
  215. arrayconstructor_to_set(right);
  216. if codegenerror then
  217. exit;
  218. end;
  219. typecheckpass(left);
  220. set_varstate(left,vs_read,[vsf_must_be_valid]);
  221. if codegenerror then
  222. exit;
  223. if not assigned(left.resultdef) then
  224. internalerror(20021126);
  225. { avoid any problems with type parameters later on }
  226. if is_typeparam(left.resultdef) or is_typeparam(right.resultdef) then
  227. begin
  228. resultdef:=cundefinedtype;
  229. exit;
  230. end;
  231. t:=self;
  232. if isbinaryoverloaded(t,[]) then
  233. begin
  234. result:=t;
  235. exit;
  236. end;
  237. if right.resultdef.typ<>setdef then
  238. CGMessage(sym_e_set_expected);
  239. if codegenerror then
  240. exit;
  241. if (m_tp7 in current_settings.modeswitches) then
  242. begin
  243. { insert a hint that a range check error might occur on non-byte
  244. elements with the in operator.
  245. }
  246. if (
  247. (left.resultdef.typ = orddef) and not
  248. (torddef(left.resultdef).ordtype in [s8bit,u8bit,uchar,pasbool1,pasbool8,bool8bit])
  249. )
  250. or
  251. (
  252. (left.resultdef.typ = enumdef) and
  253. (tenumdef(left.resultdef).maxval > 255)
  254. )
  255. then
  256. CGMessage(type_h_in_range_check);
  257. { type conversion/check }
  258. if assigned(tsetdef(right.resultdef).elementdef) then
  259. inserttypeconv(left,tsetdef(right.resultdef).elementdef);
  260. end
  261. else if not is_ordinal(left.resultdef) or (left.resultdef.size > u32inttype.size) then
  262. begin
  263. CGMessage(type_h_in_range_check);
  264. if is_signed(left.resultdef) then
  265. inserttypeconv(left,s32inttype)
  266. else
  267. inserttypeconv(left,u32inttype);
  268. end
  269. else if assigned(tsetdef(right.resultdef).elementdef) and
  270. not(is_integer(tsetdef(right.resultdef).elementdef) and
  271. is_integer(left.resultdef)) then
  272. { Type conversion to check things like 'char in set_of_byte'. }
  273. { Can't use is_subequal because that will fail for }
  274. { 'widechar in set_of_char' }
  275. { Can't use the type conversion for integers because then }
  276. { "longint in set_of_byte" will give a range check error }
  277. { instead of false }
  278. inserttypeconv(left,tsetdef(right.resultdef).elementdef);
  279. { empty set then return false }
  280. if not assigned(tsetdef(right.resultdef).elementdef) or
  281. ((right.nodetype = setconstn) and
  282. (tnormalset(tsetconstnode(right).value_set^) = [])) then
  283. begin
  284. t:=cordconstnode.create(0,pasbool1type,false);
  285. typecheckpass(t);
  286. result:=t;
  287. exit;
  288. end;
  289. result:=simplify(false);
  290. end;
  291. function tinnode.simplify(forinline : boolean):tnode;
  292. var
  293. t : tnode;
  294. begin
  295. result:=nil;
  296. { constant evaluation }
  297. if (left.nodetype=ordconstn) then
  298. begin
  299. if (right.nodetype=setconstn) then
  300. begin
  301. { tordconstnode.value is int64 -> signed -> the expression }
  302. { below will be converted to longint on 32 bit systems due }
  303. { to the rule above -> will give range check error if }
  304. { value > high(longint) if we don't take the signedness }
  305. { into account }
  306. if Tordconstnode(left).value.signed then
  307. t:=cordconstnode.create(byte(tordconstnode(left).value.svalue in Tsetconstnode(right).value_set^),
  308. pasbool1type,true)
  309. else
  310. t:=cordconstnode.create(byte(tordconstnode(left).value.uvalue in Tsetconstnode(right).value_set^),
  311. pasbool1type,true);
  312. typecheckpass(t);
  313. result:=t;
  314. exit;
  315. end
  316. else
  317. begin
  318. if (Tordconstnode(left).value<int64(tsetdef(right.resultdef).setbase)) or
  319. (Tordconstnode(left).value>int64(Tsetdef(right.resultdef).setmax)) then
  320. begin
  321. t:=cordconstnode.create(0, pasbool1type, true);
  322. typecheckpass(t);
  323. result:=t;
  324. exit;
  325. end;
  326. end;
  327. end
  328. { a in [a] => true, if a has no side effects }
  329. else if (right.nodetype=addn) and
  330. (taddnode(right).left.nodetype=setconstn) and
  331. (tsetconstnode(taddnode(right).left).elements=0) and
  332. (taddnode(right).right.nodetype=setelementn) and
  333. (tsetelementnode(taddnode(right).right).right=nil) and
  334. ((tsetelementnode(taddnode(right).right).left.isequal(left)) or
  335. (
  336. (tsetelementnode(taddnode(right).right).left.nodetype=typeconvn) and
  337. (ttypeconvnode(tsetelementnode(taddnode(right).right).left).left.isequal(left))
  338. )
  339. ) and
  340. not(might_have_sideeffects(left,[mhs_exceptions])) then
  341. begin
  342. t:=cordconstnode.create(1, pasbool1type, true);
  343. typecheckpass(t);
  344. result:=t;
  345. exit;
  346. end;
  347. end;
  348. function tinnode.pass_1 : tnode;
  349. begin
  350. result:=nil;
  351. expectloc:=LOC_REGISTER;
  352. firstpass(right);
  353. firstpass(left);
  354. if codegenerror then
  355. exit;
  356. end;
  357. {*****************************************************************************
  358. TRANGENODE
  359. *****************************************************************************}
  360. constructor trangenode.create(l,r : tnode);
  361. var
  362. value: string;
  363. begin
  364. { if right is char and left is string then }
  365. { right should be treated as one-symbol string }
  366. if is_conststringnode(l) and is_constcharnode(r) then
  367. begin
  368. value := char(tordconstnode(r).value.uvalue) + ''#0;
  369. r.free;
  370. r := cstringconstnode.createstr(value);
  371. do_typecheckpass(r);
  372. end;
  373. inherited create(rangen,l,r);
  374. end;
  375. function trangenode.pass_typecheck : tnode;
  376. begin
  377. result:=nil;
  378. typecheckpass(left);
  379. typecheckpass(right);
  380. set_varstate(left,vs_read,[vsf_must_be_valid]);
  381. set_varstate(right,vs_read,[vsf_must_be_valid]);
  382. if codegenerror then
  383. exit;
  384. { both types must be compatible }
  385. if compare_defs(left.resultdef,right.resultdef,left.nodetype)=te_incompatible then
  386. IncompatibleTypes(left.resultdef,right.resultdef);
  387. { check if only when its a constant set and
  388. ignore range nodes which are generic parameter derived }
  389. if not (nf_generic_para in flags) and (left.nodetype=ordconstn) and (right.nodetype=ordconstn) then
  390. begin
  391. { upper limit must be greater or equal than lower limit }
  392. if (tordconstnode(left).value>tordconstnode(right).value) and
  393. ((tordconstnode(left).value<0) or (tordconstnode(right).value>=0)) then
  394. CGMessage(parser_e_upper_lower_than_lower);
  395. end;
  396. resultdef:=left.resultdef;
  397. end;
  398. function trangenode.pass_1 : tnode;
  399. begin
  400. result:=nil;
  401. firstpass(left);
  402. firstpass(right);
  403. if codegenerror then
  404. exit;
  405. expectloc:=left.expectloc;
  406. end;
  407. {*****************************************************************************
  408. Case Helpers
  409. *****************************************************************************}
  410. { labels is the number of case-labels, while cases includes each individual
  411. value in a range (e.g. "0..2" counts as 3) }
  412. procedure case_count_labels(root : pcaselabel; out labels, cases: longint);
  413. procedure count(p : pcaselabel);
  414. begin
  415. inc(labels);
  416. inc(cases, (p^._high.svalue - p^._low.svalue) + 1);
  417. if assigned(p^.less) then
  418. count(p^.less);
  419. if assigned(p^.greater) then
  420. count(p^.greater);
  421. end;
  422. begin
  423. labels:=0;
  424. cases:=0;
  425. count(root);
  426. end;
  427. function case_get_max(root : pcaselabel) : tconstexprint;
  428. var
  429. hp : pcaselabel;
  430. begin
  431. hp:=root;
  432. while assigned(hp^.greater) do
  433. hp:=hp^.greater;
  434. case_get_max:=hp^._high;
  435. end;
  436. function case_get_min(root : pcaselabel) : tconstexprint;
  437. var
  438. hp : pcaselabel;
  439. begin
  440. hp:=root;
  441. while assigned(hp^.less) do
  442. hp:=hp^.less;
  443. case_get_min:=hp^._low;
  444. end;
  445. procedure deletecaselabels(p : pcaselabel);
  446. begin
  447. if assigned(p^.greater) then
  448. deletecaselabels(p^.greater);
  449. if assigned(p^.less) then
  450. deletecaselabels(p^.less);
  451. if (p^.label_type = ltConstString) then
  452. begin
  453. p^._low_str.Free;
  454. p^._high_str.Free;
  455. end;
  456. dispose(p);
  457. end;
  458. function copycaselabel(p : pcaselabel) : pcaselabel;
  459. var
  460. n : pcaselabel;
  461. begin
  462. new(n);
  463. n^:=p^;
  464. if (p^.label_type = ltConstString) then
  465. begin
  466. n^._low_str := tstringconstnode(p^._low_str.getcopy);
  467. n^._high_str := tstringconstnode(p^._high_str.getcopy);
  468. end;
  469. if assigned(p^.greater) then
  470. n^.greater:=copycaselabel(p^.greater);
  471. if assigned(p^.less) then
  472. n^.less:=copycaselabel(p^.less);
  473. copycaselabel:=n;
  474. end;
  475. procedure ppuwritecaselabel(ppufile:tcompilerppufile;p : pcaselabel);
  476. var
  477. b : byte;
  478. begin
  479. ppufile.putboolean(p^.label_type = ltConstString);
  480. if (p^.label_type = ltConstString) then
  481. begin
  482. p^._low_str.ppuwrite(ppufile);
  483. p^._high_str.ppuwrite(ppufile);
  484. end
  485. else
  486. begin
  487. ppufile.putexprint(p^._low);
  488. ppufile.putexprint(p^._high);
  489. end;
  490. ppufile.putlongint(p^.blockid);
  491. b:=ord(assigned(p^.greater)) or (ord(assigned(p^.less)) shl 1);
  492. ppufile.putbyte(b);
  493. if assigned(p^.greater) then
  494. ppuwritecaselabel(ppufile,p^.greater);
  495. if assigned(p^.less) then
  496. ppuwritecaselabel(ppufile,p^.less);
  497. end;
  498. function ppuloadcaselabel(ppufile:tcompilerppufile):pcaselabel;
  499. var
  500. b : byte;
  501. p : pcaselabel;
  502. begin
  503. new(p);
  504. if ppufile.getboolean then
  505. begin
  506. p^.label_type := ltConstString;
  507. p^._low_str := cstringconstnode.ppuload(stringconstn,ppufile);
  508. p^._high_str := cstringconstnode.ppuload(stringconstn,ppufile);
  509. end
  510. else
  511. begin
  512. p^.label_type := ltOrdinal;
  513. p^._low:=ppufile.getexprint;
  514. p^._high:=ppufile.getexprint;
  515. end;
  516. p^.blockid:=ppufile.getlongint;
  517. b:=ppufile.getbyte;
  518. if (b and 1)=1 then
  519. p^.greater:=ppuloadcaselabel(ppufile)
  520. else
  521. p^.greater:=nil;
  522. if (b and 2)=2 then
  523. p^.less:=ppuloadcaselabel(ppufile)
  524. else
  525. p^.less:=nil;
  526. ppuloadcaselabel:=p;
  527. end;
  528. {*****************************************************************************
  529. TCASENODE
  530. *****************************************************************************}
  531. constructor tcasenode.create(l:tnode);
  532. begin
  533. inherited create(casen,l);
  534. flabels:=nil;
  535. blocks:=TFPList.create;
  536. elseblock:=nil;
  537. end;
  538. destructor tcasenode.destroy;
  539. var
  540. i : longint;
  541. hp : pcaseblock;
  542. begin
  543. elseblock.free;
  544. deletecaselabels(flabels);
  545. for i:=0 to blocks.count-1 do
  546. begin
  547. pcaseblock(blocks[i])^.statement.free;
  548. hp:=pcaseblock(blocks[i]);
  549. dispose(hp);
  550. end;
  551. blocks.free;
  552. inherited destroy;
  553. end;
  554. constructor tcasenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  555. var
  556. cnt,i : longint;
  557. begin
  558. inherited ppuload(t,ppufile);
  559. elseblock:=ppuloadnode(ppufile);
  560. cnt:=ppufile.getlongint();
  561. blocks:=TFPList.create;
  562. for i:=0 to cnt-1 do
  563. addblock(i,ppuloadnode(ppufile));
  564. flabels:=ppuloadcaselabel(ppufile);
  565. { we don't save/restore the label counts, but recalculate them if needed }
  566. fcountsuptodate:=false;
  567. end;
  568. procedure tcasenode.ppuwrite(ppufile:tcompilerppufile);
  569. var
  570. i : longint;
  571. begin
  572. inherited ppuwrite(ppufile);
  573. ppuwritenode(ppufile,elseblock);
  574. ppufile.putlongint(blocks.count);
  575. for i:=0 to blocks.count-1 do
  576. ppuwritenode(ppufile,pcaseblock(blocks[i])^.statement);
  577. ppuwritecaselabel(ppufile,flabels);
  578. { we don't save/restore the label counts, but recalculate them if needed }
  579. end;
  580. procedure tcasenode.buildderefimpl;
  581. var
  582. i : integer;
  583. begin
  584. inherited buildderefimpl;
  585. if assigned(elseblock) then
  586. elseblock.buildderefimpl;
  587. for i:=0 to blocks.count-1 do
  588. pcaseblock(blocks[i])^.statement.buildderefimpl;
  589. end;
  590. procedure tcasenode.derefimpl;
  591. var
  592. i : integer;
  593. begin
  594. inherited derefimpl;
  595. if assigned(elseblock) then
  596. elseblock.derefimpl;
  597. for i:=0 to blocks.count-1 do
  598. pcaseblock(blocks[i])^.statement.derefimpl;
  599. end;
  600. function tcasenode.pass_typecheck : tnode;
  601. var
  602. i : integer;
  603. begin
  604. result:=nil;
  605. do_typecheckpass(left);
  606. for i:=0 to blocks.count-1 do
  607. typecheckpass(pcaseblock(blocks[i])^.statement);
  608. if assigned(elseblock) then
  609. typecheckpass(elseblock);
  610. resultdef:=voidtype;
  611. result:=simplify(false);
  612. end;
  613. type
  614. TLinkedListCaseLabelItem = class(TLinkedListItem)
  615. casenode: pcaselabel;
  616. constructor create(c: pcaselabel);
  617. end;
  618. constructor TLinkedListCaseLabelItem.create(c: pcaselabel);
  619. begin
  620. inherited create;
  621. casenode:=c;
  622. end;
  623. function tcasenode.pass_1 : tnode;
  624. var
  625. i: integer;
  626. node_thenblock, node_elseblock, if_node,temp_cleanup : tnode;
  627. tempcaseexpr : ttempcreatenode;
  628. if_block, init_block: tblocknode;
  629. stmt: tstatementnode;
  630. procedure add_label_to_blockid_list(list: tfpobjectlist; lab: pcaselabel);
  631. begin
  632. if not assigned(lab) then
  633. exit;
  634. if not assigned(list[lab^.blockid]) then
  635. list[lab^.blockid]:=tfpobjectlist.create(true);
  636. tfpobjectlist(list[lab^.blockid]).add(TLinkedListCaseLabelItem.create(lab));
  637. add_label_to_blockid_list(list,lab^.less);
  638. add_label_to_blockid_list(list,lab^.greater);
  639. end;
  640. function order_labels_by_blockid: tfpobjectlist;
  641. begin
  642. result:=tfpobjectlist.create(true);
  643. result.count:=blocks.count;
  644. add_label_to_blockid_list(result,flabels);
  645. end;
  646. function makeifblock(elseblock : tnode): tnode;
  647. var
  648. i, j: longint;
  649. check: taddnode;
  650. newcheck: ^taddnode;
  651. blocklist, lablist: tfpobjectlist;
  652. labitem: pcaselabel;
  653. begin
  654. result:=elseblock;
  655. blocklist:=order_labels_by_blockid;
  656. { in reverse order so that the case options at the start of the case
  657. statement are evaluated first, as they presumably are the most
  658. common }
  659. for i:=blocklist.count-1 downto 0 do
  660. begin
  661. lablist:=tfpobjectlist(blocklist[i]);
  662. check:=nil;
  663. for j:=0 to lablist.count-1 do
  664. begin
  665. if assigned(check) then
  666. begin
  667. check:=caddnode.create(orn,check,nil);
  668. newcheck:[email protected]
  669. end
  670. else
  671. newcheck:=@check;
  672. labitem:=TLinkedListCaseLabelItem(lablist[j]).casenode;
  673. newcheck^:=caddnode.create(equaln,left.getcopy,labitem^._low_str.getcopy);
  674. if (labitem^._low_str.fullcompare(labitem^._high_str)<>0) then
  675. begin
  676. newcheck^.nodetype:=gten;
  677. newcheck^:=caddnode.create(
  678. andn,newcheck^,caddnode.create(
  679. lten,left.getcopy,labitem^._high_str.getcopy));
  680. end;
  681. end;
  682. result:=cifnode.create(check,
  683. pcaseblock(blocks[i])^.statement,result);
  684. pcaseblock(blocks[i])^.statement:=nil;
  685. end;
  686. { will free its elements too because of create(true) }
  687. blocklist.free;
  688. typecheckpass(result);
  689. end;
  690. begin
  691. result:=nil;
  692. init_block:=nil;
  693. temp_cleanup:=nil;
  694. expectloc:=LOC_VOID;
  695. { only do in pass_1, so that simplify can run first and
  696. 1) possibly simplify the case node without triggering a warning
  697. 2) possibly give a compile-time error if not all cases are handled
  698. in ISO/Extended Pascal mode }
  699. if is_ordinal(left.resultdef) then
  700. checkordinalcoverage;
  701. { ideally this would be in simplify, but then checkordinalcoverage can
  702. false positives about case statements not handling all cases }
  703. if assigned(elseblock) and
  704. has_no_code(elseblock) then
  705. begin
  706. elseblock.free;
  707. elseblock:=nil;
  708. end;
  709. { evalutes the case expression }
  710. firstpass(left);
  711. set_varstate(left,vs_read,[vsf_must_be_valid]);
  712. if codegenerror then
  713. exit;
  714. { Load caseexpr into temp var if complex. }
  715. { No need to do this for ordinal, because }
  716. { in that case caseexpr is generated once }
  717. if (flabels^.label_type = ltConstString) and (not valid_for_addr(left, false)) and
  718. (blocks.count > 0) then
  719. begin
  720. init_block := internalstatements(stmt);
  721. tempcaseexpr :=
  722. ctempcreatenode.create(
  723. left.resultdef, left.resultdef.size, tt_persistent, true);
  724. temp_cleanup := ctempdeletenode.create(tempcaseexpr);
  725. typecheckpass(tnode(tempcaseexpr));
  726. addstatement(stmt, tempcaseexpr);
  727. addstatement(
  728. stmt, cassignmentnode.create(
  729. ctemprefnode.create(tempcaseexpr), left));
  730. left := ctemprefnode.create(tempcaseexpr);
  731. typecheckpass(left);
  732. end;
  733. { first case }
  734. for i:=0 to blocks.count-1 do
  735. firstpass(pcaseblock(blocks[i])^.statement);
  736. { may be handle else tree }
  737. if assigned(elseblock) then
  738. begin
  739. firstpass(elseblock);
  740. { kill case? }
  741. if blocks.count=0 then
  742. begin
  743. result:=elseblock;
  744. elseblock:=nil;
  745. exit;
  746. end;
  747. end
  748. else
  749. if blocks.count=0 then
  750. begin
  751. result:=cnothingnode.create;
  752. exit;
  753. end;
  754. if (flabels^.label_type = ltConstString) then
  755. begin
  756. if_node:=makeifblock(elseblock);
  757. if assigned(init_block) then
  758. firstpass(tnode(init_block));
  759. if_block:=internalstatements(stmt);
  760. if assigned(init_block) then
  761. addstatement(stmt, init_block);
  762. addstatement(stmt,if_node);
  763. if assigned(temp_cleanup) then
  764. addstatement(stmt,temp_cleanup);
  765. result:=if_block;
  766. elseblock:= nil;
  767. exit;
  768. end;
  769. if is_boolean(left.resultdef) then
  770. begin
  771. case blocks.count of
  772. 2:
  773. begin
  774. if boolean(qword(flabels^._low))=false then
  775. begin
  776. node_thenblock:=pcaseblock(blocks[flabels^.greater^.blockid])^.statement;
  777. node_elseblock:=pcaseblock(blocks[flabels^.blockid])^.statement;
  778. pcaseblock(blocks[flabels^.greater^.blockid])^.statement:=nil;
  779. end
  780. else
  781. begin
  782. node_thenblock:=pcaseblock(blocks[flabels^.blockid])^.statement;
  783. node_elseblock:=pcaseblock(blocks[flabels^.less^.blockid])^.statement;
  784. pcaseblock(blocks[flabels^.less^.blockid])^.statement:=nil;
  785. end;
  786. pcaseblock(blocks[flabels^.blockid])^.statement:=nil;
  787. end;
  788. 1:
  789. begin
  790. if flabels^._low=flabels^._high then
  791. begin
  792. if boolean(qword(flabels^._low))=false then
  793. begin
  794. node_thenblock:=elseblock;
  795. node_elseblock:=pcaseblock(blocks[flabels^.blockid])^.statement;
  796. end
  797. else
  798. begin
  799. node_thenblock:=pcaseblock(blocks[flabels^.blockid])^.statement;
  800. node_elseblock:=elseblock;
  801. end;
  802. pcaseblock(blocks[flabels^.blockid])^.statement:=nil;
  803. elseblock:=nil;
  804. end
  805. else
  806. begin
  807. result:=pcaseblock(blocks[flabels^.blockid])^.statement;
  808. pcaseblock(blocks[flabels^.blockid])^.statement:=nil;
  809. elseblock:=nil;
  810. exit;
  811. end;
  812. end;
  813. else
  814. internalerror(200805031);
  815. end;
  816. result:=cifnode.create(left,node_thenblock,node_elseblock);
  817. left:=nil;
  818. exit;
  819. end;
  820. { convert single case branch into if-statement }
  821. if (flabels^.greater=nil) and (flabels^.less=nil) then
  822. if flabels^.label_type=ltOrdinal then
  823. begin
  824. if flabels^._low=flabels^._high then
  825. begin
  826. result:=cifnode.create_internal(
  827. caddnode.create_internal(equaln,left.getcopy,cordconstnode.create(flabels^._low,left.resultdef,false)),
  828. pcaseblock(blocks[flabels^.blockid])^.statement,elseblock);
  829. end
  830. else
  831. begin
  832. result:=cifnode.create_internal(
  833. caddnode.create_internal(andn,
  834. caddnode.create_internal(gten,left.getcopy,cordconstnode.create(flabels^._low,left.resultdef,false)),
  835. caddnode.create_internal(lten,left.getcopy,cordconstnode.create(flabels^._high,left.resultdef,false))
  836. ),
  837. pcaseblock(blocks[flabels^.blockid])^.statement,elseblock);
  838. end;
  839. elseblock:=nil;
  840. pcaseblock(blocks[flabels^.blockid])^.statement:=nil;
  841. exit;
  842. end;
  843. end;
  844. function tcasenode.simplify(forinline:boolean):tnode;
  845. var
  846. tmp: pcaselabel;
  847. begin
  848. result:=nil;
  849. if left.nodetype=ordconstn then
  850. begin
  851. tmp:=flabels;
  852. { check all case labels until we find one that fits }
  853. while assigned(tmp) do
  854. begin
  855. if (tmp^._low<=tordconstnode(left).value) and
  856. (tmp^._high>=tordconstnode(left).value) then
  857. begin
  858. if tmp^.blockid>=blocks.count then
  859. internalerror(2014022101);
  860. result:=pcaseblock(blocks[tmp^.blockid])^.statement;
  861. if not assigned(result) then
  862. internalerror(2014022102);
  863. result:=result.getcopy;
  864. exit;
  865. end;
  866. if tmp^._high<tordconstnode(left).value then
  867. tmp:=tmp^.greater
  868. else
  869. tmp:=tmp^.less;
  870. end;
  871. { no label did match; use the else block if available }
  872. if assigned(elseblock) then
  873. result:=elseblock.getcopy
  874. else
  875. begin
  876. if ([m_iso,m_extpas]*current_settings.modeswitches)<>[] then
  877. cgmessage1(cg_e_case_missing_value,tostr(tordconstnode(left).value))
  878. else
  879. cgmessage(cg_w_case_incomplete);
  880. { no else block, so there is no code to execute at all }
  881. result:=cnothingnode.create;
  882. end;
  883. end;
  884. end;
  885. function tcasenode.dogetcopy : tnode;
  886. var
  887. n : tcasenode;
  888. i : longint;
  889. begin
  890. n:=tcasenode(inherited dogetcopy);
  891. if assigned(elseblock) then
  892. n.elseblock:=elseblock.dogetcopy
  893. else
  894. n.elseblock:=nil;
  895. if assigned(flabels) then
  896. n.flabels:=copycaselabel(flabels)
  897. else
  898. n.flabels:=nil;
  899. if assigned(blocks) then
  900. begin
  901. n.blocks:=TFPList.create;
  902. for i:=0 to blocks.count-1 do
  903. begin
  904. if not assigned(blocks[i]) then
  905. internalerror(200411302);
  906. n.addblock(i,pcaseblock(blocks[i])^.statement.dogetcopy);
  907. end;
  908. end
  909. else
  910. n.blocks:=nil;
  911. n.fcountsuptodate:=fcountsuptodate;
  912. n.flabelcnt:=flabelcnt;
  913. n.flabelcoverage:=flabelcoverage;
  914. dogetcopy:=n;
  915. end;
  916. procedure tcasenode.printnodetree(var t: text);
  917. var
  918. i : longint;
  919. begin
  920. write(t,printnodeindention,'(');
  921. printnodeindent;
  922. printnodeinfo(t);
  923. writeln(t);
  924. printnode(t,left);
  925. i:=0;
  926. for i:=0 to blocks.count-1 do
  927. begin
  928. writeln(t,printnodeindention,'(caseblock blockid: ',i);
  929. printnodeindent;
  930. printnode(t,pcaseblock(blocks[i])^.statement);
  931. printnodeunindent;
  932. writeln(t,printnodeindention,')');
  933. end;
  934. if assigned(elseblock) then
  935. begin
  936. writeln(t,printnodeindention,'(else: ',i);
  937. printnodeindent;
  938. printnode(t,elseblock);
  939. printnodeunindent;
  940. writeln(t,printnodeindention,')');
  941. end;
  942. printnodeunindent;
  943. writeln(t,printnodeindention,')');
  944. end;
  945. {$ifdef DEBUG_NODE_XML}
  946. procedure TCaseNode.XMLPrintNodeTree(var T: Text);
  947. var
  948. i : longint;
  949. begin
  950. Write(T, PrintNodeIndention, '<', nodetype2str[nodetype]);
  951. XMLPrintNodeInfo(T);
  952. WriteLn(T, '>');
  953. PrintNodeIndent;
  954. WriteLn(T, PrintNodeIndention, '<condition>');
  955. PrintNodeIndent;
  956. XMLPrintNode(T, Left);
  957. PrintNodeUnindent;
  958. WriteLn(T, PrintNodeIndention, '</condition>');
  959. i:=0;
  960. for i:=0 to blocks.count-1 do
  961. begin
  962. WriteLn(T, PrintNodeIndention, '<block id="', i, '">');
  963. PrintNodeIndent;
  964. XMLPrintNode(T, PCaseBlock(blocks[i])^.statement);
  965. PrintNodeUnindent;
  966. WriteLn(T, PrintNodeIndention, '</block>');
  967. end;
  968. if assigned(elseblock) then
  969. begin
  970. WriteLn(T, PrintNodeIndention, '<block id="else">');
  971. PrintNodeIndent;
  972. XMLPrintNode(T, ElseBlock);
  973. PrintNodeUnindent;
  974. WriteLn(T, PrintNodeIndention, '</block>');
  975. end;
  976. PrintNodeUnindent;
  977. WriteLn(T, PrintNodeIndention, '</', nodetype2str[nodetype], '>');
  978. end;
  979. {$endif DEBUG_NODE_XML}
  980. procedure tcasenode.insertintolist(l : tnodelist);
  981. begin
  982. end;
  983. function caselabelsequal(n1,n2: pcaselabel): boolean;
  984. begin
  985. result :=
  986. (not assigned(n1) and not assigned(n2)) or
  987. (assigned(n1) and assigned(n2) and
  988. (n1^._low = n2^._low) and
  989. (n1^._high = n2^._high) and
  990. { the rest of the fields don't matter for equality (JM) }
  991. caselabelsequal(n1^.less,n2^.less) and
  992. caselabelsequal(n1^.greater,n2^.greater))
  993. end;
  994. function caseblocksequal(b1,b2:TFPList): boolean;
  995. var
  996. i : longint;
  997. begin
  998. result:=false;
  999. if b1.count<>b2.count then
  1000. exit;
  1001. for i:=0 to b1.count-1 do
  1002. begin
  1003. if not pcaseblock(b1[i])^.statement.isequal(pcaseblock(b2[i])^.statement) then
  1004. exit;
  1005. end;
  1006. result:=true;
  1007. end;
  1008. function tcasenode.docompare(p: tnode): boolean;
  1009. begin
  1010. result :=
  1011. inherited docompare(p) and
  1012. caselabelsequal(flabels,tcasenode(p).flabels) and
  1013. caseblocksequal(blocks,tcasenode(p).blocks) and
  1014. elseblock.isequal(tcasenode(p).elseblock);
  1015. end;
  1016. procedure tcasenode.addblock(blockid:longint;instr:tnode);
  1017. var
  1018. hcaseblock : pcaseblock;
  1019. begin
  1020. new(hcaseblock);
  1021. fillchar(hcaseblock^,sizeof(hcaseblock^),0);
  1022. hcaseblock^.statement:=instr;
  1023. if blockid>=blocks.count then
  1024. blocks.count:=blockid+1;
  1025. blocks[blockid]:=hcaseblock;
  1026. end;
  1027. procedure tcasenode.addelseblock(instr:tnode);
  1028. begin
  1029. elseblock:=instr;
  1030. end;
  1031. function tcasenode.getlabelcnt: cardinal;
  1032. begin
  1033. if not fcountsuptodate then
  1034. updatecoverage;
  1035. result:=flabelcnt;
  1036. end;
  1037. function tcasenode.getlabelcoverage: qword;
  1038. begin
  1039. if not fcountsuptodate then
  1040. updatecoverage;
  1041. result:=flabelcoverage;
  1042. end;
  1043. procedure tcasenode.updatecoverage;
  1044. var
  1045. isord, first: boolean;
  1046. procedure count(p : pcaselabel);
  1047. begin
  1048. inc(flabelcnt);
  1049. if isord then
  1050. begin
  1051. flabelcoverage:=flabelcoverage + (p^._high - p^._low);
  1052. { ensure we don't overflow in case it covers the
  1053. full range of qword }
  1054. if not first then
  1055. inc(flabelcoverage);
  1056. first:=false;
  1057. end;
  1058. if assigned(p^.less) then
  1059. count(p^.less);
  1060. if assigned(p^.greater) then
  1061. count(p^.greater);
  1062. end;
  1063. begin
  1064. isord:=is_ordinal(left.resultdef);
  1065. flabelcnt:=0;
  1066. flabelcoverage:=0;
  1067. first:=true;
  1068. count(flabels);
  1069. fcountsuptodate:=true;
  1070. end;
  1071. procedure tcasenode.checkordinalcoverage;
  1072. function orddefspansfullrange(def: torddef): boolean;
  1073. var
  1074. packedbitsize: cardinal;
  1075. dummy: longint;
  1076. val: qword;
  1077. begin
  1078. result:=false;
  1079. packedbitsize:=def.packedbitsize;
  1080. if ((packedbitsize mod 8) <> 0) or
  1081. not ispowerof2(packedbitsize div 8,dummy) then
  1082. exit;
  1083. dec(packedbitsize);
  1084. if is_signed(def) then
  1085. begin
  1086. {$push}{$q-}
  1087. if def.low<>(-(int64(1) shl packedbitsize)) then
  1088. exit;
  1089. if def.high<>((int64(1) shl packedbitsize)-1) then
  1090. exit;
  1091. {$pop}
  1092. end
  1093. else
  1094. begin
  1095. if def.low<>0 then
  1096. exit;
  1097. val:=qword(1) shl packedbitsize;
  1098. val:=(val-1)+val;
  1099. if def.high<>val then
  1100. exit;
  1101. end;
  1102. result:=true;
  1103. end;
  1104. var
  1105. lv, hv, typcount: tconstexprint;
  1106. begin
  1107. { Check label type coverage for enumerations and small types }
  1108. getrange(left.resultdef,lv,hv);
  1109. typcount:=hv-lv;
  1110. if not assigned(elseblock) then
  1111. begin
  1112. { unless cs_check_all_case_coverage is set, only check for enums, booleans and
  1113. subrange types different from the default ones }
  1114. if (cs_check_all_case_coverage in current_settings.localswitches) or
  1115. (is_enum(left.resultdef) or
  1116. is_boolean(left.resultdef) or
  1117. not orddefspansfullrange(torddef(left.resultdef))) and
  1118. (labelcoverage<typcount) then
  1119. begin
  1120. { labels for some values of the operand are missing, and no else block is present }
  1121. cgmessage(cg_w_case_incomplete);
  1122. { in Standard/Extended Pascal, this is a dynamic violation error if it actually happens }
  1123. if ([m_extpas,m_iso]*current_settings.modeswitches)<>[] then
  1124. begin
  1125. elseblock:=ccallnode.createintern('fpc_rangeerror',nil);
  1126. typecheckpass(elseblock);
  1127. end;
  1128. end
  1129. end
  1130. else if labelcoverage=typcount then
  1131. begin
  1132. { labels for all values of the operand are present, but an extra else block is present }
  1133. MessagePos(elseblock.fileinfo, cg_w_unreachable_code);
  1134. end;
  1135. end;
  1136. procedure tcasenode.addlabel(blockid:longint;const l,h : TConstExprInt);
  1137. var
  1138. hcaselabel : pcaselabel;
  1139. function insertlabel(var p : pcaselabel):pcaselabel;
  1140. begin
  1141. if p=nil then
  1142. begin
  1143. p:=hcaselabel;
  1144. result:=p;
  1145. end
  1146. else
  1147. if (p^._low>hcaselabel^._low) and
  1148. (p^._low>hcaselabel^._high) then
  1149. begin
  1150. if (hcaselabel^.blockid = p^.blockid) and
  1151. (p^._low = hcaselabel^._high + 1) then
  1152. begin
  1153. p^._low := hcaselabel^._low;
  1154. dispose(hcaselabel);
  1155. result:=p;
  1156. end
  1157. else
  1158. result:=insertlabel(p^.less)
  1159. end
  1160. else
  1161. if (p^._high<hcaselabel^._low) and
  1162. (p^._high<hcaselabel^._high) then
  1163. begin
  1164. if (hcaselabel^.blockid = p^.blockid) and
  1165. (p^._high+1 = hcaselabel^._low) then
  1166. begin
  1167. p^._high := hcaselabel^._high;
  1168. dispose(hcaselabel);
  1169. result:=p;
  1170. end
  1171. else
  1172. result:=insertlabel(p^.greater);
  1173. end
  1174. else
  1175. begin
  1176. dispose(hcaselabel);
  1177. Message(parser_e_double_caselabel);
  1178. result:=nil;
  1179. end
  1180. end;
  1181. begin
  1182. new(hcaselabel);
  1183. fillchar(hcaselabel^,sizeof(tcaselabel),0);
  1184. hcaselabel^.blockid:=blockid;
  1185. hcaselabel^.label_type:=ltOrdinal;
  1186. hcaselabel^._low:=l;
  1187. hcaselabel^._high:=h;
  1188. insertlabel(flabels);
  1189. fcountsuptodate:=false;
  1190. end;
  1191. procedure tcasenode.addlabel(blockid: longint; l, h: tstringconstnode);
  1192. var
  1193. hcaselabel : pcaselabel;
  1194. function insertlabel(var p : pcaselabel) : pcaselabel;
  1195. begin
  1196. if not assigned(p) then
  1197. begin
  1198. p := hcaselabel;
  1199. result := p;
  1200. end
  1201. else
  1202. if (p^._low_str.fullcompare(hcaselabel^._high_str) > 0) then
  1203. result := insertlabel(p^.less)
  1204. else
  1205. if (p^._high_str.fullcompare(hcaselabel^._low_str) < 0) then
  1206. result := insertlabel(p^.greater)
  1207. else
  1208. begin
  1209. hcaselabel^._low_str.free;
  1210. hcaselabel^._high_str.free;
  1211. dispose(hcaselabel);
  1212. Message(parser_e_double_caselabel);
  1213. result:=nil;
  1214. end;
  1215. end;
  1216. begin
  1217. new(hcaselabel);
  1218. fillchar(hcaselabel^, sizeof(tcaselabel), 0);
  1219. hcaselabel^.blockid := blockid;
  1220. hcaselabel^.label_type := ltConstString;
  1221. hcaselabel^._low_str := tstringconstnode(l.getcopy);
  1222. hcaselabel^._high_str := tstringconstnode(h.getcopy);
  1223. insertlabel(flabels);
  1224. end;
  1225. end.