tcadd.pas 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  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. {$ifdef fpc}
  145. {$maxfpuregisters 0}
  146. {$endif fpc}
  147. procedure firstadd(var p : ptree);
  148. procedure make_bool_equal_size(var p:ptree);
  149. begin
  150. if porddef(p^.left^.resulttype)^.typ>porddef(p^.right^.resulttype)^.typ then
  151. begin
  152. p^.right:=gentypeconvnode(p^.right,porddef(p^.left^.resulttype));
  153. p^.right^.convtyp:=tc_bool_2_int;
  154. p^.right^.explizit:=true;
  155. firstpass(p^.right);
  156. end
  157. else
  158. if porddef(p^.left^.resulttype)^.typ<porddef(p^.right^.resulttype)^.typ then
  159. begin
  160. p^.left:=gentypeconvnode(p^.left,porddef(p^.right^.resulttype));
  161. p^.left^.convtyp:=tc_bool_2_int;
  162. p^.left^.explizit:=true;
  163. firstpass(p^.left);
  164. end;
  165. end;
  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)) and
  491. { the / operator is handled later }
  492. (p^.treetype<>slashn) then
  493. begin
  494. if (porddef(ld)^.typ<>s64bit) then
  495. begin
  496. p^.left:=gentypeconvnode(p^.left,cs64bitdef);
  497. firstpass(p^.left);
  498. end;
  499. if (porddef(rd)^.typ<>s64bit) then
  500. begin
  501. p^.right:=gentypeconvnode(p^.right,cs64bitdef);
  502. firstpass(p^.right);
  503. end;
  504. calcregisters(p,2,0,0);
  505. convdone:=true;
  506. end
  507. else if ((porddef(rd)^.typ=u64bit) or (porddef(ld)^.typ=u64bit)) and
  508. { the / operator is handled later }
  509. (p^.treetype<>slashn) then
  510. begin
  511. if (porddef(ld)^.typ<>u64bit) then
  512. begin
  513. p^.left:=gentypeconvnode(p^.left,cu64bitdef);
  514. firstpass(p^.left);
  515. end;
  516. if (porddef(rd)^.typ<>u64bit) then
  517. begin
  518. p^.right:=gentypeconvnode(p^.right,cu64bitdef);
  519. firstpass(p^.right);
  520. end;
  521. calcregisters(p,2,0,0);
  522. convdone:=true;
  523. end
  524. else
  525. { is there a cardinal? }
  526. if ((porddef(rd)^.typ=u32bit) or (porddef(ld)^.typ=u32bit)) and
  527. { the / operator is handled later }
  528. (p^.treetype<>slashn) then
  529. begin
  530. { convert constants to u32bit }
  531. {$ifndef cardinalmulfix}
  532. if (porddef(ld)^.typ<>u32bit) then
  533. begin
  534. { s32bit will be used for when the other is also s32bit }
  535. { the following line doesn't make any sense: it's the same as }
  536. { if ((porddef(rd)^.typ=u32bit) or (porddef(ld)^.typ=u32bit)) and }
  537. { (porddef(ld)^.typ<>u32bit) and (porddef(rd)^.typ=s32bit) then }
  538. { which can be simplified to }
  539. { if ((porddef(rd)^.typ=u32bit) and (porddef(rd)^.typ=s32bit) then }
  540. { which can never be true (JM) }
  541. if (porddef(rd)^.typ=s32bit) and (lt<>ordconstn) then
  542. p^.left:=gentypeconvnode(p^.left,s32bitdef)
  543. else
  544. p^.left:=gentypeconvnode(p^.left,u32bitdef);
  545. firstpass(p^.left);
  546. end;
  547. if (porddef(rd)^.typ<>u32bit) then
  548. begin
  549. { s32bit will be used for when the other is also s32bit }
  550. if (porddef(ld)^.typ=s32bit) and (rt<>ordconstn) then
  551. p^.right:=gentypeconvnode(p^.right,s32bitdef)
  552. else
  553. p^.right:=gentypeconvnode(p^.right,u32bitdef);
  554. firstpass(p^.right);
  555. end;
  556. {$else cardinalmulfix}
  557. { only do a conversion if the nodes have different signs }
  558. if (porddef(rd)^.typ=u32bit) xor (porddef(ld)^.typ=u32bit) then
  559. if (porddef(rd)^.typ=u32bit) then
  560. begin
  561. { can we make them both unsigned? }
  562. if is_constintnode(p^.left) and
  563. ((p^.treetype <> subn) and
  564. (p^.left^.value > 0)) then
  565. p^.left:=gentypeconvnode(p^.left,u32bitdef)
  566. else
  567. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  568. firstpass(p^.left);
  569. end
  570. else {if (porddef(ld)^.typ=u32bit) then}
  571. begin
  572. { can we make them both unsigned? }
  573. if is_constintnode(p^.right) and
  574. (p^.right^.value > 0) then
  575. p^.right:=gentypeconvnode(p^.right,u32bitdef)
  576. else
  577. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  578. firstpass(p^.right);
  579. end;
  580. {$endif cardinalmulfix}
  581. calcregisters(p,1,0,0);
  582. { for unsigned mul we need an extra register }
  583. { p^.registers32:=p^.left^.registers32+p^.right^.registers32; }
  584. if p^.treetype=muln then
  585. inc(p^.registers32);
  586. convdone:=true;
  587. end;
  588. end
  589. else
  590. { left side a setdef, must be before string processing,
  591. else array constructor can be seen as array of char (PFV) }
  592. if (ld^.deftype=setdef) {or is_array_constructor(ld)} then
  593. begin
  594. { trying to add a set element? }
  595. if (p^.treetype=addn) and (rd^.deftype<>setdef) then
  596. begin
  597. if (rt=setelementn) then
  598. begin
  599. if not(is_equal(psetdef(ld)^.elementtype.def,rd)) then
  600. CGMessage(type_e_set_element_are_not_comp);
  601. end
  602. else
  603. CGMessage(type_e_mismatch)
  604. end
  605. else
  606. begin
  607. if not(p^.treetype in [addn,subn,symdifn,muln,equaln,unequaln
  608. {$IfNDef NoSetInclusion}
  609. ,lten,gten
  610. {$EndIf NoSetInclusion}
  611. ]) then
  612. CGMessage(type_e_set_operation_unknown);
  613. { right def must be a also be set }
  614. if (rd^.deftype<>setdef) or not(is_equal(rd,ld)) then
  615. CGMessage(type_e_set_element_are_not_comp);
  616. end;
  617. { ranges require normsets }
  618. if (psetdef(ld)^.settype=smallset) and
  619. (rt=setelementn) and
  620. assigned(p^.right^.right) then
  621. begin
  622. { generate a temporary normset def }
  623. tempdef:=new(psetdef,init(psetdef(ld)^.elementtype.def,255));
  624. p^.left:=gentypeconvnode(p^.left,tempdef);
  625. firstpass(p^.left);
  626. dispose(tempdef,done);
  627. ld:=p^.left^.resulttype;
  628. end;
  629. { if the destination is not a smallset then insert a typeconv
  630. which loads a smallset into a normal set }
  631. if (psetdef(ld)^.settype<>smallset) and
  632. (psetdef(rd)^.settype=smallset) then
  633. begin
  634. if (p^.right^.treetype=setconstn) then
  635. begin
  636. t:=gensetconstnode(p^.right^.value_set,psetdef(p^.left^.resulttype));
  637. t^.left:=p^.right^.left;
  638. putnode(p^.right);
  639. p^.right:=t;
  640. end
  641. else
  642. p^.right:=gentypeconvnode(p^.right,psetdef(p^.left^.resulttype));
  643. firstpass(p^.right);
  644. end;
  645. { do constant evaluation }
  646. if (p^.right^.treetype=setconstn) and
  647. not assigned(p^.right^.left) and
  648. (p^.left^.treetype=setconstn) and
  649. not assigned(p^.left^.left) then
  650. begin
  651. new(resultset);
  652. case p^.treetype of
  653. addn : begin
  654. for i:=0 to 31 do
  655. resultset^[i]:=
  656. p^.right^.value_set^[i] or p^.left^.value_set^[i];
  657. t:=gensetconstnode(resultset,psetdef(ld));
  658. end;
  659. muln : begin
  660. for i:=0 to 31 do
  661. resultset^[i]:=
  662. p^.right^.value_set^[i] and p^.left^.value_set^[i];
  663. t:=gensetconstnode(resultset,psetdef(ld));
  664. end;
  665. subn : begin
  666. for i:=0 to 31 do
  667. resultset^[i]:=
  668. p^.left^.value_set^[i] and not(p^.right^.value_set^[i]);
  669. t:=gensetconstnode(resultset,psetdef(ld));
  670. end;
  671. symdifn : begin
  672. for i:=0 to 31 do
  673. resultset^[i]:=
  674. p^.left^.value_set^[i] xor p^.right^.value_set^[i];
  675. t:=gensetconstnode(resultset,psetdef(ld));
  676. end;
  677. unequaln : begin
  678. b:=true;
  679. for i:=0 to 31 do
  680. if p^.right^.value_set^[i]=p^.left^.value_set^[i] then
  681. begin
  682. b:=false;
  683. break;
  684. end;
  685. t:=genordinalconstnode(ord(b),booldef);
  686. end;
  687. equaln : begin
  688. b:=true;
  689. for i:=0 to 31 do
  690. if p^.right^.value_set^[i]<>p^.left^.value_set^[i] then
  691. begin
  692. b:=false;
  693. break;
  694. end;
  695. t:=genordinalconstnode(ord(b),booldef);
  696. end;
  697. {$IfNDef NoSetInclusion}
  698. lten : Begin
  699. b := true;
  700. For i := 0 to 31 Do
  701. If (p^.right^.value_set^[i] And p^.left^.value_set^[i]) <>
  702. p^.left^.value_set^[i] Then
  703. Begin
  704. b := false;
  705. Break
  706. End;
  707. t := genordinalconstnode(ord(b),booldef);
  708. End;
  709. gten : Begin
  710. b := true;
  711. For i := 0 to 31 Do
  712. If (p^.left^.value_set^[i] And p^.right^.value_set^[i]) <>
  713. p^.right^.value_set^[i] Then
  714. Begin
  715. b := false;
  716. Break
  717. End;
  718. t := genordinalconstnode(ord(b),booldef);
  719. End;
  720. {$EndIf NoSetInclusion}
  721. end;
  722. dispose(resultset);
  723. disposetree(p);
  724. p:=t;
  725. firstpass(p);
  726. exit;
  727. end
  728. else
  729. if psetdef(ld)^.settype=smallset then
  730. begin
  731. { are we adding set elements ? }
  732. if p^.right^.treetype=setelementn then
  733. calcregisters(p,2,0,0)
  734. else
  735. calcregisters(p,1,0,0);
  736. p^.location.loc:=LOC_REGISTER;
  737. end
  738. else
  739. begin
  740. calcregisters(p,0,0,0);
  741. { here we call SET... }
  742. procinfo^.flags:=procinfo^.flags or pi_do_call;
  743. p^.location.loc:=LOC_MEM;
  744. end;
  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)) then
  789. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  790. if not(is_shortstring(ld)) then
  791. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  792. p^.resulttype:=cshortstringdef;
  793. { this is only for add, the comparisaion is handled later }
  794. p^.location.loc:=LOC_MEM;
  795. end;
  796. { only if there is a type cast we need to do again }
  797. { the first pass }
  798. if p^.left^.treetype=typeconvn then
  799. firstpass(p^.left);
  800. if p^.right^.treetype=typeconvn then
  801. firstpass(p^.right);
  802. { here we call STRCONCAT or STRCMP or STRCOPY }
  803. procinfo^.flags:=procinfo^.flags or pi_do_call;
  804. if p^.location.loc=LOC_MEM then
  805. calcregisters(p,0,0,0)
  806. else
  807. calcregisters(p,1,0,0);
  808. convdone:=true;
  809. end
  810. else
  811. { is one a real float ? }
  812. if (rd^.deftype=floatdef) or (ld^.deftype=floatdef) then
  813. begin
  814. { if one is a fixed, then convert to f32bit }
  815. if ((rd^.deftype=floatdef) and (pfloatdef(rd)^.typ=f32bit)) or
  816. ((ld^.deftype=floatdef) and (pfloatdef(ld)^.typ=f32bit)) then
  817. begin
  818. if not is_integer(rd) or (p^.treetype<>muln) then
  819. p^.right:=gentypeconvnode(p^.right,s32fixeddef);
  820. if not is_integer(ld) or (p^.treetype<>muln) then
  821. p^.left:=gentypeconvnode(p^.left,s32fixeddef);
  822. firstpass(p^.left);
  823. firstpass(p^.right);
  824. calcregisters(p,1,0,0);
  825. p^.location.loc:=LOC_REGISTER;
  826. end
  827. else
  828. { convert both to bestreal }
  829. begin
  830. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  831. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  832. firstpass(p^.left);
  833. firstpass(p^.right);
  834. calcregisters(p,0,1,0);
  835. p^.location.loc:=LOC_FPU;
  836. end;
  837. convdone:=true;
  838. end
  839. else
  840. { pointer comperation and subtraction }
  841. if (rd^.deftype=pointerdef) and (ld^.deftype=pointerdef) then
  842. begin
  843. p^.location.loc:=LOC_REGISTER;
  844. { p^.right:=gentypeconvnode(p^.right,ld); }
  845. { firstpass(p^.right); }
  846. calcregisters(p,1,0,0);
  847. case p^.treetype of
  848. equaln,unequaln :
  849. begin
  850. if is_equal(p^.right^.resulttype,voidpointerdef) then
  851. begin
  852. p^.right:=gentypeconvnode(p^.right,ld);
  853. firstpass(p^.right);
  854. end
  855. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  856. begin
  857. p^.left:=gentypeconvnode(p^.left,rd);
  858. firstpass(p^.left);
  859. end
  860. else if not(is_equal(ld,rd)) then
  861. CGMessage(type_e_mismatch);
  862. end;
  863. ltn,lten,gtn,gten:
  864. begin
  865. if is_equal(p^.right^.resulttype,voidpointerdef) then
  866. begin
  867. p^.right:=gentypeconvnode(p^.right,ld);
  868. firstpass(p^.right);
  869. end
  870. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  871. begin
  872. p^.left:=gentypeconvnode(p^.left,rd);
  873. firstpass(p^.left);
  874. end
  875. else if not(is_equal(ld,rd)) then
  876. CGMessage(type_e_mismatch);
  877. if not(cs_extsyntax in aktmoduleswitches) then
  878. CGMessage(type_e_mismatch);
  879. end;
  880. subn:
  881. begin
  882. if not(is_equal(ld,rd)) then
  883. CGMessage(type_e_mismatch);
  884. if not(cs_extsyntax in aktmoduleswitches) then
  885. CGMessage(type_e_mismatch);
  886. p^.resulttype:=s32bitdef;
  887. exit;
  888. end;
  889. else CGMessage(type_e_mismatch);
  890. end;
  891. convdone:=true;
  892. end
  893. else
  894. if (rd^.deftype=objectdef) and (ld^.deftype=objectdef) and
  895. pobjectdef(rd)^.is_class and pobjectdef(ld)^.is_class then
  896. begin
  897. p^.location.loc:=LOC_REGISTER;
  898. if pobjectdef(rd)^.is_related(pobjectdef(ld)) then
  899. p^.right:=gentypeconvnode(p^.right,ld)
  900. else
  901. p^.left:=gentypeconvnode(p^.left,rd);
  902. firstpass(p^.right);
  903. firstpass(p^.left);
  904. calcregisters(p,1,0,0);
  905. case p^.treetype of
  906. equaln,unequaln : ;
  907. else CGMessage(type_e_mismatch);
  908. end;
  909. convdone:=true;
  910. end
  911. else
  912. if (rd^.deftype=classrefdef) and (ld^.deftype=classrefdef) then
  913. begin
  914. p^.location.loc:=LOC_REGISTER;
  915. if pobjectdef(pclassrefdef(rd)^.pointertype.def)^.is_related(pobjectdef(
  916. pclassrefdef(ld)^.pointertype.def)) then
  917. p^.right:=gentypeconvnode(p^.right,ld)
  918. else
  919. p^.left:=gentypeconvnode(p^.left,rd);
  920. firstpass(p^.right);
  921. firstpass(p^.left);
  922. calcregisters(p,1,0,0);
  923. case p^.treetype of
  924. equaln,unequaln : ;
  925. else CGMessage(type_e_mismatch);
  926. end;
  927. convdone:=true;
  928. end
  929. else
  930. { allows comperasion with nil pointer }
  931. if (rd^.deftype=objectdef) and
  932. pobjectdef(rd)^.is_class then
  933. begin
  934. p^.location.loc:=LOC_REGISTER;
  935. p^.left:=gentypeconvnode(p^.left,rd);
  936. firstpass(p^.left);
  937. calcregisters(p,1,0,0);
  938. case p^.treetype of
  939. equaln,unequaln : ;
  940. else CGMessage(type_e_mismatch);
  941. end;
  942. convdone:=true;
  943. end
  944. else
  945. if (ld^.deftype=objectdef) and
  946. pobjectdef(ld)^.is_class then
  947. begin
  948. p^.location.loc:=LOC_REGISTER;
  949. p^.right:=gentypeconvnode(p^.right,ld);
  950. firstpass(p^.right);
  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 (rd^.deftype=classrefdef) then
  960. begin
  961. p^.left:=gentypeconvnode(p^.left,rd);
  962. firstpass(p^.left);
  963. calcregisters(p,1,0,0);
  964. case p^.treetype of
  965. equaln,unequaln : ;
  966. else CGMessage(type_e_mismatch);
  967. end;
  968. convdone:=true;
  969. end
  970. else
  971. if (ld^.deftype=classrefdef) then
  972. begin
  973. p^.right:=gentypeconvnode(p^.right,ld);
  974. firstpass(p^.right);
  975. calcregisters(p,1,0,0);
  976. case p^.treetype of
  977. equaln,unequaln : ;
  978. else
  979. CGMessage(type_e_mismatch);
  980. end;
  981. convdone:=true;
  982. end
  983. else
  984. { support procvar=nil,procvar<>nil }
  985. if ((ld^.deftype=procvardef) and (rt=niln)) or
  986. ((rd^.deftype=procvardef) and (lt=niln)) then
  987. begin
  988. calcregisters(p,1,0,0);
  989. p^.location.loc:=LOC_REGISTER;
  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. {$ifdef SUPPORT_MMX}
  999. if (cs_mmx in aktlocalswitches) and is_mmx_able_array(ld) and
  1000. is_mmx_able_array(rd) and is_equal(ld,rd) then
  1001. begin
  1002. firstpass(p^.right);
  1003. firstpass(p^.left);
  1004. case p^.treetype of
  1005. addn,subn,xorn,orn,andn:
  1006. ;
  1007. { mul is a little bit restricted }
  1008. muln:
  1009. if not(mmx_type(p^.left^.resulttype) in
  1010. [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1011. CGMessage(type_e_mismatch);
  1012. else
  1013. CGMessage(type_e_mismatch);
  1014. end;
  1015. p^.location.loc:=LOC_MMXREGISTER;
  1016. calcregisters(p,0,0,1);
  1017. convdone:=true;
  1018. end
  1019. else
  1020. {$endif SUPPORT_MMX}
  1021. { this is a little bit dangerous, also the left type }
  1022. { should be checked! This broke the mmx support }
  1023. if (rd^.deftype=pointerdef) or
  1024. is_zero_based_array(rd) then
  1025. begin
  1026. if is_zero_based_array(rd) then
  1027. begin
  1028. p^.resulttype:=new(ppointerdef,init(parraydef(rd)^.elementtype));
  1029. p^.right:=gentypeconvnode(p^.right,p^.resulttype);
  1030. firstpass(p^.right);
  1031. end;
  1032. p^.location.loc:=LOC_REGISTER;
  1033. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1034. firstpass(p^.left);
  1035. calcregisters(p,1,0,0);
  1036. if p^.treetype=addn then
  1037. begin
  1038. if not(cs_extsyntax in aktmoduleswitches) or
  1039. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1040. CGMessage(type_e_mismatch);
  1041. { Dirty hack, to support multiple firstpasses (PFV) }
  1042. if (p^.resulttype=nil) and
  1043. (rd^.deftype=pointerdef) and
  1044. (ppointerdef(rd)^.pointertype.def^.size>1) then
  1045. begin
  1046. p^.left:=gennode(muln,p^.left,genordinalconstnode(ppointerdef(rd)^.pointertype.def^.size,s32bitdef));
  1047. firstpass(p^.left);
  1048. end;
  1049. end
  1050. else
  1051. CGMessage(type_e_mismatch);
  1052. convdone:=true;
  1053. end
  1054. else
  1055. if (ld^.deftype=pointerdef) or
  1056. is_zero_based_array(ld) then
  1057. begin
  1058. if is_zero_based_array(ld) then
  1059. begin
  1060. p^.resulttype:=new(ppointerdef,init(parraydef(ld)^.elementtype));
  1061. p^.left:=gentypeconvnode(p^.left,p^.resulttype);
  1062. firstpass(p^.left);
  1063. end;
  1064. p^.location.loc:=LOC_REGISTER;
  1065. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1066. firstpass(p^.right);
  1067. calcregisters(p,1,0,0);
  1068. case p^.treetype of
  1069. addn,subn : begin
  1070. if not(cs_extsyntax in aktmoduleswitches) or
  1071. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1072. CGMessage(type_e_mismatch);
  1073. { Dirty hack, to support multiple firstpasses (PFV) }
  1074. if (p^.resulttype=nil) and
  1075. (ld^.deftype=pointerdef) and
  1076. (ppointerdef(ld)^.pointertype.def^.size>1) then
  1077. begin
  1078. p^.right:=gennode(muln,p^.right,
  1079. genordinalconstnode(ppointerdef(ld)^.pointertype.def^.size,s32bitdef));
  1080. firstpass(p^.right);
  1081. end;
  1082. end;
  1083. else
  1084. CGMessage(type_e_mismatch);
  1085. end;
  1086. convdone:=true;
  1087. end
  1088. else
  1089. if (rd^.deftype=procvardef) and (ld^.deftype=procvardef) and is_equal(rd,ld) then
  1090. begin
  1091. calcregisters(p,1,0,0);
  1092. p^.location.loc:=LOC_REGISTER;
  1093. case p^.treetype of
  1094. equaln,unequaln : ;
  1095. else
  1096. CGMessage(type_e_mismatch);
  1097. end;
  1098. convdone:=true;
  1099. end
  1100. else
  1101. if (ld^.deftype=enumdef) and (rd^.deftype=enumdef) and (is_equal(ld,rd)) then
  1102. begin
  1103. calcregisters(p,1,0,0);
  1104. case p^.treetype of
  1105. equaln,unequaln,
  1106. ltn,lten,gtn,gten : ;
  1107. else CGMessage(type_e_mismatch);
  1108. end;
  1109. convdone:=true;
  1110. end;
  1111. { the general solution is to convert to 32 bit int }
  1112. if not convdone then
  1113. begin
  1114. { but an int/int gives real/real! }
  1115. if p^.treetype=slashn then
  1116. begin
  1117. CGMessage(type_h_use_div_for_int);
  1118. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  1119. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  1120. firstpass(p^.left);
  1121. firstpass(p^.right);
  1122. { maybe we need an integer register to save }
  1123. { a reference }
  1124. if ((p^.left^.location.loc<>LOC_FPU) or
  1125. (p^.right^.location.loc<>LOC_FPU)) and
  1126. (p^.left^.registers32=p^.right^.registers32) then
  1127. calcregisters(p,1,1,0)
  1128. else
  1129. calcregisters(p,0,1,0);
  1130. p^.location.loc:=LOC_FPU;
  1131. end
  1132. else
  1133. begin
  1134. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1135. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1136. firstpass(p^.left);
  1137. firstpass(p^.right);
  1138. calcregisters(p,1,0,0);
  1139. p^.location.loc:=LOC_REGISTER;
  1140. end;
  1141. end;
  1142. if codegenerror then
  1143. exit;
  1144. { determines result type for comparions }
  1145. { here the is a problem with multiple passes }
  1146. { example length(s)+1 gets internal 'longint' type first }
  1147. { if it is a arg it is converted to 'LONGINT' }
  1148. { but a second first pass will reset this to 'longint' }
  1149. case p^.treetype of
  1150. ltn,lten,gtn,gten,equaln,unequaln:
  1151. begin
  1152. if (not assigned(p^.resulttype)) or
  1153. (p^.resulttype^.deftype=stringdef) then
  1154. p^.resulttype:=booldef;
  1155. if is_64bitint(p^.left^.resulttype) then
  1156. p^.location.loc:=LOC_JUMP
  1157. else
  1158. p^.location.loc:=LOC_FLAGS;
  1159. end;
  1160. xorn:
  1161. begin
  1162. if not assigned(p^.resulttype) then
  1163. p^.resulttype:=p^.left^.resulttype;
  1164. p^.location.loc:=LOC_REGISTER;
  1165. end;
  1166. addn:
  1167. begin
  1168. if not assigned(p^.resulttype) then
  1169. begin
  1170. { for strings, return is always a 255 char string }
  1171. if is_shortstring(p^.left^.resulttype) then
  1172. p^.resulttype:=cshortstringdef
  1173. else
  1174. p^.resulttype:=p^.left^.resulttype;
  1175. end;
  1176. end;
  1177. {$ifdef cardinalmulfix}
  1178. muln:
  1179. { if we multiply an unsigned with a signed number, the result is signed }
  1180. { in the other cases, the result remains signed or unsigned depending on }
  1181. { the multiplication factors (JM) }
  1182. if (p^.left^.resulttype^.deftype = orddef) and
  1183. (p^.right^.resulttype^.deftype = orddef) and
  1184. is_signed(p^.right^.resulttype) then
  1185. p^.resulttype := p^.right^.resulttype
  1186. else p^.resulttype := p^.left^.resulttype;
  1187. (*
  1188. subn:
  1189. { if we substract a u32bit from a positive constant, the result becomes }
  1190. { s32bit as well (JM) }
  1191. begin
  1192. if (p^.right^.resulttype^.deftype = orddef) and
  1193. (p^.left^.resulttype^.deftype = orddef) and
  1194. (porddef(p^.right^.resulttype)^.typ = u32bit) and
  1195. is_constintnode(p^.left) and
  1196. { (porddef(p^.left^.resulttype)^.typ <> u32bit) and}
  1197. (p^.left^.value > 0) then
  1198. begin
  1199. p^.left := gentypeconvnode(p^.left,u32bitdef);
  1200. firstpass(p^.left);
  1201. end;
  1202. p^.resulttype:=p^.left^.resulttype;
  1203. end;
  1204. *)
  1205. {$endif cardinalmulfix}
  1206. else
  1207. p^.resulttype:=p^.left^.resulttype;
  1208. end;
  1209. end;
  1210. end.
  1211. {
  1212. $Log$
  1213. Revision 1.72 2000-03-20 10:16:51 florian
  1214. * fixed <dword>/<dword>, <int64>/<int64> and <qword>/<qword>
  1215. Revision 1.71 2000/03/18 15:01:19 jonas
  1216. * moved a $maxfpuregisters directive a bit up because it was being
  1217. ignored
  1218. Revision 1.70 2000/02/19 10:12:48 florian
  1219. * fixed one more internalerror 10
  1220. Revision 1.69 2000/02/17 14:53:42 florian
  1221. * some updates for the newcg
  1222. Revision 1.68 2000/02/14 22:34:28 florian
  1223. * fixed another internalerror
  1224. Revision 1.67 2000/02/13 22:46:28 florian
  1225. * fixed an internalerror with writeln
  1226. * fixed arrayconstructor_to_set to force the generation of better code
  1227. and added a more strict type checking
  1228. Revision 1.66 2000/02/13 14:21:51 jonas
  1229. * modifications to make the compiler functional when compiled with
  1230. -Or
  1231. Revision 1.65 2000/02/09 13:23:06 peter
  1232. * log truncated
  1233. Revision 1.64 2000/02/04 08:47:10 florian
  1234. * better register variable allocation in -Or mode
  1235. Revision 1.63 2000/01/07 01:14:43 peter
  1236. * updated copyright to 2000
  1237. Revision 1.62 2000/01/04 20:10:20 florian
  1238. * mmx support fixed
  1239. Revision 1.61 1999/12/11 18:53:31 jonas
  1240. * fixed type conversions of results of operations with cardinals
  1241. (between -dcardinalmulfix)
  1242. Revision 1.60 1999/12/09 23:18:04 pierre
  1243. * no_fast_exit if procedure contains implicit termination code
  1244. Revision 1.59 1999/12/01 12:42:33 peter
  1245. * fixed bug 698
  1246. * removed some notes about unused vars
  1247. Revision 1.58 1999/11/30 10:40:56 peter
  1248. + ttype, tsymlist
  1249. Revision 1.57 1999/11/26 13:51:29 pierre
  1250. * fix for overloading of shr shl mod and div
  1251. Revision 1.56 1999/11/18 15:34:48 pierre
  1252. * Notes/Hints for local syms changed to
  1253. Set_varstate function
  1254. Revision 1.55 1999/11/17 17:05:06 pierre
  1255. * Notes/hints changes
  1256. Revision 1.54 1999/11/16 23:45:28 pierre
  1257. * global var token was changed by overload code (form bug 707)
  1258. Revision 1.53 1999/11/15 21:53:42 peter
  1259. * fixed constant eval for bool xor/or/and bool
  1260. Revision 1.52 1999/11/15 17:53:00 pierre
  1261. + one field added for ttoken record for operator
  1262. linking the id to the corresponding operator token that
  1263. can now now all be overloaded
  1264. * overloaded operators are resetted to nil in InitSymtable
  1265. (bug when trying to compile a uint that overloads operators twice)
  1266. Revision 1.51 1999/11/06 14:34:29 peter
  1267. * truncated log to 20 revs
  1268. Revision 1.50 1999/09/27 23:45:00 peter
  1269. * procinfo is now a pointer
  1270. * support for result setting in sub procedure
  1271. Revision 1.49 1999/09/16 13:39:14 peter
  1272. * arrayconstructor 2 set conversion is now called always in the
  1273. beginning of firstadd
  1274. Revision 1.48 1999/09/15 20:35:45 florian
  1275. * small fix to operator overloading when in MMX mode
  1276. + the compiler uses now fldz and fld1 if possible
  1277. + some fixes to floating point registers
  1278. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  1279. * .... ???
  1280. Revision 1.47 1999/09/13 16:28:05 peter
  1281. * typo in previous commit open_array -> chararray :(
  1282. Revision 1.46 1999/09/10 15:40:46 peter
  1283. * fixed array check for operators, becuase array can also be a set
  1284. Revision 1.45 1999/09/08 16:05:29 peter
  1285. * pointer add/sub is now as expected and the same results as inc/dec
  1286. }