ncnv.pas 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  1. {
  2. $Id$
  3. Copyright (c) 2000 by Florian Klaempfl
  4. Type checking and register allocation for type converting 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 ncnv;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node,
  23. symtype,types,
  24. nld;
  25. type
  26. ttypeconvnode = class(tunarynode)
  27. totype : ttype;
  28. convtype : tconverttype;
  29. constructor create(node : tnode;const t : ttype);virtual;
  30. function getcopy : tnode;override;
  31. function pass_1 : tnode;override;
  32. function det_resulttype:tnode;override;
  33. function docompare(p: tnode) : boolean; override;
  34. private
  35. function resulttype_cord_to_pointer : tnode;
  36. function resulttype_string_to_string : tnode;
  37. function resulttype_char_to_string : tnode;
  38. function resulttype_int_to_real : tnode;
  39. function resulttype_real_to_real : tnode;
  40. function resulttype_cchar_to_pchar : tnode;
  41. function resulttype_cstring_to_pchar : tnode;
  42. function resulttype_char_to_char : tnode;
  43. function resulttype_arrayconstructor_to_set : tnode;
  44. function resulttype_call_helper(c : tconverttype) : tnode;
  45. protected
  46. function first_int_to_int : tnode;virtual;
  47. function first_cstring_to_pchar : tnode;virtual;
  48. function first_string_to_chararray : tnode;virtual;
  49. function first_string_to_string : tnode;virtual;
  50. function first_char_to_string : tnode;virtual;
  51. function first_nothing : tnode;virtual;
  52. function first_array_to_pointer : tnode;virtual;
  53. function first_int_to_real : tnode;virtual;
  54. function first_real_to_real : tnode;virtual;
  55. function first_pointer_to_array : tnode;virtual;
  56. function first_chararray_to_string : tnode;virtual;
  57. function first_cchar_to_pchar : tnode;virtual;
  58. function first_bool_to_int : tnode;virtual;
  59. function first_int_to_bool : tnode;virtual;
  60. function first_bool_to_bool : tnode;virtual;
  61. function first_proc_to_procvar : tnode;virtual;
  62. function first_load_smallset : tnode;virtual;
  63. function first_cord_to_pointer : tnode;virtual;
  64. function first_pchar_to_string : tnode;virtual;
  65. function first_ansistring_to_pchar : tnode;virtual;
  66. function first_arrayconstructor_to_set : tnode;virtual;
  67. function first_class_to_intf : tnode;virtual;
  68. function first_char_to_char : tnode;virtual;
  69. function first_call_helper(c : tconverttype) : tnode;
  70. end;
  71. tasnode = class(tbinarynode)
  72. constructor create(l,r : tnode);virtual;
  73. function pass_1 : tnode;override;
  74. function det_resulttype:tnode;override;
  75. end;
  76. tisnode = class(tbinarynode)
  77. constructor create(l,r : tnode);virtual;
  78. function pass_1 : tnode;override;
  79. function det_resulttype:tnode;override;
  80. end;
  81. var
  82. ctypeconvnode : class of ttypeconvnode;
  83. casnode : class of tasnode;
  84. cisnode : class of tisnode;
  85. procedure inserttypeconv(var p:tnode;const t:ttype);
  86. procedure arrayconstructor_to_set(var p : tarrayconstructornode);
  87. implementation
  88. uses
  89. globtype,systems,tokens,
  90. cutils,verbose,globals,widestr,
  91. symconst,symdef,symsym,symtable,
  92. ncon,ncal,nset,nadd,
  93. {$ifdef newcg}
  94. cgbase,
  95. {$else newcg}
  96. hcodegen,
  97. {$endif newcg}
  98. htypechk,pass_1,cpubase,cpuinfo;
  99. {*****************************************************************************
  100. Helpers
  101. *****************************************************************************}
  102. procedure inserttypeconv(var p:tnode;const t:ttype);
  103. begin
  104. if not assigned(p.resulttype.def) then
  105. begin
  106. resulttypepass(p);
  107. if codegenerror then
  108. exit;
  109. end;
  110. { don't insert obsolete type conversions }
  111. if is_equal(p.resulttype.def,t.def) then
  112. begin
  113. p.resulttype:=t;
  114. end
  115. else
  116. begin
  117. p:=ctypeconvnode.create(p,t);
  118. resulttypepass(p);
  119. end;
  120. end;
  121. {*****************************************************************************
  122. Array constructor to Set Conversion
  123. *****************************************************************************}
  124. procedure arrayconstructor_to_set(var p : tarrayconstructornode);
  125. var
  126. constp : tsetconstnode;
  127. buildp,
  128. p2,p3,p4 : tnode;
  129. htype : ttype;
  130. constset : pconstset;
  131. constsetlo,
  132. constsethi : longint;
  133. procedure update_constsethi(t:ttype);
  134. begin
  135. if ((t.def.deftype=orddef) and
  136. (torddef(t.def).high>=constsethi)) then
  137. begin
  138. constsethi:=torddef(t.def).high;
  139. if htype.def=nil then
  140. begin
  141. if (constsethi>255) or
  142. (torddef(t.def).low<0) then
  143. htype:=u8bittype
  144. else
  145. htype:=t;
  146. end;
  147. if constsethi>255 then
  148. constsethi:=255;
  149. end
  150. else if ((t.def.deftype=enumdef) and
  151. (tenumdef(t.def).max>=constsethi)) then
  152. begin
  153. if htype.def=nil then
  154. htype:=t;
  155. constsethi:=tenumdef(t.def).max;
  156. end;
  157. end;
  158. procedure do_set(pos : longint);
  159. var
  160. mask,l : longint;
  161. begin
  162. if (pos>255) or (pos<0) then
  163. Message(parser_e_illegal_set_expr);
  164. if pos>constsethi then
  165. constsethi:=pos;
  166. if pos<constsetlo then
  167. constsetlo:=pos;
  168. l:=pos shr 3;
  169. mask:=1 shl (pos mod 8);
  170. { do we allow the same twice }
  171. if (constset^[l] and mask)<>0 then
  172. Message(parser_e_illegal_set_expr);
  173. constset^[l]:=constset^[l] or mask;
  174. end;
  175. var
  176. l : longint;
  177. lr,hr : longint;
  178. begin
  179. new(constset);
  180. FillChar(constset^,sizeof(constset^),0);
  181. htype.reset;
  182. constsetlo:=0;
  183. constsethi:=0;
  184. constp:=csetconstnode.create(nil,htype);
  185. constp.value_set:=constset;
  186. buildp:=constp;
  187. if assigned(p.left) then
  188. begin
  189. while assigned(p) do
  190. begin
  191. p4:=nil; { will contain the tree to create the set }
  192. {split a range into p2 and p3 }
  193. if p.left.nodetype=arrayconstructorrangen then
  194. begin
  195. p2:=tarrayconstructorrangenode(p.left).left;
  196. p3:=tarrayconstructorrangenode(p.left).right;
  197. tarrayconstructorrangenode(p.left).left:=nil;
  198. tarrayconstructorrangenode(p.left).right:=nil;
  199. end
  200. else
  201. begin
  202. p2:=p.left;
  203. p.left:=nil;
  204. p3:=nil;
  205. end;
  206. resulttypepass(p2);
  207. if assigned(p3) then
  208. resulttypepass(p3);
  209. if codegenerror then
  210. break;
  211. case p2.resulttype.def.deftype of
  212. enumdef,
  213. orddef:
  214. begin
  215. getrange(p2.resulttype.def,lr,hr);
  216. if assigned(p3) then
  217. begin
  218. { this isn't good, you'll get problems with
  219. type t010 = 0..10;
  220. ts = set of t010;
  221. var s : ts;b : t010
  222. begin s:=[1,2,b]; end.
  223. if is_integer(p3^.resulttype.def) then
  224. begin
  225. inserttypeconv(p3,u8bitdef);
  226. end;
  227. }
  228. if assigned(htype.def) and not(is_equal(htype.def,p3.resulttype.def)) then
  229. begin
  230. aktfilepos:=p3.fileinfo;
  231. CGMessage(type_e_typeconflict_in_set);
  232. end
  233. else
  234. begin
  235. if (p2.nodetype=ordconstn) and (p3.nodetype=ordconstn) then
  236. begin
  237. if not(is_integer(p3.resulttype.def)) then
  238. htype:=p3.resulttype
  239. else
  240. begin
  241. inserttypeconv(p3,u8bittype);
  242. inserttypeconv(p2,u8bittype);
  243. end;
  244. for l:=tordconstnode(p2).value to tordconstnode(p3).value do
  245. do_set(l);
  246. p2.free;
  247. p3.free;
  248. end
  249. else
  250. begin
  251. update_constsethi(p2.resulttype);
  252. inserttypeconv(p2,htype);
  253. update_constsethi(p3.resulttype);
  254. inserttypeconv(p3,htype);
  255. if assigned(htype.def) then
  256. inserttypeconv(p3,htype)
  257. else
  258. inserttypeconv(p3,u8bittype);
  259. p4:=csetelementnode.create(p2,p3);
  260. end;
  261. end;
  262. end
  263. else
  264. begin
  265. { Single value }
  266. if p2.nodetype=ordconstn then
  267. begin
  268. if not(is_integer(p2.resulttype.def)) then
  269. update_constsethi(p2.resulttype)
  270. else
  271. inserttypeconv(p2,u8bittype);
  272. do_set(tordconstnode(p2).value);
  273. p2.free;
  274. end
  275. else
  276. begin
  277. update_constsethi(p2.resulttype);
  278. if assigned(htype.def) then
  279. inserttypeconv(p2,htype)
  280. else
  281. inserttypeconv(p2,u8bittype);
  282. p4:=csetelementnode.create(p2,nil);
  283. end;
  284. end;
  285. end;
  286. stringdef :
  287. begin
  288. { if we've already set elements which are constants }
  289. { throw an error }
  290. if ((htype.def=nil) and assigned(buildp)) or
  291. not(is_char(htype.def)) then
  292. CGMessage(type_e_typeconflict_in_set)
  293. else
  294. for l:=1 to length(pstring(tstringconstnode(p2).value_str)^) do
  295. do_set(ord(pstring(tstringconstnode(p2).value_str)^[l]));
  296. if htype.def=nil then
  297. htype:=cchartype;
  298. p2.free;
  299. end;
  300. else
  301. CGMessage(type_e_ordinal_expr_expected);
  302. end;
  303. { insert the set creation tree }
  304. if assigned(p4) then
  305. buildp:=caddnode.create(addn,buildp,p4);
  306. { load next and dispose current node }
  307. p2:=p;
  308. p:=tarrayconstructornode(tarrayconstructornode(p2).right);
  309. tarrayconstructornode(p2).right:=nil;
  310. p2.free;
  311. end;
  312. if (htype.def=nil) then
  313. begin
  314. htype:=u8bittype;
  315. constsethi:=255;
  316. end;
  317. end
  318. else
  319. begin
  320. { empty set [], only remove node }
  321. p.free;
  322. end;
  323. { set the initial set type }
  324. constp.resulttype.setdef(tsetdef.create(htype,constsethi));
  325. { determine the resulttype for the tree }
  326. resulttypepass(buildp);
  327. { set the new tree }
  328. p:=tarrayconstructornode(buildp);
  329. end;
  330. {*****************************************************************************
  331. TTYPECONVNODE
  332. *****************************************************************************}
  333. constructor ttypeconvnode.create(node : tnode;const t:ttype);
  334. begin
  335. inherited create(typeconvn,node);
  336. convtype:=tc_not_possible;
  337. totype:=t;
  338. if t.def=nil then
  339. internalerror(200103281);
  340. set_file_line(node);
  341. end;
  342. function ttypeconvnode.getcopy : tnode;
  343. var
  344. n : ttypeconvnode;
  345. begin
  346. n:=ttypeconvnode(inherited getcopy);
  347. n.convtype:=convtype;
  348. getcopy:=n;
  349. end;
  350. function ttypeconvnode.resulttype_cord_to_pointer : tnode;
  351. var
  352. t : tnode;
  353. begin
  354. result:=nil;
  355. if left.nodetype=ordconstn then
  356. begin
  357. { check if we have a valid pointer constant (JM) }
  358. if (sizeof(tordconstnode) > sizeof(tpointerord)) then
  359. if (sizeof(tpointerord) = 4) then
  360. begin
  361. if (tordconstnode(left).value < low(longint)) or
  362. (tordconstnode(left).value > high(cardinal)) then
  363. CGMessage(parser_e_range_check_error);
  364. end
  365. else if (sizeof(tpointerord) = 8) then
  366. begin
  367. if (tordconstnode(left).value < low(int64)) or
  368. (tordconstnode(left).value > high(qword)) then
  369. CGMessage(parser_e_range_check_error);
  370. end
  371. else
  372. internalerror(2001020801);
  373. t:=cpointerconstnode.create(tpointerord(tordconstnode(left).value),resulttype);
  374. resulttypepass(t);
  375. result:=t;
  376. end
  377. else
  378. internalerror(200104023);
  379. end;
  380. function ttypeconvnode.resulttype_string_to_string : tnode;
  381. var
  382. pw : pcompilerwidestring;
  383. pc : pchar;
  384. begin
  385. result:=nil;
  386. if left.nodetype=stringconstn then
  387. begin
  388. { convert ascii 2 unicode }
  389. if (tstringdef(resulttype.def).string_typ=st_widestring) and
  390. (tstringconstnode(left).st_type in [st_ansistring,st_shortstring,st_longstring]) then
  391. begin
  392. initwidestring(pw);
  393. ascii2unicode(tstringconstnode(left).value_str,tstringconstnode(left).len,pw);
  394. ansistringdispose(tstringconstnode(left).value_str,tstringconstnode(left).len);
  395. pcompilerwidestring(tstringconstnode(left).value_str):=pw;
  396. end
  397. else
  398. { convert unicode 2 ascii }
  399. if (tstringconstnode(left).st_type=st_widestring) and
  400. (tstringdef(resulttype.def).string_typ in [st_ansistring,st_shortstring,st_longstring]) then
  401. begin
  402. pw:=pcompilerwidestring(tstringconstnode(left).value_str);
  403. getmem(pc,getlengthwidestring(pw)+1);
  404. unicode2ascii(pw,pc);
  405. donewidestring(pw);
  406. tstringconstnode(left).value_str:=pc;
  407. end;
  408. tstringconstnode(left).st_type:=tstringdef(resulttype.def).string_typ;
  409. tstringconstnode(left).resulttype:=resulttype;
  410. result:=left;
  411. left:=nil;
  412. end;
  413. end;
  414. function ttypeconvnode.resulttype_char_to_string : tnode;
  415. var
  416. hp : tstringconstnode;
  417. ws : pcompilerwidestring;
  418. begin
  419. result:=nil;
  420. if left.nodetype=ordconstn then
  421. begin
  422. if tstringdef(resulttype.def).string_typ=st_widestring then
  423. begin
  424. initwidestring(ws);
  425. concatwidestringchar(ws,tcompilerwidechar(chr(tordconstnode(left).value)));
  426. hp:=cstringconstnode.createwstr(ws);
  427. donewidestring(ws);
  428. end
  429. else
  430. hp:=cstringconstnode.createstr(chr(tordconstnode(left).value),tstringdef(resulttype.def).string_typ);
  431. resulttypepass(hp);
  432. result:=hp;
  433. end;
  434. end;
  435. function ttypeconvnode.resulttype_char_to_char : tnode;
  436. var
  437. hp : tordconstnode;
  438. begin
  439. result:=nil;
  440. if left.nodetype=ordconstn then
  441. begin
  442. if (torddef(resulttype.def).typ=uchar) and
  443. (torddef(left.resulttype.def).typ=uwidechar) then
  444. begin
  445. hp:=cordconstnode.create(
  446. ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value))),cchartype);
  447. resulttypepass(hp);
  448. result:=hp;
  449. end
  450. else if (torddef(resulttype.def).typ=uwidechar) and
  451. (torddef(left.resulttype.def).typ=uchar) then
  452. begin
  453. hp:=cordconstnode.create(
  454. asciichar2unicode(chr(tordconstnode(left).value)),cwidechartype);
  455. resulttypepass(hp);
  456. result:=hp;
  457. end
  458. else
  459. internalerror(200105131);
  460. exit;
  461. end;
  462. end;
  463. function ttypeconvnode.resulttype_int_to_real : tnode;
  464. var
  465. t : trealconstnode;
  466. begin
  467. result:=nil;
  468. if left.nodetype=ordconstn then
  469. begin
  470. t:=crealconstnode.create(tordconstnode(left).value,resulttype);
  471. resulttypepass(t);
  472. result:=t;
  473. exit;
  474. end;
  475. end;
  476. function ttypeconvnode.resulttype_real_to_real : tnode;
  477. var
  478. t : tnode;
  479. begin
  480. result:=nil;
  481. if left.nodetype=realconstn then
  482. begin
  483. t:=crealconstnode.create(trealconstnode(left).value_real,resulttype);
  484. resulttypepass(t);
  485. result:=t;
  486. end;
  487. end;
  488. function ttypeconvnode.resulttype_cchar_to_pchar : tnode;
  489. begin
  490. result:=nil;
  491. if is_pwidechar(resulttype.def) then
  492. inserttypeconv(left,cwidestringtype)
  493. else
  494. inserttypeconv(left,cshortstringtype);
  495. { evaluate again, reset resulttype so the convert_typ
  496. will be calculated again and cstring_to_pchar will
  497. be used for futher conversion }
  498. result:=det_resulttype;
  499. end;
  500. function ttypeconvnode.resulttype_cstring_to_pchar : tnode;
  501. begin
  502. result:=nil;
  503. if is_pwidechar(resulttype.def) then
  504. inserttypeconv(left,cwidestringtype);
  505. end;
  506. function ttypeconvnode.resulttype_arrayconstructor_to_set : tnode;
  507. var
  508. hp : tnode;
  509. begin
  510. result:=nil;
  511. if left.nodetype<>arrayconstructorn then
  512. internalerror(5546);
  513. { remove typeconv node }
  514. hp:=left;
  515. left:=nil;
  516. { create a set constructor tree }
  517. arrayconstructor_to_set(tarrayconstructornode(hp));
  518. { now resulttypepass the set }
  519. resulttypepass(hp);
  520. result:=hp;
  521. end;
  522. function ttypeconvnode.resulttype_call_helper(c : tconverttype) : tnode;
  523. const
  524. resulttypeconvert : array[tconverttype] of pointer = (
  525. {equal} nil,
  526. {not_possible} nil,
  527. { string_2_string } @ttypeconvnode.resulttype_string_to_string,
  528. { char_2_string } @ttypeconvnode.resulttype_char_to_string,
  529. { pchar_2_string } nil,
  530. { cchar_2_pchar } @ttypeconvnode.resulttype_cchar_to_pchar,
  531. { cstring_2_pchar } @ttypeconvnode.resulttype_cstring_to_pchar,
  532. { ansistring_2_pchar } nil,
  533. { string_2_chararray } nil,
  534. { chararray_2_string } nil,
  535. { array_2_pointer } nil,
  536. { pointer_2_array } nil,
  537. { int_2_int } nil,
  538. { int_2_bool } nil,
  539. { bool_2_bool } nil,
  540. { bool_2_int } nil,
  541. { real_2_real } @ttypeconvnode.resulttype_real_to_real,
  542. { int_2_real } @ttypeconvnode.resulttype_int_to_real,
  543. { proc_2_procvar } nil,
  544. { arrayconstructor_2_set } @ttypeconvnode.resulttype_arrayconstructor_to_set,
  545. { load_smallset } nil,
  546. { cord_2_pointer } @ttypeconvnode.resulttype_cord_to_pointer,
  547. { intf_2_string } nil,
  548. { intf_2_guid } nil,
  549. { class_2_intf } nil,
  550. { char_2_char } @ttypeconvnode.resulttype_char_to_char
  551. );
  552. type
  553. tprocedureofobject = function : tnode of object;
  554. var
  555. r : packed record
  556. proc : pointer;
  557. obj : pointer;
  558. end;
  559. begin
  560. result:=nil;
  561. { this is a little bit dirty but it works }
  562. { and should be quite portable too }
  563. r.proc:=resulttypeconvert[c];
  564. r.obj:=self;
  565. if assigned(r.proc) then
  566. result:=tprocedureofobject(r){$ifdef FPC}();{$endif FPC}
  567. end;
  568. function ttypeconvnode.det_resulttype:tnode;
  569. var
  570. hp : tnode;
  571. aprocdef : tprocdef;
  572. begin
  573. result:=nil;
  574. resulttype:=totype;
  575. resulttypepass(left);
  576. if codegenerror then
  577. exit;
  578. { remove obsolete type conversions }
  579. if is_equal(left.resulttype.def,resulttype.def) then
  580. begin
  581. { becuase is_equal only checks the basetype for sets we need to
  582. check here if we are loading a smallset into a normalset }
  583. if (resulttype.def.deftype=setdef) and
  584. (left.resulttype.def.deftype=setdef) and
  585. (tsetdef(resulttype.def).settype<>smallset) and
  586. (tsetdef(left.resulttype.def).settype=smallset) then
  587. begin
  588. { try to define the set as a normalset if it's a constant set }
  589. if left.nodetype=setconstn then
  590. begin
  591. resulttype:=left.resulttype;
  592. tsetdef(resulttype.def).settype:=normset
  593. end
  594. else
  595. convtype:=tc_load_smallset;
  596. exit;
  597. end
  598. else
  599. begin
  600. left.resulttype:=resulttype;
  601. result:=left;
  602. left:=nil;
  603. exit;
  604. end;
  605. end;
  606. aprocdef:=assignment_overloaded(left.resulttype.def,resulttype.def);
  607. if assigned(aprocdef) then
  608. begin
  609. procinfo^.flags:=procinfo^.flags or pi_do_call;
  610. hp:=ccallnode.create(ccallparanode.create(left,nil),
  611. overloaded_operators[_assignment],nil,nil);
  612. { tell explicitly which def we must use !! (PM) }
  613. tcallnode(hp).procdefinition:=aprocdef;
  614. left:=nil;
  615. resulttypepass(hp);
  616. result:=hp;
  617. exit;
  618. end;
  619. if isconvertable(left.resulttype.def,resulttype.def,convtype,left.nodetype,nf_explizit in flags)=0 then
  620. begin
  621. {Procedures have a resulttype.def of voiddef and functions of their
  622. own resulttype.def. They will therefore always be incompatible with
  623. a procvar. Because isconvertable cannot check for procedures we
  624. use an extra check for them.}
  625. if (m_tp_procvar in aktmodeswitches) then
  626. begin
  627. if (resulttype.def.deftype=procvardef) and
  628. (is_procsym_load(left) or is_procsym_call(left)) then
  629. begin
  630. if is_procsym_call(left) then
  631. begin
  632. hp:=cloadnode.create(tprocsym(tcallnode(left).symtableprocentry),
  633. tcallnode(left).symtableproc);
  634. if (tcallnode(left).symtableprocentry.owner.symtabletype=objectsymtable) and
  635. assigned(tcallnode(left).methodpointer) then
  636. tloadnode(hp).set_mp(tcallnode(left).methodpointer.getcopy);
  637. resulttypepass(hp);
  638. left.free;
  639. left:=hp;
  640. aprocdef:=tprocdef(left.resulttype.def);
  641. end
  642. else
  643. begin
  644. if (left.nodetype<>addrn) then
  645. aprocdef:=tprocsym(tloadnode(left).symtableentry).definition;
  646. end;
  647. convtype:=tc_proc_2_procvar;
  648. { Now check if the procedure we are going to assign to
  649. the procvar, is compatible with the procvar's type }
  650. if assigned(aprocdef) then
  651. begin
  652. if not proc_to_procvar_equal(aprocdef,tprocvardef(resulttype.def)) then
  653. CGMessage2(type_e_incompatible_types,aprocdef.typename,resulttype.def.typename);
  654. end
  655. else
  656. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  657. exit;
  658. end;
  659. end;
  660. if nf_explizit in flags then
  661. begin
  662. { check if the result could be in a register }
  663. if not(tstoreddef(resulttype.def).is_intregable) and
  664. not(tstoreddef(resulttype.def).is_fpuregable) then
  665. make_not_regable(left);
  666. { boolean to byte are special because the
  667. location can be different }
  668. if is_integer(resulttype.def) and
  669. is_boolean(left.resulttype.def) then
  670. begin
  671. convtype:=tc_bool_2_int;
  672. exit;
  673. end;
  674. { ansistring to pchar }
  675. if is_pchar(resulttype.def) and
  676. is_ansistring(left.resulttype.def) then
  677. begin
  678. convtype:=tc_ansistring_2_pchar;
  679. exit;
  680. end;
  681. { do common tc_equal cast }
  682. convtype:=tc_equal;
  683. { enum to ordinal will always be s32bit }
  684. if (left.resulttype.def.deftype=enumdef) and
  685. is_ordinal(resulttype.def) then
  686. begin
  687. if left.nodetype=ordconstn then
  688. begin
  689. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  690. resulttypepass(hp);
  691. result:=hp;
  692. exit;
  693. end
  694. else
  695. begin
  696. if isconvertable(s32bittype.def,resulttype.def,convtype,ordconstn,false)=0 then
  697. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  698. end;
  699. end
  700. { ordinal to enumeration }
  701. else
  702. if (resulttype.def.deftype=enumdef) and
  703. is_ordinal(left.resulttype.def) then
  704. begin
  705. if left.nodetype=ordconstn then
  706. begin
  707. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  708. resulttypepass(hp);
  709. result:=hp;
  710. exit;
  711. end
  712. else
  713. begin
  714. if IsConvertable(left.resulttype.def,s32bittype.def,convtype,ordconstn,false)=0 then
  715. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  716. end;
  717. end
  718. { nil to ordinal node }
  719. else if (left.nodetype=niln) and is_ordinal(resulttype.def) then
  720. begin
  721. hp:=cordconstnode.create(0,resulttype);
  722. resulttypepass(hp);
  723. result:=hp;
  724. exit;
  725. end
  726. { constant pointer to ordinal }
  727. else if is_ordinal(resulttype.def) and
  728. (left.nodetype=pointerconstn) then
  729. begin
  730. hp:=cordconstnode.create(tpointerconstnode(left).value,resulttype);
  731. resulttypepass(hp);
  732. result:=hp;
  733. exit;
  734. end
  735. {Are we typecasting an ordconst to a char?}
  736. else
  737. if is_char(resulttype.def) and
  738. is_ordinal(left.resulttype.def) then
  739. begin
  740. if left.nodetype=ordconstn then
  741. begin
  742. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  743. resulttypepass(hp);
  744. result:=hp;
  745. exit;
  746. end
  747. else
  748. begin
  749. if IsConvertable(left.resulttype.def,u8bittype.def,convtype,ordconstn,false)=0 then
  750. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  751. end;
  752. end
  753. {Are we typecasting an ordconst to a wchar?}
  754. else
  755. if is_widechar(resulttype.def) and
  756. is_ordinal(left.resulttype.def) then
  757. begin
  758. if left.nodetype=ordconstn then
  759. begin
  760. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  761. resulttypepass(hp);
  762. result:=hp;
  763. exit;
  764. end
  765. else
  766. begin
  767. if IsConvertable(left.resulttype.def,u16bittype.def,convtype,ordconstn,false)=0 then
  768. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  769. end;
  770. end
  771. { char to ordinal }
  772. else
  773. if is_char(left.resulttype.def) and
  774. is_ordinal(resulttype.def) then
  775. begin
  776. if left.nodetype=ordconstn then
  777. begin
  778. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  779. resulttypepass(hp);
  780. result:=hp;
  781. exit;
  782. end
  783. else
  784. begin
  785. if IsConvertable(u8bittype.def,resulttype.def,convtype,ordconstn,false)=0 then
  786. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  787. end;
  788. end
  789. { widechar to ordinal }
  790. else
  791. if is_widechar(left.resulttype.def) and
  792. is_ordinal(resulttype.def) then
  793. begin
  794. if left.nodetype=ordconstn then
  795. begin
  796. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  797. resulttypepass(hp);
  798. result:=hp;
  799. exit;
  800. end
  801. else
  802. begin
  803. if IsConvertable(u16bittype.def,resulttype.def,convtype,ordconstn,false)=0 then
  804. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  805. end;
  806. end
  807. { only if the same size or formal def }
  808. { why do we allow typecasting of voiddef ?? (PM) }
  809. else
  810. begin
  811. if not(
  812. (left.resulttype.def.deftype=formaldef) or
  813. (left.resulttype.def.size=resulttype.def.size) or
  814. (is_void(left.resulttype.def) and
  815. (left.nodetype=derefn))
  816. ) then
  817. CGMessage(cg_e_illegal_type_conversion);
  818. if ((left.resulttype.def.deftype=orddef) and
  819. (resulttype.def.deftype=pointerdef)) or
  820. ((resulttype.def.deftype=orddef) and
  821. (left.resulttype.def.deftype=pointerdef)) then
  822. CGMessage(cg_d_pointer_to_longint_conv_not_portable);
  823. end;
  824. { the conversion into a strutured type is only }
  825. { possible, if the source is not a register }
  826. if ((resulttype.def.deftype in [recorddef,stringdef,arraydef]) or
  827. ((resulttype.def.deftype=objectdef) and not(is_class(resulttype.def)))
  828. ) and (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) { and
  829. it also works if the assignment is overloaded
  830. YES but this code is not executed if assignment is overloaded (PM)
  831. not assigned(assignment_overloaded(left.resulttype.def,resulttype.def))} then
  832. CGMessage(cg_e_illegal_type_conversion);
  833. end
  834. else
  835. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  836. end;
  837. { tp7 procvar support, when right is not a procvardef and we got a
  838. loadn of a procvar then convert to a calln, the check for the
  839. result is already done in is_convertible, also no conflict with
  840. @procvar is here because that has an extra addrn }
  841. if (m_tp_procvar in aktmodeswitches) and
  842. (resulttype.def.deftype<>procvardef) and
  843. (left.resulttype.def.deftype=procvardef) and
  844. (left.nodetype=loadn) then
  845. begin
  846. hp:=ccallnode.create(nil,nil,nil,nil);
  847. tcallnode(hp).set_procvar(left);
  848. resulttypepass(hp);
  849. left:=hp;
  850. end;
  851. { ordinal contants can be directly converted }
  852. if (left.nodetype=ordconstn) and is_ordinal(resulttype.def) then
  853. begin
  854. { replace the resulttype and recheck the range }
  855. left.resulttype:=resulttype;
  856. testrange(left.resulttype.def,tordconstnode(left).value,(nf_explizit in flags));
  857. result:=left;
  858. left:=nil;
  859. exit;
  860. end;
  861. { fold nil to any pointer type }
  862. if (left.nodetype=niln) and (resulttype.def.deftype=pointerdef) then
  863. begin
  864. hp:=cnilnode.create;
  865. hp.resulttype:=resulttype;
  866. resulttypepass(hp);
  867. result:=hp;
  868. exit;
  869. end;
  870. { further, pointerconstn to any pointer is folded too }
  871. if (left.nodetype=pointerconstn) and (resulttype.def.deftype=pointerdef) then
  872. begin
  873. left.resulttype:=resulttype;
  874. result:=left;
  875. left:=nil;
  876. exit;
  877. end;
  878. { now call the resulttype helper to do constant folding }
  879. result:=resulttype_call_helper(convtype);
  880. end;
  881. function ttypeconvnode.first_cord_to_pointer : tnode;
  882. begin
  883. result:=nil;
  884. internalerror(200104043);
  885. end;
  886. function ttypeconvnode.first_int_to_int : tnode;
  887. begin
  888. first_int_to_int:=nil;
  889. if (left.location.loc<>LOC_REGISTER) and
  890. (resulttype.def.size>left.resulttype.def.size) then
  891. location.loc:=LOC_REGISTER;
  892. if is_64bitint(resulttype.def) then
  893. registers32:=max(registers32,2)
  894. else
  895. registers32:=max(registers32,1);
  896. end;
  897. function ttypeconvnode.first_cstring_to_pchar : tnode;
  898. begin
  899. first_cstring_to_pchar:=nil;
  900. registers32:=1;
  901. location.loc:=LOC_REGISTER;
  902. end;
  903. function ttypeconvnode.first_string_to_chararray : tnode;
  904. begin
  905. first_string_to_chararray:=nil;
  906. registers32:=1;
  907. location.loc:=LOC_REGISTER;
  908. end;
  909. function ttypeconvnode.first_string_to_string : tnode;
  910. begin
  911. first_string_to_string:=nil;
  912. if tstringdef(resulttype.def).string_typ<>
  913. tstringdef(left.resulttype.def).string_typ then
  914. begin
  915. procinfo^.flags:=procinfo^.flags or pi_do_call;
  916. end;
  917. { for simplicity lets first keep all ansistrings
  918. as LOC_MEM, could also become LOC_REGISTER }
  919. if tstringdef(resulttype.def).string_typ in [st_ansistring,st_widestring] then
  920. { we may use ansistrings so no fast exit here }
  921. procinfo^.no_fast_exit:=true;
  922. location.loc:=LOC_MEM;
  923. end;
  924. function ttypeconvnode.first_char_to_string : tnode;
  925. begin
  926. first_char_to_string:=nil;
  927. location.loc:=LOC_MEM;
  928. end;
  929. function ttypeconvnode.first_nothing : tnode;
  930. begin
  931. first_nothing:=nil;
  932. location.loc:=LOC_MEM;
  933. end;
  934. function ttypeconvnode.first_array_to_pointer : tnode;
  935. begin
  936. first_array_to_pointer:=nil;
  937. if registers32<1 then
  938. registers32:=1;
  939. location.loc:=LOC_REGISTER;
  940. end;
  941. function ttypeconvnode.first_int_to_real : tnode;
  942. begin
  943. first_int_to_real:=nil;
  944. if registersfpu<1 then
  945. registersfpu:=1;
  946. location.loc:=LOC_FPU;
  947. end;
  948. function ttypeconvnode.first_real_to_real : tnode;
  949. begin
  950. first_real_to_real:=nil;
  951. { comp isn't a floating type }
  952. {$ifdef i386}
  953. if (tfloatdef(resulttype.def).typ=s64comp) and
  954. (tfloatdef(left.resulttype.def).typ<>s64comp) and
  955. not (nf_explizit in flags) then
  956. CGMessage(type_w_convert_real_2_comp);
  957. {$endif}
  958. if registersfpu<1 then
  959. registersfpu:=1;
  960. location.loc:=LOC_FPU;
  961. end;
  962. function ttypeconvnode.first_pointer_to_array : tnode;
  963. begin
  964. first_pointer_to_array:=nil;
  965. if registers32<1 then
  966. registers32:=1;
  967. location.loc:=LOC_REFERENCE;
  968. end;
  969. function ttypeconvnode.first_chararray_to_string : tnode;
  970. begin
  971. first_chararray_to_string:=nil;
  972. { the only important information is the location of the }
  973. { result }
  974. { other stuff is done by firsttypeconv }
  975. location.loc:=LOC_MEM;
  976. end;
  977. function ttypeconvnode.first_cchar_to_pchar : tnode;
  978. begin
  979. first_cchar_to_pchar:=nil;
  980. internalerror(200104021);
  981. end;
  982. function ttypeconvnode.first_bool_to_int : tnode;
  983. begin
  984. first_bool_to_int:=nil;
  985. { byte(boolean) or word(wordbool) or longint(longbool) must
  986. be accepted for var parameters }
  987. if (nf_explizit in flags) and
  988. (left.resulttype.def.size=resulttype.def.size) and
  989. (left.location.loc in [LOC_REFERENCE,LOC_MEM,LOC_CREGISTER]) then
  990. exit;
  991. location.loc:=LOC_REGISTER;
  992. if registers32<1 then
  993. registers32:=1;
  994. end;
  995. function ttypeconvnode.first_int_to_bool : tnode;
  996. begin
  997. first_int_to_bool:=nil;
  998. { byte(boolean) or word(wordbool) or longint(longbool) must
  999. be accepted for var parameters }
  1000. if (nf_explizit in flags) and
  1001. (left.resulttype.def.size=resulttype.def.size) and
  1002. (left.location.loc in [LOC_REFERENCE,LOC_MEM,LOC_CREGISTER]) then
  1003. exit;
  1004. location.loc:=LOC_REGISTER;
  1005. { need if bool to bool !!
  1006. not very nice !!
  1007. insertypeconv(left,s32bittype);
  1008. left.explizit:=true;
  1009. firstpass(left); }
  1010. if registers32<1 then
  1011. registers32:=1;
  1012. end;
  1013. function ttypeconvnode.first_bool_to_bool : tnode;
  1014. begin
  1015. first_bool_to_bool:=nil;
  1016. location.loc:=LOC_REGISTER;
  1017. if registers32<1 then
  1018. registers32:=1;
  1019. end;
  1020. function ttypeconvnode.first_char_to_char : tnode;
  1021. begin
  1022. first_char_to_char:=nil;
  1023. location.loc:=LOC_REGISTER;
  1024. if registers32<1 then
  1025. registers32:=1;
  1026. end;
  1027. function ttypeconvnode.first_proc_to_procvar : tnode;
  1028. begin
  1029. first_proc_to_procvar:=nil;
  1030. if (left.location.loc<>LOC_REFERENCE) then
  1031. CGMessage(cg_e_illegal_expression);
  1032. registers32:=left.registers32;
  1033. if registers32<1 then
  1034. registers32:=1;
  1035. location.loc:=LOC_REGISTER;
  1036. end;
  1037. function ttypeconvnode.first_load_smallset : tnode;
  1038. begin
  1039. first_load_smallset:=nil;
  1040. end;
  1041. function ttypeconvnode.first_pchar_to_string : tnode;
  1042. begin
  1043. first_pchar_to_string:=nil;
  1044. location.loc:=LOC_REFERENCE;
  1045. end;
  1046. function ttypeconvnode.first_ansistring_to_pchar : tnode;
  1047. begin
  1048. first_ansistring_to_pchar:=nil;
  1049. location.loc:=LOC_REGISTER;
  1050. if registers32<1 then
  1051. registers32:=1;
  1052. end;
  1053. function ttypeconvnode.first_arrayconstructor_to_set : tnode;
  1054. begin
  1055. first_arrayconstructor_to_set:=nil;
  1056. internalerror(200104022);
  1057. end;
  1058. function ttypeconvnode.first_class_to_intf : tnode;
  1059. begin
  1060. first_class_to_intf:=nil;
  1061. location.loc:=LOC_REFERENCE;
  1062. if registers32<1 then
  1063. registers32:=1;
  1064. end;
  1065. function ttypeconvnode.first_call_helper(c : tconverttype) : tnode;
  1066. const
  1067. firstconvert : array[tconverttype] of pointer = (
  1068. @ttypeconvnode.first_nothing, {equal}
  1069. @ttypeconvnode.first_nothing, {not_possible}
  1070. @ttypeconvnode.first_string_to_string,
  1071. @ttypeconvnode.first_char_to_string,
  1072. @ttypeconvnode.first_pchar_to_string,
  1073. @ttypeconvnode.first_cchar_to_pchar,
  1074. @ttypeconvnode.first_cstring_to_pchar,
  1075. @ttypeconvnode.first_ansistring_to_pchar,
  1076. @ttypeconvnode.first_string_to_chararray,
  1077. @ttypeconvnode.first_chararray_to_string,
  1078. @ttypeconvnode.first_array_to_pointer,
  1079. @ttypeconvnode.first_pointer_to_array,
  1080. @ttypeconvnode.first_int_to_int,
  1081. @ttypeconvnode.first_int_to_bool,
  1082. @ttypeconvnode.first_bool_to_bool,
  1083. @ttypeconvnode.first_bool_to_int,
  1084. @ttypeconvnode.first_real_to_real,
  1085. @ttypeconvnode.first_int_to_real,
  1086. @ttypeconvnode.first_proc_to_procvar,
  1087. @ttypeconvnode.first_arrayconstructor_to_set,
  1088. @ttypeconvnode.first_load_smallset,
  1089. @ttypeconvnode.first_cord_to_pointer,
  1090. @ttypeconvnode.first_nothing,
  1091. @ttypeconvnode.first_nothing,
  1092. @ttypeconvnode.first_class_to_intf,
  1093. @ttypeconvnode.first_char_to_char
  1094. );
  1095. type
  1096. tprocedureofobject = function : tnode of object;
  1097. var
  1098. r : packed record
  1099. proc : pointer;
  1100. obj : pointer;
  1101. end;
  1102. begin
  1103. { this is a little bit dirty but it works }
  1104. { and should be quite portable too }
  1105. r.proc:=firstconvert[c];
  1106. r.obj:=self;
  1107. first_call_helper:=tprocedureofobject(r){$ifdef FPC}();{$endif FPC}
  1108. end;
  1109. function ttypeconvnode.pass_1 : tnode;
  1110. begin
  1111. result:=nil;
  1112. firstpass(left);
  1113. if codegenerror then
  1114. exit;
  1115. { load the value_str from the left part }
  1116. registers32:=left.registers32;
  1117. registersfpu:=left.registersfpu;
  1118. {$ifdef SUPPORT_MMX}
  1119. registersmmx:=left.registersmmx;
  1120. {$endif}
  1121. set_location(location,left.location);
  1122. if nf_explizit in flags then
  1123. begin
  1124. { check if the result could be in a register }
  1125. if not(tstoreddef(resulttype.def).is_intregable) and
  1126. not(tstoreddef(resulttype.def).is_fpuregable) then
  1127. make_not_regable(left);
  1128. end;
  1129. if convtype=tc_equal then
  1130. begin
  1131. { remove typeconv node if left is a const. For other nodes we can't
  1132. remove it because the secondpass can still depend on the old type (PFV) }
  1133. if is_constnode(left) then
  1134. begin
  1135. left.resulttype:=resulttype;
  1136. result:=left;
  1137. left:=nil;
  1138. end;
  1139. end
  1140. else
  1141. begin
  1142. result:=first_call_helper(convtype);
  1143. end;
  1144. end;
  1145. {*****************************************************************************
  1146. TISNODE
  1147. *****************************************************************************}
  1148. constructor tisnode.create(l,r : tnode);
  1149. begin
  1150. inherited create(isn,l,r);
  1151. end;
  1152. function tisnode.det_resulttype:tnode;
  1153. begin
  1154. result:=nil;
  1155. resulttypepass(left);
  1156. resulttypepass(right);
  1157. set_varstate(left,true);
  1158. set_varstate(right,true);
  1159. if codegenerror then
  1160. exit;
  1161. if (right.resulttype.def.deftype=classrefdef) then
  1162. begin
  1163. { left must be a class }
  1164. if is_class(left.resulttype.def) then
  1165. begin
  1166. { the operands must be related }
  1167. if (not(tobjectdef(left.resulttype.def).is_related(
  1168. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1169. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1170. tobjectdef(left.resulttype.def)))) then
  1171. CGMessage(type_e_mismatch);
  1172. end
  1173. else
  1174. CGMessage(type_e_mismatch);
  1175. end
  1176. else
  1177. CGMessage(type_e_mismatch);
  1178. resulttype:=booltype;
  1179. end;
  1180. function tisnode.pass_1 : tnode;
  1181. begin
  1182. result:=nil;
  1183. firstpass(left);
  1184. firstpass(right);
  1185. if codegenerror then
  1186. exit;
  1187. left_right_max;
  1188. location.loc:=LOC_FLAGS;
  1189. end;
  1190. {*****************************************************************************
  1191. TASNODE
  1192. *****************************************************************************}
  1193. constructor tasnode.create(l,r : tnode);
  1194. begin
  1195. inherited create(asn,l,r);
  1196. end;
  1197. function tasnode.det_resulttype:tnode;
  1198. begin
  1199. result:=nil;
  1200. resulttypepass(right);
  1201. resulttypepass(left);
  1202. set_varstate(right,true);
  1203. set_varstate(left,true);
  1204. if codegenerror then
  1205. exit;
  1206. if (right.resulttype.def.deftype=classrefdef) then
  1207. begin
  1208. { left must be a class }
  1209. if is_class(left.resulttype.def) then
  1210. begin
  1211. { the operands must be related }
  1212. if (not(tobjectdef(left.resulttype.def).is_related(
  1213. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1214. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1215. tobjectdef(left.resulttype.def)))) then
  1216. CGMessage(type_e_mismatch);
  1217. end
  1218. else
  1219. CGMessage(type_e_mismatch);
  1220. resulttype:=tclassrefdef(right.resulttype.def).pointertype;
  1221. end
  1222. else
  1223. CGMessage(type_e_mismatch);
  1224. end;
  1225. function tasnode.pass_1 : tnode;
  1226. begin
  1227. result:=nil;
  1228. firstpass(right);
  1229. firstpass(left);
  1230. if codegenerror then
  1231. exit;
  1232. left_right_max;
  1233. set_location(location,left.location);
  1234. end;
  1235. function ttypeconvnode.docompare(p: tnode) : boolean;
  1236. begin
  1237. docompare :=
  1238. inherited docompare(p) and
  1239. (convtype = ttypeconvnode(p).convtype);
  1240. end;
  1241. begin
  1242. ctypeconvnode:=ttypeconvnode;
  1243. casnode:=tasnode;
  1244. cisnode:=tisnode;
  1245. end.
  1246. {
  1247. $Log$
  1248. Revision 1.29 2001-07-08 21:00:15 peter
  1249. * various widestring updates, it works now mostly without charset
  1250. mapping supported
  1251. Revision 1.28 2001/05/13 15:43:46 florian
  1252. * made resultype_char_to_char a little bit robuster
  1253. Revision 1.27 2001/05/08 21:06:30 florian
  1254. * some more support for widechars commited especially
  1255. regarding type casting and constants
  1256. Revision 1.26 2001/05/04 15:52:03 florian
  1257. * some Delphi incompatibilities fixed:
  1258. - out, dispose and new can be used as idenfiers now
  1259. - const p = apointerype(nil); is supported now
  1260. + support for const p = apointertype(pointer(1234)); added
  1261. Revision 1.25 2001/04/13 22:20:58 peter
  1262. * remove wrongly placed first_call_helper
  1263. Revision 1.24 2001/04/13 01:22:08 peter
  1264. * symtable change to classes
  1265. * range check generation and errors fixed, make cycle DEBUG=1 works
  1266. * memory leaks fixed
  1267. Revision 1.23 2001/04/04 22:42:39 peter
  1268. * move constant folding into det_resulttype
  1269. Revision 1.22 2001/04/02 21:20:30 peter
  1270. * resulttype rewrite
  1271. Revision 1.21 2001/03/08 17:44:47 jonas
  1272. * fixed web bug 1430
  1273. Revision 1.20 2001/02/21 11:49:50 jonas
  1274. * evaluate typecasts of const pointers to ordinals inline ('merged')
  1275. Revision 1.19 2001/02/20 18:37:10 peter
  1276. * removed unused code
  1277. Revision 1.18 2001/02/20 13:14:18 marco
  1278. * Fix from Peter for passing a procedure of method to a other method in a method
  1279. Revision 1.17 2001/02/08 13:09:03 jonas
  1280. * fixed web bug 1396: tpointerord is now a cardinal instead of a longint,
  1281. but added a hack in ncnv so that pointer(-1) still works
  1282. Revision 1.16 2000/12/31 11:14:10 jonas
  1283. + implemented/fixed docompare() mathods for all nodes (not tested)
  1284. + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
  1285. and constant strings/chars together
  1286. * n386add.pas: don't copy temp strings (of size 256) to another temp string
  1287. when adding
  1288. Revision 1.15 2000/12/08 12:41:01 jonas
  1289. * fixed bug in sign extension patch
  1290. Revision 1.14 2000/12/07 17:19:42 jonas
  1291. * new constant handling: from now on, hex constants >$7fffffff are
  1292. parsed as unsigned constants (otherwise, $80000000 got sign extended
  1293. and became $ffffffff80000000), all constants in the longint range
  1294. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  1295. are cardinals and the rest are int64's.
  1296. * added lots of longint typecast to prevent range check errors in the
  1297. compiler and rtl
  1298. * type casts of symbolic ordinal constants are now preserved
  1299. * fixed bug where the original resulttype.def wasn't restored correctly
  1300. after doing a 64bit rangecheck
  1301. Revision 1.13 2000/11/29 00:30:32 florian
  1302. * unused units removed from uses clause
  1303. * some changes for widestrings
  1304. Revision 1.12 2000/11/20 16:06:04 jonas
  1305. + allow evaluation of 64bit constant expressions at compile time
  1306. * disable range checking for explicit typecasts of constant expressions
  1307. Revision 1.11 2000/11/12 23:24:11 florian
  1308. * interfaces are basically running
  1309. Revision 1.10 2000/11/04 14:25:20 florian
  1310. + merged Attila's changes for interfaces, not tested yet
  1311. Revision 1.9 2000/10/31 22:02:48 peter
  1312. * symtable splitted, no real code changes
  1313. Revision 1.8 2000/10/14 21:52:55 peter
  1314. * fixed memory leaks
  1315. Revision 1.7 2000/10/14 10:14:50 peter
  1316. * moehrendorf oct 2000 rewrite
  1317. Revision 1.6 2000/10/01 19:48:24 peter
  1318. * lot of compile updates for cg11
  1319. Revision 1.5 2000/09/28 19:49:52 florian
  1320. *** empty log message ***
  1321. Revision 1.4 2000/09/27 18:14:31 florian
  1322. * fixed a lot of syntax errors in the n*.pas stuff
  1323. Revision 1.3 2000/09/26 20:06:13 florian
  1324. * hmm, still a lot of work to get things compilable
  1325. Revision 1.2 2000/09/26 14:59:34 florian
  1326. * more conversion work done
  1327. Revision 1.1 2000/09/25 15:37:14 florian
  1328. * more fixes
  1329. }