tcadd.pas 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  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. { these one can't be in flags! }
  423. if p^.treetype in [xorn,unequaln,equaln] then
  424. begin
  425. if p^.left^.location.loc=LOC_FLAGS then
  426. begin
  427. p^.left:=gentypeconvnode(p^.left,porddef(p^.left^.resulttype));
  428. p^.left^.convtyp:=tc_bool_2_int;
  429. p^.left^.explizit:=true;
  430. firstpass(p^.left);
  431. end;
  432. if p^.right^.location.loc=LOC_FLAGS then
  433. begin
  434. p^.right:=gentypeconvnode(p^.right,porddef(p^.right^.resulttype));
  435. p^.right^.convtyp:=tc_bool_2_int;
  436. p^.right^.explizit:=true;
  437. firstpass(p^.right);
  438. end;
  439. { readjust registers }
  440. calcregisters(p,1,0,0);
  441. end;
  442. convdone:=true;
  443. end
  444. else
  445. { Both are chars? only convert to shortstrings for addn }
  446. if is_char(rd) and is_char(ld) then
  447. begin
  448. if p^.treetype=addn then
  449. begin
  450. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  451. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  452. firstpass(p^.left);
  453. firstpass(p^.right);
  454. { here we call STRCOPY }
  455. procinfo^.flags:=procinfo^.flags or pi_do_call;
  456. calcregisters(p,0,0,0);
  457. p^.location.loc:=LOC_MEM;
  458. end
  459. else
  460. calcregisters(p,1,0,0);
  461. convdone:=true;
  462. end
  463. { is there a 64 bit type ? }
  464. else if ((porddef(rd)^.typ=s64bit) or (porddef(ld)^.typ=s64bit)) and
  465. { the / operator is handled later }
  466. (p^.treetype<>slashn) then
  467. begin
  468. if (porddef(ld)^.typ<>s64bit) then
  469. begin
  470. p^.left:=gentypeconvnode(p^.left,cs64bitdef);
  471. firstpass(p^.left);
  472. end;
  473. if (porddef(rd)^.typ<>s64bit) then
  474. begin
  475. p^.right:=gentypeconvnode(p^.right,cs64bitdef);
  476. firstpass(p^.right);
  477. end;
  478. calcregisters(p,2,0,0);
  479. convdone:=true;
  480. end
  481. else if ((porddef(rd)^.typ=u64bit) or (porddef(ld)^.typ=u64bit)) and
  482. { the / operator is handled later }
  483. (p^.treetype<>slashn) then
  484. begin
  485. if (porddef(ld)^.typ<>u64bit) then
  486. begin
  487. p^.left:=gentypeconvnode(p^.left,cu64bitdef);
  488. firstpass(p^.left);
  489. end;
  490. if (porddef(rd)^.typ<>u64bit) then
  491. begin
  492. p^.right:=gentypeconvnode(p^.right,cu64bitdef);
  493. firstpass(p^.right);
  494. end;
  495. calcregisters(p,2,0,0);
  496. convdone:=true;
  497. end
  498. else
  499. { is there a cardinal? }
  500. if ((porddef(rd)^.typ=u32bit) or (porddef(ld)^.typ=u32bit)) and
  501. { the / operator is handled later }
  502. (p^.treetype<>slashn) then
  503. begin
  504. { convert constants to u32bit }
  505. {$ifndef cardinalmulfix}
  506. if (porddef(ld)^.typ<>u32bit) then
  507. begin
  508. { s32bit will be used for when the other is also s32bit }
  509. { the following line doesn't make any sense: it's the same as }
  510. { if ((porddef(rd)^.typ=u32bit) or (porddef(ld)^.typ=u32bit)) and }
  511. { (porddef(ld)^.typ<>u32bit) and (porddef(rd)^.typ=s32bit) then }
  512. { which can be simplified to }
  513. { if ((porddef(rd)^.typ=u32bit) and (porddef(rd)^.typ=s32bit) then }
  514. { which can never be true (JM) }
  515. if (porddef(rd)^.typ=s32bit) and (lt<>ordconstn) then
  516. p^.left:=gentypeconvnode(p^.left,s32bitdef)
  517. else
  518. p^.left:=gentypeconvnode(p^.left,u32bitdef);
  519. firstpass(p^.left);
  520. end;
  521. if (porddef(rd)^.typ<>u32bit) then
  522. begin
  523. { s32bit will be used for when the other is also s32bit }
  524. if (porddef(ld)^.typ=s32bit) and (rt<>ordconstn) then
  525. p^.right:=gentypeconvnode(p^.right,s32bitdef)
  526. else
  527. p^.right:=gentypeconvnode(p^.right,u32bitdef);
  528. firstpass(p^.right);
  529. end;
  530. {$else cardinalmulfix}
  531. { only do a conversion if the nodes have different signs }
  532. if (porddef(rd)^.typ=u32bit) xor (porddef(ld)^.typ=u32bit) then
  533. if (porddef(rd)^.typ=u32bit) then
  534. begin
  535. { can we make them both unsigned? }
  536. if is_constintnode(p^.left) and
  537. ((p^.treetype <> subn) and
  538. (p^.left^.value > 0)) then
  539. p^.left:=gentypeconvnode(p^.left,u32bitdef)
  540. else
  541. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  542. firstpass(p^.left);
  543. end
  544. else {if (porddef(ld)^.typ=u32bit) then}
  545. begin
  546. { can we make them both unsigned? }
  547. if is_constintnode(p^.right) and
  548. (p^.right^.value > 0) then
  549. p^.right:=gentypeconvnode(p^.right,u32bitdef)
  550. else
  551. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  552. firstpass(p^.right);
  553. end;
  554. {$endif cardinalmulfix}
  555. calcregisters(p,1,0,0);
  556. { for unsigned mul we need an extra register }
  557. { p^.registers32:=p^.left^.registers32+p^.right^.registers32; }
  558. if p^.treetype=muln then
  559. inc(p^.registers32);
  560. convdone:=true;
  561. end;
  562. end
  563. else
  564. { left side a setdef, must be before string processing,
  565. else array constructor can be seen as array of char (PFV) }
  566. if (ld^.deftype=setdef) {or is_array_constructor(ld)} then
  567. begin
  568. { trying to add a set element? }
  569. if (p^.treetype=addn) and (rd^.deftype<>setdef) then
  570. begin
  571. if (rt=setelementn) then
  572. begin
  573. if not(is_equal(psetdef(ld)^.elementtype.def,rd)) then
  574. CGMessage(type_e_set_element_are_not_comp);
  575. end
  576. else
  577. CGMessage(type_e_mismatch)
  578. end
  579. else
  580. begin
  581. if not(p^.treetype in [addn,subn,symdifn,muln,equaln,unequaln
  582. {$IfNDef NoSetInclusion}
  583. ,lten,gten
  584. {$EndIf NoSetInclusion}
  585. ]) then
  586. CGMessage(type_e_set_operation_unknown);
  587. { right def must be a also be set }
  588. if (rd^.deftype<>setdef) or not(is_equal(rd,ld)) then
  589. CGMessage(type_e_set_element_are_not_comp);
  590. end;
  591. { ranges require normsets }
  592. if (psetdef(ld)^.settype=smallset) and
  593. (rt=setelementn) and
  594. assigned(p^.right^.right) then
  595. begin
  596. { generate a temporary normset def }
  597. tempdef:=new(psetdef,init(psetdef(ld)^.elementtype.def,255));
  598. p^.left:=gentypeconvnode(p^.left,tempdef);
  599. firstpass(p^.left);
  600. dispose(tempdef,done);
  601. ld:=p^.left^.resulttype;
  602. end;
  603. { if the destination is not a smallset then insert a typeconv
  604. which loads a smallset into a normal set }
  605. if (psetdef(ld)^.settype<>smallset) and
  606. (psetdef(rd)^.settype=smallset) then
  607. begin
  608. if (p^.right^.treetype=setconstn) then
  609. begin
  610. t:=gensetconstnode(p^.right^.value_set,psetdef(p^.left^.resulttype));
  611. t^.left:=p^.right^.left;
  612. putnode(p^.right);
  613. p^.right:=t;
  614. end
  615. else
  616. p^.right:=gentypeconvnode(p^.right,psetdef(p^.left^.resulttype));
  617. firstpass(p^.right);
  618. end;
  619. { do constant evaluation }
  620. if (p^.right^.treetype=setconstn) and
  621. not assigned(p^.right^.left) and
  622. (p^.left^.treetype=setconstn) and
  623. not assigned(p^.left^.left) then
  624. begin
  625. new(resultset);
  626. case p^.treetype of
  627. addn : begin
  628. for i:=0 to 31 do
  629. resultset^[i]:=
  630. p^.right^.value_set^[i] or p^.left^.value_set^[i];
  631. t:=gensetconstnode(resultset,psetdef(ld));
  632. end;
  633. muln : begin
  634. for i:=0 to 31 do
  635. resultset^[i]:=
  636. p^.right^.value_set^[i] and p^.left^.value_set^[i];
  637. t:=gensetconstnode(resultset,psetdef(ld));
  638. end;
  639. subn : begin
  640. for i:=0 to 31 do
  641. resultset^[i]:=
  642. p^.left^.value_set^[i] and not(p^.right^.value_set^[i]);
  643. t:=gensetconstnode(resultset,psetdef(ld));
  644. end;
  645. symdifn : begin
  646. for i:=0 to 31 do
  647. resultset^[i]:=
  648. p^.left^.value_set^[i] xor p^.right^.value_set^[i];
  649. t:=gensetconstnode(resultset,psetdef(ld));
  650. end;
  651. unequaln : begin
  652. b:=true;
  653. for i:=0 to 31 do
  654. if p^.right^.value_set^[i]=p^.left^.value_set^[i] then
  655. begin
  656. b:=false;
  657. break;
  658. end;
  659. t:=genordinalconstnode(ord(b),booldef);
  660. end;
  661. equaln : begin
  662. b:=true;
  663. for i:=0 to 31 do
  664. if p^.right^.value_set^[i]<>p^.left^.value_set^[i] then
  665. begin
  666. b:=false;
  667. break;
  668. end;
  669. t:=genordinalconstnode(ord(b),booldef);
  670. end;
  671. {$IfNDef NoSetInclusion}
  672. lten : Begin
  673. b := true;
  674. For i := 0 to 31 Do
  675. If (p^.right^.value_set^[i] And p^.left^.value_set^[i]) <>
  676. p^.left^.value_set^[i] Then
  677. Begin
  678. b := false;
  679. Break
  680. End;
  681. t := genordinalconstnode(ord(b),booldef);
  682. End;
  683. gten : Begin
  684. b := true;
  685. For i := 0 to 31 Do
  686. If (p^.left^.value_set^[i] And p^.right^.value_set^[i]) <>
  687. p^.right^.value_set^[i] Then
  688. Begin
  689. b := false;
  690. Break
  691. End;
  692. t := genordinalconstnode(ord(b),booldef);
  693. End;
  694. {$EndIf NoSetInclusion}
  695. end;
  696. dispose(resultset);
  697. disposetree(p);
  698. p:=t;
  699. firstpass(p);
  700. exit;
  701. end
  702. else
  703. if psetdef(ld)^.settype=smallset then
  704. begin
  705. { are we adding set elements ? }
  706. if p^.right^.treetype=setelementn then
  707. calcregisters(p,2,0,0)
  708. else
  709. calcregisters(p,1,0,0);
  710. p^.location.loc:=LOC_REGISTER;
  711. end
  712. else
  713. begin
  714. calcregisters(p,0,0,0);
  715. { here we call SET... }
  716. procinfo^.flags:=procinfo^.flags or pi_do_call;
  717. p^.location.loc:=LOC_MEM;
  718. end;
  719. convdone:=true;
  720. end
  721. else
  722. { compare pchar to char arrays by addresses
  723. like BP/Delphi }
  724. if (is_pchar(ld) and is_chararray(rd)) or
  725. (is_pchar(rd) and is_chararray(ld)) then
  726. begin
  727. if is_chararray(rd) then
  728. begin
  729. p^.right:=gentypeconvnode(p^.right,ld);
  730. firstpass(p^.right);
  731. end
  732. else
  733. begin
  734. p^.left:=gentypeconvnode(p^.left,rd);
  735. firstpass(p^.left);
  736. end;
  737. p^.location.loc:=LOC_REGISTER;
  738. calcregisters(p,1,0,0);
  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))
  783. {$ifdef newoptimizations2}
  784. {$ifdef i386}
  785. { shortstring + char handled seperately (JM) }
  786. and (not(cs_optimize in aktglobalswitches) or
  787. (p^.treetype <> addn) or not(is_char(rd)))
  788. {$endif i386}
  789. {$endif newoptimizations2}
  790. then
  791. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  792. if not(is_shortstring(ld)) then
  793. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  794. p^.resulttype:=cshortstringdef;
  795. { this is only for add, the comparisaion is handled later }
  796. p^.location.loc:=LOC_MEM;
  797. end;
  798. { only if there is a type cast we need to do again }
  799. { the first pass }
  800. if p^.left^.treetype=typeconvn then
  801. firstpass(p^.left);
  802. if p^.right^.treetype=typeconvn then
  803. firstpass(p^.right);
  804. { here we call STRCONCAT or STRCMP or STRCOPY }
  805. procinfo^.flags:=procinfo^.flags or pi_do_call;
  806. if p^.location.loc=LOC_MEM then
  807. calcregisters(p,0,0,0)
  808. else
  809. calcregisters(p,1,0,0);
  810. {$ifdef newoptimizations}
  811. {$ifdef i386}
  812. { not always necessary, only if it is not a constant char and }
  813. { not a regvar, but don't know how to check this here (JM) }
  814. if is_char(rd) then
  815. inc(p^.registers32);
  816. {$endif i386}
  817. {$endif newoptimizations}
  818. convdone:=true;
  819. end
  820. else
  821. { is one a real float ? }
  822. if (rd^.deftype=floatdef) or (ld^.deftype=floatdef) then
  823. begin
  824. { if one is a fixed, then convert to f32bit }
  825. if ((rd^.deftype=floatdef) and (pfloatdef(rd)^.typ=f32bit)) or
  826. ((ld^.deftype=floatdef) and (pfloatdef(ld)^.typ=f32bit)) then
  827. begin
  828. if not is_integer(rd) or (p^.treetype<>muln) then
  829. p^.right:=gentypeconvnode(p^.right,s32fixeddef);
  830. if not is_integer(ld) or (p^.treetype<>muln) then
  831. p^.left:=gentypeconvnode(p^.left,s32fixeddef);
  832. firstpass(p^.left);
  833. firstpass(p^.right);
  834. calcregisters(p,1,0,0);
  835. p^.location.loc:=LOC_REGISTER;
  836. end
  837. else
  838. { convert both to bestreal }
  839. begin
  840. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  841. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  842. firstpass(p^.left);
  843. firstpass(p^.right);
  844. calcregisters(p,0,1,0);
  845. p^.location.loc:=LOC_FPU;
  846. end;
  847. convdone:=true;
  848. end
  849. else
  850. { pointer comperation and subtraction }
  851. if (rd^.deftype=pointerdef) and (ld^.deftype=pointerdef) then
  852. begin
  853. p^.location.loc:=LOC_REGISTER;
  854. { p^.right:=gentypeconvnode(p^.right,ld); }
  855. { firstpass(p^.right); }
  856. calcregisters(p,1,0,0);
  857. case p^.treetype of
  858. equaln,unequaln :
  859. begin
  860. if is_equal(p^.right^.resulttype,voidpointerdef) then
  861. begin
  862. p^.right:=gentypeconvnode(p^.right,ld);
  863. firstpass(p^.right);
  864. end
  865. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  866. begin
  867. p^.left:=gentypeconvnode(p^.left,rd);
  868. firstpass(p^.left);
  869. end
  870. else if not(is_equal(ld,rd)) then
  871. CGMessage(type_e_mismatch);
  872. end;
  873. ltn,lten,gtn,gten:
  874. begin
  875. if is_equal(p^.right^.resulttype,voidpointerdef) then
  876. begin
  877. p^.right:=gentypeconvnode(p^.right,ld);
  878. firstpass(p^.right);
  879. end
  880. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  881. begin
  882. p^.left:=gentypeconvnode(p^.left,rd);
  883. firstpass(p^.left);
  884. end
  885. else if not(is_equal(ld,rd)) then
  886. CGMessage(type_e_mismatch);
  887. if not(cs_extsyntax in aktmoduleswitches) then
  888. CGMessage(type_e_mismatch);
  889. end;
  890. subn:
  891. begin
  892. if not(is_equal(ld,rd)) then
  893. CGMessage(type_e_mismatch);
  894. if not(cs_extsyntax in aktmoduleswitches) then
  895. CGMessage(type_e_mismatch);
  896. p^.resulttype:=s32bitdef;
  897. exit;
  898. end;
  899. else CGMessage(type_e_mismatch);
  900. end;
  901. convdone:=true;
  902. end
  903. else
  904. if (rd^.deftype=objectdef) and (ld^.deftype=objectdef) and
  905. pobjectdef(rd)^.is_class and pobjectdef(ld)^.is_class then
  906. begin
  907. p^.location.loc:=LOC_REGISTER;
  908. if pobjectdef(rd)^.is_related(pobjectdef(ld)) then
  909. p^.right:=gentypeconvnode(p^.right,ld)
  910. else
  911. p^.left:=gentypeconvnode(p^.left,rd);
  912. firstpass(p^.right);
  913. firstpass(p^.left);
  914. calcregisters(p,1,0,0);
  915. case p^.treetype of
  916. equaln,unequaln : ;
  917. else CGMessage(type_e_mismatch);
  918. end;
  919. convdone:=true;
  920. end
  921. else
  922. if (rd^.deftype=classrefdef) and (ld^.deftype=classrefdef) then
  923. begin
  924. p^.location.loc:=LOC_REGISTER;
  925. if pobjectdef(pclassrefdef(rd)^.pointertype.def)^.is_related(pobjectdef(
  926. pclassrefdef(ld)^.pointertype.def)) then
  927. p^.right:=gentypeconvnode(p^.right,ld)
  928. else
  929. p^.left:=gentypeconvnode(p^.left,rd);
  930. firstpass(p^.right);
  931. firstpass(p^.left);
  932. calcregisters(p,1,0,0);
  933. case p^.treetype of
  934. equaln,unequaln : ;
  935. else CGMessage(type_e_mismatch);
  936. end;
  937. convdone:=true;
  938. end
  939. else
  940. { allows comperasion with nil pointer }
  941. if (rd^.deftype=objectdef) and
  942. pobjectdef(rd)^.is_class then
  943. begin
  944. p^.location.loc:=LOC_REGISTER;
  945. p^.left:=gentypeconvnode(p^.left,rd);
  946. firstpass(p^.left);
  947. calcregisters(p,1,0,0);
  948. case p^.treetype of
  949. equaln,unequaln : ;
  950. else CGMessage(type_e_mismatch);
  951. end;
  952. convdone:=true;
  953. end
  954. else
  955. if (ld^.deftype=objectdef) and
  956. pobjectdef(ld)^.is_class then
  957. begin
  958. p^.location.loc:=LOC_REGISTER;
  959. p^.right:=gentypeconvnode(p^.right,ld);
  960. firstpass(p^.right);
  961. calcregisters(p,1,0,0);
  962. case p^.treetype of
  963. equaln,unequaln : ;
  964. else CGMessage(type_e_mismatch);
  965. end;
  966. convdone:=true;
  967. end
  968. else
  969. if (rd^.deftype=classrefdef) then
  970. begin
  971. p^.left:=gentypeconvnode(p^.left,rd);
  972. firstpass(p^.left);
  973. calcregisters(p,1,0,0);
  974. case p^.treetype of
  975. equaln,unequaln : ;
  976. else CGMessage(type_e_mismatch);
  977. end;
  978. convdone:=true;
  979. end
  980. else
  981. if (ld^.deftype=classrefdef) then
  982. begin
  983. p^.right:=gentypeconvnode(p^.right,ld);
  984. firstpass(p^.right);
  985. calcregisters(p,1,0,0);
  986. case p^.treetype of
  987. equaln,unequaln : ;
  988. else
  989. CGMessage(type_e_mismatch);
  990. end;
  991. convdone:=true;
  992. end
  993. else
  994. { support procvar=nil,procvar<>nil }
  995. if ((ld^.deftype=procvardef) and (rt=niln)) or
  996. ((rd^.deftype=procvardef) and (lt=niln)) then
  997. begin
  998. calcregisters(p,1,0,0);
  999. p^.location.loc:=LOC_REGISTER;
  1000. case p^.treetype of
  1001. equaln,unequaln : ;
  1002. else
  1003. CGMessage(type_e_mismatch);
  1004. end;
  1005. convdone:=true;
  1006. end
  1007. else
  1008. {$ifdef SUPPORT_MMX}
  1009. if (cs_mmx in aktlocalswitches) and is_mmx_able_array(ld) and
  1010. is_mmx_able_array(rd) and is_equal(ld,rd) then
  1011. begin
  1012. firstpass(p^.right);
  1013. firstpass(p^.left);
  1014. case p^.treetype of
  1015. addn,subn,xorn,orn,andn:
  1016. ;
  1017. { mul is a little bit restricted }
  1018. muln:
  1019. if not(mmx_type(p^.left^.resulttype) in
  1020. [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1021. CGMessage(type_e_mismatch);
  1022. else
  1023. CGMessage(type_e_mismatch);
  1024. end;
  1025. p^.location.loc:=LOC_MMXREGISTER;
  1026. calcregisters(p,0,0,1);
  1027. convdone:=true;
  1028. end
  1029. else
  1030. {$endif SUPPORT_MMX}
  1031. { this is a little bit dangerous, also the left type }
  1032. { should be checked! This broke the mmx support }
  1033. if (rd^.deftype=pointerdef) or
  1034. is_zero_based_array(rd) then
  1035. begin
  1036. if is_zero_based_array(rd) then
  1037. begin
  1038. p^.resulttype:=new(ppointerdef,init(parraydef(rd)^.elementtype));
  1039. p^.right:=gentypeconvnode(p^.right,p^.resulttype);
  1040. firstpass(p^.right);
  1041. end;
  1042. p^.location.loc:=LOC_REGISTER;
  1043. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1044. firstpass(p^.left);
  1045. calcregisters(p,1,0,0);
  1046. if p^.treetype=addn then
  1047. begin
  1048. if not(cs_extsyntax in aktmoduleswitches) or
  1049. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1050. CGMessage(type_e_mismatch);
  1051. { Dirty hack, to support multiple firstpasses (PFV) }
  1052. if (p^.resulttype=nil) and
  1053. (rd^.deftype=pointerdef) and
  1054. (ppointerdef(rd)^.pointertype.def^.size>1) then
  1055. begin
  1056. p^.left:=gennode(muln,p^.left,genordinalconstnode(ppointerdef(rd)^.pointertype.def^.size,s32bitdef));
  1057. firstpass(p^.left);
  1058. end;
  1059. end
  1060. else
  1061. CGMessage(type_e_mismatch);
  1062. convdone:=true;
  1063. end
  1064. else
  1065. if (ld^.deftype=pointerdef) or
  1066. is_zero_based_array(ld) then
  1067. begin
  1068. if is_zero_based_array(ld) then
  1069. begin
  1070. p^.resulttype:=new(ppointerdef,init(parraydef(ld)^.elementtype));
  1071. p^.left:=gentypeconvnode(p^.left,p^.resulttype);
  1072. firstpass(p^.left);
  1073. end;
  1074. p^.location.loc:=LOC_REGISTER;
  1075. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1076. firstpass(p^.right);
  1077. calcregisters(p,1,0,0);
  1078. case p^.treetype of
  1079. addn,subn : begin
  1080. if not(cs_extsyntax in aktmoduleswitches) or
  1081. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1082. CGMessage(type_e_mismatch);
  1083. { Dirty hack, to support multiple firstpasses (PFV) }
  1084. if (p^.resulttype=nil) and
  1085. (ld^.deftype=pointerdef) and
  1086. (ppointerdef(ld)^.pointertype.def^.size>1) then
  1087. begin
  1088. p^.right:=gennode(muln,p^.right,
  1089. genordinalconstnode(ppointerdef(ld)^.pointertype.def^.size,s32bitdef));
  1090. firstpass(p^.right);
  1091. end;
  1092. end;
  1093. else
  1094. CGMessage(type_e_mismatch);
  1095. end;
  1096. convdone:=true;
  1097. end
  1098. else
  1099. if (rd^.deftype=procvardef) and (ld^.deftype=procvardef) and is_equal(rd,ld) then
  1100. begin
  1101. calcregisters(p,1,0,0);
  1102. p^.location.loc:=LOC_REGISTER;
  1103. case p^.treetype of
  1104. equaln,unequaln : ;
  1105. else
  1106. CGMessage(type_e_mismatch);
  1107. end;
  1108. convdone:=true;
  1109. end
  1110. else
  1111. if (ld^.deftype=enumdef) and (rd^.deftype=enumdef) then
  1112. begin
  1113. if not(is_equal(ld,rd)) then
  1114. begin
  1115. p^.right:=gentypeconvnode(p^.right,ld);
  1116. firstpass(p^.right);
  1117. end;
  1118. calcregisters(p,1,0,0);
  1119. case p^.treetype of
  1120. equaln,unequaln,
  1121. ltn,lten,gtn,gten : ;
  1122. else CGMessage(type_e_mismatch);
  1123. end;
  1124. convdone:=true;
  1125. end;
  1126. { the general solution is to convert to 32 bit int }
  1127. if not convdone then
  1128. begin
  1129. { but an int/int gives real/real! }
  1130. if p^.treetype=slashn then
  1131. begin
  1132. CGMessage(type_h_use_div_for_int);
  1133. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  1134. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  1135. firstpass(p^.left);
  1136. firstpass(p^.right);
  1137. { maybe we need an integer register to save }
  1138. { a reference }
  1139. if ((p^.left^.location.loc<>LOC_FPU) or
  1140. (p^.right^.location.loc<>LOC_FPU)) and
  1141. (p^.left^.registers32=p^.right^.registers32) then
  1142. calcregisters(p,1,1,0)
  1143. else
  1144. calcregisters(p,0,1,0);
  1145. p^.location.loc:=LOC_FPU;
  1146. end
  1147. else
  1148. begin
  1149. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1150. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1151. firstpass(p^.left);
  1152. firstpass(p^.right);
  1153. calcregisters(p,1,0,0);
  1154. p^.location.loc:=LOC_REGISTER;
  1155. end;
  1156. end;
  1157. if codegenerror then
  1158. exit;
  1159. { determines result type for comparions }
  1160. { here the is a problem with multiple passes }
  1161. { example length(s)+1 gets internal 'longint' type first }
  1162. { if it is a arg it is converted to 'LONGINT' }
  1163. { but a second first pass will reset this to 'longint' }
  1164. case p^.treetype of
  1165. ltn,lten,gtn,gten,equaln,unequaln:
  1166. begin
  1167. if (not assigned(p^.resulttype)) or
  1168. (p^.resulttype^.deftype=stringdef) then
  1169. p^.resulttype:=booldef;
  1170. if is_64bitint(p^.left^.resulttype) then
  1171. p^.location.loc:=LOC_JUMP
  1172. else
  1173. p^.location.loc:=LOC_FLAGS;
  1174. end;
  1175. xorn:
  1176. begin
  1177. if not assigned(p^.resulttype) then
  1178. p^.resulttype:=p^.left^.resulttype;
  1179. p^.location.loc:=LOC_REGISTER;
  1180. end;
  1181. addn:
  1182. begin
  1183. if not assigned(p^.resulttype) then
  1184. begin
  1185. { for strings, return is always a 255 char string }
  1186. if is_shortstring(p^.left^.resulttype) then
  1187. p^.resulttype:=cshortstringdef
  1188. else
  1189. p^.resulttype:=p^.left^.resulttype;
  1190. end;
  1191. end;
  1192. {$ifdef cardinalmulfix}
  1193. muln:
  1194. { if we multiply an unsigned with a signed number, the result is signed }
  1195. { in the other cases, the result remains signed or unsigned depending on }
  1196. { the multiplication factors (JM) }
  1197. if (p^.left^.resulttype^.deftype = orddef) and
  1198. (p^.right^.resulttype^.deftype = orddef) and
  1199. is_signed(p^.right^.resulttype) then
  1200. p^.resulttype := p^.right^.resulttype
  1201. else p^.resulttype := p^.left^.resulttype;
  1202. (*
  1203. subn:
  1204. { if we substract a u32bit from a positive constant, the result becomes }
  1205. { s32bit as well (JM) }
  1206. begin
  1207. if (p^.right^.resulttype^.deftype = orddef) and
  1208. (p^.left^.resulttype^.deftype = orddef) and
  1209. (porddef(p^.right^.resulttype)^.typ = u32bit) and
  1210. is_constintnode(p^.left) and
  1211. { (porddef(p^.left^.resulttype)^.typ <> u32bit) and}
  1212. (p^.left^.value > 0) then
  1213. begin
  1214. p^.left := gentypeconvnode(p^.left,u32bitdef);
  1215. firstpass(p^.left);
  1216. end;
  1217. p^.resulttype:=p^.left^.resulttype;
  1218. end;
  1219. *)
  1220. {$endif cardinalmulfix}
  1221. else
  1222. p^.resulttype:=p^.left^.resulttype;
  1223. end;
  1224. end;
  1225. end.
  1226. {
  1227. $Log$
  1228. Revision 1.2 2000-07-13 11:32:50 michael
  1229. + removed logs
  1230. }