nadd.pas 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Type checking and simplification for add nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nadd;
  18. {$i fpcdefs.inc}
  19. { define addstringopt}
  20. interface
  21. uses
  22. node,symtype;
  23. type
  24. taddnode = class(tbinopnode)
  25. private
  26. resultrealdefderef: tderef;
  27. function pass_typecheck_internal:tnode;
  28. public
  29. resultrealdef : tdef;
  30. constructor create(tt : tnodetype;l,r : tnode);override;
  31. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  32. procedure ppuwrite(ppufile:tcompilerppufile);override;
  33. procedure buildderefimpl;override;
  34. procedure derefimpl;override;
  35. function pass_1 : tnode;override;
  36. function pass_typecheck:tnode;override;
  37. function simplify(forinline: boolean) : tnode;override;
  38. function dogetcopy : tnode;override;
  39. function docompare(p: tnode): boolean; override;
  40. {$ifdef state_tracking}
  41. function track_state_pass(exec_known:boolean):boolean;override;
  42. {$endif}
  43. protected
  44. { override the following if you want to implement }
  45. { parts explicitely in the code generator (JM) }
  46. function first_addstring: tnode; virtual;
  47. function first_addset: tnode; virtual;
  48. { only implements "muln" nodes, the rest always has to be done in }
  49. { the code generator for performance reasons (JM) }
  50. function first_add64bitint: tnode; virtual;
  51. { override and return false if you can handle 32x32->64 }
  52. { bit multiplies directly in your code generator. If }
  53. { this function is overridden to return false, you can }
  54. { get multiplies with left/right both s32bit or u32bit, }
  55. { and resultdef of the muln s64bit or u64bit }
  56. function use_generic_mul32to64: boolean; virtual;
  57. { This routine calls internal runtime library helpers
  58. for all floating point arithmetic in the case
  59. where the emulation switches is on. Otherwise
  60. returns nil, and everything must be done in
  61. the code generation phase.
  62. }
  63. function first_addfloat : tnode; virtual;
  64. private
  65. { checks whether a muln can be calculated as a 32bit }
  66. { * 32bit -> 64 bit }
  67. function try_make_mul32to64: boolean;
  68. { Match against the ranges, i.e.:
  69. var a:1..10;
  70. begin
  71. if a>0 then
  72. ...
  73. always evaluates to true. (DM)
  74. }
  75. function cmp_of_disjunct_ranges(var res : boolean) : boolean;
  76. end;
  77. taddnodeclass = class of taddnode;
  78. var
  79. { caddnode is used to create nodes of the add type }
  80. { the virtual constructor allows to assign }
  81. { another class type to caddnode => processor }
  82. { specific node types can be created }
  83. caddnode : taddnodeclass = taddnode;
  84. implementation
  85. uses
  86. {$IFNDEF USE_FAKE_SYSUTILS}
  87. sysutils,
  88. {$ELSE}
  89. fksysutl,
  90. {$ENDIF}
  91. globtype,systems,constexp,
  92. cutils,verbose,globals,widestr,
  93. symconst,symdef,symsym,symtable,defutil,defcmp,
  94. cgbase,
  95. htypechk,pass_1,
  96. nld,nbas,nmat,ncnv,ncon,nset,nopt,ncal,ninl,nmem,nutils,
  97. {$ifdef state_tracking}
  98. nstate,
  99. {$endif}
  100. cpuinfo,procinfo;
  101. {*****************************************************************************
  102. TADDNODE
  103. *****************************************************************************}
  104. {$maxfpuregisters 0}
  105. function getbestreal(t1,t2 : tdef) : tdef;
  106. const
  107. floatweight : array[tfloattype] of byte =
  108. (2,3,4,5,0,1,6);
  109. begin
  110. if t1.typ=floatdef then
  111. begin
  112. result:=t1;
  113. if t2.typ=floatdef then
  114. begin
  115. { when a comp or currency is used, use always the
  116. best float type to calculate the result }
  117. if (tfloatdef(t2).floattype in [s64comp,s64currency]) or
  118. (tfloatdef(t2).floattype in [s64comp,s64currency]) then
  119. result:=pbestrealtype^
  120. else
  121. if floatweight[tfloatdef(t2).floattype]>floatweight[tfloatdef(t1).floattype] then
  122. result:=t2;
  123. end;
  124. end
  125. else if t2.typ=floatdef then
  126. result:=t2
  127. else internalerror(200508061);
  128. end;
  129. constructor taddnode.create(tt : tnodetype;l,r : tnode);
  130. begin
  131. inherited create(tt,l,r);
  132. end;
  133. constructor taddnode.ppuload(t: tnodetype; ppufile: tcompilerppufile);
  134. begin
  135. inherited ppuload(t, ppufile);
  136. ppufile.getderef(resultrealdefderef);
  137. end;
  138. procedure taddnode.ppuwrite(ppufile: tcompilerppufile);
  139. begin
  140. inherited ppuwrite(ppufile);
  141. ppufile.putderef(resultrealdefderef);
  142. end;
  143. procedure taddnode.buildderefimpl;
  144. begin
  145. inherited buildderefimpl;
  146. resultrealdefderef.build(resultrealdef);
  147. end;
  148. procedure taddnode.derefimpl;
  149. begin
  150. inherited derefimpl;
  151. resultrealdef:=tdef(resultrealdefderef.resolve);
  152. end;
  153. function taddnode.cmp_of_disjunct_ranges(var res : boolean) : boolean;
  154. var
  155. hp : tnode;
  156. realdef : tdef;
  157. v : tconstexprint;
  158. begin
  159. result:=false;
  160. { check for comparision with known result because the ranges of the operands don't overlap }
  161. if (is_constintnode(right) and (left.resultdef.typ=orddef) and
  162. { don't ignore type checks }
  163. is_subequal(right.resultdef,left.resultdef)) or
  164. (is_constintnode(left) and (right.resultdef.typ=orddef) and
  165. { don't ignore type checks }
  166. is_subequal(left.resultdef,right.resultdef)) then
  167. begin
  168. if is_constintnode(right) then
  169. begin
  170. hp:=left;
  171. v:=Tordconstnode(right).value;
  172. end
  173. else
  174. begin
  175. hp:=right;
  176. v:=Tordconstnode(left).value;
  177. end;
  178. realdef:=hp.resultdef;
  179. { stop with finding the real def when we either encounter
  180. a) an explicit type conversion (then the value has to be
  181. re-interpreted)
  182. b) an "absolute" type conversion (also requires
  183. re-interpretation)
  184. }
  185. while (hp.nodetype=typeconvn) and
  186. ([nf_internal,nf_explicit,nf_absolute] * hp.flags = []) do
  187. begin
  188. hp:=ttypeconvnode(hp).left;
  189. realdef:=hp.resultdef;
  190. end;
  191. if is_constintnode(left) then
  192. with torddef(realdef) do
  193. case nodetype of
  194. ltn:
  195. if v<low then
  196. begin
  197. result:=true;
  198. res:=true;
  199. end
  200. else if v>=high then
  201. begin
  202. result:=true;
  203. res:=false;
  204. end;
  205. lten:
  206. if v<=low then
  207. begin
  208. result:=true;
  209. res:=true;
  210. end
  211. else if v>high then
  212. begin
  213. result:=true;
  214. res:=false;
  215. end;
  216. gtn:
  217. if v<=low then
  218. begin
  219. result:=true;
  220. res:=false;
  221. end
  222. else if v>high then
  223. begin
  224. result:=true;
  225. res:=true;
  226. end;
  227. gten :
  228. if v<low then
  229. begin
  230. result:=true;
  231. res:=false;
  232. end
  233. else if v>=high then
  234. begin
  235. result:=true;
  236. res:=true;
  237. end;
  238. equaln:
  239. if (v<low) or (v>high) then
  240. begin
  241. result:=true;
  242. res:=false;
  243. end;
  244. unequaln:
  245. if (v<low) or (v>high) then
  246. begin
  247. result:=true;
  248. res:=true;
  249. end;
  250. end
  251. else
  252. with torddef(realdef) do
  253. case nodetype of
  254. ltn:
  255. if high<v then
  256. begin
  257. result:=true;
  258. res:=true;
  259. end
  260. else if low>=v then
  261. begin
  262. result:=true;
  263. res:=false;
  264. end;
  265. lten:
  266. if high<=v then
  267. begin
  268. result:=true;
  269. res:=true;
  270. end
  271. else if low>v then
  272. begin
  273. result:=true;
  274. res:=false;
  275. end;
  276. gtn:
  277. if high<=v then
  278. begin
  279. result:=true;
  280. res:=false;
  281. end
  282. else if low>v then
  283. begin
  284. result:=true;
  285. res:=true;
  286. end;
  287. gten:
  288. if high<v then
  289. begin
  290. result:=true;
  291. res:=false;
  292. end
  293. else if low>=v then
  294. begin
  295. result:=true;
  296. res:=true;
  297. end;
  298. equaln:
  299. if (v<low) or (v>high) then
  300. begin
  301. result:=true;
  302. res:=false;
  303. end;
  304. unequaln:
  305. if (v<low) or (v>high) then
  306. begin
  307. result:=true;
  308. res:=true;
  309. end;
  310. end;
  311. end;
  312. end;
  313. function taddnode.simplify(forinline : boolean) : tnode;
  314. var
  315. t : tnode;
  316. lt,rt : tnodetype;
  317. rd,ld : tdef;
  318. rv,lv,v : tconstexprint;
  319. rvd,lvd : bestreal;
  320. ws1,ws2 : pcompilerwidestring;
  321. concatstrings : boolean;
  322. c1,c2 : array[0..1] of char;
  323. s1,s2 : pchar;
  324. l1,l2 : longint;
  325. resultset : Tconstset;
  326. res,
  327. b : boolean;
  328. begin
  329. result:=nil;
  330. { load easier access variables }
  331. rd:=right.resultdef;
  332. ld:=left.resultdef;
  333. rt:=right.nodetype;
  334. lt:=left.nodetype;
  335. if (nodetype = slashn) and
  336. (((rt = ordconstn) and
  337. (tordconstnode(right).value = 0)) or
  338. ((rt = realconstn) and
  339. (trealconstnode(right).value_real = 0.0))) then
  340. begin
  341. if floating_point_range_check_error then
  342. begin
  343. result:=crealconstnode.create(1,pbestrealtype^);
  344. Message(parser_e_division_by_zero);
  345. exit;
  346. end;
  347. end;
  348. { both are int constants }
  349. if (
  350. (
  351. is_constintnode(left) and
  352. is_constintnode(right)
  353. ) or
  354. (
  355. is_constboolnode(left) and
  356. is_constboolnode(right) and
  357. (nodetype in [slashn,ltn,lten,gtn,gten,equaln,unequaln,andn,xorn,orn])
  358. ) or
  359. (
  360. is_constenumnode(left) and
  361. is_constenumnode(right) and
  362. allowenumop(nodetype))
  363. ) or
  364. (
  365. (lt = pointerconstn) and
  366. is_constintnode(right) and
  367. (nodetype in [addn,subn])
  368. ) or
  369. (
  370. (lt in [pointerconstn,niln]) and
  371. (rt in [pointerconstn,niln]) and
  372. (nodetype in [ltn,lten,gtn,gten,equaln,unequaln,subn])
  373. ) then
  374. begin
  375. t:=nil;
  376. { load values }
  377. case lt of
  378. ordconstn:
  379. lv:=tordconstnode(left).value;
  380. pointerconstn:
  381. lv:=tpointerconstnode(left).value;
  382. niln:
  383. lv:=0;
  384. else
  385. internalerror(2002080202);
  386. end;
  387. case rt of
  388. ordconstn:
  389. rv:=tordconstnode(right).value;
  390. pointerconstn:
  391. rv:=tpointerconstnode(right).value;
  392. niln:
  393. rv:=0;
  394. else
  395. internalerror(2002080203);
  396. end;
  397. { type checking already took care of multiplying }
  398. { integer constants with pointeddef.size if necessary }
  399. case nodetype of
  400. addn :
  401. begin
  402. v:=lv+rv;
  403. if v.overflow then
  404. begin
  405. Message(parser_e_arithmetic_operation_overflow);
  406. { Recover }
  407. t:=genintconstnode(0)
  408. end
  409. else if (lt=pointerconstn) then
  410. t := cpointerconstnode.create(qword(v),resultdef)
  411. else
  412. if is_integer(ld) then
  413. t := create_simplified_ord_const(v,resultdef,forinline)
  414. else
  415. t := cordconstnode.create(v,resultdef,(ld.typ<>enumdef));
  416. end;
  417. subn :
  418. begin
  419. v:=lv-rv;
  420. if v.overflow then
  421. begin
  422. Message(parser_e_arithmetic_operation_overflow);
  423. { Recover }
  424. t:=genintconstnode(0)
  425. end
  426. else if (lt=pointerconstn) then
  427. { pointer-pointer results in an integer }
  428. if (rt=pointerconstn) then
  429. begin
  430. if not(nf_has_pointerdiv in flags) then
  431. internalerror(2008030101);
  432. t := cpointerconstnode.create(qword(v),resultdef)
  433. end
  434. else
  435. t := cpointerconstnode.create(qword(v),resultdef)
  436. else
  437. if is_integer(ld) then
  438. t := create_simplified_ord_const(v,resultdef,forinline)
  439. else
  440. t:=cordconstnode.create(v,resultdef,(ld.typ<>enumdef));
  441. end;
  442. muln :
  443. begin
  444. v:=lv*rv;
  445. if v.overflow then
  446. begin
  447. message(parser_e_arithmetic_operation_overflow);
  448. { Recover }
  449. t:=genintconstnode(0)
  450. end
  451. else
  452. t := create_simplified_ord_const(v,resultdef,forinline)
  453. end;
  454. xorn :
  455. if is_integer(ld) then
  456. t := create_simplified_ord_const(lv xor rv,resultdef,forinline)
  457. else
  458. t:=cordconstnode.create(lv xor rv,resultdef,true);
  459. orn :
  460. if is_integer(ld) then
  461. t:=create_simplified_ord_const(lv or rv,resultdef,forinline)
  462. else
  463. t:=cordconstnode.create(lv or rv,resultdef,true);
  464. andn :
  465. if is_integer(ld) then
  466. t:=create_simplified_ord_const(lv and rv,resultdef,forinline)
  467. else
  468. t:=cordconstnode.create(lv and rv,resultdef,true);
  469. ltn :
  470. t:=cordconstnode.create(ord(lv<rv),pasbool8type,true);
  471. lten :
  472. t:=cordconstnode.create(ord(lv<=rv),pasbool8type,true);
  473. gtn :
  474. t:=cordconstnode.create(ord(lv>rv),pasbool8type,true);
  475. gten :
  476. t:=cordconstnode.create(ord(lv>=rv),pasbool8type,true);
  477. equaln :
  478. t:=cordconstnode.create(ord(lv=rv),pasbool8type,true);
  479. unequaln :
  480. t:=cordconstnode.create(ord(lv<>rv),pasbool8type,true);
  481. slashn :
  482. begin
  483. { int/int becomes a real }
  484. rvd:=rv;
  485. lvd:=lv;
  486. t:=crealconstnode.create(lvd/rvd,resultrealdef);
  487. end;
  488. else
  489. internalerror(2008022101);
  490. end;
  491. result:=t;
  492. exit;
  493. end
  494. else if cmp_of_disjunct_ranges(res) then
  495. begin
  496. if res then
  497. t:=Cordconstnode.create(1,pasbool8type,true)
  498. else
  499. t:=Cordconstnode.create(0,pasbool8type,true);
  500. { don't do this optimization, if the variable expression might
  501. have a side effect }
  502. if (is_constintnode(left) and might_have_sideeffects(right)) or
  503. (is_constintnode(right) and might_have_sideeffects(left)) then
  504. t.free
  505. else
  506. result:=t;
  507. exit;
  508. end;
  509. { Add,Sub,Mul with constant 0, 1 or -1? }
  510. if is_constintnode(right) and is_integer(left.resultdef) then
  511. begin
  512. if tordconstnode(right).value = 0 then
  513. begin
  514. case nodetype of
  515. addn,subn:
  516. result := left.getcopy;
  517. muln:
  518. result:=cordconstnode.create(0,resultdef,true);
  519. end;
  520. end
  521. else if tordconstnode(right).value = 1 then
  522. begin
  523. case nodetype of
  524. muln:
  525. result := left.getcopy;
  526. end;
  527. end
  528. {$ifdef VER2_2}
  529. else if (tordconstnode(right).value.svalue = -1) and (tordconstnode(right).value.signed) then
  530. {$else}
  531. else if tordconstnode(right).value = -1 then
  532. {$endif}
  533. begin
  534. case nodetype of
  535. muln:
  536. result := cunaryminusnode.create(left.getcopy);
  537. end;
  538. end;
  539. if assigned(result) then
  540. exit;
  541. end;
  542. if is_constintnode(left) and is_integer(right.resultdef) then
  543. begin
  544. if tordconstnode(left).value = 0 then
  545. begin
  546. case nodetype of
  547. addn:
  548. result := right.getcopy;
  549. subn:
  550. result := cunaryminusnode.create(right.getcopy);
  551. muln:
  552. result:=cordconstnode.create(0,right.resultdef,true);
  553. end;
  554. end
  555. else if tordconstnode(left).value = 1 then
  556. begin
  557. case nodetype of
  558. muln:
  559. result := right.getcopy;
  560. end;
  561. end
  562. {$ifdef VER2_2}
  563. else if (tordconstnode(left).value.svalue = -1) and (tordconstnode(left).value.signed) then
  564. {$else}
  565. else if tordconstnode(left).value = -1 then
  566. {$endif}
  567. begin
  568. case nodetype of
  569. muln:
  570. result := cunaryminusnode.create(right.getcopy);
  571. end;
  572. end;
  573. if assigned(result) then
  574. exit;
  575. end;
  576. { both real constants ? }
  577. if (lt=realconstn) and (rt=realconstn) then
  578. begin
  579. lvd:=trealconstnode(left).value_real;
  580. rvd:=trealconstnode(right).value_real;
  581. case nodetype of
  582. addn :
  583. t:=crealconstnode.create(lvd+rvd,resultrealdef);
  584. subn :
  585. t:=crealconstnode.create(lvd-rvd,resultrealdef);
  586. muln :
  587. t:=crealconstnode.create(lvd*rvd,resultrealdef);
  588. starstarn:
  589. begin
  590. if lvd<0 then
  591. begin
  592. Message(parser_e_invalid_float_operation);
  593. t:=crealconstnode.create(0,resultrealdef);
  594. end
  595. else if lvd=0 then
  596. t:=crealconstnode.create(1.0,resultrealdef)
  597. else
  598. t:=crealconstnode.create(exp(ln(lvd)*rvd),resultrealdef);
  599. end;
  600. slashn :
  601. t:=crealconstnode.create(lvd/rvd,resultrealdef);
  602. ltn :
  603. t:=cordconstnode.create(ord(lvd<rvd),pasbool8type,true);
  604. lten :
  605. t:=cordconstnode.create(ord(lvd<=rvd),pasbool8type,true);
  606. gtn :
  607. t:=cordconstnode.create(ord(lvd>rvd),pasbool8type,true);
  608. gten :
  609. t:=cordconstnode.create(ord(lvd>=rvd),pasbool8type,true);
  610. equaln :
  611. t:=cordconstnode.create(ord(lvd=rvd),pasbool8type,true);
  612. unequaln :
  613. t:=cordconstnode.create(ord(lvd<>rvd),pasbool8type,true);
  614. else
  615. internalerror(2008022102);
  616. end;
  617. result:=t;
  618. exit;
  619. end;
  620. { first, we handle widestrings, so we can check later for }
  621. { stringconstn only }
  622. { widechars are converted above to widestrings too }
  623. { this isn't ver y efficient, but I don't think }
  624. { that it does matter that much (FK) }
  625. if (lt=stringconstn) and (rt=stringconstn) and
  626. (tstringconstnode(left).cst_type in [cst_widestring,cst_unicodestring]) and
  627. (tstringconstnode(right).cst_type in [cst_widestring,cst_unicodestring]) then
  628. begin
  629. initwidestring(ws1);
  630. initwidestring(ws2);
  631. copywidestring(pcompilerwidestring(tstringconstnode(left).value_str),ws1);
  632. copywidestring(pcompilerwidestring(tstringconstnode(right).value_str),ws2);
  633. case nodetype of
  634. addn :
  635. begin
  636. concatwidestrings(ws1,ws2);
  637. t:=cstringconstnode.createwstr(ws1);
  638. end;
  639. ltn :
  640. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<0),pasbool8type,true);
  641. lten :
  642. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<=0),pasbool8type,true);
  643. gtn :
  644. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)>0),pasbool8type,true);
  645. gten :
  646. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)>=0),pasbool8type,true);
  647. equaln :
  648. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)=0),pasbool8type,true);
  649. unequaln :
  650. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<>0),pasbool8type,true);
  651. else
  652. internalerror(2008022103);
  653. end;
  654. donewidestring(ws1);
  655. donewidestring(ws2);
  656. result:=t;
  657. exit;
  658. end;
  659. { concating strings ? }
  660. concatstrings:=false;
  661. if (lt=ordconstn) and (rt=ordconstn) and
  662. is_char(ld) and is_char(rd) then
  663. begin
  664. c1[0]:=char(int64(tordconstnode(left).value));
  665. c1[1]:=#0;
  666. l1:=1;
  667. c2[0]:=char(int64(tordconstnode(right).value));
  668. c2[1]:=#0;
  669. l2:=1;
  670. s1:=@c1[0];
  671. s2:=@c2[0];
  672. concatstrings:=true;
  673. end
  674. else if (lt=stringconstn) and (rt=ordconstn) and is_char(rd) then
  675. begin
  676. s1:=tstringconstnode(left).value_str;
  677. l1:=tstringconstnode(left).len;
  678. c2[0]:=char(int64(tordconstnode(right).value));
  679. c2[1]:=#0;
  680. s2:=@c2[0];
  681. l2:=1;
  682. concatstrings:=true;
  683. end
  684. else if (lt=ordconstn) and (rt=stringconstn) and is_char(ld) then
  685. begin
  686. c1[0]:=char(int64(tordconstnode(left).value));
  687. c1[1]:=#0;
  688. l1:=1;
  689. s1:=@c1[0];
  690. s2:=tstringconstnode(right).value_str;
  691. l2:=tstringconstnode(right).len;
  692. concatstrings:=true;
  693. end
  694. else if (lt=stringconstn) and (rt=stringconstn) then
  695. begin
  696. s1:=tstringconstnode(left).value_str;
  697. l1:=tstringconstnode(left).len;
  698. s2:=tstringconstnode(right).value_str;
  699. l2:=tstringconstnode(right).len;
  700. concatstrings:=true;
  701. end;
  702. if concatstrings then
  703. begin
  704. case nodetype of
  705. addn :
  706. begin
  707. t:=cstringconstnode.createpchar(concatansistrings(s1,s2,l1,l2),l1+l2);
  708. typecheckpass(t);
  709. tstringconstnode(t).changestringtype(resultdef);
  710. end;
  711. ltn :
  712. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<0),pasbool8type,true);
  713. lten :
  714. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<=0),pasbool8type,true);
  715. gtn :
  716. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)>0),pasbool8type,true);
  717. gten :
  718. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)>=0),pasbool8type,true);
  719. equaln :
  720. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)=0),pasbool8type,true);
  721. unequaln :
  722. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<>0),pasbool8type,true);
  723. else
  724. internalerror(2008022104);
  725. end;
  726. result:=t;
  727. exit;
  728. end;
  729. { set constant evaluation }
  730. if (right.nodetype=setconstn) and
  731. not assigned(tsetconstnode(right).left) and
  732. (left.nodetype=setconstn) and
  733. not assigned(tsetconstnode(left).left) then
  734. begin
  735. case nodetype of
  736. addn :
  737. begin
  738. resultset:=tsetconstnode(right).value_set^ + tsetconstnode(left).value_set^;
  739. t:=csetconstnode.create(@resultset,resultdef);
  740. end;
  741. muln :
  742. begin
  743. resultset:=tsetconstnode(right).value_set^ * tsetconstnode(left).value_set^;
  744. t:=csetconstnode.create(@resultset,resultdef);
  745. end;
  746. subn :
  747. begin
  748. resultset:=tsetconstnode(left).value_set^ - tsetconstnode(right).value_set^;
  749. t:=csetconstnode.create(@resultset,resultdef);
  750. end;
  751. symdifn :
  752. begin
  753. resultset:=tsetconstnode(right).value_set^ >< tsetconstnode(left).value_set^;
  754. t:=csetconstnode.create(@resultset,resultdef);
  755. end;
  756. unequaln :
  757. begin
  758. b:=tsetconstnode(right).value_set^ <> tsetconstnode(left).value_set^;
  759. t:=cordconstnode.create(byte(b),pasbool8type,true);
  760. end;
  761. equaln :
  762. begin
  763. b:=tsetconstnode(right).value_set^ = tsetconstnode(left).value_set^;
  764. t:=cordconstnode.create(byte(b),pasbool8type,true);
  765. end;
  766. lten :
  767. begin
  768. b:=tsetconstnode(left).value_set^ <= tsetconstnode(right).value_set^;
  769. t:=cordconstnode.create(byte(b),pasbool8type,true);
  770. end;
  771. gten :
  772. begin
  773. b:=tsetconstnode(left).value_set^ >= tsetconstnode(right).value_set^;
  774. t:=cordconstnode.create(byte(b),pasbool8type,true);
  775. end;
  776. else
  777. internalerror(2008022105);
  778. end;
  779. result:=t;
  780. exit;
  781. end;
  782. { slow simplifications }
  783. if (cs_opt_level2 in current_settings.optimizerswitches) then
  784. begin
  785. { the comparison is might be expensive and the nodes are usually only
  786. equal if some previous optimizations were done so don't check
  787. this simplification always
  788. }
  789. if is_boolean(left.resultdef) and is_boolean(right.resultdef) and
  790. { since the expressions might have sideeffects, we may only remove them
  791. if short boolean evaluation is turned on }
  792. (nf_short_bool in flags) then
  793. begin
  794. if left.isequal(right) then
  795. begin
  796. case nodetype of
  797. andn,orn:
  798. begin
  799. result:=left;
  800. left:=nil;
  801. exit;
  802. end;
  803. {
  804. xorn:
  805. begin
  806. result:=cordconstnode.create(0,resultdef,true);
  807. exit;
  808. end;
  809. }
  810. end;
  811. end;
  812. end;
  813. { using sqr(x) for reals instead of x*x might reduces register pressure and/or
  814. memory accesses while sqr(<real>) has no drawback }
  815. if
  816. {$ifdef cpufpemu}
  817. (current_settings.fputype<>fpu_soft) and
  818. not(cs_fp_emulation in current_settings.moduleswitches) and
  819. {$endif cpufpemu}
  820. (nodetype=muln) and
  821. is_real(left.resultdef) and is_real(right.resultdef) and
  822. left.isequal(right) and
  823. not(might_have_sideeffects(left)) then
  824. begin
  825. result:=cinlinenode.create(in_sqr_real,false,left);
  826. left:=nil;
  827. exit;
  828. end;
  829. {$ifdef cpurox}
  830. { optimize (i shl x) or (i shr (bitsizeof(i)-x)) into rol(x,i) (and different flavours with shl/shr swapped etc.) }
  831. if (nodetype=orn)
  832. {$ifndef cpu64bitalu}
  833. and (left.resultdef.typ=orddef) and
  834. not(torddef(left.resultdef).ordtype in [s64bit,u64bit,scurrency])
  835. {$endif cpu64bitalu}
  836. then
  837. begin
  838. if (left.nodetype=shrn) and (right.nodetype=shln) and
  839. is_constintnode(tshlshrnode(left).right) and
  840. is_constintnode(tshlshrnode(right).right) and
  841. (tordconstnode(tshlshrnode(right).right).value>0) and
  842. (tordconstnode(tshlshrnode(left).right).value>0) and
  843. tshlshrnode(left).left.isequal(tshlshrnode(right).left) and
  844. not(might_have_sideeffects(tshlshrnode(left).left)) then
  845. begin
  846. if tordconstnode(tshlshrnode(left).right).value=
  847. tshlshrnode(left).left.resultdef.size*8-tordconstnode(tshlshrnode(right).right).value then
  848. begin
  849. result:=cinlinenode.create(in_ror_x_y,false,
  850. ccallparanode.create(tshlshrnode(left).right,
  851. ccallparanode.create(tshlshrnode(left).left,nil)));
  852. tshlshrnode(left).left:=nil;
  853. tshlshrnode(left).right:=nil;
  854. exit;
  855. end
  856. else if tordconstnode(tshlshrnode(right).right).value=
  857. tshlshrnode(left).left.resultdef.size*8-tordconstnode(tshlshrnode(left).right).value then
  858. begin
  859. result:=cinlinenode.create(in_rol_x_y,false,
  860. ccallparanode.create(tshlshrnode(right).right,
  861. ccallparanode.create(tshlshrnode(left).left,nil)));
  862. tshlshrnode(left).left:=nil;
  863. tshlshrnode(right).right:=nil;
  864. exit;
  865. end;
  866. end;
  867. if (left.nodetype=shln) and (right.nodetype=shrn) and
  868. is_constintnode(tshlshrnode(left).right) and
  869. is_constintnode(tshlshrnode(right).right) and
  870. (tordconstnode(tshlshrnode(right).right).value>0) and
  871. (tordconstnode(tshlshrnode(left).right).value>0) and
  872. tshlshrnode(left).left.isequal(tshlshrnode(right).left) and
  873. not(might_have_sideeffects(tshlshrnode(left).left)) then
  874. begin
  875. if tordconstnode(tshlshrnode(left).right).value=
  876. tshlshrnode(left).left.resultdef.size*8-tordconstnode(tshlshrnode(right).right).value then
  877. begin
  878. result:=cinlinenode.create(in_rol_x_y,false,
  879. ccallparanode.create(tshlshrnode(left).right,
  880. ccallparanode.create(tshlshrnode(left).left,nil)));
  881. tshlshrnode(left).left:=nil;
  882. tshlshrnode(left).right:=nil;
  883. exit;
  884. end
  885. else if tordconstnode(tshlshrnode(right).right).value=
  886. tshlshrnode(left).left.resultdef.size*8-tordconstnode(tshlshrnode(left).right).value then
  887. begin
  888. result:=cinlinenode.create(in_ror_x_y,false,
  889. ccallparanode.create(tshlshrnode(right).right,
  890. ccallparanode.create(tshlshrnode(left).left,nil)));
  891. tshlshrnode(left).left:=nil;
  892. tshlshrnode(right).right:=nil;
  893. exit;
  894. end;
  895. end;
  896. end;
  897. {$endif cpurox}
  898. end;
  899. end;
  900. function taddnode.dogetcopy: tnode;
  901. var
  902. n: taddnode;
  903. begin
  904. n:=taddnode(inherited dogetcopy);
  905. n.resultrealdef:=resultrealdef;
  906. result:=n;
  907. end;
  908. function taddnode.docompare(p: tnode): boolean;
  909. begin
  910. result:=
  911. inherited docompare(p) and
  912. equal_defs(taddnode(p).resultrealdef,resultrealdef);
  913. end;
  914. function taddnode.pass_typecheck:tnode;
  915. begin
  916. { This function is small to keep the stack small for recursive of
  917. large + operations }
  918. typecheckpass(left);
  919. typecheckpass(right);
  920. result:=pass_typecheck_internal;
  921. end;
  922. function taddnode.pass_typecheck_internal:tnode;
  923. var
  924. hp : tnode;
  925. rd,ld,nd : tdef;
  926. hsym : tfieldvarsym;
  927. llow,lhigh,
  928. rlow,rhigh : tconstexprint;
  929. strtype : tstringtype;
  930. res,
  931. b : boolean;
  932. lt,rt : tnodetype;
  933. ot : tnodetype;
  934. {$ifdef state_tracking}
  935. factval : Tnode;
  936. change : boolean;
  937. {$endif}
  938. begin
  939. result:=nil;
  940. { avoid any problems with type parameters later on }
  941. if is_typeparam(left.resultdef) or is_typeparam(right.resultdef) then
  942. begin
  943. resultdef:=cundefinedtype;
  944. exit;
  945. end;
  946. { both left and right need to be valid }
  947. set_varstate(left,vs_read,[vsf_must_be_valid]);
  948. set_varstate(right,vs_read,[vsf_must_be_valid]);
  949. if codegenerror then
  950. exit;
  951. { tp procvar support }
  952. maybe_call_procvar(left,true);
  953. maybe_call_procvar(right,true);
  954. { convert array constructors to sets, because there is no other operator
  955. possible for array constructors }
  956. if is_array_constructor(left.resultdef) then
  957. begin
  958. arrayconstructor_to_set(left);
  959. typecheckpass(left);
  960. end;
  961. if is_array_constructor(right.resultdef) then
  962. begin
  963. arrayconstructor_to_set(right);
  964. typecheckpass(right);
  965. end;
  966. { allow operator overloading }
  967. hp:=self;
  968. if isbinaryoverloaded(hp) then
  969. begin
  970. result:=hp;
  971. exit;
  972. end;
  973. { Stop checking when an error was found in the operator checking }
  974. if codegenerror then
  975. begin
  976. result:=cerrornode.create;
  977. exit;
  978. end;
  979. { Kylix allows enum+ordconstn in an enum type declaration, we need to do
  980. the conversion here before the constant folding }
  981. if (m_delphi in current_settings.modeswitches) and
  982. (blocktype in [bt_type,bt_const_type,bt_var_type]) then
  983. begin
  984. if (left.resultdef.typ=enumdef) and
  985. (right.resultdef.typ=orddef) then
  986. begin
  987. { insert explicit typecast to default signed int }
  988. left:=ctypeconvnode.create_internal(left,sinttype);
  989. typecheckpass(left);
  990. end
  991. else
  992. if (left.resultdef.typ=orddef) and
  993. (right.resultdef.typ=enumdef) then
  994. begin
  995. { insert explicit typecast to default signed int }
  996. right:=ctypeconvnode.create_internal(right,sinttype);
  997. typecheckpass(right);
  998. end;
  999. end;
  1000. { is one a real float, then both need to be floats, this
  1001. need to be done before the constant folding so constant
  1002. operation on a float and int are also handled }
  1003. {$ifdef x86}
  1004. { use extended as default real type only when the x87 fpu is used }
  1005. {$ifdef i386}
  1006. if not(current_settings.fputype=fpu_x87) then
  1007. resultrealdef:=s64floattype
  1008. else
  1009. resultrealdef:=pbestrealtype^;
  1010. {$endif i386}
  1011. {$ifdef x86_64}
  1012. { x86-64 has no x87 only mode, so use always double as default }
  1013. resultrealdef:=s64floattype;
  1014. {$endif x86_6}
  1015. {$else not x86}
  1016. resultrealdef:=pbestrealtype^;
  1017. {$endif not x86}
  1018. if (right.resultdef.typ=floatdef) or (left.resultdef.typ=floatdef) then
  1019. begin
  1020. { when both floattypes are already equal then use that
  1021. floattype for results }
  1022. if (right.resultdef.typ=floatdef) and
  1023. (left.resultdef.typ=floatdef) and
  1024. (tfloatdef(left.resultdef).floattype=tfloatdef(right.resultdef).floattype) then
  1025. resultrealdef:=left.resultdef
  1026. { when there is a currency type then use currency, but
  1027. only when currency is defined as float }
  1028. else
  1029. if (is_currency(right.resultdef) or
  1030. is_currency(left.resultdef)) and
  1031. ((s64currencytype.typ = floatdef) or
  1032. (nodetype <> slashn)) then
  1033. begin
  1034. resultrealdef:=s64currencytype;
  1035. inserttypeconv(right,resultrealdef);
  1036. inserttypeconv(left,resultrealdef);
  1037. end
  1038. else
  1039. begin
  1040. resultrealdef:=getbestreal(left.resultdef,right.resultdef);
  1041. inserttypeconv(right,resultrealdef);
  1042. inserttypeconv(left,resultrealdef);
  1043. end;
  1044. end;
  1045. { If both operands are constant and there is a unicodestring
  1046. or unicodestring then convert everything to unicodestring }
  1047. if is_constnode(right) and is_constnode(left) and
  1048. (is_unicodestring(right.resultdef) or
  1049. is_unicodestring(left.resultdef)) then
  1050. begin
  1051. inserttypeconv(right,cunicodestringtype);
  1052. inserttypeconv(left,cunicodestringtype);
  1053. end;
  1054. { If both operands are constant and there is a widechar
  1055. or widestring then convert everything to widestring. This
  1056. allows constant folding like char+widechar }
  1057. if is_constnode(right) and is_constnode(left) and
  1058. (is_widestring(right.resultdef) or
  1059. is_widestring(left.resultdef) or
  1060. is_widechar(right.resultdef) or
  1061. is_widechar(left.resultdef)) then
  1062. begin
  1063. inserttypeconv(right,cwidestringtype);
  1064. inserttypeconv(left,cwidestringtype);
  1065. end;
  1066. { load easier access variables }
  1067. rd:=right.resultdef;
  1068. ld:=left.resultdef;
  1069. rt:=right.nodetype;
  1070. lt:=left.nodetype;
  1071. { 4 character constant strings are compatible with orddef }
  1072. { in macpas mode (become cardinals) }
  1073. if (m_mac in current_settings.modeswitches) and
  1074. { only allow for comparisons, additions etc are }
  1075. { normally program errors }
  1076. (nodetype in [ltn,lten,gtn,gten,unequaln,equaln]) and
  1077. (((lt=stringconstn) and
  1078. (tstringconstnode(left).len=4) and
  1079. (rd.typ=orddef)) or
  1080. ((rt=stringconstn) and
  1081. (tstringconstnode(right).len=4) and
  1082. (ld.typ=orddef))) then
  1083. begin
  1084. if (rt=stringconstn) then
  1085. begin
  1086. inserttypeconv(right,u32inttype);
  1087. rt:=right.nodetype;
  1088. rd:=right.resultdef;
  1089. end
  1090. else
  1091. begin
  1092. inserttypeconv(left,u32inttype);
  1093. lt:=left.nodetype;
  1094. ld:=left.resultdef;
  1095. end;
  1096. end;
  1097. { but an int/int gives real/real! }
  1098. if (nodetype=slashn) and not(is_vector(left.resultdef)) and not(is_vector(right.resultdef)) then
  1099. begin
  1100. if is_currency(left.resultdef) and
  1101. is_currency(right.resultdef) then
  1102. { In case of currency, converting to float means dividing by 10000 }
  1103. { However, since this is already a division, both divisions by }
  1104. { 10000 are eliminated when we divide the results -> we can skip }
  1105. { them. }
  1106. if s64currencytype.typ = floatdef then
  1107. begin
  1108. { there's no s64comptype or so, how do we avoid the type conversion?
  1109. left.resultdef := s64comptype;
  1110. right.resultdef := s64comptype; }
  1111. end
  1112. else
  1113. begin
  1114. left.resultdef := s64inttype;
  1115. right.resultdef := s64inttype;
  1116. end;
  1117. inserttypeconv(right,resultrealdef);
  1118. inserttypeconv(left,resultrealdef);
  1119. end
  1120. { if both are orddefs then check sub types }
  1121. else if (ld.typ=orddef) and (rd.typ=orddef) then
  1122. begin
  1123. { set for & and | operations in macpas mode: they only work on }
  1124. { booleans, and always short circuit evaluation }
  1125. if (nf_short_bool in flags) then
  1126. begin
  1127. if not is_boolean(ld) then
  1128. begin
  1129. inserttypeconv(left,pasbool8type);
  1130. ld := left.resultdef;
  1131. end;
  1132. if not is_boolean(rd) then
  1133. begin
  1134. inserttypeconv(right,pasbool8type);
  1135. rd := right.resultdef;
  1136. end;
  1137. end;
  1138. { 2 booleans? }
  1139. if (is_boolean(ld) and is_boolean(rd)) then
  1140. begin
  1141. case nodetype of
  1142. xorn,
  1143. andn,
  1144. orn:
  1145. begin
  1146. { Make sides equal to the largest boolean }
  1147. if (torddef(left.resultdef).size>torddef(right.resultdef).size) or
  1148. (is_cbool(left.resultdef) and not is_cbool(right.resultdef)) then
  1149. begin
  1150. right:=ctypeconvnode.create_internal(right,left.resultdef);
  1151. ttypeconvnode(right).convtype:=tc_bool_2_bool;
  1152. typecheckpass(right);
  1153. end
  1154. else if (torddef(left.resultdef).size<torddef(right.resultdef).size) or
  1155. (not is_cbool(left.resultdef) and is_cbool(right.resultdef)) then
  1156. begin
  1157. left:=ctypeconvnode.create_internal(left,right.resultdef);
  1158. ttypeconvnode(left).convtype:=tc_bool_2_bool;
  1159. typecheckpass(left);
  1160. end;
  1161. end;
  1162. ltn,
  1163. lten,
  1164. gtn,
  1165. gten:
  1166. begin
  1167. { convert both to pasbool to perform the comparison (so
  1168. that longbool(4) = longbool(2), since both represent
  1169. "true" }
  1170. inserttypeconv(left,pasbool8type);
  1171. inserttypeconv(right,pasbool8type);
  1172. end;
  1173. unequaln,
  1174. equaln:
  1175. begin
  1176. if not(cs_full_boolean_eval in current_settings.localswitches) or
  1177. (nf_short_bool in flags) then
  1178. begin
  1179. { Remove any compares with constants }
  1180. if (left.nodetype=ordconstn) then
  1181. begin
  1182. hp:=right;
  1183. b:=(tordconstnode(left).value<>0);
  1184. ot:=nodetype;
  1185. left.free;
  1186. left:=nil;
  1187. right:=nil;
  1188. if (not(b) and (ot=equaln)) or
  1189. (b and (ot=unequaln)) then
  1190. begin
  1191. hp:=cnotnode.create(hp);
  1192. end;
  1193. result:=hp;
  1194. exit;
  1195. end;
  1196. if (right.nodetype=ordconstn) then
  1197. begin
  1198. hp:=left;
  1199. b:=(tordconstnode(right).value<>0);
  1200. ot:=nodetype;
  1201. right.free;
  1202. right:=nil;
  1203. left:=nil;
  1204. if (not(b) and (ot=equaln)) or
  1205. (b and (ot=unequaln)) then
  1206. begin
  1207. hp:=cnotnode.create(hp);
  1208. end;
  1209. result:=hp;
  1210. exit;
  1211. end;
  1212. end;
  1213. { Delphi-compatibility: convert both to pasbool to
  1214. perform the equality comparison }
  1215. inserttypeconv(left,pasbool8type);
  1216. inserttypeconv(right,pasbool8type);
  1217. end;
  1218. else
  1219. begin
  1220. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1221. result:=cnothingnode.create;
  1222. exit;
  1223. end;
  1224. end;
  1225. end
  1226. { Both are chars? }
  1227. else if is_char(rd) and is_char(ld) then
  1228. begin
  1229. if nodetype=addn then
  1230. begin
  1231. resultdef:=cshortstringtype;
  1232. if not(is_constcharnode(left) and is_constcharnode(right)) then
  1233. begin
  1234. inserttypeconv(left,cshortstringtype);
  1235. {$ifdef addstringopt}
  1236. hp := genaddsstringcharoptnode(self);
  1237. result := hp;
  1238. exit;
  1239. {$endif addstringopt}
  1240. end
  1241. end
  1242. else if not(nodetype in [ltn,lten,gtn,gten,unequaln,equaln]) then
  1243. begin
  1244. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1245. result:=cnothingnode.create;
  1246. exit;
  1247. end;
  1248. end
  1249. { There is a widechar? }
  1250. else if is_widechar(rd) or is_widechar(ld) then
  1251. begin
  1252. { widechar+widechar gives widestring }
  1253. if nodetype=addn then
  1254. begin
  1255. inserttypeconv(left,cwidestringtype);
  1256. if (torddef(rd).ordtype<>uwidechar) then
  1257. inserttypeconv(right,cwidechartype);
  1258. resultdef:=cwidestringtype;
  1259. end
  1260. else
  1261. begin
  1262. if (torddef(ld).ordtype<>uwidechar) then
  1263. inserttypeconv(left,cwidechartype);
  1264. if (torddef(rd).ordtype<>uwidechar) then
  1265. inserttypeconv(right,cwidechartype);
  1266. end;
  1267. end
  1268. { is there a currency type ? }
  1269. else if ((torddef(rd).ordtype=scurrency) or (torddef(ld).ordtype=scurrency)) then
  1270. begin
  1271. if (torddef(ld).ordtype<>scurrency) then
  1272. inserttypeconv(left,s64currencytype);
  1273. if (torddef(rd).ordtype<>scurrency) then
  1274. inserttypeconv(right,s64currencytype);
  1275. end
  1276. { "and" does't care about the sign of integers }
  1277. { "xor", "or" and compares don't need extension to native int }
  1278. { size either as long as both values are signed or unsigned }
  1279. { "xor" and "or" also don't care about the sign if the values }
  1280. { occupy an entire register }
  1281. { don't do it if either type is 64 bit, since in that case we }
  1282. { can't safely find a "common" type }
  1283. else if is_integer(ld) and is_integer(rd) and
  1284. not is_64bitint(ld) and not is_64bitint(rd) and
  1285. ((nodetype=andn) or
  1286. ((nodetype in [orn,xorn,equaln,unequaln,gtn,gten,ltn,lten]) and
  1287. not(is_signed(ld) xor is_signed(rd)))) then
  1288. begin
  1289. if (rd.size>ld.size) or
  1290. { Delphi-compatible: prefer unsigned type for "and" with equal size }
  1291. ((rd.size=ld.size) and
  1292. not is_signed(rd)) then
  1293. begin
  1294. if (rd.size=ld.size) and
  1295. is_signed(ld) then
  1296. inserttypeconv_internal(left,rd)
  1297. else
  1298. begin
  1299. { not to left right.resultdef, because that may
  1300. cause a range error if left and right's def don't
  1301. completely overlap }
  1302. nd:=get_common_intdef(torddef(ld),torddef(rd),true);
  1303. inserttypeconv(left,nd);
  1304. inserttypeconv(right,nd);
  1305. end;
  1306. end
  1307. else
  1308. begin
  1309. if (rd.size=ld.size) and
  1310. is_signed(rd) then
  1311. inserttypeconv_internal(right,ld)
  1312. else
  1313. begin
  1314. nd:=get_common_intdef(torddef(ld),torddef(rd),true);
  1315. inserttypeconv(left,nd);
  1316. inserttypeconv(right,nd);
  1317. end;
  1318. end
  1319. end
  1320. { is there a signed 64 bit type ? }
  1321. else if ((torddef(rd).ordtype=s64bit) or (torddef(ld).ordtype=s64bit)) then
  1322. begin
  1323. if (torddef(ld).ordtype<>s64bit) then
  1324. inserttypeconv(left,s64inttype);
  1325. if (torddef(rd).ordtype<>s64bit) then
  1326. inserttypeconv(right,s64inttype);
  1327. end
  1328. { is there a unsigned 64 bit type ? }
  1329. else if ((torddef(rd).ordtype=u64bit) or (torddef(ld).ordtype=u64bit)) then
  1330. begin
  1331. if (torddef(ld).ordtype<>u64bit) then
  1332. inserttypeconv(left,u64inttype);
  1333. if (torddef(rd).ordtype<>u64bit) then
  1334. inserttypeconv(right,u64inttype);
  1335. end
  1336. { 64 bit cpus do calculations always in 64 bit }
  1337. {$ifndef cpu64bitaddr}
  1338. { is there a cardinal? }
  1339. else if ((torddef(rd).ordtype=u32bit) or (torddef(ld).ordtype=u32bit)) then
  1340. begin
  1341. { convert positive constants to u32bit }
  1342. if (torddef(ld).ordtype<>u32bit) and
  1343. is_constintnode(left) and
  1344. (tordconstnode(left).value >= 0) then
  1345. inserttypeconv(left,u32inttype);
  1346. if (torddef(rd).ordtype<>u32bit) and
  1347. is_constintnode(right) and
  1348. (tordconstnode(right).value >= 0) then
  1349. inserttypeconv(right,u32inttype);
  1350. { when one of the operand is signed or the operation is subn then perform
  1351. the operation in 64bit, can't use rd/ld here because there
  1352. could be already typeconvs inserted.
  1353. This is compatible with the code below for other unsigned types (PFV) }
  1354. if is_signed(left.resultdef) or
  1355. is_signed(right.resultdef) or
  1356. (nodetype=subn) then
  1357. begin
  1358. if nodetype<>subn then
  1359. CGMessage(type_h_mixed_signed_unsigned);
  1360. { mark as internal in case added for a subn, so }
  1361. { ttypeconvnode.simplify can remove the 64 bit }
  1362. { typecast again if semantically correct. Even }
  1363. { if we could detect that here already, we }
  1364. { mustn't do it here because that would change }
  1365. { overload choosing behaviour etc. The code in }
  1366. { ncnv.pas is run after that is already decided }
  1367. if (not is_signed(left.resultdef) and
  1368. not is_signed(right.resultdef)) or
  1369. (nodetype in [orn,xorn]) then
  1370. include(flags,nf_internal);
  1371. inserttypeconv(left,s64inttype);
  1372. inserttypeconv(right,s64inttype);
  1373. end
  1374. else
  1375. begin
  1376. if (torddef(left.resultdef).ordtype<>u32bit) then
  1377. inserttypeconv(left,u32inttype);
  1378. if (torddef(right.resultdef).ordtype<>u32bit) then
  1379. inserttypeconv(right,u32inttype);
  1380. end;
  1381. end
  1382. {$endif cpu64bitaddr}
  1383. { generic ord conversion is sinttype }
  1384. else
  1385. begin
  1386. { When there is a signed type or there is a minus operation
  1387. we convert to signed int. Otherwise (both are unsigned) we keep
  1388. the result also unsigned. This is compatible with Delphi (PFV) }
  1389. if is_signed(ld) or
  1390. is_signed(rd) or
  1391. (nodetype=subn) then
  1392. begin
  1393. {$ifdef cpunodefaultint}
  1394. { for small cpus we use the smallest common type }
  1395. nd:=get_common_intdef(torddef(ld),torddef(rd),false);
  1396. inserttypeconv(right,nd);
  1397. inserttypeconv(left,nd);
  1398. {$else cpunodefaultint}
  1399. inserttypeconv(right,sinttype);
  1400. inserttypeconv(left,sinttype);
  1401. {$endif cpunodefaultint}
  1402. end
  1403. else
  1404. begin
  1405. inserttypeconv(right,uinttype);
  1406. inserttypeconv(left,uinttype);
  1407. end;
  1408. end;
  1409. end
  1410. { if both are floatdefs, conversion is already done before constant folding }
  1411. else if (ld.typ=floatdef) then
  1412. begin
  1413. if not(nodetype in [addn,subn,muln,slashn,equaln,unequaln,ltn,lten,gtn,gten]) then
  1414. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1415. end
  1416. { left side a setdef, must be before string processing,
  1417. else array constructor can be seen as array of char (PFV) }
  1418. else if (ld.typ=setdef) then
  1419. begin
  1420. if not(nodetype in [addn,subn,symdifn,muln,equaln,unequaln,lten,gten]) then
  1421. CGMessage(type_e_set_operation_unknown);
  1422. { right must either be a set or a set element }
  1423. if (rd.typ<>setdef) and
  1424. (rt<>setelementn) then
  1425. CGMessage(type_e_mismatch)
  1426. { Make operands the same setdef. If one's elementtype fits }
  1427. { entirely inside the other's, pick the one with the largest }
  1428. { range. Otherwise create a new setdef with a range which }
  1429. { can contain both. }
  1430. else if not(equal_defs(ld,rd)) then
  1431. begin
  1432. { note: ld cannot be an empty set with elementdef=nil in }
  1433. { case right is not a set, arrayconstructor_to_set takes }
  1434. { care of that }
  1435. { 1: rd is a set with an assigned elementdef, and ld is }
  1436. { either an empty set without elementdef or a set whose }
  1437. { elementdef fits in rd's elementdef -> convert to rd }
  1438. if ((rd.typ=setdef) and
  1439. assigned(tsetdef(rd).elementdef) and
  1440. (not assigned(tsetdef(ld).elementdef) or
  1441. is_in_limit(ld,rd))) then
  1442. inserttypeconv(left,rd)
  1443. { 2: rd is either an empty set without elementdef or a set }
  1444. { whose elementdef fits in ld's elementdef, or a set }
  1445. { element whose def fits in ld's elementdef -> convert }
  1446. { to ld. ld's elementdef can't be nil here, is caught }
  1447. { previous case and "note:" above }
  1448. else if ((rd.typ=setdef) and
  1449. (not assigned(tsetdef(rd).elementdef) or
  1450. is_in_limit(rd,ld))) or
  1451. ((rd.typ<>setdef) and
  1452. is_in_limit(rd,tsetdef(ld).elementdef)) then
  1453. if (rd.typ=setdef) then
  1454. inserttypeconv(right,ld)
  1455. else
  1456. inserttypeconv(right,tsetdef(ld).elementdef)
  1457. { 3: otherwise create setdef which encompasses both, taking }
  1458. { into account empty sets without elementdef }
  1459. else
  1460. begin
  1461. if assigned(tsetdef(ld).elementdef) then
  1462. begin
  1463. llow:=tsetdef(ld).setbase;
  1464. lhigh:=tsetdef(ld).setmax;
  1465. end;
  1466. if (rd.typ=setdef) then
  1467. if assigned(tsetdef(rd).elementdef) then
  1468. begin
  1469. rlow:=tsetdef(rd).setbase;
  1470. rhigh:=tsetdef(rd).setmax;
  1471. end
  1472. else
  1473. begin
  1474. { ld's elementdef must have been valid }
  1475. rlow:=llow;
  1476. rhigh:=lhigh;
  1477. end
  1478. else
  1479. getrange(rd,rlow,rhigh);
  1480. if not assigned(tsetdef(ld).elementdef) then
  1481. begin
  1482. llow:=rlow;
  1483. lhigh:=rhigh;
  1484. end;
  1485. nd:=tsetdef.create(tsetdef(ld).elementdef,min(llow,rlow),max(lhigh,rhigh));
  1486. inserttypeconv(left,nd);
  1487. if (rd.typ=setdef) then
  1488. inserttypeconv(right,nd)
  1489. else
  1490. inserttypeconv(right,tsetdef(nd).elementdef);
  1491. end;
  1492. end;
  1493. end
  1494. { pointer comparision and subtraction }
  1495. else if (
  1496. (rd.typ=pointerdef) and (ld.typ=pointerdef)
  1497. ) or
  1498. { compare/add pchar to variable (not stringconst) char arrays
  1499. by addresses like BP/Delphi }
  1500. (
  1501. (nodetype in [equaln,unequaln,subn,addn]) and
  1502. (
  1503. ((is_pchar(ld) or (lt=niln)) and is_chararray(rd) and (rt<>stringconstn)) or
  1504. ((is_pchar(rd) or (rt=niln)) and is_chararray(ld) and (lt<>stringconstn))
  1505. )
  1506. ) then
  1507. begin
  1508. { convert char array to pointer }
  1509. if is_chararray(rd) then
  1510. begin
  1511. inserttypeconv(right,charpointertype);
  1512. rd:=right.resultdef;
  1513. end
  1514. else if is_chararray(ld) then
  1515. begin
  1516. inserttypeconv(left,charpointertype);
  1517. ld:=left.resultdef;
  1518. end;
  1519. case nodetype of
  1520. equaln,unequaln :
  1521. begin
  1522. if is_voidpointer(right.resultdef) then
  1523. inserttypeconv(right,left.resultdef)
  1524. else if is_voidpointer(left.resultdef) then
  1525. inserttypeconv(left,right.resultdef)
  1526. else if not(equal_defs(ld,rd)) then
  1527. IncompatibleTypes(ld,rd);
  1528. { now that the type checking is done, convert both to charpointer, }
  1529. { because methodpointers are 8 bytes even though only the first 4 }
  1530. { bytes must be compared. This can happen here if we are in }
  1531. { TP/Delphi mode, because there @methodpointer = voidpointer (but }
  1532. { a voidpointer of 8 bytes). A conversion to voidpointer would be }
  1533. { optimized away, since the result already was a voidpointer, so }
  1534. { use a charpointer instead (JM) }
  1535. inserttypeconv_internal(left,charpointertype);
  1536. inserttypeconv_internal(right,charpointertype);
  1537. end;
  1538. ltn,lten,gtn,gten:
  1539. begin
  1540. if (cs_extsyntax in current_settings.moduleswitches) then
  1541. begin
  1542. if is_voidpointer(right.resultdef) then
  1543. inserttypeconv(right,left.resultdef)
  1544. else if is_voidpointer(left.resultdef) then
  1545. inserttypeconv(left,right.resultdef)
  1546. else if not(equal_defs(ld,rd)) then
  1547. IncompatibleTypes(ld,rd);
  1548. end
  1549. else
  1550. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1551. end;
  1552. subn:
  1553. begin
  1554. if (cs_extsyntax in current_settings.moduleswitches) then
  1555. begin
  1556. if is_voidpointer(right.resultdef) then
  1557. begin
  1558. if is_big_untyped_addrnode(right) then
  1559. CGMessage1(type_w_untyped_arithmetic_unportable,node2opstr(nodetype));
  1560. inserttypeconv(right,left.resultdef)
  1561. end
  1562. else if is_voidpointer(left.resultdef) then
  1563. inserttypeconv(left,right.resultdef)
  1564. else if not(equal_defs(ld,rd)) then
  1565. IncompatibleTypes(ld,rd);
  1566. end
  1567. else
  1568. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1569. if not(nf_has_pointerdiv in flags) and
  1570. (tpointerdef(rd).pointeddef.size>1) then
  1571. begin
  1572. hp:=getcopy;
  1573. include(hp.flags,nf_has_pointerdiv);
  1574. result:=cmoddivnode.create(divn,hp,cordconstnode.create(tpointerdef(rd).pointeddef.size,sinttype,false));
  1575. end;
  1576. resultdef:=sinttype;
  1577. exit;
  1578. end;
  1579. else
  1580. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1581. end;
  1582. end
  1583. { is one of the operands a string?,
  1584. chararrays are also handled as strings (after conversion), also take
  1585. care of chararray+chararray and chararray+char.
  1586. Note: Must be done after pointerdef+pointerdef has been checked, else
  1587. pchar is converted to string }
  1588. else if (rd.typ=stringdef) or
  1589. (ld.typ=stringdef) or
  1590. { stringconstn's can be arraydefs }
  1591. (lt=stringconstn) or
  1592. (rt=stringconstn) or
  1593. ((is_pchar(rd) or is_chararray(rd) or is_char(rd) or is_open_chararray(rd) or
  1594. is_pwidechar(rd) or is_widechararray(rd) or is_widechar(rd) or is_open_widechararray(rd)) and
  1595. (is_pchar(ld) or is_chararray(ld) or is_char(ld) or is_open_chararray(ld) or
  1596. is_pwidechar(ld) or is_widechararray(ld) or is_widechar(ld) or is_open_widechararray(ld))) then
  1597. begin
  1598. if (nodetype in [addn,equaln,unequaln,lten,gten,ltn,gtn]) then
  1599. begin
  1600. { Is there a unicodestring? }
  1601. if is_unicodestring(rd) or is_unicodestring(ld) then
  1602. strtype:=st_unicodestring
  1603. else
  1604. { Is there a widestring? }
  1605. if is_widestring(rd) or is_widestring(ld) or
  1606. is_pwidechar(rd) or is_widechararray(rd) or is_widechar(rd) or is_open_widechararray(rd) or
  1607. is_pwidechar(ld) or is_widechararray(ld) or is_widechar(ld) or is_open_widechararray(ld) then
  1608. strtype:=st_widestring
  1609. else
  1610. if is_ansistring(rd) or is_ansistring(ld) or
  1611. ((cs_ansistrings in current_settings.localswitches) and
  1612. //todo: Move some of this to longstring's then they are implemented?
  1613. (
  1614. is_pchar(rd) or (is_chararray(rd) and (rd.size > 255)) or is_open_chararray(rd) or (lt = stringconstn) or
  1615. is_pchar(ld) or (is_chararray(ld) and (ld.size > 255)) or is_open_chararray(ld) or (rt = stringconstn)
  1616. )
  1617. ) then
  1618. strtype:=st_ansistring
  1619. else
  1620. if is_longstring(rd) or is_longstring(ld) then
  1621. strtype:=st_longstring
  1622. else
  1623. begin
  1624. { TODO: todo: add a warning/hint here if one converting a too large array}
  1625. { nodes is PChar, array [with size > 255] or OpenArrayOfChar.
  1626. Note: Delphi halts with error if "array [0..xx] of char"
  1627. is assigned to ShortString and string length is less
  1628. then array size }
  1629. strtype:= st_shortstring;
  1630. end;
  1631. // Now convert nodes to common string type
  1632. case strtype of
  1633. st_widestring :
  1634. begin
  1635. if not(is_widestring(rd)) then
  1636. inserttypeconv(right,cwidestringtype);
  1637. if not(is_widestring(ld)) then
  1638. inserttypeconv(left,cwidestringtype);
  1639. end;
  1640. st_unicodestring :
  1641. begin
  1642. if not(is_unicodestring(rd)) then
  1643. inserttypeconv(right,cunicodestringtype);
  1644. if not(is_unicodestring(ld)) then
  1645. inserttypeconv(left,cunicodestringtype);
  1646. end;
  1647. st_ansistring :
  1648. begin
  1649. { use same code page if possible (don't force same code
  1650. page in case both are ansistrings with code page <>
  1651. CP_NONE, since then data loss can occur (the ansistring
  1652. helpers will convert them at run time to an encoding
  1653. that can represent both encodings) }
  1654. if is_ansistring(ld) and
  1655. (tstringdef(ld).encoding<>0) and
  1656. (tstringdef(ld).encoding<>globals.CP_NONE) and
  1657. (not is_ansistring(rd) or
  1658. (tstringdef(rd).encoding=0) or
  1659. (tstringdef(rd).encoding=globals.CP_NONE)) then
  1660. inserttypeconv(right,ld)
  1661. else if is_ansistring(rd) and
  1662. (tstringdef(rd).encoding<>0) and
  1663. (tstringdef(rd).encoding<>globals.CP_NONE) and
  1664. (not is_ansistring(ld) or
  1665. (tstringdef(ld).encoding=0) or
  1666. (tstringdef(ld).encoding=globals.CP_NONE)) then
  1667. inserttypeconv(left,rd)
  1668. else
  1669. begin
  1670. if not is_ansistring(ld) then
  1671. inserttypeconv(left,getansistringdef);
  1672. if not is_ansistring(rd) then
  1673. inserttypeconv(right,getansistringdef);
  1674. end;
  1675. end;
  1676. st_longstring :
  1677. begin
  1678. if not(is_longstring(rd)) then
  1679. inserttypeconv(right,clongstringtype);
  1680. if not(is_longstring(ld)) then
  1681. inserttypeconv(left,clongstringtype);
  1682. end;
  1683. st_shortstring :
  1684. begin
  1685. if not(is_shortstring(ld)) then
  1686. inserttypeconv(left,cshortstringtype);
  1687. { don't convert char, that can be handled by the optimized node }
  1688. if not(is_shortstring(rd) or is_char(rd)) then
  1689. inserttypeconv(right,cshortstringtype);
  1690. end;
  1691. else
  1692. internalerror(2005101);
  1693. end;
  1694. end
  1695. else
  1696. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1697. end
  1698. { implicit pointer object type comparison }
  1699. else if is_implicit_pointer_object_type(rd) or is_implicit_pointer_object_type(ld) then
  1700. begin
  1701. if (nodetype in [equaln,unequaln]) then
  1702. begin
  1703. if is_implicit_pointer_object_type(rd) and is_implicit_pointer_object_type(ld) then
  1704. begin
  1705. if tobjectdef(rd).is_related(tobjectdef(ld)) then
  1706. inserttypeconv(right,left.resultdef)
  1707. else
  1708. inserttypeconv(left,right.resultdef);
  1709. end
  1710. else if is_implicit_pointer_object_type(rd) then
  1711. inserttypeconv(left,right.resultdef)
  1712. else
  1713. inserttypeconv(right,left.resultdef);
  1714. end
  1715. else
  1716. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1717. end
  1718. else if (rd.typ=classrefdef) and (ld.typ=classrefdef) then
  1719. begin
  1720. if (nodetype in [equaln,unequaln]) then
  1721. begin
  1722. if tobjectdef(tclassrefdef(rd).pointeddef).is_related(
  1723. tobjectdef(tclassrefdef(ld).pointeddef)) then
  1724. inserttypeconv(right,left.resultdef)
  1725. else
  1726. inserttypeconv(left,right.resultdef);
  1727. end
  1728. else
  1729. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1730. end
  1731. { allow comparison with nil pointer }
  1732. else if is_implicit_pointer_object_type(rd) or (rd.typ=classrefdef) then
  1733. begin
  1734. if (nodetype in [equaln,unequaln]) then
  1735. inserttypeconv(left,right.resultdef)
  1736. else
  1737. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1738. end
  1739. else if is_implicit_pointer_object_type(ld) or (ld.typ=classrefdef) then
  1740. begin
  1741. if (nodetype in [equaln,unequaln]) then
  1742. inserttypeconv(right,left.resultdef)
  1743. else
  1744. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1745. end
  1746. { support procvar=nil,procvar<>nil }
  1747. else if ((ld.typ=procvardef) and (rt=niln)) or
  1748. ((rd.typ=procvardef) and (lt=niln)) then
  1749. begin
  1750. if not(nodetype in [equaln,unequaln]) then
  1751. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1752. { find proc field in methodpointer record }
  1753. hsym:=tfieldvarsym(trecorddef(methodpointertype).symtable.Find('proc'));
  1754. if not assigned(hsym) then
  1755. internalerror(200412043);
  1756. { For methodpointers compare only tmethodpointer.proc }
  1757. if (rd.typ=procvardef) and
  1758. (not tprocvardef(rd).is_addressonly) then
  1759. begin
  1760. right:=csubscriptnode.create(
  1761. hsym,
  1762. ctypeconvnode.create_internal(right,methodpointertype));
  1763. typecheckpass(right);
  1764. end;
  1765. if (ld.typ=procvardef) and
  1766. (not tprocvardef(ld).is_addressonly) then
  1767. begin
  1768. left:=csubscriptnode.create(
  1769. hsym,
  1770. ctypeconvnode.create_internal(left,methodpointertype));
  1771. typecheckpass(left);
  1772. end;
  1773. end
  1774. { support dynamicarray=nil,dynamicarray<>nil }
  1775. else if (is_dynamic_array(ld) and (rt=niln)) or
  1776. (is_dynamic_array(rd) and (lt=niln)) or
  1777. (is_dynamic_array(ld) and is_dynamic_array(rd)) then
  1778. begin
  1779. if not(nodetype in [equaln,unequaln]) then
  1780. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1781. end
  1782. {$ifdef SUPPORT_MMX}
  1783. { mmx support, this must be before the zero based array
  1784. check }
  1785. else if (cs_mmx in current_settings.localswitches) and
  1786. is_mmx_able_array(ld) and
  1787. is_mmx_able_array(rd) and
  1788. equal_defs(ld,rd) then
  1789. begin
  1790. case nodetype of
  1791. addn,subn,xorn,orn,andn:
  1792. ;
  1793. { mul is a little bit restricted }
  1794. muln:
  1795. if not(mmx_type(ld) in [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1796. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1797. else
  1798. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1799. end;
  1800. end
  1801. {$endif SUPPORT_MMX}
  1802. { vector support, this must be before the zero based array
  1803. check }
  1804. else if (cs_support_vectors in current_settings.globalswitches) and
  1805. is_vector(ld) and
  1806. is_vector(rd) and
  1807. equal_defs(ld,rd) then
  1808. begin
  1809. if not(nodetype in [addn,subn,xorn,orn,andn,muln,slashn]) then
  1810. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1811. { both defs must be equal, so taking left or right as resultdef doesn't matter }
  1812. resultdef:=left.resultdef;
  1813. end
  1814. { this is a little bit dangerous, also the left type }
  1815. { pointer to should be checked! This broke the mmx support }
  1816. else if (rd.typ=pointerdef) or
  1817. (is_zero_based_array(rd) and (rt<>stringconstn)) then
  1818. begin
  1819. if is_zero_based_array(rd) then
  1820. begin
  1821. resultdef:=tpointerdef.create(tarraydef(rd).elementdef);
  1822. inserttypeconv(right,resultdef);
  1823. end
  1824. else
  1825. resultdef:=right.resultdef;
  1826. inserttypeconv(left,sinttype);
  1827. if nodetype=addn then
  1828. begin
  1829. if not(cs_extsyntax in current_settings.moduleswitches) or
  1830. (not (is_pchar(ld) or is_chararray(ld) or is_open_chararray(ld) or is_widechar(ld) or is_widechararray(ld) or is_open_widechararray(ld)) and
  1831. not(cs_pointermath in current_settings.localswitches) and
  1832. not((ld.typ=pointerdef) and tpointerdef(ld).has_pointer_math)) then
  1833. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1834. if (rd.typ=pointerdef) and
  1835. (tpointerdef(rd).pointeddef.size>1) then
  1836. begin
  1837. left:=caddnode.create(muln,left,
  1838. cordconstnode.create(tpointerdef(rd).pointeddef.size,sinttype,true));
  1839. typecheckpass(left);
  1840. end;
  1841. end
  1842. else
  1843. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1844. end
  1845. else if (ld.typ=pointerdef) or
  1846. (is_zero_based_array(ld) and (lt<>stringconstn)) then
  1847. begin
  1848. if is_zero_based_array(ld) then
  1849. begin
  1850. resultdef:=tpointerdef.create(tarraydef(ld).elementdef);
  1851. inserttypeconv(left,resultdef);
  1852. end
  1853. else
  1854. resultdef:=left.resultdef;
  1855. inserttypeconv(right,sinttype);
  1856. if nodetype in [addn,subn] then
  1857. begin
  1858. if (lt=niln) then
  1859. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),'NIL',rd.typename);
  1860. if not(cs_extsyntax in current_settings.moduleswitches) or
  1861. (not (is_pchar(ld) or is_chararray(ld) or is_open_chararray(ld) or is_widechar(ld) or is_widechararray(ld) or is_open_widechararray(ld)) and
  1862. not(cs_pointermath in current_settings.localswitches) and
  1863. not((ld.typ=pointerdef) and tpointerdef(ld).has_pointer_math)) then
  1864. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1865. if (ld.typ=pointerdef) then
  1866. begin
  1867. if is_big_untyped_addrnode(left) then
  1868. CGMessage1(type_w_untyped_arithmetic_unportable,node2opstr(nodetype));
  1869. if (tpointerdef(ld).pointeddef.size>1) then
  1870. begin
  1871. right:=caddnode.create(muln,right,
  1872. cordconstnode.create(tpointerdef(ld).pointeddef.size,sinttype,true));
  1873. typecheckpass(right);
  1874. end
  1875. end else
  1876. if is_zero_based_array(ld) and
  1877. (tarraydef(ld).elementdef.size>1) then
  1878. begin
  1879. right:=caddnode.create(muln,right,
  1880. cordconstnode.create(tarraydef(ld).elementdef.size,sinttype,true));
  1881. typecheckpass(right);
  1882. end;
  1883. end
  1884. else
  1885. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1886. end
  1887. else if (rd.typ=procvardef) and
  1888. (ld.typ=procvardef) and
  1889. equal_defs(rd,ld) then
  1890. begin
  1891. if (nodetype in [equaln,unequaln]) then
  1892. begin
  1893. if tprocvardef(rd).is_addressonly then
  1894. begin
  1895. inserttypeconv_internal(right,voidpointertype);
  1896. inserttypeconv_internal(left,voidpointertype);
  1897. end
  1898. else
  1899. begin
  1900. { find proc field in methodpointer record }
  1901. hsym:=tfieldvarsym(trecorddef(methodpointertype).symtable.Find('proc'));
  1902. if not assigned(hsym) then
  1903. internalerror(200412043);
  1904. { Compare tmehodpointer(left).proc }
  1905. right:=csubscriptnode.create(
  1906. hsym,
  1907. ctypeconvnode.create_internal(right,methodpointertype));
  1908. typecheckpass(right);
  1909. left:=csubscriptnode.create(
  1910. hsym,
  1911. ctypeconvnode.create_internal(left,methodpointertype));
  1912. typecheckpass(left);
  1913. end;
  1914. end
  1915. else
  1916. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1917. end
  1918. { enums }
  1919. else if (ld.typ=enumdef) and (rd.typ=enumdef) then
  1920. begin
  1921. if allowenumop(nodetype) then
  1922. inserttypeconv(right,left.resultdef)
  1923. else
  1924. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1925. end
  1926. { generic conversion, this is for error recovery }
  1927. else
  1928. begin
  1929. inserttypeconv(left,sinttype);
  1930. inserttypeconv(right,sinttype);
  1931. end;
  1932. if cmp_of_disjunct_ranges(res) then
  1933. begin
  1934. if res then
  1935. CGMessage(type_w_comparison_always_true)
  1936. else
  1937. CGMessage(type_w_comparison_always_false);
  1938. end;
  1939. { set resultdef if not already done }
  1940. if not assigned(resultdef) then
  1941. begin
  1942. case nodetype of
  1943. ltn,lten,gtn,gten,equaln,unequaln :
  1944. resultdef:=pasbool8type;
  1945. slashn :
  1946. resultdef:=resultrealdef;
  1947. addn:
  1948. begin
  1949. { for strings, return is always a 255 char string }
  1950. if is_shortstring(left.resultdef) then
  1951. resultdef:=cshortstringtype
  1952. else
  1953. { for ansistrings set resultdef to assignment left node
  1954. if it is an assignment and left node expects ansistring }
  1955. if is_ansistring(left.resultdef) and
  1956. assigned(aktassignmentnode) and
  1957. (aktassignmentnode.right=self) and
  1958. is_ansistring(aktassignmentnode.left.resultdef) then
  1959. resultdef:=aktassignmentnode.left.resultdef
  1960. else
  1961. resultdef:=left.resultdef;
  1962. end;
  1963. else
  1964. resultdef:=left.resultdef;
  1965. end;
  1966. end;
  1967. { when the result is currency we need some extra code for
  1968. multiplication and division. this should not be done when
  1969. the muln or slashn node is created internally }
  1970. if not(nf_is_currency in flags) and
  1971. is_currency(resultdef) then
  1972. begin
  1973. case nodetype of
  1974. slashn :
  1975. begin
  1976. { slashn will only work with floats }
  1977. hp:=caddnode.create(muln,getcopy,crealconstnode.create(10000.0,s64currencytype));
  1978. include(hp.flags,nf_is_currency);
  1979. result:=hp;
  1980. end;
  1981. muln :
  1982. begin
  1983. if s64currencytype.typ=floatdef then
  1984. hp:=caddnode.create(slashn,getcopy,crealconstnode.create(10000.0,s64currencytype))
  1985. else
  1986. hp:=cmoddivnode.create(divn,getcopy,cordconstnode.create(10000,s64currencytype,false));
  1987. include(hp.flags,nf_is_currency);
  1988. result:=hp
  1989. end;
  1990. end;
  1991. end;
  1992. if not codegenerror and
  1993. not assigned(result) then
  1994. result:=simplify(false);
  1995. end;
  1996. function taddnode.first_addstring: tnode;
  1997. const
  1998. swap_relation: array [ltn..unequaln] of Tnodetype=(gtn, gten, ltn, lten, equaln, unequaln);
  1999. var
  2000. p: tnode;
  2001. newstatement : tstatementnode;
  2002. tempnode (*,tempnode2*) : ttempcreatenode;
  2003. cmpfuncname: string;
  2004. para: tcallparanode;
  2005. begin
  2006. { when we get here, we are sure that both the left and the right }
  2007. { node are both strings of the same stringtype (JM) }
  2008. case nodetype of
  2009. addn:
  2010. begin
  2011. if (left.nodetype=stringconstn) and (tstringconstnode(left).len=0) then
  2012. begin
  2013. result:=right;
  2014. left.free;
  2015. left:=nil;
  2016. right:=nil;
  2017. exit;
  2018. end;
  2019. if (right.nodetype=stringconstn) and (tstringconstnode(right).len=0) then
  2020. begin
  2021. result:=left;
  2022. left:=nil;
  2023. right.free;
  2024. right:=nil;
  2025. exit;
  2026. end;
  2027. { create the call to the concat routine both strings as arguments }
  2028. if assigned(aktassignmentnode) and
  2029. (aktassignmentnode.right=self) and
  2030. (aktassignmentnode.left.resultdef=resultdef) and
  2031. valid_for_var(aktassignmentnode.left,false) then
  2032. begin
  2033. para:=ccallparanode.create(
  2034. right,
  2035. ccallparanode.create(
  2036. left,
  2037. ccallparanode.create(aktassignmentnode.left.getcopy,nil)
  2038. )
  2039. );
  2040. if is_ansistring(resultdef) then
  2041. para:=ccallparanode.create(
  2042. cordconstnode.create(
  2043. getparaencoding(resultdef),
  2044. u16inttype,
  2045. true
  2046. ),
  2047. para
  2048. );
  2049. result:=ccallnode.createintern(
  2050. 'fpc_'+tstringdef(resultdef).stringtypname+'_concat',
  2051. para
  2052. );
  2053. include(aktassignmentnode.flags,nf_assign_done_in_right);
  2054. firstpass(result);
  2055. end
  2056. else
  2057. begin
  2058. result:=internalstatements(newstatement);
  2059. tempnode:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2060. addstatement(newstatement,tempnode);
  2061. para:=ccallparanode.create(
  2062. right,
  2063. ccallparanode.create(
  2064. left,
  2065. ccallparanode.create(ctemprefnode.create(tempnode),nil)
  2066. )
  2067. );
  2068. if is_ansistring(resultdef) then
  2069. para:=ccallparanode.create(
  2070. cordconstnode.create(
  2071. getparaencoding(resultdef),
  2072. u16inttype,
  2073. true
  2074. ),
  2075. para
  2076. );
  2077. addstatement(
  2078. newstatement,
  2079. ccallnode.createintern(
  2080. 'fpc_'+tstringdef(resultdef).stringtypname+'_concat',
  2081. para
  2082. )
  2083. );
  2084. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
  2085. addstatement(newstatement,ctemprefnode.create(tempnode));
  2086. end;
  2087. { we reused the arguments }
  2088. left := nil;
  2089. right := nil;
  2090. end;
  2091. ltn,lten,gtn,gten,equaln,unequaln :
  2092. begin
  2093. { generate better code for comparison with empty string, we
  2094. only need to compare the length with 0 }
  2095. if (nodetype in [equaln,unequaln,gtn,gten,ltn,lten]) and
  2096. { windows widestrings are too complicated to be handled optimized }
  2097. not(is_widestring(left.resultdef) and (target_info.system in systems_windows)) and
  2098. (((left.nodetype=stringconstn) and (tstringconstnode(left).len=0)) or
  2099. ((right.nodetype=stringconstn) and (tstringconstnode(right).len=0))) then
  2100. begin
  2101. { switch so that the constant is always on the right }
  2102. if left.nodetype = stringconstn then
  2103. begin
  2104. p := left;
  2105. left := right;
  2106. right := p;
  2107. nodetype:=swap_relation[nodetype];
  2108. end;
  2109. if is_shortstring(left.resultdef) or
  2110. (nodetype in [gtn,gten,ltn,lten]) then
  2111. { compare the length with 0 }
  2112. result := caddnode.create(nodetype,
  2113. cinlinenode.create(in_length_x,false,left),
  2114. cordconstnode.create(0,s32inttype,false))
  2115. else
  2116. begin
  2117. (*
  2118. if is_widestring(left.resultdef) and
  2119. (target_info.system in system_windows) then
  2120. begin
  2121. { windows like widestrings requires that we also check the length }
  2122. result:=internalstatements(newstatement);
  2123. tempnode:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  2124. tempnode2:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2125. addstatement(newstatement,tempnode);
  2126. addstatement(newstatement,tempnode2);
  2127. { poor man's cse }
  2128. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  2129. ctypeconvnode.create_internal(left,voidpointertype))
  2130. );
  2131. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(tempnode2),
  2132. caddnode.create(orn,
  2133. caddnode.create(nodetype,
  2134. ctemprefnode.create(tempnode),
  2135. cpointerconstnode.create(0,voidpointertype)
  2136. ),
  2137. caddnode.create(nodetype,
  2138. ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),s32inttype),
  2139. cordconstnode.create(0,s32inttype,false)
  2140. )
  2141. )
  2142. ));
  2143. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
  2144. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode2));
  2145. addstatement(newstatement,ctemprefnode.create(tempnode2));
  2146. end
  2147. else
  2148. *)
  2149. begin
  2150. { compare the pointer with nil (for ansistrings etc), }
  2151. { faster than getting the length (JM) }
  2152. result:= caddnode.create(nodetype,
  2153. ctypeconvnode.create_internal(left,voidpointertype),
  2154. cpointerconstnode.create(0,voidpointertype));
  2155. end;
  2156. end;
  2157. { left is reused }
  2158. left := nil;
  2159. { right isn't }
  2160. right.free;
  2161. right := nil;
  2162. exit;
  2163. end;
  2164. { no string constant -> call compare routine }
  2165. cmpfuncname := 'fpc_'+tstringdef(left.resultdef).stringtypname+'_compare';
  2166. { for equality checks use optimized version }
  2167. if nodetype in [equaln,unequaln] then
  2168. cmpfuncname := cmpfuncname + '_equal';
  2169. result := ccallnode.createintern(cmpfuncname,
  2170. ccallparanode.create(right,ccallparanode.create(left,nil)));
  2171. { and compare its result with 0 according to the original operator }
  2172. result := caddnode.create(nodetype,result,
  2173. cordconstnode.create(0,s32inttype,false));
  2174. left := nil;
  2175. right := nil;
  2176. end;
  2177. end;
  2178. end;
  2179. function taddnode.first_addset : tnode;
  2180. procedure call_varset_helper(const n : string);
  2181. var
  2182. newstatement : tstatementnode;
  2183. temp : ttempcreatenode;
  2184. begin
  2185. { add two var sets }
  2186. result:=internalstatements(newstatement);
  2187. { create temp for result }
  2188. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2189. addstatement(newstatement,temp);
  2190. addstatement(newstatement,ccallnode.createintern(n,
  2191. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2192. ccallparanode.create(ctemprefnode.create(temp),
  2193. ccallparanode.create(right,
  2194. ccallparanode.create(left,nil)))))
  2195. );
  2196. { remove reused parts from original node }
  2197. left:=nil;
  2198. right:=nil;
  2199. { the last statement should return the value as
  2200. location and type, this is done be referencing the
  2201. temp and converting it first from a persistent temp to
  2202. normal temp }
  2203. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2204. addstatement(newstatement,ctemprefnode.create(temp));
  2205. end;
  2206. var
  2207. procname: string[31];
  2208. tempn: tnode;
  2209. newstatement : tstatementnode;
  2210. temp : ttempcreatenode;
  2211. begin
  2212. result:=nil;
  2213. case nodetype of
  2214. equaln,unequaln,lten,gten:
  2215. begin
  2216. case nodetype of
  2217. equaln,unequaln:
  2218. procname := 'fpc_varset_comp_sets';
  2219. lten,gten:
  2220. begin
  2221. procname := 'fpc_varset_contains_sets';
  2222. { (left >= right) = (right <= left) }
  2223. if nodetype = gten then
  2224. begin
  2225. tempn := left;
  2226. left := right;
  2227. right := tempn;
  2228. end;
  2229. end;
  2230. end;
  2231. result := ccallnode.createinternres(procname,
  2232. ccallparanode.create(cordconstnode.create(left.resultdef.size,sinttype,false),
  2233. ccallparanode.create(right,
  2234. ccallparanode.create(left,nil))),resultdef);
  2235. { left and right are reused as parameters }
  2236. left := nil;
  2237. right := nil;
  2238. { for an unequaln, we have to negate the result of comp_sets }
  2239. if nodetype = unequaln then
  2240. result := cnotnode.create(result);
  2241. end;
  2242. addn:
  2243. begin
  2244. { optimize first loading of a set }
  2245. if (right.nodetype=setelementn) and
  2246. not(assigned(tsetelementnode(right).right)) and
  2247. is_emptyset(left) then
  2248. begin
  2249. result:=internalstatements(newstatement);
  2250. { create temp for result }
  2251. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2252. addstatement(newstatement,temp);
  2253. { adjust for set base }
  2254. tsetelementnode(right).left:=caddnode.create(subn,
  2255. ctypeconvnode.create_internal(tsetelementnode(right).left,sinttype),
  2256. cordconstnode.create(tsetdef(resultdef).setbase,sinttype,false));
  2257. addstatement(newstatement,ccallnode.createintern('fpc_varset_create_element',
  2258. ccallparanode.create(ctemprefnode.create(temp),
  2259. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2260. ccallparanode.create(tsetelementnode(right).left,nil))))
  2261. );
  2262. { the last statement should return the value as
  2263. location and type, this is done be referencing the
  2264. temp and converting it first from a persistent temp to
  2265. normal temp }
  2266. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2267. addstatement(newstatement,ctemprefnode.create(temp));
  2268. tsetelementnode(right).left := nil;
  2269. end
  2270. else
  2271. begin
  2272. if right.nodetype=setelementn then
  2273. begin
  2274. result:=internalstatements(newstatement);
  2275. { create temp for result }
  2276. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2277. addstatement(newstatement,temp);
  2278. { adjust for set base }
  2279. tsetelementnode(right).left:=caddnode.create(subn,
  2280. ctypeconvnode.create_internal(tsetelementnode(right).left,sinttype),
  2281. cordconstnode.create(tsetdef(resultdef).setbase,sinttype,false));
  2282. { add a range or a single element? }
  2283. if assigned(tsetelementnode(right).right) then
  2284. begin
  2285. { adjust for set base }
  2286. tsetelementnode(right).right:=caddnode.create(subn,
  2287. ctypeconvnode.create_internal(tsetelementnode(right).right,sinttype),
  2288. cordconstnode.create(tsetdef(resultdef).setbase,sinttype,false));
  2289. addstatement(newstatement,ccallnode.createintern('fpc_varset_set_range',
  2290. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2291. ccallparanode.create(tsetelementnode(right).right,
  2292. ccallparanode.create(tsetelementnode(right).left,
  2293. ccallparanode.create(ctemprefnode.create(temp),
  2294. ccallparanode.create(left,nil))))))
  2295. );
  2296. end
  2297. else
  2298. addstatement(newstatement,ccallnode.createintern('fpc_varset_set',
  2299. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2300. ccallparanode.create(ctypeconvnode.create_internal(tsetelementnode(right).left,sinttype),
  2301. ccallparanode.create(ctemprefnode.create(temp),
  2302. ccallparanode.create(left,nil)))))
  2303. );
  2304. { remove reused parts from original node }
  2305. tsetelementnode(right).right:=nil;
  2306. tsetelementnode(right).left:=nil;
  2307. left:=nil;
  2308. { the last statement should return the value as
  2309. location and type, this is done be referencing the
  2310. temp and converting it first from a persistent temp to
  2311. normal temp }
  2312. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2313. addstatement(newstatement,ctemprefnode.create(temp));
  2314. end
  2315. else
  2316. call_varset_helper('fpc_varset_add_sets');
  2317. end
  2318. end;
  2319. subn:
  2320. call_varset_helper('fpc_varset_sub_sets');
  2321. symdifn:
  2322. call_varset_helper('fpc_varset_symdif_sets');
  2323. muln:
  2324. call_varset_helper('fpc_varset_mul_sets');
  2325. else
  2326. internalerror(200609241);
  2327. end;
  2328. end;
  2329. function taddnode.use_generic_mul32to64: boolean;
  2330. begin
  2331. result := true;
  2332. end;
  2333. function taddnode.try_make_mul32to64: boolean;
  2334. function canbe32bitint(v: tconstexprint): boolean;
  2335. begin
  2336. result := ((v >= int64(low(longint))) and (v <= int64(high(longint)))) or
  2337. ((v >= qword(low(cardinal))) and (v <= qword(high(cardinal))))
  2338. end;
  2339. var
  2340. temp: tnode;
  2341. begin
  2342. result := false;
  2343. if ((left.nodetype = typeconvn) and
  2344. is_integer(ttypeconvnode(left).left.resultdef) and
  2345. (not(torddef(ttypeconvnode(left).left.resultdef).ordtype in [u64bit,s64bit])) and
  2346. (((right.nodetype = ordconstn) and canbe32bitint(tordconstnode(right).value)) or
  2347. ((right.nodetype = typeconvn) and
  2348. is_integer(ttypeconvnode(right).left.resultdef) and
  2349. not(torddef(ttypeconvnode(right).left.resultdef).ordtype in [u64bit,s64bit])) and
  2350. ((is_signed(ttypeconvnode(left).left.resultdef) =
  2351. is_signed(ttypeconvnode(right).left.resultdef)) or
  2352. (is_signed(ttypeconvnode(left).left.resultdef) and
  2353. (torddef(ttypeconvnode(right).left.resultdef).ordtype in [u8bit,u16bit]))))) then
  2354. begin
  2355. temp := ttypeconvnode(left).left;
  2356. ttypeconvnode(left).left := nil;
  2357. left.free;
  2358. left := temp;
  2359. if (right.nodetype = typeconvn) then
  2360. begin
  2361. temp := ttypeconvnode(right).left;
  2362. ttypeconvnode(right).left := nil;
  2363. right.free;
  2364. right := temp;
  2365. end;
  2366. if (is_signed(left.resultdef)) then
  2367. begin
  2368. inserttypeconv(left,s32inttype);
  2369. inserttypeconv(right,s32inttype);
  2370. end
  2371. else
  2372. begin
  2373. inserttypeconv(left,u32inttype);
  2374. inserttypeconv(right,u32inttype);
  2375. end;
  2376. firstpass(left);
  2377. firstpass(right);
  2378. result := true;
  2379. end;
  2380. end;
  2381. function taddnode.first_add64bitint: tnode;
  2382. var
  2383. procname: string[31];
  2384. temp: tnode;
  2385. power: longint;
  2386. begin
  2387. result := nil;
  2388. { create helper calls mul }
  2389. if nodetype <> muln then
  2390. exit;
  2391. { make sure that if there is a constant, that it's on the right }
  2392. if left.nodetype = ordconstn then
  2393. begin
  2394. temp := right;
  2395. right := left;
  2396. left := temp;
  2397. end;
  2398. { can we use a shift instead of a mul? }
  2399. if not (cs_check_overflow in current_settings.localswitches) and
  2400. (right.nodetype = ordconstn) and
  2401. ispowerof2(tordconstnode(right).value,power) then
  2402. begin
  2403. tordconstnode(right).value := power;
  2404. result := cshlshrnode.create(shln,left,right);
  2405. { left and right are reused }
  2406. left := nil;
  2407. right := nil;
  2408. { return firstpassed new node }
  2409. exit;
  2410. end;
  2411. if not(use_generic_mul32to64) and
  2412. try_make_mul32to64 then
  2413. exit;
  2414. { when currency is used set the result of the
  2415. parameters to s64bit, so they are not converted }
  2416. if is_currency(resultdef) then
  2417. begin
  2418. left.resultdef:=s64inttype;
  2419. right.resultdef:=s64inttype;
  2420. end;
  2421. { otherwise, create the parameters for the helper }
  2422. right := ccallparanode.create(
  2423. cordconstnode.create(ord(cs_check_overflow in current_settings.localswitches),pasbool8type,true),
  2424. ccallparanode.create(right,ccallparanode.create(left,nil)));
  2425. left := nil;
  2426. { only qword needs the unsigned code, the
  2427. signed code is also used for currency }
  2428. if is_signed(resultdef) then
  2429. procname := 'fpc_mul_int64'
  2430. else
  2431. procname := 'fpc_mul_qword';
  2432. result := ccallnode.createintern(procname,right);
  2433. right := nil;
  2434. end;
  2435. function taddnode.first_addfloat : tnode;
  2436. var
  2437. procname: string[31];
  2438. { do we need to reverse the result ? }
  2439. notnode : boolean;
  2440. fdef : tdef;
  2441. begin
  2442. result := nil;
  2443. notnode := false;
  2444. { In non-emulation mode, real opcodes are
  2445. emitted for floating point values.
  2446. }
  2447. if not (cs_fp_emulation in current_settings.moduleswitches) then
  2448. exit;
  2449. if not(target_info.system in systems_wince) then
  2450. begin
  2451. case tfloatdef(left.resultdef).floattype of
  2452. s32real:
  2453. begin
  2454. fdef:=search_system_type('FLOAT32REC').typedef;
  2455. procname:='float32';
  2456. end;
  2457. s64real:
  2458. begin
  2459. fdef:=search_system_type('FLOAT64').typedef;
  2460. procname:='float64';
  2461. end;
  2462. {!!! not yet implemented
  2463. s128real:
  2464. }
  2465. else
  2466. internalerror(2005082601);
  2467. end;
  2468. case nodetype of
  2469. addn:
  2470. procname:=procname+'_add';
  2471. muln:
  2472. procname:=procname+'_mul';
  2473. subn:
  2474. procname:=procname+'_sub';
  2475. slashn:
  2476. procname:=procname+'_div';
  2477. ltn:
  2478. procname:=procname+'_lt';
  2479. lten:
  2480. procname:=procname+'_le';
  2481. gtn:
  2482. begin
  2483. procname:=procname+'_le';
  2484. notnode:=true;
  2485. end;
  2486. gten:
  2487. begin
  2488. procname:=procname+'_lt';
  2489. notnode:=true;
  2490. end;
  2491. equaln:
  2492. procname:=procname+'_eq';
  2493. unequaln:
  2494. begin
  2495. procname:=procname+'_eq';
  2496. notnode:=true;
  2497. end;
  2498. else
  2499. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),left.resultdef.typename,right.resultdef.typename);
  2500. end;
  2501. end
  2502. else
  2503. begin
  2504. case nodetype of
  2505. addn:
  2506. procname:='ADD';
  2507. muln:
  2508. procname:='MUL';
  2509. subn:
  2510. procname:='SUB';
  2511. slashn:
  2512. procname:='DIV';
  2513. ltn:
  2514. procname:='LT';
  2515. lten:
  2516. procname:='LE';
  2517. gtn:
  2518. procname:='GT';
  2519. gten:
  2520. procname:='GE';
  2521. equaln:
  2522. procname:='EQ';
  2523. unequaln:
  2524. procname:='NE';
  2525. else
  2526. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),left.resultdef.typename,right.resultdef.typename);
  2527. end;
  2528. case tfloatdef(left.resultdef).floattype of
  2529. s32real:
  2530. begin
  2531. procname:=procname+'S';
  2532. if nodetype in [addn,muln,subn,slashn] then
  2533. procname:=lower(procname);
  2534. end;
  2535. s64real:
  2536. procname:=procname+'D';
  2537. {!!! not yet implemented
  2538. s128real:
  2539. }
  2540. else
  2541. internalerror(2005082602);
  2542. end;
  2543. end;
  2544. { cast softfpu result? }
  2545. if not(target_info.system in systems_wince) then
  2546. begin
  2547. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  2548. resultdef:=pasbool8type;
  2549. result:=ctypeconvnode.create_internal(ccallnode.createintern(procname,ccallparanode.create(
  2550. ctypeconvnode.create_internal(right,fdef),
  2551. ccallparanode.create(
  2552. ctypeconvnode.create_internal(left,fdef),nil))),resultdef);
  2553. end
  2554. else
  2555. result:=ccallnode.createintern(procname,ccallparanode.create(right,
  2556. ccallparanode.create(left,nil)));
  2557. left:=nil;
  2558. right:=nil;
  2559. { do we need to reverse the result }
  2560. if notnode then
  2561. result:=cnotnode.create(result);
  2562. end;
  2563. function taddnode.pass_1 : tnode;
  2564. var
  2565. {$ifdef addstringopt}
  2566. hp : tnode;
  2567. {$endif addstringopt}
  2568. rd,ld : tdef;
  2569. i : longint;
  2570. lt,rt : tnodetype;
  2571. {$ifdef cpuneedsmulhelper}
  2572. procname : string[32];
  2573. {$endif cpuneedsmulhelper}
  2574. begin
  2575. result:=nil;
  2576. { Can we optimize multiple string additions into a single call?
  2577. This need to be done on a complete tree to detect the multiple
  2578. add nodes and is therefor done before the subtrees are processed }
  2579. if canbemultistringadd(self) then
  2580. begin
  2581. result := genmultistringadd(self);
  2582. exit;
  2583. end;
  2584. { first do the two subtrees }
  2585. firstpass(left);
  2586. firstpass(right);
  2587. if codegenerror then
  2588. exit;
  2589. { load easier access variables }
  2590. rd:=right.resultdef;
  2591. ld:=left.resultdef;
  2592. rt:=right.nodetype;
  2593. lt:=left.nodetype;
  2594. { int/int gives real/real! }
  2595. if nodetype=slashn then
  2596. begin
  2597. {$ifdef cpufpemu}
  2598. if (current_settings.fputype=fpu_soft) or (cs_fp_emulation in current_settings.moduleswitches) then
  2599. begin
  2600. result:=first_addfloat;
  2601. if assigned(result) then
  2602. exit;
  2603. end;
  2604. {$endif cpufpemu}
  2605. expectloc:=LOC_FPUREGISTER;
  2606. end
  2607. { if both are orddefs then check sub types }
  2608. else if (ld.typ=orddef) and (rd.typ=orddef) then
  2609. begin
  2610. { optimize multiplacation by a power of 2 }
  2611. if not(cs_check_overflow in current_settings.localswitches) and
  2612. (nodetype = muln) and
  2613. (((left.nodetype = ordconstn) and
  2614. ispowerof2(tordconstnode(left).value,i)) or
  2615. ((right.nodetype = ordconstn) and
  2616. ispowerof2(tordconstnode(right).value,i))) then
  2617. begin
  2618. if left.nodetype = ordconstn then
  2619. begin
  2620. tordconstnode(left).value := i;
  2621. result := cshlshrnode.create(shln,right,left);
  2622. end
  2623. else
  2624. begin
  2625. tordconstnode(right).value := i;
  2626. result := cshlshrnode.create(shln,left,right);
  2627. end;
  2628. left := nil;
  2629. right := nil;
  2630. exit;
  2631. end;
  2632. { 2 booleans ? }
  2633. if is_boolean(ld) and is_boolean(rd) then
  2634. begin
  2635. if (not(cs_full_boolean_eval in current_settings.localswitches) or
  2636. (nf_short_bool in flags)) and
  2637. (nodetype in [andn,orn]) then
  2638. expectloc:=LOC_JUMP
  2639. else
  2640. begin
  2641. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  2642. expectloc:=LOC_FLAGS
  2643. else
  2644. expectloc:=LOC_REGISTER;
  2645. end;
  2646. end
  2647. else
  2648. { Both are chars? only convert to shortstrings for addn }
  2649. if is_char(ld) then
  2650. begin
  2651. if nodetype=addn then
  2652. internalerror(200103291);
  2653. expectloc:=LOC_FLAGS;
  2654. end
  2655. {$ifndef cpu64bitaddr}
  2656. { is there a 64 bit type ? }
  2657. else if (torddef(ld).ordtype in [s64bit,u64bit,scurrency]) then
  2658. begin
  2659. result := first_add64bitint;
  2660. if assigned(result) then
  2661. exit;
  2662. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2663. expectloc:=LOC_REGISTER
  2664. else
  2665. expectloc:=LOC_JUMP;
  2666. end
  2667. {$endif cpu64bitaddr}
  2668. {$ifndef cpuneedsmulhelper}
  2669. { is there a cardinal? }
  2670. else if (torddef(ld).ordtype=u32bit) then
  2671. begin
  2672. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2673. expectloc:=LOC_REGISTER
  2674. else
  2675. expectloc:=LOC_FLAGS;
  2676. end
  2677. {$endif cpuneedsmulhelper}
  2678. { generic s32bit conversion }
  2679. else
  2680. begin
  2681. {$ifdef cpuneedsmulhelper}
  2682. if (nodetype=muln) and not(torddef(resultdef).ordtype in [u8bit,s8bit]) then
  2683. begin
  2684. result := nil;
  2685. case torddef(resultdef).ordtype of
  2686. s16bit:
  2687. procname := 'fpc_mul_integer';
  2688. u16bit:
  2689. procname := 'fpc_mul_word';
  2690. s32bit:
  2691. procname := 'fpc_mul_longint';
  2692. u32bit:
  2693. procname := 'fpc_mul_dword';
  2694. else
  2695. internalerror(2011022301);
  2696. end;
  2697. result := ccallnode.createintern(procname,
  2698. ccallparanode.create(cordconstnode.create(0,pasbool8type,false),
  2699. ccallparanode.create(right,
  2700. ccallparanode.create(left,nil))));
  2701. left := nil;
  2702. right := nil;
  2703. firstpass(result);
  2704. exit;
  2705. end;
  2706. {$endif cpuneedsmulhelper}
  2707. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2708. expectloc:=LOC_REGISTER
  2709. else
  2710. expectloc:=LOC_FLAGS;
  2711. end;
  2712. end
  2713. { left side a setdef, must be before string processing,
  2714. else array constructor can be seen as array of char (PFV) }
  2715. else if (ld.typ=setdef) then
  2716. begin
  2717. { small sets are handled inline by the compiler.
  2718. small set doesn't have support for adding ranges }
  2719. if is_smallset(ld) and
  2720. not(
  2721. (right.nodetype=setelementn) and
  2722. assigned(tsetelementnode(right).right)
  2723. ) then
  2724. begin
  2725. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  2726. expectloc:=LOC_FLAGS
  2727. else
  2728. expectloc:=LOC_REGISTER;
  2729. end
  2730. else
  2731. begin
  2732. result := first_addset;
  2733. if assigned(result) then
  2734. exit;
  2735. expectloc:=LOC_CREFERENCE;
  2736. end;
  2737. end
  2738. { compare pchar by addresses like BP/Delphi }
  2739. else if is_pchar(ld) then
  2740. begin
  2741. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2742. expectloc:=LOC_REGISTER
  2743. else
  2744. expectloc:=LOC_FLAGS;
  2745. end
  2746. { is one of the operands a string }
  2747. else if (ld.typ=stringdef) then
  2748. begin
  2749. if is_widestring(ld) then
  2750. begin
  2751. { this is only for add, the comparisaion is handled later }
  2752. expectloc:=LOC_REGISTER;
  2753. end
  2754. else if is_unicodestring(ld) then
  2755. begin
  2756. { this is only for add, the comparisaion is handled later }
  2757. expectloc:=LOC_REGISTER;
  2758. end
  2759. else if is_ansistring(ld) then
  2760. begin
  2761. { this is only for add, the comparisaion is handled later }
  2762. expectloc:=LOC_REGISTER;
  2763. end
  2764. else if is_longstring(ld) then
  2765. begin
  2766. { this is only for add, the comparisaion is handled later }
  2767. expectloc:=LOC_REFERENCE;
  2768. end
  2769. else
  2770. begin
  2771. {$ifdef addstringopt}
  2772. { can create a call which isn't handled by callparatemp }
  2773. if canbeaddsstringcharoptnode(self) then
  2774. begin
  2775. hp := genaddsstringcharoptnode(self);
  2776. pass_1 := hp;
  2777. exit;
  2778. end
  2779. else
  2780. {$endif addstringopt}
  2781. begin
  2782. { Fix right to be shortstring }
  2783. if is_char(right.resultdef) then
  2784. begin
  2785. inserttypeconv(right,cshortstringtype);
  2786. firstpass(right);
  2787. end;
  2788. end;
  2789. {$ifdef addstringopt}
  2790. { can create a call which isn't handled by callparatemp }
  2791. if canbeaddsstringcsstringoptnode(self) then
  2792. begin
  2793. hp := genaddsstringcsstringoptnode(self);
  2794. pass_1 := hp;
  2795. exit;
  2796. end;
  2797. {$endif addstringopt}
  2798. end;
  2799. { otherwise, let addstring convert everything }
  2800. result := first_addstring;
  2801. exit;
  2802. end
  2803. { is one a real float ? }
  2804. else if (rd.typ=floatdef) or (ld.typ=floatdef) then
  2805. begin
  2806. {$ifdef cpufpemu}
  2807. if (current_settings.fputype=fpu_soft) or (cs_fp_emulation in current_settings.moduleswitches) then
  2808. begin
  2809. result:=first_addfloat;
  2810. if assigned(result) then
  2811. exit;
  2812. end;
  2813. {$endif cpufpemu}
  2814. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2815. expectloc:=LOC_FPUREGISTER
  2816. else
  2817. expectloc:=LOC_FLAGS;
  2818. end
  2819. { pointer comperation and subtraction }
  2820. else if (ld.typ=pointerdef) then
  2821. begin
  2822. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2823. expectloc:=LOC_REGISTER
  2824. else
  2825. expectloc:=LOC_FLAGS;
  2826. end
  2827. else if is_implicit_pointer_object_type(ld) then
  2828. begin
  2829. expectloc:=LOC_FLAGS;
  2830. end
  2831. else if (ld.typ=classrefdef) then
  2832. begin
  2833. expectloc:=LOC_FLAGS;
  2834. end
  2835. { support procvar=nil,procvar<>nil }
  2836. else if ((ld.typ=procvardef) and (rt=niln)) or
  2837. ((rd.typ=procvardef) and (lt=niln)) then
  2838. begin
  2839. expectloc:=LOC_FLAGS;
  2840. end
  2841. {$ifdef SUPPORT_MMX}
  2842. { mmx support, this must be before the zero based array
  2843. check }
  2844. else if (cs_mmx in current_settings.localswitches) and is_mmx_able_array(ld) and
  2845. is_mmx_able_array(rd) then
  2846. begin
  2847. expectloc:=LOC_MMXREGISTER;
  2848. end
  2849. {$endif SUPPORT_MMX}
  2850. else if (rd.typ=pointerdef) or (ld.typ=pointerdef) then
  2851. begin
  2852. expectloc:=LOC_REGISTER;
  2853. end
  2854. else if (rd.typ=procvardef) and
  2855. (ld.typ=procvardef) and
  2856. equal_defs(rd,ld) then
  2857. begin
  2858. expectloc:=LOC_FLAGS;
  2859. end
  2860. else if (ld.typ=enumdef) then
  2861. begin
  2862. expectloc:=LOC_FLAGS;
  2863. end
  2864. {$ifdef SUPPORT_MMX}
  2865. else if (cs_mmx in current_settings.localswitches) and
  2866. is_mmx_able_array(ld) and
  2867. is_mmx_able_array(rd) then
  2868. begin
  2869. expectloc:=LOC_MMXREGISTER;
  2870. end
  2871. {$endif SUPPORT_MMX}
  2872. { the general solution is to convert to 32 bit int }
  2873. else
  2874. begin
  2875. expectloc:=LOC_REGISTER;
  2876. end;
  2877. end;
  2878. {$ifdef state_tracking}
  2879. function Taddnode.track_state_pass(exec_known:boolean):boolean;
  2880. var factval:Tnode;
  2881. begin
  2882. track_state_pass:=false;
  2883. if left.track_state_pass(exec_known) then
  2884. begin
  2885. track_state_pass:=true;
  2886. left.resultdef:=nil;
  2887. do_typecheckpass(left);
  2888. end;
  2889. factval:=aktstate.find_fact(left);
  2890. if factval<>nil then
  2891. begin
  2892. track_state_pass:=true;
  2893. left.destroy;
  2894. left:=factval.getcopy;
  2895. end;
  2896. if right.track_state_pass(exec_known) then
  2897. begin
  2898. track_state_pass:=true;
  2899. right.resultdef:=nil;
  2900. do_typecheckpass(right);
  2901. end;
  2902. factval:=aktstate.find_fact(right);
  2903. if factval<>nil then
  2904. begin
  2905. track_state_pass:=true;
  2906. right.destroy;
  2907. right:=factval.getcopy;
  2908. end;
  2909. end;
  2910. {$endif}
  2911. end.