tcadd.pas 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  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. hcodegen,htypechk,pass_1,
  30. cpubase,tccnv
  31. ;
  32. function isbinaryoverloaded(var p : ptree) : boolean;
  33. var
  34. rd,ld : pdef;
  35. t : ptree;
  36. optoken : ttoken;
  37. begin
  38. isbinaryoverloaded:=false;
  39. { overloaded operator ? }
  40. { load easier access variables }
  41. rd:=p^.right^.resulttype;
  42. ld:=p^.left^.resulttype;
  43. if (p^.treetype=starstarn) or
  44. (ld^.deftype=recorddef) or
  45. ((ld^.deftype=arraydef) and
  46. not((cs_mmx in aktlocalswitches) and
  47. is_mmx_able_array(ld)) and
  48. (not (rd^.deftype in [orddef])) and
  49. (not is_chararray(ld))
  50. ) or
  51. { <> and = are defined for classes }
  52. ((ld^.deftype=objectdef) and
  53. (not(pobjectdef(ld)^.is_class) or
  54. not(p^.treetype in [equaln,unequaln])
  55. )
  56. ) or
  57. (rd^.deftype=recorddef) or
  58. ((rd^.deftype=arraydef) and
  59. not((cs_mmx in aktlocalswitches) and
  60. is_mmx_able_array(rd)) and
  61. (not (ld^.deftype in [orddef])) and
  62. (not is_chararray(rd))
  63. ) or
  64. { <> and = are defined for classes }
  65. ((rd^.deftype=objectdef) and
  66. (not(pobjectdef(rd)^.is_class) or
  67. not(p^.treetype in [equaln,unequaln])
  68. )
  69. ) then
  70. begin
  71. isbinaryoverloaded:=true;
  72. {!!!!!!!!! handle paras }
  73. case p^.treetype of
  74. { the nil as symtable signs firstcalln that this is
  75. an overloaded operator }
  76. addn:
  77. optoken:=_PLUS;
  78. subn:
  79. optoken:=_MINUS;
  80. muln:
  81. optoken:=_STAR;
  82. starstarn:
  83. optoken:=_STARSTAR;
  84. slashn:
  85. optoken:=_SLASH;
  86. ltn:
  87. optoken:=tokens._lt;
  88. gtn:
  89. optoken:=tokens._gt;
  90. lten:
  91. optoken:=_lte;
  92. gten:
  93. optoken:=_gte;
  94. equaln,unequaln :
  95. optoken:=_EQUAL;
  96. symdifn :
  97. optoken:=_SYMDIF;
  98. modn :
  99. optoken:=_OP_MOD;
  100. orn :
  101. optoken:=_OP_OR;
  102. xorn :
  103. optoken:=_OP_XOR;
  104. andn :
  105. optoken:=_OP_AND;
  106. divn :
  107. optoken:=_OP_DIV;
  108. shln :
  109. optoken:=_OP_SHL;
  110. shrn :
  111. optoken:=_OP_SHR;
  112. else
  113. exit;
  114. end;
  115. t:=gencallnode(overloaded_operators[optoken],nil);
  116. { we have to convert p^.left and p^.right into
  117. callparanodes }
  118. if t^.symtableprocentry=nil then
  119. begin
  120. CGMessage(parser_e_operator_not_overloaded);
  121. putnode(t);
  122. end
  123. else
  124. begin
  125. inc(t^.symtableprocentry^.refs);
  126. t^.left:=gencallparanode(p^.left,nil);
  127. t^.left:=gencallparanode(p^.right,t^.left);
  128. if p^.treetype=unequaln then
  129. t:=gensinglenode(notn,t);
  130. firstpass(t);
  131. putnode(p);
  132. p:=t;
  133. end;
  134. end;
  135. end;
  136. {*****************************************************************************
  137. FirstAdd
  138. *****************************************************************************}
  139. procedure firstadd(var p : ptree);
  140. procedure make_bool_equal_size(var p:ptree);
  141. begin
  142. if porddef(p^.left^.resulttype)^.typ>porddef(p^.right^.resulttype)^.typ then
  143. begin
  144. p^.right:=gentypeconvnode(p^.right,porddef(p^.left^.resulttype));
  145. p^.right^.convtyp:=tc_bool_2_int;
  146. p^.right^.explizit:=true;
  147. firstpass(p^.right);
  148. end
  149. else
  150. if porddef(p^.left^.resulttype)^.typ<porddef(p^.right^.resulttype)^.typ then
  151. begin
  152. p^.left:=gentypeconvnode(p^.left,porddef(p^.right^.resulttype));
  153. p^.left^.convtyp:=tc_bool_2_int;
  154. p^.left^.explizit:=true;
  155. firstpass(p^.left);
  156. end;
  157. end;
  158. var
  159. t,hp : ptree;
  160. ot,
  161. lt,rt : ttreetyp;
  162. rv,lv : longint;
  163. rvd,lvd : bestreal;
  164. resdef,
  165. rd,ld : pdef;
  166. tempdef : pdef;
  167. concatstrings : boolean;
  168. { to evalute const sets }
  169. resultset : pconstset;
  170. i : longint;
  171. b : boolean;
  172. convdone : boolean;
  173. s1,s2 : pchar;
  174. l1,l2 : longint;
  175. begin
  176. { first do the two subtrees }
  177. firstpass(p^.left);
  178. firstpass(p^.right);
  179. if codegenerror then
  180. exit;
  181. { convert array constructors to sets, because there is no other operator
  182. possible for array constructors }
  183. if is_array_constructor(p^.left^.resulttype) then
  184. arrayconstructor_to_set(p^.left);
  185. if is_array_constructor(p^.right^.resulttype) then
  186. arrayconstructor_to_set(p^.right);
  187. { both left and right need to be valid }
  188. set_varstate(p^.left,true);
  189. set_varstate(p^.right,true);
  190. { load easier access variables }
  191. lt:=p^.left^.treetype;
  192. rt:=p^.right^.treetype;
  193. rd:=p^.right^.resulttype;
  194. ld:=p^.left^.resulttype;
  195. convdone:=false;
  196. if isbinaryoverloaded(p) then
  197. exit;
  198. { compact consts }
  199. { convert int consts to real consts, if the }
  200. { other operand is a real const }
  201. if (rt=realconstn) and is_constintnode(p^.left) then
  202. begin
  203. t:=genrealconstnode(p^.left^.value,p^.right^.resulttype);
  204. disposetree(p^.left);
  205. p^.left:=t;
  206. lt:=realconstn;
  207. end;
  208. if (lt=realconstn) and is_constintnode(p^.right) then
  209. begin
  210. t:=genrealconstnode(p^.right^.value,p^.left^.resulttype);
  211. disposetree(p^.right);
  212. p^.right:=t;
  213. rt:=realconstn;
  214. end;
  215. { both are int constants, also allow operations on two equal enums
  216. in fpc mode (Needed for conversion of C code) }
  217. if ((lt=ordconstn) and (rt=ordconstn)) and
  218. ((is_constintnode(p^.left) and is_constintnode(p^.right)) or
  219. (is_constboolnode(p^.left) and is_constboolnode(p^.right) and
  220. (p^.treetype in [ltn,lten,gtn,gten,equaln,unequaln,andn,xorn,orn]))) then
  221. begin
  222. { return a boolean for boolean operations (and,xor,or) }
  223. if is_constboolnode(p^.left) then
  224. resdef:=booldef
  225. else
  226. resdef:=s32bitdef;
  227. lv:=p^.left^.value;
  228. rv:=p^.right^.value;
  229. case p^.treetype of
  230. addn : t:=genordinalconstnode(lv+rv,resdef);
  231. subn : t:=genordinalconstnode(lv-rv,resdef);
  232. muln : t:=genordinalconstnode(lv*rv,resdef);
  233. xorn : t:=genordinalconstnode(lv xor rv,resdef);
  234. orn : t:=genordinalconstnode(lv or rv,resdef);
  235. andn : t:=genordinalconstnode(lv and rv,resdef);
  236. ltn : t:=genordinalconstnode(ord(lv<rv),booldef);
  237. lten : t:=genordinalconstnode(ord(lv<=rv),booldef);
  238. gtn : t:=genordinalconstnode(ord(lv>rv),booldef);
  239. gten : t:=genordinalconstnode(ord(lv>=rv),booldef);
  240. equaln : t:=genordinalconstnode(ord(lv=rv),booldef);
  241. unequaln : t:=genordinalconstnode(ord(lv<>rv),booldef);
  242. slashn : begin
  243. { int/int becomes a real }
  244. if int(rv)=0 then
  245. begin
  246. Message(parser_e_invalid_float_operation);
  247. t:=genrealconstnode(0,bestrealdef^);
  248. end
  249. else
  250. t:=genrealconstnode(int(lv)/int(rv),bestrealdef^);
  251. firstpass(t);
  252. end;
  253. else
  254. CGMessage(type_e_mismatch);
  255. end;
  256. disposetree(p);
  257. firstpass(t);
  258. p:=t;
  259. exit;
  260. end;
  261. { both real constants ? }
  262. if (lt=realconstn) and (rt=realconstn) then
  263. begin
  264. lvd:=p^.left^.value_real;
  265. rvd:=p^.right^.value_real;
  266. case p^.treetype of
  267. addn : t:=genrealconstnode(lvd+rvd,bestrealdef^);
  268. subn : t:=genrealconstnode(lvd-rvd,bestrealdef^);
  269. muln : t:=genrealconstnode(lvd*rvd,bestrealdef^);
  270. starstarn,
  271. caretn : begin
  272. if lvd<0 then
  273. begin
  274. Message(parser_e_invalid_float_operation);
  275. t:=genrealconstnode(0,bestrealdef^);
  276. end
  277. else if lvd=0 then
  278. t:=genrealconstnode(1.0,bestrealdef^)
  279. else
  280. t:=genrealconstnode(exp(ln(lvd)*rvd),bestrealdef^);
  281. end;
  282. slashn :
  283. begin
  284. if rvd=0 then
  285. begin
  286. Message(parser_e_invalid_float_operation);
  287. t:=genrealconstnode(0,bestrealdef^);
  288. end
  289. else
  290. t:=genrealconstnode(lvd/rvd,bestrealdef^);
  291. end;
  292. ltn : t:=genordinalconstnode(ord(lvd<rvd),booldef);
  293. lten : t:=genordinalconstnode(ord(lvd<=rvd),booldef);
  294. gtn : t:=genordinalconstnode(ord(lvd>rvd),booldef);
  295. gten : t:=genordinalconstnode(ord(lvd>=rvd),booldef);
  296. equaln : t:=genordinalconstnode(ord(lvd=rvd),booldef);
  297. unequaln : t:=genordinalconstnode(ord(lvd<>rvd),booldef);
  298. else
  299. CGMessage(type_e_mismatch);
  300. end;
  301. disposetree(p);
  302. p:=t;
  303. firstpass(p);
  304. exit;
  305. end;
  306. { concating strings ? }
  307. concatstrings:=false;
  308. s1:=nil;
  309. s2:=nil;
  310. if (lt=ordconstn) and (rt=ordconstn) and
  311. is_char(ld) and is_char(rd) then
  312. begin
  313. s1:=strpnew(char(byte(p^.left^.value)));
  314. s2:=strpnew(char(byte(p^.right^.value)));
  315. l1:=1;
  316. l2:=1;
  317. concatstrings:=true;
  318. end
  319. else
  320. if (lt=stringconstn) and (rt=ordconstn) and is_char(rd) then
  321. begin
  322. s1:=getpcharcopy(p^.left);
  323. l1:=p^.left^.length;
  324. s2:=strpnew(char(byte(p^.right^.value)));
  325. l2:=1;
  326. concatstrings:=true;
  327. end
  328. else
  329. if (lt=ordconstn) and (rt=stringconstn) and is_char(ld) then
  330. begin
  331. s1:=strpnew(char(byte(p^.left^.value)));
  332. l1:=1;
  333. s2:=getpcharcopy(p^.right);
  334. l2:=p^.right^.length;
  335. concatstrings:=true;
  336. end
  337. else if (lt=stringconstn) and (rt=stringconstn) then
  338. begin
  339. s1:=getpcharcopy(p^.left);
  340. l1:=p^.left^.length;
  341. s2:=getpcharcopy(p^.right);
  342. l2:=p^.right^.length;
  343. concatstrings:=true;
  344. end;
  345. { I will need to translate all this to ansistrings !!! }
  346. if concatstrings then
  347. begin
  348. case p^.treetype of
  349. addn :
  350. t:=genpcharconstnode(concatansistrings(s1,s2,l1,l2),l1+l2);
  351. ltn :
  352. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)<0),booldef);
  353. lten :
  354. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)<=0),booldef);
  355. gtn :
  356. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)>0),booldef);
  357. gten :
  358. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)>=0),booldef);
  359. equaln :
  360. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)=0),booldef);
  361. unequaln :
  362. t:=genordinalconstnode(byte(compareansistrings(s1,s2,l1,l2)<>0),booldef);
  363. end;
  364. ansistringdispose(s1,l1);
  365. ansistringdispose(s2,l2);
  366. disposetree(p);
  367. firstpass(t);
  368. p:=t;
  369. exit;
  370. end;
  371. { if both are orddefs then check sub types }
  372. if (ld^.deftype=orddef) and (rd^.deftype=orddef) then
  373. begin
  374. { 2 booleans ? }
  375. if is_boolean(ld) and is_boolean(rd) then
  376. begin
  377. case p^.treetype of
  378. andn,
  379. orn:
  380. begin
  381. calcregisters(p,0,0,0);
  382. make_bool_equal_size(p);
  383. p^.location.loc:=LOC_JUMP;
  384. end;
  385. xorn,ltn,lten,gtn,gten :
  386. begin
  387. make_bool_equal_size(p);
  388. if (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) and
  389. (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) then
  390. calcregisters(p,2,0,0)
  391. else
  392. calcregisters(p,1,0,0);
  393. end;
  394. unequaln,
  395. equaln:
  396. begin
  397. make_bool_equal_size(p);
  398. { Remove any compares with constants }
  399. if (p^.left^.treetype=ordconstn) then
  400. begin
  401. hp:=p^.right;
  402. b:=(p^.left^.value<>0);
  403. ot:=p^.treetype;
  404. disposetree(p^.left);
  405. putnode(p);
  406. p:=hp;
  407. if (not(b) and (ot=equaln)) or
  408. (b and (ot=unequaln)) then
  409. begin
  410. p:=gensinglenode(notn,p);
  411. firstpass(p);
  412. end;
  413. exit;
  414. end;
  415. if (p^.right^.treetype=ordconstn) then
  416. begin
  417. hp:=p^.left;
  418. b:=(p^.right^.value<>0);
  419. ot:=p^.treetype;
  420. disposetree(p^.right);
  421. putnode(p);
  422. p:=hp;
  423. if (not(b) and (ot=equaln)) or
  424. (b and (ot=unequaln)) then
  425. begin
  426. p:=gensinglenode(notn,p);
  427. firstpass(p);
  428. end;
  429. exit;
  430. end;
  431. if (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) and
  432. (p^.left^.location.loc in [LOC_JUMP,LOC_FLAGS]) then
  433. calcregisters(p,2,0,0)
  434. else
  435. calcregisters(p,1,0,0);
  436. end;
  437. else
  438. CGMessage(type_e_mismatch);
  439. end;
  440. { these one can't be in flags! }
  441. if p^.treetype in [xorn,unequaln,equaln] then
  442. begin
  443. if p^.left^.location.loc=LOC_FLAGS then
  444. begin
  445. p^.left:=gentypeconvnode(p^.left,porddef(p^.left^.resulttype));
  446. p^.left^.convtyp:=tc_bool_2_int;
  447. p^.left^.explizit:=true;
  448. firstpass(p^.left);
  449. end;
  450. if p^.right^.location.loc=LOC_FLAGS then
  451. begin
  452. p^.right:=gentypeconvnode(p^.right,porddef(p^.right^.resulttype));
  453. p^.right^.convtyp:=tc_bool_2_int;
  454. p^.right^.explizit:=true;
  455. firstpass(p^.right);
  456. end;
  457. { readjust registers }
  458. calcregisters(p,1,0,0);
  459. end;
  460. convdone:=true;
  461. end
  462. else
  463. { Both are chars? only convert to shortstrings for addn }
  464. if is_char(rd) and is_char(ld) then
  465. begin
  466. if p^.treetype=addn then
  467. begin
  468. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  469. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  470. firstpass(p^.left);
  471. firstpass(p^.right);
  472. { here we call STRCOPY }
  473. procinfo^.flags:=procinfo^.flags or pi_do_call;
  474. calcregisters(p,0,0,0);
  475. p^.location.loc:=LOC_MEM;
  476. end
  477. else
  478. calcregisters(p,1,0,0);
  479. convdone:=true;
  480. end
  481. { is there a 64 bit type ? }
  482. else if (porddef(rd)^.typ=s64bit) or (porddef(ld)^.typ=s64bit) then
  483. begin
  484. if (porddef(ld)^.typ<>s64bit) then
  485. begin
  486. p^.left:=gentypeconvnode(p^.left,cs64bitdef);
  487. firstpass(p^.left);
  488. end;
  489. if (porddef(rd)^.typ<>s64bit) then
  490. begin
  491. p^.right:=gentypeconvnode(p^.right,cs64bitdef);
  492. firstpass(p^.right);
  493. end;
  494. calcregisters(p,2,0,0);
  495. convdone:=true;
  496. end
  497. else if (porddef(rd)^.typ=u64bit) or (porddef(ld)^.typ=u64bit) then
  498. begin
  499. if (porddef(ld)^.typ<>u64bit) then
  500. begin
  501. p^.left:=gentypeconvnode(p^.left,cu64bitdef);
  502. firstpass(p^.left);
  503. end;
  504. if (porddef(rd)^.typ<>u64bit) then
  505. begin
  506. p^.right:=gentypeconvnode(p^.right,cu64bitdef);
  507. firstpass(p^.right);
  508. end;
  509. calcregisters(p,2,0,0);
  510. convdone:=true;
  511. end
  512. else
  513. { is there a cardinal? }
  514. if (porddef(rd)^.typ=u32bit) or (porddef(ld)^.typ=u32bit) 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 is_constintnode(p^.left) and
  549. ((p^.treetype <> subn) and
  550. (p^.left^.value > 0)) then
  551. p^.left:=gentypeconvnode(p^.left,u32bitdef)
  552. else
  553. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  554. firstpass(p^.left);
  555. end
  556. else {if (porddef(ld)^.typ=u32bit) then}
  557. begin
  558. { can we make them both unsigned? }
  559. if 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 }
  609. tempdef:=new(psetdef,init(psetdef(ld)^.elementtype.def,255));
  610. p^.left:=gentypeconvnode(p^.left,tempdef);
  611. firstpass(p^.left);
  612. dispose(tempdef,done);
  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. calcregisters(p,1,0,0);
  718. { are we adding set elements ? }
  719. if p^.right^.treetype=setelementn then
  720. begin
  721. { we need at least two registers PM }
  722. if p^.registers32<2 then
  723. p^.registers32:=2;
  724. end;
  725. p^.location.loc:=LOC_REGISTER;
  726. end
  727. else
  728. begin
  729. calcregisters(p,0,0,0);
  730. { here we call SET... }
  731. procinfo^.flags:=procinfo^.flags or pi_do_call;
  732. p^.location.loc:=LOC_MEM;
  733. end;
  734. convdone:=true;
  735. end
  736. else
  737. { is one of the operands a string?,
  738. chararrays are also handled as strings (after conversion) }
  739. if (rd^.deftype=stringdef) or (ld^.deftype=stringdef) or
  740. ((is_chararray(rd) or is_char(rd)) and
  741. (is_chararray(ld) or is_char(ld))) then
  742. begin
  743. if is_widestring(rd) or is_widestring(ld) then
  744. begin
  745. if not(is_widestring(rd)) then
  746. p^.right:=gentypeconvnode(p^.right,cwidestringdef);
  747. if not(is_widestring(ld)) then
  748. p^.left:=gentypeconvnode(p^.left,cwidestringdef);
  749. p^.resulttype:=cwidestringdef;
  750. { this is only for add, the comparisaion is handled later }
  751. p^.location.loc:=LOC_REGISTER;
  752. end
  753. else if is_ansistring(rd) or is_ansistring(ld) then
  754. begin
  755. if not(is_ansistring(rd)) then
  756. p^.right:=gentypeconvnode(p^.right,cansistringdef);
  757. if not(is_ansistring(ld)) then
  758. p^.left:=gentypeconvnode(p^.left,cansistringdef);
  759. { we use ansistrings so no fast exit here }
  760. procinfo^.no_fast_exit:=true;
  761. p^.resulttype:=cansistringdef;
  762. { this is only for add, the comparisaion is handled later }
  763. p^.location.loc:=LOC_REGISTER;
  764. end
  765. else if is_longstring(rd) or is_longstring(ld) then
  766. begin
  767. if not(is_longstring(rd)) then
  768. p^.right:=gentypeconvnode(p^.right,clongstringdef);
  769. if not(is_longstring(ld)) then
  770. p^.left:=gentypeconvnode(p^.left,clongstringdef);
  771. p^.resulttype:=clongstringdef;
  772. { this is only for add, the comparisaion is handled later }
  773. p^.location.loc:=LOC_MEM;
  774. end
  775. else
  776. begin
  777. if not(is_shortstring(rd)) then
  778. p^.right:=gentypeconvnode(p^.right,cshortstringdef);
  779. if not(is_shortstring(ld)) then
  780. p^.left:=gentypeconvnode(p^.left,cshortstringdef);
  781. p^.resulttype:=cshortstringdef;
  782. { this is only for add, the comparisaion is handled later }
  783. p^.location.loc:=LOC_MEM;
  784. end;
  785. { only if there is a type cast we need to do again }
  786. { the first pass }
  787. if p^.left^.treetype=typeconvn then
  788. firstpass(p^.left);
  789. if p^.right^.treetype=typeconvn then
  790. firstpass(p^.right);
  791. { here we call STRCONCAT or STRCMP or STRCOPY }
  792. procinfo^.flags:=procinfo^.flags or pi_do_call;
  793. if p^.location.loc=LOC_MEM then
  794. calcregisters(p,0,0,0)
  795. else
  796. calcregisters(p,1,0,0);
  797. convdone:=true;
  798. end
  799. else
  800. { is one a real float ? }
  801. if (rd^.deftype=floatdef) or (ld^.deftype=floatdef) then
  802. begin
  803. { if one is a fixed, then convert to f32bit }
  804. if ((rd^.deftype=floatdef) and (pfloatdef(rd)^.typ=f32bit)) or
  805. ((ld^.deftype=floatdef) and (pfloatdef(ld)^.typ=f32bit)) then
  806. begin
  807. if not is_integer(rd) or (p^.treetype<>muln) then
  808. p^.right:=gentypeconvnode(p^.right,s32fixeddef);
  809. if not is_integer(ld) or (p^.treetype<>muln) then
  810. p^.left:=gentypeconvnode(p^.left,s32fixeddef);
  811. firstpass(p^.left);
  812. firstpass(p^.right);
  813. calcregisters(p,1,0,0);
  814. p^.location.loc:=LOC_REGISTER;
  815. end
  816. else
  817. { convert both to bestreal }
  818. begin
  819. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  820. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  821. firstpass(p^.left);
  822. firstpass(p^.right);
  823. calcregisters(p,1,1,0);
  824. p^.location.loc:=LOC_FPU;
  825. end;
  826. convdone:=true;
  827. end
  828. else
  829. { pointer comperation and subtraction }
  830. if (rd^.deftype=pointerdef) and (ld^.deftype=pointerdef) then
  831. begin
  832. p^.location.loc:=LOC_REGISTER;
  833. { p^.right:=gentypeconvnode(p^.right,ld); }
  834. { firstpass(p^.right); }
  835. calcregisters(p,1,0,0);
  836. case p^.treetype of
  837. equaln,unequaln :
  838. begin
  839. if is_equal(p^.right^.resulttype,voidpointerdef) then
  840. begin
  841. p^.right:=gentypeconvnode(p^.right,ld);
  842. firstpass(p^.right);
  843. end
  844. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  845. begin
  846. p^.left:=gentypeconvnode(p^.left,rd);
  847. firstpass(p^.left);
  848. end
  849. else if not(is_equal(ld,rd)) then
  850. CGMessage(type_e_mismatch);
  851. end;
  852. ltn,lten,gtn,gten:
  853. begin
  854. if is_equal(p^.right^.resulttype,voidpointerdef) then
  855. begin
  856. p^.right:=gentypeconvnode(p^.right,ld);
  857. firstpass(p^.right);
  858. end
  859. else if is_equal(p^.left^.resulttype,voidpointerdef) then
  860. begin
  861. p^.left:=gentypeconvnode(p^.left,rd);
  862. firstpass(p^.left);
  863. end
  864. else if not(is_equal(ld,rd)) then
  865. CGMessage(type_e_mismatch);
  866. if not(cs_extsyntax in aktmoduleswitches) then
  867. CGMessage(type_e_mismatch);
  868. end;
  869. subn:
  870. begin
  871. if not(is_equal(ld,rd)) then
  872. CGMessage(type_e_mismatch);
  873. if not(cs_extsyntax in aktmoduleswitches) then
  874. CGMessage(type_e_mismatch);
  875. p^.resulttype:=s32bitdef;
  876. exit;
  877. end;
  878. else CGMessage(type_e_mismatch);
  879. end;
  880. convdone:=true;
  881. end
  882. else
  883. if (rd^.deftype=objectdef) and (ld^.deftype=objectdef) and
  884. pobjectdef(rd)^.is_class and pobjectdef(ld)^.is_class then
  885. begin
  886. p^.location.loc:=LOC_REGISTER;
  887. if pobjectdef(rd)^.is_related(pobjectdef(ld)) then
  888. p^.right:=gentypeconvnode(p^.right,ld)
  889. else
  890. p^.left:=gentypeconvnode(p^.left,rd);
  891. firstpass(p^.right);
  892. firstpass(p^.left);
  893. calcregisters(p,1,0,0);
  894. case p^.treetype of
  895. equaln,unequaln : ;
  896. else CGMessage(type_e_mismatch);
  897. end;
  898. convdone:=true;
  899. end
  900. else
  901. if (rd^.deftype=classrefdef) and (ld^.deftype=classrefdef) then
  902. begin
  903. p^.location.loc:=LOC_REGISTER;
  904. if pobjectdef(pclassrefdef(rd)^.pointertype.def)^.is_related(pobjectdef(
  905. pclassrefdef(ld)^.pointertype.def)) then
  906. p^.right:=gentypeconvnode(p^.right,ld)
  907. else
  908. p^.left:=gentypeconvnode(p^.left,rd);
  909. firstpass(p^.right);
  910. firstpass(p^.left);
  911. calcregisters(p,1,0,0);
  912. case p^.treetype of
  913. equaln,unequaln : ;
  914. else CGMessage(type_e_mismatch);
  915. end;
  916. convdone:=true;
  917. end
  918. else
  919. { allows comperasion with nil pointer }
  920. if (rd^.deftype=objectdef) and
  921. pobjectdef(rd)^.is_class then
  922. begin
  923. p^.location.loc:=LOC_REGISTER;
  924. p^.left:=gentypeconvnode(p^.left,rd);
  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 (ld^.deftype=objectdef) and
  935. pobjectdef(ld)^.is_class then
  936. begin
  937. p^.location.loc:=LOC_REGISTER;
  938. p^.right:=gentypeconvnode(p^.right,ld);
  939. firstpass(p^.right);
  940. calcregisters(p,1,0,0);
  941. case p^.treetype of
  942. equaln,unequaln : ;
  943. else CGMessage(type_e_mismatch);
  944. end;
  945. convdone:=true;
  946. end
  947. else
  948. if (rd^.deftype=classrefdef) then
  949. begin
  950. p^.left:=gentypeconvnode(p^.left,rd);
  951. firstpass(p^.left);
  952. calcregisters(p,1,0,0);
  953. case p^.treetype of
  954. equaln,unequaln : ;
  955. else CGMessage(type_e_mismatch);
  956. end;
  957. convdone:=true;
  958. end
  959. else
  960. if (ld^.deftype=classrefdef) then
  961. begin
  962. p^.right:=gentypeconvnode(p^.right,ld);
  963. firstpass(p^.right);
  964. calcregisters(p,1,0,0);
  965. case p^.treetype of
  966. equaln,unequaln : ;
  967. else
  968. CGMessage(type_e_mismatch);
  969. end;
  970. convdone:=true;
  971. end
  972. else
  973. { support procvar=nil,procvar<>nil }
  974. if ((ld^.deftype=procvardef) and (rt=niln)) or
  975. ((rd^.deftype=procvardef) and (lt=niln)) then
  976. begin
  977. calcregisters(p,1,0,0);
  978. p^.location.loc:=LOC_REGISTER;
  979. case p^.treetype of
  980. equaln,unequaln : ;
  981. else
  982. CGMessage(type_e_mismatch);
  983. end;
  984. convdone:=true;
  985. end
  986. else
  987. {$ifdef SUPPORT_MMX}
  988. if (cs_mmx in aktlocalswitches) and is_mmx_able_array(ld) and
  989. is_mmx_able_array(rd) and is_equal(ld,rd) then
  990. begin
  991. firstpass(p^.right);
  992. firstpass(p^.left);
  993. case p^.treetype of
  994. addn,subn,xorn,orn,andn:
  995. ;
  996. { mul is a little bit restricted }
  997. muln:
  998. if not(mmx_type(p^.left^.resulttype) in
  999. [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1000. CGMessage(type_e_mismatch);
  1001. else
  1002. CGMessage(type_e_mismatch);
  1003. end;
  1004. p^.location.loc:=LOC_MMXREGISTER;
  1005. calcregisters(p,0,0,1);
  1006. convdone:=true;
  1007. end
  1008. else
  1009. {$endif SUPPORT_MMX}
  1010. { this is a little bit dangerous, also the left type }
  1011. { should be checked! This broke the mmx support }
  1012. if (rd^.deftype=pointerdef) or
  1013. is_zero_based_array(rd) then
  1014. begin
  1015. if is_zero_based_array(rd) then
  1016. begin
  1017. p^.resulttype:=new(ppointerdef,init(parraydef(rd)^.elementtype));
  1018. p^.right:=gentypeconvnode(p^.right,p^.resulttype);
  1019. firstpass(p^.right);
  1020. end;
  1021. p^.location.loc:=LOC_REGISTER;
  1022. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1023. firstpass(p^.left);
  1024. calcregisters(p,1,0,0);
  1025. if p^.treetype=addn then
  1026. begin
  1027. if not(cs_extsyntax in aktmoduleswitches) or
  1028. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1029. CGMessage(type_e_mismatch);
  1030. { Dirty hack, to support multiple firstpasses (PFV) }
  1031. if (p^.resulttype=nil) and
  1032. (rd^.deftype=pointerdef) and
  1033. (ppointerdef(rd)^.pointertype.def^.size>1) then
  1034. begin
  1035. p^.left:=gennode(muln,p^.left,genordinalconstnode(ppointerdef(rd)^.pointertype.def^.size,s32bitdef));
  1036. firstpass(p^.left);
  1037. end;
  1038. end
  1039. else
  1040. CGMessage(type_e_mismatch);
  1041. convdone:=true;
  1042. end
  1043. else
  1044. if (ld^.deftype=pointerdef) or
  1045. is_zero_based_array(ld) then
  1046. begin
  1047. if is_zero_based_array(ld) then
  1048. begin
  1049. p^.resulttype:=new(ppointerdef,init(parraydef(ld)^.elementtype));
  1050. p^.left:=gentypeconvnode(p^.left,p^.resulttype);
  1051. firstpass(p^.left);
  1052. end;
  1053. p^.location.loc:=LOC_REGISTER;
  1054. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1055. firstpass(p^.right);
  1056. calcregisters(p,1,0,0);
  1057. case p^.treetype of
  1058. addn,subn : begin
  1059. if not(cs_extsyntax in aktmoduleswitches) or
  1060. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1061. CGMessage(type_e_mismatch);
  1062. { Dirty hack, to support multiple firstpasses (PFV) }
  1063. if (p^.resulttype=nil) and
  1064. (ld^.deftype=pointerdef) and
  1065. (ppointerdef(ld)^.pointertype.def^.size>1) then
  1066. begin
  1067. p^.right:=gennode(muln,p^.right,
  1068. genordinalconstnode(ppointerdef(ld)^.pointertype.def^.size,s32bitdef));
  1069. firstpass(p^.right);
  1070. end;
  1071. end;
  1072. else
  1073. CGMessage(type_e_mismatch);
  1074. end;
  1075. convdone:=true;
  1076. end
  1077. else
  1078. if (rd^.deftype=procvardef) and (ld^.deftype=procvardef) and is_equal(rd,ld) then
  1079. begin
  1080. calcregisters(p,1,0,0);
  1081. p^.location.loc:=LOC_REGISTER;
  1082. case p^.treetype of
  1083. equaln,unequaln : ;
  1084. else
  1085. CGMessage(type_e_mismatch);
  1086. end;
  1087. convdone:=true;
  1088. end
  1089. else
  1090. if (ld^.deftype=enumdef) and (rd^.deftype=enumdef) and (is_equal(ld,rd)) then
  1091. begin
  1092. calcregisters(p,1,0,0);
  1093. case p^.treetype of
  1094. equaln,unequaln,
  1095. ltn,lten,gtn,gten : ;
  1096. else CGMessage(type_e_mismatch);
  1097. end;
  1098. convdone:=true;
  1099. end;
  1100. { the general solution is to convert to 32 bit int }
  1101. if not convdone then
  1102. begin
  1103. { but an int/int gives real/real! }
  1104. if p^.treetype=slashn then
  1105. begin
  1106. CGMessage(type_h_use_div_for_int);
  1107. p^.right:=gentypeconvnode(p^.right,bestrealdef^);
  1108. p^.left:=gentypeconvnode(p^.left,bestrealdef^);
  1109. firstpass(p^.left);
  1110. firstpass(p^.right);
  1111. { maybe we need an integer register to save }
  1112. { a reference }
  1113. if ((p^.left^.location.loc<>LOC_FPU) or
  1114. (p^.right^.location.loc<>LOC_FPU)) and
  1115. (p^.left^.registers32=p^.right^.registers32) then
  1116. calcregisters(p,1,1,0)
  1117. else
  1118. calcregisters(p,0,1,0);
  1119. p^.location.loc:=LOC_FPU;
  1120. end
  1121. else
  1122. begin
  1123. p^.right:=gentypeconvnode(p^.right,s32bitdef);
  1124. p^.left:=gentypeconvnode(p^.left,s32bitdef);
  1125. firstpass(p^.left);
  1126. firstpass(p^.right);
  1127. calcregisters(p,1,0,0);
  1128. p^.location.loc:=LOC_REGISTER;
  1129. end;
  1130. end;
  1131. if codegenerror then
  1132. exit;
  1133. { determines result type for comparions }
  1134. { here the is a problem with multiple passes }
  1135. { example length(s)+1 gets internal 'longint' type first }
  1136. { if it is a arg it is converted to 'LONGINT' }
  1137. { but a second first pass will reset this to 'longint' }
  1138. case p^.treetype of
  1139. ltn,lten,gtn,gten,equaln,unequaln:
  1140. begin
  1141. if (not assigned(p^.resulttype)) or
  1142. (p^.resulttype^.deftype=stringdef) then
  1143. p^.resulttype:=booldef;
  1144. if is_64bitint(p^.left^.resulttype) then
  1145. p^.location.loc:=LOC_JUMP
  1146. else
  1147. p^.location.loc:=LOC_FLAGS;
  1148. end;
  1149. xorn:
  1150. begin
  1151. if not assigned(p^.resulttype) then
  1152. p^.resulttype:=p^.left^.resulttype;
  1153. p^.location.loc:=LOC_REGISTER;
  1154. end;
  1155. addn:
  1156. begin
  1157. if not assigned(p^.resulttype) then
  1158. begin
  1159. { for strings, return is always a 255 char string }
  1160. if is_shortstring(p^.left^.resulttype) then
  1161. p^.resulttype:=cshortstringdef
  1162. else
  1163. p^.resulttype:=p^.left^.resulttype;
  1164. end;
  1165. end;
  1166. {$ifdef cardinalmulfix}
  1167. muln:
  1168. { if we multiply an unsigned with a signed number, the result is signed }
  1169. { in the other cases, the result remains signed or unsigned depending on }
  1170. { the multiplication factors (JM) }
  1171. if (p^.left^.resulttype^.deftype = orddef) and
  1172. (p^.right^.resulttype^.deftype = orddef) and
  1173. is_signed(p^.right^.resulttype) then
  1174. p^.resulttype := p^.right^.resulttype
  1175. else p^.resulttype := p^.left^.resulttype;
  1176. (*
  1177. subn:
  1178. { if we substract a u32bit from a positive constant, the result becomes }
  1179. { s32bit as well (JM) }
  1180. begin
  1181. if (p^.right^.resulttype^.deftype = orddef) and
  1182. (p^.left^.resulttype^.deftype = orddef) and
  1183. (porddef(p^.right^.resulttype)^.typ = u32bit) and
  1184. is_constintnode(p^.left) and
  1185. { (porddef(p^.left^.resulttype)^.typ <> u32bit) and}
  1186. (p^.left^.value > 0) then
  1187. begin
  1188. p^.left := gentypeconvnode(p^.left,u32bitdef);
  1189. firstpass(p^.left);
  1190. end;
  1191. p^.resulttype:=p^.left^.resulttype;
  1192. end;
  1193. *)
  1194. {$endif cardinalmulfix}
  1195. else
  1196. p^.resulttype:=p^.left^.resulttype;
  1197. end;
  1198. end;
  1199. end.
  1200. {
  1201. $Log$
  1202. Revision 1.63 2000-01-07 01:14:43 peter
  1203. * updated copyright to 2000
  1204. Revision 1.62 2000/01/04 20:10:20 florian
  1205. * mmx support fixed
  1206. Revision 1.61 1999/12/11 18:53:31 jonas
  1207. * fixed type conversions of results of operations with cardinals
  1208. (between -dcardinalmulfix)
  1209. Revision 1.60 1999/12/09 23:18:04 pierre
  1210. * no_fast_exit if procedure contains implicit termination code
  1211. Revision 1.59 1999/12/01 12:42:33 peter
  1212. * fixed bug 698
  1213. * removed some notes about unused vars
  1214. Revision 1.58 1999/11/30 10:40:56 peter
  1215. + ttype, tsymlist
  1216. Revision 1.57 1999/11/26 13:51:29 pierre
  1217. * fix for overloading of shr shl mod and div
  1218. Revision 1.56 1999/11/18 15:34:48 pierre
  1219. * Notes/Hints for local syms changed to
  1220. Set_varstate function
  1221. Revision 1.55 1999/11/17 17:05:06 pierre
  1222. * Notes/hints changes
  1223. Revision 1.54 1999/11/16 23:45:28 pierre
  1224. * global var token was changed by overload code (form bug 707)
  1225. Revision 1.53 1999/11/15 21:53:42 peter
  1226. * fixed constant eval for bool xor/or/and bool
  1227. Revision 1.52 1999/11/15 17:53:00 pierre
  1228. + one field added for ttoken record for operator
  1229. linking the id to the corresponding operator token that
  1230. can now now all be overloaded
  1231. * overloaded operators are resetted to nil in InitSymtable
  1232. (bug when trying to compile a uint that overloads operators twice)
  1233. Revision 1.51 1999/11/06 14:34:29 peter
  1234. * truncated log to 20 revs
  1235. Revision 1.50 1999/09/27 23:45:00 peter
  1236. * procinfo is now a pointer
  1237. * support for result setting in sub procedure
  1238. Revision 1.49 1999/09/16 13:39:14 peter
  1239. * arrayconstructor 2 set conversion is now called always in the
  1240. beginning of firstadd
  1241. Revision 1.48 1999/09/15 20:35:45 florian
  1242. * small fix to operator overloading when in MMX mode
  1243. + the compiler uses now fldz and fld1 if possible
  1244. + some fixes to floating point registers
  1245. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  1246. * .... ???
  1247. Revision 1.47 1999/09/13 16:28:05 peter
  1248. * typo in previous commit open_array -> chararray :(
  1249. Revision 1.46 1999/09/10 15:40:46 peter
  1250. * fixed array check for operators, becuase array can also be a set
  1251. Revision 1.45 1999/09/08 16:05:29 peter
  1252. * pointer add/sub is now as expected and the same results as inc/dec
  1253. Revision 1.44 1999/09/07 07:52:19 peter
  1254. * > < >= <= support for boolean
  1255. * boolean constants are now calculated like integer constants
  1256. Revision 1.43 1999/08/23 23:44:05 pierre
  1257. * setelementn registers32 corrected
  1258. Revision 1.42 1999/08/07 11:29:27 peter
  1259. * better fix for muln register allocation
  1260. Revision 1.41 1999/08/05 21:58:57 peter
  1261. * fixed register count ord*ord
  1262. Revision 1.40 1999/08/04 13:03:13 jonas
  1263. * all tokens now start with an underscore
  1264. * PowerPC compiles!!
  1265. Revision 1.39 1999/08/04 00:23:33 florian
  1266. * renamed i386asm and i386base to cpuasm and cpubase
  1267. Revision 1.38 1999/08/03 22:03:24 peter
  1268. * moved bitmask constants to sets
  1269. * some other type/const renamings
  1270. Revision 1.37 1999/07/16 10:04:37 peter
  1271. * merged
  1272. Revision 1.36 1999/06/17 15:32:48 pierre
  1273. * merged from 0-99-12 branch
  1274. Revision 1.34.2.3 1999/07/16 09:54:58 peter
  1275. * @procvar support in tp7 mode works again
  1276. Revision 1.34.2.2 1999/06/17 15:25:07 pierre
  1277. * for arrays of char operators can not be overloaded
  1278. Revision 1.35 1999/06/17 13:19:57 pierre
  1279. * merged from 0_99_12 branch
  1280. Revision 1.34.2.1 1999/06/17 12:35:23 pierre
  1281. * allow array binary operator overloading if not with orddef
  1282. Revision 1.34 1999/06/02 10:11:52 florian
  1283. * make cycle fixed i.e. compilation with 0.99.10
  1284. * some fixes for qword
  1285. * start of register calling conventions
  1286. }