tcadd.pas 52 KB

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