nadd.pas 122 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070
  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? Make them equal to the largest boolean }
  1139. if (is_boolean(ld) and is_boolean(rd)) then
  1140. begin
  1141. if (torddef(left.resultdef).size>torddef(right.resultdef).size) or
  1142. (is_cbool(left.resultdef) and not is_cbool(right.resultdef)) then
  1143. begin
  1144. right:=ctypeconvnode.create_internal(right,left.resultdef);
  1145. ttypeconvnode(right).convtype:=tc_bool_2_bool;
  1146. typecheckpass(right);
  1147. end
  1148. else if (torddef(left.resultdef).size<torddef(right.resultdef).size) or
  1149. (not is_cbool(left.resultdef) and is_cbool(right.resultdef)) then
  1150. begin
  1151. left:=ctypeconvnode.create_internal(left,right.resultdef);
  1152. ttypeconvnode(left).convtype:=tc_bool_2_bool;
  1153. typecheckpass(left);
  1154. end;
  1155. case nodetype of
  1156. xorn,
  1157. andn,
  1158. orn:
  1159. begin
  1160. end;
  1161. ltn,
  1162. lten,
  1163. gtn,
  1164. gten:
  1165. begin
  1166. { convert both to pasbool to perform the comparison (so
  1167. that longbool(4) = longbool(2), since both represent
  1168. "true" }
  1169. inserttypeconv(left,pasbool8type);
  1170. inserttypeconv(right,pasbool8type);
  1171. end;
  1172. unequaln,
  1173. equaln:
  1174. begin
  1175. if not(cs_full_boolean_eval in current_settings.localswitches) or
  1176. (nf_short_bool in flags) then
  1177. begin
  1178. { Remove any compares with constants }
  1179. if (left.nodetype=ordconstn) then
  1180. begin
  1181. hp:=right;
  1182. b:=(tordconstnode(left).value<>0);
  1183. ot:=nodetype;
  1184. left.free;
  1185. left:=nil;
  1186. right:=nil;
  1187. if (not(b) and (ot=equaln)) or
  1188. (b and (ot=unequaln)) then
  1189. begin
  1190. hp:=cnotnode.create(hp);
  1191. end;
  1192. result:=hp;
  1193. exit;
  1194. end;
  1195. if (right.nodetype=ordconstn) then
  1196. begin
  1197. hp:=left;
  1198. b:=(tordconstnode(right).value<>0);
  1199. ot:=nodetype;
  1200. right.free;
  1201. right:=nil;
  1202. left:=nil;
  1203. if (not(b) and (ot=equaln)) or
  1204. (b and (ot=unequaln)) then
  1205. begin
  1206. hp:=cnotnode.create(hp);
  1207. end;
  1208. result:=hp;
  1209. exit;
  1210. end;
  1211. end;
  1212. { Delphi-compatibility: convert both to pasbool to
  1213. perform the equality comparison }
  1214. inserttypeconv(left,pasbool8type);
  1215. inserttypeconv(right,pasbool8type);
  1216. end;
  1217. else
  1218. begin
  1219. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1220. result:=cnothingnode.create;
  1221. exit;
  1222. end;
  1223. end;
  1224. end
  1225. { Both are chars? }
  1226. else if is_char(rd) and is_char(ld) then
  1227. begin
  1228. if nodetype=addn then
  1229. begin
  1230. resultdef:=cshortstringtype;
  1231. if not(is_constcharnode(left) and is_constcharnode(right)) then
  1232. begin
  1233. inserttypeconv(left,cshortstringtype);
  1234. {$ifdef addstringopt}
  1235. hp := genaddsstringcharoptnode(self);
  1236. result := hp;
  1237. exit;
  1238. {$endif addstringopt}
  1239. end
  1240. end
  1241. else if not(nodetype in [ltn,lten,gtn,gten,unequaln,equaln]) then
  1242. begin
  1243. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1244. result:=cnothingnode.create;
  1245. exit;
  1246. end;
  1247. end
  1248. { There is a widechar? }
  1249. else if is_widechar(rd) or is_widechar(ld) then
  1250. begin
  1251. { widechar+widechar gives widestring }
  1252. if nodetype=addn then
  1253. begin
  1254. inserttypeconv(left,cwidestringtype);
  1255. if (torddef(rd).ordtype<>uwidechar) then
  1256. inserttypeconv(right,cwidechartype);
  1257. resultdef:=cwidestringtype;
  1258. end
  1259. else
  1260. begin
  1261. if (torddef(ld).ordtype<>uwidechar) then
  1262. inserttypeconv(left,cwidechartype);
  1263. if (torddef(rd).ordtype<>uwidechar) then
  1264. inserttypeconv(right,cwidechartype);
  1265. end;
  1266. end
  1267. { is there a currency type ? }
  1268. else if ((torddef(rd).ordtype=scurrency) or (torddef(ld).ordtype=scurrency)) then
  1269. begin
  1270. if (torddef(ld).ordtype<>scurrency) then
  1271. inserttypeconv(left,s64currencytype);
  1272. if (torddef(rd).ordtype<>scurrency) then
  1273. inserttypeconv(right,s64currencytype);
  1274. end
  1275. { "and" does't care about the sign of integers }
  1276. { "xor", "or" and compares don't need extension to native int }
  1277. { size either as long as both values are signed or unsigned }
  1278. { "xor" and "or" also don't care about the sign if the values }
  1279. { occupy an entire register }
  1280. { don't do it if either type is 64 bit, since in that case we }
  1281. { can't safely find a "common" type }
  1282. else if is_integer(ld) and is_integer(rd) and
  1283. not is_64bitint(ld) and not is_64bitint(rd) and
  1284. ((nodetype=andn) or
  1285. ((nodetype in [orn,xorn,equaln,unequaln,gtn,gten,ltn,lten]) and
  1286. not(is_signed(ld) xor is_signed(rd)))) then
  1287. begin
  1288. if (rd.size>ld.size) or
  1289. { Delphi-compatible: prefer unsigned type for "and" with equal size }
  1290. ((rd.size=ld.size) and
  1291. not is_signed(rd)) then
  1292. begin
  1293. if (rd.size=ld.size) and
  1294. is_signed(ld) then
  1295. inserttypeconv_internal(left,rd)
  1296. else
  1297. begin
  1298. { not to left right.resultdef, because that may
  1299. cause a range error if left and right's def don't
  1300. completely overlap }
  1301. nd:=get_common_intdef(torddef(ld),torddef(rd),true);
  1302. inserttypeconv(left,nd);
  1303. inserttypeconv(right,nd);
  1304. end;
  1305. end
  1306. else
  1307. begin
  1308. if (rd.size=ld.size) and
  1309. is_signed(rd) then
  1310. inserttypeconv_internal(right,ld)
  1311. else
  1312. begin
  1313. nd:=get_common_intdef(torddef(ld),torddef(rd),true);
  1314. inserttypeconv(left,nd);
  1315. inserttypeconv(right,nd);
  1316. end;
  1317. end
  1318. end
  1319. { is there a signed 64 bit type ? }
  1320. else if ((torddef(rd).ordtype=s64bit) or (torddef(ld).ordtype=s64bit)) then
  1321. begin
  1322. if (torddef(ld).ordtype<>s64bit) then
  1323. inserttypeconv(left,s64inttype);
  1324. if (torddef(rd).ordtype<>s64bit) then
  1325. inserttypeconv(right,s64inttype);
  1326. end
  1327. { is there a unsigned 64 bit type ? }
  1328. else if ((torddef(rd).ordtype=u64bit) or (torddef(ld).ordtype=u64bit)) then
  1329. begin
  1330. if (torddef(ld).ordtype<>u64bit) then
  1331. inserttypeconv(left,u64inttype);
  1332. if (torddef(rd).ordtype<>u64bit) then
  1333. inserttypeconv(right,u64inttype);
  1334. end
  1335. { 64 bit cpus do calculations always in 64 bit }
  1336. {$ifndef cpu64bitaddr}
  1337. { is there a cardinal? }
  1338. else if ((torddef(rd).ordtype=u32bit) or (torddef(ld).ordtype=u32bit)) then
  1339. begin
  1340. { convert positive constants to u32bit }
  1341. if (torddef(ld).ordtype<>u32bit) and
  1342. is_constintnode(left) and
  1343. (tordconstnode(left).value >= 0) then
  1344. inserttypeconv(left,u32inttype);
  1345. if (torddef(rd).ordtype<>u32bit) and
  1346. is_constintnode(right) and
  1347. (tordconstnode(right).value >= 0) then
  1348. inserttypeconv(right,u32inttype);
  1349. { when one of the operand is signed or the operation is subn then perform
  1350. the operation in 64bit, can't use rd/ld here because there
  1351. could be already typeconvs inserted.
  1352. This is compatible with the code below for other unsigned types (PFV) }
  1353. if is_signed(left.resultdef) or
  1354. is_signed(right.resultdef) or
  1355. (nodetype=subn) then
  1356. begin
  1357. if nodetype<>subn then
  1358. CGMessage(type_h_mixed_signed_unsigned);
  1359. { mark as internal in case added for a subn, so }
  1360. { ttypeconvnode.simplify can remove the 64 bit }
  1361. { typecast again if semantically correct. Even }
  1362. { if we could detect that here already, we }
  1363. { mustn't do it here because that would change }
  1364. { overload choosing behaviour etc. The code in }
  1365. { ncnv.pas is run after that is already decided }
  1366. if (not is_signed(left.resultdef) and
  1367. not is_signed(right.resultdef)) or
  1368. (nodetype in [orn,xorn]) then
  1369. include(flags,nf_internal);
  1370. inserttypeconv(left,s64inttype);
  1371. inserttypeconv(right,s64inttype);
  1372. end
  1373. else
  1374. begin
  1375. if (torddef(left.resultdef).ordtype<>u32bit) then
  1376. inserttypeconv(left,u32inttype);
  1377. if (torddef(right.resultdef).ordtype<>u32bit) then
  1378. inserttypeconv(right,u32inttype);
  1379. end;
  1380. end
  1381. {$endif cpu64bitaddr}
  1382. { generic ord conversion is sinttype }
  1383. else
  1384. begin
  1385. { When there is a signed type or there is a minus operation
  1386. we convert to signed int. Otherwise (both are unsigned) we keep
  1387. the result also unsigned. This is compatible with Delphi (PFV) }
  1388. if is_signed(ld) or
  1389. is_signed(rd) or
  1390. (nodetype=subn) then
  1391. begin
  1392. {$ifdef cpunodefaultint}
  1393. { for small cpus we use the smallest common type }
  1394. nd:=get_common_intdef(torddef(ld),torddef(rd),false);
  1395. inserttypeconv(right,nd);
  1396. inserttypeconv(left,nd);
  1397. {$else cpunodefaultint}
  1398. inserttypeconv(right,sinttype);
  1399. inserttypeconv(left,sinttype);
  1400. {$endif cpunodefaultint}
  1401. end
  1402. else
  1403. begin
  1404. inserttypeconv(right,uinttype);
  1405. inserttypeconv(left,uinttype);
  1406. end;
  1407. end;
  1408. end
  1409. { if both are floatdefs, conversion is already done before constant folding }
  1410. else if (ld.typ=floatdef) then
  1411. begin
  1412. if not(nodetype in [addn,subn,muln,slashn,equaln,unequaln,ltn,lten,gtn,gten]) then
  1413. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1414. end
  1415. { left side a setdef, must be before string processing,
  1416. else array constructor can be seen as array of char (PFV) }
  1417. else if (ld.typ=setdef) then
  1418. begin
  1419. if not(nodetype in [addn,subn,symdifn,muln,equaln,unequaln,lten,gten]) then
  1420. CGMessage(type_e_set_operation_unknown);
  1421. { right must either be a set or a set element }
  1422. if (rd.typ<>setdef) and
  1423. (rt<>setelementn) then
  1424. CGMessage(type_e_mismatch)
  1425. { Make operands the same setdef. If one's elementtype fits }
  1426. { entirely inside the other's, pick the one with the largest }
  1427. { range. Otherwise create a new setdef with a range which }
  1428. { can contain both. }
  1429. else if not(equal_defs(ld,rd)) then
  1430. begin
  1431. { note: ld cannot be an empty set with elementdef=nil in }
  1432. { case right is not a set, arrayconstructor_to_set takes }
  1433. { care of that }
  1434. { 1: rd is a set with an assigned elementdef, and ld is }
  1435. { either an empty set without elementdef or a set whose }
  1436. { elementdef fits in rd's elementdef -> convert to rd }
  1437. if ((rd.typ=setdef) and
  1438. assigned(tsetdef(rd).elementdef) and
  1439. (not assigned(tsetdef(ld).elementdef) or
  1440. is_in_limit(ld,rd))) then
  1441. inserttypeconv(left,rd)
  1442. { 2: rd is either an empty set without elementdef or a set }
  1443. { whose elementdef fits in ld's elementdef, or a set }
  1444. { element whose def fits in ld's elementdef -> convert }
  1445. { to ld. ld's elementdef can't be nil here, is caught }
  1446. { previous case and "note:" above }
  1447. else if ((rd.typ=setdef) and
  1448. (not assigned(tsetdef(rd).elementdef) or
  1449. is_in_limit(rd,ld))) or
  1450. ((rd.typ<>setdef) and
  1451. is_in_limit(rd,tsetdef(ld).elementdef)) then
  1452. if (rd.typ=setdef) then
  1453. inserttypeconv(right,ld)
  1454. else
  1455. inserttypeconv(right,tsetdef(ld).elementdef)
  1456. { 3: otherwise create setdef which encompasses both, taking }
  1457. { into account empty sets without elementdef }
  1458. else
  1459. begin
  1460. if assigned(tsetdef(ld).elementdef) then
  1461. begin
  1462. llow:=tsetdef(ld).setbase;
  1463. lhigh:=tsetdef(ld).setmax;
  1464. end;
  1465. if (rd.typ=setdef) then
  1466. if assigned(tsetdef(rd).elementdef) then
  1467. begin
  1468. rlow:=tsetdef(rd).setbase;
  1469. rhigh:=tsetdef(rd).setmax;
  1470. end
  1471. else
  1472. begin
  1473. { ld's elementdef must have been valid }
  1474. rlow:=llow;
  1475. rhigh:=lhigh;
  1476. end
  1477. else
  1478. getrange(rd,rlow,rhigh);
  1479. if not assigned(tsetdef(ld).elementdef) then
  1480. begin
  1481. llow:=rlow;
  1482. lhigh:=rhigh;
  1483. end;
  1484. nd:=tsetdef.create(tsetdef(ld).elementdef,min(llow,rlow),max(lhigh,rhigh));
  1485. inserttypeconv(left,nd);
  1486. if (rd.typ=setdef) then
  1487. inserttypeconv(right,nd)
  1488. else
  1489. inserttypeconv(right,tsetdef(nd).elementdef);
  1490. end;
  1491. end;
  1492. end
  1493. { pointer comparision and subtraction }
  1494. else if (
  1495. (rd.typ=pointerdef) and (ld.typ=pointerdef)
  1496. ) or
  1497. { compare/add pchar to variable (not stringconst) char arrays
  1498. by addresses like BP/Delphi }
  1499. (
  1500. (nodetype in [equaln,unequaln,subn,addn]) and
  1501. (
  1502. ((is_pchar(ld) or (lt=niln)) and is_chararray(rd) and (rt<>stringconstn)) or
  1503. ((is_pchar(rd) or (rt=niln)) and is_chararray(ld) and (lt<>stringconstn))
  1504. )
  1505. ) then
  1506. begin
  1507. { convert char array to pointer }
  1508. if is_chararray(rd) then
  1509. begin
  1510. inserttypeconv(right,charpointertype);
  1511. rd:=right.resultdef;
  1512. end
  1513. else if is_chararray(ld) then
  1514. begin
  1515. inserttypeconv(left,charpointertype);
  1516. ld:=left.resultdef;
  1517. end;
  1518. case nodetype of
  1519. equaln,unequaln :
  1520. begin
  1521. if is_voidpointer(right.resultdef) then
  1522. inserttypeconv(right,left.resultdef)
  1523. else if is_voidpointer(left.resultdef) then
  1524. inserttypeconv(left,right.resultdef)
  1525. else if not(equal_defs(ld,rd)) then
  1526. IncompatibleTypes(ld,rd);
  1527. { now that the type checking is done, convert both to charpointer, }
  1528. { because methodpointers are 8 bytes even though only the first 4 }
  1529. { bytes must be compared. This can happen here if we are in }
  1530. { TP/Delphi mode, because there @methodpointer = voidpointer (but }
  1531. { a voidpointer of 8 bytes). A conversion to voidpointer would be }
  1532. { optimized away, since the result already was a voidpointer, so }
  1533. { use a charpointer instead (JM) }
  1534. inserttypeconv_internal(left,charpointertype);
  1535. inserttypeconv_internal(right,charpointertype);
  1536. end;
  1537. ltn,lten,gtn,gten:
  1538. begin
  1539. if (cs_extsyntax in current_settings.moduleswitches) then
  1540. begin
  1541. if is_voidpointer(right.resultdef) then
  1542. inserttypeconv(right,left.resultdef)
  1543. else if is_voidpointer(left.resultdef) then
  1544. inserttypeconv(left,right.resultdef)
  1545. else if not(equal_defs(ld,rd)) then
  1546. IncompatibleTypes(ld,rd);
  1547. end
  1548. else
  1549. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1550. end;
  1551. subn:
  1552. begin
  1553. if (cs_extsyntax in current_settings.moduleswitches) then
  1554. begin
  1555. if is_voidpointer(right.resultdef) then
  1556. begin
  1557. if is_big_untyped_addrnode(right) then
  1558. CGMessage1(type_w_untyped_arithmetic_unportable,node2opstr(nodetype));
  1559. inserttypeconv(right,left.resultdef)
  1560. end
  1561. else if is_voidpointer(left.resultdef) then
  1562. inserttypeconv(left,right.resultdef)
  1563. else if not(equal_defs(ld,rd)) then
  1564. IncompatibleTypes(ld,rd);
  1565. end
  1566. else
  1567. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1568. if not(nf_has_pointerdiv in flags) and
  1569. (tpointerdef(rd).pointeddef.size>1) then
  1570. begin
  1571. hp:=getcopy;
  1572. include(hp.flags,nf_has_pointerdiv);
  1573. result:=cmoddivnode.create(divn,hp,cordconstnode.create(tpointerdef(rd).pointeddef.size,sinttype,false));
  1574. end;
  1575. resultdef:=sinttype;
  1576. exit;
  1577. end;
  1578. else
  1579. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1580. end;
  1581. end
  1582. { is one of the operands a string?,
  1583. chararrays are also handled as strings (after conversion), also take
  1584. care of chararray+chararray and chararray+char.
  1585. Note: Must be done after pointerdef+pointerdef has been checked, else
  1586. pchar is converted to string }
  1587. else if (rd.typ=stringdef) or
  1588. (ld.typ=stringdef) or
  1589. { stringconstn's can be arraydefs }
  1590. (lt=stringconstn) or
  1591. (rt=stringconstn) or
  1592. ((is_pchar(rd) or is_chararray(rd) or is_char(rd) or is_open_chararray(rd) or
  1593. is_pwidechar(rd) or is_widechararray(rd) or is_widechar(rd) or is_open_widechararray(rd)) and
  1594. (is_pchar(ld) or is_chararray(ld) or is_char(ld) or is_open_chararray(ld) or
  1595. is_pwidechar(ld) or is_widechararray(ld) or is_widechar(ld) or is_open_widechararray(ld))) then
  1596. begin
  1597. if (nodetype in [addn,equaln,unequaln,lten,gten,ltn,gtn]) then
  1598. begin
  1599. { Is there a unicodestring? }
  1600. if is_unicodestring(rd) or is_unicodestring(ld) then
  1601. strtype:=st_unicodestring
  1602. else
  1603. { Is there a widestring? }
  1604. if is_widestring(rd) or is_widestring(ld) or
  1605. is_pwidechar(rd) or is_widechararray(rd) or is_widechar(rd) or is_open_widechararray(rd) or
  1606. is_pwidechar(ld) or is_widechararray(ld) or is_widechar(ld) or is_open_widechararray(ld) then
  1607. strtype:=st_widestring
  1608. else
  1609. if is_ansistring(rd) or is_ansistring(ld) or
  1610. ((cs_ansistrings in current_settings.localswitches) and
  1611. //todo: Move some of this to longstring's then they are implemented?
  1612. (
  1613. is_pchar(rd) or (is_chararray(rd) and (rd.size > 255)) or is_open_chararray(rd) or (lt = stringconstn) or
  1614. is_pchar(ld) or (is_chararray(ld) and (ld.size > 255)) or is_open_chararray(ld) or (rt = stringconstn)
  1615. )
  1616. ) then
  1617. strtype:=st_ansistring
  1618. else
  1619. if is_longstring(rd) or is_longstring(ld) then
  1620. strtype:=st_longstring
  1621. else
  1622. begin
  1623. { TODO: todo: add a warning/hint here if one converting a too large array}
  1624. { nodes is PChar, array [with size > 255] or OpenArrayOfChar.
  1625. Note: Delphi halts with error if "array [0..xx] of char"
  1626. is assigned to ShortString and string length is less
  1627. then array size }
  1628. strtype:= st_shortstring;
  1629. end;
  1630. // Now convert nodes to common string type
  1631. case strtype of
  1632. st_widestring :
  1633. begin
  1634. if not(is_widestring(rd)) then
  1635. inserttypeconv(right,cwidestringtype);
  1636. if not(is_widestring(ld)) then
  1637. inserttypeconv(left,cwidestringtype);
  1638. end;
  1639. st_unicodestring :
  1640. begin
  1641. if not(is_unicodestring(rd)) then
  1642. inserttypeconv(right,cunicodestringtype);
  1643. if not(is_unicodestring(ld)) then
  1644. inserttypeconv(left,cunicodestringtype);
  1645. end;
  1646. st_ansistring :
  1647. begin
  1648. { use same code page if possible (don't force same code
  1649. page in case both are ansistrings with code page <>
  1650. CP_NONE, since then data loss can occur (the ansistring
  1651. helpers will convert them at run time to an encoding
  1652. that can represent both encodings) }
  1653. if is_ansistring(ld) and
  1654. (tstringdef(ld).encoding<>0) and
  1655. (tstringdef(ld).encoding<>globals.CP_NONE) and
  1656. (not is_ansistring(rd) or
  1657. (tstringdef(rd).encoding=0) or
  1658. (tstringdef(rd).encoding=globals.CP_NONE)) then
  1659. inserttypeconv(right,ld)
  1660. else if is_ansistring(rd) and
  1661. (tstringdef(rd).encoding<>0) and
  1662. (tstringdef(rd).encoding<>globals.CP_NONE) and
  1663. (not is_ansistring(ld) or
  1664. (tstringdef(ld).encoding=0) or
  1665. (tstringdef(ld).encoding=globals.CP_NONE)) then
  1666. inserttypeconv(left,rd)
  1667. else
  1668. begin
  1669. if not is_ansistring(ld) then
  1670. inserttypeconv(left,getansistringdef);
  1671. if not is_ansistring(rd) then
  1672. inserttypeconv(right,getansistringdef);
  1673. end;
  1674. end;
  1675. st_longstring :
  1676. begin
  1677. if not(is_longstring(rd)) then
  1678. inserttypeconv(right,clongstringtype);
  1679. if not(is_longstring(ld)) then
  1680. inserttypeconv(left,clongstringtype);
  1681. end;
  1682. st_shortstring :
  1683. begin
  1684. if not(is_shortstring(ld)) then
  1685. inserttypeconv(left,cshortstringtype);
  1686. { don't convert char, that can be handled by the optimized node }
  1687. if not(is_shortstring(rd) or is_char(rd)) then
  1688. inserttypeconv(right,cshortstringtype);
  1689. end;
  1690. else
  1691. internalerror(2005101);
  1692. end;
  1693. end
  1694. else
  1695. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1696. end
  1697. { implicit pointer object type comparison }
  1698. else if is_implicit_pointer_object_type(rd) or is_implicit_pointer_object_type(ld) then
  1699. begin
  1700. if (nodetype in [equaln,unequaln]) then
  1701. begin
  1702. if is_implicit_pointer_object_type(rd) and is_implicit_pointer_object_type(ld) then
  1703. begin
  1704. if tobjectdef(rd).is_related(tobjectdef(ld)) then
  1705. inserttypeconv(right,left.resultdef)
  1706. else
  1707. inserttypeconv(left,right.resultdef);
  1708. end
  1709. else if is_implicit_pointer_object_type(rd) then
  1710. inserttypeconv(left,right.resultdef)
  1711. else
  1712. inserttypeconv(right,left.resultdef);
  1713. end
  1714. else
  1715. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1716. end
  1717. else if (rd.typ=classrefdef) and (ld.typ=classrefdef) then
  1718. begin
  1719. if (nodetype in [equaln,unequaln]) then
  1720. begin
  1721. if tobjectdef(tclassrefdef(rd).pointeddef).is_related(
  1722. tobjectdef(tclassrefdef(ld).pointeddef)) then
  1723. inserttypeconv(right,left.resultdef)
  1724. else
  1725. inserttypeconv(left,right.resultdef);
  1726. end
  1727. else
  1728. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1729. end
  1730. { allow comparison with nil pointer }
  1731. else if is_implicit_pointer_object_type(rd) or (rd.typ=classrefdef) then
  1732. begin
  1733. if (nodetype in [equaln,unequaln]) then
  1734. inserttypeconv(left,right.resultdef)
  1735. else
  1736. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1737. end
  1738. else if is_implicit_pointer_object_type(ld) or (ld.typ=classrefdef) then
  1739. begin
  1740. if (nodetype in [equaln,unequaln]) then
  1741. inserttypeconv(right,left.resultdef)
  1742. else
  1743. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1744. end
  1745. { support procvar=nil,procvar<>nil }
  1746. else if ((ld.typ=procvardef) and (rt=niln)) or
  1747. ((rd.typ=procvardef) and (lt=niln)) then
  1748. begin
  1749. if not(nodetype in [equaln,unequaln]) then
  1750. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1751. { find proc field in methodpointer record }
  1752. hsym:=tfieldvarsym(trecorddef(methodpointertype).symtable.Find('proc'));
  1753. if not assigned(hsym) then
  1754. internalerror(200412043);
  1755. { For methodpointers compare only tmethodpointer.proc }
  1756. if (rd.typ=procvardef) and
  1757. (not tprocvardef(rd).is_addressonly) then
  1758. begin
  1759. right:=csubscriptnode.create(
  1760. hsym,
  1761. ctypeconvnode.create_internal(right,methodpointertype));
  1762. typecheckpass(right);
  1763. end;
  1764. if (ld.typ=procvardef) and
  1765. (not tprocvardef(ld).is_addressonly) then
  1766. begin
  1767. left:=csubscriptnode.create(
  1768. hsym,
  1769. ctypeconvnode.create_internal(left,methodpointertype));
  1770. typecheckpass(left);
  1771. end;
  1772. end
  1773. { support dynamicarray=nil,dynamicarray<>nil }
  1774. else if (is_dynamic_array(ld) and (rt=niln)) or
  1775. (is_dynamic_array(rd) and (lt=niln)) or
  1776. (is_dynamic_array(ld) and is_dynamic_array(rd)) then
  1777. begin
  1778. if not(nodetype in [equaln,unequaln]) then
  1779. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1780. end
  1781. {$ifdef SUPPORT_MMX}
  1782. { mmx support, this must be before the zero based array
  1783. check }
  1784. else if (cs_mmx in current_settings.localswitches) and
  1785. is_mmx_able_array(ld) and
  1786. is_mmx_able_array(rd) and
  1787. equal_defs(ld,rd) then
  1788. begin
  1789. case nodetype of
  1790. addn,subn,xorn,orn,andn:
  1791. ;
  1792. { mul is a little bit restricted }
  1793. muln:
  1794. if not(mmx_type(ld) in [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1795. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1796. else
  1797. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1798. end;
  1799. end
  1800. {$endif SUPPORT_MMX}
  1801. { vector support, this must be before the zero based array
  1802. check }
  1803. else if (cs_support_vectors in current_settings.globalswitches) and
  1804. is_vector(ld) and
  1805. is_vector(rd) and
  1806. equal_defs(ld,rd) then
  1807. begin
  1808. if not(nodetype in [addn,subn,xorn,orn,andn,muln,slashn]) then
  1809. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1810. { both defs must be equal, so taking left or right as resultdef doesn't matter }
  1811. resultdef:=left.resultdef;
  1812. end
  1813. { this is a little bit dangerous, also the left type }
  1814. { pointer to should be checked! This broke the mmx support }
  1815. else if (rd.typ=pointerdef) or
  1816. (is_zero_based_array(rd) and (rt<>stringconstn)) then
  1817. begin
  1818. if is_zero_based_array(rd) then
  1819. begin
  1820. resultdef:=tpointerdef.create(tarraydef(rd).elementdef);
  1821. inserttypeconv(right,resultdef);
  1822. end
  1823. else
  1824. resultdef:=right.resultdef;
  1825. inserttypeconv(left,sinttype);
  1826. if nodetype=addn then
  1827. begin
  1828. if not(cs_extsyntax in current_settings.moduleswitches) or
  1829. (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
  1830. not(cs_pointermath in current_settings.localswitches) and
  1831. not((ld.typ=pointerdef) and tpointerdef(ld).has_pointer_math)) then
  1832. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1833. if (rd.typ=pointerdef) and
  1834. (tpointerdef(rd).pointeddef.size>1) then
  1835. begin
  1836. left:=caddnode.create(muln,left,
  1837. cordconstnode.create(tpointerdef(rd).pointeddef.size,sinttype,true));
  1838. typecheckpass(left);
  1839. end;
  1840. end
  1841. else
  1842. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1843. end
  1844. else if (ld.typ=pointerdef) or
  1845. (is_zero_based_array(ld) and (lt<>stringconstn)) then
  1846. begin
  1847. if is_zero_based_array(ld) then
  1848. begin
  1849. resultdef:=tpointerdef.create(tarraydef(ld).elementdef);
  1850. inserttypeconv(left,resultdef);
  1851. end
  1852. else
  1853. resultdef:=left.resultdef;
  1854. inserttypeconv(right,sinttype);
  1855. if nodetype in [addn,subn] then
  1856. begin
  1857. if (lt=niln) then
  1858. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),'NIL',rd.typename);
  1859. if not(cs_extsyntax in current_settings.moduleswitches) or
  1860. (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
  1861. not(cs_pointermath in current_settings.localswitches) and
  1862. not((ld.typ=pointerdef) and tpointerdef(ld).has_pointer_math)) then
  1863. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1864. if (ld.typ=pointerdef) then
  1865. begin
  1866. if is_big_untyped_addrnode(left) then
  1867. CGMessage1(type_w_untyped_arithmetic_unportable,node2opstr(nodetype));
  1868. if (tpointerdef(ld).pointeddef.size>1) then
  1869. begin
  1870. right:=caddnode.create(muln,right,
  1871. cordconstnode.create(tpointerdef(ld).pointeddef.size,sinttype,true));
  1872. typecheckpass(right);
  1873. end
  1874. end else
  1875. if is_zero_based_array(ld) and
  1876. (tarraydef(ld).elementdef.size>1) then
  1877. begin
  1878. right:=caddnode.create(muln,right,
  1879. cordconstnode.create(tarraydef(ld).elementdef.size,sinttype,true));
  1880. typecheckpass(right);
  1881. end;
  1882. end
  1883. else
  1884. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1885. end
  1886. else if (rd.typ=procvardef) and
  1887. (ld.typ=procvardef) and
  1888. equal_defs(rd,ld) then
  1889. begin
  1890. if (nodetype in [equaln,unequaln]) then
  1891. begin
  1892. if tprocvardef(rd).is_addressonly then
  1893. begin
  1894. inserttypeconv_internal(right,voidpointertype);
  1895. inserttypeconv_internal(left,voidpointertype);
  1896. end
  1897. else
  1898. begin
  1899. { find proc field in methodpointer record }
  1900. hsym:=tfieldvarsym(trecorddef(methodpointertype).symtable.Find('proc'));
  1901. if not assigned(hsym) then
  1902. internalerror(200412043);
  1903. { Compare tmehodpointer(left).proc }
  1904. right:=csubscriptnode.create(
  1905. hsym,
  1906. ctypeconvnode.create_internal(right,methodpointertype));
  1907. typecheckpass(right);
  1908. left:=csubscriptnode.create(
  1909. hsym,
  1910. ctypeconvnode.create_internal(left,methodpointertype));
  1911. typecheckpass(left);
  1912. end;
  1913. end
  1914. else
  1915. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1916. end
  1917. { enums }
  1918. else if (ld.typ=enumdef) and (rd.typ=enumdef) then
  1919. begin
  1920. if allowenumop(nodetype) then
  1921. inserttypeconv(right,left.resultdef)
  1922. else
  1923. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);
  1924. end
  1925. { generic conversion, this is for error recovery }
  1926. else
  1927. begin
  1928. inserttypeconv(left,sinttype);
  1929. inserttypeconv(right,sinttype);
  1930. end;
  1931. if cmp_of_disjunct_ranges(res) then
  1932. begin
  1933. if res then
  1934. CGMessage(type_w_comparison_always_true)
  1935. else
  1936. CGMessage(type_w_comparison_always_false);
  1937. end;
  1938. { set resultdef if not already done }
  1939. if not assigned(resultdef) then
  1940. begin
  1941. case nodetype of
  1942. ltn,lten,gtn,gten,equaln,unequaln :
  1943. resultdef:=pasbool8type;
  1944. slashn :
  1945. resultdef:=resultrealdef;
  1946. addn:
  1947. begin
  1948. { for strings, return is always a 255 char string }
  1949. if is_shortstring(left.resultdef) then
  1950. resultdef:=cshortstringtype
  1951. else
  1952. { for ansistrings set resultdef to assignment left node
  1953. if it is an assignment and left node expects ansistring }
  1954. if is_ansistring(left.resultdef) and
  1955. assigned(aktassignmentnode) and
  1956. (aktassignmentnode.right=self) and
  1957. is_ansistring(aktassignmentnode.left.resultdef) then
  1958. resultdef:=aktassignmentnode.left.resultdef
  1959. else
  1960. resultdef:=left.resultdef;
  1961. end;
  1962. else
  1963. resultdef:=left.resultdef;
  1964. end;
  1965. end;
  1966. { when the result is currency we need some extra code for
  1967. multiplication and division. this should not be done when
  1968. the muln or slashn node is created internally }
  1969. if not(nf_is_currency in flags) and
  1970. is_currency(resultdef) then
  1971. begin
  1972. case nodetype of
  1973. slashn :
  1974. begin
  1975. { slashn will only work with floats }
  1976. hp:=caddnode.create(muln,getcopy,crealconstnode.create(10000.0,s64currencytype));
  1977. include(hp.flags,nf_is_currency);
  1978. result:=hp;
  1979. end;
  1980. muln :
  1981. begin
  1982. if s64currencytype.typ=floatdef then
  1983. hp:=caddnode.create(slashn,getcopy,crealconstnode.create(10000.0,s64currencytype))
  1984. else
  1985. hp:=cmoddivnode.create(divn,getcopy,cordconstnode.create(10000,s64currencytype,false));
  1986. include(hp.flags,nf_is_currency);
  1987. result:=hp
  1988. end;
  1989. end;
  1990. end;
  1991. if not codegenerror and
  1992. not assigned(result) then
  1993. result:=simplify(false);
  1994. end;
  1995. function taddnode.first_addstring: tnode;
  1996. const
  1997. swap_relation: array [ltn..unequaln] of Tnodetype=(gtn, gten, ltn, lten, equaln, unequaln);
  1998. var
  1999. p: tnode;
  2000. newstatement : tstatementnode;
  2001. tempnode (*,tempnode2*) : ttempcreatenode;
  2002. cmpfuncname: string;
  2003. para: tcallparanode;
  2004. begin
  2005. { when we get here, we are sure that both the left and the right }
  2006. { node are both strings of the same stringtype (JM) }
  2007. case nodetype of
  2008. addn:
  2009. begin
  2010. if (left.nodetype=stringconstn) and (tstringconstnode(left).len=0) then
  2011. begin
  2012. result:=right;
  2013. left.free;
  2014. left:=nil;
  2015. right:=nil;
  2016. exit;
  2017. end;
  2018. if (right.nodetype=stringconstn) and (tstringconstnode(right).len=0) then
  2019. begin
  2020. result:=left;
  2021. left:=nil;
  2022. right.free;
  2023. right:=nil;
  2024. exit;
  2025. end;
  2026. { create the call to the concat routine both strings as arguments }
  2027. if assigned(aktassignmentnode) and
  2028. (aktassignmentnode.right=self) and
  2029. (aktassignmentnode.left.resultdef=resultdef) and
  2030. valid_for_var(aktassignmentnode.left,false) then
  2031. begin
  2032. para:=ccallparanode.create(
  2033. right,
  2034. ccallparanode.create(
  2035. left,
  2036. ccallparanode.create(aktassignmentnode.left.getcopy,nil)
  2037. )
  2038. );
  2039. if is_ansistring(resultdef) then
  2040. para:=ccallparanode.create(
  2041. cordconstnode.create(
  2042. getparaencoding(resultdef),
  2043. u16inttype,
  2044. true
  2045. ),
  2046. para
  2047. );
  2048. result:=ccallnode.createintern(
  2049. 'fpc_'+tstringdef(resultdef).stringtypname+'_concat',
  2050. para
  2051. );
  2052. include(aktassignmentnode.flags,nf_assign_done_in_right);
  2053. firstpass(result);
  2054. end
  2055. else
  2056. begin
  2057. result:=internalstatements(newstatement);
  2058. tempnode:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2059. addstatement(newstatement,tempnode);
  2060. para:=ccallparanode.create(
  2061. right,
  2062. ccallparanode.create(
  2063. left,
  2064. ccallparanode.create(ctemprefnode.create(tempnode),nil)
  2065. )
  2066. );
  2067. if is_ansistring(resultdef) then
  2068. para:=ccallparanode.create(
  2069. cordconstnode.create(
  2070. getparaencoding(resultdef),
  2071. u16inttype,
  2072. true
  2073. ),
  2074. para
  2075. );
  2076. addstatement(
  2077. newstatement,
  2078. ccallnode.createintern(
  2079. 'fpc_'+tstringdef(resultdef).stringtypname+'_concat',
  2080. para
  2081. )
  2082. );
  2083. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
  2084. addstatement(newstatement,ctemprefnode.create(tempnode));
  2085. end;
  2086. { we reused the arguments }
  2087. left := nil;
  2088. right := nil;
  2089. end;
  2090. ltn,lten,gtn,gten,equaln,unequaln :
  2091. begin
  2092. { generate better code for comparison with empty string, we
  2093. only need to compare the length with 0 }
  2094. if (nodetype in [equaln,unequaln,gtn,gten,ltn,lten]) and
  2095. { windows widestrings are too complicated to be handled optimized }
  2096. not(is_widestring(left.resultdef) and (target_info.system in systems_windows)) and
  2097. (((left.nodetype=stringconstn) and (tstringconstnode(left).len=0)) or
  2098. ((right.nodetype=stringconstn) and (tstringconstnode(right).len=0))) then
  2099. begin
  2100. { switch so that the constant is always on the right }
  2101. if left.nodetype = stringconstn then
  2102. begin
  2103. p := left;
  2104. left := right;
  2105. right := p;
  2106. nodetype:=swap_relation[nodetype];
  2107. end;
  2108. if is_shortstring(left.resultdef) or
  2109. (nodetype in [gtn,gten,ltn,lten]) then
  2110. { compare the length with 0 }
  2111. result := caddnode.create(nodetype,
  2112. cinlinenode.create(in_length_x,false,left),
  2113. cordconstnode.create(0,s32inttype,false))
  2114. else
  2115. begin
  2116. (*
  2117. if is_widestring(left.resultdef) and
  2118. (target_info.system in system_windows) then
  2119. begin
  2120. { windows like widestrings requires that we also check the length }
  2121. result:=internalstatements(newstatement);
  2122. tempnode:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  2123. tempnode2:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2124. addstatement(newstatement,tempnode);
  2125. addstatement(newstatement,tempnode2);
  2126. { poor man's cse }
  2127. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  2128. ctypeconvnode.create_internal(left,voidpointertype))
  2129. );
  2130. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(tempnode2),
  2131. caddnode.create(orn,
  2132. caddnode.create(nodetype,
  2133. ctemprefnode.create(tempnode),
  2134. cpointerconstnode.create(0,voidpointertype)
  2135. ),
  2136. caddnode.create(nodetype,
  2137. ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),s32inttype),
  2138. cordconstnode.create(0,s32inttype,false)
  2139. )
  2140. )
  2141. ));
  2142. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
  2143. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode2));
  2144. addstatement(newstatement,ctemprefnode.create(tempnode2));
  2145. end
  2146. else
  2147. *)
  2148. begin
  2149. { compare the pointer with nil (for ansistrings etc), }
  2150. { faster than getting the length (JM) }
  2151. result:= caddnode.create(nodetype,
  2152. ctypeconvnode.create_internal(left,voidpointertype),
  2153. cpointerconstnode.create(0,voidpointertype));
  2154. end;
  2155. end;
  2156. { left is reused }
  2157. left := nil;
  2158. { right isn't }
  2159. right.free;
  2160. right := nil;
  2161. exit;
  2162. end;
  2163. { no string constant -> call compare routine }
  2164. cmpfuncname := 'fpc_'+tstringdef(left.resultdef).stringtypname+'_compare';
  2165. { for equality checks use optimized version }
  2166. if nodetype in [equaln,unequaln] then
  2167. cmpfuncname := cmpfuncname + '_equal';
  2168. result := ccallnode.createintern(cmpfuncname,
  2169. ccallparanode.create(right,ccallparanode.create(left,nil)));
  2170. { and compare its result with 0 according to the original operator }
  2171. result := caddnode.create(nodetype,result,
  2172. cordconstnode.create(0,s32inttype,false));
  2173. left := nil;
  2174. right := nil;
  2175. end;
  2176. end;
  2177. end;
  2178. function taddnode.first_addset : tnode;
  2179. procedure call_varset_helper(const n : string);
  2180. var
  2181. newstatement : tstatementnode;
  2182. temp : ttempcreatenode;
  2183. begin
  2184. { add two var sets }
  2185. result:=internalstatements(newstatement);
  2186. { create temp for result }
  2187. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2188. addstatement(newstatement,temp);
  2189. addstatement(newstatement,ccallnode.createintern(n,
  2190. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2191. ccallparanode.create(ctemprefnode.create(temp),
  2192. ccallparanode.create(right,
  2193. ccallparanode.create(left,nil)))))
  2194. );
  2195. { remove reused parts from original node }
  2196. left:=nil;
  2197. right:=nil;
  2198. { the last statement should return the value as
  2199. location and type, this is done be referencing the
  2200. temp and converting it first from a persistent temp to
  2201. normal temp }
  2202. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2203. addstatement(newstatement,ctemprefnode.create(temp));
  2204. end;
  2205. var
  2206. procname: string[31];
  2207. tempn: tnode;
  2208. newstatement : tstatementnode;
  2209. temp : ttempcreatenode;
  2210. begin
  2211. result:=nil;
  2212. case nodetype of
  2213. equaln,unequaln,lten,gten:
  2214. begin
  2215. case nodetype of
  2216. equaln,unequaln:
  2217. procname := 'fpc_varset_comp_sets';
  2218. lten,gten:
  2219. begin
  2220. procname := 'fpc_varset_contains_sets';
  2221. { (left >= right) = (right <= left) }
  2222. if nodetype = gten then
  2223. begin
  2224. tempn := left;
  2225. left := right;
  2226. right := tempn;
  2227. end;
  2228. end;
  2229. end;
  2230. result := ccallnode.createinternres(procname,
  2231. ccallparanode.create(cordconstnode.create(left.resultdef.size,sinttype,false),
  2232. ccallparanode.create(right,
  2233. ccallparanode.create(left,nil))),resultdef);
  2234. { left and right are reused as parameters }
  2235. left := nil;
  2236. right := nil;
  2237. { for an unequaln, we have to negate the result of comp_sets }
  2238. if nodetype = unequaln then
  2239. result := cnotnode.create(result);
  2240. end;
  2241. addn:
  2242. begin
  2243. { optimize first loading of a set }
  2244. if (right.nodetype=setelementn) and
  2245. not(assigned(tsetelementnode(right).right)) and
  2246. is_emptyset(left) then
  2247. begin
  2248. result:=internalstatements(newstatement);
  2249. { create temp for result }
  2250. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2251. addstatement(newstatement,temp);
  2252. { adjust for set base }
  2253. tsetelementnode(right).left:=caddnode.create(subn,
  2254. ctypeconvnode.create_internal(tsetelementnode(right).left,sinttype),
  2255. cordconstnode.create(tsetdef(resultdef).setbase,sinttype,false));
  2256. addstatement(newstatement,ccallnode.createintern('fpc_varset_create_element',
  2257. ccallparanode.create(ctemprefnode.create(temp),
  2258. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2259. ccallparanode.create(tsetelementnode(right).left,nil))))
  2260. );
  2261. { the last statement should return the value as
  2262. location and type, this is done be referencing the
  2263. temp and converting it first from a persistent temp to
  2264. normal temp }
  2265. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2266. addstatement(newstatement,ctemprefnode.create(temp));
  2267. tsetelementnode(right).left := nil;
  2268. end
  2269. else
  2270. begin
  2271. if right.nodetype=setelementn then
  2272. begin
  2273. result:=internalstatements(newstatement);
  2274. { create temp for result }
  2275. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2276. addstatement(newstatement,temp);
  2277. { adjust for set base }
  2278. tsetelementnode(right).left:=caddnode.create(subn,
  2279. ctypeconvnode.create_internal(tsetelementnode(right).left,sinttype),
  2280. cordconstnode.create(tsetdef(resultdef).setbase,sinttype,false));
  2281. { add a range or a single element? }
  2282. if assigned(tsetelementnode(right).right) then
  2283. begin
  2284. { adjust for set base }
  2285. tsetelementnode(right).right:=caddnode.create(subn,
  2286. ctypeconvnode.create_internal(tsetelementnode(right).right,sinttype),
  2287. cordconstnode.create(tsetdef(resultdef).setbase,sinttype,false));
  2288. addstatement(newstatement,ccallnode.createintern('fpc_varset_set_range',
  2289. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2290. ccallparanode.create(tsetelementnode(right).right,
  2291. ccallparanode.create(tsetelementnode(right).left,
  2292. ccallparanode.create(ctemprefnode.create(temp),
  2293. ccallparanode.create(left,nil))))))
  2294. );
  2295. end
  2296. else
  2297. addstatement(newstatement,ccallnode.createintern('fpc_varset_set',
  2298. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2299. ccallparanode.create(ctypeconvnode.create_internal(tsetelementnode(right).left,sinttype),
  2300. ccallparanode.create(ctemprefnode.create(temp),
  2301. ccallparanode.create(left,nil)))))
  2302. );
  2303. { remove reused parts from original node }
  2304. tsetelementnode(right).right:=nil;
  2305. tsetelementnode(right).left:=nil;
  2306. left:=nil;
  2307. { the last statement should return the value as
  2308. location and type, this is done be referencing the
  2309. temp and converting it first from a persistent temp to
  2310. normal temp }
  2311. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2312. addstatement(newstatement,ctemprefnode.create(temp));
  2313. end
  2314. else
  2315. call_varset_helper('fpc_varset_add_sets');
  2316. end
  2317. end;
  2318. subn:
  2319. call_varset_helper('fpc_varset_sub_sets');
  2320. symdifn:
  2321. call_varset_helper('fpc_varset_symdif_sets');
  2322. muln:
  2323. call_varset_helper('fpc_varset_mul_sets');
  2324. else
  2325. internalerror(200609241);
  2326. end;
  2327. end;
  2328. function taddnode.use_generic_mul32to64: boolean;
  2329. begin
  2330. result := true;
  2331. end;
  2332. function taddnode.try_make_mul32to64: boolean;
  2333. function canbe32bitint(v: tconstexprint): boolean;
  2334. begin
  2335. result := ((v >= int64(low(longint))) and (v <= int64(high(longint)))) or
  2336. ((v >= qword(low(cardinal))) and (v <= qword(high(cardinal))))
  2337. end;
  2338. var
  2339. temp: tnode;
  2340. begin
  2341. result := false;
  2342. if ((left.nodetype = typeconvn) and
  2343. is_integer(ttypeconvnode(left).left.resultdef) and
  2344. (not(torddef(ttypeconvnode(left).left.resultdef).ordtype in [u64bit,s64bit])) and
  2345. (((right.nodetype = ordconstn) and canbe32bitint(tordconstnode(right).value)) or
  2346. ((right.nodetype = typeconvn) and
  2347. is_integer(ttypeconvnode(right).left.resultdef) and
  2348. not(torddef(ttypeconvnode(right).left.resultdef).ordtype in [u64bit,s64bit])) and
  2349. ((is_signed(ttypeconvnode(left).left.resultdef) =
  2350. is_signed(ttypeconvnode(right).left.resultdef)) or
  2351. (is_signed(ttypeconvnode(left).left.resultdef) and
  2352. (torddef(ttypeconvnode(right).left.resultdef).ordtype in [u8bit,u16bit]))))) then
  2353. begin
  2354. temp := ttypeconvnode(left).left;
  2355. ttypeconvnode(left).left := nil;
  2356. left.free;
  2357. left := temp;
  2358. if (right.nodetype = typeconvn) then
  2359. begin
  2360. temp := ttypeconvnode(right).left;
  2361. ttypeconvnode(right).left := nil;
  2362. right.free;
  2363. right := temp;
  2364. end;
  2365. if (is_signed(left.resultdef)) then
  2366. begin
  2367. inserttypeconv(left,s32inttype);
  2368. inserttypeconv(right,s32inttype);
  2369. end
  2370. else
  2371. begin
  2372. inserttypeconv(left,u32inttype);
  2373. inserttypeconv(right,u32inttype);
  2374. end;
  2375. firstpass(left);
  2376. firstpass(right);
  2377. result := true;
  2378. end;
  2379. end;
  2380. function taddnode.first_add64bitint: tnode;
  2381. var
  2382. procname: string[31];
  2383. temp: tnode;
  2384. power: longint;
  2385. begin
  2386. result := nil;
  2387. { create helper calls mul }
  2388. if nodetype <> muln then
  2389. exit;
  2390. { make sure that if there is a constant, that it's on the right }
  2391. if left.nodetype = ordconstn then
  2392. begin
  2393. temp := right;
  2394. right := left;
  2395. left := temp;
  2396. end;
  2397. { can we use a shift instead of a mul? }
  2398. if not (cs_check_overflow in current_settings.localswitches) and
  2399. (right.nodetype = ordconstn) and
  2400. ispowerof2(tordconstnode(right).value,power) then
  2401. begin
  2402. tordconstnode(right).value := power;
  2403. result := cshlshrnode.create(shln,left,right);
  2404. { left and right are reused }
  2405. left := nil;
  2406. right := nil;
  2407. { return firstpassed new node }
  2408. exit;
  2409. end;
  2410. if not(use_generic_mul32to64) and
  2411. try_make_mul32to64 then
  2412. exit;
  2413. { when currency is used set the result of the
  2414. parameters to s64bit, so they are not converted }
  2415. if is_currency(resultdef) then
  2416. begin
  2417. left.resultdef:=s64inttype;
  2418. right.resultdef:=s64inttype;
  2419. end;
  2420. { otherwise, create the parameters for the helper }
  2421. right := ccallparanode.create(
  2422. cordconstnode.create(ord(cs_check_overflow in current_settings.localswitches),pasbool8type,true),
  2423. ccallparanode.create(right,ccallparanode.create(left,nil)));
  2424. left := nil;
  2425. { only qword needs the unsigned code, the
  2426. signed code is also used for currency }
  2427. if is_signed(resultdef) then
  2428. procname := 'fpc_mul_int64'
  2429. else
  2430. procname := 'fpc_mul_qword';
  2431. result := ccallnode.createintern(procname,right);
  2432. right := nil;
  2433. end;
  2434. function taddnode.first_addfloat : tnode;
  2435. var
  2436. procname: string[31];
  2437. { do we need to reverse the result ? }
  2438. notnode : boolean;
  2439. fdef : tdef;
  2440. begin
  2441. result := nil;
  2442. notnode := false;
  2443. { In non-emulation mode, real opcodes are
  2444. emitted for floating point values.
  2445. }
  2446. if not (cs_fp_emulation in current_settings.moduleswitches) then
  2447. exit;
  2448. if not(target_info.system in systems_wince) then
  2449. begin
  2450. case tfloatdef(left.resultdef).floattype of
  2451. s32real:
  2452. begin
  2453. fdef:=search_system_type('FLOAT32REC').typedef;
  2454. procname:='float32';
  2455. end;
  2456. s64real:
  2457. begin
  2458. fdef:=search_system_type('FLOAT64').typedef;
  2459. procname:='float64';
  2460. end;
  2461. {!!! not yet implemented
  2462. s128real:
  2463. }
  2464. else
  2465. internalerror(2005082601);
  2466. end;
  2467. case nodetype of
  2468. addn:
  2469. procname:=procname+'_add';
  2470. muln:
  2471. procname:=procname+'_mul';
  2472. subn:
  2473. procname:=procname+'_sub';
  2474. slashn:
  2475. procname:=procname+'_div';
  2476. ltn:
  2477. procname:=procname+'_lt';
  2478. lten:
  2479. procname:=procname+'_le';
  2480. gtn:
  2481. begin
  2482. procname:=procname+'_le';
  2483. notnode:=true;
  2484. end;
  2485. gten:
  2486. begin
  2487. procname:=procname+'_lt';
  2488. notnode:=true;
  2489. end;
  2490. equaln:
  2491. procname:=procname+'_eq';
  2492. unequaln:
  2493. begin
  2494. procname:=procname+'_eq';
  2495. notnode:=true;
  2496. end;
  2497. else
  2498. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),left.resultdef.typename,right.resultdef.typename);
  2499. end;
  2500. end
  2501. else
  2502. begin
  2503. case nodetype of
  2504. addn:
  2505. procname:='ADD';
  2506. muln:
  2507. procname:='MUL';
  2508. subn:
  2509. procname:='SUB';
  2510. slashn:
  2511. procname:='DIV';
  2512. ltn:
  2513. procname:='LT';
  2514. lten:
  2515. procname:='LE';
  2516. gtn:
  2517. procname:='GT';
  2518. gten:
  2519. procname:='GE';
  2520. equaln:
  2521. procname:='EQ';
  2522. unequaln:
  2523. procname:='NE';
  2524. else
  2525. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),left.resultdef.typename,right.resultdef.typename);
  2526. end;
  2527. case tfloatdef(left.resultdef).floattype of
  2528. s32real:
  2529. begin
  2530. procname:=procname+'S';
  2531. if nodetype in [addn,muln,subn,slashn] then
  2532. procname:=lower(procname);
  2533. end;
  2534. s64real:
  2535. procname:=procname+'D';
  2536. {!!! not yet implemented
  2537. s128real:
  2538. }
  2539. else
  2540. internalerror(2005082602);
  2541. end;
  2542. end;
  2543. { cast softfpu result? }
  2544. if not(target_info.system in systems_wince) then
  2545. begin
  2546. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  2547. resultdef:=pasbool8type;
  2548. result:=ctypeconvnode.create_internal(ccallnode.createintern(procname,ccallparanode.create(
  2549. ctypeconvnode.create_internal(right,fdef),
  2550. ccallparanode.create(
  2551. ctypeconvnode.create_internal(left,fdef),nil))),resultdef);
  2552. end
  2553. else
  2554. result:=ccallnode.createintern(procname,ccallparanode.create(right,
  2555. ccallparanode.create(left,nil)));
  2556. left:=nil;
  2557. right:=nil;
  2558. { do we need to reverse the result }
  2559. if notnode then
  2560. result:=cnotnode.create(result);
  2561. end;
  2562. function taddnode.pass_1 : tnode;
  2563. var
  2564. {$ifdef addstringopt}
  2565. hp : tnode;
  2566. {$endif addstringopt}
  2567. rd,ld : tdef;
  2568. i : longint;
  2569. lt,rt : tnodetype;
  2570. {$ifdef cpuneedsmulhelper}
  2571. procname : string[32];
  2572. {$endif cpuneedsmulhelper}
  2573. begin
  2574. result:=nil;
  2575. { Can we optimize multiple string additions into a single call?
  2576. This need to be done on a complete tree to detect the multiple
  2577. add nodes and is therefor done before the subtrees are processed }
  2578. if canbemultistringadd(self) then
  2579. begin
  2580. result := genmultistringadd(self);
  2581. exit;
  2582. end;
  2583. { first do the two subtrees }
  2584. firstpass(left);
  2585. firstpass(right);
  2586. if codegenerror then
  2587. exit;
  2588. { load easier access variables }
  2589. rd:=right.resultdef;
  2590. ld:=left.resultdef;
  2591. rt:=right.nodetype;
  2592. lt:=left.nodetype;
  2593. { int/int gives real/real! }
  2594. if nodetype=slashn then
  2595. begin
  2596. {$ifdef cpufpemu}
  2597. if (current_settings.fputype=fpu_soft) or (cs_fp_emulation in current_settings.moduleswitches) then
  2598. begin
  2599. result:=first_addfloat;
  2600. if assigned(result) then
  2601. exit;
  2602. end;
  2603. {$endif cpufpemu}
  2604. expectloc:=LOC_FPUREGISTER;
  2605. end
  2606. { if both are orddefs then check sub types }
  2607. else if (ld.typ=orddef) and (rd.typ=orddef) then
  2608. begin
  2609. { optimize multiplacation by a power of 2 }
  2610. if not(cs_check_overflow in current_settings.localswitches) and
  2611. (nodetype = muln) and
  2612. (((left.nodetype = ordconstn) and
  2613. ispowerof2(tordconstnode(left).value,i)) or
  2614. ((right.nodetype = ordconstn) and
  2615. ispowerof2(tordconstnode(right).value,i))) then
  2616. begin
  2617. if left.nodetype = ordconstn then
  2618. begin
  2619. tordconstnode(left).value := i;
  2620. result := cshlshrnode.create(shln,right,left);
  2621. end
  2622. else
  2623. begin
  2624. tordconstnode(right).value := i;
  2625. result := cshlshrnode.create(shln,left,right);
  2626. end;
  2627. left := nil;
  2628. right := nil;
  2629. exit;
  2630. end;
  2631. { 2 booleans ? }
  2632. if is_boolean(ld) and is_boolean(rd) then
  2633. begin
  2634. if (not(cs_full_boolean_eval in current_settings.localswitches) or
  2635. (nf_short_bool in flags)) and
  2636. (nodetype in [andn,orn]) then
  2637. expectloc:=LOC_JUMP
  2638. else
  2639. begin
  2640. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  2641. expectloc:=LOC_FLAGS
  2642. else
  2643. expectloc:=LOC_REGISTER;
  2644. end;
  2645. end
  2646. else
  2647. { Both are chars? only convert to shortstrings for addn }
  2648. if is_char(ld) then
  2649. begin
  2650. if nodetype=addn then
  2651. internalerror(200103291);
  2652. expectloc:=LOC_FLAGS;
  2653. end
  2654. {$ifndef cpu64bitaddr}
  2655. { is there a 64 bit type ? }
  2656. else if (torddef(ld).ordtype in [s64bit,u64bit,scurrency]) then
  2657. begin
  2658. result := first_add64bitint;
  2659. if assigned(result) then
  2660. exit;
  2661. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2662. expectloc:=LOC_REGISTER
  2663. else
  2664. expectloc:=LOC_JUMP;
  2665. end
  2666. {$endif cpu64bitaddr}
  2667. {$ifndef cpuneedsmulhelper}
  2668. { is there a cardinal? }
  2669. else if (torddef(ld).ordtype=u32bit) then
  2670. begin
  2671. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2672. expectloc:=LOC_REGISTER
  2673. else
  2674. expectloc:=LOC_FLAGS;
  2675. end
  2676. {$endif cpuneedsmulhelper}
  2677. { generic s32bit conversion }
  2678. else
  2679. begin
  2680. {$ifdef cpuneedsmulhelper}
  2681. if (nodetype=muln) and not(torddef(resultdef).ordtype in [u8bit,s8bit]) then
  2682. begin
  2683. result := nil;
  2684. case torddef(resultdef).ordtype of
  2685. s16bit:
  2686. procname := 'fpc_mul_integer';
  2687. u16bit:
  2688. procname := 'fpc_mul_word';
  2689. s32bit:
  2690. procname := 'fpc_mul_longint';
  2691. u32bit:
  2692. procname := 'fpc_mul_dword';
  2693. else
  2694. internalerror(2011022301);
  2695. end;
  2696. result := ccallnode.createintern(procname,
  2697. ccallparanode.create(cordconstnode.create(0,pasbool8type,false),
  2698. ccallparanode.create(right,
  2699. ccallparanode.create(left,nil))));
  2700. left := nil;
  2701. right := nil;
  2702. firstpass(result);
  2703. exit;
  2704. end;
  2705. {$endif cpuneedsmulhelper}
  2706. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2707. expectloc:=LOC_REGISTER
  2708. else
  2709. expectloc:=LOC_FLAGS;
  2710. end;
  2711. end
  2712. { left side a setdef, must be before string processing,
  2713. else array constructor can be seen as array of char (PFV) }
  2714. else if (ld.typ=setdef) then
  2715. begin
  2716. { small sets are handled inline by the compiler.
  2717. small set doesn't have support for adding ranges }
  2718. if is_smallset(ld) and
  2719. not(
  2720. (right.nodetype=setelementn) and
  2721. assigned(tsetelementnode(right).right)
  2722. ) then
  2723. begin
  2724. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  2725. expectloc:=LOC_FLAGS
  2726. else
  2727. expectloc:=LOC_REGISTER;
  2728. end
  2729. else
  2730. begin
  2731. result := first_addset;
  2732. if assigned(result) then
  2733. exit;
  2734. expectloc:=LOC_CREFERENCE;
  2735. end;
  2736. end
  2737. { compare pchar by addresses like BP/Delphi }
  2738. else if is_pchar(ld) then
  2739. begin
  2740. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2741. expectloc:=LOC_REGISTER
  2742. else
  2743. expectloc:=LOC_FLAGS;
  2744. end
  2745. { is one of the operands a string }
  2746. else if (ld.typ=stringdef) then
  2747. begin
  2748. if is_widestring(ld) then
  2749. begin
  2750. { this is only for add, the comparisaion is handled later }
  2751. expectloc:=LOC_REGISTER;
  2752. end
  2753. else if is_unicodestring(ld) then
  2754. begin
  2755. { this is only for add, the comparisaion is handled later }
  2756. expectloc:=LOC_REGISTER;
  2757. end
  2758. else if is_ansistring(ld) then
  2759. begin
  2760. { this is only for add, the comparisaion is handled later }
  2761. expectloc:=LOC_REGISTER;
  2762. end
  2763. else if is_longstring(ld) then
  2764. begin
  2765. { this is only for add, the comparisaion is handled later }
  2766. expectloc:=LOC_REFERENCE;
  2767. end
  2768. else
  2769. begin
  2770. {$ifdef addstringopt}
  2771. { can create a call which isn't handled by callparatemp }
  2772. if canbeaddsstringcharoptnode(self) then
  2773. begin
  2774. hp := genaddsstringcharoptnode(self);
  2775. pass_1 := hp;
  2776. exit;
  2777. end
  2778. else
  2779. {$endif addstringopt}
  2780. begin
  2781. { Fix right to be shortstring }
  2782. if is_char(right.resultdef) then
  2783. begin
  2784. inserttypeconv(right,cshortstringtype);
  2785. firstpass(right);
  2786. end;
  2787. end;
  2788. {$ifdef addstringopt}
  2789. { can create a call which isn't handled by callparatemp }
  2790. if canbeaddsstringcsstringoptnode(self) then
  2791. begin
  2792. hp := genaddsstringcsstringoptnode(self);
  2793. pass_1 := hp;
  2794. exit;
  2795. end;
  2796. {$endif addstringopt}
  2797. end;
  2798. { otherwise, let addstring convert everything }
  2799. result := first_addstring;
  2800. exit;
  2801. end
  2802. { is one a real float ? }
  2803. else if (rd.typ=floatdef) or (ld.typ=floatdef) then
  2804. begin
  2805. {$ifdef cpufpemu}
  2806. if (current_settings.fputype=fpu_soft) or (cs_fp_emulation in current_settings.moduleswitches) then
  2807. begin
  2808. result:=first_addfloat;
  2809. if assigned(result) then
  2810. exit;
  2811. end;
  2812. {$endif cpufpemu}
  2813. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2814. expectloc:=LOC_FPUREGISTER
  2815. else
  2816. expectloc:=LOC_FLAGS;
  2817. end
  2818. { pointer comperation and subtraction }
  2819. else if (ld.typ=pointerdef) then
  2820. begin
  2821. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  2822. expectloc:=LOC_REGISTER
  2823. else
  2824. expectloc:=LOC_FLAGS;
  2825. end
  2826. else if is_implicit_pointer_object_type(ld) then
  2827. begin
  2828. expectloc:=LOC_FLAGS;
  2829. end
  2830. else if (ld.typ=classrefdef) then
  2831. begin
  2832. expectloc:=LOC_FLAGS;
  2833. end
  2834. { support procvar=nil,procvar<>nil }
  2835. else if ((ld.typ=procvardef) and (rt=niln)) or
  2836. ((rd.typ=procvardef) and (lt=niln)) then
  2837. begin
  2838. expectloc:=LOC_FLAGS;
  2839. end
  2840. {$ifdef SUPPORT_MMX}
  2841. { mmx support, this must be before the zero based array
  2842. check }
  2843. else if (cs_mmx in current_settings.localswitches) and is_mmx_able_array(ld) and
  2844. is_mmx_able_array(rd) then
  2845. begin
  2846. expectloc:=LOC_MMXREGISTER;
  2847. end
  2848. {$endif SUPPORT_MMX}
  2849. else if (rd.typ=pointerdef) or (ld.typ=pointerdef) then
  2850. begin
  2851. expectloc:=LOC_REGISTER;
  2852. end
  2853. else if (rd.typ=procvardef) and
  2854. (ld.typ=procvardef) and
  2855. equal_defs(rd,ld) then
  2856. begin
  2857. expectloc:=LOC_FLAGS;
  2858. end
  2859. else if (ld.typ=enumdef) then
  2860. begin
  2861. expectloc:=LOC_FLAGS;
  2862. end
  2863. {$ifdef SUPPORT_MMX}
  2864. else if (cs_mmx in current_settings.localswitches) and
  2865. is_mmx_able_array(ld) and
  2866. is_mmx_able_array(rd) then
  2867. begin
  2868. expectloc:=LOC_MMXREGISTER;
  2869. end
  2870. {$endif SUPPORT_MMX}
  2871. { the general solution is to convert to 32 bit int }
  2872. else
  2873. begin
  2874. expectloc:=LOC_REGISTER;
  2875. end;
  2876. end;
  2877. {$ifdef state_tracking}
  2878. function Taddnode.track_state_pass(exec_known:boolean):boolean;
  2879. var factval:Tnode;
  2880. begin
  2881. track_state_pass:=false;
  2882. if left.track_state_pass(exec_known) then
  2883. begin
  2884. track_state_pass:=true;
  2885. left.resultdef:=nil;
  2886. do_typecheckpass(left);
  2887. end;
  2888. factval:=aktstate.find_fact(left);
  2889. if factval<>nil then
  2890. begin
  2891. track_state_pass:=true;
  2892. left.destroy;
  2893. left:=factval.getcopy;
  2894. end;
  2895. if right.track_state_pass(exec_known) then
  2896. begin
  2897. track_state_pass:=true;
  2898. right.resultdef:=nil;
  2899. do_typecheckpass(right);
  2900. end;
  2901. factval:=aktstate.find_fact(right);
  2902. if factval<>nil then
  2903. begin
  2904. track_state_pass:=true;
  2905. right.destroy;
  2906. right:=factval.getcopy;
  2907. end;
  2908. end;
  2909. {$endif}
  2910. end.