tcadd.pas 52 KB

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