tcadd.pas 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Type checking and register allocation for add node
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit tcadd;
  19. interface
  20. uses
  21. tree;
  22. procedure firstadd(var p : ptree);
  23. function isbinaryoverloaded(var p : ptree) : boolean;
  24. implementation
  25. uses
  26. globtype,systems,tokens,
  27. cobjects,verbose,globals,
  28. symconst,symtable,aasm,types,
  29. {$ifdef newcg}
  30. cgbase,
  31. {$else newcg}
  32. hcodegen,
  33. {$endif newcg}
  34. htypechk,pass_1,
  35. cpubase,tccnv
  36. ;
  37. function isbinaryoverloaded(var p : ptree) : boolean;
  38. var
  39. rd,ld : pdef;
  40. t : ptree;
  41. optoken : ttoken;
  42. begin
  43. isbinaryoverloaded:=false;
  44. { overloaded operator ? }
  45. { load easier access variables }
  46. rd:=p^.right^.resulttype;
  47. ld:=p^.left^.resulttype;
  48. if isbinaryoperatoroverloadable(ld,rd,voiddef,p^.treetype) then
  49. begin
  50. isbinaryoverloaded:=true;
  51. {!!!!!!!!! handle paras }
  52. case p^.treetype of
  53. { the nil as symtable signs firstcalln that this is
  54. an overloaded operator }
  55. addn:
  56. optoken:=_PLUS;
  57. subn:
  58. optoken:=_MINUS;
  59. muln:
  60. optoken:=_STAR;
  61. starstarn:
  62. optoken:=_STARSTAR;
  63. slashn:
  64. optoken:=_SLASH;
  65. ltn:
  66. optoken:=tokens._lt;
  67. gtn:
  68. optoken:=tokens._gt;
  69. lten:
  70. optoken:=_lte;
  71. gten:
  72. optoken:=_gte;
  73. equaln,unequaln :
  74. optoken:=_EQUAL;
  75. symdifn :
  76. optoken:=_SYMDIF;
  77. modn :
  78. optoken:=_OP_MOD;
  79. orn :
  80. optoken:=_OP_OR;
  81. xorn :
  82. optoken:=_OP_XOR;
  83. andn :
  84. optoken:=_OP_AND;
  85. divn :
  86. optoken:=_OP_DIV;
  87. shln :
  88. optoken:=_OP_SHL;
  89. shrn :
  90. optoken:=_OP_SHR;
  91. else
  92. exit;
  93. end;
  94. t:=gencallnode(overloaded_operators[optoken],nil);
  95. { we have to convert p^.left and p^.right into
  96. callparanodes }
  97. if t^.symtableprocentry=nil then
  98. begin
  99. CGMessage(parser_e_operator_not_overloaded);
  100. putnode(t);
  101. end
  102. else
  103. begin
  104. inc(t^.symtableprocentry^.refs);
  105. t^.left:=gencallparanode(p^.left,nil);
  106. t^.left:=gencallparanode(p^.right,t^.left);
  107. if p^.treetype=unequaln then
  108. t:=gensinglenode(notn,t);
  109. firstpass(t);
  110. putnode(p);
  111. p:=t;
  112. end;
  113. end;
  114. end;
  115. {*****************************************************************************
  116. FirstAdd
  117. *****************************************************************************}
  118. {$ifdef fpc}
  119. {$maxfpuregisters 0}
  120. {$endif fpc}
  121. procedure firstadd(var p : ptree);
  122. procedure make_bool_equal_size(var p:ptree);
  123. begin
  124. if porddef(p^.left^.resulttype)^.typ>porddef(p^.right^.resulttype)^.typ then
  125. begin
  126. p^.right:=gentypeconvnode(p^.right,porddef(p^.left^.resulttype));
  127. p^.right^.convtyp:=tc_bool_2_int;
  128. p^.right^.explizit:=true;
  129. firstpass(p^.right);
  130. end
  131. else
  132. if porddef(p^.left^.resulttype)^.typ<porddef(p^.right^.resulttype)^.typ then
  133. begin
  134. p^.left:=gentypeconvnode(p^.left,porddef(p^.right^.resulttype));
  135. p^.left^.convtyp:=tc_bool_2_int;
  136. p^.left^.explizit:=true;
  137. firstpass(p^.left);
  138. end;
  139. end;
  140. var
  141. t,hp : ptree;
  142. ot,
  143. lt,rt : ttreetyp;
  144. rv,lv : longint;
  145. rvd,lvd : bestreal;
  146. resdef,
  147. rd,ld : pdef;
  148. tempdef : pdef;
  149. concatstrings : boolean;
  150. { to evalute const sets }
  151. resultset : pconstset;
  152. i : longint;
  153. b : boolean;
  154. convdone : boolean;
  155. s1,s2 : pchar;
  156. l1,l2 : longint;
  157. begin
  158. { first do the two subtrees }
  159. firstpass(p^.left);
  160. firstpass(p^.right);
  161. if codegenerror then
  162. exit;
  163. { convert array constructors to sets, because there is no other operator
  164. possible for array constructors }
  165. if is_array_constructor(p^.left^.resulttype) then
  166. arrayconstructor_to_set(p^.left);
  167. if is_array_constructor(p^.right^.resulttype) then
  168. arrayconstructor_to_set(p^.right);
  169. { both left and right need to be valid }
  170. set_varstate(p^.left,true);
  171. set_varstate(p^.right,true);
  172. { load easier access variables }
  173. lt:=p^.left^.treetype;
  174. rt:=p^.right^.treetype;
  175. rd:=p^.right^.resulttype;
  176. ld:=p^.left^.resulttype;
  177. convdone:=false;
  178. if isbinaryoverloaded(p) then
  179. exit;
  180. { compact consts }
  181. { convert int consts to real consts, if the }
  182. { other operand is a real const }
  183. if (rt=realconstn) and is_constintnode(p^.left) then
  184. begin
  185. t:=genrealconstnode(p^.left^.value,p^.right^.resulttype);
  186. disposetree(p^.left);
  187. p^.left:=t;
  188. lt:=realconstn;
  189. end;
  190. if (lt=realconstn) and is_constintnode(p^.right) then
  191. begin
  192. t:=genrealconstnode(p^.right^.value,p^.left^.resulttype);
  193. disposetree(p^.right);
  194. p^.right:=t;
  195. rt:=realconstn;
  196. end;
  197. { both are int constants, also allow operations on two equal enums
  198. in fpc mode (Needed for conversion of C code) }
  199. if ((lt=ordconstn) and (rt=ordconstn)) and
  200. ((is_constintnode(p^.left) and is_constintnode(p^.right)) or
  201. (is_constboolnode(p^.left) and is_constboolnode(p^.right) and
  202. (p^.treetype in [ltn,lten,gtn,gten,equaln,unequaln,andn,xorn,orn]))) then
  203. begin
  204. { return a boolean for boolean operations (and,xor,or) }
  205. if is_constboolnode(p^.left) then
  206. resdef:=booldef
  207. else
  208. resdef:=s32bitdef;
  209. lv:=p^.left^.value;
  210. rv:=p^.right^.value;
  211. case p^.treetype of
  212. addn : t:=genordinalconstnode(lv+rv,resdef);
  213. subn : t:=genordinalconstnode(lv-rv,resdef);
  214. muln : t:=genordinalconstnode(lv*rv,resdef);
  215. xorn : t:=genordinalconstnode(lv xor rv,resdef);
  216. orn : t:=genordinalconstnode(lv or rv,resdef);
  217. andn : t:=genordinalconstnode(lv and rv,resdef);
  218. ltn : t:=genordinalconstnode(ord(lv<rv),booldef);
  219. lten : t:=genordinalconstnode(ord(lv<=rv),booldef);
  220. gtn : t:=genordinalconstnode(ord(lv>rv),booldef);
  221. gten : t:=genordinalconstnode(ord(lv>=rv),booldef);
  222. equaln : t:=genordinalconstnode(ord(lv=rv),booldef);
  223. unequaln : t:=genordinalconstnode(ord(lv<>rv),booldef);
  224. slashn : begin
  225. { int/int becomes a real }
  226. if int(rv)=0 then
  227. begin
  228. Message(parser_e_invalid_float_operation);
  229. t:=genrealconstnode(0,bestrealdef^);
  230. end
  231. else
  232. t:=genrealconstnode(int(lv)/int(rv),bestrealdef^);
  233. firstpass(t);
  234. end;
  235. else
  236. CGMessage(type_e_mismatch);
  237. end;
  238. disposetree(p);
  239. firstpass(t);
  240. p:=t;
  241. exit;
  242. end;
  243. { both real constants ? }
  244. if (lt=realconstn) and (rt=realconstn) then
  245. begin
  246. lvd:=p^.left^.value_real;
  247. rvd:=p^.right^.value_real;
  248. case p^.treetype of
  249. addn : t:=genrealconstnode(lvd+rvd,bestrealdef^);
  250. subn : t:=genrealconstnode(lvd-rvd,bestrealdef^);
  251. muln : t:=genrealconstnode(lvd*rvd,bestrealdef^);
  252. starstarn,
  253. caretn : begin
  254. if lvd<0 then
  255. begin
  256. Message(parser_e_invalid_float_operation);
  257. t:=genrealconstnode(0,bestrealdef^);
  258. end
  259. else if lvd=0 then
  260. t:=genrealconstnode(1.0,bestrealdef^)
  261. else
  262. t:=genrealconstnode(exp(ln(lvd)*rvd),bestrealdef^);
  263. end;
  264. slashn :
  265. begin
  266. if rvd=0 then
  267. begin
  268. Message(parser_e_invalid_float_operation);
  269. t:=genrealconstnode(0,bestrealdef^);
  270. end
  271. else
  272. t:=genrealconstnode(lvd/rvd,bestrealdef^);
  273. end;
  274. ltn : t:=genordinalconstnode(ord(lvd<rvd),booldef);
  275. lten : t:=genordinalconstnode(ord(lvd<=rvd),booldef);
  276. gtn : t:=genordinalconstnode(ord(lvd>rvd),booldef);
  277. gten : t:=genordinalconstnode(ord(lvd>=rvd),booldef);
  278. equaln : t:=genordinalconstnode(ord(lvd=rvd),booldef);
  279. unequaln : t:=genordinalconstnode(ord(lvd<>rvd),booldef);
  280. else
  281. CGMessage(type_e_mismatch);
  282. end;
  283. disposetree(p);
  284. p:=t;
  285. firstpass(p);
  286. exit;
  287. end;
  288. { concating strings ? }
  289. concatstrings:=false;
  290. s1:=nil;
  291. s2:=nil;
  292. if (lt=ordconstn) and (rt=ordconstn) and
  293. is_char(ld) and is_char(rd) then
  294. begin
  295. s1:=strpnew(char(byte(p^.left^.value)));
  296. s2:=strpnew(char(byte(p^.right^.value)));
  297. l1:=1;
  298. l2:=1;
  299. concatstrings:=true;
  300. end
  301. else
  302. if (lt=stringconstn) and (rt=ordconstn) and is_char(rd) then
  303. begin
  304. s1:=getpcharcopy(p^.left);
  305. l1:=p^.left^.length;
  306. s2:=strpnew(char(byte(p^.right^.value)));
  307. l2:=1;
  308. concatstrings:=true;
  309. end
  310. else
  311. if (lt=ordconstn) and (rt=stringconstn) and is_char(ld) then
  312. begin
  313. s1:=strpnew(char(byte(p^.left^.value)));
  314. l1:=1;
  315. s2:=getpcharcopy(p^.right);
  316. l2:=p^.right^.length;
  317. concatstrings:=true;
  318. end
  319. else if (lt=stringconstn) and (rt=stringconstn) then
  320. begin
  321. s1:=getpcharcopy(p^.left);
  322. l1:=p^.left^.length;
  323. s2:=getpcharcopy(p^.right);
  324. l2:=p^.right^.length;
  325. concatstrings:=true;
  326. end;
  327. { I will need to translate all this to ansistrings !!! }
  328. if concatstrings then
  329. begin
  330. case p^.treetype of
  331. addn :
  332. t:=genpcharconstnode(concatansistrings(s1,s2,l1,l2),l1+l2);
  333. ltn :
  334. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)<0),booldef);
  335. lten :
  336. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)<=0),booldef);
  337. gtn :
  338. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)>0),booldef);
  339. gten :
  340. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)>=0),booldef);
  341. equaln :
  342. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)=0),booldef);
  343. unequaln :
  344. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)<>0),booldef);
  345. end;
  346. ansistringdispose(s1,l1);
  347. ansistringdispose(s2,l2);
  348. disposetree(p);
  349. firstpass(t);
  350. p:=t;
  351. exit;
  352. end;
  353. { if both are orddefs then check sub types }
  354. if (ld^.deftype=orddef) and (rd^.deftype=orddef) then
  355. begin
  356. { 2 booleans ? }
  357. if is_boolean(ld) and is_boolean(rd) then
  358. begin
  359. case p^.treetype of
  360. andn,
  361. orn:
  362. begin
  363. make_bool_equal_size(p);
  364. calcregisters(p,0,0,0);
  365. p^.location.loc:=LOC_JUMP;
  366. end;
  367. xorn,ltn,lten,gtn,gten:
  368. begin
  369. make_bool_equal_size(p);
  370. if (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) and
  371. (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) then
  372. calcregisters(p,2,0,0)
  373. else
  374. calcregisters(p,1,0,0);
  375. end;
  376. unequaln,
  377. equaln:
  378. begin
  379. make_bool_equal_size(p);
  380. { Remove any compares with constants }
  381. if (p^.left^.treetype=ordconstn) then
  382. begin
  383. hp:=p^.right;
  384. b:=(p^.left^.value<>0);
  385. ot:=p^.treetype;
  386. disposetree(p^.left);
  387. putnode(p);
  388. p:=hp;
  389. if (not(b) and (ot=equaln)) or
  390. (b and (ot=unequaln)) then
  391. begin
  392. p:=gensinglenode(notn,p);
  393. firstpass(p);
  394. end;
  395. exit;
  396. end;
  397. if (p^.right^.treetype=ordconstn) then
  398. begin
  399. hp:=p^.left;
  400. b:=(p^.right^.value<>0);
  401. ot:=p^.treetype;
  402. disposetree(p^.right);
  403. putnode(p);
  404. p:=hp;
  405. if (not(b) and (ot=equaln)) or
  406. (b and (ot=unequaln)) then
  407. begin
  408. p:=gensinglenode(notn,p);
  409. firstpass(p);
  410. end;
  411. exit;
  412. end;
  413. if (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) and
  414. (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) then
  415. calcregisters(p,2,0,0)
  416. else
  417. calcregisters(p,1,0,0);
  418. end;
  419. else
  420. CGMessage(type_e_mismatch);
  421. end;
  422. { these one can't be in flags! }
  423. if p^.treetype in [xorn,unequaln,equaln] then
  424. begin
  425. if p^.left^.location.loc=LOC_FLAGS then
  426. begin
  427. p^.left:=gentypeconvnode(p^.left,porddef(p^.left^.resulttype));
  428. p^.left^.convtyp:=tc_bool_2_int;
  429. p^.left^.explizit:=true;
  430. firstpass(p^.left);
  431. end;
  432. if p^.right^.location.loc=LOC_FLAGS then
  433. begin
  434. p^.right:=gentypeconvnode(p^.right,porddef(p^.right^.resulttype));
  435. p^.right^.convtyp:=tc_bool_2_int;
  436. p^.right^.explizit:=true;
  437. firstpass(p^.right);
  438. end;
  439. { readjust registers }
  440. calcregisters(p,1,0,0);
  441. end;
  442. convdone:=true;
  443. end
  444. else
  445. { Both are chars? only convert to shortstrings for addn }
  446. if is_char(rd) and is_char(ld) then
  447. begin
  448. if p^.treetype=addn then
  449. begin
  450. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  451. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  452. firstpass(p^.left);
  453. firstpass(p^.right);
  454. { here we call STRCOPY }
  455. procinfo^.flags:=procinfo^.flags or pi_do_call;
  456. calcregisters(p,0,0,0);
  457. p^.location.loc:=LOC_MEM;
  458. end
  459. else
  460. calcregisters(p,1,0,0);
  461. convdone:=true;
  462. end
  463. { is there a 64 bit type ? }
  464. else if ((porddef(rd)^.typ=s64bit) or (porddef(ld)^.typ=s64bit)) and
  465. { the / operator is handled later }
  466. (p^.treetype<>slashn) then
  467. begin
  468. if (porddef(ld)^.typ<>s64bit) then
  469. begin
  470. p^.left:=gentypeconvnode(p^.left,cs64bitdef);
  471. firstpass(p^.left);
  472. end;
  473. if (porddef(rd)^.typ<>s64bit) then
  474. begin
  475. p^.right:=gentypeconvnode(p^.right,cs64bitdef);
  476. firstpass(p^.right);
  477. end;
  478. calcregisters(p,2,0,0);
  479. convdone:=true;
  480. end
  481. else if ((porddef(rd)^.typ=u64bit) or (porddef(ld)^.typ=u64bit)) and
  482. { the / operator is handled later }
  483. (p^.treetype<>slashn) then
  484. begin
  485. if (porddef(ld)^.typ<>u64bit) then
  486. begin
  487. p^.left:=gentypeconvnode(p^.left,cu64bitdef);
  488. firstpass(p^.left);
  489. end;
  490. if (porddef(rd)^.typ<>u64bit) then
  491. begin
  492. p^.right:=gentypeconvnode(p^.right,cu64bitdef);
  493. firstpass(p^.right);
  494. end;
  495. calcregisters(p,2,0,0);
  496. convdone:=true;
  497. end
  498. else
  499. { is there a cardinal? }
  500. if ((porddef(rd)^.typ=u32bit) or (porddef(ld)^.typ=u32bit)) and
  501. { the / operator is handled later }
  502. (p^.treetype<>slashn) then
  503. begin
  504. { convert constants to u32bit }
  505. {$ifndef cardinalmulfix}
  506. if (porddef(ld)^.typ<>u32bit) then
  507. begin
  508. { s32bit will be used for when the other is also s32bit }
  509. { the following line doesn't make any sense: it's the same as }
  510. { if ((porddef(rd)^.typ=u32bit) or (porddef(ld)^.typ=u32bit)) and }
  511. { (porddef(ld)^.typ<>u32bit) and (porddef(rd)^.typ=s32bit) then }
  512. { which can be simplified to }
  513. { if ((porddef(rd)^.typ=u32bit) and (porddef(rd)^.typ=s32bit) then }
  514. { which can never be true (JM) }
  515. if (porddef(rd)^.typ=s32bit) and (lt<>ordconstn) then
  516. p^.left:=gentypeconvnode(p^.left,s32bitdef)
  517. else
  518. p^.left:=gentypeconvnode(p^.left,u32bitdef);
  519. firstpass(p^.left);
  520. end;
  521. if (porddef(rd)^.typ<>u32bit) then
  522. begin
  523. { s32bit will be used for when the other is also s32bit }
  524. if (porddef(ld)^.typ=s32bit) and (rt<>ordconstn) then
  525. p^.right:=gentypeconvnode(p^.right,s32bitdef)
  526. else
  527. p^.right:=gentypeconvnode(p^.right,u32bitdef);
  528. firstpass(p^.right);
  529. end;
  530. {$else cardinalmulfix}
  531. { only do a conversion if the nodes have different signs }
  532. if (porddef(rd)^.typ=u32bit) xor (porddef(ld)^.typ=u32bit) then
  533. if (porddef(rd)^.typ=u32bit) then
  534. begin
  535. { can we make them both unsigned? }
  536. if is_constintnode(p^.left) and
  537. ((p^.treetype <> subn) and
  538. (p^.left^.value > 0)) then
  539. p^.left:=gentypeconvnode(p^.left,u32bitdef)
  540. else
  541. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  542. firstpass(p^.left);
  543. end
  544. else {if (porddef(ld)^.typ=u32bit) then}
  545. begin
  546. { can we make them both unsigned? }
  547. if is_constintnode(p^.right) and
  548. (p^.right^.value > 0) then
  549. p^.right:=gentypeconvnode(p^.right,u32bitdef)
  550. else
  551. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  552. firstpass(p^.right);
  553. end;
  554. {$endif cardinalmulfix}
  555. calcregisters(p,1,0,0);
  556. { for unsigned mul we need an extra register }
  557. { p^.registers32:=p^.left^.registers32+p^.right^.registers32; }
  558. if p^.treetype=muln then
  559. inc(p^.registers32);
  560. convdone:=true;
  561. end;
  562. end
  563. else
  564. { left side a setdef, must be before string processing,
  565. else array constructor can be seen as array of char (PFV) }
  566. if (ld^.deftype=setdef) {or is_array_constructor(ld)} then
  567. begin
  568. { trying to add a set element? }
  569. if (p^.treetype=addn) and (rd^.deftype<>setdef) then
  570. begin
  571. if (rt=setelementn) then
  572. begin
  573. if not(is_equal(psetdef(ld)^.elementtype.def,rd)) then
  574. CGMessage(type_e_set_element_are_not_comp);
  575. end
  576. else
  577. CGMessage(type_e_mismatch)
  578. end
  579. else
  580. begin
  581. if not(p^.treetype in [addn,subn,symdifn,muln,equaln,unequaln
  582. {$IfNDef NoSetInclusion}
  583. ,lten,gten
  584. {$EndIf NoSetInclusion}
  585. ]) then
  586. CGMessage(type_e_set_operation_unknown);
  587. { right def must be a also be set }
  588. if (rd^.deftype<>setdef) or not(is_equal(rd,ld)) then
  589. CGMessage(type_e_set_element_are_not_comp);
  590. end;
  591. { ranges require normsets }
  592. if (psetdef(ld)^.settype=smallset) and
  593. (rt=setelementn) and
  594. assigned(p^.right^.right) then
  595. begin
  596. { generate a temporary normset def }
  597. tempdef:=new(psetdef,init(psetdef(ld)^.elementtype.def,255));
  598. p^.left:=gentypeconvnode(p^.left,tempdef);
  599. firstpass(p^.left);
  600. dispose(tempdef,done);
  601. ld:=p^.left^.resulttype;
  602. end;
  603. { if the destination is not a smallset then insert a typeconv
  604. which loads a smallset into a normal set }
  605. if (psetdef(ld)^.settype<>smallset) and
  606. (psetdef(rd)^.settype=smallset) then
  607. begin
  608. if (p^.right^.treetype=setconstn) then
  609. begin
  610. t:=gensetconstnode(p^.right^.value_set,psetdef(p^.left^.resulttype));
  611. t^.left:=p^.right^.left;
  612. putnode(p^.right);
  613. p^.right:=t;
  614. end
  615. else
  616. p^.right:=gentypeconvnode(p^.right,psetdef(p^.left^.resulttype));
  617. firstpass(p^.right);
  618. end;
  619. { do constant evaluation }
  620. if (p^.right^.treetype=setconstn) and
  621. not assigned(p^.right^.left) and
  622. (p^.left^.treetype=setconstn) and
  623. not assigned(p^.left^.left) then
  624. begin
  625. new(resultset);
  626. case p^.treetype of
  627. addn : begin
  628. for i:=0 to 31 do
  629. resultset^[i]:=
  630. p^.right^.value_set^[i] or p^.left^.value_set^[i];
  631. t:=gensetconstnode(resultset,psetdef(ld));
  632. end;
  633. muln : begin
  634. for i:=0 to 31 do
  635. resultset^[i]:=
  636. p^.right^.value_set^[i] and p^.left^.value_set^[i];
  637. t:=gensetconstnode(resultset,psetdef(ld));
  638. end;
  639. subn : begin
  640. for i:=0 to 31 do
  641. resultset^[i]:=
  642. p^.left^.value_set^[i] and not(p^.right^.value_set^[i]);
  643. t:=gensetconstnode(resultset,psetdef(ld));
  644. end;
  645. symdifn : begin
  646. for i:=0 to 31 do
  647. resultset^[i]:=
  648. p^.left^.value_set^[i] xor p^.right^.value_set^[i];
  649. t:=gensetconstnode(resultset,psetdef(ld));
  650. end;
  651. unequaln : begin
  652. b:=true;
  653. for i:=0 to 31 do
  654. if p^.right^.value_set^[i]=p^.left^.value_set^[i] then
  655. begin
  656. b:=false;
  657. break;
  658. end;
  659. t:=genordinalconstnode(ord(b),booldef);
  660. end;
  661. equaln : begin
  662. b:=true;
  663. for i:=0 to 31 do
  664. if p^.right^.value_set^[i]<>p^.left^.value_set^[i] then
  665. begin
  666. b:=false;
  667. break;
  668. end;
  669. t:=genordinalconstnode(ord(b),booldef);
  670. end;
  671. {$IfNDef NoSetInclusion}
  672. lten : Begin
  673. b := true;
  674. For i := 0 to 31 Do
  675. If (p^.right^.value_set^[i] And p^.left^.value_set^[i]) <>
  676. p^.left^.value_set^[i] Then
  677. Begin
  678. b := false;
  679. Break
  680. End;
  681. t := genordinalconstnode(ord(b),booldef);
  682. End;
  683. gten : Begin
  684. b := true;
  685. For i := 0 to 31 Do
  686. If (p^.left^.value_set^[i] And p^.right^.value_set^[i]) <>
  687. p^.right^.value_set^[i] Then
  688. Begin
  689. b := false;
  690. Break
  691. End;
  692. t := genordinalconstnode(ord(b),booldef);
  693. End;
  694. {$EndIf NoSetInclusion}
  695. end;
  696. dispose(resultset);
  697. disposetree(p);
  698. p:=t;
  699. firstpass(p);
  700. exit;
  701. end
  702. else
  703. if psetdef(ld)^.settype=smallset then
  704. begin
  705. { are we adding set elements ? }
  706. if p^.right^.treetype=setelementn then
  707. calcregisters(p,2,0,0)
  708. else
  709. calcregisters(p,1,0,0);
  710. p^.location.loc:=LOC_REGISTER;
  711. end
  712. else
  713. begin
  714. calcregisters(p,0,0,0);
  715. { here we call SET... }
  716. procinfo^.flags:=procinfo^.flags or pi_do_call;
  717. p^.location.loc:=LOC_MEM;
  718. end;
  719. convdone:=true;
  720. end
  721. else
  722. { compare pchar to char arrays by addresses
  723. like BP/Delphi }
  724. if (is_pchar(ld) and is_chararray(rd)) or
  725. (is_pchar(rd) and is_chararray(ld)) then
  726. begin
  727. if is_chararray(rd) then
  728. begin
  729. p^.right:=gentypeconvnode(p^.right,ld);
  730. firstpass(p^.right);
  731. end
  732. else
  733. begin
  734. p^.left:=gentypeconvnode(p^.left,rd);
  735. firstpass(p^.left);
  736. end;
  737. p^.location.loc:=LOC_REGISTER;
  738. calcregisters(p,1,0,0);
  739. convdone:=true;
  740. end
  741. else
  742. { is one of the operands a string?,
  743. chararrays are also handled as strings (after conversion) }
  744. if (rd^.deftype=stringdef) or (ld^.deftype=stringdef) or
  745. ((is_chararray(rd) or is_char(rd)) and
  746. (is_chararray(ld) or is_char(ld))) then
  747. begin
  748. if is_widestring(rd) or is_widestring(ld) then
  749. begin
  750. if not(is_widestring(rd)) then
  751. p^.right:=gentypeconvnode(p^.right,cwidestringdef);
  752. if not(is_widestring(ld)) then
  753. p^.left:=gentypeconvnode(p^.left,cwidestringdef);
  754. p^.resulttype:=cwidestringdef;
  755. { this is only for add, the comparisaion is handled later }
  756. p^.location.loc:=LOC_REGISTER;
  757. end
  758. else if is_ansistring(rd) or is_ansistring(ld) then
  759. begin
  760. if not(is_ansistring(rd)) then
  761. p^.right:=gentypeconvnode(p^.right,cansistringdef);
  762. if not(is_ansistring(ld)) then
  763. p^.left:=gentypeconvnode(p^.left,cansistringdef);
  764. { we use ansistrings so no fast exit here }
  765. procinfo^.no_fast_exit:=true;
  766. p^.resulttype:=cansistringdef;
  767. { this is only for add, the comparisaion is handled later }
  768. p^.location.loc:=LOC_REGISTER;
  769. end
  770. else if is_longstring(rd) or is_longstring(ld) then
  771. begin
  772. if not(is_longstring(rd)) then
  773. p^.right:=gentypeconvnode(p^.right,clongstringdef);
  774. if not(is_longstring(ld)) then
  775. p^.left:=gentypeconvnode(p^.left,clongstringdef);
  776. p^.resulttype:=clongstringdef;
  777. { this is only for add, the comparisaion is handled later }
  778. p^.location.loc:=LOC_MEM;
  779. end
  780. else
  781. begin
  782. if not(is_shortstring(rd))
  783. {$ifdef newoptimizations2}
  784. {$ifdef i386}
  785. { shortstring + char handled seperately (JM) }
  786. and (not(cs_optimize in aktglobalswitches) or
  787. (p^.treetype <> addn) or not(is_char(rd)))
  788. {$endif i386}
  789. {$endif newoptimizations2}
  790. then
  791. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  792. if not(is_shortstring(ld)) then
  793. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  794. p^.resulttype:=cshortstringdef;
  795. { this is only for add, the comparisaion is handled later }
  796. p^.location.loc:=LOC_MEM;
  797. end;
  798. { only if there is a type cast we need to do again }
  799. { the first pass }
  800. if p^.left^.treetype=typeconvn then
  801. firstpass(p^.left);
  802. if p^.right^.treetype=typeconvn then
  803. firstpass(p^.right);
  804. { here we call STRCONCAT or STRCMP or STRCOPY }
  805. procinfo^.flags:=procinfo^.flags or pi_do_call;
  806. if p^.location.loc=LOC_MEM then
  807. calcregisters(p,0,0,0)
  808. else
  809. calcregisters(p,1,0,0);
  810. {$ifdef i386}
  811. { not always necessary, only if it is not a constant char and }
  812. { not a regvar, but don't know how to check this here (JM) }
  813. if is_char(rd) then
  814. inc(p^.registers32);
  815. {$endif i386}
  816. convdone:=true;
  817. end
  818. else
  819. { is one a real float ? }
  820. if (rd^.deftype=floatdef) or (ld^.deftype=floatdef) then
  821. begin
  822. { if one is a fixed, then convert to f32bit }
  823. if ((rd^.deftype=floatdef) and (pfloatdef(rd)^.typ=f32bit)) or
  824. ((ld^.deftype=floatdef) and (pfloatdef(ld)^.typ=f32bit)) then
  825. begin
  826. if not is_integer(rd) or (p^.treetype<>muln) then
  827. p^.right:=gentypeconvnode(p^.right,s32fixeddef);
  828. if not is_integer(ld) or (p^.treetype<>muln) then
  829. p^.left:=gentypeconvnode(p^.left,s32fixeddef);
  830. firstpass(p^.left);
  831. firstpass(p^.right);
  832. calcregisters(p,1,0,0);
  833. p^.location.loc:=LOC_REGISTER;
  834. end
  835. else
  836. { convert both to bestreal }
  837. begin
  838. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  839. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  840. firstpass(p^.left);
  841. firstpass(p^.right);
  842. calcregisters(p,0,1,0);
  843. p^.location.loc:=LOC_FPU;
  844. end;
  845. convdone:=true;
  846. end
  847. else
  848. { pointer comperation and subtraction }
  849. if (rd^.deftype=pointerdef) and (ld^.deftype=pointerdef) then
  850. begin
  851. p^.location.loc:=LOC_REGISTER;
  852. { p^.right:=gentypeconvnode(p^.right,ld); }
  853. { firstpass(p^.right); }
  854. calcregisters(p,1,0,0);
  855. case p^.treetype of
  856. equaln,unequaln :
  857. begin
  858. if is_equal(p^.right^.resulttype,voidpointerdef) then
  859. begin
  860. p^.right:=gentypeconvnode(p^.right,ld);
  861. firstpass(p^.right);
  862. end
  863. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  864. begin
  865. p^.left:=gentypeconvnode(p^.left,rd);
  866. firstpass(p^.left);
  867. end
  868. else if not(is_equal(ld,rd)) then
  869. CGMessage(type_e_mismatch);
  870. end;
  871. ltn,lten,gtn,gten:
  872. begin
  873. if is_equal(p^.right^.resulttype,voidpointerdef) then
  874. begin
  875. p^.right:=gentypeconvnode(p^.right,ld);
  876. firstpass(p^.right);
  877. end
  878. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  879. begin
  880. p^.left:=gentypeconvnode(p^.left,rd);
  881. firstpass(p^.left);
  882. end
  883. else if not(is_equal(ld,rd)) then
  884. CGMessage(type_e_mismatch);
  885. if not(cs_extsyntax in aktmoduleswitches) then
  886. CGMessage(type_e_mismatch);
  887. end;
  888. subn:
  889. begin
  890. if not(is_equal(ld,rd)) then
  891. CGMessage(type_e_mismatch);
  892. if not(cs_extsyntax in aktmoduleswitches) then
  893. CGMessage(type_e_mismatch);
  894. p^.resulttype:=s32bitdef;
  895. exit;
  896. end;
  897. else CGMessage(type_e_mismatch);
  898. end;
  899. convdone:=true;
  900. end
  901. else
  902. if (rd^.deftype=objectdef) and (ld^.deftype=objectdef) and
  903. pobjectdef(rd)^.is_class and pobjectdef(ld)^.is_class then
  904. begin
  905. p^.location.loc:=LOC_REGISTER;
  906. if pobjectdef(rd)^.is_related(pobjectdef(ld)) then
  907. p^.right:=gentypeconvnode(p^.right,ld)
  908. else
  909. p^.left:=gentypeconvnode(p^.left,rd);
  910. firstpass(p^.right);
  911. firstpass(p^.left);
  912. calcregisters(p,1,0,0);
  913. case p^.treetype of
  914. equaln,unequaln : ;
  915. else CGMessage(type_e_mismatch);
  916. end;
  917. convdone:=true;
  918. end
  919. else
  920. if (rd^.deftype=classrefdef) and (ld^.deftype=classrefdef) then
  921. begin
  922. p^.location.loc:=LOC_REGISTER;
  923. if pobjectdef(pclassrefdef(rd)^.pointertype.def)^.is_related(pobjectdef(
  924. pclassrefdef(ld)^.pointertype.def)) then
  925. p^.right:=gentypeconvnode(p^.right,ld)
  926. else
  927. p^.left:=gentypeconvnode(p^.left,rd);
  928. firstpass(p^.right);
  929. firstpass(p^.left);
  930. calcregisters(p,1,0,0);
  931. case p^.treetype of
  932. equaln,unequaln : ;
  933. else CGMessage(type_e_mismatch);
  934. end;
  935. convdone:=true;
  936. end
  937. else
  938. { allows comperasion with nil pointer }
  939. if (rd^.deftype=objectdef) and
  940. pobjectdef(rd)^.is_class then
  941. begin
  942. p^.location.loc:=LOC_REGISTER;
  943. p^.left:=gentypeconvnode(p^.left,rd);
  944. firstpass(p^.left);
  945. calcregisters(p,1,0,0);
  946. case p^.treetype of
  947. equaln,unequaln : ;
  948. else CGMessage(type_e_mismatch);
  949. end;
  950. convdone:=true;
  951. end
  952. else
  953. if (ld^.deftype=objectdef) and
  954. pobjectdef(ld)^.is_class then
  955. begin
  956. p^.location.loc:=LOC_REGISTER;
  957. p^.right:=gentypeconvnode(p^.right,ld);
  958. firstpass(p^.right);
  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 (rd^.deftype=classrefdef) then
  968. begin
  969. p^.left:=gentypeconvnode(p^.left,rd);
  970. firstpass(p^.left);
  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 (ld^.deftype=classrefdef) then
  980. begin
  981. p^.right:=gentypeconvnode(p^.right,ld);
  982. firstpass(p^.right);
  983. calcregisters(p,1,0,0);
  984. case p^.treetype of
  985. equaln,unequaln : ;
  986. else
  987. CGMessage(type_e_mismatch);
  988. end;
  989. convdone:=true;
  990. end
  991. else
  992. { support procvar=nil,procvar<>nil }
  993. if ((ld^.deftype=procvardef) and (rt=niln)) or
  994. ((rd^.deftype=procvardef) and (lt=niln)) then
  995. begin
  996. calcregisters(p,1,0,0);
  997. p^.location.loc:=LOC_REGISTER;
  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. {$ifdef SUPPORT_MMX}
  1007. if (cs_mmx in aktlocalswitches) and is_mmx_able_array(ld) and
  1008. is_mmx_able_array(rd) and is_equal(ld,rd) then
  1009. begin
  1010. firstpass(p^.right);
  1011. firstpass(p^.left);
  1012. case p^.treetype of
  1013. addn,subn,xorn,orn,andn:
  1014. ;
  1015. { mul is a little bit restricted }
  1016. muln:
  1017. if not(mmx_type(p^.left^.resulttype) in
  1018. [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1019. CGMessage(type_e_mismatch);
  1020. else
  1021. CGMessage(type_e_mismatch);
  1022. end;
  1023. p^.location.loc:=LOC_MMXREGISTER;
  1024. calcregisters(p,0,0,1);
  1025. convdone:=true;
  1026. end
  1027. else
  1028. {$endif SUPPORT_MMX}
  1029. { this is a little bit dangerous, also the left type }
  1030. { should be checked! This broke the mmx support }
  1031. if (rd^.deftype=pointerdef) or
  1032. is_zero_based_array(rd) then
  1033. begin
  1034. if is_zero_based_array(rd) then
  1035. begin
  1036. p^.resulttype:=new(ppointerdef,init(parraydef(rd)^.elementtype));
  1037. p^.right:=gentypeconvnode(p^.right,p^.resulttype);
  1038. firstpass(p^.right);
  1039. end;
  1040. p^.location.loc:=LOC_REGISTER;
  1041. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1042. firstpass(p^.left);
  1043. calcregisters(p,1,0,0);
  1044. if p^.treetype=addn then
  1045. begin
  1046. if not(cs_extsyntax in aktmoduleswitches) or
  1047. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1048. CGMessage(type_e_mismatch);
  1049. { Dirty hack, to support multiple firstpasses (PFV) }
  1050. if (p^.resulttype=nil) and
  1051. (rd^.deftype=pointerdef) and
  1052. (ppointerdef(rd)^.pointertype.def^.size>1) then
  1053. begin
  1054. p^.left:=gennode(muln,p^.left,genordinalconstnode(ppointerdef(rd)^.pointertype.def^.size,s32bitdef));
  1055. firstpass(p^.left);
  1056. end;
  1057. end
  1058. else
  1059. CGMessage(type_e_mismatch);
  1060. convdone:=true;
  1061. end
  1062. else
  1063. if (ld^.deftype=pointerdef) or
  1064. is_zero_based_array(ld) then
  1065. begin
  1066. if is_zero_based_array(ld) then
  1067. begin
  1068. p^.resulttype:=new(ppointerdef,init(parraydef(ld)^.elementtype));
  1069. p^.left:=gentypeconvnode(p^.left,p^.resulttype);
  1070. firstpass(p^.left);
  1071. end;
  1072. p^.location.loc:=LOC_REGISTER;
  1073. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1074. firstpass(p^.right);
  1075. calcregisters(p,1,0,0);
  1076. case p^.treetype of
  1077. addn,subn : begin
  1078. if not(cs_extsyntax in aktmoduleswitches) or
  1079. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1080. CGMessage(type_e_mismatch);
  1081. { Dirty hack, to support multiple firstpasses (PFV) }
  1082. if (p^.resulttype=nil) and
  1083. (ld^.deftype=pointerdef) and
  1084. (ppointerdef(ld)^.pointertype.def^.size>1) then
  1085. begin
  1086. p^.right:=gennode(muln,p^.right,
  1087. genordinalconstnode(ppointerdef(ld)^.pointertype.def^.size,s32bitdef));
  1088. firstpass(p^.right);
  1089. end;
  1090. end;
  1091. else
  1092. CGMessage(type_e_mismatch);
  1093. end;
  1094. convdone:=true;
  1095. end
  1096. else
  1097. if (rd^.deftype=procvardef) and (ld^.deftype=procvardef) and is_equal(rd,ld) then
  1098. begin
  1099. calcregisters(p,1,0,0);
  1100. p^.location.loc:=LOC_REGISTER;
  1101. case p^.treetype of
  1102. equaln,unequaln : ;
  1103. else
  1104. CGMessage(type_e_mismatch);
  1105. end;
  1106. convdone:=true;
  1107. end
  1108. else
  1109. if (ld^.deftype=enumdef) and (rd^.deftype=enumdef) then
  1110. begin
  1111. if not(is_equal(ld,rd)) then
  1112. begin
  1113. p^.right:=gentypeconvnode(p^.right,ld);
  1114. firstpass(p^.right);
  1115. end;
  1116. calcregisters(p,1,0,0);
  1117. case p^.treetype of
  1118. equaln,unequaln,
  1119. ltn,lten,gtn,gten : ;
  1120. else CGMessage(type_e_mismatch);
  1121. end;
  1122. convdone:=true;
  1123. end;
  1124. { the general solution is to convert to 32 bit int }
  1125. if not convdone then
  1126. begin
  1127. { but an int/int gives real/real! }
  1128. if p^.treetype=slashn then
  1129. begin
  1130. CGMessage(type_h_use_div_for_int);
  1131. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  1132. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  1133. firstpass(p^.left);
  1134. firstpass(p^.right);
  1135. { maybe we need an integer register to save }
  1136. { a reference }
  1137. if ((p^.left^.location.loc<>LOC_FPU) or
  1138. (p^.right^.location.loc<>LOC_FPU)) and
  1139. (p^.left^.registers32=p^.right^.registers32) then
  1140. calcregisters(p,1,1,0)
  1141. else
  1142. calcregisters(p,0,1,0);
  1143. p^.location.loc:=LOC_FPU;
  1144. end
  1145. else
  1146. begin
  1147. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1148. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1149. firstpass(p^.left);
  1150. firstpass(p^.right);
  1151. calcregisters(p,1,0,0);
  1152. p^.location.loc:=LOC_REGISTER;
  1153. end;
  1154. end;
  1155. if codegenerror then
  1156. exit;
  1157. { determines result type for comparions }
  1158. { here the is a problem with multiple passes }
  1159. { example length(s)+1 gets internal 'longint' type first }
  1160. { if it is a arg it is converted to 'LONGINT' }
  1161. { but a second first pass will reset this to 'longint' }
  1162. case p^.treetype of
  1163. ltn,lten,gtn,gten,equaln,unequaln:
  1164. begin
  1165. if (not assigned(p^.resulttype)) or
  1166. (p^.resulttype^.deftype=stringdef) then
  1167. p^.resulttype:=booldef;
  1168. if is_64bitint(p^.left^.resulttype) then
  1169. p^.location.loc:=LOC_JUMP
  1170. else
  1171. p^.location.loc:=LOC_FLAGS;
  1172. end;
  1173. xorn:
  1174. begin
  1175. if not assigned(p^.resulttype) then
  1176. p^.resulttype:=p^.left^.resulttype;
  1177. p^.location.loc:=LOC_REGISTER;
  1178. end;
  1179. addn:
  1180. begin
  1181. if not assigned(p^.resulttype) then
  1182. begin
  1183. { for strings, return is always a 255 char string }
  1184. if is_shortstring(p^.left^.resulttype) then
  1185. p^.resulttype:=cshortstringdef
  1186. else
  1187. p^.resulttype:=p^.left^.resulttype;
  1188. end;
  1189. end;
  1190. {$ifdef cardinalmulfix}
  1191. muln:
  1192. { if we multiply an unsigned with a signed number, the result is signed }
  1193. { in the other cases, the result remains signed or unsigned depending on }
  1194. { the multiplication factors (JM) }
  1195. if (p^.left^.resulttype^.deftype = orddef) and
  1196. (p^.right^.resulttype^.deftype = orddef) and
  1197. is_signed(p^.right^.resulttype) then
  1198. p^.resulttype := p^.right^.resulttype
  1199. else p^.resulttype := p^.left^.resulttype;
  1200. (*
  1201. subn:
  1202. { if we substract a u32bit from a positive constant, the result becomes }
  1203. { s32bit as well (JM) }
  1204. begin
  1205. if (p^.right^.resulttype^.deftype = orddef) and
  1206. (p^.left^.resulttype^.deftype = orddef) and
  1207. (porddef(p^.right^.resulttype)^.typ = u32bit) and
  1208. is_constintnode(p^.left) and
  1209. { (porddef(p^.left^.resulttype)^.typ <> u32bit) and}
  1210. (p^.left^.value > 0) then
  1211. begin
  1212. p^.left := gentypeconvnode(p^.left,u32bitdef);
  1213. firstpass(p^.left);
  1214. end;
  1215. p^.resulttype:=p^.left^.resulttype;
  1216. end;
  1217. *)
  1218. {$endif cardinalmulfix}
  1219. else
  1220. p^.resulttype:=p^.left^.resulttype;
  1221. end;
  1222. end;
  1223. end.
  1224. {
  1225. $Log$
  1226. Revision 1.3 2000-07-14 05:11:49 michael
  1227. + Patch to 1.1
  1228. Revision 1.2 2000/07/13 11:32:50 michael
  1229. + removed logs
  1230. }