tcadd.pas 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Type checking and register allocation for add node
  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 tcadd;
  19. interface
  20. uses
  21. tree;
  22. procedure firstadd(var p : ptree);
  23. function isbinaryoverloaded(var p : ptree) : boolean;
  24. implementation
  25. uses
  26. globtype,systems,tokens,
  27. cobjects,verbose,globals,
  28. symconst,symtable,aasm,types,
  29. {$ifdef newcg}
  30. cgbase,
  31. {$else newcg}
  32. hcodegen,
  33. {$endif newcg}
  34. htypechk,pass_1,
  35. cpubase,tccnv
  36. ;
  37. function isbinaryoverloaded(var p : ptree) : boolean;
  38. var
  39. rd,ld : pdef;
  40. t : ptree;
  41. optoken : ttoken;
  42. begin
  43. isbinaryoverloaded:=false;
  44. { overloaded operator ? }
  45. { load easier access variables }
  46. rd:=p^.right^.resulttype;
  47. ld:=p^.left^.resulttype;
  48. if (p^.treetype=starstarn) or
  49. (ld^.deftype=recorddef) or
  50. ((ld^.deftype=arraydef) and
  51. not((cs_mmx in aktlocalswitches) and
  52. is_mmx_able_array(ld)) and
  53. (not (rd^.deftype in [orddef])) and
  54. (not is_chararray(ld))
  55. ) or
  56. { <> and = are defined for classes }
  57. ((ld^.deftype=objectdef) and
  58. (not(pobjectdef(ld)^.is_class) or
  59. not(p^.treetype in [equaln,unequaln])
  60. )
  61. ) or
  62. (rd^.deftype=recorddef) or
  63. ((rd^.deftype=arraydef) and
  64. not((cs_mmx in aktlocalswitches) and
  65. is_mmx_able_array(rd)) and
  66. (not (ld^.deftype in [orddef])) and
  67. (not is_chararray(rd))
  68. ) or
  69. { <> and = are defined for classes }
  70. ((rd^.deftype=objectdef) and
  71. (not(pobjectdef(rd)^.is_class) or
  72. not(p^.treetype in [equaln,unequaln])
  73. )
  74. ) then
  75. begin
  76. isbinaryoverloaded:=true;
  77. {!!!!!!!!! handle paras }
  78. case p^.treetype of
  79. { the nil as symtable signs firstcalln that this is
  80. an overloaded operator }
  81. addn:
  82. optoken:=_PLUS;
  83. subn:
  84. optoken:=_MINUS;
  85. muln:
  86. optoken:=_STAR;
  87. starstarn:
  88. optoken:=_STARSTAR;
  89. slashn:
  90. optoken:=_SLASH;
  91. ltn:
  92. optoken:=tokens._lt;
  93. gtn:
  94. optoken:=tokens._gt;
  95. lten:
  96. optoken:=_lte;
  97. gten:
  98. optoken:=_gte;
  99. equaln,unequaln :
  100. optoken:=_EQUAL;
  101. symdifn :
  102. optoken:=_SYMDIF;
  103. modn :
  104. optoken:=_OP_MOD;
  105. orn :
  106. optoken:=_OP_OR;
  107. xorn :
  108. optoken:=_OP_XOR;
  109. andn :
  110. optoken:=_OP_AND;
  111. divn :
  112. optoken:=_OP_DIV;
  113. shln :
  114. optoken:=_OP_SHL;
  115. shrn :
  116. optoken:=_OP_SHR;
  117. else
  118. exit;
  119. end;
  120. t:=gencallnode(overloaded_operators[optoken],nil);
  121. { we have to convert p^.left and p^.right into
  122. callparanodes }
  123. if t^.symtableprocentry=nil then
  124. begin
  125. CGMessage(parser_e_operator_not_overloaded);
  126. putnode(t);
  127. end
  128. else
  129. begin
  130. inc(t^.symtableprocentry^.refs);
  131. t^.left:=gencallparanode(p^.left,nil);
  132. t^.left:=gencallparanode(p^.right,t^.left);
  133. if p^.treetype=unequaln then
  134. t:=gensinglenode(notn,t);
  135. firstpass(t);
  136. putnode(p);
  137. p:=t;
  138. end;
  139. end;
  140. end;
  141. {*****************************************************************************
  142. FirstAdd
  143. *****************************************************************************}
  144. procedure firstadd(var p : ptree);
  145. procedure make_bool_equal_size(var p:ptree);
  146. begin
  147. if porddef(p^.left^.resulttype)^.typ>porddef(p^.right^.resulttype)^.typ then
  148. begin
  149. p^.right:=gentypeconvnode(p^.right,porddef(p^.left^.resulttype));
  150. p^.right^.convtyp:=tc_bool_2_int;
  151. p^.right^.explizit:=true;
  152. firstpass(p^.right);
  153. end
  154. else
  155. if porddef(p^.left^.resulttype)^.typ<porddef(p^.right^.resulttype)^.typ then
  156. begin
  157. p^.left:=gentypeconvnode(p^.left,porddef(p^.right^.resulttype));
  158. p^.left^.convtyp:=tc_bool_2_int;
  159. p^.left^.explizit:=true;
  160. firstpass(p^.left);
  161. end;
  162. end;
  163. {$ifdef fpc}
  164. {$maxfpuregisters 0}
  165. {$endif fpc}
  166. var
  167. t,hp : ptree;
  168. ot,
  169. lt,rt : ttreetyp;
  170. rv,lv : longint;
  171. rvd,lvd : bestreal;
  172. resdef,
  173. rd,ld : pdef;
  174. tempdef : pdef;
  175. concatstrings : boolean;
  176. { to evalute const sets }
  177. resultset : pconstset;
  178. i : longint;
  179. b : boolean;
  180. convdone : boolean;
  181. s1,s2 : pchar;
  182. l1,l2 : longint;
  183. begin
  184. { first do the two subtrees }
  185. firstpass(p^.left);
  186. firstpass(p^.right);
  187. if codegenerror then
  188. exit;
  189. { convert array constructors to sets, because there is no other operator
  190. possible for array constructors }
  191. if is_array_constructor(p^.left^.resulttype) then
  192. arrayconstructor_to_set(p^.left);
  193. if is_array_constructor(p^.right^.resulttype) then
  194. arrayconstructor_to_set(p^.right);
  195. { both left and right need to be valid }
  196. set_varstate(p^.left,true);
  197. set_varstate(p^.right,true);
  198. { load easier access variables }
  199. lt:=p^.left^.treetype;
  200. rt:=p^.right^.treetype;
  201. rd:=p^.right^.resulttype;
  202. ld:=p^.left^.resulttype;
  203. convdone:=false;
  204. if isbinaryoverloaded(p) then
  205. exit;
  206. { compact consts }
  207. { convert int consts to real consts, if the }
  208. { other operand is a real const }
  209. if (rt=realconstn) and is_constintnode(p^.left) then
  210. begin
  211. t:=genrealconstnode(p^.left^.value,p^.right^.resulttype);
  212. disposetree(p^.left);
  213. p^.left:=t;
  214. lt:=realconstn;
  215. end;
  216. if (lt=realconstn) and is_constintnode(p^.right) then
  217. begin
  218. t:=genrealconstnode(p^.right^.value,p^.left^.resulttype);
  219. disposetree(p^.right);
  220. p^.right:=t;
  221. rt:=realconstn;
  222. end;
  223. { both are int constants, also allow operations on two equal enums
  224. in fpc mode (Needed for conversion of C code) }
  225. if ((lt=ordconstn) and (rt=ordconstn)) and
  226. ((is_constintnode(p^.left) and is_constintnode(p^.right)) or
  227. (is_constboolnode(p^.left) and is_constboolnode(p^.right) and
  228. (p^.treetype in [ltn,lten,gtn,gten,equaln,unequaln,andn,xorn,orn]))) then
  229. begin
  230. { return a boolean for boolean operations (and,xor,or) }
  231. if is_constboolnode(p^.left) then
  232. resdef:=booldef
  233. else
  234. resdef:=s32bitdef;
  235. lv:=p^.left^.value;
  236. rv:=p^.right^.value;
  237. case p^.treetype of
  238. addn : t:=genordinalconstnode(lv+rv,resdef);
  239. subn : t:=genordinalconstnode(lv-rv,resdef);
  240. muln : t:=genordinalconstnode(lv*rv,resdef);
  241. xorn : t:=genordinalconstnode(lv xor rv,resdef);
  242. orn : t:=genordinalconstnode(lv or rv,resdef);
  243. andn : t:=genordinalconstnode(lv and rv,resdef);
  244. ltn : t:=genordinalconstnode(ord(lv<rv),booldef);
  245. lten : t:=genordinalconstnode(ord(lv<=rv),booldef);
  246. gtn : t:=genordinalconstnode(ord(lv>rv),booldef);
  247. gten : t:=genordinalconstnode(ord(lv>=rv),booldef);
  248. equaln : t:=genordinalconstnode(ord(lv=rv),booldef);
  249. unequaln : t:=genordinalconstnode(ord(lv<>rv),booldef);
  250. slashn : begin
  251. { int/int becomes a real }
  252. if int(rv)=0 then
  253. begin
  254. Message(parser_e_invalid_float_operation);
  255. t:=genrealconstnode(0,bestrealdef^);
  256. end
  257. else
  258. t:=genrealconstnode(int(lv)/int(rv),bestrealdef^);
  259. firstpass(t);
  260. end;
  261. else
  262. CGMessage(type_e_mismatch);
  263. end;
  264. disposetree(p);
  265. firstpass(t);
  266. p:=t;
  267. exit;
  268. end;
  269. { both real constants ? }
  270. if (lt=realconstn) and (rt=realconstn) then
  271. begin
  272. lvd:=p^.left^.value_real;
  273. rvd:=p^.right^.value_real;
  274. case p^.treetype of
  275. addn : t:=genrealconstnode(lvd+rvd,bestrealdef^);
  276. subn : t:=genrealconstnode(lvd-rvd,bestrealdef^);
  277. muln : t:=genrealconstnode(lvd*rvd,bestrealdef^);
  278. starstarn,
  279. caretn : begin
  280. if lvd<0 then
  281. begin
  282. Message(parser_e_invalid_float_operation);
  283. t:=genrealconstnode(0,bestrealdef^);
  284. end
  285. else if lvd=0 then
  286. t:=genrealconstnode(1.0,bestrealdef^)
  287. else
  288. t:=genrealconstnode(exp(ln(lvd)*rvd),bestrealdef^);
  289. end;
  290. slashn :
  291. begin
  292. if rvd=0 then
  293. begin
  294. Message(parser_e_invalid_float_operation);
  295. t:=genrealconstnode(0,bestrealdef^);
  296. end
  297. else
  298. t:=genrealconstnode(lvd/rvd,bestrealdef^);
  299. end;
  300. ltn : t:=genordinalconstnode(ord(lvd<rvd),booldef);
  301. lten : t:=genordinalconstnode(ord(lvd<=rvd),booldef);
  302. gtn : t:=genordinalconstnode(ord(lvd>rvd),booldef);
  303. gten : t:=genordinalconstnode(ord(lvd>=rvd),booldef);
  304. equaln : t:=genordinalconstnode(ord(lvd=rvd),booldef);
  305. unequaln : t:=genordinalconstnode(ord(lvd<>rvd),booldef);
  306. else
  307. CGMessage(type_e_mismatch);
  308. end;
  309. disposetree(p);
  310. p:=t;
  311. firstpass(p);
  312. exit;
  313. end;
  314. { concating strings ? }
  315. concatstrings:=false;
  316. s1:=nil;
  317. s2:=nil;
  318. if (lt=ordconstn) and (rt=ordconstn) and
  319. is_char(ld) and is_char(rd) then
  320. begin
  321. s1:=strpnew(char(byte(p^.left^.value)));
  322. s2:=strpnew(char(byte(p^.right^.value)));
  323. l1:=1;
  324. l2:=1;
  325. concatstrings:=true;
  326. end
  327. else
  328. if (lt=stringconstn) and (rt=ordconstn) and is_char(rd) then
  329. begin
  330. s1:=getpcharcopy(p^.left);
  331. l1:=p^.left^.length;
  332. s2:=strpnew(char(byte(p^.right^.value)));
  333. l2:=1;
  334. concatstrings:=true;
  335. end
  336. else
  337. if (lt=ordconstn) and (rt=stringconstn) and is_char(ld) then
  338. begin
  339. s1:=strpnew(char(byte(p^.left^.value)));
  340. l1:=1;
  341. s2:=getpcharcopy(p^.right);
  342. l2:=p^.right^.length;
  343. concatstrings:=true;
  344. end
  345. else if (lt=stringconstn) and (rt=stringconstn) then
  346. begin
  347. s1:=getpcharcopy(p^.left);
  348. l1:=p^.left^.length;
  349. s2:=getpcharcopy(p^.right);
  350. l2:=p^.right^.length;
  351. concatstrings:=true;
  352. end;
  353. { I will need to translate all this to ansistrings !!! }
  354. if concatstrings then
  355. begin
  356. case p^.treetype of
  357. addn :
  358. t:=genpcharconstnode(concatansistrings(s1,s2,l1,l2),l1+l2);
  359. ltn :
  360. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)<0),booldef);
  361. lten :
  362. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)<=0),booldef);
  363. gtn :
  364. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)>0),booldef);
  365. gten :
  366. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)>=0),booldef);
  367. equaln :
  368. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)=0),booldef);
  369. unequaln :
  370. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)<>0),booldef);
  371. end;
  372. ansistringdispose(s1,l1);
  373. ansistringdispose(s2,l2);
  374. disposetree(p);
  375. firstpass(t);
  376. p:=t;
  377. exit;
  378. end;
  379. { if both are orddefs then check sub types }
  380. if (ld^.deftype=orddef) and (rd^.deftype=orddef) then
  381. begin
  382. { 2 booleans ? }
  383. if is_boolean(ld) and is_boolean(rd) then
  384. begin
  385. case p^.treetype of
  386. andn,
  387. orn:
  388. begin
  389. make_bool_equal_size(p);
  390. calcregisters(p,0,0,0);
  391. p^.location.loc:=LOC_JUMP;
  392. end;
  393. xorn,ltn,lten,gtn,gten:
  394. begin
  395. make_bool_equal_size(p);
  396. if (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) and
  397. (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) then
  398. calcregisters(p,2,0,0)
  399. else
  400. calcregisters(p,1,0,0);
  401. end;
  402. unequaln,
  403. equaln:
  404. begin
  405. make_bool_equal_size(p);
  406. { Remove any compares with constants }
  407. if (p^.left^.treetype=ordconstn) then
  408. begin
  409. hp:=p^.right;
  410. b:=(p^.left^.value<>0);
  411. ot:=p^.treetype;
  412. disposetree(p^.left);
  413. putnode(p);
  414. p:=hp;
  415. if (not(b) and (ot=equaln)) or
  416. (b and (ot=unequaln)) then
  417. begin
  418. p:=gensinglenode(notn,p);
  419. firstpass(p);
  420. end;
  421. exit;
  422. end;
  423. if (p^.right^.treetype=ordconstn) then
  424. begin
  425. hp:=p^.left;
  426. b:=(p^.right^.value<>0);
  427. ot:=p^.treetype;
  428. disposetree(p^.right);
  429. putnode(p);
  430. p:=hp;
  431. if (not(b) and (ot=equaln)) or
  432. (b and (ot=unequaln)) then
  433. begin
  434. p:=gensinglenode(notn,p);
  435. firstpass(p);
  436. end;
  437. exit;
  438. end;
  439. if (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) and
  440. (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) then
  441. calcregisters(p,2,0,0)
  442. else
  443. calcregisters(p,1,0,0);
  444. end;
  445. else
  446. CGMessage(type_e_mismatch);
  447. end;
  448. { these one can't be in flags! }
  449. if p^.treetype in [xorn,unequaln,equaln] then
  450. begin
  451. if p^.left^.location.loc=LOC_FLAGS then
  452. begin
  453. p^.left:=gentypeconvnode(p^.left,porddef(p^.left^.resulttype));
  454. p^.left^.convtyp:=tc_bool_2_int;
  455. p^.left^.explizit:=true;
  456. firstpass(p^.left);
  457. end;
  458. if p^.right^.location.loc=LOC_FLAGS then
  459. begin
  460. p^.right:=gentypeconvnode(p^.right,porddef(p^.right^.resulttype));
  461. p^.right^.convtyp:=tc_bool_2_int;
  462. p^.right^.explizit:=true;
  463. firstpass(p^.right);
  464. end;
  465. { readjust registers }
  466. calcregisters(p,1,0,0);
  467. end;
  468. convdone:=true;
  469. end
  470. else
  471. { Both are chars? only convert to shortstrings for addn }
  472. if is_char(rd) and is_char(ld) then
  473. begin
  474. if p^.treetype=addn then
  475. begin
  476. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  477. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  478. firstpass(p^.left);
  479. firstpass(p^.right);
  480. { here we call STRCOPY }
  481. procinfo^.flags:=procinfo^.flags or pi_do_call;
  482. calcregisters(p,0,0,0);
  483. p^.location.loc:=LOC_MEM;
  484. end
  485. else
  486. calcregisters(p,1,0,0);
  487. convdone:=true;
  488. end
  489. { is there a 64 bit type ? }
  490. else if (porddef(rd)^.typ=s64bit) or (porddef(ld)^.typ=s64bit) then
  491. begin
  492. if (porddef(ld)^.typ<>s64bit) then
  493. begin
  494. p^.left:=gentypeconvnode(p^.left,cs64bitdef);
  495. firstpass(p^.left);
  496. end;
  497. if (porddef(rd)^.typ<>s64bit) then
  498. begin
  499. p^.right:=gentypeconvnode(p^.right,cs64bitdef);
  500. firstpass(p^.right);
  501. end;
  502. calcregisters(p,2,0,0);
  503. convdone:=true;
  504. end
  505. else if (porddef(rd)^.typ=u64bit) or (porddef(ld)^.typ=u64bit) then
  506. begin
  507. if (porddef(ld)^.typ<>u64bit) then
  508. begin
  509. p^.left:=gentypeconvnode(p^.left,cu64bitdef);
  510. firstpass(p^.left);
  511. end;
  512. if (porddef(rd)^.typ<>u64bit) then
  513. begin
  514. p^.right:=gentypeconvnode(p^.right,cu64bitdef);
  515. firstpass(p^.right);
  516. end;
  517. calcregisters(p,2,0,0);
  518. convdone:=true;
  519. end
  520. else
  521. { is there a cardinal? }
  522. if (porddef(rd)^.typ=u32bit) or (porddef(ld)^.typ=u32bit) then
  523. begin
  524. { convert constants to u32bit }
  525. {$ifndef cardinalmulfix}
  526. if (porddef(ld)^.typ<>u32bit) then
  527. begin
  528. { s32bit will be used for when the other is also s32bit }
  529. { the following line doesn't make any sense: it's the same as }
  530. { if ((porddef(rd)^.typ=u32bit) or (porddef(ld)^.typ=u32bit)) and }
  531. { (porddef(ld)^.typ<>u32bit) and (porddef(rd)^.typ=s32bit) then }
  532. { which can be simplified to }
  533. { if ((porddef(rd)^.typ=u32bit) and (porddef(rd)^.typ=s32bit) then }
  534. { which can never be true (JM) }
  535. if (porddef(rd)^.typ=s32bit) and (lt<>ordconstn) then
  536. p^.left:=gentypeconvnode(p^.left,s32bitdef)
  537. else
  538. p^.left:=gentypeconvnode(p^.left,u32bitdef);
  539. firstpass(p^.left);
  540. end;
  541. if (porddef(rd)^.typ<>u32bit) then
  542. begin
  543. { s32bit will be used for when the other is also s32bit }
  544. if (porddef(ld)^.typ=s32bit) and (rt<>ordconstn) then
  545. p^.right:=gentypeconvnode(p^.right,s32bitdef)
  546. else
  547. p^.right:=gentypeconvnode(p^.right,u32bitdef);
  548. firstpass(p^.right);
  549. end;
  550. {$else cardinalmulfix}
  551. { only do a conversion if the nodes have different signs }
  552. if (porddef(rd)^.typ=u32bit) xor (porddef(ld)^.typ=u32bit) then
  553. if (porddef(rd)^.typ=u32bit) then
  554. begin
  555. { can we make them both unsigned? }
  556. if is_constintnode(p^.left) and
  557. ((p^.treetype <> subn) and
  558. (p^.left^.value > 0)) then
  559. p^.left:=gentypeconvnode(p^.left,u32bitdef)
  560. else
  561. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  562. firstpass(p^.left);
  563. end
  564. else {if (porddef(ld)^.typ=u32bit) then}
  565. begin
  566. { can we make them both unsigned? }
  567. if is_constintnode(p^.right) and
  568. (p^.right^.value > 0) then
  569. p^.right:=gentypeconvnode(p^.right,u32bitdef)
  570. else
  571. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  572. firstpass(p^.right);
  573. end;
  574. {$endif cardinalmulfix}
  575. calcregisters(p,1,0,0);
  576. { for unsigned mul we need an extra register }
  577. { p^.registers32:=p^.left^.registers32+p^.right^.registers32; }
  578. if p^.treetype=muln then
  579. inc(p^.registers32);
  580. convdone:=true;
  581. end;
  582. end
  583. else
  584. { left side a setdef, must be before string processing,
  585. else array constructor can be seen as array of char (PFV) }
  586. if (ld^.deftype=setdef) {or is_array_constructor(ld)} then
  587. begin
  588. { trying to add a set element? }
  589. if (p^.treetype=addn) and (rd^.deftype<>setdef) then
  590. begin
  591. if (rt=setelementn) then
  592. begin
  593. if not(is_equal(psetdef(ld)^.elementtype.def,rd)) then
  594. CGMessage(type_e_set_element_are_not_comp);
  595. end
  596. else
  597. CGMessage(type_e_mismatch)
  598. end
  599. else
  600. begin
  601. if not(p^.treetype in [addn,subn,symdifn,muln,equaln,unequaln
  602. {$IfNDef NoSetInclusion}
  603. ,lten,gten
  604. {$EndIf NoSetInclusion}
  605. ]) then
  606. CGMessage(type_e_set_operation_unknown);
  607. { right def must be a also be set }
  608. if (rd^.deftype<>setdef) or not(is_equal(rd,ld)) then
  609. CGMessage(type_e_set_element_are_not_comp);
  610. end;
  611. { ranges require normsets }
  612. if (psetdef(ld)^.settype=smallset) and
  613. (rt=setelementn) and
  614. assigned(p^.right^.right) then
  615. begin
  616. { generate a temporary normset def }
  617. tempdef:=new(psetdef,init(psetdef(ld)^.elementtype.def,255));
  618. p^.left:=gentypeconvnode(p^.left,tempdef);
  619. firstpass(p^.left);
  620. dispose(tempdef,done);
  621. ld:=p^.left^.resulttype;
  622. end;
  623. { if the destination is not a smallset then insert a typeconv
  624. which loads a smallset into a normal set }
  625. if (psetdef(ld)^.settype<>smallset) and
  626. (psetdef(rd)^.settype=smallset) then
  627. begin
  628. if (p^.right^.treetype=setconstn) then
  629. begin
  630. t:=gensetconstnode(p^.right^.value_set,psetdef(p^.left^.resulttype));
  631. t^.left:=p^.right^.left;
  632. putnode(p^.right);
  633. p^.right:=t;
  634. end
  635. else
  636. p^.right:=gentypeconvnode(p^.right,psetdef(p^.left^.resulttype));
  637. firstpass(p^.right);
  638. end;
  639. { do constant evaluation }
  640. if (p^.right^.treetype=setconstn) and
  641. not assigned(p^.right^.left) and
  642. (p^.left^.treetype=setconstn) and
  643. not assigned(p^.left^.left) then
  644. begin
  645. new(resultset);
  646. case p^.treetype of
  647. addn : begin
  648. for i:=0 to 31 do
  649. resultset^[i]:=
  650. p^.right^.value_set^[i] or p^.left^.value_set^[i];
  651. t:=gensetconstnode(resultset,psetdef(ld));
  652. end;
  653. muln : begin
  654. for i:=0 to 31 do
  655. resultset^[i]:=
  656. p^.right^.value_set^[i] and p^.left^.value_set^[i];
  657. t:=gensetconstnode(resultset,psetdef(ld));
  658. end;
  659. subn : begin
  660. for i:=0 to 31 do
  661. resultset^[i]:=
  662. p^.left^.value_set^[i] and not(p^.right^.value_set^[i]);
  663. t:=gensetconstnode(resultset,psetdef(ld));
  664. end;
  665. symdifn : begin
  666. for i:=0 to 31 do
  667. resultset^[i]:=
  668. p^.left^.value_set^[i] xor p^.right^.value_set^[i];
  669. t:=gensetconstnode(resultset,psetdef(ld));
  670. end;
  671. unequaln : begin
  672. b:=true;
  673. for i:=0 to 31 do
  674. if p^.right^.value_set^[i]=p^.left^.value_set^[i] then
  675. begin
  676. b:=false;
  677. break;
  678. end;
  679. t:=genordinalconstnode(ord(b),booldef);
  680. end;
  681. equaln : begin
  682. b:=true;
  683. for i:=0 to 31 do
  684. if p^.right^.value_set^[i]<>p^.left^.value_set^[i] then
  685. begin
  686. b:=false;
  687. break;
  688. end;
  689. t:=genordinalconstnode(ord(b),booldef);
  690. end;
  691. {$IfNDef NoSetInclusion}
  692. lten : Begin
  693. b := true;
  694. For i := 0 to 31 Do
  695. If (p^.right^.value_set^[i] And p^.left^.value_set^[i]) <>
  696. p^.left^.value_set^[i] Then
  697. Begin
  698. b := false;
  699. Break
  700. End;
  701. t := genordinalconstnode(ord(b),booldef);
  702. End;
  703. gten : Begin
  704. b := true;
  705. For i := 0 to 31 Do
  706. If (p^.left^.value_set^[i] And p^.right^.value_set^[i]) <>
  707. p^.right^.value_set^[i] Then
  708. Begin
  709. b := false;
  710. Break
  711. End;
  712. t := genordinalconstnode(ord(b),booldef);
  713. End;
  714. {$EndIf NoSetInclusion}
  715. end;
  716. dispose(resultset);
  717. disposetree(p);
  718. p:=t;
  719. firstpass(p);
  720. exit;
  721. end
  722. else
  723. if psetdef(ld)^.settype=smallset then
  724. begin
  725. { are we adding set elements ? }
  726. if p^.right^.treetype=setelementn then
  727. calcregisters(p,2,0,0)
  728. else
  729. calcregisters(p,1,0,0);
  730. p^.location.loc:=LOC_REGISTER;
  731. end
  732. else
  733. begin
  734. calcregisters(p,0,0,0);
  735. { here we call SET... }
  736. procinfo^.flags:=procinfo^.flags or pi_do_call;
  737. p^.location.loc:=LOC_MEM;
  738. end;
  739. convdone:=true;
  740. end
  741. else
  742. { is one of the operands a string?,
  743. chararrays are also handled as strings (after conversion) }
  744. if (rd^.deftype=stringdef) or (ld^.deftype=stringdef) or
  745. ((is_chararray(rd) or is_char(rd)) and
  746. (is_chararray(ld) or is_char(ld))) then
  747. begin
  748. if is_widestring(rd) or is_widestring(ld) then
  749. begin
  750. if not(is_widestring(rd)) then
  751. p^.right:=gentypeconvnode(p^.right,cwidestringdef);
  752. if not(is_widestring(ld)) then
  753. p^.left:=gentypeconvnode(p^.left,cwidestringdef);
  754. p^.resulttype:=cwidestringdef;
  755. { this is only for add, the comparisaion is handled later }
  756. p^.location.loc:=LOC_REGISTER;
  757. end
  758. else if is_ansistring(rd) or is_ansistring(ld) then
  759. begin
  760. if not(is_ansistring(rd)) then
  761. p^.right:=gentypeconvnode(p^.right,cansistringdef);
  762. if not(is_ansistring(ld)) then
  763. p^.left:=gentypeconvnode(p^.left,cansistringdef);
  764. { we use ansistrings so no fast exit here }
  765. procinfo^.no_fast_exit:=true;
  766. p^.resulttype:=cansistringdef;
  767. { this is only for add, the comparisaion is handled later }
  768. p^.location.loc:=LOC_REGISTER;
  769. end
  770. else if is_longstring(rd) or is_longstring(ld) then
  771. begin
  772. if not(is_longstring(rd)) then
  773. p^.right:=gentypeconvnode(p^.right,clongstringdef);
  774. if not(is_longstring(ld)) then
  775. p^.left:=gentypeconvnode(p^.left,clongstringdef);
  776. p^.resulttype:=clongstringdef;
  777. { this is only for add, the comparisaion is handled later }
  778. p^.location.loc:=LOC_MEM;
  779. end
  780. else
  781. begin
  782. if not(is_shortstring(rd)) then
  783. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  784. if not(is_shortstring(ld)) then
  785. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  786. p^.resulttype:=cshortstringdef;
  787. { this is only for add, the comparisaion is handled later }
  788. p^.location.loc:=LOC_MEM;
  789. end;
  790. { only if there is a type cast we need to do again }
  791. { the first pass }
  792. if p^.left^.treetype=typeconvn then
  793. firstpass(p^.left);
  794. if p^.right^.treetype=typeconvn then
  795. firstpass(p^.right);
  796. { here we call STRCONCAT or STRCMP or STRCOPY }
  797. procinfo^.flags:=procinfo^.flags or pi_do_call;
  798. if p^.location.loc=LOC_MEM then
  799. calcregisters(p,0,0,0)
  800. else
  801. calcregisters(p,1,0,0);
  802. convdone:=true;
  803. end
  804. else
  805. { is one a real float ? }
  806. if (rd^.deftype=floatdef) or (ld^.deftype=floatdef) then
  807. begin
  808. { if one is a fixed, then convert to f32bit }
  809. if ((rd^.deftype=floatdef) and (pfloatdef(rd)^.typ=f32bit)) or
  810. ((ld^.deftype=floatdef) and (pfloatdef(ld)^.typ=f32bit)) then
  811. begin
  812. if not is_integer(rd) or (p^.treetype<>muln) then
  813. p^.right:=gentypeconvnode(p^.right,s32fixeddef);
  814. if not is_integer(ld) or (p^.treetype<>muln) then
  815. p^.left:=gentypeconvnode(p^.left,s32fixeddef);
  816. firstpass(p^.left);
  817. firstpass(p^.right);
  818. calcregisters(p,1,0,0);
  819. p^.location.loc:=LOC_REGISTER;
  820. end
  821. else
  822. { convert both to bestreal }
  823. begin
  824. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  825. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  826. firstpass(p^.left);
  827. firstpass(p^.right);
  828. calcregisters(p,0,1,0);
  829. p^.location.loc:=LOC_FPU;
  830. end;
  831. convdone:=true;
  832. end
  833. else
  834. { pointer comperation and subtraction }
  835. if (rd^.deftype=pointerdef) and (ld^.deftype=pointerdef) then
  836. begin
  837. p^.location.loc:=LOC_REGISTER;
  838. { p^.right:=gentypeconvnode(p^.right,ld); }
  839. { firstpass(p^.right); }
  840. calcregisters(p,1,0,0);
  841. case p^.treetype of
  842. equaln,unequaln :
  843. begin
  844. if is_equal(p^.right^.resulttype,voidpointerdef) then
  845. begin
  846. p^.right:=gentypeconvnode(p^.right,ld);
  847. firstpass(p^.right);
  848. end
  849. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  850. begin
  851. p^.left:=gentypeconvnode(p^.left,rd);
  852. firstpass(p^.left);
  853. end
  854. else if not(is_equal(ld,rd)) then
  855. CGMessage(type_e_mismatch);
  856. end;
  857. ltn,lten,gtn,gten:
  858. begin
  859. if is_equal(p^.right^.resulttype,voidpointerdef) then
  860. begin
  861. p^.right:=gentypeconvnode(p^.right,ld);
  862. firstpass(p^.right);
  863. end
  864. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  865. begin
  866. p^.left:=gentypeconvnode(p^.left,rd);
  867. firstpass(p^.left);
  868. end
  869. else if not(is_equal(ld,rd)) then
  870. CGMessage(type_e_mismatch);
  871. if not(cs_extsyntax in aktmoduleswitches) then
  872. CGMessage(type_e_mismatch);
  873. end;
  874. subn:
  875. begin
  876. if not(is_equal(ld,rd)) then
  877. CGMessage(type_e_mismatch);
  878. if not(cs_extsyntax in aktmoduleswitches) then
  879. CGMessage(type_e_mismatch);
  880. p^.resulttype:=s32bitdef;
  881. exit;
  882. end;
  883. else CGMessage(type_e_mismatch);
  884. end;
  885. convdone:=true;
  886. end
  887. else
  888. if (rd^.deftype=objectdef) and (ld^.deftype=objectdef) and
  889. pobjectdef(rd)^.is_class and pobjectdef(ld)^.is_class then
  890. begin
  891. p^.location.loc:=LOC_REGISTER;
  892. if pobjectdef(rd)^.is_related(pobjectdef(ld)) then
  893. p^.right:=gentypeconvnode(p^.right,ld)
  894. else
  895. p^.left:=gentypeconvnode(p^.left,rd);
  896. firstpass(p^.right);
  897. firstpass(p^.left);
  898. calcregisters(p,1,0,0);
  899. case p^.treetype of
  900. equaln,unequaln : ;
  901. else CGMessage(type_e_mismatch);
  902. end;
  903. convdone:=true;
  904. end
  905. else
  906. if (rd^.deftype=classrefdef) and (ld^.deftype=classrefdef) then
  907. begin
  908. p^.location.loc:=LOC_REGISTER;
  909. if pobjectdef(pclassrefdef(rd)^.pointertype.def)^.is_related(pobjectdef(
  910. pclassrefdef(ld)^.pointertype.def)) then
  911. p^.right:=gentypeconvnode(p^.right,ld)
  912. else
  913. p^.left:=gentypeconvnode(p^.left,rd);
  914. firstpass(p^.right);
  915. firstpass(p^.left);
  916. calcregisters(p,1,0,0);
  917. case p^.treetype of
  918. equaln,unequaln : ;
  919. else CGMessage(type_e_mismatch);
  920. end;
  921. convdone:=true;
  922. end
  923. else
  924. { allows comperasion with nil pointer }
  925. if (rd^.deftype=objectdef) and
  926. pobjectdef(rd)^.is_class then
  927. begin
  928. p^.location.loc:=LOC_REGISTER;
  929. p^.left:=gentypeconvnode(p^.left,rd);
  930. firstpass(p^.left);
  931. calcregisters(p,1,0,0);
  932. case p^.treetype of
  933. equaln,unequaln : ;
  934. else CGMessage(type_e_mismatch);
  935. end;
  936. convdone:=true;
  937. end
  938. else
  939. if (ld^.deftype=objectdef) and
  940. pobjectdef(ld)^.is_class then
  941. begin
  942. p^.location.loc:=LOC_REGISTER;
  943. p^.right:=gentypeconvnode(p^.right,ld);
  944. firstpass(p^.right);
  945. calcregisters(p,1,0,0);
  946. case p^.treetype of
  947. equaln,unequaln : ;
  948. else CGMessage(type_e_mismatch);
  949. end;
  950. convdone:=true;
  951. end
  952. else
  953. if (rd^.deftype=classrefdef) then
  954. begin
  955. p^.left:=gentypeconvnode(p^.left,rd);
  956. firstpass(p^.left);
  957. calcregisters(p,1,0,0);
  958. case p^.treetype of
  959. equaln,unequaln : ;
  960. else CGMessage(type_e_mismatch);
  961. end;
  962. convdone:=true;
  963. end
  964. else
  965. if (ld^.deftype=classrefdef) then
  966. begin
  967. p^.right:=gentypeconvnode(p^.right,ld);
  968. firstpass(p^.right);
  969. calcregisters(p,1,0,0);
  970. case p^.treetype of
  971. equaln,unequaln : ;
  972. else
  973. CGMessage(type_e_mismatch);
  974. end;
  975. convdone:=true;
  976. end
  977. else
  978. { support procvar=nil,procvar<>nil }
  979. if ((ld^.deftype=procvardef) and (rt=niln)) or
  980. ((rd^.deftype=procvardef) and (lt=niln)) then
  981. begin
  982. calcregisters(p,1,0,0);
  983. p^.location.loc:=LOC_REGISTER;
  984. case p^.treetype of
  985. equaln,unequaln : ;
  986. else
  987. CGMessage(type_e_mismatch);
  988. end;
  989. convdone:=true;
  990. end
  991. else
  992. {$ifdef SUPPORT_MMX}
  993. if (cs_mmx in aktlocalswitches) and is_mmx_able_array(ld) and
  994. is_mmx_able_array(rd) and is_equal(ld,rd) then
  995. begin
  996. firstpass(p^.right);
  997. firstpass(p^.left);
  998. case p^.treetype of
  999. addn,subn,xorn,orn,andn:
  1000. ;
  1001. { mul is a little bit restricted }
  1002. muln:
  1003. if not(mmx_type(p^.left^.resulttype) in
  1004. [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1005. CGMessage(type_e_mismatch);
  1006. else
  1007. CGMessage(type_e_mismatch);
  1008. end;
  1009. p^.location.loc:=LOC_MMXREGISTER;
  1010. calcregisters(p,0,0,1);
  1011. convdone:=true;
  1012. end
  1013. else
  1014. {$endif SUPPORT_MMX}
  1015. { this is a little bit dangerous, also the left type }
  1016. { should be checked! This broke the mmx support }
  1017. if (rd^.deftype=pointerdef) or
  1018. is_zero_based_array(rd) then
  1019. begin
  1020. if is_zero_based_array(rd) then
  1021. begin
  1022. p^.resulttype:=new(ppointerdef,init(parraydef(rd)^.elementtype));
  1023. p^.right:=gentypeconvnode(p^.right,p^.resulttype);
  1024. firstpass(p^.right);
  1025. end;
  1026. p^.location.loc:=LOC_REGISTER;
  1027. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1028. firstpass(p^.left);
  1029. calcregisters(p,1,0,0);
  1030. if p^.treetype=addn then
  1031. begin
  1032. if not(cs_extsyntax in aktmoduleswitches) or
  1033. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1034. CGMessage(type_e_mismatch);
  1035. { Dirty hack, to support multiple firstpasses (PFV) }
  1036. if (p^.resulttype=nil) and
  1037. (rd^.deftype=pointerdef) and
  1038. (ppointerdef(rd)^.pointertype.def^.size>1) then
  1039. begin
  1040. p^.left:=gennode(muln,p^.left,genordinalconstnode(ppointerdef(rd)^.pointertype.def^.size,s32bitdef));
  1041. firstpass(p^.left);
  1042. end;
  1043. end
  1044. else
  1045. CGMessage(type_e_mismatch);
  1046. convdone:=true;
  1047. end
  1048. else
  1049. if (ld^.deftype=pointerdef) or
  1050. is_zero_based_array(ld) then
  1051. begin
  1052. if is_zero_based_array(ld) then
  1053. begin
  1054. p^.resulttype:=new(ppointerdef,init(parraydef(ld)^.elementtype));
  1055. p^.left:=gentypeconvnode(p^.left,p^.resulttype);
  1056. firstpass(p^.left);
  1057. end;
  1058. p^.location.loc:=LOC_REGISTER;
  1059. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1060. firstpass(p^.right);
  1061. calcregisters(p,1,0,0);
  1062. case p^.treetype of
  1063. addn,subn : begin
  1064. if not(cs_extsyntax in aktmoduleswitches) or
  1065. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1066. CGMessage(type_e_mismatch);
  1067. { Dirty hack, to support multiple firstpasses (PFV) }
  1068. if (p^.resulttype=nil) and
  1069. (ld^.deftype=pointerdef) and
  1070. (ppointerdef(ld)^.pointertype.def^.size>1) then
  1071. begin
  1072. p^.right:=gennode(muln,p^.right,
  1073. genordinalconstnode(ppointerdef(ld)^.pointertype.def^.size,s32bitdef));
  1074. firstpass(p^.right);
  1075. end;
  1076. end;
  1077. else
  1078. CGMessage(type_e_mismatch);
  1079. end;
  1080. convdone:=true;
  1081. end
  1082. else
  1083. if (rd^.deftype=procvardef) and (ld^.deftype=procvardef) and is_equal(rd,ld) then
  1084. begin
  1085. calcregisters(p,1,0,0);
  1086. p^.location.loc:=LOC_REGISTER;
  1087. case p^.treetype of
  1088. equaln,unequaln : ;
  1089. else
  1090. CGMessage(type_e_mismatch);
  1091. end;
  1092. convdone:=true;
  1093. end
  1094. else
  1095. if (ld^.deftype=enumdef) and (rd^.deftype=enumdef) and (is_equal(ld,rd)) then
  1096. begin
  1097. calcregisters(p,1,0,0);
  1098. case p^.treetype of
  1099. equaln,unequaln,
  1100. ltn,lten,gtn,gten : ;
  1101. else CGMessage(type_e_mismatch);
  1102. end;
  1103. convdone:=true;
  1104. end;
  1105. { the general solution is to convert to 32 bit int }
  1106. if not convdone then
  1107. begin
  1108. { but an int/int gives real/real! }
  1109. if p^.treetype=slashn then
  1110. begin
  1111. CGMessage(type_h_use_div_for_int);
  1112. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  1113. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  1114. firstpass(p^.left);
  1115. firstpass(p^.right);
  1116. { maybe we need an integer register to save }
  1117. { a reference }
  1118. if ((p^.left^.location.loc<>LOC_FPU) or
  1119. (p^.right^.location.loc<>LOC_FPU)) and
  1120. (p^.left^.registers32=p^.right^.registers32) then
  1121. calcregisters(p,1,1,0)
  1122. else
  1123. calcregisters(p,0,1,0);
  1124. p^.location.loc:=LOC_FPU;
  1125. end
  1126. else
  1127. begin
  1128. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1129. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1130. firstpass(p^.left);
  1131. firstpass(p^.right);
  1132. calcregisters(p,1,0,0);
  1133. p^.location.loc:=LOC_REGISTER;
  1134. end;
  1135. end;
  1136. if codegenerror then
  1137. exit;
  1138. { determines result type for comparions }
  1139. { here the is a problem with multiple passes }
  1140. { example length(s)+1 gets internal 'longint' type first }
  1141. { if it is a arg it is converted to 'LONGINT' }
  1142. { but a second first pass will reset this to 'longint' }
  1143. case p^.treetype of
  1144. ltn,lten,gtn,gten,equaln,unequaln:
  1145. begin
  1146. if (not assigned(p^.resulttype)) or
  1147. (p^.resulttype^.deftype=stringdef) then
  1148. p^.resulttype:=booldef;
  1149. if is_64bitint(p^.left^.resulttype) then
  1150. p^.location.loc:=LOC_JUMP
  1151. else
  1152. p^.location.loc:=LOC_FLAGS;
  1153. end;
  1154. xorn:
  1155. begin
  1156. if not assigned(p^.resulttype) then
  1157. p^.resulttype:=p^.left^.resulttype;
  1158. p^.location.loc:=LOC_REGISTER;
  1159. end;
  1160. addn:
  1161. begin
  1162. if not assigned(p^.resulttype) then
  1163. begin
  1164. { for strings, return is always a 255 char string }
  1165. if is_shortstring(p^.left^.resulttype) then
  1166. p^.resulttype:=cshortstringdef
  1167. else
  1168. p^.resulttype:=p^.left^.resulttype;
  1169. end;
  1170. end;
  1171. {$ifdef cardinalmulfix}
  1172. muln:
  1173. { if we multiply an unsigned with a signed number, the result is signed }
  1174. { in the other cases, the result remains signed or unsigned depending on }
  1175. { the multiplication factors (JM) }
  1176. if (p^.left^.resulttype^.deftype = orddef) and
  1177. (p^.right^.resulttype^.deftype = orddef) and
  1178. is_signed(p^.right^.resulttype) then
  1179. p^.resulttype := p^.right^.resulttype
  1180. else p^.resulttype := p^.left^.resulttype;
  1181. (*
  1182. subn:
  1183. { if we substract a u32bit from a positive constant, the result becomes }
  1184. { s32bit as well (JM) }
  1185. begin
  1186. if (p^.right^.resulttype^.deftype = orddef) and
  1187. (p^.left^.resulttype^.deftype = orddef) and
  1188. (porddef(p^.right^.resulttype)^.typ = u32bit) and
  1189. is_constintnode(p^.left) and
  1190. { (porddef(p^.left^.resulttype)^.typ <> u32bit) and}
  1191. (p^.left^.value > 0) then
  1192. begin
  1193. p^.left := gentypeconvnode(p^.left,u32bitdef);
  1194. firstpass(p^.left);
  1195. end;
  1196. p^.resulttype:=p^.left^.resulttype;
  1197. end;
  1198. *)
  1199. {$endif cardinalmulfix}
  1200. else
  1201. p^.resulttype:=p^.left^.resulttype;
  1202. end;
  1203. end;
  1204. end.
  1205. {
  1206. $Log$
  1207. Revision 1.70 2000-02-19 10:12:48 florian
  1208. * fixed one more internalerror 10
  1209. Revision 1.69 2000/02/17 14:53:42 florian
  1210. * some updates for the newcg
  1211. Revision 1.68 2000/02/14 22:34:28 florian
  1212. * fixed another internalerror
  1213. Revision 1.67 2000/02/13 22:46:28 florian
  1214. * fixed an internalerror with writeln
  1215. * fixed arrayconstructor_to_set to force the generation of better code
  1216. and added a more strict type checking
  1217. Revision 1.66 2000/02/13 14:21:51 jonas
  1218. * modifications to make the compiler functional when compiled with
  1219. -Or
  1220. Revision 1.65 2000/02/09 13:23:06 peter
  1221. * log truncated
  1222. Revision 1.64 2000/02/04 08:47:10 florian
  1223. * better register variable allocation in -Or mode
  1224. Revision 1.63 2000/01/07 01:14:43 peter
  1225. * updated copyright to 2000
  1226. Revision 1.62 2000/01/04 20:10:20 florian
  1227. * mmx support fixed
  1228. Revision 1.61 1999/12/11 18:53:31 jonas
  1229. * fixed type conversions of results of operations with cardinals
  1230. (between -dcardinalmulfix)
  1231. Revision 1.60 1999/12/09 23:18:04 pierre
  1232. * no_fast_exit if procedure contains implicit termination code
  1233. Revision 1.59 1999/12/01 12:42:33 peter
  1234. * fixed bug 698
  1235. * removed some notes about unused vars
  1236. Revision 1.58 1999/11/30 10:40:56 peter
  1237. + ttype, tsymlist
  1238. Revision 1.57 1999/11/26 13:51:29 pierre
  1239. * fix for overloading of shr shl mod and div
  1240. Revision 1.56 1999/11/18 15:34:48 pierre
  1241. * Notes/Hints for local syms changed to
  1242. Set_varstate function
  1243. Revision 1.55 1999/11/17 17:05:06 pierre
  1244. * Notes/hints changes
  1245. Revision 1.54 1999/11/16 23:45:28 pierre
  1246. * global var token was changed by overload code (form bug 707)
  1247. Revision 1.53 1999/11/15 21:53:42 peter
  1248. * fixed constant eval for bool xor/or/and bool
  1249. Revision 1.52 1999/11/15 17:53:00 pierre
  1250. + one field added for ttoken record for operator
  1251. linking the id to the corresponding operator token that
  1252. can now now all be overloaded
  1253. * overloaded operators are resetted to nil in InitSymtable
  1254. (bug when trying to compile a uint that overloads operators twice)
  1255. Revision 1.51 1999/11/06 14:34:29 peter
  1256. * truncated log to 20 revs
  1257. Revision 1.50 1999/09/27 23:45:00 peter
  1258. * procinfo is now a pointer
  1259. * support for result setting in sub procedure
  1260. Revision 1.49 1999/09/16 13:39:14 peter
  1261. * arrayconstructor 2 set conversion is now called always in the
  1262. beginning of firstadd
  1263. Revision 1.48 1999/09/15 20:35:45 florian
  1264. * small fix to operator overloading when in MMX mode
  1265. + the compiler uses now fldz and fld1 if possible
  1266. + some fixes to floating point registers
  1267. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  1268. * .... ???
  1269. Revision 1.47 1999/09/13 16:28:05 peter
  1270. * typo in previous commit open_array -> chararray :(
  1271. Revision 1.46 1999/09/10 15:40:46 peter
  1272. * fixed array check for operators, becuase array can also be a set
  1273. Revision 1.45 1999/09/08 16:05:29 peter
  1274. * pointer add/sub is now as expected and the same results as inc/dec
  1275. }