nadd.pas 82 KB

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