nadd.pas 81 KB

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