nadd.pas 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Type checking and register allocation for add 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 nadd;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node;
  23. type
  24. taddnode = class(tbinopnode)
  25. constructor create(tt : tnodetype;l,r : tnode);override;
  26. function pass_1 : tnode;override;
  27. function det_resulttype:tnode;override;
  28. end;
  29. var
  30. { caddnode is used to create nodes of the add type }
  31. { the virtual constructor allows to assign }
  32. { another class type to caddnode => processor }
  33. { specific node types can be created }
  34. caddnode : class of taddnode;
  35. implementation
  36. uses
  37. globtype,systems,
  38. cutils,verbose,globals,widestr,
  39. symconst,symtype,symdef,types,
  40. cpuinfo,
  41. {$ifdef newcg}
  42. cgbase,
  43. {$else newcg}
  44. hcodegen,
  45. {$endif newcg}
  46. htypechk,pass_1,
  47. nmat,ncnv,nld,ncon,nset,nopt,
  48. cpubase;
  49. {*****************************************************************************
  50. TADDNODE
  51. *****************************************************************************}
  52. {$ifdef fpc}
  53. {$maxfpuregisters 0}
  54. {$endif fpc}
  55. constructor taddnode.create(tt : tnodetype;l,r : tnode);
  56. begin
  57. inherited create(tt,l,r);
  58. end;
  59. function taddnode.det_resulttype:tnode;
  60. var
  61. hp,t : tnode;
  62. lt,rt : tnodetype;
  63. rd,ld : tdef;
  64. htype : ttype;
  65. ot : tnodetype;
  66. concatstrings : boolean;
  67. resultset : pconstset;
  68. i : longint;
  69. b : boolean;
  70. s1,s2 : pchar;
  71. ws1,ws2,
  72. ws3 : tcompilerwidestring;
  73. l1,l2 : longint;
  74. rv,lv : tconstexprint;
  75. rvd,lvd : bestreal;
  76. begin
  77. result:=nil;
  78. { first do the two subtrees }
  79. resulttypepass(left);
  80. resulttypepass(right);
  81. { both left and right need to be valid }
  82. set_varstate(left,true);
  83. set_varstate(right,true);
  84. if codegenerror then
  85. exit;
  86. { convert array constructors to sets, because there is no other operator
  87. possible for array constructors }
  88. if is_array_constructor(left.resulttype.def) then
  89. begin
  90. arrayconstructor_to_set(tarrayconstructornode(left));
  91. resulttypepass(left);
  92. end;
  93. if is_array_constructor(right.resulttype.def) then
  94. begin
  95. arrayconstructor_to_set(tarrayconstructornode(right));
  96. resulttypepass(right);
  97. end;
  98. { allow operator overloading }
  99. hp:=self;
  100. if isbinaryoverloaded(hp) then
  101. begin
  102. resulttypepass(hp);
  103. result:=hp;
  104. exit;
  105. end;
  106. { Kylix allows enum+ordconstn in an enum declaration (blocktype
  107. is bt_type), we need to do the conversion here before the
  108. constant folding }
  109. if (m_delphi in aktmodeswitches) and
  110. (blocktype=bt_type) then
  111. begin
  112. if (left.resulttype.def.deftype=enumdef) and
  113. (right.resulttype.def.deftype=orddef) then
  114. begin
  115. { insert explicit typecast to s32bit }
  116. left:=ctypeconvnode.create(left,s32bittype);
  117. include(left.flags,nf_explizit);
  118. resulttypepass(left);
  119. end
  120. else
  121. if (left.resulttype.def.deftype=orddef) and
  122. (right.resulttype.def.deftype=enumdef) then
  123. begin
  124. { insert explicit typecast to s32bit }
  125. right:=ctypeconvnode.create(right,s32bittype);
  126. include(right.flags,nf_explizit);
  127. resulttypepass(right);
  128. end;
  129. end;
  130. { is one a real float, then both need to be floats, this
  131. need to be done before the constant folding so constant
  132. operation on a float and int are also handled }
  133. if (right.resulttype.def.deftype=floatdef) or (left.resulttype.def.deftype=floatdef) then
  134. begin
  135. inserttypeconv(right,pbestrealtype^);
  136. inserttypeconv(left,pbestrealtype^);
  137. end;
  138. { if one operand is a widechar or a widestring, both operands }
  139. { are converted to widestring. This must be done before constant }
  140. { folding to allow char+widechar etc. }
  141. if is_widestring(right.resulttype.def) or
  142. is_widestring(left.resulttype.def) or
  143. is_widechar(right.resulttype.def) or
  144. is_widechar(left.resulttype.def) then
  145. begin
  146. inserttypeconv(right,cwidestringtype);
  147. inserttypeconv(left,cwidestringtype);
  148. end;
  149. { load easier access variables }
  150. rd:=right.resulttype.def;
  151. ld:=left.resulttype.def;
  152. rt:=right.nodetype;
  153. lt:=left.nodetype;
  154. { both are int constants }
  155. if (((is_constintnode(left) and is_constintnode(right)) or
  156. (is_constboolnode(left) and is_constboolnode(right) and
  157. (nodetype in [ltn,lten,gtn,gten,equaln,unequaln,andn,xorn,orn])))) or
  158. { support pointer arithmetics on constants (JM) }
  159. ((lt = pointerconstn) and is_constintnode(right) and
  160. (nodetype in [addn,subn])) or
  161. ((lt = pointerconstn) and (rt = pointerconstn) and
  162. (nodetype in [ltn,lten,gtn,gten,equaln,unequaln,subn])) then
  163. begin
  164. { when comparing/substracting pointers, make sure they are }
  165. { of the same type (JM) }
  166. if (lt = pointerconstn) and (rt = pointerconstn) then
  167. begin
  168. if not(cs_extsyntax in aktmoduleswitches) and
  169. not(nodetype in [equaln,unequaln]) then
  170. CGMessage(type_e_mismatch)
  171. else
  172. if (nodetype <> subn) and
  173. is_voidpointer(rd) then
  174. inserttypeconv(right,left.resulttype)
  175. else if (nodetype <> subn) and
  176. is_voidpointer(ld) then
  177. inserttypeconv(left,right.resulttype)
  178. else if not(is_equal(ld,rd)) then
  179. CGMessage(type_e_mismatch);
  180. end
  181. else if (lt=ordconstn) and (rt=ordconstn) then
  182. begin
  183. { make left const type the biggest, this type will be used
  184. for orn,andn,xorn }
  185. if rd.size>ld.size then
  186. inserttypeconv(left,right.resulttype);
  187. end;
  188. { load values }
  189. if (lt = ordconstn) then
  190. lv:=tordconstnode(left).value
  191. else
  192. lv:=tpointerconstnode(left).value;
  193. if (rt = ordconstn) then
  194. rv:=tordconstnode(right).value
  195. else
  196. rv:=tpointerconstnode(right).value;
  197. if (lt = pointerconstn) and
  198. (rt <> pointerconstn) then
  199. rv := rv * tpointerdef(left.resulttype.def).pointertype.def.size;
  200. if (rt = pointerconstn) and
  201. (lt <> pointerconstn) then
  202. lv := lv * tpointerdef(right.resulttype.def).pointertype.def.size;
  203. case nodetype of
  204. addn :
  205. if (lt <> pointerconstn) then
  206. t := genintconstnode(lv+rv)
  207. else
  208. t := cpointerconstnode.create(lv+rv,left.resulttype);
  209. subn :
  210. if (lt <> pointerconstn) or (rt = pointerconstn) then
  211. t := genintconstnode(lv-rv)
  212. else
  213. t := cpointerconstnode.create(lv-rv,left.resulttype);
  214. muln :
  215. t:=genintconstnode(lv*rv);
  216. xorn :
  217. t:=cordconstnode.create(lv xor rv,left.resulttype);
  218. orn :
  219. t:=cordconstnode.create(lv or rv,left.resulttype);
  220. andn :
  221. t:=cordconstnode.create(lv and rv,left.resulttype);
  222. ltn :
  223. t:=cordconstnode.create(ord(lv<rv),booltype);
  224. lten :
  225. t:=cordconstnode.create(ord(lv<=rv),booltype);
  226. gtn :
  227. t:=cordconstnode.create(ord(lv>rv),booltype);
  228. gten :
  229. t:=cordconstnode.create(ord(lv>=rv),booltype);
  230. equaln :
  231. t:=cordconstnode.create(ord(lv=rv),booltype);
  232. unequaln :
  233. t:=cordconstnode.create(ord(lv<>rv),booltype);
  234. slashn :
  235. begin
  236. { int/int becomes a real }
  237. if int(rv)=0 then
  238. begin
  239. Message(parser_e_invalid_float_operation);
  240. t:=crealconstnode.create(0,pbestrealtype^);
  241. end
  242. else
  243. t:=crealconstnode.create(int(lv)/int(rv),pbestrealtype^);
  244. end;
  245. else
  246. CGMessage(type_e_mismatch);
  247. end;
  248. resulttypepass(t);
  249. result:=t;
  250. exit;
  251. end;
  252. { both real constants ? }
  253. if (lt=realconstn) and (rt=realconstn) then
  254. begin
  255. lvd:=trealconstnode(left).value_real;
  256. rvd:=trealconstnode(right).value_real;
  257. case nodetype of
  258. addn :
  259. t:=crealconstnode.create(lvd+rvd,pbestrealtype^);
  260. subn :
  261. t:=crealconstnode.create(lvd-rvd,pbestrealtype^);
  262. muln :
  263. t:=crealconstnode.create(lvd*rvd,pbestrealtype^);
  264. starstarn,
  265. caretn :
  266. begin
  267. if lvd<0 then
  268. begin
  269. Message(parser_e_invalid_float_operation);
  270. t:=crealconstnode.create(0,pbestrealtype^);
  271. end
  272. else if lvd=0 then
  273. t:=crealconstnode.create(1.0,pbestrealtype^)
  274. else
  275. t:=crealconstnode.create(exp(ln(lvd)*rvd),pbestrealtype^);
  276. end;
  277. slashn :
  278. begin
  279. if rvd=0 then
  280. begin
  281. Message(parser_e_invalid_float_operation);
  282. t:=crealconstnode.create(0,pbestrealtype^);
  283. end
  284. else
  285. t:=crealconstnode.create(lvd/rvd,pbestrealtype^);
  286. end;
  287. ltn :
  288. t:=cordconstnode.create(ord(lvd<rvd),booltype);
  289. lten :
  290. t:=cordconstnode.create(ord(lvd<=rvd),booltype);
  291. gtn :
  292. t:=cordconstnode.create(ord(lvd>rvd),booltype);
  293. gten :
  294. t:=cordconstnode.create(ord(lvd>=rvd),booltype);
  295. equaln :
  296. t:=cordconstnode.create(ord(lvd=rvd),booltype);
  297. unequaln :
  298. t:=cordconstnode.create(ord(lvd<>rvd),booltype);
  299. else
  300. CGMessage(type_e_mismatch);
  301. end;
  302. resulttypepass(t);
  303. result:=t;
  304. exit;
  305. end;
  306. { first, we handle widestrings, so we can check later for }
  307. { stringconstn only }
  308. { widechars are converted above to widestrings too }
  309. { this isn't veryy efficient, but I don't think }
  310. { that it does matter that much (FK) }
  311. if (lt=stringconstn) and (rt=stringconstn) and
  312. (tstringconstnode(left).st_type=st_widestring) and
  313. (tstringconstnode(right).st_type=st_widestring) then
  314. begin
  315. initwidestring(ws1);
  316. initwidestring(ws2);
  317. copywidestring(pcompilerwidestring(tstringconstnode(left).value_str)^,ws1);
  318. copywidestring(pcompilerwidestring(tstringconstnode(right).value_str)^,ws2);
  319. case nodetype of
  320. addn :
  321. begin
  322. initwidestring(ws3);
  323. concatwidestrings(ws1,ws2,ws3);
  324. t:=cstringconstnode.createwstr(ws3);
  325. donewidestring(ws3);
  326. end;
  327. ltn :
  328. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<0),booltype);
  329. lten :
  330. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<=0),booltype);
  331. gtn :
  332. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)>0),booltype);
  333. gten :
  334. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)>=0),booltype);
  335. equaln :
  336. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)=0),booltype);
  337. unequaln :
  338. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<>0),booltype);
  339. end;
  340. donewidestring(ws1);
  341. donewidestring(ws2);
  342. resulttypepass(t);
  343. result:=t;
  344. exit;
  345. end;
  346. { concating strings ? }
  347. concatstrings:=false;
  348. s1:=nil;
  349. s2:=nil;
  350. if (lt=ordconstn) and (rt=ordconstn) and
  351. is_char(ld) and is_char(rd) then
  352. begin
  353. s1:=strpnew(char(byte(tordconstnode(left).value)));
  354. s2:=strpnew(char(byte(tordconstnode(right).value)));
  355. l1:=1;
  356. l2:=1;
  357. concatstrings:=true;
  358. end
  359. else
  360. if (lt=stringconstn) and (rt=ordconstn) and is_char(rd) then
  361. begin
  362. s1:=tstringconstnode(left).getpcharcopy;
  363. l1:=tstringconstnode(left).len;
  364. s2:=strpnew(char(byte(tordconstnode(right).value)));
  365. l2:=1;
  366. concatstrings:=true;
  367. end
  368. else
  369. if (lt=ordconstn) and (rt=stringconstn) and is_char(ld) then
  370. begin
  371. s1:=strpnew(char(byte(tordconstnode(left).value)));
  372. l1:=1;
  373. s2:=tstringconstnode(right).getpcharcopy;
  374. l2:=tstringconstnode(right).len;
  375. concatstrings:=true;
  376. end
  377. else if (lt=stringconstn) and (rt=stringconstn) then
  378. begin
  379. s1:=tstringconstnode(left).getpcharcopy;
  380. l1:=tstringconstnode(left).len;
  381. s2:=tstringconstnode(right).getpcharcopy;
  382. l2:=tstringconstnode(right).len;
  383. concatstrings:=true;
  384. end;
  385. if concatstrings then
  386. begin
  387. case nodetype of
  388. addn :
  389. t:=cstringconstnode.createpchar(concatansistrings(s1,s2,l1,l2),l1+l2);
  390. ltn :
  391. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<0),booltype);
  392. lten :
  393. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<=0),booltype);
  394. gtn :
  395. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)>0),booltype);
  396. gten :
  397. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)>=0),booltype);
  398. equaln :
  399. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)=0),booltype);
  400. unequaln :
  401. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<>0),booltype);
  402. end;
  403. ansistringdispose(s1,l1);
  404. ansistringdispose(s2,l2);
  405. resulttypepass(t);
  406. result:=t;
  407. exit;
  408. end;
  409. { set constant evaluation }
  410. if (right.nodetype=setconstn) and
  411. not assigned(tsetconstnode(right).left) and
  412. (left.nodetype=setconstn) and
  413. not assigned(tsetconstnode(left).left) then
  414. begin
  415. { check types }
  416. inserttypeconv(left,right.resulttype);
  417. if codegenerror then
  418. begin
  419. { recover by only returning the left part }
  420. result:=left;
  421. left:=nil;
  422. exit;
  423. end;
  424. new(resultset);
  425. case nodetype of
  426. addn :
  427. begin
  428. for i:=0 to 31 do
  429. resultset^[i]:=tsetconstnode(right).value_set^[i] or tsetconstnode(left).value_set^[i];
  430. t:=csetconstnode.create(resultset,left.resulttype);
  431. end;
  432. muln :
  433. begin
  434. for i:=0 to 31 do
  435. resultset^[i]:=tsetconstnode(right).value_set^[i] and tsetconstnode(left).value_set^[i];
  436. t:=csetconstnode.create(resultset,left.resulttype);
  437. end;
  438. subn :
  439. begin
  440. for i:=0 to 31 do
  441. resultset^[i]:=tsetconstnode(left).value_set^[i] and not(tsetconstnode(right).value_set^[i]);
  442. t:=csetconstnode.create(resultset,left.resulttype);
  443. end;
  444. symdifn :
  445. begin
  446. for i:=0 to 31 do
  447. resultset^[i]:=tsetconstnode(left).value_set^[i] xor tsetconstnode(right).value_set^[i];
  448. t:=csetconstnode.create(resultset,left.resulttype);
  449. end;
  450. unequaln :
  451. begin
  452. b:=true;
  453. for i:=0 to 31 do
  454. if tsetconstnode(right).value_set^[i]=tsetconstnode(left).value_set^[i] then
  455. begin
  456. b:=false;
  457. break;
  458. end;
  459. t:=cordconstnode.create(ord(b),booltype);
  460. end;
  461. equaln :
  462. begin
  463. b:=true;
  464. for i:=0 to 31 do
  465. if tsetconstnode(right).value_set^[i]<>tsetconstnode(left).value_set^[i] then
  466. begin
  467. b:=false;
  468. break;
  469. end;
  470. t:=cordconstnode.create(ord(b),booltype);
  471. end;
  472. lten :
  473. begin
  474. b := true;
  475. For i := 0 to 31 Do
  476. If (tsetconstnode(right).value_set^[i] And tsetconstnode(left).value_set^[i]) <>
  477. tsetconstnode(left).value_set^[i] Then
  478. Begin
  479. b := false;
  480. Break
  481. End;
  482. t := cordconstnode.create(ord(b),booltype);
  483. End;
  484. gten :
  485. Begin
  486. b := true;
  487. For i := 0 to 31 Do
  488. If (tsetconstnode(left).value_set^[i] And tsetconstnode(right).value_set^[i]) <>
  489. tsetconstnode(right).value_set^[i] Then
  490. Begin
  491. b := false;
  492. Break
  493. End;
  494. t := cordconstnode.create(ord(b),booltype);
  495. End;
  496. end;
  497. dispose(resultset);
  498. resulttypepass(t);
  499. result:=t;
  500. exit;
  501. end;
  502. { but an int/int gives real/real! }
  503. if nodetype=slashn then
  504. begin
  505. CGMessage(type_h_use_div_for_int);
  506. inserttypeconv(right,pbestrealtype^);
  507. inserttypeconv(left,pbestrealtype^);
  508. end
  509. { if both are orddefs then check sub types }
  510. else if (ld.deftype=orddef) and (rd.deftype=orddef) then
  511. begin
  512. { 2 booleans? Make them equal to the largest boolean }
  513. if is_boolean(ld) and is_boolean(rd) then
  514. begin
  515. if torddef(left.resulttype.def).size>torddef(right.resulttype.def).size then
  516. begin
  517. inserttypeconv(right,left.resulttype);
  518. ttypeconvnode(right).convtype:=tc_bool_2_int;
  519. include(right.flags,nf_explizit);
  520. end
  521. else if torddef(left.resulttype.def).size<torddef(right.resulttype.def).size then
  522. begin
  523. inserttypeconv(left,right.resulttype);
  524. ttypeconvnode(left).convtype:=tc_bool_2_int;
  525. include(left.flags,nf_explizit);
  526. end;
  527. case nodetype of
  528. xorn,
  529. ltn,
  530. lten,
  531. gtn,
  532. gten,
  533. andn,
  534. orn:
  535. begin
  536. end;
  537. unequaln,
  538. equaln:
  539. begin
  540. if not(cs_full_boolean_eval in aktlocalswitches) then
  541. begin
  542. { Remove any compares with constants }
  543. if (left.nodetype=ordconstn) then
  544. begin
  545. hp:=right;
  546. b:=(tordconstnode(left).value<>0);
  547. ot:=nodetype;
  548. left.free;
  549. left:=nil;
  550. right:=nil;
  551. if (not(b) and (ot=equaln)) or
  552. (b and (ot=unequaln)) then
  553. begin
  554. hp:=cnotnode.create(hp);
  555. resulttypepass(hp);
  556. end;
  557. result:=hp;
  558. exit;
  559. end;
  560. if (right.nodetype=ordconstn) then
  561. begin
  562. hp:=left;
  563. b:=(tordconstnode(right).value<>0);
  564. ot:=nodetype;
  565. right.free;
  566. right:=nil;
  567. left:=nil;
  568. if (not(b) and (ot=equaln)) or
  569. (b and (ot=unequaln)) then
  570. begin
  571. hp:=cnotnode.create(hp);
  572. resulttypepass(hp);
  573. end;
  574. result:=hp;
  575. exit;
  576. end;
  577. end;
  578. end;
  579. else
  580. CGMessage(type_e_mismatch);
  581. end;
  582. end
  583. { Both are chars? }
  584. else if is_char(rd) and is_char(ld) then
  585. begin
  586. if nodetype=addn then
  587. begin
  588. resulttype:=cshortstringtype;
  589. if not(is_constcharnode(left) and is_constcharnode(right)) then
  590. begin
  591. inserttypeconv(left,cshortstringtype);
  592. hp := genaddsstringcharoptnode(self);
  593. resulttypepass(hp);
  594. result := hp;
  595. exit;
  596. end;
  597. end;
  598. end
  599. { is there a signed 64 bit type ? }
  600. else if ((torddef(rd).typ=s64bit) or (torddef(ld).typ=s64bit)) then
  601. begin
  602. if (torddef(ld).typ<>s64bit) then
  603. inserttypeconv(left,cs64bittype);
  604. if (torddef(rd).typ<>s64bit) then
  605. inserttypeconv(right,cs64bittype);
  606. end
  607. { is there a unsigned 64 bit type ? }
  608. else if ((torddef(rd).typ=u64bit) or (torddef(ld).typ=u64bit)) then
  609. begin
  610. if (torddef(ld).typ<>u64bit) then
  611. inserttypeconv(left,cu64bittype);
  612. if (torddef(rd).typ<>u64bit) then
  613. inserttypeconv(right,cu64bittype);
  614. end
  615. { is there a cardinal? }
  616. else if ((torddef(rd).typ=u32bit) or (torddef(ld).typ=u32bit)) then
  617. begin
  618. if is_signed(ld) and
  619. { then rd = u32bit }
  620. { convert positive constants to u32bit }
  621. not(is_constintnode(left) and
  622. (tordconstnode(left).value >= 0)) and
  623. { range/overflow checking on mixed signed/cardinal expressions }
  624. { is only possible if you convert everything to 64bit (JM) }
  625. ((aktlocalswitches * [cs_check_overflow,cs_check_range] <> []) and
  626. (nodetype in [addn,subn,muln])) then
  627. begin
  628. { perform the operation in 64bit }
  629. CGMessage(type_w_mixed_signed_unsigned);
  630. inserttypeconv(left,cs64bittype);
  631. inserttypeconv(right,cs64bittype);
  632. end
  633. else
  634. begin
  635. if is_signed(ld) and
  636. not(is_constintnode(left) and
  637. (tordconstnode(left).value >= 0)) and
  638. (cs_check_range in aktlocalswitches) then
  639. CGMessage(type_w_mixed_signed_unsigned2);
  640. inserttypeconv(left,u32bittype);
  641. if is_signed(rd) and
  642. { then ld = u32bit }
  643. { convert positive constants to u32bit }
  644. not(is_constintnode(right) and
  645. (tordconstnode(right).value >= 0)) and
  646. ((aktlocalswitches * [cs_check_overflow,cs_check_range] <> []) and
  647. (nodetype in [addn,subn,muln])) then
  648. begin
  649. { perform the operation in 64bit }
  650. CGMessage(type_w_mixed_signed_unsigned);
  651. inserttypeconv(left,cs64bittype);
  652. inserttypeconv(right,cs64bittype);
  653. end
  654. else
  655. begin
  656. if is_signed(rd) and
  657. not(is_constintnode(right) and
  658. (tordconstnode(right).value >= 0)) and
  659. (cs_check_range in aktlocalswitches) then
  660. CGMessage(type_w_mixed_signed_unsigned2);
  661. inserttypeconv(right,u32bittype);
  662. end;
  663. end;
  664. end
  665. { generic ord conversion is s32bit }
  666. else
  667. begin
  668. inserttypeconv(right,s32bittype);
  669. inserttypeconv(left,s32bittype);
  670. end;
  671. end
  672. { if both are floatdefs, conversion is already done before constant folding }
  673. else if (ld.deftype=floatdef) then
  674. begin
  675. { already converted }
  676. end
  677. else if (right.resulttype.def.deftype=floatdef) or (left.resulttype.def.deftype=floatdef) then
  678. begin
  679. inserttypeconv(right,pbestrealtype^);
  680. inserttypeconv(left,pbestrealtype^);
  681. end
  682. { left side a setdef, must be before string processing,
  683. else array constructor can be seen as array of char (PFV) }
  684. else if (ld.deftype=setdef) then
  685. begin
  686. { trying to add a set element? }
  687. if (nodetype=addn) and (rd.deftype<>setdef) then
  688. begin
  689. if (rt=setelementn) then
  690. begin
  691. if not(is_equal(tsetdef(ld).elementtype.def,rd)) then
  692. CGMessage(type_e_set_element_are_not_comp);
  693. end
  694. else
  695. CGMessage(type_e_mismatch)
  696. end
  697. else
  698. begin
  699. if not(nodetype in [addn,subn,symdifn,muln,equaln,unequaln,lten,gten]) then
  700. CGMessage(type_e_set_operation_unknown);
  701. { right def must be a also be set }
  702. if (rd.deftype<>setdef) or not(is_equal(rd,ld)) then
  703. CGMessage(type_e_set_element_are_not_comp);
  704. end;
  705. { ranges require normsets }
  706. if (tsetdef(ld).settype=smallset) and
  707. (rt=setelementn) and
  708. assigned(tsetelementnode(right).right) then
  709. begin
  710. { generate a temporary normset def, it'll be destroyed
  711. when the symtable is unloaded }
  712. htype.setdef(tsetdef.create(tsetdef(ld).elementtype,255));
  713. inserttypeconv(left,htype);
  714. end;
  715. end
  716. { compare pchar to char arrays by addresses like BP/Delphi }
  717. else if (is_pchar(ld) and is_chararray(rd)) or
  718. (is_pchar(rd) and is_chararray(ld)) then
  719. begin
  720. if is_chararray(rd) then
  721. inserttypeconv(right,left.resulttype)
  722. else
  723. inserttypeconv(left,right.resulttype);
  724. end
  725. { is one of the operands a string?,
  726. chararrays are also handled as strings (after conversion), also take
  727. care of chararray+chararray and chararray+char }
  728. else if (rd.deftype=stringdef) or (ld.deftype=stringdef) or
  729. ((is_chararray(rd) or is_char(rd)) and
  730. (is_chararray(ld) or is_char(ld))) then
  731. begin
  732. if is_widestring(rd) or is_widestring(ld) then
  733. begin
  734. if not(is_widestring(rd)) then
  735. inserttypeconv(right,cwidestringtype);
  736. if not(is_widestring(ld)) then
  737. inserttypeconv(left,cwidestringtype);
  738. end
  739. else if is_ansistring(rd) or is_ansistring(ld) then
  740. begin
  741. if not(is_ansistring(rd)) then
  742. inserttypeconv(right,cansistringtype);
  743. if not(is_ansistring(ld)) then
  744. inserttypeconv(left,cansistringtype);
  745. end
  746. else if is_longstring(rd) or is_longstring(ld) then
  747. begin
  748. if not(is_longstring(rd)) then
  749. inserttypeconv(right,clongstringtype);
  750. if not(is_longstring(ld)) then
  751. inserttypeconv(left,clongstringtype);
  752. location.loc:=LOC_MEM;
  753. end
  754. else
  755. begin
  756. if not(is_shortstring(ld)) then
  757. inserttypeconv(left,cshortstringtype);
  758. { don't convert char, that can be handled by the optimized node }
  759. if not(is_shortstring(rd) or is_char(rd)) then
  760. inserttypeconv(right,cshortstringtype);
  761. end;
  762. end
  763. { pointer comparision and subtraction }
  764. else if (rd.deftype=pointerdef) and (ld.deftype=pointerdef) then
  765. begin
  766. case nodetype of
  767. equaln,unequaln :
  768. begin
  769. if is_voidpointer(right.resulttype.def) then
  770. inserttypeconv(right,left.resulttype)
  771. else if is_voidpointer(left.resulttype.def) then
  772. inserttypeconv(left,right.resulttype)
  773. else if not(is_equal(ld,rd)) then
  774. CGMessage(type_e_mismatch);
  775. end;
  776. ltn,lten,gtn,gten:
  777. begin
  778. if (cs_extsyntax in aktmoduleswitches) then
  779. begin
  780. if is_voidpointer(right.resulttype.def) then
  781. inserttypeconv(right,left.resulttype)
  782. else if is_voidpointer(left.resulttype.def) then
  783. inserttypeconv(left,right.resulttype)
  784. else if not(is_equal(ld,rd)) then
  785. CGMessage(type_e_mismatch);
  786. end
  787. else
  788. CGMessage(type_e_mismatch);
  789. end;
  790. subn:
  791. begin
  792. if (cs_extsyntax in aktmoduleswitches) then
  793. begin
  794. if is_voidpointer(right.resulttype.def) then
  795. inserttypeconv(right,left.resulttype)
  796. else if is_voidpointer(left.resulttype.def) then
  797. inserttypeconv(left,right.resulttype)
  798. else if not(is_equal(ld,rd)) then
  799. CGMessage(type_e_mismatch);
  800. end
  801. else
  802. CGMessage(type_e_mismatch);
  803. resulttype:=s32bittype;
  804. exit;
  805. end;
  806. addn:
  807. begin
  808. if (cs_extsyntax in aktmoduleswitches) then
  809. begin
  810. if is_voidpointer(right.resulttype.def) then
  811. inserttypeconv(right,left.resulttype)
  812. else if is_voidpointer(left.resulttype.def) then
  813. inserttypeconv(left,right.resulttype)
  814. else if not(is_equal(ld,rd)) then
  815. CGMessage(type_e_mismatch);
  816. end
  817. else
  818. CGMessage(type_e_mismatch);
  819. resulttype:=s32bittype;
  820. exit;
  821. end;
  822. else
  823. CGMessage(type_e_mismatch);
  824. end;
  825. end
  826. { class or interface equation }
  827. else if is_class_or_interface(rd) or is_class_or_interface(ld) then
  828. begin
  829. if is_class_or_interface(rd) and is_class_or_interface(ld) then
  830. begin
  831. if tobjectdef(rd).is_related(tobjectdef(ld)) then
  832. inserttypeconv(right,left.resulttype)
  833. else
  834. inserttypeconv(left,right.resulttype);
  835. end
  836. else if is_class_or_interface(rd) then
  837. inserttypeconv(left,right.resulttype)
  838. else
  839. inserttypeconv(right,left.resulttype);
  840. if not(nodetype in [equaln,unequaln]) then
  841. CGMessage(type_e_mismatch);
  842. end
  843. else if (rd.deftype=classrefdef) and (ld.deftype=classrefdef) then
  844. begin
  845. if tobjectdef(tclassrefdef(rd).pointertype.def).is_related(
  846. tobjectdef(tclassrefdef(ld).pointertype.def)) then
  847. inserttypeconv(right,left.resulttype)
  848. else
  849. inserttypeconv(left,right.resulttype);
  850. if not(nodetype in [equaln,unequaln]) then
  851. CGMessage(type_e_mismatch);
  852. end
  853. { allows comperasion with nil pointer }
  854. else if is_class_or_interface(rd) or (rd.deftype=classrefdef) then
  855. begin
  856. inserttypeconv(left,right.resulttype);
  857. if not(nodetype in [equaln,unequaln]) then
  858. CGMessage(type_e_mismatch);
  859. end
  860. else if is_class_or_interface(ld) or (ld.deftype=classrefdef) then
  861. begin
  862. inserttypeconv(right,left.resulttype);
  863. if not(nodetype in [equaln,unequaln]) then
  864. CGMessage(type_e_mismatch);
  865. end
  866. { support procvar=nil,procvar<>nil }
  867. else if ((ld.deftype=procvardef) and (rt=niln)) or
  868. ((rd.deftype=procvardef) and (lt=niln)) then
  869. begin
  870. if not(nodetype in [equaln,unequaln]) then
  871. CGMessage(type_e_mismatch);
  872. end
  873. {$ifdef SUPPORT_MMX}
  874. { mmx support, this must be before the zero based array
  875. check }
  876. else if (cs_mmx in aktlocalswitches) and
  877. is_mmx_able_array(ld) and
  878. is_mmx_able_array(rd) and
  879. is_equal(ld,rd) then
  880. begin
  881. case nodetype of
  882. addn,subn,xorn,orn,andn:
  883. ;
  884. { mul is a little bit restricted }
  885. muln:
  886. if not(mmx_type(ld) in [mmxu16bit,mmxs16bit,mmxfixed16]) then
  887. CGMessage(type_e_mismatch);
  888. else
  889. CGMessage(type_e_mismatch);
  890. end;
  891. end
  892. {$endif SUPPORT_MMX}
  893. { this is a little bit dangerous, also the left type }
  894. { pointer to should be checked! This broke the mmx support }
  895. else if (rd.deftype=pointerdef) or is_zero_based_array(rd) then
  896. begin
  897. if is_zero_based_array(rd) then
  898. begin
  899. resulttype.setdef(tpointerdef.create(tarraydef(rd).elementtype));
  900. inserttypeconv(right,resulttype);
  901. end;
  902. inserttypeconv(left,s32bittype);
  903. if nodetype=addn then
  904. begin
  905. if not(cs_extsyntax in aktmoduleswitches) or
  906. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  907. CGMessage(type_e_mismatch);
  908. if (rd.deftype=pointerdef) and
  909. (tpointerdef(rd).pointertype.def.size>1) then
  910. left:=caddnode.create(muln,left,cordconstnode.create(tpointerdef(rd).pointertype.def.size,s32bittype));
  911. end
  912. else
  913. CGMessage(type_e_mismatch);
  914. end
  915. else if (ld.deftype=pointerdef) or is_zero_based_array(ld) then
  916. begin
  917. if is_zero_based_array(ld) then
  918. begin
  919. resulttype.setdef(tpointerdef.create(tarraydef(ld).elementtype));
  920. inserttypeconv(left,resulttype);
  921. end;
  922. inserttypeconv(right,s32bittype);
  923. if nodetype in [addn,subn] then
  924. begin
  925. if not(cs_extsyntax in aktmoduleswitches) or
  926. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  927. CGMessage(type_e_mismatch);
  928. if (ld.deftype=pointerdef) and
  929. (tpointerdef(ld).pointertype.def.size>1) then
  930. right:=caddnode.create(muln,right,cordconstnode.create(tpointerdef(ld).pointertype.def.size,s32bittype));
  931. end
  932. else
  933. CGMessage(type_e_mismatch);
  934. end
  935. else if (rd.deftype=procvardef) and (ld.deftype=procvardef) and is_equal(rd,ld) then
  936. begin
  937. if not (nodetype in [equaln,unequaln]) then
  938. CGMessage(type_e_mismatch);
  939. end
  940. { enums }
  941. else if (ld.deftype=enumdef) and (rd.deftype=enumdef) then
  942. begin
  943. if not(is_equal(ld,rd)) then
  944. inserttypeconv(right,left.resulttype);
  945. if not(nodetype in [equaln,unequaln,ltn,lten,gtn,gten]) then
  946. CGMessage(type_e_mismatch);
  947. end
  948. { generic conversion, this is for error recovery }
  949. else
  950. begin
  951. inserttypeconv(left,s32bittype);
  952. inserttypeconv(right,s32bittype);
  953. end;
  954. { set resulttype if not already done }
  955. if not assigned(resulttype.def) then
  956. begin
  957. case nodetype of
  958. ltn,lten,gtn,gten,equaln,unequaln :
  959. resulttype:=booltype;
  960. slashn :
  961. resulttype:=pbestrealtype^;
  962. addn:
  963. begin
  964. { for strings, return is always a 255 char string }
  965. if is_shortstring(left.resulttype.def) then
  966. resulttype:=cshortstringtype
  967. else
  968. resulttype:=left.resulttype;
  969. end;
  970. else
  971. resulttype:=left.resulttype;
  972. end;
  973. end;
  974. end;
  975. function taddnode.pass_1 : tnode;
  976. var
  977. hp : tnode;
  978. lt,rt : tnodetype;
  979. rd,ld : tdef;
  980. begin
  981. result:=nil;
  982. { first do the two subtrees }
  983. firstpass(left);
  984. firstpass(right);
  985. if codegenerror then
  986. exit;
  987. { load easier access variables }
  988. rd:=right.resulttype.def;
  989. ld:=left.resulttype.def;
  990. rt:=right.nodetype;
  991. lt:=left.nodetype;
  992. { int/int gives real/real! }
  993. if nodetype=slashn then
  994. begin
  995. { maybe we need an integer register to save }
  996. { a reference }
  997. if ((left.location.loc<>LOC_FPU) or
  998. (right.location.loc<>LOC_FPU)) and
  999. (left.registers32=right.registers32) then
  1000. calcregisters(self,1,1,0)
  1001. else
  1002. calcregisters(self,0,1,0);
  1003. location.loc:=LOC_FPU;
  1004. end
  1005. { if both are orddefs then check sub types }
  1006. else if (ld.deftype=orddef) and (rd.deftype=orddef) then
  1007. begin
  1008. { 2 booleans ? }
  1009. if is_boolean(ld) and is_boolean(rd) then
  1010. begin
  1011. if not(cs_full_boolean_eval in aktlocalswitches) and
  1012. (nodetype in [andn,orn]) then
  1013. begin
  1014. calcregisters(self,0,0,0);
  1015. location.loc:=LOC_JUMP;
  1016. end
  1017. else
  1018. begin
  1019. if (left.location.loc in [LOC_JUMP,LOC_FLAGS]) and
  1020. (left.location.loc in [LOC_JUMP,LOC_FLAGS]) then
  1021. calcregisters(self,2,0,0)
  1022. else
  1023. calcregisters(self,1,0,0);
  1024. end;
  1025. end
  1026. else
  1027. { Both are chars? only convert to shortstrings for addn }
  1028. if is_char(ld) then
  1029. begin
  1030. if nodetype=addn then
  1031. internalerror(200103291);
  1032. calcregisters(self,1,0,0);
  1033. end
  1034. { is there a 64 bit type ? }
  1035. else if (torddef(ld).typ in [s64bit,u64bit]) then
  1036. calcregisters(self,2,0,0)
  1037. { is there a cardinal? }
  1038. else if (torddef(ld).typ=u32bit) then
  1039. begin
  1040. calcregisters(self,1,0,0);
  1041. { for unsigned mul we need an extra register }
  1042. if nodetype=muln then
  1043. inc(registers32);
  1044. end
  1045. { generic s32bit conversion }
  1046. else
  1047. calcregisters(self,1,0,0);
  1048. end
  1049. { left side a setdef, must be before string processing,
  1050. else array constructor can be seen as array of char (PFV) }
  1051. else if (ld.deftype=setdef) then
  1052. begin
  1053. if tsetdef(ld).settype=smallset then
  1054. begin
  1055. { are we adding set elements ? }
  1056. if right.nodetype=setelementn then
  1057. calcregisters(self,2,0,0)
  1058. else
  1059. calcregisters(self,1,0,0);
  1060. location.loc:=LOC_REGISTER;
  1061. end
  1062. else
  1063. begin
  1064. calcregisters(self,0,0,0);
  1065. { here we call SET... }
  1066. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1067. location.loc:=LOC_MEM;
  1068. end;
  1069. end
  1070. { compare pchar by addresses like BP/Delphi }
  1071. else if is_pchar(ld) then
  1072. begin
  1073. location.loc:=LOC_REGISTER;
  1074. calcregisters(self,1,0,0);
  1075. end
  1076. { is one of the operands a string }
  1077. else if (ld.deftype=stringdef) then
  1078. begin
  1079. if is_widestring(ld) then
  1080. begin
  1081. { we use reference counted widestrings so no fast exit here }
  1082. procinfo^.no_fast_exit:=true;
  1083. { this is only for add, the comparisaion is handled later }
  1084. location.loc:=LOC_REGISTER;
  1085. end
  1086. else if is_ansistring(ld) then
  1087. begin
  1088. { we use ansistrings so no fast exit here }
  1089. procinfo^.no_fast_exit:=true;
  1090. { this is only for add, the comparisaion is handled later }
  1091. location.loc:=LOC_REGISTER;
  1092. end
  1093. else if is_longstring(ld) then
  1094. begin
  1095. { this is only for add, the comparisaion is handled later }
  1096. location.loc:=LOC_MEM;
  1097. end
  1098. else
  1099. begin
  1100. if canbeaddsstringcharoptnode(self) then
  1101. begin
  1102. hp := genaddsstringcharoptnode(self);
  1103. firstpass(hp);
  1104. pass_1 := hp;
  1105. exit;
  1106. end
  1107. else
  1108. begin
  1109. { Fix right to be shortstring }
  1110. if is_char(right.resulttype.def) then
  1111. begin
  1112. inserttypeconv(right,cshortstringtype);
  1113. firstpass(right);
  1114. end;
  1115. end;
  1116. if canbeaddsstringcsstringoptnode(self) then
  1117. begin
  1118. hp := genaddsstringcsstringoptnode(self);
  1119. firstpass(hp);
  1120. pass_1 := hp;
  1121. exit;
  1122. end;
  1123. { this is only for add, the comparisaion is handled later }
  1124. location.loc:=LOC_MEM;
  1125. end;
  1126. { here we call STRCONCAT or STRCMP or STRCOPY }
  1127. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1128. if location.loc=LOC_MEM then
  1129. calcregisters(self,0,0,0)
  1130. else
  1131. calcregisters(self,1,0,0);
  1132. end
  1133. { is one a real float ? }
  1134. else if (rd.deftype=floatdef) or (ld.deftype=floatdef) then
  1135. begin
  1136. calcregisters(self,0,1,0);
  1137. location.loc:=LOC_FPU;
  1138. end
  1139. { pointer comperation and subtraction }
  1140. else if (ld.deftype=pointerdef) then
  1141. begin
  1142. location.loc:=LOC_REGISTER;
  1143. calcregisters(self,1,0,0);
  1144. end
  1145. else if is_class_or_interface(ld) then
  1146. begin
  1147. location.loc:=LOC_REGISTER;
  1148. calcregisters(self,1,0,0);
  1149. end
  1150. else if (ld.deftype=classrefdef) then
  1151. begin
  1152. location.loc:=LOC_REGISTER;
  1153. calcregisters(self,1,0,0);
  1154. end
  1155. { support procvar=nil,procvar<>nil }
  1156. else if ((ld.deftype=procvardef) and (rt=niln)) or
  1157. ((rd.deftype=procvardef) and (lt=niln)) then
  1158. begin
  1159. calcregisters(self,1,0,0);
  1160. location.loc:=LOC_REGISTER;
  1161. end
  1162. {$ifdef SUPPORT_MMX}
  1163. { mmx support, this must be before the zero based array
  1164. check }
  1165. else if (cs_mmx in aktlocalswitches) and is_mmx_able_array(ld) and
  1166. is_mmx_able_array(rd) then
  1167. begin
  1168. location.loc:=LOC_MMXREGISTER;
  1169. calcregisters(self,0,0,1);
  1170. end
  1171. {$endif SUPPORT_MMX}
  1172. else if (rd.deftype=pointerdef) or (ld.deftype=pointerdef) then
  1173. begin
  1174. location.loc:=LOC_REGISTER;
  1175. calcregisters(self,1,0,0);
  1176. end
  1177. else if (rd.deftype=procvardef) and (ld.deftype=procvardef) and is_equal(rd,ld) then
  1178. begin
  1179. calcregisters(self,1,0,0);
  1180. location.loc:=LOC_REGISTER;
  1181. end
  1182. else if (ld.deftype=enumdef) then
  1183. begin
  1184. calcregisters(self,1,0,0);
  1185. end
  1186. {$ifdef SUPPORT_MMX}
  1187. else if (cs_mmx in aktlocalswitches) and
  1188. is_mmx_able_array(ld) and
  1189. is_mmx_able_array(rd) then
  1190. begin
  1191. location.loc:=LOC_MMXREGISTER;
  1192. calcregisters(self,0,0,1);
  1193. end
  1194. {$endif SUPPORT_MMX}
  1195. { the general solution is to convert to 32 bit int }
  1196. else
  1197. begin
  1198. calcregisters(self,1,0,0);
  1199. location.loc:=LOC_REGISTER;
  1200. end;
  1201. case nodetype of
  1202. ltn,lten,gtn,gten,equaln,unequaln:
  1203. begin
  1204. if is_64bitint(left.resulttype.def) then
  1205. location.loc:=LOC_JUMP
  1206. else
  1207. location.loc:=LOC_FLAGS;
  1208. end;
  1209. xorn:
  1210. begin
  1211. location.loc:=LOC_REGISTER;
  1212. end;
  1213. end;
  1214. end;
  1215. begin
  1216. caddnode:=taddnode;
  1217. end.
  1218. {
  1219. $Log$
  1220. Revision 1.30 2001-06-04 21:41:26 peter
  1221. * readded generic conversion to s32bit that i removed yesterday. It
  1222. is still used for error recovery, added a small note about that
  1223. Revision 1.29 2001/06/04 18:13:53 peter
  1224. * Support kylix hack of having enum+integer in a enum declaration.
  1225. Revision 1.28 2001/05/27 14:30:55 florian
  1226. + some widestring stuff added
  1227. Revision 1.27 2001/05/19 21:11:50 peter
  1228. * first check for overloaded operator before doing inserting any
  1229. typeconvs
  1230. Revision 1.26 2001/05/19 12:53:52 peter
  1231. * check set types when doing constant set evaluation
  1232. Revision 1.25 2001/04/13 01:22:08 peter
  1233. * symtable change to classes
  1234. * range check generation and errors fixed, make cycle DEBUG=1 works
  1235. * memory leaks fixed
  1236. Revision 1.24 2001/04/04 22:42:39 peter
  1237. * move constant folding into det_resulttype
  1238. Revision 1.23 2001/04/02 21:20:30 peter
  1239. * resulttype rewrite
  1240. Revision 1.22 2001/02/04 11:12:17 jonas
  1241. * fixed web bug 1377 & const pointer arithmtic
  1242. Revision 1.21 2001/01/14 22:13:13 peter
  1243. * constant calculation fixed. The type of the new constant is now
  1244. defined after the calculation is done. This should remove a lot
  1245. of wrong warnings (and errors with -Cr).
  1246. Revision 1.20 2000/12/31 11:14:10 jonas
  1247. + implemented/fixed docompare() mathods for all nodes (not tested)
  1248. + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
  1249. and constant strings/chars together
  1250. * n386add.pas: don't copy temp strings (of size 256) to another temp string
  1251. when adding
  1252. Revision 1.19 2000/12/16 15:55:32 jonas
  1253. + warning when there is a chance to get a range check error because of
  1254. automatic type conversion to u32bit
  1255. * arithmetic operations with a cardinal and a signed operand are carried
  1256. out in 64bit when range checking is on ("merged" from fixes branch)
  1257. Revision 1.18 2000/11/29 00:30:31 florian
  1258. * unused units removed from uses clause
  1259. * some changes for widestrings
  1260. Revision 1.17 2000/11/20 15:30:42 jonas
  1261. * changed types of values used for constant expression evaluation to
  1262. tconstexprint
  1263. Revision 1.16 2000/11/13 11:30:55 florian
  1264. * some bugs with interfaces and NIL fixed
  1265. Revision 1.15 2000/11/04 14:25:20 florian
  1266. + merged Attila's changes for interfaces, not tested yet
  1267. Revision 1.14 2000/10/31 22:02:47 peter
  1268. * symtable splitted, no real code changes
  1269. Revision 1.13 2000/10/14 10:14:50 peter
  1270. * moehrendorf oct 2000 rewrite
  1271. Revision 1.12 2000/10/01 19:48:23 peter
  1272. * lot of compile updates for cg11
  1273. Revision 1.11 2000/09/30 16:08:45 peter
  1274. * more cg11 updates
  1275. Revision 1.10 2000/09/28 19:49:52 florian
  1276. *** empty log message ***
  1277. Revision 1.9 2000/09/27 21:33:22 florian
  1278. * finally nadd.pas compiles
  1279. Revision 1.8 2000/09/27 20:25:44 florian
  1280. * more stuff fixed
  1281. Revision 1.7 2000/09/27 18:14:31 florian
  1282. * fixed a lot of syntax errors in the n*.pas stuff
  1283. Revision 1.6 2000/09/24 15:06:19 peter
  1284. * use defines.inc
  1285. Revision 1.5 2000/09/22 22:42:52 florian
  1286. * more fixes
  1287. Revision 1.4 2000/09/21 12:22:42 jonas
  1288. * put piece of code between -dnewoptimizations2 since it wasn't
  1289. necessary otherwise
  1290. + support for full boolean evaluation (from tcadd)
  1291. Revision 1.3 2000/09/20 21:50:59 florian
  1292. * updated
  1293. Revision 1.2 2000/08/29 08:24:45 jonas
  1294. * some modifications to -dcardinalmulfix code
  1295. Revision 1.1 2000/08/26 12:24:20 florian
  1296. * initial release
  1297. }