nld.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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 : psym;
  27. symtable : psymtable;
  28. constructor create(v : psym;st : psymtable);virtual;
  29. function getcopy : tnode;override;
  30. function pass_1 : tnode;override;
  31. function docompare(p: tnode): boolean; override;
  32. end;
  33. { different assignment types }
  34. tassigntype = (at_normal,at_plus,at_minus,at_star,at_slash);
  35. tassignmentnode = class(tbinarynode)
  36. assigntype : tassigntype;
  37. constructor create(l,r : tnode);virtual;
  38. function getcopy : tnode;override;
  39. function pass_1 : tnode;override;
  40. function docompare(p: tnode): boolean; override;
  41. end;
  42. tfuncretnode = class(tnode)
  43. funcretprocinfo : pointer;
  44. rettype : ttype;
  45. constructor create;virtual;
  46. function getcopy : tnode;override;
  47. function pass_1 : tnode;override;
  48. function docompare(p: tnode): boolean; override;
  49. end;
  50. tarrayconstructorrangenode = class(tbinarynode)
  51. constructor create(l,r : tnode);virtual;
  52. function pass_1 : tnode;override;
  53. end;
  54. tarrayconstructornode = class(tbinarynode)
  55. constructordef : pdef;
  56. constructor create(l,r : tnode);virtual;
  57. function getcopy : tnode;override;
  58. function pass_1 : tnode;override;
  59. function docompare(p: tnode): boolean; override;
  60. end;
  61. ttypenode = class(tnode)
  62. typenodetype : pdef;
  63. typenodesym:ptypesym;
  64. constructor create(t : pdef;sym:ptypesym);virtual;
  65. function getcopy : tnode;override;
  66. function pass_1 : tnode;override;
  67. function docompare(p: tnode): boolean; override;
  68. end;
  69. var
  70. cloadnode : class of tloadnode;
  71. cassignmentnode : class of tassignmentnode;
  72. cfuncretnode : class of tfuncretnode;
  73. carrayconstructorrangenode : class of tarrayconstructorrangenode;
  74. carrayconstructornode : class of tarrayconstructornode;
  75. ctypenode : class of ttypenode;
  76. function genloadnode(v : pvarsym;st : psymtable) : tloadnode;
  77. function gentypenode(t : pdef;sym:ptypesym) : ttypenode;
  78. function genloadcallnode(v: pprocsym;st: psymtable): tloadnode;
  79. function genloadmethodcallnode(v: pprocsym;st: psymtable; mp: tnode): tloadnode;
  80. function gentypedconstloadnode(sym : ptypedconstsym;st : psymtable) : tloadnode;
  81. implementation
  82. uses
  83. cutils,verbose,globtype,globals,systems,
  84. symconst,symdef,symtable,types,
  85. htypechk,pass_1,
  86. ncnv,nmem,cpubase,tgcpu,hcodegen
  87. {$ifdef newcg}
  88. ,cgbase
  89. ,tgobj
  90. {$endif newcg}
  91. ;
  92. function genloadnode(v : pvarsym;st : psymtable) : tloadnode;
  93. var
  94. n : tloadnode;
  95. begin
  96. n:=cloadnode.create(v,st);
  97. n.resulttype:=v^.vartype.def;
  98. genloadnode:=n;
  99. end;
  100. function genloadcallnode(v: pprocsym;st: psymtable): tloadnode;
  101. var
  102. n : tloadnode;
  103. begin
  104. n:=cloadnode.create(v,st);
  105. n.resulttype:=v^.definition;
  106. genloadcallnode:=n;
  107. end;
  108. function genloadmethodcallnode(v: pprocsym;st: psymtable; mp: tnode): tloadnode;
  109. var
  110. n : tloadnode;
  111. begin
  112. n:=cloadnode.create(v,st);
  113. n.resulttype:=v^.definition;
  114. n.left:=mp;
  115. genloadmethodcallnode:=n;
  116. end;
  117. function gentypedconstloadnode(sym : ptypedconstsym;st : psymtable) : tloadnode;
  118. var
  119. n : tloadnode;
  120. begin
  121. n:=cloadnode.create(sym,st);
  122. n.resulttype:=sym^.typedconsttype.def;
  123. gentypedconstloadnode:=n;
  124. end;
  125. function gentypenode(t : pdef;sym:ptypesym) : ttypenode;
  126. begin
  127. gentypenode:=ctypenode.create(t,sym);
  128. end;
  129. {*****************************************************************************
  130. TLOADNODE
  131. *****************************************************************************}
  132. constructor tloadnode.create(v : psym;st : psymtable);
  133. begin
  134. inherited create(loadn,nil);
  135. symtableentry:=v;
  136. symtable:=st;
  137. end;
  138. function tloadnode.getcopy : tnode;
  139. var
  140. n : tloadnode;
  141. begin
  142. n:=tloadnode(inherited getcopy);
  143. n.symtable:=symtable;
  144. n.symtableentry:=symtableentry;
  145. result:=n;
  146. end;
  147. function tloadnode.pass_1 : tnode;
  148. var
  149. p1 : tnode;
  150. begin
  151. result:=nil;
  152. if (symtable^.symtabletype=withsymtable) and
  153. (pwithsymtable(symtable)^.direct_with) and
  154. (symtableentry^.typ=varsym) then
  155. begin
  156. p1:=tnode(pwithsymtable(symtable)^.withrefnode).getcopy;
  157. p1:=gensubscriptnode(pvarsym(symtableentry),p1);
  158. left:=nil;
  159. firstpass(p1);
  160. result:=p1;
  161. exit;
  162. end;
  163. location.loc:=LOC_REFERENCE;
  164. registers32:=0;
  165. registersfpu:=0;
  166. {$ifdef SUPPORT_MMX}
  167. registersmmx:=0;
  168. {$endif SUPPORT_MMX}
  169. { handle first absolute as it will replace the symtableentry }
  170. if symtableentry^.typ=absolutesym then
  171. begin
  172. resulttype:=pabsolutesym(symtableentry)^.vartype.def;
  173. { replace the symtableentry when it points to a var, else
  174. we are finished }
  175. if pabsolutesym(symtableentry)^.abstyp=tovar then
  176. begin
  177. symtableentry:=pabsolutesym(symtableentry)^.ref;
  178. symtable:=symtableentry^.owner;
  179. include(flags,nf_absolute);
  180. end
  181. else
  182. exit;
  183. end;
  184. case symtableentry^.typ of
  185. funcretsym :
  186. begin
  187. p1:=cfuncretnode.create;
  188. tfuncretnode(p1).funcretprocinfo:=pprocinfo(pfuncretsym(symtableentry)^.funcretprocinfo);
  189. tfuncretnode(p1).rettype:=pfuncretsym(symtableentry)^.rettype;
  190. firstpass(p1);
  191. { if it's refered as absolute then we need to have the
  192. type of the absolute instead of the function return,
  193. the function return is then also assigned }
  194. if nf_absolute in flags then
  195. begin
  196. pprocinfo(tfuncretnode(p1).funcretprocinfo)^.funcret_state:=vs_assigned;
  197. p1.resulttype:=resulttype;
  198. end;
  199. left:=nil;
  200. result:=p1;
  201. end;
  202. constsym:
  203. begin
  204. if pconstsym(symtableentry)^.consttyp=constresourcestring then
  205. begin
  206. resulttype:=cansistringdef;
  207. { we use ansistrings so no fast exit here }
  208. if assigned(procinfo) then
  209. procinfo^.no_fast_exit:=true;
  210. location.loc:=LOC_MEM;
  211. end
  212. else
  213. internalerror(22799);
  214. end;
  215. varsym :
  216. begin
  217. { if it's refered by absolute then it's used }
  218. if nf_absolute in flags then
  219. pvarsym(symtableentry)^.varstate:=vs_used
  220. else
  221. if (resulttype=nil) then
  222. resulttype:=pvarsym(symtableentry)^.vartype.def;
  223. if (symtable^.symtabletype in [parasymtable,localsymtable]) and
  224. (lexlevel>symtable^.symtablelevel) then
  225. begin
  226. { if the variable is in an other stackframe then we need
  227. a register to dereference }
  228. if (symtable^.symtablelevel)>0 then
  229. begin
  230. registers32:=1;
  231. { further, the variable can't be put into a register }
  232. pvarsym(symtableentry)^.varoptions:=
  233. pvarsym(symtableentry)^.varoptions-[vo_fpuregable,vo_regable];
  234. end;
  235. end;
  236. if (pvarsym(symtableentry)^.varspez=vs_const) then
  237. location.loc:=LOC_MEM;
  238. { we need a register for call by reference parameters }
  239. if (pvarsym(symtableentry)^.varspez in [vs_var,vs_out]) or
  240. ((pvarsym(symtableentry)^.varspez=vs_const) and
  241. push_addr_param(pvarsym(symtableentry)^.vartype.def)) or
  242. { call by value open arrays are also indirect addressed }
  243. is_open_array(pvarsym(symtableentry)^.vartype.def) then
  244. registers32:=1;
  245. if symtable^.symtabletype=withsymtable then
  246. inc(registers32);
  247. if ([vo_is_thread_var,vo_is_dll_var]*pvarsym(symtableentry)^.varoptions)<>[] then
  248. registers32:=1;
  249. { count variable references }
  250. { this will create problem with local var set by
  251. under_procedures
  252. if (assigned(pvarsym(symtableentry)^.owner) and assigned(aktprocsym)
  253. and ((pvarsym(symtableentry)^.owner = aktprocsym^.definition^.localst)
  254. or (pvarsym(symtableentry)^.owner = aktprocsym^.definition^.localst))) then }
  255. if t_times<1 then
  256. inc(pvarsym(symtableentry)^.refs)
  257. else
  258. inc(pvarsym(symtableentry)^.refs,t_times);
  259. end;
  260. typedconstsym :
  261. if not(nf_absolute in flags) then
  262. resulttype:=ptypedconstsym(symtableentry)^.typedconsttype.def;
  263. procsym :
  264. begin
  265. if assigned(pprocsym(symtableentry)^.definition^.nextoverloaded) then
  266. CGMessage(parser_e_no_overloaded_procvars);
  267. resulttype:=pprocsym(symtableentry)^.definition;
  268. { if the owner of the procsym is a object, }
  269. { left must be set, if left isn't set }
  270. { it can be only self }
  271. { this code is only used in TP procvar mode }
  272. if (m_tp_procvar in aktmodeswitches) and
  273. not(assigned(left)) and
  274. (pprocsym(symtableentry)^.owner^.symtabletype=objectsymtable) then
  275. left:=genselfnode(pobjectdef(symtableentry^.owner^.defowner));
  276. { method pointer ? }
  277. if assigned(left) then
  278. begin
  279. firstpass(left);
  280. registers32:=max(registers32,left.registers32);
  281. registersfpu:=max(registersfpu,left.registersfpu);
  282. {$ifdef SUPPORT_MMX}
  283. registersmmx:=max(registersmmx,left.registersmmx);
  284. {$endif SUPPORT_MMX}
  285. end;
  286. end;
  287. else
  288. internalerror(3);
  289. end;
  290. end;
  291. function tloadnode.docompare(p: tnode): boolean;
  292. begin
  293. docompare :=
  294. inherited docompare(p) and
  295. (symtableentry = tloadnode(p).symtableentry) and
  296. (symtable = tloadnode(p).symtable);
  297. end;
  298. {*****************************************************************************
  299. TASSIGNMENTNODE
  300. *****************************************************************************}
  301. constructor tassignmentnode.create(l,r : tnode);
  302. begin
  303. inherited create(assignn,l,r);
  304. assigntype:=at_normal;
  305. end;
  306. function tassignmentnode.getcopy : tnode;
  307. var
  308. n : tassignmentnode;
  309. begin
  310. n:=tassignmentnode(inherited getcopy);
  311. n.assigntype:=assigntype;
  312. getcopy:=n;
  313. end;
  314. function tassignmentnode.pass_1 : tnode;
  315. {$ifdef newoptimizations2}
  316. var
  317. hp : tnode;
  318. {$endif newoptimizations2}
  319. begin
  320. result:=nil;
  321. { must be made unique }
  322. if assigned(left) then
  323. begin
  324. set_unique(left);
  325. { set we the function result? }
  326. set_funcret_is_valid(left);
  327. end;
  328. firstpass(left);
  329. set_varstate(left,false);
  330. if codegenerror then
  331. exit;
  332. { assignements to open arrays aren't allowed }
  333. if is_open_array(left.resulttype) then
  334. CGMessage(type_e_mismatch);
  335. { test if we can avoid copying string to temp
  336. as in s:=s+...; (PM) }
  337. {$ifdef dummyi386}
  338. if ((right.treetype=addn) or (right.treetype=subn)) and
  339. equal_trees(left,right.left) and
  340. (ret_in_acc(left.resulttype)) and
  341. (not cs_rangechecking in aktmoduleswitches^) then
  342. begin
  343. disposetree(right.left);
  344. hp:=right;
  345. right:=right.right;
  346. if hp.treetype=addn then
  347. assigntyp:=at_plus
  348. else
  349. assigntyp:=at_minus;
  350. putnode(hp);
  351. end;
  352. if assigntyp<>at_normal then
  353. begin
  354. { for fpu type there is no faster way }
  355. if is_fpu(left.resulttype) then
  356. case assigntyp of
  357. at_plus : right:=gennode(addn,getcopy(left),right);
  358. at_minus : right:=gennode(subn,getcopy(left),right);
  359. at_star : right:=gennode(muln,getcopy(left),right);
  360. at_slash : right:=gennode(slashn,getcopy(left),right);
  361. end;
  362. end;
  363. {$endif i386}
  364. firstpass(right);
  365. set_varstate(right,true);
  366. if codegenerror then
  367. exit;
  368. { some string functions don't need conversion, so treat them separatly }
  369. if is_shortstring(left.resulttype) and (assigned(right.resulttype)) then
  370. begin
  371. if not (is_shortstring(right.resulttype) or
  372. is_ansistring(right.resulttype) or
  373. is_char(right.resulttype)) then
  374. begin
  375. right:=gentypeconvnode(right,left.resulttype);
  376. firstpass(right);
  377. if codegenerror then
  378. exit;
  379. end;
  380. { we call STRCOPY }
  381. procinfo^.flags:=procinfo^.flags or pi_do_call;
  382. { test for s:=s+anything ... }
  383. { the problem is for
  384. s:=s+s+s;
  385. this is broken here !! }
  386. {$ifdef newoptimizations2}
  387. { the above is fixed now, but still problem with s := s + f(); if }
  388. { f modifies s (bad programming, so only enable if uncertain }
  389. { optimizations are on) (JM) }
  390. if (cs_UncertainOpts in aktglobalswitches) then
  391. begin
  392. hp := right;
  393. while hp.treetype=addn do hp:=hp.left;
  394. if equal_trees(left,hp) and
  395. not multiple_uses(left,right) then
  396. begin
  397. concat_string:=true;
  398. hp:=right;
  399. while hp.treetype=addn do
  400. begin
  401. hp.use_strconcat:=true;
  402. hp:=hp.left;
  403. end;
  404. end;
  405. end;
  406. {$endif newoptimizations2}
  407. end
  408. else
  409. begin
  410. right:=gentypeconvnode(right,left.resulttype);
  411. firstpass(right);
  412. if codegenerror then
  413. exit;
  414. end;
  415. { test if node can be assigned, properties are allowed }
  416. valid_for_assign(left,true);
  417. { check if local proc/func is assigned to procvar }
  418. if right.resulttype^.deftype=procvardef then
  419. test_local_to_procvar(pprocvardef(right.resulttype),left.resulttype);
  420. resulttype:=voiddef;
  421. {
  422. registers32:=max(left.registers32,right.registers32);
  423. registersfpu:=max(left.registersfpu,right.registersfpu);
  424. }
  425. registers32:=left.registers32+right.registers32;
  426. registersfpu:=max(left.registersfpu,right.registersfpu);
  427. {$ifdef SUPPORT_MMX}
  428. registersmmx:=max(left.registersmmx,right.registersmmx);
  429. {$endif SUPPORT_MMX}
  430. end;
  431. function tassignmentnode.docompare(p: tnode): boolean;
  432. begin
  433. docompare :=
  434. inherited docompare(p) and
  435. (assigntype = tassignmentnode(p).assigntype);
  436. end;
  437. {*****************************************************************************
  438. TFUNCRETNODE
  439. *****************************************************************************}
  440. constructor tfuncretnode.create;
  441. begin
  442. inherited create(funcretn);
  443. funcretprocinfo:=nil;
  444. end;
  445. function tfuncretnode.getcopy : tnode;
  446. var
  447. n : tfuncretnode;
  448. begin
  449. n:=tfuncretnode(inherited getcopy);
  450. n.funcretprocinfo:=funcretprocinfo;
  451. n.rettype:=rettype;
  452. getcopy:=n;
  453. end;
  454. function tfuncretnode.pass_1 : tnode;
  455. begin
  456. result:=nil;
  457. resulttype:=rettype.def;
  458. location.loc:=LOC_REFERENCE;
  459. if ret_in_param(rettype.def) or
  460. (procinfo<>pprocinfo(funcretprocinfo)) then
  461. registers32:=1;
  462. end;
  463. function tfuncretnode.docompare(p: tnode): boolean;
  464. begin
  465. docompare :=
  466. inherited docompare(p) and
  467. (funcretprocinfo = tfuncretnode(p).funcretprocinfo) and
  468. (rettype.def = tfuncretnode(p).rettype.def) and
  469. (rettype.sym = tfuncretnode(p).rettype.sym);
  470. end;
  471. {*****************************************************************************
  472. TARRAYCONSTRUCTORRANGENODE
  473. *****************************************************************************}
  474. constructor tarrayconstructorrangenode.create(l,r : tnode);
  475. begin
  476. inherited create(arrayconstructorrangen,l,r);
  477. end;
  478. function tarrayconstructorrangenode.pass_1 : tnode;
  479. begin
  480. result:=nil;
  481. firstpass(left);
  482. set_varstate(left,true);
  483. firstpass(right);
  484. set_varstate(right,true);
  485. calcregisters(self,0,0,0);
  486. resulttype:=left.resulttype;
  487. end;
  488. {****************************************************************************
  489. TARRAYCONSTRUCTORNODE
  490. *****************************************************************************}
  491. constructor tarrayconstructornode.create(l,r : tnode);
  492. begin
  493. inherited create(arrayconstructorn,l,r);
  494. constructordef:=nil;
  495. end;
  496. function tarrayconstructornode.getcopy : tnode;
  497. var
  498. n : tarrayconstructornode;
  499. begin
  500. n:=tarrayconstructornode(inherited getcopy);
  501. n.constructordef:=constructordef;
  502. result:=n;
  503. end;
  504. function tarrayconstructornode.pass_1 : tnode;
  505. var
  506. pd : pdef;
  507. thp,
  508. chp,
  509. hp : tarrayconstructornode;
  510. len : longint;
  511. varia : boolean;
  512. procedure postprocess(t : tnode);
  513. begin
  514. calcregisters(tbinarynode(t),0,0,0);
  515. { looks a little bit dangerous to me }
  516. { len-1 gives problems with is_open_array if len=0, }
  517. { is_open_array checks now for isconstructor (FK) }
  518. { if no type is set then we set the type to voiddef to overcome a
  519. 0 addressing }
  520. if not assigned(pd) then
  521. pd:=voiddef;
  522. { skip if already done ! (PM) }
  523. if not assigned(t.resulttype) or
  524. (t.resulttype^.deftype<>arraydef) or
  525. not parraydef(t.resulttype)^.IsConstructor or
  526. (parraydef(t.resulttype)^.lowrange<>0) or
  527. (parraydef(t.resulttype)^.highrange<>len-1) then
  528. t.resulttype:=new(parraydef,init(0,len-1,s32bitdef));
  529. parraydef(t.resulttype)^.elementtype.def:=pd;
  530. parraydef(t.resulttype)^.IsConstructor:=true;
  531. parraydef(t.resulttype)^.IsVariant:=varia;
  532. t.location.loc:=LOC_MEM;
  533. end;
  534. begin
  535. result:=nil;
  536. { are we allowing array constructor? Then convert it to a set }
  537. if not allow_array_constructor then
  538. begin
  539. hp:=tarrayconstructornode(getcopy);
  540. arrayconstructor_to_set(hp);
  541. firstpass(hp);
  542. pass_1:=hp;
  543. exit;
  544. end;
  545. { only pass left tree, right tree contains next construct if any }
  546. pd:=constructordef;
  547. len:=0;
  548. varia:=false;
  549. if assigned(left) then
  550. begin
  551. hp:=self;
  552. while assigned(hp) do
  553. begin
  554. firstpass(hp.left);
  555. set_varstate(hp.left,true);
  556. if (not get_para_resulttype) and
  557. (not(nf_novariaallowed in flags)) then
  558. begin
  559. case hp.left.resulttype^.deftype of
  560. enumdef :
  561. begin
  562. hp.left:=gentypeconvnode(hp.left,s32bitdef);
  563. firstpass(hp.left);
  564. end;
  565. orddef :
  566. begin
  567. if is_integer(hp.left.resulttype) and
  568. not(is_64bitint(hp.left.resulttype)) then
  569. begin
  570. hp.left:=gentypeconvnode(hp.left,s32bitdef);
  571. firstpass(hp.left);
  572. end;
  573. end;
  574. floatdef :
  575. begin
  576. hp.left:=gentypeconvnode(hp.left,bestrealdef^);
  577. firstpass(hp.left);
  578. end;
  579. stringdef :
  580. begin
  581. if nf_cargs in flags then
  582. begin
  583. hp.left:=gentypeconvnode(hp.left,charpointerdef);
  584. firstpass(hp.left);
  585. end;
  586. end;
  587. procvardef :
  588. begin
  589. hp.left:=gentypeconvnode(hp.left,voidpointerdef);
  590. firstpass(hp.left);
  591. end;
  592. pointerdef,
  593. classrefdef,
  594. objectdef : ;
  595. else
  596. CGMessagePos1(hp.left.fileinfo,type_e_wrong_type_in_array_constructor,hp.left.resulttype^.typename);
  597. end;
  598. end;
  599. if (pd=nil) then
  600. pd:=hp.left.resulttype
  601. else
  602. begin
  603. if ((nf_novariaallowed in flags) or (not varia)) and
  604. (not is_equal(pd,hp.left.resulttype)) then
  605. begin
  606. { if both should be equal try inserting a conversion }
  607. if nf_novariaallowed in flags then
  608. begin
  609. hp.left:=gentypeconvnode(hp.left,pd);
  610. firstpass(hp.left);
  611. end;
  612. varia:=true;
  613. end;
  614. end;
  615. inc(len);
  616. hp:=tarrayconstructornode(hp.right);
  617. end;
  618. { swap the tree for cargs }
  619. if (nf_cargs in flags) and (not(nf_cargswap in flags)) then
  620. begin
  621. chp:=nil;
  622. { we need a copy here, because self is destroyed }
  623. { by firstpass later }
  624. hp:=tarrayconstructornode(getcopy);
  625. while assigned(hp) do
  626. begin
  627. thp:=tarrayconstructornode(hp.right);
  628. hp.right:=chp;
  629. chp:=hp;
  630. hp:=thp;
  631. end;
  632. include(chp.flags,nf_cargs);
  633. include(chp.flags,nf_cargswap);
  634. postprocess(chp);
  635. pass_1:=chp;
  636. exit;
  637. end;
  638. end;
  639. postprocess(self);
  640. end;
  641. function tarrayconstructornode.docompare(p: tnode): boolean;
  642. begin
  643. docompare :=
  644. inherited docompare(p) and
  645. (constructordef = tarrayconstructornode(p).constructordef);
  646. end;
  647. {*****************************************************************************
  648. TTYPENODE
  649. *****************************************************************************}
  650. constructor ttypenode.create(t : pdef;sym:ptypesym);
  651. begin
  652. inherited create(typen);
  653. resulttype:=generrordef;
  654. typenodetype:=t;
  655. typenodesym:=sym;
  656. end;
  657. function ttypenode.getcopy : tnode;
  658. var
  659. n : ttypenode;
  660. begin
  661. n:=ttypenode(inherited getcopy);
  662. n.typenodetype:=typenodetype;
  663. n.typenodesym:=typenodesym;
  664. result:=n;
  665. end;
  666. function ttypenode.pass_1 : tnode;
  667. begin
  668. pass_1:=nil;
  669. { do nothing, resulttype is already set }
  670. end;
  671. function ttypenode.docompare(p: tnode): boolean;
  672. begin
  673. docompare :=
  674. inherited docompare(p) and
  675. (typenodetype = ttypenode(p).typenodetype) and
  676. (typenodesym = ttypenode(p).typenodesym);
  677. end;
  678. begin
  679. cloadnode:=tloadnode;
  680. cassignmentnode:=tassignmentnode;
  681. cfuncretnode:=tfuncretnode;
  682. carrayconstructorrangenode:=tarrayconstructorrangenode;
  683. carrayconstructornode:=tarrayconstructornode;
  684. ctypenode:=ttypenode;
  685. end.
  686. {
  687. $Log$
  688. Revision 1.10 2000-12-31 11:14:10 jonas
  689. + implemented/fixed docompare() mathods for all nodes (not tested)
  690. + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
  691. and constant strings/chars together
  692. * n386add.pas: don't copy temp strings (of size 256) to another temp string
  693. when adding
  694. Revision 1.9 2000/11/29 00:30:33 florian
  695. * unused units removed from uses clause
  696. * some changes for widestrings
  697. Revision 1.8 2000/11/04 14:25:20 florian
  698. + merged Attila's changes for interfaces, not tested yet
  699. Revision 1.7 2000/10/31 22:02:49 peter
  700. * symtable splitted, no real code changes
  701. Revision 1.6 2000/10/14 10:14:50 peter
  702. * moehrendorf oct 2000 rewrite
  703. Revision 1.5 2000/10/01 19:48:24 peter
  704. * lot of compile updates for cg11
  705. Revision 1.4 2000/09/28 19:49:52 florian
  706. *** empty log message ***
  707. Revision 1.3 2000/09/27 18:14:31 florian
  708. * fixed a lot of syntax errors in the n*.pas stuff
  709. Revision 1.2 2000/09/25 15:37:14 florian
  710. * more fixes
  711. Revision 1.1 2000/09/25 14:55:05 florian
  712. * initial revision
  713. }