tcadd.pas 51 KB

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