nadd.pas 80 KB

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