nadd.pas 78 KB

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