tcadd.pas 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  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. cutils,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 (porddef(ld)^.typ in [u8bit,u16bit]) or
  547. (is_constintnode(p^.left) and
  548. (p^.treetype <> subn) and
  549. (p^.left^.value > 0)) then
  550. p^.left:=gentypeconvnode(p^.left,u32bitdef)
  551. else
  552. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  553. firstpass(p^.left);
  554. end
  555. else {if (porddef(ld)^.typ=u32bit) then}
  556. begin
  557. { can we make them both unsigned? }
  558. if (porddef(rd)^.typ in [u8bit,u16bit]) or
  559. (is_constintnode(p^.right) and
  560. (p^.right^.value > 0)) then
  561. p^.right:=gentypeconvnode(p^.right,u32bitdef)
  562. else
  563. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  564. firstpass(p^.right);
  565. end;
  566. {$endif cardinalmulfix}
  567. calcregisters(p,1,0,0);
  568. { for unsigned mul we need an extra register }
  569. { p^.registers32:=p^.left^.registers32+p^.right^.registers32; }
  570. if p^.treetype=muln then
  571. inc(p^.registers32);
  572. convdone:=true;
  573. end;
  574. end
  575. else
  576. { left side a setdef, must be before string processing,
  577. else array constructor can be seen as array of char (PFV) }
  578. if (ld^.deftype=setdef) {or is_array_constructor(ld)} then
  579. begin
  580. { trying to add a set element? }
  581. if (p^.treetype=addn) and (rd^.deftype<>setdef) then
  582. begin
  583. if (rt=setelementn) then
  584. begin
  585. if not(is_equal(psetdef(ld)^.elementtype.def,rd)) then
  586. CGMessage(type_e_set_element_are_not_comp);
  587. end
  588. else
  589. CGMessage(type_e_mismatch)
  590. end
  591. else
  592. begin
  593. if not(p^.treetype in [addn,subn,symdifn,muln,equaln,unequaln
  594. {$IfNDef NoSetInclusion}
  595. ,lten,gten
  596. {$EndIf NoSetInclusion}
  597. ]) then
  598. CGMessage(type_e_set_operation_unknown);
  599. { right def must be a also be set }
  600. if (rd^.deftype<>setdef) or not(is_equal(rd,ld)) then
  601. CGMessage(type_e_set_element_are_not_comp);
  602. end;
  603. { ranges require normsets }
  604. if (psetdef(ld)^.settype=smallset) and
  605. (rt=setelementn) and
  606. assigned(p^.right^.right) then
  607. begin
  608. { generate a temporary normset def, it'll be destroyed
  609. when the symtable is unloaded }
  610. tempdef:=new(psetdef,init(psetdef(ld)^.elementtype.def,255));
  611. p^.left:=gentypeconvnode(p^.left,tempdef);
  612. firstpass(p^.left);
  613. ld:=p^.left^.resulttype;
  614. end;
  615. { if the destination is not a smallset then insert a typeconv
  616. which loads a smallset into a normal set }
  617. if (psetdef(ld)^.settype<>smallset) and
  618. (psetdef(rd)^.settype=smallset) then
  619. begin
  620. if (p^.right^.treetype=setconstn) then
  621. begin
  622. t:=gensetconstnode(p^.right^.value_set,psetdef(p^.left^.resulttype));
  623. t^.left:=p^.right^.left;
  624. putnode(p^.right);
  625. p^.right:=t;
  626. end
  627. else
  628. p^.right:=gentypeconvnode(p^.right,psetdef(p^.left^.resulttype));
  629. firstpass(p^.right);
  630. end;
  631. { do constant evaluation }
  632. if (p^.right^.treetype=setconstn) and
  633. not assigned(p^.right^.left) and
  634. (p^.left^.treetype=setconstn) and
  635. not assigned(p^.left^.left) then
  636. begin
  637. new(resultset);
  638. case p^.treetype of
  639. addn : begin
  640. for i:=0 to 31 do
  641. resultset^[i]:=
  642. p^.right^.value_set^[i] or p^.left^.value_set^[i];
  643. t:=gensetconstnode(resultset,psetdef(ld));
  644. end;
  645. muln : begin
  646. for i:=0 to 31 do
  647. resultset^[i]:=
  648. p^.right^.value_set^[i] and p^.left^.value_set^[i];
  649. t:=gensetconstnode(resultset,psetdef(ld));
  650. end;
  651. subn : begin
  652. for i:=0 to 31 do
  653. resultset^[i]:=
  654. p^.left^.value_set^[i] and not(p^.right^.value_set^[i]);
  655. t:=gensetconstnode(resultset,psetdef(ld));
  656. end;
  657. symdifn : begin
  658. for i:=0 to 31 do
  659. resultset^[i]:=
  660. p^.left^.value_set^[i] xor p^.right^.value_set^[i];
  661. t:=gensetconstnode(resultset,psetdef(ld));
  662. end;
  663. unequaln : begin
  664. b:=true;
  665. for i:=0 to 31 do
  666. if p^.right^.value_set^[i]=p^.left^.value_set^[i] then
  667. begin
  668. b:=false;
  669. break;
  670. end;
  671. t:=genordinalconstnode(ord(b),booldef);
  672. end;
  673. equaln : begin
  674. b:=true;
  675. for i:=0 to 31 do
  676. if p^.right^.value_set^[i]<>p^.left^.value_set^[i] then
  677. begin
  678. b:=false;
  679. break;
  680. end;
  681. t:=genordinalconstnode(ord(b),booldef);
  682. end;
  683. {$IfNDef NoSetInclusion}
  684. lten : Begin
  685. b := true;
  686. For i := 0 to 31 Do
  687. If (p^.right^.value_set^[i] And p^.left^.value_set^[i]) <>
  688. p^.left^.value_set^[i] Then
  689. Begin
  690. b := false;
  691. Break
  692. End;
  693. t := genordinalconstnode(ord(b),booldef);
  694. End;
  695. gten : Begin
  696. b := true;
  697. For i := 0 to 31 Do
  698. If (p^.left^.value_set^[i] And p^.right^.value_set^[i]) <>
  699. p^.right^.value_set^[i] Then
  700. Begin
  701. b := false;
  702. Break
  703. End;
  704. t := genordinalconstnode(ord(b),booldef);
  705. End;
  706. {$EndIf NoSetInclusion}
  707. end;
  708. dispose(resultset);
  709. disposetree(p);
  710. p:=t;
  711. firstpass(p);
  712. exit;
  713. end
  714. else
  715. if psetdef(ld)^.settype=smallset then
  716. begin
  717. { are we adding set elements ? }
  718. if p^.right^.treetype=setelementn then
  719. calcregisters(p,2,0,0)
  720. else
  721. calcregisters(p,1,0,0);
  722. p^.location.loc:=LOC_REGISTER;
  723. end
  724. else
  725. begin
  726. calcregisters(p,0,0,0);
  727. { here we call SET... }
  728. procinfo^.flags:=procinfo^.flags or pi_do_call;
  729. p^.location.loc:=LOC_MEM;
  730. end;
  731. convdone:=true;
  732. end
  733. else
  734. { compare pchar to char arrays by addresses
  735. like BP/Delphi }
  736. if (is_pchar(ld) and is_chararray(rd)) or
  737. (is_pchar(rd) and is_chararray(ld)) then
  738. begin
  739. if is_chararray(rd) then
  740. begin
  741. p^.right:=gentypeconvnode(p^.right,ld);
  742. firstpass(p^.right);
  743. end
  744. else
  745. begin
  746. p^.left:=gentypeconvnode(p^.left,rd);
  747. firstpass(p^.left);
  748. end;
  749. p^.location.loc:=LOC_REGISTER;
  750. calcregisters(p,1,0,0);
  751. convdone:=true;
  752. end
  753. else
  754. { is one of the operands a string?,
  755. chararrays are also handled as strings (after conversion) }
  756. if (rd^.deftype=stringdef) or (ld^.deftype=stringdef) or
  757. ((is_chararray(rd) or is_char(rd)) and
  758. (is_chararray(ld) or is_char(ld))) then
  759. begin
  760. if is_widestring(rd) or is_widestring(ld) then
  761. begin
  762. if not(is_widestring(rd)) then
  763. p^.right:=gentypeconvnode(p^.right,cwidestringdef);
  764. if not(is_widestring(ld)) then
  765. p^.left:=gentypeconvnode(p^.left,cwidestringdef);
  766. p^.resulttype:=cwidestringdef;
  767. { this is only for add, the comparisaion is handled later }
  768. p^.location.loc:=LOC_REGISTER;
  769. end
  770. else if is_ansistring(rd) or is_ansistring(ld) then
  771. begin
  772. if not(is_ansistring(rd)) then
  773. p^.right:=gentypeconvnode(p^.right,cansistringdef);
  774. if not(is_ansistring(ld)) then
  775. p^.left:=gentypeconvnode(p^.left,cansistringdef);
  776. { we use ansistrings so no fast exit here }
  777. procinfo^.no_fast_exit:=true;
  778. p^.resulttype:=cansistringdef;
  779. { this is only for add, the comparisaion is handled later }
  780. p^.location.loc:=LOC_REGISTER;
  781. end
  782. else if is_longstring(rd) or is_longstring(ld) then
  783. begin
  784. if not(is_longstring(rd)) then
  785. p^.right:=gentypeconvnode(p^.right,clongstringdef);
  786. if not(is_longstring(ld)) then
  787. p^.left:=gentypeconvnode(p^.left,clongstringdef);
  788. p^.resulttype:=clongstringdef;
  789. { this is only for add, the comparisaion is handled later }
  790. p^.location.loc:=LOC_MEM;
  791. end
  792. else
  793. begin
  794. if not(is_shortstring(rd))
  795. {$ifdef newoptimizations2}
  796. {$ifdef i386}
  797. { shortstring + char handled seperately (JM) }
  798. and (not(cs_optimize in aktglobalswitches) or
  799. (p^.treetype <> addn) or not(is_char(rd)))
  800. {$endif i386}
  801. {$endif newoptimizations2}
  802. then
  803. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  804. if not(is_shortstring(ld)) then
  805. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  806. p^.resulttype:=cshortstringdef;
  807. { this is only for add, the comparisaion is handled later }
  808. p^.location.loc:=LOC_MEM;
  809. end;
  810. { only if there is a type cast we need to do again }
  811. { the first pass }
  812. if p^.left^.treetype=typeconvn then
  813. firstpass(p^.left);
  814. if p^.right^.treetype=typeconvn then
  815. firstpass(p^.right);
  816. { here we call STRCONCAT or STRCMP or STRCOPY }
  817. procinfo^.flags:=procinfo^.flags or pi_do_call;
  818. if p^.location.loc=LOC_MEM then
  819. calcregisters(p,0,0,0)
  820. else
  821. calcregisters(p,1,0,0);
  822. {$ifdef i386}
  823. { not always necessary, only if it is not a constant char and }
  824. { not a regvar, but don't know how to check this here (JM) }
  825. if is_char(rd) then
  826. inc(p^.registers32);
  827. {$endif i386}
  828. convdone:=true;
  829. end
  830. else
  831. { is one a real float ? }
  832. if (rd^.deftype=floatdef) or (ld^.deftype=floatdef) then
  833. begin
  834. { if one is a fixed, then convert to f32bit }
  835. if ((rd^.deftype=floatdef) and (pfloatdef(rd)^.typ=f32bit)) or
  836. ((ld^.deftype=floatdef) and (pfloatdef(ld)^.typ=f32bit)) then
  837. begin
  838. if not is_integer(rd) or (p^.treetype<>muln) then
  839. p^.right:=gentypeconvnode(p^.right,s32fixeddef);
  840. if not is_integer(ld) or (p^.treetype<>muln) then
  841. p^.left:=gentypeconvnode(p^.left,s32fixeddef);
  842. firstpass(p^.left);
  843. firstpass(p^.right);
  844. calcregisters(p,1,0,0);
  845. p^.location.loc:=LOC_REGISTER;
  846. end
  847. else
  848. { convert both to bestreal }
  849. begin
  850. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  851. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  852. firstpass(p^.left);
  853. firstpass(p^.right);
  854. calcregisters(p,0,1,0);
  855. p^.location.loc:=LOC_FPU;
  856. end;
  857. convdone:=true;
  858. end
  859. else
  860. { pointer comperation and subtraction }
  861. if (rd^.deftype=pointerdef) and (ld^.deftype=pointerdef) then
  862. begin
  863. p^.location.loc:=LOC_REGISTER;
  864. { p^.right:=gentypeconvnode(p^.right,ld); }
  865. { firstpass(p^.right); }
  866. calcregisters(p,1,0,0);
  867. case p^.treetype of
  868. equaln,unequaln :
  869. begin
  870. if is_equal(p^.right^.resulttype,voidpointerdef) then
  871. begin
  872. p^.right:=gentypeconvnode(p^.right,ld);
  873. firstpass(p^.right);
  874. end
  875. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  876. begin
  877. p^.left:=gentypeconvnode(p^.left,rd);
  878. firstpass(p^.left);
  879. end
  880. else if not(is_equal(ld,rd)) then
  881. CGMessage(type_e_mismatch);
  882. end;
  883. ltn,lten,gtn,gten:
  884. begin
  885. if is_equal(p^.right^.resulttype,voidpointerdef) then
  886. begin
  887. p^.right:=gentypeconvnode(p^.right,ld);
  888. firstpass(p^.right);
  889. end
  890. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  891. begin
  892. p^.left:=gentypeconvnode(p^.left,rd);
  893. firstpass(p^.left);
  894. end
  895. else if not(is_equal(ld,rd)) then
  896. CGMessage(type_e_mismatch);
  897. if not(cs_extsyntax in aktmoduleswitches) then
  898. CGMessage(type_e_mismatch);
  899. end;
  900. subn:
  901. begin
  902. if not(is_equal(ld,rd)) then
  903. CGMessage(type_e_mismatch);
  904. if not(cs_extsyntax in aktmoduleswitches) then
  905. CGMessage(type_e_mismatch);
  906. p^.resulttype:=s32bitdef;
  907. exit;
  908. end;
  909. else CGMessage(type_e_mismatch);
  910. end;
  911. convdone:=true;
  912. end
  913. else
  914. if (rd^.deftype=objectdef) and (ld^.deftype=objectdef) and
  915. pobjectdef(rd)^.is_class and pobjectdef(ld)^.is_class then
  916. begin
  917. p^.location.loc:=LOC_REGISTER;
  918. if pobjectdef(rd)^.is_related(pobjectdef(ld)) then
  919. p^.right:=gentypeconvnode(p^.right,ld)
  920. else
  921. p^.left:=gentypeconvnode(p^.left,rd);
  922. firstpass(p^.right);
  923. firstpass(p^.left);
  924. calcregisters(p,1,0,0);
  925. case p^.treetype of
  926. equaln,unequaln : ;
  927. else CGMessage(type_e_mismatch);
  928. end;
  929. convdone:=true;
  930. end
  931. else
  932. if (rd^.deftype=classrefdef) and (ld^.deftype=classrefdef) then
  933. begin
  934. p^.location.loc:=LOC_REGISTER;
  935. if pobjectdef(pclassrefdef(rd)^.pointertype.def)^.is_related(pobjectdef(
  936. pclassrefdef(ld)^.pointertype.def)) then
  937. p^.right:=gentypeconvnode(p^.right,ld)
  938. else
  939. p^.left:=gentypeconvnode(p^.left,rd);
  940. firstpass(p^.right);
  941. firstpass(p^.left);
  942. calcregisters(p,1,0,0);
  943. case p^.treetype of
  944. equaln,unequaln : ;
  945. else CGMessage(type_e_mismatch);
  946. end;
  947. convdone:=true;
  948. end
  949. else
  950. { allows comperasion with nil pointer }
  951. if (rd^.deftype=objectdef) and
  952. pobjectdef(rd)^.is_class then
  953. begin
  954. p^.location.loc:=LOC_REGISTER;
  955. p^.left:=gentypeconvnode(p^.left,rd);
  956. firstpass(p^.left);
  957. calcregisters(p,1,0,0);
  958. case p^.treetype of
  959. equaln,unequaln : ;
  960. else CGMessage(type_e_mismatch);
  961. end;
  962. convdone:=true;
  963. end
  964. else
  965. if (ld^.deftype=objectdef) and
  966. pobjectdef(ld)^.is_class then
  967. begin
  968. p^.location.loc:=LOC_REGISTER;
  969. p^.right:=gentypeconvnode(p^.right,ld);
  970. firstpass(p^.right);
  971. calcregisters(p,1,0,0);
  972. case p^.treetype of
  973. equaln,unequaln : ;
  974. else CGMessage(type_e_mismatch);
  975. end;
  976. convdone:=true;
  977. end
  978. else
  979. if (rd^.deftype=classrefdef) then
  980. begin
  981. p^.left:=gentypeconvnode(p^.left,rd);
  982. firstpass(p^.left);
  983. calcregisters(p,1,0,0);
  984. case p^.treetype of
  985. equaln,unequaln : ;
  986. else CGMessage(type_e_mismatch);
  987. end;
  988. convdone:=true;
  989. end
  990. else
  991. if (ld^.deftype=classrefdef) then
  992. begin
  993. p^.right:=gentypeconvnode(p^.right,ld);
  994. firstpass(p^.right);
  995. calcregisters(p,1,0,0);
  996. case p^.treetype of
  997. equaln,unequaln : ;
  998. else
  999. CGMessage(type_e_mismatch);
  1000. end;
  1001. convdone:=true;
  1002. end
  1003. else
  1004. { support procvar=nil,procvar<>nil }
  1005. if ((ld^.deftype=procvardef) and (rt=niln)) or
  1006. ((rd^.deftype=procvardef) and (lt=niln)) then
  1007. begin
  1008. calcregisters(p,1,0,0);
  1009. p^.location.loc:=LOC_REGISTER;
  1010. case p^.treetype of
  1011. equaln,unequaln : ;
  1012. else
  1013. CGMessage(type_e_mismatch);
  1014. end;
  1015. convdone:=true;
  1016. end
  1017. else
  1018. {$ifdef SUPPORT_MMX}
  1019. if (cs_mmx in aktlocalswitches) and is_mmx_able_array(ld) and
  1020. is_mmx_able_array(rd) and is_equal(ld,rd) then
  1021. begin
  1022. firstpass(p^.right);
  1023. firstpass(p^.left);
  1024. case p^.treetype of
  1025. addn,subn,xorn,orn,andn:
  1026. ;
  1027. { mul is a little bit restricted }
  1028. muln:
  1029. if not(mmx_type(p^.left^.resulttype) in
  1030. [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1031. CGMessage(type_e_mismatch);
  1032. else
  1033. CGMessage(type_e_mismatch);
  1034. end;
  1035. p^.location.loc:=LOC_MMXREGISTER;
  1036. calcregisters(p,0,0,1);
  1037. convdone:=true;
  1038. end
  1039. else
  1040. {$endif SUPPORT_MMX}
  1041. { this is a little bit dangerous, also the left type }
  1042. { should be checked! This broke the mmx support }
  1043. if (rd^.deftype=pointerdef) or
  1044. is_zero_based_array(rd) then
  1045. begin
  1046. if is_zero_based_array(rd) then
  1047. begin
  1048. p^.resulttype:=new(ppointerdef,init(parraydef(rd)^.elementtype));
  1049. p^.right:=gentypeconvnode(p^.right,p^.resulttype);
  1050. firstpass(p^.right);
  1051. end;
  1052. p^.location.loc:=LOC_REGISTER;
  1053. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1054. firstpass(p^.left);
  1055. calcregisters(p,1,0,0);
  1056. if p^.treetype=addn then
  1057. begin
  1058. if not(cs_extsyntax in aktmoduleswitches) or
  1059. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1060. CGMessage(type_e_mismatch);
  1061. { Dirty hack, to support multiple firstpasses (PFV) }
  1062. if (p^.resulttype=nil) and
  1063. (rd^.deftype=pointerdef) and
  1064. (ppointerdef(rd)^.pointertype.def^.size>1) then
  1065. begin
  1066. p^.left:=gennode(muln,p^.left,genordinalconstnode(ppointerdef(rd)^.pointertype.def^.size,s32bitdef));
  1067. firstpass(p^.left);
  1068. end;
  1069. end
  1070. else
  1071. CGMessage(type_e_mismatch);
  1072. convdone:=true;
  1073. end
  1074. else
  1075. if (ld^.deftype=pointerdef) or
  1076. is_zero_based_array(ld) then
  1077. begin
  1078. if is_zero_based_array(ld) then
  1079. begin
  1080. p^.resulttype:=new(ppointerdef,init(parraydef(ld)^.elementtype));
  1081. p^.left:=gentypeconvnode(p^.left,p^.resulttype);
  1082. firstpass(p^.left);
  1083. end;
  1084. p^.location.loc:=LOC_REGISTER;
  1085. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1086. firstpass(p^.right);
  1087. calcregisters(p,1,0,0);
  1088. case p^.treetype of
  1089. addn,subn : begin
  1090. if not(cs_extsyntax in aktmoduleswitches) or
  1091. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1092. CGMessage(type_e_mismatch);
  1093. { Dirty hack, to support multiple firstpasses (PFV) }
  1094. if (p^.resulttype=nil) and
  1095. (ld^.deftype=pointerdef) and
  1096. (ppointerdef(ld)^.pointertype.def^.size>1) then
  1097. begin
  1098. p^.right:=gennode(muln,p^.right,
  1099. genordinalconstnode(ppointerdef(ld)^.pointertype.def^.size,s32bitdef));
  1100. firstpass(p^.right);
  1101. end;
  1102. end;
  1103. else
  1104. CGMessage(type_e_mismatch);
  1105. end;
  1106. convdone:=true;
  1107. end
  1108. else
  1109. if (rd^.deftype=procvardef) and (ld^.deftype=procvardef) and is_equal(rd,ld) then
  1110. begin
  1111. calcregisters(p,1,0,0);
  1112. p^.location.loc:=LOC_REGISTER;
  1113. case p^.treetype of
  1114. equaln,unequaln : ;
  1115. else
  1116. CGMessage(type_e_mismatch);
  1117. end;
  1118. convdone:=true;
  1119. end
  1120. else
  1121. if (ld^.deftype=enumdef) and (rd^.deftype=enumdef) then
  1122. begin
  1123. if not(is_equal(ld,rd)) then
  1124. begin
  1125. p^.right:=gentypeconvnode(p^.right,ld);
  1126. firstpass(p^.right);
  1127. end;
  1128. calcregisters(p,1,0,0);
  1129. case p^.treetype of
  1130. equaln,unequaln,
  1131. ltn,lten,gtn,gten : ;
  1132. else CGMessage(type_e_mismatch);
  1133. end;
  1134. convdone:=true;
  1135. end;
  1136. { the general solution is to convert to 32 bit int }
  1137. if not convdone then
  1138. begin
  1139. { but an int/int gives real/real! }
  1140. if p^.treetype=slashn then
  1141. begin
  1142. CGMessage(type_h_use_div_for_int);
  1143. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  1144. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  1145. firstpass(p^.left);
  1146. firstpass(p^.right);
  1147. { maybe we need an integer register to save }
  1148. { a reference }
  1149. if ((p^.left^.location.loc<>LOC_FPU) or
  1150. (p^.right^.location.loc<>LOC_FPU)) and
  1151. (p^.left^.registers32=p^.right^.registers32) then
  1152. calcregisters(p,1,1,0)
  1153. else
  1154. calcregisters(p,0,1,0);
  1155. p^.location.loc:=LOC_FPU;
  1156. end
  1157. else
  1158. begin
  1159. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1160. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1161. firstpass(p^.left);
  1162. firstpass(p^.right);
  1163. calcregisters(p,1,0,0);
  1164. p^.location.loc:=LOC_REGISTER;
  1165. end;
  1166. end;
  1167. if codegenerror then
  1168. exit;
  1169. { determines result type for comparions }
  1170. { here the is a problem with multiple passes }
  1171. { example length(s)+1 gets internal 'longint' type first }
  1172. { if it is a arg it is converted to 'LONGINT' }
  1173. { but a second first pass will reset this to 'longint' }
  1174. case p^.treetype of
  1175. ltn,lten,gtn,gten,equaln,unequaln:
  1176. begin
  1177. if (not assigned(p^.resulttype)) or
  1178. (p^.resulttype^.deftype=stringdef) then
  1179. p^.resulttype:=booldef;
  1180. if is_64bitint(p^.left^.resulttype) then
  1181. p^.location.loc:=LOC_JUMP
  1182. else
  1183. p^.location.loc:=LOC_FLAGS;
  1184. end;
  1185. xorn:
  1186. begin
  1187. if not assigned(p^.resulttype) then
  1188. p^.resulttype:=p^.left^.resulttype;
  1189. p^.location.loc:=LOC_REGISTER;
  1190. end;
  1191. addn:
  1192. begin
  1193. if not assigned(p^.resulttype) then
  1194. begin
  1195. { for strings, return is always a 255 char string }
  1196. if is_shortstring(p^.left^.resulttype) then
  1197. p^.resulttype:=cshortstringdef
  1198. else
  1199. p^.resulttype:=p^.left^.resulttype;
  1200. end;
  1201. end;
  1202. {$ifdef cardinalmulfix}
  1203. muln:
  1204. { if we multiply an unsigned with a signed number, the result is signed }
  1205. { in the other cases, the result remains signed or unsigned depending on }
  1206. { the multiplication factors (JM) }
  1207. if (p^.left^.resulttype^.deftype = orddef) and
  1208. (p^.right^.resulttype^.deftype = orddef) and
  1209. is_signed(p^.right^.resulttype) then
  1210. p^.resulttype := p^.right^.resulttype
  1211. else p^.resulttype := p^.left^.resulttype;
  1212. (*
  1213. subn:
  1214. { if we substract a u32bit from a positive constant, the result becomes }
  1215. { s32bit as well (JM) }
  1216. begin
  1217. if (p^.right^.resulttype^.deftype = orddef) and
  1218. (p^.left^.resulttype^.deftype = orddef) and
  1219. (porddef(p^.right^.resulttype)^.typ = u32bit) and
  1220. is_constintnode(p^.left) and
  1221. { (porddef(p^.left^.resulttype)^.typ <> u32bit) and}
  1222. (p^.left^.value > 0) then
  1223. begin
  1224. p^.left := gentypeconvnode(p^.left,u32bitdef);
  1225. firstpass(p^.left);
  1226. end;
  1227. p^.resulttype:=p^.left^.resulttype;
  1228. end;
  1229. *)
  1230. {$endif cardinalmulfix}
  1231. else
  1232. p^.resulttype:=p^.left^.resulttype;
  1233. end;
  1234. end;
  1235. end.
  1236. {
  1237. $Log$
  1238. Revision 1.8 2000-09-10 20:19:23 peter
  1239. * fixed crash with smallset -> normalset conversion (merged)
  1240. Revision 1.7 2000/08/29 08:24:45 jonas
  1241. * some modifications to -dcardinalmulfix code
  1242. Revision 1.6 2000/08/27 16:11:54 peter
  1243. * moved some util functions from globals,cobjects to cutils
  1244. * splitted files into finput,fmodule
  1245. Revision 1.5 2000/08/17 12:03:48 florian
  1246. * fixed several problems with the int64 constants
  1247. Revision 1.4 2000/07/27 09:19:37 jonas
  1248. * removed obsolete typeconversion (it got removed by the compiler in
  1249. firsttypeconv anyway) (merged from fixes branch)
  1250. Revision 1.3 2000/07/14 05:11:49 michael
  1251. + Patch to 1.1
  1252. Revision 1.2 2000/07/13 11:32:50 michael
  1253. + removed logs
  1254. }