tcadd.pas 51 KB

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