nadd.pas 78 KB

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