nld.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. {
  2. $Id$
  3. Copyright (c) 2000 by Florian Klaempfl
  4. Type checking and register allocation for load/assignment nodes
  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 nld;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node,
  23. symbase,symtype,symsym;
  24. type
  25. tloadnode = class(tunarynode)
  26. symtableentry : tsym;
  27. symtable : tsymtable;
  28. constructor create(v : tsym;st : tsymtable);virtual;
  29. procedure set_mp(p:tnode);
  30. function getcopy : tnode;override;
  31. function pass_1 : tnode;override;
  32. function det_resulttype:tnode;override;
  33. function docompare(p: tnode): boolean; override;
  34. end;
  35. { different assignment types }
  36. tassigntype = (at_normal,at_plus,at_minus,at_star,at_slash);
  37. tassignmentnode = class(tbinarynode)
  38. assigntype : tassigntype;
  39. constructor create(l,r : tnode);virtual;
  40. function getcopy : tnode;override;
  41. function pass_1 : tnode;override;
  42. function det_resulttype:tnode;override;
  43. function docompare(p: tnode): boolean; override;
  44. end;
  45. tfuncretnode = class(tnode)
  46. funcretsym : tfuncretsym;
  47. constructor create(v:tsym);virtual;
  48. function getcopy : tnode;override;
  49. function pass_1 : tnode;override;
  50. function det_resulttype:tnode;override;
  51. function docompare(p: tnode): boolean; override;
  52. end;
  53. tarrayconstructorrangenode = class(tbinarynode)
  54. constructor create(l,r : tnode);virtual;
  55. function pass_1 : tnode;override;
  56. function det_resulttype:tnode;override;
  57. end;
  58. tarrayconstructornode = class(tbinarynode)
  59. constructor create(l,r : tnode);virtual;
  60. function getcopy : tnode;override;
  61. function pass_1 : tnode;override;
  62. function det_resulttype:tnode;override;
  63. function docompare(p: tnode): boolean; override;
  64. procedure force_type(tt:ttype);
  65. end;
  66. ttypenode = class(tnode)
  67. allowed : boolean;
  68. restype : ttype;
  69. constructor create(t : ttype);virtual;
  70. function pass_1 : tnode;override;
  71. function det_resulttype:tnode;override;
  72. function docompare(p: tnode): boolean; override;
  73. end;
  74. var
  75. cloadnode : class of tloadnode;
  76. cassignmentnode : class of tassignmentnode;
  77. cfuncretnode : class of tfuncretnode;
  78. carrayconstructorrangenode : class of tarrayconstructorrangenode;
  79. carrayconstructornode : class of tarrayconstructornode;
  80. ctypenode : class of ttypenode;
  81. implementation
  82. uses
  83. cutils,verbose,globtype,globals,systems,
  84. symconst,symdef,symtable,types,
  85. htypechk,pass_1,
  86. ncnv,nmem,cpubase,tgcpu,cgbase
  87. ;
  88. {*****************************************************************************
  89. TLOADNODE
  90. *****************************************************************************}
  91. constructor tloadnode.create(v : tsym;st : tsymtable);
  92. begin
  93. inherited create(loadn,nil);
  94. if not assigned(v) then
  95. internalerror(200108121);
  96. symtableentry:=v;
  97. symtable:=st;
  98. end;
  99. procedure tloadnode.set_mp(p:tnode);
  100. begin
  101. left:=p;
  102. end;
  103. function tloadnode.getcopy : tnode;
  104. var
  105. n : tloadnode;
  106. begin
  107. n:=tloadnode(inherited getcopy);
  108. n.symtable:=symtable;
  109. n.symtableentry:=symtableentry;
  110. result:=n;
  111. end;
  112. function tloadnode.det_resulttype:tnode;
  113. var
  114. p1 : tnode;
  115. p : pprocinfo;
  116. begin
  117. result:=nil;
  118. { optimize simple with loadings }
  119. if (symtable.symtabletype=withsymtable) and
  120. (twithsymtable(symtable).direct_with) and
  121. (symtableentry.typ=varsym) then
  122. begin
  123. p1:=tnode(twithsymtable(symtable).withrefnode).getcopy;
  124. p1:=csubscriptnode.create(tvarsym(symtableentry),p1);
  125. left:=nil;
  126. resulttypepass(p1);
  127. result:=p1;
  128. exit;
  129. end;
  130. { handle first absolute as it will replace the symtableentry }
  131. if symtableentry.typ=absolutesym then
  132. begin
  133. { force the resulttype to the type of the absolute }
  134. resulttype:=tabsolutesym(symtableentry).vartype;
  135. { replace the symtableentry when it points to a var, else
  136. we are finished }
  137. if tabsolutesym(symtableentry).abstyp=tovar then
  138. begin
  139. symtableentry:=tabsolutesym(symtableentry).ref;
  140. symtable:=symtableentry.owner;
  141. include(flags,nf_absolute);
  142. end
  143. else
  144. exit;
  145. end;
  146. case symtableentry.typ of
  147. funcretsym :
  148. begin
  149. { find the main funcret for the function }
  150. p:=procinfo;
  151. while assigned(p) do
  152. begin
  153. if assigned(p^.procdef.funcretsym) and
  154. ((tfuncretsym(symtableentry)=p^.procdef.resultfuncretsym) or
  155. (tfuncretsym(symtableentry)=p^.procdef.funcretsym)) then
  156. begin
  157. symtableentry:=p^.procdef.funcretsym;
  158. break;
  159. end;
  160. p:=p^.parent;
  161. end;
  162. { generate funcretnode }
  163. p1:=cfuncretnode.create(symtableentry);
  164. resulttypepass(p1);
  165. { if it's refered as absolute then we need to have the
  166. type of the absolute instead of the function return,
  167. the function return is then also assigned }
  168. if nf_absolute in flags then
  169. begin
  170. tfuncretsym(symtableentry).funcretstate:=vs_assigned;
  171. p1.resulttype:=resulttype;
  172. end;
  173. left:=nil;
  174. result:=p1;
  175. end;
  176. constsym:
  177. begin
  178. if tconstsym(symtableentry).consttyp=constresourcestring then
  179. resulttype:=cansistringtype
  180. else
  181. internalerror(22799);
  182. end;
  183. varsym :
  184. begin
  185. { if it's refered by absolute then it's used }
  186. if nf_absolute in flags then
  187. tvarsym(symtableentry).varstate:=vs_used
  188. else
  189. resulttype:=tvarsym(symtableentry).vartype;
  190. end;
  191. typedconstsym :
  192. if not(nf_absolute in flags) then
  193. resulttype:=ttypedconstsym(symtableentry).typedconsttype;
  194. procsym :
  195. begin
  196. if assigned(tprocsym(symtableentry).definition.nextoverloaded) then
  197. CGMessage(parser_e_no_overloaded_procvars);
  198. resulttype.setdef(tprocsym(symtableentry).definition);
  199. { if the owner of the procsym is a object, }
  200. { left must be set, if left isn't set }
  201. { it can be only self }
  202. { this code is only used in TP procvar mode }
  203. if (m_tp_procvar in aktmodeswitches) and
  204. not(assigned(left)) and
  205. (tprocsym(symtableentry).owner.symtabletype=objectsymtable) then
  206. begin
  207. left:=cselfnode.create(tobjectdef(symtableentry.owner.defowner));
  208. end;
  209. { process methodpointer }
  210. if assigned(left) then
  211. begin
  212. { if only typenode then remove }
  213. if left.nodetype=typen then
  214. begin
  215. left.free;
  216. left:=nil;
  217. end
  218. else
  219. resulttypepass(left);
  220. end;
  221. end;
  222. else
  223. internalerror(200104141);
  224. end;
  225. end;
  226. function tloadnode.pass_1 : tnode;
  227. begin
  228. result:=nil;
  229. location.loc:=LOC_REFERENCE;
  230. registers32:=0;
  231. registersfpu:=0;
  232. {$ifdef SUPPORT_MMX}
  233. registersmmx:=0;
  234. {$endif SUPPORT_MMX}
  235. case symtableentry.typ of
  236. absolutesym :
  237. ;
  238. funcretsym :
  239. internalerror(200104142);
  240. constsym:
  241. begin
  242. if tconstsym(symtableentry).consttyp=constresourcestring then
  243. begin
  244. { we use ansistrings so no fast exit here }
  245. if assigned(procinfo) then
  246. procinfo^.no_fast_exit:=true;
  247. location.loc:=LOC_MEM;
  248. end;
  249. end;
  250. varsym :
  251. begin
  252. if (symtable.symtabletype in [parasymtable,localsymtable]) and
  253. (lexlevel>symtable.symtablelevel) then
  254. begin
  255. { if the variable is in an other stackframe then we need
  256. a register to dereference }
  257. if (symtable.symtablelevel)>0 then
  258. begin
  259. registers32:=1;
  260. { further, the variable can't be put into a register }
  261. tvarsym(symtableentry).varoptions:=
  262. tvarsym(symtableentry).varoptions-[vo_fpuregable,vo_regable];
  263. end;
  264. end;
  265. if (tvarsym(symtableentry).varspez=vs_const) then
  266. location.loc:=LOC_MEM;
  267. { we need a register for call by reference parameters }
  268. if (tvarsym(symtableentry).varspez in [vs_var,vs_out]) or
  269. ((tvarsym(symtableentry).varspez=vs_const) and
  270. push_addr_param(tvarsym(symtableentry).vartype.def)) or
  271. { call by value open arrays are also indirect addressed }
  272. is_open_array(tvarsym(symtableentry).vartype.def) then
  273. registers32:=1;
  274. if symtable.symtabletype=withsymtable then
  275. inc(registers32);
  276. if ([vo_is_thread_var,vo_is_dll_var]*tvarsym(symtableentry).varoptions)<>[] then
  277. registers32:=1;
  278. { count variable references }
  279. { this will create problem with local var set by
  280. under_procedures
  281. if (assigned(tvarsym(symtableentry).owner) and assigned(aktprocsym)
  282. and ((tvarsym(symtableentry).owner = aktprocsym.definition.localst)
  283. or (tvarsym(symtableentry).owner = aktprocsym.definition.localst))) then }
  284. if t_times<1 then
  285. inc(tvarsym(symtableentry).refs)
  286. else
  287. inc(tvarsym(symtableentry).refs,t_times);
  288. end;
  289. typedconstsym :
  290. ;
  291. procsym :
  292. begin
  293. { method pointer ? }
  294. if assigned(left) then
  295. begin
  296. firstpass(left);
  297. registers32:=max(registers32,left.registers32);
  298. registersfpu:=max(registersfpu,left.registersfpu);
  299. {$ifdef SUPPORT_MMX}
  300. registersmmx:=max(registersmmx,left.registersmmx);
  301. {$endif SUPPORT_MMX}
  302. end;
  303. end;
  304. else
  305. internalerror(200104143);
  306. end;
  307. end;
  308. function tloadnode.docompare(p: tnode): boolean;
  309. begin
  310. docompare :=
  311. inherited docompare(p) and
  312. (symtableentry = tloadnode(p).symtableentry) and
  313. (symtable = tloadnode(p).symtable);
  314. end;
  315. {*****************************************************************************
  316. TASSIGNMENTNODE
  317. *****************************************************************************}
  318. constructor tassignmentnode.create(l,r : tnode);
  319. begin
  320. inherited create(assignn,l,r);
  321. assigntype:=at_normal;
  322. end;
  323. function tassignmentnode.getcopy : tnode;
  324. var
  325. n : tassignmentnode;
  326. begin
  327. n:=tassignmentnode(inherited getcopy);
  328. n.assigntype:=assigntype;
  329. getcopy:=n;
  330. end;
  331. function tassignmentnode.det_resulttype:tnode;
  332. begin
  333. result:=nil;
  334. resulttype:=voidtype;
  335. { must be made unique }
  336. if assigned(left) then
  337. begin
  338. set_unique(left);
  339. { set we the function result? }
  340. set_funcret_is_valid(left);
  341. end;
  342. resulttypepass(left);
  343. resulttypepass(right);
  344. set_varstate(left,false);
  345. set_varstate(right,true);
  346. if codegenerror then
  347. exit;
  348. { assignments to open arrays aren't allowed }
  349. if is_open_array(left.resulttype.def) then
  350. CGMessage(type_e_mismatch);
  351. { some string functions don't need conversion, so treat them separatly }
  352. if not (
  353. is_shortstring(left.resulttype.def) and
  354. (
  355. is_shortstring(right.resulttype.def) or
  356. is_ansistring(right.resulttype.def) or
  357. is_char(right.resulttype.def)
  358. )
  359. ) then
  360. inserttypeconv(right,left.resulttype);
  361. { test if node can be assigned, properties are allowed }
  362. valid_for_assignment(left);
  363. { check if local proc/func is assigned to procvar }
  364. if right.resulttype.def.deftype=procvardef then
  365. test_local_to_procvar(tprocvardef(right.resulttype.def),left.resulttype.def);
  366. end;
  367. function tassignmentnode.pass_1 : tnode;
  368. begin
  369. result:=nil;
  370. firstpass(left);
  371. firstpass(right);
  372. if codegenerror then
  373. exit;
  374. { some string functions don't need conversion, so treat them separatly }
  375. if is_shortstring(left.resulttype.def) and
  376. (
  377. is_shortstring(right.resulttype.def) or
  378. is_ansistring(right.resulttype.def) or
  379. is_char(right.resulttype.def)
  380. ) then
  381. begin
  382. { we call STRCOPY }
  383. procinfo^.flags:=procinfo^.flags or pi_do_call;
  384. { test for s:=s+anything ... }
  385. { the problem is for
  386. s:=s+s+s;
  387. this is broken here !! }
  388. {$ifdef newoptimizations2}
  389. { the above is fixed now, but still problem with s := s + f(); if }
  390. { f modifies s (bad programming, so only enable if uncertain }
  391. { optimizations are on) (JM) }
  392. if (cs_UncertainOpts in aktglobalswitches) then
  393. begin
  394. hp := right;
  395. while hp.treetype=addn do hp:=hp.left;
  396. if equal_trees(left,hp) and
  397. not multiple_uses(left,right) then
  398. begin
  399. concat_string:=true;
  400. hp:=right;
  401. while hp.treetype=addn do
  402. begin
  403. hp.use_strconcat:=true;
  404. hp:=hp.left;
  405. end;
  406. end;
  407. end;
  408. {$endif newoptimizations2}
  409. end;
  410. registers32:=left.registers32+right.registers32;
  411. registersfpu:=max(left.registersfpu,right.registersfpu);
  412. {$ifdef SUPPORT_MMX}
  413. registersmmx:=max(left.registersmmx,right.registersmmx);
  414. {$endif SUPPORT_MMX}
  415. end;
  416. function tassignmentnode.docompare(p: tnode): boolean;
  417. begin
  418. docompare :=
  419. inherited docompare(p) and
  420. (assigntype = tassignmentnode(p).assigntype);
  421. end;
  422. {*****************************************************************************
  423. TFUNCRETNODE
  424. *****************************************************************************}
  425. constructor tfuncretnode.create(v:tsym);
  426. begin
  427. inherited create(funcretn);
  428. funcretsym:=tfuncretsym(v);
  429. end;
  430. function tfuncretnode.getcopy : tnode;
  431. var
  432. n : tfuncretnode;
  433. begin
  434. n:=tfuncretnode(inherited getcopy);
  435. n.funcretsym:=funcretsym;
  436. getcopy:=n;
  437. end;
  438. function tfuncretnode.det_resulttype:tnode;
  439. begin
  440. result:=nil;
  441. resulttype:=funcretsym.returntype;
  442. end;
  443. function tfuncretnode.pass_1 : tnode;
  444. begin
  445. result:=nil;
  446. location.loc:=LOC_REFERENCE;
  447. if ret_in_param(resulttype.def) or
  448. (lexlevel<>funcretsym.owner.symtablelevel) then
  449. registers32:=1;
  450. end;
  451. function tfuncretnode.docompare(p: tnode): boolean;
  452. begin
  453. docompare :=
  454. inherited docompare(p) and
  455. (funcretsym = tfuncretnode(p).funcretsym);
  456. end;
  457. {*****************************************************************************
  458. TARRAYCONSTRUCTORRANGENODE
  459. *****************************************************************************}
  460. constructor tarrayconstructorrangenode.create(l,r : tnode);
  461. begin
  462. inherited create(arrayconstructorrangen,l,r);
  463. end;
  464. function tarrayconstructorrangenode.det_resulttype:tnode;
  465. begin
  466. result:=nil;
  467. resulttypepass(left);
  468. resulttypepass(right);
  469. set_varstate(left,true);
  470. set_varstate(right,true);
  471. if codegenerror then
  472. exit;
  473. resulttype:=left.resulttype;
  474. end;
  475. function tarrayconstructorrangenode.pass_1 : tnode;
  476. begin
  477. firstpass(left);
  478. firstpass(right);
  479. calcregisters(self,0,0,0);
  480. result:=nil;
  481. end;
  482. {****************************************************************************
  483. TARRAYCONSTRUCTORNODE
  484. *****************************************************************************}
  485. constructor tarrayconstructornode.create(l,r : tnode);
  486. begin
  487. inherited create(arrayconstructorn,l,r);
  488. end;
  489. function tarrayconstructornode.getcopy : tnode;
  490. var
  491. n : tarrayconstructornode;
  492. begin
  493. n:=tarrayconstructornode(inherited getcopy);
  494. result:=n;
  495. end;
  496. function tarrayconstructornode.det_resulttype:tnode;
  497. var
  498. htype : ttype;
  499. hp : tarrayconstructornode;
  500. len : longint;
  501. varia : boolean;
  502. begin
  503. result:=nil;
  504. { are we allowing array constructor? Then convert it to a set }
  505. if not allow_array_constructor then
  506. begin
  507. hp:=tarrayconstructornode(getcopy);
  508. arrayconstructor_to_set(hp);
  509. resulttypepass(hp);
  510. result:=hp;
  511. exit;
  512. end;
  513. { only pass left tree, right tree contains next construct if any }
  514. htype.reset;
  515. len:=0;
  516. varia:=false;
  517. if assigned(left) then
  518. begin
  519. hp:=self;
  520. while assigned(hp) do
  521. begin
  522. resulttypepass(hp.left);
  523. set_varstate(hp.left,true);
  524. if (htype.def=nil) then
  525. htype:=hp.left.resulttype
  526. else
  527. begin
  528. if ((nf_novariaallowed in flags) or (not varia)) and
  529. (not is_equal(htype.def,hp.left.resulttype.def)) then
  530. begin
  531. varia:=true;
  532. end;
  533. end;
  534. inc(len);
  535. hp:=tarrayconstructornode(hp.right);
  536. end;
  537. end;
  538. if not assigned(htype.def) then
  539. htype:=voidtype;
  540. resulttype.setdef(tarraydef.create(0,len-1,s32bittype));
  541. tarraydef(resulttype.def).elementtype:=htype;
  542. tarraydef(resulttype.def).IsConstructor:=true;
  543. tarraydef(resulttype.def).IsVariant:=varia;
  544. end;
  545. procedure tarrayconstructornode.force_type(tt:ttype);
  546. var
  547. hp : tarrayconstructornode;
  548. begin
  549. tarraydef(resulttype.def).elementtype:=tt;
  550. tarraydef(resulttype.def).IsConstructor:=true;
  551. tarraydef(resulttype.def).IsVariant:=false;
  552. if assigned(left) then
  553. begin
  554. hp:=self;
  555. while assigned(hp) do
  556. begin
  557. inserttypeconv(hp.left,tt);
  558. hp:=tarrayconstructornode(hp.right);
  559. end;
  560. end;
  561. end;
  562. function tarrayconstructornode.pass_1 : tnode;
  563. var
  564. thp,
  565. chp,
  566. hp : tarrayconstructornode;
  567. dovariant : boolean;
  568. htype : ttype;
  569. begin
  570. dovariant:=(nf_forcevaria in flags) or tarraydef(resulttype.def).isvariant;
  571. result:=nil;
  572. { only pass left tree, right tree contains next construct if any }
  573. if assigned(left) then
  574. begin
  575. hp:=self;
  576. while assigned(hp) do
  577. begin
  578. firstpass(hp.left);
  579. { Insert typeconvs for array of const }
  580. if dovariant then
  581. begin
  582. case hp.left.resulttype.def.deftype of
  583. enumdef :
  584. begin
  585. hp.left:=ctypeconvnode.create(hp.left,s32bittype);
  586. firstpass(hp.left);
  587. end;
  588. orddef :
  589. begin
  590. if is_integer(hp.left.resulttype.def) and
  591. not(is_64bitint(hp.left.resulttype.def)) then
  592. begin
  593. hp.left:=ctypeconvnode.create(hp.left,s32bittype);
  594. firstpass(hp.left);
  595. end;
  596. end;
  597. floatdef :
  598. begin
  599. hp.left:=ctypeconvnode.create(hp.left,pbestrealtype^);
  600. firstpass(hp.left);
  601. end;
  602. stringdef :
  603. begin
  604. if nf_cargs in flags then
  605. begin
  606. hp.left:=ctypeconvnode.create(hp.left,charpointertype);
  607. firstpass(hp.left);
  608. end;
  609. end;
  610. procvardef :
  611. begin
  612. hp.left:=ctypeconvnode.create(hp.left,voidpointertype);
  613. firstpass(hp.left);
  614. end;
  615. pointerdef,
  616. classrefdef,
  617. objectdef : ;
  618. else
  619. CGMessagePos1(hp.left.fileinfo,type_e_wrong_type_in_array_constructor,hp.left.resulttype.def.typename);
  620. end;
  621. end;
  622. hp:=tarrayconstructornode(hp.right);
  623. end;
  624. { swap the tree for cargs }
  625. if (nf_cargs in flags) and (not(nf_cargswap in flags)) then
  626. begin
  627. chp:=nil;
  628. { save resulttype }
  629. htype:=resulttype;
  630. { we need a copy here, because self is destroyed }
  631. { by firstpass later }
  632. hp:=tarrayconstructornode(getcopy);
  633. while assigned(hp) do
  634. begin
  635. thp:=tarrayconstructornode(hp.right);
  636. hp.right:=chp;
  637. chp:=hp;
  638. hp:=thp;
  639. end;
  640. include(chp.flags,nf_cargs);
  641. include(chp.flags,nf_cargswap);
  642. calcregisters(chp,0,0,0);
  643. chp.location.loc:=LOC_MEM;
  644. chp.resulttype:=htype;
  645. result:=chp;
  646. exit;
  647. end;
  648. end;
  649. calcregisters(self,0,0,0);
  650. location.loc:=LOC_MEM;
  651. end;
  652. function tarrayconstructornode.docompare(p: tnode): boolean;
  653. begin
  654. docompare :=
  655. inherited docompare(p);
  656. end;
  657. {*****************************************************************************
  658. TTYPENODE
  659. *****************************************************************************}
  660. constructor ttypenode.create(t : ttype);
  661. begin
  662. inherited create(typen);
  663. restype:=t;
  664. allowed:=false;
  665. end;
  666. function ttypenode.det_resulttype:tnode;
  667. begin
  668. result:=nil;
  669. resulttype:=restype;
  670. end;
  671. function ttypenode.pass_1 : tnode;
  672. begin
  673. result:=nil;
  674. { a typenode can't generate code, so we give here
  675. an error. Else it'll be an abstract error in pass_2.
  676. Only when the allowed flag is set we don't generate
  677. an error }
  678. if not allowed then
  679. Message(parser_e_no_type_not_allowed_here);
  680. end;
  681. function ttypenode.docompare(p: tnode): boolean;
  682. begin
  683. docompare :=
  684. inherited docompare(p);
  685. end;
  686. begin
  687. cloadnode:=tloadnode;
  688. cassignmentnode:=tassignmentnode;
  689. cfuncretnode:=tfuncretnode;
  690. carrayconstructorrangenode:=tarrayconstructorrangenode;
  691. carrayconstructornode:=tarrayconstructornode;
  692. ctypenode:=ttypenode;
  693. end.
  694. {
  695. $Log$
  696. Revision 1.24 2001-08-30 15:48:34 jonas
  697. * fix from Peter for getting correct symtableentry for funcret loads
  698. Revision 1.23 2001/08/26 13:36:41 florian
  699. * some cg reorganisation
  700. * some PPC updates
  701. Revision 1.22 2001/08/12 22:11:52 peter
  702. * errordef.typesym is not updated anymore
  703. Revision 1.21 2001/08/06 21:40:47 peter
  704. * funcret moved from tprocinfo to tprocdef
  705. Revision 1.20 2001/07/30 20:52:25 peter
  706. * fixed array constructor passing with type conversions
  707. Revision 1.19 2001/06/04 18:07:47 peter
  708. * remove unused typenode for procvar load. Don't know what happened why
  709. this code was not there already with revision 1.17.
  710. Revision 1.18 2001/06/04 11:48:01 peter
  711. * better const to var checking
  712. Revision 1.17 2001/05/19 21:19:57 peter
  713. * remove unused typenode for procvars to prevent error
  714. * typenode.allowed flag to allow a typenode
  715. Revision 1.16 2001/05/09 19:57:51 peter
  716. * typenode doesn't generate code, give error in pass_1 instead of
  717. getting an abstract methode runtime error
  718. Revision 1.15 2001/04/14 14:06:31 peter
  719. * move more code from loadnode.pass_1 to det_resulttype
  720. Revision 1.14 2001/04/13 01:22:10 peter
  721. * symtable change to classes
  722. * range check generation and errors fixed, make cycle DEBUG=1 works
  723. * memory leaks fixed
  724. Revision 1.13 2001/04/05 21:03:08 peter
  725. * array constructor fix
  726. Revision 1.12 2001/04/04 22:42:40 peter
  727. * move constant folding into det_resulttype
  728. Revision 1.11 2001/04/02 21:20:31 peter
  729. * resulttype rewrite
  730. Revision 1.10 2000/12/31 11:14:10 jonas
  731. + implemented/fixed docompare() mathods for all nodes (not tested)
  732. + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
  733. and constant strings/chars together
  734. * n386add.pas: don't copy temp strings (of size 256) to another temp string
  735. when adding
  736. Revision 1.9 2000/11/29 00:30:33 florian
  737. * unused units removed from uses clause
  738. * some changes for widestrings
  739. Revision 1.8 2000/11/04 14:25:20 florian
  740. + merged Attila's changes for interfaces, not tested yet
  741. Revision 1.7 2000/10/31 22:02:49 peter
  742. * symtable splitted, no real code changes
  743. Revision 1.6 2000/10/14 10:14:50 peter
  744. * moehrendorf oct 2000 rewrite
  745. Revision 1.5 2000/10/01 19:48:24 peter
  746. * lot of compile updates for cg11
  747. Revision 1.4 2000/09/28 19:49:52 florian
  748. *** empty log message ***
  749. Revision 1.3 2000/09/27 18:14:31 florian
  750. * fixed a lot of syntax errors in the n*.pas stuff
  751. Revision 1.2 2000/09/25 15:37:14 florian
  752. * more fixes
  753. Revision 1.1 2000/09/25 14:55:05 florian
  754. * initial revision
  755. }