nadd.pas 81 KB

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