nadd.pas 82 KB

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