nadd.pas 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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 fpcdefs.inc}
  20. { define addstringopt}
  21. interface
  22. uses
  23. node;
  24. type
  25. taddnode = class(tbinopnode)
  26. constructor create(tt : tnodetype;l,r : tnode);override;
  27. function pass_1 : tnode;override;
  28. function det_resulttype:tnode;override;
  29. {$ifdef state_tracking}
  30. function track_state_pass(exec_known:boolean):boolean;override;
  31. {$endif}
  32. protected
  33. { override the following if you want to implement }
  34. { parts explicitely in the code generator (JM) }
  35. function first_addstring: tnode; virtual;
  36. function first_addset: tnode; virtual;
  37. { only implements "muln" nodes, the rest always has to be done in }
  38. { the code generator for performance reasons (JM) }
  39. function first_add64bitint: tnode; virtual;
  40. {$ifdef cpufpemu}
  41. { This routine calls internal runtime library helpers
  42. for all floating point arithmetic in the case
  43. where the emulation switches is on. Otherwise
  44. returns nil, and everything must be done in
  45. the code generation phase.
  46. }
  47. function first_addfloat : tnode; virtual;
  48. {$endif cpufpemu}
  49. end;
  50. taddnodeclass = class of taddnode;
  51. var
  52. { caddnode is used to create nodes of the add type }
  53. { the virtual constructor allows to assign }
  54. { another class type to caddnode => processor }
  55. { specific node types can be created }
  56. caddnode : taddnodeclass;
  57. implementation
  58. uses
  59. globtype,systems,
  60. cutils,verbose,globals,widestr,
  61. symconst,symtype,symdef,symsym,symtable,defutil,defcmp,
  62. cgbase,
  63. htypechk,pass_1,
  64. nbas,nmat,ncnv,ncon,nset,nopt,ncal,ninl,
  65. {$ifdef state_tracking}
  66. nstate,
  67. {$endif}
  68. cpuinfo,procinfo;
  69. {*****************************************************************************
  70. TADDNODE
  71. *****************************************************************************}
  72. {$ifdef fpc}
  73. {$maxfpuregisters 0}
  74. {$endif fpc}
  75. constructor taddnode.create(tt : tnodetype;l,r : tnode);
  76. begin
  77. inherited create(tt,l,r);
  78. end;
  79. function taddnode.det_resulttype:tnode;
  80. var
  81. hp,t : tnode;
  82. lt,rt : tnodetype;
  83. rd,ld : tdef;
  84. htype : ttype;
  85. ot : tnodetype;
  86. concatstrings : boolean;
  87. resultset : Tconstset;
  88. i : longint;
  89. b : boolean;
  90. s1,s2 : pchar;
  91. ws1,ws2 : pcompilerwidestring;
  92. l1,l2 : longint;
  93. rv,lv : tconstexprint;
  94. rvd,lvd : bestreal;
  95. resultrealtype : ttype;
  96. {$ifdef state_tracking}
  97. factval : Tnode;
  98. change : boolean;
  99. {$endif}
  100. begin
  101. result:=nil;
  102. { first do the two subtrees }
  103. resulttypepass(left);
  104. resulttypepass(right);
  105. { both left and right need to be valid }
  106. set_varstate(left,vs_used,true);
  107. set_varstate(right,vs_used,true);
  108. if codegenerror then
  109. exit;
  110. { convert array constructors to sets, because there is no other operator
  111. possible for array constructors }
  112. if is_array_constructor(left.resulttype.def) then
  113. begin
  114. arrayconstructor_to_set(left);
  115. resulttypepass(left);
  116. end;
  117. if is_array_constructor(right.resulttype.def) then
  118. begin
  119. arrayconstructor_to_set(right);
  120. resulttypepass(right);
  121. end;
  122. { allow operator overloading }
  123. hp:=self;
  124. if isbinaryoverloaded(hp) then
  125. begin
  126. result:=hp;
  127. exit;
  128. end;
  129. { Stop checking when an error was found in the operator checking }
  130. if codegenerror then
  131. begin
  132. result:=cerrornode.create;
  133. exit;
  134. end;
  135. { Kylix allows enum+ordconstn in an enum declaration (blocktype
  136. is bt_type), we need to do the conversion here before the
  137. constant folding }
  138. if (m_delphi in aktmodeswitches) and
  139. (blocktype=bt_type) then
  140. begin
  141. if (left.resulttype.def.deftype=enumdef) and
  142. (right.resulttype.def.deftype=orddef) then
  143. begin
  144. { insert explicit typecast to s32bit }
  145. left:=ctypeconvnode.create_explicit(left,s32bittype);
  146. resulttypepass(left);
  147. end
  148. else
  149. if (left.resulttype.def.deftype=orddef) and
  150. (right.resulttype.def.deftype=enumdef) then
  151. begin
  152. { insert explicit typecast to s32bit }
  153. right:=ctypeconvnode.create_explicit(right,s32bittype);
  154. resulttypepass(right);
  155. end;
  156. end;
  157. { is one a real float, then both need to be floats, this
  158. need to be done before the constant folding so constant
  159. operation on a float and int are also handled }
  160. resultrealtype:=pbestrealtype^;
  161. if (right.resulttype.def.deftype=floatdef) or (left.resulttype.def.deftype=floatdef) then
  162. begin
  163. { when both floattypes are already equal then use that
  164. floattype for results }
  165. if (right.resulttype.def.deftype=floatdef) and
  166. (left.resulttype.def.deftype=floatdef) and
  167. (tfloatdef(left.resulttype.def).typ=tfloatdef(right.resulttype.def).typ) then
  168. resultrealtype:=left.resulttype
  169. { when there is a currency type then use currency, but
  170. only when currency is defined as float }
  171. else
  172. if (s64currencytype.def.deftype=floatdef) and
  173. (is_currency(right.resulttype.def) or
  174. is_currency(left.resulttype.def)) then
  175. begin
  176. resultrealtype:=s64currencytype;
  177. inserttypeconv(right,resultrealtype);
  178. inserttypeconv(left,resultrealtype);
  179. end
  180. else
  181. begin
  182. inserttypeconv(right,resultrealtype);
  183. inserttypeconv(left,resultrealtype);
  184. end;
  185. end;
  186. { if one operand is a widechar or a widestring, both operands }
  187. { are converted to widestring. This must be done before constant }
  188. { folding to allow char+widechar etc. }
  189. if is_widestring(right.resulttype.def) or
  190. is_widestring(left.resulttype.def) or
  191. is_widechar(right.resulttype.def) or
  192. is_widechar(left.resulttype.def) then
  193. begin
  194. inserttypeconv(right,cwidestringtype);
  195. inserttypeconv(left,cwidestringtype);
  196. end;
  197. { load easier access variables }
  198. rd:=right.resulttype.def;
  199. ld:=left.resulttype.def;
  200. rt:=right.nodetype;
  201. lt:=left.nodetype;
  202. if (nodetype = slashn) and
  203. (((rt = ordconstn) and
  204. (tordconstnode(right).value = 0)) or
  205. ((rt = realconstn) and
  206. (trealconstnode(right).value_real = 0.0))) then
  207. begin
  208. if (cs_check_range in aktlocalswitches) or
  209. (cs_check_overflow in aktlocalswitches) then
  210. begin
  211. result:=crealconstnode.create(1,pbestrealtype^);
  212. Message(parser_e_division_by_zero);
  213. exit;
  214. end;
  215. end;
  216. { both are int constants }
  217. if ((is_constintnode(left) and is_constintnode(right)) or
  218. (is_constboolnode(left) and is_constboolnode(right) and
  219. (nodetype in [slashn,ltn,lten,gtn,gten,equaln,unequaln,andn,xorn,orn])) or
  220. (is_constenumnode(left) and is_constenumnode(right) and
  221. (nodetype in [equaln,unequaln,ltn,lten,gtn,gten]))) or
  222. { support pointer arithmetics on constants (JM) }
  223. ((lt = pointerconstn) and is_constintnode(right) and
  224. (nodetype in [addn,subn])) or
  225. (((lt = pointerconstn) or (lt = niln)) and
  226. ((rt = pointerconstn) or (rt = niln)) and
  227. (nodetype in [ltn,lten,gtn,gten,equaln,unequaln,subn])) then
  228. begin
  229. { when comparing/substracting pointers, make sure they are }
  230. { of the same type (JM) }
  231. if (lt = pointerconstn) and (rt = pointerconstn) then
  232. begin
  233. if not(cs_extsyntax in aktmoduleswitches) and
  234. not(nodetype in [equaln,unequaln]) then
  235. CGMessage(type_e_mismatch)
  236. else
  237. if (nodetype <> subn) and
  238. is_voidpointer(rd) then
  239. inserttypeconv(right,left.resulttype)
  240. else if (nodetype <> subn) and
  241. is_voidpointer(ld) then
  242. inserttypeconv(left,right.resulttype)
  243. else if not(equal_defs(ld,rd)) then
  244. IncompatibleTypes(ld,rd);
  245. end
  246. else if (ld.deftype=enumdef) and (rd.deftype=enumdef) then
  247. begin
  248. if not(equal_defs(ld,rd)) then
  249. inserttypeconv(right,left.resulttype);
  250. end
  251. else if (lt=ordconstn) and (rt=ordconstn) then
  252. begin
  253. { make left const type the biggest (u32bit is bigger than
  254. s32bit for or,and,xor) }
  255. if (rd.size>ld.size) or
  256. ((torddef(rd).typ=u32bit) and
  257. (torddef(ld).typ=s32bit) and
  258. (nodetype in [orn,andn,xorn])) then
  259. inserttypeconv(left,right.resulttype);
  260. end;
  261. { load values }
  262. case lt of
  263. ordconstn:
  264. lv:=tordconstnode(left).value;
  265. pointerconstn:
  266. lv:=tpointerconstnode(left).value;
  267. niln:
  268. lv:=0;
  269. else
  270. internalerror(2002080202);
  271. end;
  272. case rt of
  273. ordconstn:
  274. rv:=tordconstnode(right).value;
  275. pointerconstn:
  276. rv:=tpointerconstnode(right).value;
  277. niln:
  278. rv:=0;
  279. else
  280. internalerror(2002080203);
  281. end;
  282. if (lt = pointerconstn) and
  283. (rt <> pointerconstn) then
  284. rv := rv * tpointerdef(left.resulttype.def).pointertype.def.size;
  285. if (rt = pointerconstn) and
  286. (lt <> pointerconstn) then
  287. lv := lv * tpointerdef(right.resulttype.def).pointertype.def.size;
  288. case nodetype of
  289. addn :
  290. if (lt <> pointerconstn) then
  291. t := genintconstnode(lv+rv)
  292. else
  293. t := cpointerconstnode.create(lv+rv,left.resulttype);
  294. subn :
  295. if (lt <> pointerconstn) or (rt = pointerconstn) then
  296. t := genintconstnode(lv-rv)
  297. else
  298. t := cpointerconstnode.create(lv-rv,left.resulttype);
  299. muln :
  300. if (torddef(ld).typ <> u64bit) or
  301. (torddef(rd).typ <> u64bit) then
  302. t:=genintconstnode(lv*rv)
  303. else
  304. t:=genintconstnode(int64(qword(lv)*qword(rv)));
  305. xorn :
  306. t:=cordconstnode.create(lv xor rv,left.resulttype,true);
  307. orn :
  308. t:=cordconstnode.create(lv or rv,left.resulttype,true);
  309. andn :
  310. t:=cordconstnode.create(lv and rv,left.resulttype,true);
  311. ltn :
  312. t:=cordconstnode.create(ord(lv<rv),booltype,true);
  313. lten :
  314. t:=cordconstnode.create(ord(lv<=rv),booltype,true);
  315. gtn :
  316. t:=cordconstnode.create(ord(lv>rv),booltype,true);
  317. gten :
  318. t:=cordconstnode.create(ord(lv>=rv),booltype,true);
  319. equaln :
  320. t:=cordconstnode.create(ord(lv=rv),booltype,true);
  321. unequaln :
  322. t:=cordconstnode.create(ord(lv<>rv),booltype,true);
  323. slashn :
  324. begin
  325. { int/int becomes a real }
  326. rvd:=rv;
  327. lvd:=lv;
  328. t:=crealconstnode.create(lvd/rvd,resultrealtype);
  329. end;
  330. else
  331. begin
  332. CGMessage(type_e_mismatch);
  333. t:=cnothingnode.create;
  334. end;
  335. end;
  336. result:=t;
  337. exit;
  338. end;
  339. { both real constants ? }
  340. if (lt=realconstn) and (rt=realconstn) then
  341. begin
  342. lvd:=trealconstnode(left).value_real;
  343. rvd:=trealconstnode(right).value_real;
  344. case nodetype of
  345. addn :
  346. t:=crealconstnode.create(lvd+rvd,resultrealtype);
  347. subn :
  348. t:=crealconstnode.create(lvd-rvd,resultrealtype);
  349. muln :
  350. t:=crealconstnode.create(lvd*rvd,resultrealtype);
  351. starstarn,
  352. caretn :
  353. begin
  354. if lvd<0 then
  355. begin
  356. Message(parser_e_invalid_float_operation);
  357. t:=crealconstnode.create(0,resultrealtype);
  358. end
  359. else if lvd=0 then
  360. t:=crealconstnode.create(1.0,resultrealtype)
  361. else
  362. t:=crealconstnode.create(exp(ln(lvd)*rvd),resultrealtype);
  363. end;
  364. slashn :
  365. t:=crealconstnode.create(lvd/rvd,resultrealtype);
  366. ltn :
  367. t:=cordconstnode.create(ord(lvd<rvd),booltype,true);
  368. lten :
  369. t:=cordconstnode.create(ord(lvd<=rvd),booltype,true);
  370. gtn :
  371. t:=cordconstnode.create(ord(lvd>rvd),booltype,true);
  372. gten :
  373. t:=cordconstnode.create(ord(lvd>=rvd),booltype,true);
  374. equaln :
  375. t:=cordconstnode.create(ord(lvd=rvd),booltype,true);
  376. unequaln :
  377. t:=cordconstnode.create(ord(lvd<>rvd),booltype,true);
  378. else
  379. begin
  380. CGMessage(type_e_mismatch);
  381. t:=cnothingnode.create;
  382. end;
  383. end;
  384. result:=t;
  385. exit;
  386. end;
  387. { first, we handle widestrings, so we can check later for }
  388. { stringconstn only }
  389. { widechars are converted above to widestrings too }
  390. { this isn't veryy efficient, but I don't think }
  391. { that it does matter that much (FK) }
  392. if (lt=stringconstn) and (rt=stringconstn) and
  393. (tstringconstnode(left).st_type=st_widestring) and
  394. (tstringconstnode(right).st_type=st_widestring) then
  395. begin
  396. initwidestring(ws1);
  397. initwidestring(ws2);
  398. copywidestring(pcompilerwidestring(tstringconstnode(left).value_str),ws1);
  399. copywidestring(pcompilerwidestring(tstringconstnode(right).value_str),ws2);
  400. case nodetype of
  401. addn :
  402. begin
  403. concatwidestrings(ws1,ws2);
  404. t:=cstringconstnode.createwstr(ws1);
  405. end;
  406. ltn :
  407. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<0),booltype,true);
  408. lten :
  409. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<=0),booltype,true);
  410. gtn :
  411. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)>0),booltype,true);
  412. gten :
  413. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)>=0),booltype,true);
  414. equaln :
  415. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)=0),booltype,true);
  416. unequaln :
  417. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<>0),booltype,true);
  418. else
  419. begin
  420. CGMessage(type_e_mismatch);
  421. t:=cnothingnode.create;
  422. end;
  423. end;
  424. donewidestring(ws1);
  425. donewidestring(ws2);
  426. result:=t;
  427. exit;
  428. end;
  429. { concating strings ? }
  430. concatstrings:=false;
  431. s1:=nil;
  432. s2:=nil;
  433. if (lt=ordconstn) and (rt=ordconstn) and
  434. is_char(ld) and is_char(rd) then
  435. begin
  436. s1:=strpnew(char(byte(tordconstnode(left).value)));
  437. s2:=strpnew(char(byte(tordconstnode(right).value)));
  438. l1:=1;
  439. l2:=1;
  440. concatstrings:=true;
  441. end
  442. else
  443. if (lt=stringconstn) and (rt=ordconstn) and is_char(rd) then
  444. begin
  445. s1:=tstringconstnode(left).getpcharcopy;
  446. l1:=tstringconstnode(left).len;
  447. s2:=strpnew(char(byte(tordconstnode(right).value)));
  448. l2:=1;
  449. concatstrings:=true;
  450. end
  451. else
  452. if (lt=ordconstn) and (rt=stringconstn) and is_char(ld) then
  453. begin
  454. s1:=strpnew(char(byte(tordconstnode(left).value)));
  455. l1:=1;
  456. s2:=tstringconstnode(right).getpcharcopy;
  457. l2:=tstringconstnode(right).len;
  458. concatstrings:=true;
  459. end
  460. else if (lt=stringconstn) and (rt=stringconstn) then
  461. begin
  462. s1:=tstringconstnode(left).getpcharcopy;
  463. l1:=tstringconstnode(left).len;
  464. s2:=tstringconstnode(right).getpcharcopy;
  465. l2:=tstringconstnode(right).len;
  466. concatstrings:=true;
  467. end;
  468. if concatstrings then
  469. begin
  470. case nodetype of
  471. addn :
  472. t:=cstringconstnode.createpchar(concatansistrings(s1,s2,l1,l2),l1+l2);
  473. ltn :
  474. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<0),booltype,true);
  475. lten :
  476. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<=0),booltype,true);
  477. gtn :
  478. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)>0),booltype,true);
  479. gten :
  480. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)>=0),booltype,true);
  481. equaln :
  482. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)=0),booltype,true);
  483. unequaln :
  484. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<>0),booltype,true);
  485. end;
  486. ansistringdispose(s1,l1);
  487. ansistringdispose(s2,l2);
  488. result:=t;
  489. exit;
  490. end;
  491. { set constant evaluation }
  492. if (right.nodetype=setconstn) and
  493. not assigned(tsetconstnode(right).left) and
  494. (left.nodetype=setconstn) and
  495. not assigned(tsetconstnode(left).left) then
  496. begin
  497. { check if size adjusting is needed, only for left
  498. to right as the other way is checked in the typeconv }
  499. if (tsetdef(right.resulttype.def).settype=smallset) and
  500. (tsetdef(left.resulttype.def).settype<>smallset) then
  501. right.resulttype.setdef(tsetdef.create(tsetdef(right.resulttype.def).elementtype,255));
  502. { check base types }
  503. inserttypeconv(left,right.resulttype);
  504. if codegenerror then
  505. begin
  506. { recover by only returning the left part }
  507. result:=left;
  508. left:=nil;
  509. exit;
  510. end;
  511. case nodetype of
  512. addn :
  513. begin
  514. resultset:=tsetconstnode(right).value_set^ + tsetconstnode(left).value_set^;
  515. t:=csetconstnode.create(@resultset,left.resulttype);
  516. end;
  517. muln :
  518. begin
  519. resultset:=tsetconstnode(right).value_set^ * tsetconstnode(left).value_set^;
  520. t:=csetconstnode.create(@resultset,left.resulttype);
  521. end;
  522. subn :
  523. begin
  524. resultset:=tsetconstnode(left).value_set^ - tsetconstnode(right).value_set^;
  525. t:=csetconstnode.create(@resultset,left.resulttype);
  526. end;
  527. symdifn :
  528. begin
  529. resultset:=tsetconstnode(right).value_set^ >< tsetconstnode(left).value_set^;
  530. t:=csetconstnode.create(@resultset,left.resulttype);
  531. end;
  532. unequaln :
  533. begin
  534. b:=tsetconstnode(right).value_set^ <> tsetconstnode(left).value_set^;
  535. t:=cordconstnode.create(byte(b),booltype,true);
  536. end;
  537. equaln :
  538. begin
  539. b:=tsetconstnode(right).value_set^ = tsetconstnode(left).value_set^;
  540. t:=cordconstnode.create(byte(b),booltype,true);
  541. end;
  542. lten :
  543. begin
  544. b:=tsetconstnode(left).value_set^ <= tsetconstnode(right).value_set^;
  545. t:=cordconstnode.create(byte(b),booltype,true);
  546. end;
  547. gten :
  548. begin
  549. b:=tsetconstnode(left).value_set^ >= tsetconstnode(right).value_set^;
  550. t:=cordconstnode.create(byte(b),booltype,true);
  551. end;
  552. end;
  553. result:=t;
  554. exit;
  555. end;
  556. { but an int/int gives real/real! }
  557. if nodetype=slashn then
  558. begin
  559. if (left.resulttype.def.deftype <> floatdef) and
  560. (right.resulttype.def.deftype <> floatdef) then
  561. CGMessage(type_h_use_div_for_int);
  562. inserttypeconv(right,resultrealtype);
  563. inserttypeconv(left,resultrealtype);
  564. end
  565. { if both are orddefs then check sub types }
  566. else if (ld.deftype=orddef) and (rd.deftype=orddef) then
  567. begin
  568. { optimize multiplacation by a power of 2 }
  569. if not(cs_check_overflow in aktlocalswitches) and
  570. (nodetype = muln) and
  571. (((left.nodetype = ordconstn) and
  572. ispowerof2(tordconstnode(left).value,i)) or
  573. ((right.nodetype = ordconstn) and
  574. ispowerof2(tordconstnode(right).value,i))) then
  575. begin
  576. if left.nodetype = ordconstn then
  577. begin
  578. tordconstnode(left).value := i;
  579. result := cshlshrnode.create(shln,right,left);
  580. end
  581. else
  582. begin
  583. tordconstnode(right).value := i;
  584. result := cshlshrnode.create(shln,left,right);
  585. end;
  586. left := nil;
  587. right := nil;
  588. exit;
  589. end;
  590. { 2 booleans? Make them equal to the largest boolean }
  591. if is_boolean(ld) and is_boolean(rd) then
  592. begin
  593. if torddef(left.resulttype.def).size>torddef(right.resulttype.def).size then
  594. begin
  595. right:=ctypeconvnode.create_explicit(right,left.resulttype);
  596. ttypeconvnode(right).convtype:=tc_bool_2_int;
  597. resulttypepass(right);
  598. end
  599. else if torddef(left.resulttype.def).size<torddef(right.resulttype.def).size then
  600. begin
  601. left:=ctypeconvnode.create_explicit(left,right.resulttype);
  602. ttypeconvnode(left).convtype:=tc_bool_2_int;
  603. resulttypepass(left);
  604. end;
  605. case nodetype of
  606. xorn,
  607. ltn,
  608. lten,
  609. gtn,
  610. gten,
  611. andn,
  612. orn:
  613. begin
  614. end;
  615. unequaln,
  616. equaln:
  617. begin
  618. if not(cs_full_boolean_eval in aktlocalswitches) then
  619. begin
  620. { Remove any compares with constants }
  621. if (left.nodetype=ordconstn) then
  622. begin
  623. hp:=right;
  624. b:=(tordconstnode(left).value<>0);
  625. ot:=nodetype;
  626. left.free;
  627. left:=nil;
  628. right:=nil;
  629. if (not(b) and (ot=equaln)) or
  630. (b and (ot=unequaln)) then
  631. begin
  632. hp:=cnotnode.create(hp);
  633. end;
  634. result:=hp;
  635. exit;
  636. end;
  637. if (right.nodetype=ordconstn) then
  638. begin
  639. hp:=left;
  640. b:=(tordconstnode(right).value<>0);
  641. ot:=nodetype;
  642. right.free;
  643. right:=nil;
  644. left:=nil;
  645. if (not(b) and (ot=equaln)) or
  646. (b and (ot=unequaln)) then
  647. begin
  648. hp:=cnotnode.create(hp);
  649. end;
  650. result:=hp;
  651. exit;
  652. end;
  653. end;
  654. end;
  655. else
  656. CGMessage(type_e_mismatch);
  657. end;
  658. end
  659. { Both are chars? }
  660. else if is_char(rd) and is_char(ld) then
  661. begin
  662. if nodetype=addn then
  663. begin
  664. resulttype:=cshortstringtype;
  665. if not(is_constcharnode(left) and is_constcharnode(right)) then
  666. begin
  667. inserttypeconv(left,cshortstringtype);
  668. {$ifdef addstringopt}
  669. hp := genaddsstringcharoptnode(self);
  670. result := hp;
  671. exit;
  672. {$endif addstringopt}
  673. end;
  674. end;
  675. end
  676. { is there a currency type ? }
  677. else if ((torddef(rd).typ=scurrency) or (torddef(ld).typ=scurrency)) then
  678. begin
  679. if (torddef(ld).typ<>scurrency) then
  680. inserttypeconv(left,s64currencytype);
  681. if (torddef(rd).typ<>scurrency) then
  682. inserttypeconv(right,s64currencytype);
  683. end
  684. { is there a signed 64 bit type ? }
  685. else if ((torddef(rd).typ=s64bit) or (torddef(ld).typ=s64bit)) then
  686. begin
  687. if (torddef(ld).typ<>s64bit) then
  688. inserttypeconv(left,cs64bittype);
  689. if (torddef(rd).typ<>s64bit) then
  690. inserttypeconv(right,cs64bittype);
  691. end
  692. { is there a unsigned 64 bit type ? }
  693. else if ((torddef(rd).typ=u64bit) or (torddef(ld).typ=u64bit)) then
  694. begin
  695. if (torddef(ld).typ<>u64bit) then
  696. inserttypeconv(left,cu64bittype);
  697. if (torddef(rd).typ<>u64bit) then
  698. inserttypeconv(right,cu64bittype);
  699. end
  700. { is there a cardinal? }
  701. else if ((torddef(rd).typ=u32bit) or (torddef(ld).typ=u32bit)) then
  702. begin
  703. { and,or,xor work on bit patterns and don't care
  704. about the sign }
  705. if nodetype in [andn,orn,xorn] then
  706. begin
  707. inserttypeconv_explicit(left,u32bittype);
  708. inserttypeconv_explicit(right,u32bittype);
  709. end
  710. else
  711. begin
  712. if is_signed(ld) and
  713. { then rd = u32bit }
  714. { convert positive constants to u32bit }
  715. not(is_constintnode(left) and
  716. (tordconstnode(left).value >= 0)) then
  717. begin
  718. { perform the operation in 64bit }
  719. CGMessage(type_w_mixed_signed_unsigned);
  720. inserttypeconv(left,cs64bittype);
  721. inserttypeconv(right,cs64bittype);
  722. end
  723. else
  724. begin
  725. if is_signed(ld) and
  726. not(is_constintnode(left) and
  727. (tordconstnode(left).value >= 0)) then
  728. CGMessage(type_w_mixed_signed_unsigned2);
  729. inserttypeconv(left,u32bittype);
  730. if is_signed(rd) and
  731. { then ld = u32bit }
  732. { convert positive constants to u32bit }
  733. not(is_constintnode(right) and
  734. (tordconstnode(right).value >= 0)) then
  735. begin
  736. { perform the operation in 64bit }
  737. CGMessage(type_w_mixed_signed_unsigned);
  738. inserttypeconv(left,cs64bittype);
  739. inserttypeconv(right,cs64bittype);
  740. end
  741. else
  742. begin
  743. if is_signed(rd) and
  744. not(is_constintnode(right) and
  745. (tordconstnode(right).value >= 0)) then
  746. CGMessage(type_w_mixed_signed_unsigned2);
  747. inserttypeconv(right,u32bittype);
  748. end;
  749. end;
  750. end;
  751. end
  752. { generic ord conversion is s32bit }
  753. else
  754. begin
  755. { if the left or right value is smaller than the normal
  756. type s32bittype and is unsigned, and the other value
  757. is a constant < 0, the result will always be false/true
  758. for equal / unequal nodes.
  759. }
  760. if (
  761. { left : unsigned ordinal var, right : < 0 constant }
  762. (
  763. ((is_signed(ld)=false) and (is_constintnode(left) =false)) and
  764. ((is_constintnode(right)) and (tordconstnode(right).value < 0))
  765. ) or
  766. { right : unsigned ordinal var, left : < 0 constant }
  767. (
  768. ((is_signed(rd)=false) and (is_constintnode(right) =false)) and
  769. ((is_constintnode(left)) and (tordconstnode(left).value < 0))
  770. )
  771. ) then
  772. begin
  773. if nodetype = equaln then
  774. CGMessage(type_w_signed_unsigned_always_false)
  775. else
  776. if nodetype = unequaln then
  777. CGMessage(type_w_signed_unsigned_always_true)
  778. else
  779. if (is_constintnode(left) and (nodetype in [ltn,lten])) or
  780. (is_constintnode(right) and (nodetype in [gtn,gten])) then
  781. CGMessage(type_w_signed_unsigned_always_true)
  782. else
  783. if (is_constintnode(right) and (nodetype in [ltn,lten])) or
  784. (is_constintnode(left) and (nodetype in [gtn,gten])) then
  785. CGMessage(type_w_signed_unsigned_always_false);
  786. end;
  787. inserttypeconv(right,s32bittype);
  788. inserttypeconv(left,s32bittype);
  789. end;
  790. end
  791. { if both are floatdefs, conversion is already done before constant folding }
  792. else if (ld.deftype=floatdef) then
  793. begin
  794. { already converted }
  795. end
  796. { left side a setdef, must be before string processing,
  797. else array constructor can be seen as array of char (PFV) }
  798. else if (ld.deftype=setdef) then
  799. begin
  800. { trying to add a set element? }
  801. if (nodetype=addn) and (rd.deftype<>setdef) then
  802. begin
  803. if (rt=setelementn) then
  804. begin
  805. if not(equal_defs(tsetdef(ld).elementtype.def,rd)) then
  806. CGMessage(type_e_set_element_are_not_comp);
  807. end
  808. else
  809. CGMessage(type_e_mismatch)
  810. end
  811. else
  812. begin
  813. if not(nodetype in [addn,subn,symdifn,muln,equaln,unequaln,lten,gten]) then
  814. CGMessage(type_e_set_operation_unknown);
  815. { right def must be a also be set }
  816. if (rd.deftype<>setdef) or not(equal_defs(rd,ld)) then
  817. CGMessage(type_e_set_element_are_not_comp);
  818. end;
  819. { ranges require normsets }
  820. if (tsetdef(ld).settype=smallset) and
  821. (rt=setelementn) and
  822. assigned(tsetelementnode(right).right) then
  823. begin
  824. { generate a temporary normset def, it'll be destroyed
  825. when the symtable is unloaded }
  826. htype.setdef(tsetdef.create(tsetdef(ld).elementtype,255));
  827. inserttypeconv(left,htype);
  828. end;
  829. { if the right side is also a setdef then the settype must
  830. be the same as the left setdef }
  831. if (rd.deftype=setdef) and
  832. (tsetdef(ld).settype<>tsetdef(rd).settype) then
  833. begin
  834. { when right is a normset we need to typecast both
  835. to normsets }
  836. if (tsetdef(rd).settype=normset) then
  837. inserttypeconv(left,right.resulttype)
  838. else
  839. inserttypeconv(right,left.resulttype);
  840. end;
  841. end
  842. { compare pchar to char arrays by addresses like BP/Delphi }
  843. else if ((is_pchar(ld) or (lt=niln)) and is_chararray(rd)) or
  844. ((is_pchar(rd) or (rt=niln)) and is_chararray(ld)) then
  845. begin
  846. if is_chararray(rd) then
  847. inserttypeconv(right,charpointertype)
  848. else
  849. inserttypeconv(left,charpointertype);
  850. end
  851. { pointer comparision and subtraction }
  852. else if (rd.deftype=pointerdef) and (ld.deftype=pointerdef) then
  853. begin
  854. case nodetype of
  855. equaln,unequaln :
  856. begin
  857. if is_voidpointer(right.resulttype.def) then
  858. inserttypeconv(right,left.resulttype)
  859. else if is_voidpointer(left.resulttype.def) then
  860. inserttypeconv(left,right.resulttype)
  861. else if not(equal_defs(ld,rd)) then
  862. IncompatibleTypes(ld,rd);
  863. end;
  864. ltn,lten,gtn,gten:
  865. begin
  866. if (cs_extsyntax in aktmoduleswitches) then
  867. begin
  868. if is_voidpointer(right.resulttype.def) then
  869. inserttypeconv(right,left.resulttype)
  870. else if is_voidpointer(left.resulttype.def) then
  871. inserttypeconv(left,right.resulttype)
  872. else if not(equal_defs(ld,rd)) then
  873. IncompatibleTypes(ld,rd);
  874. end
  875. else
  876. CGMessage(type_e_mismatch);
  877. end;
  878. subn:
  879. begin
  880. if (cs_extsyntax in aktmoduleswitches) then
  881. begin
  882. if is_voidpointer(right.resulttype.def) then
  883. inserttypeconv(right,left.resulttype)
  884. else if is_voidpointer(left.resulttype.def) then
  885. inserttypeconv(left,right.resulttype)
  886. else if not(equal_defs(ld,rd)) then
  887. IncompatibleTypes(ld,rd);
  888. end
  889. else
  890. CGMessage(type_e_mismatch);
  891. resulttype:=s32bittype;
  892. exit;
  893. end;
  894. addn:
  895. begin
  896. if (cs_extsyntax in aktmoduleswitches) then
  897. begin
  898. if is_voidpointer(right.resulttype.def) then
  899. inserttypeconv(right,left.resulttype)
  900. else if is_voidpointer(left.resulttype.def) then
  901. inserttypeconv(left,right.resulttype)
  902. else if not(equal_defs(ld,rd)) then
  903. IncompatibleTypes(ld,rd);
  904. end
  905. else
  906. CGMessage(type_e_mismatch);
  907. resulttype:=s32bittype;
  908. exit;
  909. end;
  910. else
  911. CGMessage(type_e_mismatch);
  912. end;
  913. end
  914. { is one of the operands a string?,
  915. chararrays are also handled as strings (after conversion), also take
  916. care of chararray+chararray and chararray+char.
  917. Note: Must be done after pointerdef+pointerdef has been checked, else
  918. pchar is converted to string }
  919. else if (rd.deftype=stringdef) or (ld.deftype=stringdef) or
  920. ((is_pchar(rd) or is_chararray(rd) or is_char(rd)) and
  921. (is_pchar(ld) or is_chararray(ld) or is_char(ld))) then
  922. begin
  923. if is_widestring(rd) or is_widestring(ld) then
  924. begin
  925. if not(is_widestring(rd)) then
  926. inserttypeconv(right,cwidestringtype);
  927. if not(is_widestring(ld)) then
  928. inserttypeconv(left,cwidestringtype);
  929. end
  930. else if is_ansistring(rd) or is_ansistring(ld) then
  931. begin
  932. if not(is_ansistring(rd)) then
  933. inserttypeconv(right,cansistringtype);
  934. if not(is_ansistring(ld)) then
  935. inserttypeconv(left,cansistringtype);
  936. end
  937. else if is_longstring(rd) or is_longstring(ld) then
  938. begin
  939. if not(is_longstring(rd)) then
  940. inserttypeconv(right,clongstringtype);
  941. if not(is_longstring(ld)) then
  942. inserttypeconv(left,clongstringtype);
  943. end
  944. else
  945. begin
  946. if not(is_shortstring(ld)) then
  947. inserttypeconv(left,cshortstringtype);
  948. { don't convert char, that can be handled by the optimized node }
  949. if not(is_shortstring(rd) or is_char(rd)) then
  950. inserttypeconv(right,cshortstringtype);
  951. end;
  952. end
  953. { class or interface equation }
  954. else if is_class_or_interface(rd) or is_class_or_interface(ld) then
  955. begin
  956. if is_class_or_interface(rd) and is_class_or_interface(ld) then
  957. begin
  958. if tobjectdef(rd).is_related(tobjectdef(ld)) then
  959. inserttypeconv(right,left.resulttype)
  960. else
  961. inserttypeconv(left,right.resulttype);
  962. end
  963. else if is_class_or_interface(rd) then
  964. inserttypeconv(left,right.resulttype)
  965. else
  966. inserttypeconv(right,left.resulttype);
  967. if not(nodetype in [equaln,unequaln]) then
  968. CGMessage(type_e_mismatch);
  969. end
  970. else if (rd.deftype=classrefdef) and (ld.deftype=classrefdef) then
  971. begin
  972. if tobjectdef(tclassrefdef(rd).pointertype.def).is_related(
  973. tobjectdef(tclassrefdef(ld).pointertype.def)) then
  974. inserttypeconv(right,left.resulttype)
  975. else
  976. inserttypeconv(left,right.resulttype);
  977. if not(nodetype in [equaln,unequaln]) then
  978. CGMessage(type_e_mismatch);
  979. end
  980. { allows comperasion with nil pointer }
  981. else if is_class_or_interface(rd) or (rd.deftype=classrefdef) then
  982. begin
  983. inserttypeconv(left,right.resulttype);
  984. if not(nodetype in [equaln,unequaln]) then
  985. CGMessage(type_e_mismatch);
  986. end
  987. else if is_class_or_interface(ld) or (ld.deftype=classrefdef) then
  988. begin
  989. inserttypeconv(right,left.resulttype);
  990. if not(nodetype in [equaln,unequaln]) then
  991. CGMessage(type_e_mismatch);
  992. end
  993. { support procvar=nil,procvar<>nil }
  994. else if ((ld.deftype=procvardef) and (rt=niln)) or
  995. ((rd.deftype=procvardef) and (lt=niln)) then
  996. begin
  997. if not(nodetype in [equaln,unequaln]) then
  998. CGMessage(type_e_mismatch);
  999. end
  1000. { support dynamicarray=nil,dynamicarray<>nil }
  1001. else if (is_dynamic_array(ld) and (rt=niln)) or
  1002. (is_dynamic_array(rd) and (lt=niln)) then
  1003. begin
  1004. if not(nodetype in [equaln,unequaln]) then
  1005. CGMessage(type_e_mismatch);
  1006. end
  1007. {$ifdef SUPPORT_MMX}
  1008. { mmx support, this must be before the zero based array
  1009. check }
  1010. else if (cs_mmx in aktlocalswitches) and
  1011. is_mmx_able_array(ld) and
  1012. is_mmx_able_array(rd) and
  1013. equal_defs(ld,rd) then
  1014. begin
  1015. case nodetype of
  1016. addn,subn,xorn,orn,andn:
  1017. ;
  1018. { mul is a little bit restricted }
  1019. muln:
  1020. if not(mmx_type(ld) in [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1021. CGMessage(type_e_mismatch);
  1022. else
  1023. CGMessage(type_e_mismatch);
  1024. end;
  1025. end
  1026. {$endif SUPPORT_MMX}
  1027. { this is a little bit dangerous, also the left type }
  1028. { pointer to should be checked! This broke the mmx support }
  1029. else if (rd.deftype=pointerdef) or is_zero_based_array(rd) then
  1030. begin
  1031. if is_zero_based_array(rd) then
  1032. begin
  1033. resulttype.setdef(tpointerdef.create(tarraydef(rd).elementtype));
  1034. inserttypeconv(right,resulttype);
  1035. end;
  1036. inserttypeconv(left,s32bittype);
  1037. if nodetype=addn then
  1038. begin
  1039. if not(cs_extsyntax in aktmoduleswitches) or
  1040. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1041. CGMessage(type_e_mismatch);
  1042. if (rd.deftype=pointerdef) and
  1043. (tpointerdef(rd).pointertype.def.size>1) then
  1044. left:=caddnode.create(muln,left,
  1045. cordconstnode.create(tpointerdef(rd).pointertype.def.size,s32bittype,true));
  1046. end
  1047. else
  1048. CGMessage(type_e_mismatch);
  1049. end
  1050. else if (ld.deftype=pointerdef) or is_zero_based_array(ld) then
  1051. begin
  1052. if is_zero_based_array(ld) then
  1053. begin
  1054. resulttype.setdef(tpointerdef.create(tarraydef(ld).elementtype));
  1055. inserttypeconv(left,resulttype);
  1056. end;
  1057. inserttypeconv(right,s32bittype);
  1058. if nodetype in [addn,subn] then
  1059. begin
  1060. if not(cs_extsyntax in aktmoduleswitches) or
  1061. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1062. CGMessage(type_e_mismatch);
  1063. if (ld.deftype=pointerdef) and
  1064. (tpointerdef(ld).pointertype.def.size>1) then
  1065. right:=caddnode.create(muln,right,
  1066. cordconstnode.create(tpointerdef(ld).pointertype.def.size,s32bittype,true));
  1067. end
  1068. else
  1069. CGMessage(type_e_mismatch);
  1070. end
  1071. else if (rd.deftype=procvardef) and
  1072. (ld.deftype=procvardef) and
  1073. equal_defs(rd,ld) then
  1074. begin
  1075. if not (nodetype in [equaln,unequaln]) then
  1076. CGMessage(type_e_mismatch);
  1077. end
  1078. { enums }
  1079. else if (ld.deftype=enumdef) and (rd.deftype=enumdef) then
  1080. begin
  1081. if not(equal_defs(ld,rd)) then
  1082. inserttypeconv(right,left.resulttype);
  1083. if not(nodetype in [equaln,unequaln,ltn,lten,gtn,gten]) then
  1084. CGMessage(type_e_mismatch);
  1085. end
  1086. { generic conversion, this is for error recovery }
  1087. else
  1088. begin
  1089. inserttypeconv(left,s32bittype);
  1090. inserttypeconv(right,s32bittype);
  1091. end;
  1092. { set resulttype if not already done }
  1093. if not assigned(resulttype.def) then
  1094. begin
  1095. case nodetype of
  1096. ltn,lten,gtn,gten,equaln,unequaln :
  1097. resulttype:=booltype;
  1098. slashn :
  1099. resulttype:=resultrealtype;
  1100. addn:
  1101. begin
  1102. { for strings, return is always a 255 char string }
  1103. if is_shortstring(left.resulttype.def) then
  1104. resulttype:=cshortstringtype
  1105. else
  1106. resulttype:=left.resulttype;
  1107. end;
  1108. else
  1109. resulttype:=left.resulttype;
  1110. end;
  1111. end;
  1112. { when the result is currency we need some extra code for
  1113. multiplication and division. this should not be done when
  1114. the muln or slashn node is created internally }
  1115. if not(nf_is_currency in flags) and
  1116. is_currency(resulttype.def) then
  1117. begin
  1118. case nodetype of
  1119. slashn :
  1120. begin
  1121. { slashn will only work with floats }
  1122. hp:=caddnode.create(muln,getcopy,crealconstnode.create(10000.0,s64currencytype));
  1123. include(hp.flags,nf_is_currency);
  1124. result:=hp;
  1125. end;
  1126. muln :
  1127. begin
  1128. if s64currencytype.def.deftype=floatdef then
  1129. hp:=caddnode.create(slashn,getcopy,crealconstnode.create(10000.0,s64currencytype))
  1130. else
  1131. hp:=cmoddivnode.create(divn,getcopy,cordconstnode.create(10000,s64currencytype,false));
  1132. include(hp.flags,nf_is_currency);
  1133. result:=hp
  1134. end;
  1135. end;
  1136. end;
  1137. end;
  1138. function taddnode.first_addstring: tnode;
  1139. var
  1140. p: tnode;
  1141. begin
  1142. { when we get here, we are sure that both the left and the right }
  1143. { node are both strings of the same stringtype (JM) }
  1144. case nodetype of
  1145. addn:
  1146. begin
  1147. { create the call to the concat routine both strings as arguments }
  1148. result := ccallnode.createintern('fpc_'+
  1149. tstringdef(resulttype.def).stringtypname+'_concat',
  1150. ccallparanode.create(right,ccallparanode.create(left,nil)));
  1151. { we reused the arguments }
  1152. left := nil;
  1153. right := nil;
  1154. end;
  1155. ltn,lten,gtn,gten,equaln,unequaln :
  1156. begin
  1157. { generate better code for s='' and s<>'' }
  1158. if (nodetype in [equaln,unequaln]) and
  1159. (((left.nodetype=stringconstn) and (str_length(left)=0)) or
  1160. ((right.nodetype=stringconstn) and (str_length(right)=0))) then
  1161. begin
  1162. { switch so that the constant is always on the right }
  1163. if left.nodetype = stringconstn then
  1164. begin
  1165. p := left;
  1166. left := right;
  1167. right := p;
  1168. end;
  1169. if is_shortstring(left.resulttype.def) then
  1170. { compare the length with 0 }
  1171. result := caddnode.create(nodetype,
  1172. cinlinenode.create(in_length_x,false,left),
  1173. cordconstnode.create(0,s32bittype,false))
  1174. else
  1175. begin
  1176. { compare the pointer with nil (for ansistrings etc), }
  1177. { faster than getting the length (JM) }
  1178. result:= caddnode.create(nodetype,
  1179. ctypeconvnode.create_explicit(left,voidpointertype),
  1180. cpointerconstnode.create(0,voidpointertype));
  1181. end;
  1182. { left is reused }
  1183. left := nil;
  1184. { right isn't }
  1185. right.free;
  1186. right := nil;
  1187. exit;
  1188. end;
  1189. { no string constant -> call compare routine }
  1190. result := ccallnode.createintern('fpc_'+
  1191. tstringdef(left.resulttype.def).stringtypname+'_compare',
  1192. ccallparanode.create(right,ccallparanode.create(left,nil)));
  1193. { and compare its result with 0 according to the original operator }
  1194. result := caddnode.create(nodetype,result,
  1195. cordconstnode.create(0,s32bittype,false));
  1196. left := nil;
  1197. right := nil;
  1198. end;
  1199. end;
  1200. end;
  1201. function taddnode.first_addset: tnode;
  1202. var
  1203. procname: string[31];
  1204. tempn: tnode;
  1205. paras: tcallparanode;
  1206. srsym: ttypesym;
  1207. begin
  1208. { get the sym that represents the fpc_normal_set type }
  1209. if not searchsystype('FPC_NORMAL_SET',srsym) then
  1210. internalerror(200108313);
  1211. case nodetype of
  1212. equaln,unequaln,lten,gten:
  1213. begin
  1214. case nodetype of
  1215. equaln,unequaln:
  1216. procname := 'fpc_set_comp_sets';
  1217. lten,gten:
  1218. begin
  1219. procname := 'fpc_set_contains_sets';
  1220. { (left >= right) = (right <= left) }
  1221. if nodetype = gten then
  1222. begin
  1223. tempn := left;
  1224. left := right;
  1225. right := tempn;
  1226. end;
  1227. end;
  1228. end;
  1229. { convert the arguments (explicitely) to fpc_normal_set's }
  1230. left := ctypeconvnode.create_explicit(left,srsym.restype);
  1231. right := ctypeconvnode.create_explicit(right,srsym.restype);
  1232. result := ccallnode.createintern(procname,ccallparanode.create(right,
  1233. ccallparanode.create(left,nil)));
  1234. { left and right are reused as parameters }
  1235. left := nil;
  1236. right := nil;
  1237. { for an unequaln, we have to negate the result of comp_sets }
  1238. if nodetype = unequaln then
  1239. result := cnotnode.create(result);
  1240. end;
  1241. addn:
  1242. begin
  1243. { optimize first loading of a set }
  1244. if (right.nodetype=setelementn) and
  1245. not(assigned(tsetelementnode(right).right)) and
  1246. is_emptyset(left) then
  1247. begin
  1248. { type cast the value to pass as argument to a byte, }
  1249. { since that's what the helper expects }
  1250. tsetelementnode(right).left :=
  1251. ctypeconvnode.create_explicit(tsetelementnode(right).left,u8bittype);
  1252. { set the resulttype to the actual one (otherwise it's }
  1253. { "fpc_normal_set") }
  1254. result := ccallnode.createinternres('fpc_set_create_element',
  1255. ccallparanode.create(tsetelementnode(right).left,nil),
  1256. resulttype);
  1257. { reused }
  1258. tsetelementnode(right).left := nil;
  1259. end
  1260. else
  1261. begin
  1262. if right.nodetype=setelementn then
  1263. begin
  1264. { convert the arguments to bytes, since that's what }
  1265. { the helper expects }
  1266. tsetelementnode(right).left :=
  1267. ctypeconvnode.create_explicit(tsetelementnode(right).left,
  1268. u8bittype);
  1269. { convert the original set (explicitely) to an }
  1270. { fpc_normal_set so we can pass it to the helper }
  1271. left := ctypeconvnode.create_explicit(left,srsym.restype);
  1272. { add a range or a single element? }
  1273. if assigned(tsetelementnode(right).right) then
  1274. begin
  1275. tsetelementnode(right).right :=
  1276. ctypeconvnode.create_explicit(tsetelementnode(right).right,
  1277. u8bittype);
  1278. { create the call }
  1279. result := ccallnode.createinternres('fpc_set_set_range',
  1280. ccallparanode.create(tsetelementnode(right).right,
  1281. ccallparanode.create(tsetelementnode(right).left,
  1282. ccallparanode.create(left,nil))),resulttype);
  1283. end
  1284. else
  1285. begin
  1286. result := ccallnode.createinternres('fpc_set_set_byte',
  1287. ccallparanode.create(tsetelementnode(right).left,
  1288. ccallparanode.create(left,nil)),resulttype);
  1289. end;
  1290. { remove reused parts from original node }
  1291. tsetelementnode(right).right := nil;
  1292. tsetelementnode(right).left := nil;
  1293. left := nil;
  1294. end
  1295. else
  1296. begin
  1297. { add two sets }
  1298. { convert the sets to fpc_normal_set's }
  1299. result := ccallnode.createinternres('fpc_set_add_sets',
  1300. ccallparanode.create(
  1301. ctypeconvnode.create_explicit(right,srsym.restype),
  1302. ccallparanode.create(
  1303. ctypeconvnode.create_explicit(left,srsym.restype),nil)),resulttype);
  1304. { remove reused parts from original node }
  1305. left := nil;
  1306. right := nil;
  1307. end;
  1308. end
  1309. end;
  1310. subn,symdifn,muln:
  1311. begin
  1312. { convert the sets to fpc_normal_set's }
  1313. paras := ccallparanode.create(ctypeconvnode.create_explicit(right,srsym.restype),
  1314. ccallparanode.create(ctypeconvnode.create_explicit(left,srsym.restype),nil));
  1315. case nodetype of
  1316. subn:
  1317. result := ccallnode.createinternres('fpc_set_sub_sets',
  1318. paras,resulttype);
  1319. symdifn:
  1320. result := ccallnode.createinternres('fpc_set_symdif_sets',
  1321. paras,resulttype);
  1322. muln:
  1323. result := ccallnode.createinternres('fpc_set_mul_sets',
  1324. paras,resulttype);
  1325. end;
  1326. { remove reused parts from original node }
  1327. left := nil;
  1328. right := nil;
  1329. end;
  1330. else
  1331. internalerror(200108311);
  1332. end;
  1333. end;
  1334. function taddnode.first_add64bitint: tnode;
  1335. var
  1336. procname: string[31];
  1337. temp: tnode;
  1338. power: longint;
  1339. begin
  1340. result := nil;
  1341. { create helper calls mul }
  1342. if nodetype <> muln then
  1343. exit;
  1344. { make sure that if there is a constant, that it's on the right }
  1345. if left.nodetype = ordconstn then
  1346. begin
  1347. temp := right;
  1348. right := left;
  1349. left := temp;
  1350. end;
  1351. { can we use a shift instead of a mul? }
  1352. if not (cs_check_overflow in aktlocalswitches) and
  1353. (right.nodetype = ordconstn) and
  1354. ispowerof2(tordconstnode(right).value,power) then
  1355. begin
  1356. tordconstnode(right).value := power;
  1357. result := cshlshrnode.create(shln,left,right);
  1358. { left and right are reused }
  1359. left := nil;
  1360. right := nil;
  1361. { return firstpassed new node }
  1362. exit;
  1363. end;
  1364. { when currency is used set the result of the
  1365. parameters to s64bit, so they are not converted }
  1366. if is_currency(resulttype.def) then
  1367. begin
  1368. left.resulttype:=cs64bittype;
  1369. right.resulttype:=cs64bittype;
  1370. end;
  1371. { otherwise, create the parameters for the helper }
  1372. right := ccallparanode.create(
  1373. cordconstnode.create(ord(cs_check_overflow in aktlocalswitches),booltype,true),
  1374. ccallparanode.create(right,ccallparanode.create(left,nil)));
  1375. left := nil;
  1376. { only qword needs the unsigned code, the
  1377. signed code is also used for currency }
  1378. if is_signed(resulttype.def) then
  1379. procname := 'fpc_mul_int64'
  1380. else
  1381. procname := 'fpc_mul_qword';
  1382. result := ccallnode.createintern(procname,right);
  1383. right := nil;
  1384. end;
  1385. {$ifdef cpufpemu}
  1386. function taddnode.first_addfloat: tnode;
  1387. var
  1388. procname: string[31];
  1389. temp: tnode;
  1390. power: longint;
  1391. { do we need to reverse the result ? }
  1392. notnode : boolean;
  1393. begin
  1394. result := nil;
  1395. notnode := false;
  1396. { In non-emulation mode, real opcodes are
  1397. emitted for floating point values.
  1398. }
  1399. if not (cs_fp_emulation in aktmoduleswitches) then
  1400. exit;
  1401. case nodetype of
  1402. addn : procname := 'fpc_single_add';
  1403. muln : procname := 'fpc_single_mul';
  1404. subn : procname := 'fpc_single_sub';
  1405. slashn : procname := 'fpc_single_div';
  1406. ltn : procname := 'fpc_single_lt';
  1407. lten: procname := 'fpc_single_le';
  1408. gtn:
  1409. begin
  1410. procname := 'fpc_single_le';
  1411. notnode := true;
  1412. end;
  1413. gten:
  1414. begin
  1415. procname := 'fpc_single_lt';
  1416. notnode := true;
  1417. end;
  1418. equaln: procname := 'fpc_single_eq';
  1419. unequaln :
  1420. begin
  1421. procname := 'fpc_single_eq';
  1422. notnode := true;
  1423. end;
  1424. else
  1425. CGMessage(type_e_mismatch);
  1426. end;
  1427. { convert the arguments (explicitely) to fpc_normal_set's }
  1428. result := ccallnode.createintern(procname,ccallparanode.create(right,
  1429. ccallparanode.create(left,nil)));
  1430. left:=nil;
  1431. right:=nil;
  1432. { do we need to reverse the result }
  1433. if notnode then
  1434. result := cnotnode.create(result);
  1435. end;
  1436. {$endif cpufpemu}
  1437. function taddnode.pass_1 : tnode;
  1438. var
  1439. {$ifdef addstringopt}
  1440. hp : tnode;
  1441. {$endif addstringopt}
  1442. lt,rt : tnodetype;
  1443. rd,ld : tdef;
  1444. begin
  1445. result:=nil;
  1446. { first do the two subtrees }
  1447. firstpass(left);
  1448. firstpass(right);
  1449. if codegenerror then
  1450. exit;
  1451. { load easier access variables }
  1452. rd:=right.resulttype.def;
  1453. ld:=left.resulttype.def;
  1454. rt:=right.nodetype;
  1455. lt:=left.nodetype;
  1456. { int/int gives real/real! }
  1457. if nodetype=slashn then
  1458. begin
  1459. {$ifdef cpufpemu}
  1460. result := first_addfloat;
  1461. if assigned(result) then
  1462. exit;
  1463. {$endif cpufpemu}
  1464. expectloc:=LOC_FPUREGISTER;
  1465. { maybe we need an integer register to save }
  1466. { a reference }
  1467. if ((left.expectloc<>LOC_FPUREGISTER) or
  1468. (right.expectloc<>LOC_FPUREGISTER)) and
  1469. (left.registers32=right.registers32) then
  1470. calcregisters(self,1,1,0)
  1471. else
  1472. calcregisters(self,0,1,0);
  1473. { an add node always first loads both the left and the }
  1474. { right in the fpu before doing the calculation. However, }
  1475. { calcregisters(0,2,0) will overestimate the number of }
  1476. { necessary registers (it will make it 3 in case one of }
  1477. { the operands is already in the fpu) (JM) }
  1478. if ((left.expectloc<>LOC_FPUREGISTER) or
  1479. (right.expectloc<>LOC_FPUREGISTER)) and
  1480. (registersfpu < 2) then
  1481. inc(registersfpu);
  1482. end
  1483. { if both are orddefs then check sub types }
  1484. else if (ld.deftype=orddef) and (rd.deftype=orddef) then
  1485. begin
  1486. { 2 booleans ? }
  1487. if is_boolean(ld) and is_boolean(rd) then
  1488. begin
  1489. if not(cs_full_boolean_eval in aktlocalswitches) and
  1490. (nodetype in [andn,orn]) then
  1491. begin
  1492. expectloc:=LOC_JUMP;
  1493. calcregisters(self,0,0,0);
  1494. end
  1495. else
  1496. begin
  1497. expectloc:=LOC_FLAGS;
  1498. if (left.expectloc in [LOC_JUMP,LOC_FLAGS]) and
  1499. (left.expectloc in [LOC_JUMP,LOC_FLAGS]) then
  1500. calcregisters(self,2,0,0)
  1501. else
  1502. calcregisters(self,1,0,0);
  1503. end;
  1504. end
  1505. else
  1506. { Both are chars? only convert to shortstrings for addn }
  1507. if is_char(ld) then
  1508. begin
  1509. if nodetype=addn then
  1510. internalerror(200103291);
  1511. expectloc:=LOC_FLAGS;
  1512. calcregisters(self,1,0,0);
  1513. end
  1514. { is there a 64 bit type ? }
  1515. else if (torddef(ld).typ in [s64bit,u64bit,scurrency]) then
  1516. begin
  1517. result := first_add64bitint;
  1518. if assigned(result) then
  1519. exit;
  1520. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  1521. expectloc:=LOC_REGISTER
  1522. else
  1523. expectloc:=LOC_JUMP;
  1524. calcregisters(self,2,0,0)
  1525. end
  1526. { is there a cardinal? }
  1527. else if (torddef(ld).typ=u32bit) then
  1528. begin
  1529. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  1530. expectloc:=LOC_REGISTER
  1531. else
  1532. expectloc:=LOC_FLAGS;
  1533. calcregisters(self,1,0,0);
  1534. { for unsigned mul we need an extra register }
  1535. if nodetype=muln then
  1536. inc(registers32);
  1537. end
  1538. { generic s32bit conversion }
  1539. else
  1540. begin
  1541. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  1542. expectloc:=LOC_REGISTER
  1543. else
  1544. expectloc:=LOC_FLAGS;
  1545. calcregisters(self,1,0,0);
  1546. end;
  1547. end
  1548. { left side a setdef, must be before string processing,
  1549. else array constructor can be seen as array of char (PFV) }
  1550. else if (ld.deftype=setdef) then
  1551. begin
  1552. if tsetdef(ld).settype=smallset then
  1553. begin
  1554. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  1555. expectloc:=LOC_FLAGS
  1556. else
  1557. expectloc:=LOC_REGISTER;
  1558. { are we adding set elements ? }
  1559. if right.nodetype=setelementn then
  1560. calcregisters(self,2,0,0)
  1561. else
  1562. calcregisters(self,1,0,0);
  1563. end
  1564. else
  1565. {$ifdef i386}
  1566. if cs_mmx in aktlocalswitches then
  1567. begin
  1568. expectloc:=LOC_MMXREGISTER;
  1569. calcregisters(self,0,0,4);
  1570. end
  1571. else
  1572. {$endif}
  1573. begin
  1574. result := first_addset;
  1575. if assigned(result) then
  1576. exit;
  1577. expectloc:=LOC_CREFERENCE;
  1578. calcregisters(self,0,0,0);
  1579. { here we call SET... }
  1580. include(current_procinfo.flags,pi_do_call);
  1581. end;
  1582. end
  1583. { compare pchar by addresses like BP/Delphi }
  1584. else if is_pchar(ld) then
  1585. begin
  1586. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  1587. expectloc:=LOC_REGISTER
  1588. else
  1589. expectloc:=LOC_FLAGS;
  1590. calcregisters(self,1,0,0);
  1591. end
  1592. { is one of the operands a string }
  1593. else if (ld.deftype=stringdef) then
  1594. begin
  1595. if is_widestring(ld) then
  1596. begin
  1597. { this is only for add, the comparisaion is handled later }
  1598. expectloc:=LOC_REGISTER;
  1599. end
  1600. else if is_ansistring(ld) then
  1601. begin
  1602. { this is only for add, the comparisaion is handled later }
  1603. expectloc:=LOC_REGISTER;
  1604. end
  1605. else if is_longstring(ld) then
  1606. begin
  1607. { this is only for add, the comparisaion is handled later }
  1608. expectloc:=LOC_REFERENCE;
  1609. end
  1610. else
  1611. begin
  1612. {$ifdef addstringopt}
  1613. { can create a call which isn't handled by callparatemp }
  1614. if canbeaddsstringcharoptnode(self) then
  1615. begin
  1616. hp := genaddsstringcharoptnode(self);
  1617. pass_1 := hp;
  1618. exit;
  1619. end
  1620. else
  1621. {$endif addstringopt}
  1622. begin
  1623. { Fix right to be shortstring }
  1624. if is_char(right.resulttype.def) then
  1625. begin
  1626. inserttypeconv(right,cshortstringtype);
  1627. firstpass(right);
  1628. end;
  1629. end;
  1630. {$ifdef addstringopt}
  1631. { can create a call which isn't handled by callparatemp }
  1632. if canbeaddsstringcsstringoptnode(self) then
  1633. begin
  1634. hp := genaddsstringcsstringoptnode(self);
  1635. pass_1 := hp;
  1636. exit;
  1637. end;
  1638. {$endif addstringopt}
  1639. end;
  1640. { otherwise, let addstring convert everything }
  1641. result := first_addstring;
  1642. exit;
  1643. end
  1644. { is one a real float ? }
  1645. else if (rd.deftype=floatdef) or (ld.deftype=floatdef) then
  1646. begin
  1647. {$ifdef cpufpemu}
  1648. result := first_addfloat;
  1649. if assigned(result) then
  1650. exit;
  1651. {$endif cpufpemu}
  1652. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  1653. expectloc:=LOC_FPUREGISTER
  1654. else
  1655. expectloc:=LOC_FLAGS;
  1656. calcregisters(self,0,1,0);
  1657. { an add node always first loads both the left and the }
  1658. { right in the fpu before doing the calculation. However, }
  1659. { calcregisters(0,2,0) will overestimate the number of }
  1660. { necessary registers (it will make it 3 in case one of }
  1661. { the operands is already in the fpu) (JM) }
  1662. if ((left.expectloc<>LOC_FPUREGISTER) or
  1663. (right.expectloc<>LOC_FPUREGISTER)) and
  1664. (registersfpu < 2) then
  1665. inc(registersfpu);
  1666. end
  1667. { pointer comperation and subtraction }
  1668. else if (ld.deftype=pointerdef) then
  1669. begin
  1670. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  1671. expectloc:=LOC_REGISTER
  1672. else
  1673. expectloc:=LOC_FLAGS;
  1674. calcregisters(self,1,0,0);
  1675. end
  1676. else if is_class_or_interface(ld) then
  1677. begin
  1678. expectloc:=LOC_FLAGS;
  1679. calcregisters(self,1,0,0);
  1680. end
  1681. else if (ld.deftype=classrefdef) then
  1682. begin
  1683. expectloc:=LOC_FLAGS;
  1684. calcregisters(self,1,0,0);
  1685. end
  1686. { support procvar=nil,procvar<>nil }
  1687. else if ((ld.deftype=procvardef) and (rt=niln)) or
  1688. ((rd.deftype=procvardef) and (lt=niln)) then
  1689. begin
  1690. expectloc:=LOC_FLAGS;
  1691. calcregisters(self,1,0,0);
  1692. end
  1693. {$ifdef SUPPORT_MMX}
  1694. { mmx support, this must be before the zero based array
  1695. check }
  1696. else if (cs_mmx in aktlocalswitches) and is_mmx_able_array(ld) and
  1697. is_mmx_able_array(rd) then
  1698. begin
  1699. expectloc:=LOC_MMXREGISTER;
  1700. calcregisters(self,0,0,1);
  1701. end
  1702. {$endif SUPPORT_MMX}
  1703. else if (rd.deftype=pointerdef) or (ld.deftype=pointerdef) then
  1704. begin
  1705. expectloc:=LOC_REGISTER;
  1706. calcregisters(self,1,0,0);
  1707. end
  1708. else if (rd.deftype=procvardef) and
  1709. (ld.deftype=procvardef) and
  1710. equal_defs(rd,ld) then
  1711. begin
  1712. expectloc:=LOC_FLAGS;
  1713. calcregisters(self,1,0,0);
  1714. end
  1715. else if (ld.deftype=enumdef) then
  1716. begin
  1717. expectloc:=LOC_FLAGS;
  1718. calcregisters(self,1,0,0);
  1719. end
  1720. {$ifdef SUPPORT_MMX}
  1721. else if (cs_mmx in aktlocalswitches) and
  1722. is_mmx_able_array(ld) and
  1723. is_mmx_able_array(rd) then
  1724. begin
  1725. expectloc:=LOC_MMXREGISTER;
  1726. calcregisters(self,0,0,1);
  1727. end
  1728. {$endif SUPPORT_MMX}
  1729. { the general solution is to convert to 32 bit int }
  1730. else
  1731. begin
  1732. expectloc:=LOC_REGISTER;
  1733. calcregisters(self,1,0,0);
  1734. end;
  1735. end;
  1736. {$ifdef state_tracking}
  1737. function Taddnode.track_state_pass(exec_known:boolean):boolean;
  1738. var factval:Tnode;
  1739. begin
  1740. track_state_pass:=false;
  1741. if left.track_state_pass(exec_known) then
  1742. begin
  1743. track_state_pass:=true;
  1744. left.resulttype.def:=nil;
  1745. do_resulttypepass(left);
  1746. end;
  1747. factval:=aktstate.find_fact(left);
  1748. if factval<>nil then
  1749. begin
  1750. track_state_pass:=true;
  1751. left.destroy;
  1752. left:=factval.getcopy;
  1753. end;
  1754. if right.track_state_pass(exec_known) then
  1755. begin
  1756. track_state_pass:=true;
  1757. right.resulttype.def:=nil;
  1758. do_resulttypepass(right);
  1759. end;
  1760. factval:=aktstate.find_fact(right);
  1761. if factval<>nil then
  1762. begin
  1763. track_state_pass:=true;
  1764. right.destroy;
  1765. right:=factval.getcopy;
  1766. end;
  1767. end;
  1768. {$endif}
  1769. begin
  1770. caddnode:=taddnode;
  1771. end.
  1772. {
  1773. $Log$
  1774. Revision 1.101 2003-12-21 11:28:41 daniel
  1775. * Some work to allow mmx instructions to be used for 32 byte sets
  1776. Revision 1.100 2003/12/09 21:17:04 jonas
  1777. + support for evaluating qword constant expressions (both arguments have
  1778. to be a qword, constants have to be explicitly typecasted to qword)
  1779. Revision 1.99 2003/10/28 15:35:18 peter
  1780. * compare longint-cardinal also makes types wider
  1781. Revision 1.98 2003/10/21 18:16:13 peter
  1782. * IncompatibleTypes() added that will include unit names when
  1783. the typenames are the same
  1784. Revision 1.97 2003/10/08 19:19:45 peter
  1785. * set_varstate cleanup
  1786. Revision 1.96 2003/10/01 20:34:48 peter
  1787. * procinfo unit contains tprocinfo
  1788. * cginfo renamed to cgbase
  1789. * moved cgmessage to verbose
  1790. * fixed ppc and sparc compiles
  1791. Revision 1.95 2003/09/06 16:47:24 florian
  1792. + support of NaN and Inf in the compiler as values of real constants
  1793. Revision 1.94 2003/09/03 15:55:00 peter
  1794. * NEWRA branch merged
  1795. Revision 1.93.2.1 2003/08/31 21:07:44 daniel
  1796. * callparatemp ripped
  1797. Revision 1.93 2003/06/05 20:05:55 peter
  1798. * removed changesettype because that will change the definition
  1799. of the setdef forever and can result in a different between
  1800. original interface and current implementation definition
  1801. Revision 1.92 2003/06/03 21:04:43 peter
  1802. * widen cardinal+signed operations
  1803. Revision 1.91 2003/05/26 21:15:18 peter
  1804. * disable string node optimizations for the moment
  1805. Revision 1.90 2003/05/26 19:38:28 peter
  1806. * generic fpc_shorstr_concat
  1807. + fpc_shortstr_append_shortstr optimization
  1808. Revision 1.89 2003/05/24 21:12:57 florian
  1809. * if something doesn't work with callparatemp, the define callparatemp
  1810. should be used because other processors with reigster calling conventions
  1811. depend on this as well
  1812. Revision 1.88 2003/05/23 22:57:38 jonas
  1813. - disable addoptnodes for powerpc, because they can generate calls in
  1814. pass_2, so -dcallparatemp can't detect them as nested calls
  1815. Revision 1.87 2003/04/27 11:21:32 peter
  1816. * aktprocdef renamed to current_procdef
  1817. * procinfo renamed to current_procinfo
  1818. * procinfo will now be stored in current_module so it can be
  1819. cleaned up properly
  1820. * gen_main_procsym changed to create_main_proc and release_main_proc
  1821. to also generate a tprocinfo structure
  1822. * fixed unit implicit initfinal
  1823. Revision 1.86 2003/04/26 09:12:55 peter
  1824. * add string returns in LOC_REFERENCE
  1825. Revision 1.85 2003/04/24 22:29:57 florian
  1826. * fixed a lot of PowerPC related stuff
  1827. Revision 1.84 2003/04/23 20:16:04 peter
  1828. + added currency support based on int64
  1829. + is_64bit for use in cg units instead of is_64bitint
  1830. * removed cgmessage from n386add, replace with internalerrors
  1831. Revision 1.83 2003/04/23 10:10:07 peter
  1832. * expectloc fixes
  1833. Revision 1.82 2003/04/22 23:50:22 peter
  1834. * firstpass uses expectloc
  1835. * checks if there are differences between the expectloc and
  1836. location.loc from secondpass in EXTDEBUG
  1837. Revision 1.81 2003/02/15 22:20:14 carl
  1838. * bugfix for generic calls to FPU emulation code
  1839. Revision 1.80 2003/02/12 22:10:07 carl
  1840. * load_frame_pointer is now generic
  1841. * change fpu emulation routine names
  1842. Revision 1.79 2003/01/02 22:19:54 peter
  1843. * support pchar-char operations converting to string first
  1844. * support chararray-nil
  1845. Revision 1.78 2002/12/11 22:41:03 peter
  1846. * stop processing assignment node when the binaryoverload generates
  1847. a codegenerror
  1848. Revision 1.77 2002/12/06 16:56:57 peter
  1849. * only compile cs_fp_emulation support when cpufpuemu is defined
  1850. * define cpufpuemu for m68k only
  1851. Revision 1.76 2002/11/30 21:32:24 carl
  1852. + Add loading of softfpu in emulation mode
  1853. + Correct routine call for softfpu
  1854. * Extended type must also be defined even with softfpu
  1855. Revision 1.75 2002/11/27 13:11:38 peter
  1856. * more currency fixes, taddcurr runs now successfull
  1857. Revision 1.74 2002/11/27 11:28:40 peter
  1858. * when both flaottypes are the same then handle the addnode using
  1859. that floattype instead of bestrealtype
  1860. Revision 1.73 2002/11/25 18:43:32 carl
  1861. - removed the invalid if <> checking (Delphi is strange on this)
  1862. + implemented abstract warning on instance creation of class with
  1863. abstract methods.
  1864. * some error message cleanups
  1865. Revision 1.72 2002/11/25 17:43:17 peter
  1866. * splitted defbase in defutil,symutil,defcmp
  1867. * merged isconvertable and is_equal into compare_defs(_ext)
  1868. * made operator search faster by walking the list only once
  1869. Revision 1.71 2002/11/23 22:50:06 carl
  1870. * some small speed optimizations
  1871. + added several new warnings/hints
  1872. Revision 1.70 2002/11/16 14:20:22 peter
  1873. * fix tbs0417
  1874. Revision 1.69 2002/11/15 01:58:50 peter
  1875. * merged changes from 1.0.7 up to 04-11
  1876. - -V option for generating bug report tracing
  1877. - more tracing for option parsing
  1878. - errors for cdecl and high()
  1879. - win32 import stabs
  1880. - win32 records<=8 are returned in eax:edx (turned off by default)
  1881. - heaptrc update
  1882. - more info for temp management in .s file with EXTDEBUG
  1883. Revision 1.68 2002/10/08 16:50:43 jonas
  1884. * fixed web bug 2136
  1885. Revision 1.67 2002/10/05 00:47:03 peter
  1886. * support dynamicarray<>nil
  1887. Revision 1.66 2002/10/04 21:19:28 jonas
  1888. * fixed web bug 2139: checking for division by zero fixed
  1889. Revision 1.65 2002/09/07 15:25:02 peter
  1890. * old logs removed and tabs fixed
  1891. Revision 1.64 2002/09/07 12:16:05 carl
  1892. * second part bug report 1996 fix, testrange in cordconstnode
  1893. only called if option is set (also make parsing a tiny faster)
  1894. Revision 1.63 2002/09/04 19:32:56 jonas
  1895. * changed some ctypeconvnode/toggleflag(nf_explizit) combo's to
  1896. ctypeconvnode.create_explicit() statements
  1897. Revision 1.62 2002/08/17 09:23:34 florian
  1898. * first part of current_procinfo rewrite
  1899. Revision 1.61 2002/08/15 15:15:55 carl
  1900. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  1901. * more generic nodes for maths
  1902. * several fixes for better m68k support
  1903. Revision 1.60 2002/08/12 15:08:39 carl
  1904. + stab register indexes for powerpc (moved from gdb to cpubase)
  1905. + tprocessor enumeration moved to cpuinfo
  1906. + linker in target_info is now a class
  1907. * many many updates for m68k (will soon start to compile)
  1908. - removed some ifdef or correct them for correct cpu
  1909. Revision 1.59 2002/08/02 07:44:30 jonas
  1910. * made assigned() handling generic
  1911. * add nodes now can also evaluate constant expressions at compile time
  1912. that contain nil nodes
  1913. Revision 1.58 2002/07/26 11:17:52 jonas
  1914. * the optimization of converting a multiplication with a power of two to
  1915. a shl is moved from n386add/secondpass to nadd/resulttypepass
  1916. Revision 1.57 2002/07/23 13:08:16 jonas
  1917. * fixed constant set evaluation of new set handling for non-commutative
  1918. operators
  1919. Revision 1.56 2002/07/23 12:34:29 daniel
  1920. * Readded old set code. To use it define 'oldset'. Activated by default
  1921. for ppc.
  1922. Revision 1.55 2002/07/22 11:48:04 daniel
  1923. * Sets are now internally sets.
  1924. Revision 1.54 2002/07/20 11:57:53 florian
  1925. * types.pas renamed to defbase.pas because D6 contains a types
  1926. unit so this would conflicts if D6 programms are compiled
  1927. + Willamette/SSE2 instructions to assembler added
  1928. Revision 1.53 2002/07/19 11:41:34 daniel
  1929. * State tracker work
  1930. * The whilen and repeatn are now completely unified into whilerepeatn. This
  1931. allows the state tracker to change while nodes automatically into
  1932. repeat nodes.
  1933. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  1934. 'not(a>b)' is optimized into 'a<=b'.
  1935. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  1936. by removing the notn and later switchting the true and falselabels. The
  1937. same is done with 'repeat until not a'.
  1938. Revision 1.52 2002/07/14 18:00:43 daniel
  1939. + Added the beginning of a state tracker. This will track the values of
  1940. variables through procedures and optimize things away.
  1941. Revision 1.51 2002/05/18 13:34:08 peter
  1942. * readded missing revisions
  1943. Revision 1.50 2002/05/16 19:46:37 carl
  1944. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1945. + try to fix temp allocation (still in ifdef)
  1946. + generic constructor calls
  1947. + start of tassembler / tmodulebase class cleanup
  1948. Revision 1.48 2002/05/13 19:54:36 peter
  1949. * removed n386ld and n386util units
  1950. * maybe_save/maybe_restore added instead of the old maybe_push
  1951. Revision 1.47 2002/05/12 16:53:06 peter
  1952. * moved entry and exitcode to ncgutil and cgobj
  1953. * foreach gets extra argument for passing local data to the
  1954. iterator function
  1955. * -CR checks also class typecasts at runtime by changing them
  1956. into as
  1957. * fixed compiler to cycle with the -CR option
  1958. * fixed stabs with elf writer, finally the global variables can
  1959. be watched
  1960. * removed a lot of routines from cga unit and replaced them by
  1961. calls to cgobj
  1962. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1963. u32bit then the other is typecasted also to u32bit without giving
  1964. a rangecheck warning/error.
  1965. * fixed pascal calling method with reversing also the high tree in
  1966. the parast, detected by tcalcst3 test
  1967. Revision 1.46 2002/04/23 19:16:34 peter
  1968. * add pinline unit that inserts compiler supported functions using
  1969. one or more statements
  1970. * moved finalize and setlength from ninl to pinline
  1971. Revision 1.45 2002/04/04 19:05:56 peter
  1972. * removed unused units
  1973. * use tlocation.size in cg.a_*loc*() routines
  1974. Revision 1.44 2002/04/02 17:11:28 peter
  1975. * tlocation,treference update
  1976. * LOC_CONSTANT added for better constant handling
  1977. * secondadd splitted in multiple routines
  1978. * location_force_reg added for loading a location to a register
  1979. of a specified size
  1980. * secondassignment parses now first the right and then the left node
  1981. (this is compatible with Kylix). This saves a lot of push/pop especially
  1982. with string operations
  1983. * adapted some routines to use the new cg methods
  1984. }