nadd.pas 52 KB

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