ncon.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Florian Klaempfl
  4. Type checking and register allocation for constants
  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 ncon;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,widestr,
  23. node,
  24. aasmbase,aasmtai,cpuinfo,globals,
  25. symconst,symtype,symdef,symsym;
  26. type
  27. trealconstnode = class(tnode)
  28. restype : ttype;
  29. value_real : bestreal;
  30. lab_real : tasmlabel;
  31. constructor create(v : bestreal;const t:ttype);virtual;
  32. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  33. procedure ppuwrite(ppufile:tcompilerppufile);override;
  34. procedure buildderefimpl;override;
  35. procedure derefimpl;override;
  36. function getcopy : tnode;override;
  37. function pass_1 : tnode;override;
  38. function det_resulttype:tnode;override;
  39. function docompare(p: tnode) : boolean; override;
  40. procedure printnodedata(var t:text);override;
  41. end;
  42. trealconstnodeclass = class of trealconstnode;
  43. tordconstnode = class(tnode)
  44. restype : ttype;
  45. value : TConstExprInt;
  46. rangecheck : boolean;
  47. { create an ordinal constant node of the specified type and value.
  48. _rangecheck determines if the value of the ordinal should be checked
  49. against the ranges of the type definition.
  50. }
  51. constructor create(v : tconstexprint;const t:ttype; _rangecheck : boolean);virtual;
  52. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  53. procedure ppuwrite(ppufile:tcompilerppufile);override;
  54. procedure buildderefimpl;override;
  55. procedure derefimpl;override;
  56. function getcopy : tnode;override;
  57. function pass_1 : tnode;override;
  58. function det_resulttype:tnode;override;
  59. function docompare(p: tnode) : boolean; override;
  60. procedure printnodedata(var t:text);override;
  61. end;
  62. tordconstnodeclass = class of tordconstnode;
  63. tpointerconstnode = class(tnode)
  64. restype : ttype;
  65. value : TConstPtrUInt;
  66. constructor create(v : TConstPtrUInt;const t:ttype);virtual;
  67. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  68. procedure ppuwrite(ppufile:tcompilerppufile);override;
  69. procedure buildderefimpl;override;
  70. procedure derefimpl;override;
  71. function getcopy : tnode;override;
  72. function pass_1 : tnode;override;
  73. function det_resulttype:tnode;override;
  74. function docompare(p: tnode) : boolean; override;
  75. end;
  76. tpointerconstnodeclass = class of tpointerconstnode;
  77. tstringconstnode = class(tnode)
  78. value_str : pchar;
  79. len : longint;
  80. lab_str : tasmlabel;
  81. st_type : tstringtype;
  82. constructor createstr(const s : string;st:tstringtype);virtual;
  83. constructor createpchar(s : pchar;l : longint);virtual;
  84. constructor createwstr(w : pcompilerwidestring);virtual;
  85. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  86. procedure ppuwrite(ppufile:tcompilerppufile);override;
  87. procedure buildderefimpl;override;
  88. procedure derefimpl;override;
  89. destructor destroy;override;
  90. function getcopy : tnode;override;
  91. function pass_1 : tnode;override;
  92. function det_resulttype:tnode;override;
  93. function getpcharcopy : pchar;
  94. function docompare(p: tnode) : boolean; override;
  95. end;
  96. tstringconstnodeclass = class of tstringconstnode;
  97. tsetconstnode = class(tunarynode)
  98. restype : ttype;
  99. value_set : pconstset;
  100. lab_set : tasmlabel;
  101. constructor create(s : pconstset;const t:ttype);virtual;
  102. destructor destroy;override;
  103. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  104. procedure ppuwrite(ppufile:tcompilerppufile);override;
  105. procedure buildderefimpl;override;
  106. procedure derefimpl;override;
  107. function getcopy : tnode;override;
  108. function pass_1 : tnode;override;
  109. function det_resulttype:tnode;override;
  110. function docompare(p: tnode) : boolean; override;
  111. end;
  112. tsetconstnodeclass = class of tsetconstnode;
  113. tnilnode = class(tnode)
  114. constructor create;virtual;
  115. function pass_1 : tnode;override;
  116. function det_resulttype:tnode;override;
  117. end;
  118. tnilnodeclass = class of tnilnode;
  119. tguidconstnode = class(tnode)
  120. value : tguid;
  121. constructor create(const g:tguid);virtual;
  122. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  123. procedure ppuwrite(ppufile:tcompilerppufile);override;
  124. function getcopy : tnode;override;
  125. function pass_1 : tnode;override;
  126. function det_resulttype:tnode;override;
  127. function docompare(p: tnode) : boolean; override;
  128. end;
  129. tguidconstnodeclass = class of tguidconstnode;
  130. var
  131. crealconstnode : trealconstnodeclass;
  132. cordconstnode : tordconstnodeclass;
  133. cpointerconstnode : tpointerconstnodeclass;
  134. cstringconstnode : tstringconstnodeclass;
  135. csetconstnode : tsetconstnodeclass;
  136. cguidconstnode : tguidconstnodeclass;
  137. cnilnode : tnilnodeclass;
  138. function genintconstnode(v : TConstExprInt) : tordconstnode;
  139. function genenumnode(v : tenumsym) : tordconstnode;
  140. { some helper routines }
  141. {$ifdef INT64FUNCRESOK}
  142. function get_ordinal_value(p : tnode) : TConstExprInt;
  143. {$else INT64FUNCRESOK}
  144. function get_ordinal_value(p : tnode) : longint;
  145. {$endif INT64FUNCRESOK}
  146. function is_constresourcestringnode(p : tnode) : boolean;
  147. function str_length(p : tnode) : longint;
  148. function is_emptyset(p : tnode):boolean;
  149. function genconstsymtree(p : tconstsym) : tnode;
  150. implementation
  151. uses
  152. cutils,
  153. verbose,systems,
  154. defutil,
  155. cpubase,cgbase,
  156. nld;
  157. function genintconstnode(v : TConstExprInt) : tordconstnode;
  158. var
  159. htype : ttype;
  160. begin
  161. int_to_type(v,htype);
  162. genintconstnode:=cordconstnode.create(v,htype,true);
  163. end;
  164. function genenumnode(v : tenumsym) : tordconstnode;
  165. var
  166. htype : ttype;
  167. begin
  168. htype.setdef(v.definition);
  169. genenumnode:=cordconstnode.create(v.value,htype,true);
  170. end;
  171. {$ifdef INT64FUNCRESOK}
  172. function get_ordinal_value(p : tnode) : TConstExprInt;
  173. {$else INT64FUNCRESOK}
  174. function get_ordinal_value(p : tnode) : longint;
  175. {$endif INT64FUNCRESOK}
  176. begin
  177. get_ordinal_value:=0;
  178. if is_constnode(p) then
  179. begin
  180. if p.nodetype=ordconstn then
  181. get_ordinal_value:=tordconstnode(p).value
  182. else
  183. Message(type_e_ordinal_expr_expected);
  184. end
  185. else
  186. Message(type_e_constant_expr_expected);
  187. end;
  188. function is_constresourcestringnode(p : tnode) : boolean;
  189. begin
  190. is_constresourcestringnode:=(p.nodetype=loadn) and
  191. (tloadnode(p).symtableentry.typ=constsym) and
  192. (tconstsym(tloadnode(p).symtableentry).consttyp=constresourcestring);
  193. end;
  194. function str_length(p : tnode) : longint;
  195. begin
  196. str_length:=tstringconstnode(p).len;
  197. end;
  198. function is_emptyset(p : tnode):boolean;
  199. begin
  200. is_emptyset:=(p.nodetype=setconstn) and
  201. (Tsetconstnode(p).value_set^=[]);
  202. end;
  203. function genconstsymtree(p : tconstsym) : tnode;
  204. var
  205. p1 : tnode;
  206. len : longint;
  207. pc : pchar;
  208. begin
  209. p1:=nil;
  210. case p.consttyp of
  211. constord :
  212. p1:=cordconstnode.create(p.value.valueord,p.consttype,true);
  213. conststring :
  214. begin
  215. len:=p.value.len;
  216. if not(cs_ansistrings in aktlocalswitches) and (len>255) then
  217. len:=255;
  218. getmem(pc,len+1);
  219. move(pchar(p.value.valueptr)^,pc^,len);
  220. pc[len]:=#0;
  221. p1:=cstringconstnode.createpchar(pc,len);
  222. end;
  223. constreal :
  224. p1:=crealconstnode.create(pbestreal(p.value.valueptr)^,pbestrealtype^);
  225. constset :
  226. p1:=csetconstnode.create(pconstset(p.value.valueptr),p.consttype);
  227. constpointer :
  228. p1:=cpointerconstnode.create(p.value.valueordptr,p.consttype);
  229. constnil :
  230. p1:=cnilnode.create;
  231. else
  232. internalerror(200205103);
  233. end;
  234. genconstsymtree:=p1;
  235. end;
  236. {*****************************************************************************
  237. TREALCONSTNODE
  238. *****************************************************************************}
  239. { generic code }
  240. { overridden by: }
  241. { i386 }
  242. constructor trealconstnode.create(v : bestreal;const t:ttype);
  243. begin
  244. inherited create(realconstn);
  245. restype:=t;
  246. value_real:=v;
  247. lab_real:=nil;
  248. end;
  249. constructor trealconstnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  250. begin
  251. inherited ppuload(t,ppufile);
  252. ppufile.gettype(restype);
  253. value_real:=ppufile.getreal;
  254. lab_real:=tasmlabel(ppufile.getasmsymbol);
  255. end;
  256. procedure trealconstnode.ppuwrite(ppufile:tcompilerppufile);
  257. begin
  258. inherited ppuwrite(ppufile);
  259. ppufile.puttype(restype);
  260. ppufile.putreal(value_real);
  261. ppufile.putasmsymbol(lab_real);
  262. end;
  263. procedure trealconstnode.buildderefimpl;
  264. begin
  265. inherited buildderefimpl;
  266. restype.buildderef;
  267. end;
  268. procedure trealconstnode.derefimpl;
  269. begin
  270. inherited derefimpl;
  271. restype.resolve;
  272. objectlibrary.derefasmsymbol(tasmsymbol(lab_real));
  273. end;
  274. function trealconstnode.getcopy : tnode;
  275. var
  276. n : trealconstnode;
  277. begin
  278. n:=trealconstnode(inherited getcopy);
  279. n.value_real:=value_real;
  280. n.lab_real:=lab_real;
  281. getcopy:=n;
  282. end;
  283. function trealconstnode.det_resulttype:tnode;
  284. begin
  285. result:=nil;
  286. resulttype:=restype;
  287. end;
  288. function trealconstnode.pass_1 : tnode;
  289. begin
  290. result:=nil;
  291. expectloc:=LOC_CREFERENCE;
  292. { needs to be loaded into an FPU register }
  293. registersfpu:=1;
  294. end;
  295. function trealconstnode.docompare(p: tnode): boolean;
  296. begin
  297. docompare :=
  298. inherited docompare(p) and
  299. (value_real = trealconstnode(p).value_real) and
  300. { floating point compares for non-numbers give strange results usually }
  301. is_number_float(value_real) and
  302. is_number_float(trealconstnode(p).value_real);
  303. end;
  304. procedure Trealconstnode.printnodedata(var t:text);
  305. begin
  306. inherited printnodedata(t);
  307. writeln(t,printnodeindention,'value = ',value_real);
  308. end;
  309. {*****************************************************************************
  310. TORDCONSTNODE
  311. *****************************************************************************}
  312. constructor tordconstnode.create(v : tconstexprint;const t:ttype;_rangecheck : boolean);
  313. begin
  314. inherited create(ordconstn);
  315. value:=v;
  316. restype:=t;
  317. rangecheck := _rangecheck;
  318. end;
  319. constructor tordconstnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  320. begin
  321. inherited ppuload(t,ppufile);
  322. ppufile.gettype(restype);
  323. value:=ppufile.getexprint;
  324. { normally, the value is already compiled, so we don't need
  325. to do once again a range check
  326. }
  327. rangecheck := false;
  328. end;
  329. procedure tordconstnode.ppuwrite(ppufile:tcompilerppufile);
  330. begin
  331. inherited ppuwrite(ppufile);
  332. ppufile.puttype(restype);
  333. ppufile.putexprint(value);
  334. end;
  335. procedure tordconstnode.buildderefimpl;
  336. begin
  337. inherited buildderefimpl;
  338. restype.buildderef;
  339. end;
  340. procedure tordconstnode.derefimpl;
  341. begin
  342. inherited derefimpl;
  343. restype.resolve;
  344. end;
  345. function tordconstnode.getcopy : tnode;
  346. var
  347. n : tordconstnode;
  348. begin
  349. n:=tordconstnode(inherited getcopy);
  350. n.value:=value;
  351. n.restype := restype;
  352. getcopy:=n;
  353. end;
  354. function tordconstnode.det_resulttype:tnode;
  355. begin
  356. result:=nil;
  357. resulttype:=restype;
  358. { only do range checking when explicitly asked for it }
  359. if rangecheck then
  360. testrange(resulttype.def,value,false);
  361. end;
  362. function tordconstnode.pass_1 : tnode;
  363. begin
  364. result:=nil;
  365. expectloc:=LOC_CONSTANT;
  366. end;
  367. function tordconstnode.docompare(p: tnode): boolean;
  368. begin
  369. docompare :=
  370. inherited docompare(p) and
  371. (value = tordconstnode(p).value);
  372. end;
  373. procedure Tordconstnode.printnodedata(var t:text);
  374. begin
  375. inherited printnodedata(t);
  376. writeln(t,printnodeindention,'value = ',value);
  377. end;
  378. {*****************************************************************************
  379. TPOINTERCONSTNODE
  380. *****************************************************************************}
  381. constructor tpointerconstnode.create(v : TConstPtrUInt;const t:ttype);
  382. begin
  383. inherited create(pointerconstn);
  384. value:=v;
  385. restype:=t;
  386. end;
  387. constructor tpointerconstnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  388. begin
  389. inherited ppuload(t,ppufile);
  390. ppufile.gettype(restype);
  391. value:=ppufile.getptruint;
  392. end;
  393. procedure tpointerconstnode.ppuwrite(ppufile:tcompilerppufile);
  394. begin
  395. inherited ppuwrite(ppufile);
  396. ppufile.puttype(restype);
  397. ppufile.putptruint(value);
  398. end;
  399. procedure tpointerconstnode.buildderefimpl;
  400. begin
  401. inherited buildderefimpl;
  402. restype.buildderef;
  403. end;
  404. procedure tpointerconstnode.derefimpl;
  405. begin
  406. inherited derefimpl;
  407. restype.resolve;
  408. end;
  409. function tpointerconstnode.getcopy : tnode;
  410. var
  411. n : tpointerconstnode;
  412. begin
  413. n:=tpointerconstnode(inherited getcopy);
  414. n.value:=value;
  415. n.restype := restype;
  416. getcopy:=n;
  417. end;
  418. function tpointerconstnode.det_resulttype:tnode;
  419. begin
  420. result:=nil;
  421. resulttype:=restype;
  422. end;
  423. function tpointerconstnode.pass_1 : tnode;
  424. begin
  425. result:=nil;
  426. expectloc:=LOC_CONSTANT;
  427. end;
  428. function tpointerconstnode.docompare(p: tnode): boolean;
  429. begin
  430. docompare :=
  431. inherited docompare(p) and
  432. (value = tpointerconstnode(p).value);
  433. end;
  434. {*****************************************************************************
  435. TSTRINGCONSTNODE
  436. *****************************************************************************}
  437. constructor tstringconstnode.createstr(const s : string;st:tstringtype);
  438. var
  439. l : longint;
  440. begin
  441. inherited create(stringconstn);
  442. l:=length(s);
  443. len:=l;
  444. { stringdup write even past a #0 }
  445. getmem(value_str,l+1);
  446. move(s[1],value_str^,l);
  447. value_str[l]:=#0;
  448. lab_str:=nil;
  449. if st=st_default then
  450. begin
  451. if cs_ansistrings in aktlocalswitches then
  452. {$ifdef ansistring_bits}
  453. case aktansistring_bits of
  454. sb_16:
  455. st_type:=st_ansistring16;
  456. sb_32:
  457. st_type:=st_ansistring32;
  458. sb_64:
  459. st_type:=st_ansistring64;
  460. end
  461. {$else}
  462. st_type:=st_ansistring
  463. {$endif}
  464. else
  465. st_type:=st_shortstring;
  466. end
  467. else
  468. st_type:=st;
  469. end;
  470. constructor tstringconstnode.createwstr(w : pcompilerwidestring);
  471. begin
  472. inherited create(stringconstn);
  473. len:=getlengthwidestring(w);
  474. initwidestring(pcompilerwidestring(value_str));
  475. copywidestring(w,pcompilerwidestring(value_str));
  476. lab_str:=nil;
  477. st_type:=st_widestring;
  478. end;
  479. constructor tstringconstnode.createpchar(s : pchar;l : longint);
  480. begin
  481. inherited create(stringconstn);
  482. len:=l;
  483. value_str:=s;
  484. if (cs_ansistrings in aktlocalswitches) or
  485. (len>255) then
  486. {$ifdef ansistring_bits}
  487. case aktansistring_bits of
  488. sb_16:
  489. st_type:=st_ansistring16;
  490. sb_32:
  491. st_type:=st_ansistring32;
  492. sb_64:
  493. st_type:=st_ansistring64;
  494. end
  495. {$else}
  496. st_type:=st_ansistring
  497. {$endif}
  498. else
  499. st_type:=st_shortstring;
  500. lab_str:=nil;
  501. end;
  502. destructor tstringconstnode.destroy;
  503. begin
  504. if st_type=st_widestring then
  505. donewidestring(pcompilerwidestring(value_str))
  506. else
  507. ansistringdispose(value_str,len);
  508. inherited destroy;
  509. end;
  510. constructor tstringconstnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  511. begin
  512. inherited ppuload(t,ppufile);
  513. st_type:=tstringtype(ppufile.getbyte);
  514. len:=ppufile.getlongint;
  515. getmem(value_str,len+1);
  516. ppufile.getdata(value_str^,len);
  517. value_str[len]:=#0;
  518. lab_str:=tasmlabel(ppufile.getasmsymbol);
  519. end;
  520. procedure tstringconstnode.ppuwrite(ppufile:tcompilerppufile);
  521. begin
  522. inherited ppuwrite(ppufile);
  523. ppufile.putbyte(byte(st_type));
  524. ppufile.putlongint(len);
  525. ppufile.putdata(value_str^,len);
  526. ppufile.putasmsymbol(lab_str);
  527. end;
  528. procedure tstringconstnode.buildderefimpl;
  529. begin
  530. inherited buildderefimpl;
  531. end;
  532. procedure tstringconstnode.derefimpl;
  533. begin
  534. inherited derefimpl;
  535. objectlibrary.derefasmsymbol(tasmsymbol(lab_str));
  536. end;
  537. function tstringconstnode.getcopy : tnode;
  538. var
  539. n : tstringconstnode;
  540. begin
  541. n:=tstringconstnode(inherited getcopy);
  542. n.st_type:=st_type;
  543. n.len:=len;
  544. n.lab_str:=lab_str;
  545. if st_type=st_widestring then
  546. begin
  547. initwidestring(pcompilerwidestring(n.value_str));
  548. copywidestring(pcompilerwidestring(value_str),pcompilerwidestring(n.value_str));
  549. end
  550. else
  551. n.value_str:=getpcharcopy;
  552. getcopy:=n;
  553. end;
  554. function tstringconstnode.det_resulttype:tnode;
  555. begin
  556. result:=nil;
  557. case st_type of
  558. st_shortstring :
  559. resulttype:=cshortstringtype;
  560. {$ifdef ansistring_bits}
  561. st_ansistring16:
  562. resulttype:=cansistringtype16;
  563. st_ansistring32:
  564. resulttype:=cansistringtype32;
  565. st_ansistring64:
  566. resulttype:=cansistringtype64;
  567. {$else}
  568. st_ansistring :
  569. resulttype:=cansistringtype;
  570. {$endif}
  571. st_widestring :
  572. resulttype:=cwidestringtype;
  573. st_longstring :
  574. resulttype:=clongstringtype;
  575. end;
  576. end;
  577. function tstringconstnode.pass_1 : tnode;
  578. begin
  579. result:=nil;
  580. {$ifdef ansistring_bits}
  581. if (st_type in [st_ansistring16,st_ansistring32,st_ansistring64,st_widestring]) and
  582. {$else}
  583. if (st_type in [st_ansistring,st_widestring]) and
  584. {$endif}
  585. (len=0) then
  586. expectloc:=LOC_CONSTANT
  587. else
  588. expectloc:=LOC_CREFERENCE;
  589. end;
  590. function tstringconstnode.getpcharcopy : pchar;
  591. var
  592. pc : pchar;
  593. begin
  594. pc:=nil;
  595. getmem(pc,len+1);
  596. if pc=nil then
  597. Message(general_f_no_memory_left);
  598. move(value_str^,pc^,len+1);
  599. getpcharcopy:=pc;
  600. end;
  601. function tstringconstnode.docompare(p: tnode): boolean;
  602. begin
  603. docompare :=
  604. inherited docompare(p) and
  605. (len = tstringconstnode(p).len) and
  606. { Don't compare the pchars, since they may contain null chars }
  607. { Since all equal constant strings are replaced by the same }
  608. { label, the following compare should be enough (JM) }
  609. (lab_str = tstringconstnode(p).lab_str);
  610. end;
  611. {*****************************************************************************
  612. TSETCONSTNODE
  613. *****************************************************************************}
  614. constructor tsetconstnode.create(s : pconstset;const t:ttype);
  615. begin
  616. inherited create(setconstn,nil);
  617. restype:=t;
  618. if assigned(s) then
  619. begin
  620. new(value_set);
  621. value_set^:=s^;
  622. end
  623. else
  624. value_set:=nil;
  625. end;
  626. destructor tsetconstnode.destroy;
  627. begin
  628. if assigned(value_set) then
  629. dispose(value_set);
  630. inherited destroy;
  631. end;
  632. constructor tsetconstnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  633. begin
  634. inherited ppuload(t,ppufile);
  635. ppufile.gettype(restype);
  636. new(value_set);
  637. ppufile.getdata(value_set^,sizeof(tconstset));
  638. end;
  639. procedure tsetconstnode.ppuwrite(ppufile:tcompilerppufile);
  640. begin
  641. inherited ppuwrite(ppufile);
  642. ppufile.puttype(restype);
  643. ppufile.putdata(value_set^,sizeof(tconstset));
  644. end;
  645. procedure tsetconstnode.buildderefimpl;
  646. begin
  647. inherited buildderefimpl;
  648. restype.buildderef;
  649. end;
  650. procedure tsetconstnode.derefimpl;
  651. begin
  652. inherited derefimpl;
  653. restype.resolve;
  654. end;
  655. function tsetconstnode.getcopy : tnode;
  656. var
  657. n : tsetconstnode;
  658. begin
  659. n:=tsetconstnode(inherited getcopy);
  660. if assigned(value_set) then
  661. begin
  662. new(n.value_set);
  663. n.value_set^:=value_set^
  664. end
  665. else
  666. n.value_set:=nil;
  667. n.restype := restype;
  668. n.lab_set:=lab_set;
  669. getcopy:=n;
  670. end;
  671. function tsetconstnode.det_resulttype:tnode;
  672. begin
  673. result:=nil;
  674. resulttype:=restype;
  675. end;
  676. function tsetconstnode.pass_1 : tnode;
  677. begin
  678. result:=nil;
  679. if tsetdef(resulttype.def).settype=smallset then
  680. expectloc:=LOC_CONSTANT
  681. else
  682. expectloc:=LOC_CREFERENCE;
  683. end;
  684. function tsetconstnode.docompare(p: tnode): boolean;
  685. begin
  686. docompare:=(inherited docompare(p)) and
  687. (value_set^=Tsetconstnode(p).value_set^);
  688. end;
  689. {*****************************************************************************
  690. TNILNODE
  691. *****************************************************************************}
  692. constructor tnilnode.create;
  693. begin
  694. inherited create(niln);
  695. end;
  696. function tnilnode.det_resulttype:tnode;
  697. begin
  698. result:=nil;
  699. resulttype:=voidpointertype;
  700. end;
  701. function tnilnode.pass_1 : tnode;
  702. begin
  703. result:=nil;
  704. expectloc:=LOC_CONSTANT;
  705. end;
  706. {*****************************************************************************
  707. TGUIDCONSTNODE
  708. *****************************************************************************}
  709. constructor tguidconstnode.create(const g:tguid);
  710. begin
  711. inherited create(guidconstn);
  712. value:=g;
  713. end;
  714. constructor tguidconstnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  715. begin
  716. inherited ppuload(t,ppufile);
  717. ppufile.getguid(value);
  718. end;
  719. procedure tguidconstnode.ppuwrite(ppufile:tcompilerppufile);
  720. begin
  721. inherited ppuwrite(ppufile);
  722. ppufile.putguid(value);
  723. end;
  724. function tguidconstnode.getcopy : tnode;
  725. var
  726. n : tguidconstnode;
  727. begin
  728. n:=tguidconstnode(inherited getcopy);
  729. n.value:=value;
  730. getcopy:=n;
  731. end;
  732. function tguidconstnode.det_resulttype:tnode;
  733. begin
  734. result:=nil;
  735. resulttype.setdef(rec_tguid);
  736. end;
  737. function tguidconstnode.pass_1 : tnode;
  738. begin
  739. result:=nil;
  740. expectloc:=LOC_CREFERENCE;
  741. end;
  742. function tguidconstnode.docompare(p: tnode): boolean;
  743. begin
  744. docompare :=
  745. inherited docompare(p) and
  746. (guid2string(value) = guid2string(tguidconstnode(p).value));
  747. end;
  748. begin
  749. crealconstnode:=trealconstnode;
  750. cordconstnode:=tordconstnode;
  751. cpointerconstnode:=tpointerconstnode;
  752. cstringconstnode:=tstringconstnode;
  753. csetconstnode:=tsetconstnode;
  754. cnilnode:=tnilnode;
  755. cguidconstnode:=tguidconstnode;
  756. end.
  757. {
  758. $Log$
  759. Revision 1.64 2004-06-20 08:55:29 florian
  760. * logs truncated
  761. Revision 1.63 2004/06/16 20:07:08 florian
  762. * dwarf branch merged
  763. Revision 1.62 2004/05/24 20:39:41 florian
  764. * stricter handling of formal const parameters and IE fixed
  765. Revision 1.61 2004/04/29 19:56:37 daniel
  766. * Prepare compiler infrastructure for multiple ansistring types
  767. Revision 1.60.2.2 2004/05/30 10:45:50 peter
  768. * merged fixes from main branch
  769. Revision 1.62 2004/05/24 20:39:41 florian
  770. * stricter handling of formal const parameters and IE fixed
  771. }