ncnv.pas 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 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 fpcdefs.inc}
  20. interface
  21. uses
  22. node,
  23. symtype,defbase,
  24. nld;
  25. type
  26. ttypeconvnode = class(tunarynode)
  27. totype : ttype;
  28. convtype : tconverttype;
  29. constructor create(node : tnode;const t : ttype);virtual;
  30. constructor create_explicit(node : tnode;const t : ttype);
  31. function getcopy : tnode;override;
  32. function pass_1 : tnode;override;
  33. function det_resulttype:tnode;override;
  34. function docompare(p: tnode) : boolean; override;
  35. private
  36. function resulttype_cord_to_pointer : tnode;
  37. function resulttype_chararray_to_string : tnode;
  38. function resulttype_string_to_chararray : tnode;
  39. function resulttype_string_to_string : tnode;
  40. function resulttype_char_to_string : tnode;
  41. function resulttype_char_to_chararray : tnode;
  42. function resulttype_int_to_real : tnode;
  43. function resulttype_real_to_real : tnode;
  44. function resulttype_cchar_to_pchar : tnode;
  45. function resulttype_cstring_to_pchar : tnode;
  46. function resulttype_char_to_char : tnode;
  47. function resulttype_arrayconstructor_to_set : tnode;
  48. function resulttype_pchar_to_string : tnode;
  49. function resulttype_interface_to_guid : tnode;
  50. function resulttype_dynarray_to_openarray : tnode;
  51. function resulttype_call_helper(c : tconverttype) : tnode;
  52. protected
  53. function first_int_to_int : tnode;virtual;
  54. function first_cstring_to_pchar : tnode;virtual;
  55. function first_string_to_chararray : tnode;virtual;
  56. function first_char_to_string : tnode;virtual;
  57. function first_nothing : tnode;virtual;
  58. function first_array_to_pointer : tnode;virtual;
  59. function first_int_to_real : tnode;virtual;
  60. function first_real_to_real : tnode;virtual;
  61. function first_pointer_to_array : tnode;virtual;
  62. function first_cchar_to_pchar : tnode;virtual;
  63. function first_bool_to_int : tnode;virtual;
  64. function first_int_to_bool : tnode;virtual;
  65. function first_bool_to_bool : tnode;virtual;
  66. function first_proc_to_procvar : tnode;virtual;
  67. function first_load_smallset : tnode;virtual;
  68. function first_cord_to_pointer : tnode;virtual;
  69. function first_ansistring_to_pchar : tnode;virtual;
  70. function first_arrayconstructor_to_set : tnode;virtual;
  71. function first_class_to_intf : tnode;virtual;
  72. function first_char_to_char : tnode;virtual;
  73. function first_call_helper(c : tconverttype) : tnode;
  74. { these wrapper are necessary, because the first_* stuff is called }
  75. { through a table. Without the wrappers override wouldn't have }
  76. { any effect }
  77. function _first_int_to_int : tnode;
  78. function _first_cstring_to_pchar : tnode;
  79. function _first_string_to_chararray : tnode;
  80. function _first_char_to_string : tnode;
  81. function _first_nothing : tnode;
  82. function _first_array_to_pointer : tnode;
  83. function _first_int_to_real : tnode;
  84. function _first_real_to_real : tnode;
  85. function _first_pointer_to_array : tnode;
  86. function _first_cchar_to_pchar : tnode;
  87. function _first_bool_to_int : tnode;
  88. function _first_int_to_bool : tnode;
  89. function _first_bool_to_bool : tnode;
  90. function _first_proc_to_procvar : tnode;
  91. function _first_load_smallset : tnode;
  92. function _first_cord_to_pointer : tnode;
  93. function _first_ansistring_to_pchar : tnode;
  94. function _first_arrayconstructor_to_set : tnode;
  95. function _first_class_to_intf : tnode;
  96. function _first_char_to_char : tnode;
  97. procedure second_int_to_int;virtual;abstract;
  98. procedure second_string_to_string;virtual;abstract;
  99. procedure second_cstring_to_pchar;virtual;abstract;
  100. procedure second_string_to_chararray;virtual;abstract;
  101. procedure second_array_to_pointer;virtual;abstract;
  102. procedure second_pointer_to_array;virtual;abstract;
  103. procedure second_chararray_to_string;virtual;abstract;
  104. procedure second_char_to_string;virtual;abstract;
  105. procedure second_int_to_real;virtual;abstract;
  106. procedure second_real_to_real;virtual;abstract;
  107. procedure second_cord_to_pointer;virtual;abstract;
  108. procedure second_proc_to_procvar;virtual;abstract;
  109. procedure second_bool_to_int;virtual;abstract;
  110. procedure second_int_to_bool;virtual;abstract;
  111. procedure second_bool_to_bool;virtual;abstract;
  112. procedure second_load_smallset;virtual;abstract;
  113. procedure second_ansistring_to_pchar;virtual;abstract;
  114. procedure second_pchar_to_string;virtual;abstract;
  115. procedure second_class_to_intf;virtual;abstract;
  116. procedure second_char_to_char;virtual;abstract;
  117. procedure second_nothing; virtual;abstract;
  118. end;
  119. ttypeconvnodeclass = class of ttypeconvnode;
  120. tasnode = class(tbinarynode)
  121. constructor create(l,r : tnode);virtual;
  122. function pass_1 : tnode;override;
  123. function det_resulttype:tnode;override;
  124. end;
  125. tasnodeclass = class of tasnode;
  126. tisnode = class(tbinarynode)
  127. constructor create(l,r : tnode);virtual;
  128. function pass_1 : tnode;override;
  129. function det_resulttype:tnode;override;
  130. procedure pass_2;override;
  131. end;
  132. tisnodeclass = class of tisnode;
  133. var
  134. ctypeconvnode : ttypeconvnodeclass;
  135. casnode : tasnodeclass;
  136. cisnode : tisnodeclass;
  137. procedure inserttypeconv(var p:tnode;const t:ttype);
  138. procedure inserttypeconv_explicit(var p:tnode;const t:ttype);
  139. procedure arrayconstructor_to_set(var p : tnode);
  140. implementation
  141. uses
  142. globtype,systems,tokens,
  143. cutils,verbose,globals,widestr,
  144. symconst,symdef,symsym,symtable,
  145. ncon,ncal,nset,nadd,ninl,nmem,nmat,
  146. cgbase,
  147. htypechk,pass_1,cpubase,cpuinfo;
  148. {*****************************************************************************
  149. Helpers
  150. *****************************************************************************}
  151. procedure inserttypeconv(var p:tnode;const t:ttype);
  152. begin
  153. if not assigned(p.resulttype.def) then
  154. begin
  155. resulttypepass(p);
  156. if codegenerror then
  157. exit;
  158. end;
  159. { don't insert obsolete type conversions }
  160. if is_equal(p.resulttype.def,t.def) and
  161. not ((p.resulttype.def.deftype=setdef) and
  162. (tsetdef(p.resulttype.def).settype <>
  163. tsetdef(t.def).settype)) then
  164. begin
  165. p.resulttype:=t;
  166. end
  167. else
  168. begin
  169. p:=ctypeconvnode.create(p,t);
  170. resulttypepass(p);
  171. end;
  172. end;
  173. procedure inserttypeconv_explicit(var p:tnode;const t:ttype);
  174. begin
  175. if not assigned(p.resulttype.def) then
  176. begin
  177. resulttypepass(p);
  178. if codegenerror then
  179. exit;
  180. end;
  181. { don't insert obsolete type conversions }
  182. if is_equal(p.resulttype.def,t.def) and
  183. not ((p.resulttype.def.deftype=setdef) and
  184. (tsetdef(p.resulttype.def).settype <>
  185. tsetdef(t.def).settype)) then
  186. begin
  187. p.resulttype:=t;
  188. end
  189. else
  190. begin
  191. p:=ctypeconvnode.create_explicit(p,t);
  192. resulttypepass(p);
  193. end;
  194. end;
  195. {*****************************************************************************
  196. Array constructor to Set Conversion
  197. *****************************************************************************}
  198. procedure arrayconstructor_to_set(var p : tnode);
  199. var
  200. constp : tsetconstnode;
  201. buildp,
  202. p2,p3,p4 : tnode;
  203. htype : ttype;
  204. constset : Pconstset;
  205. constsetlo,
  206. constsethi : longint;
  207. procedure update_constsethi(t:ttype);
  208. begin
  209. if ((t.def.deftype=orddef) and
  210. (torddef(t.def).high>=constsethi)) then
  211. begin
  212. constsethi:=torddef(t.def).high;
  213. if htype.def=nil then
  214. begin
  215. if (constsethi>255) or
  216. (torddef(t.def).low<0) then
  217. htype:=u8bittype
  218. else
  219. htype:=t;
  220. end;
  221. if constsethi>255 then
  222. constsethi:=255;
  223. end
  224. else if ((t.def.deftype=enumdef) and
  225. (tenumdef(t.def).max>=constsethi)) then
  226. begin
  227. if htype.def=nil then
  228. htype:=t;
  229. constsethi:=tenumdef(t.def).max;
  230. end;
  231. end;
  232. procedure do_set(pos : longint);
  233. {$ifdef oldset}
  234. var
  235. mask,l : longint;
  236. {$endif}
  237. begin
  238. if (pos and not $ff)<>0 then
  239. Message(parser_e_illegal_set_expr);
  240. if pos>constsethi then
  241. constsethi:=pos;
  242. if pos<constsetlo then
  243. constsetlo:=pos;
  244. {$ifdef oldset}
  245. { to do this correctly we use the 32bit array }
  246. l:=pos shr 5;
  247. mask:=1 shl (pos mod 32);
  248. { do we allow the same twice }
  249. if (pconst32bitset(constset)^[l] and mask)<>0 then
  250. Message(parser_e_illegal_set_expr);
  251. pconst32bitset(constset)^[l]:=pconst32bitset(constset)^[l] or mask;
  252. {$else}
  253. include(constset^,pos);
  254. {$endif}
  255. end;
  256. var
  257. l : Longint;
  258. lr,hr : TConstExprInt;
  259. hp : tarrayconstructornode;
  260. begin
  261. if p.nodetype<>arrayconstructorn then
  262. internalerror(200205105);
  263. new(constset);
  264. {$ifdef oldset}
  265. FillChar(constset^,sizeof(constset^),0);
  266. {$else}
  267. constset^:=[];
  268. {$endif}
  269. htype.reset;
  270. constsetlo:=0;
  271. constsethi:=0;
  272. constp:=csetconstnode.create(nil,htype);
  273. constp.value_set:=constset;
  274. buildp:=constp;
  275. hp:=tarrayconstructornode(p);
  276. if assigned(hp.left) then
  277. begin
  278. while assigned(hp) do
  279. begin
  280. p4:=nil; { will contain the tree to create the set }
  281. {split a range into p2 and p3 }
  282. if hp.left.nodetype=arrayconstructorrangen then
  283. begin
  284. p2:=tarrayconstructorrangenode(hp.left).left;
  285. p3:=tarrayconstructorrangenode(hp.left).right;
  286. tarrayconstructorrangenode(hp.left).left:=nil;
  287. tarrayconstructorrangenode(hp.left).right:=nil;
  288. end
  289. else
  290. begin
  291. p2:=hp.left;
  292. hp.left:=nil;
  293. p3:=nil;
  294. end;
  295. resulttypepass(p2);
  296. if assigned(p3) then
  297. resulttypepass(p3);
  298. if codegenerror then
  299. break;
  300. case p2.resulttype.def.deftype of
  301. enumdef,
  302. orddef:
  303. begin
  304. getrange(p2.resulttype.def,lr,hr);
  305. if assigned(p3) then
  306. begin
  307. { this isn't good, you'll get problems with
  308. type t010 = 0..10;
  309. ts = set of t010;
  310. var s : ts;b : t010
  311. begin s:=[1,2,b]; end.
  312. if is_integer(p3^.resulttype.def) then
  313. begin
  314. inserttypeconv(p3,u8bitdef);
  315. end;
  316. }
  317. if assigned(htype.def) and not(is_equal(htype.def,p3.resulttype.def)) then
  318. begin
  319. aktfilepos:=p3.fileinfo;
  320. CGMessage(type_e_typeconflict_in_set);
  321. end
  322. else
  323. begin
  324. if (p2.nodetype=ordconstn) and (p3.nodetype=ordconstn) then
  325. begin
  326. if not(is_integer(p3.resulttype.def)) then
  327. htype:=p3.resulttype
  328. else
  329. begin
  330. inserttypeconv(p3,u8bittype);
  331. inserttypeconv(p2,u8bittype);
  332. end;
  333. for l:=tordconstnode(p2).value to tordconstnode(p3).value do
  334. do_set(l);
  335. p2.free;
  336. p3.free;
  337. end
  338. else
  339. begin
  340. update_constsethi(p2.resulttype);
  341. inserttypeconv(p2,htype);
  342. update_constsethi(p3.resulttype);
  343. inserttypeconv(p3,htype);
  344. if assigned(htype.def) then
  345. inserttypeconv(p3,htype)
  346. else
  347. inserttypeconv(p3,u8bittype);
  348. p4:=csetelementnode.create(p2,p3);
  349. end;
  350. end;
  351. end
  352. else
  353. begin
  354. { Single value }
  355. if p2.nodetype=ordconstn then
  356. begin
  357. if not(is_integer(p2.resulttype.def)) then
  358. update_constsethi(p2.resulttype)
  359. else
  360. inserttypeconv(p2,u8bittype);
  361. do_set(tordconstnode(p2).value);
  362. p2.free;
  363. end
  364. else
  365. begin
  366. update_constsethi(p2.resulttype);
  367. if assigned(htype.def) then
  368. inserttypeconv(p2,htype)
  369. else
  370. inserttypeconv(p2,u8bittype);
  371. p4:=csetelementnode.create(p2,nil);
  372. end;
  373. end;
  374. end;
  375. stringdef :
  376. begin
  377. { if we've already set elements which are constants }
  378. { throw an error }
  379. if ((htype.def=nil) and assigned(buildp)) or
  380. not(is_char(htype.def)) then
  381. CGMessage(type_e_typeconflict_in_set)
  382. else
  383. for l:=1 to length(pstring(tstringconstnode(p2).value_str)^) do
  384. do_set(ord(pstring(tstringconstnode(p2).value_str)^[l]));
  385. if htype.def=nil then
  386. htype:=cchartype;
  387. p2.free;
  388. end;
  389. else
  390. CGMessage(type_e_ordinal_expr_expected);
  391. end;
  392. { insert the set creation tree }
  393. if assigned(p4) then
  394. buildp:=caddnode.create(addn,buildp,p4);
  395. { load next and dispose current node }
  396. p2:=hp;
  397. hp:=tarrayconstructornode(tarrayconstructornode(p2).right);
  398. tarrayconstructornode(p2).right:=nil;
  399. p2.free;
  400. end;
  401. if (htype.def=nil) then
  402. htype:=u8bittype;
  403. end
  404. else
  405. begin
  406. { empty set [], only remove node }
  407. p.free;
  408. end;
  409. { set the initial set type }
  410. constp.resulttype.setdef(tsetdef.create(htype,constsethi));
  411. { determine the resulttype for the tree }
  412. resulttypepass(buildp);
  413. { set the new tree }
  414. p:=buildp;
  415. end;
  416. {*****************************************************************************
  417. TTYPECONVNODE
  418. *****************************************************************************}
  419. constructor ttypeconvnode.create(node : tnode;const t:ttype);
  420. begin
  421. inherited create(typeconvn,node);
  422. convtype:=tc_not_possible;
  423. totype:=t;
  424. if t.def=nil then
  425. internalerror(200103281);
  426. set_file_line(node);
  427. end;
  428. constructor ttypeconvnode.create_explicit(node : tnode;const t:ttype);
  429. begin
  430. self.create(node,t);
  431. toggleflag(nf_explizit);
  432. end;
  433. function ttypeconvnode.getcopy : tnode;
  434. var
  435. n : ttypeconvnode;
  436. begin
  437. n:=ttypeconvnode(inherited getcopy);
  438. n.convtype:=convtype;
  439. getcopy:=n;
  440. end;
  441. function ttypeconvnode.resulttype_cord_to_pointer : tnode;
  442. var
  443. t : tnode;
  444. begin
  445. result:=nil;
  446. if left.nodetype=ordconstn then
  447. begin
  448. { check if we have a valid pointer constant (JM) }
  449. if (sizeof(pointer) > sizeof(TConstPtrUInt)) then
  450. if (sizeof(TConstPtrUInt) = 4) then
  451. begin
  452. if (tordconstnode(left).value < low(longint)) or
  453. (tordconstnode(left).value > high(cardinal)) then
  454. CGMessage(parser_e_range_check_error);
  455. end
  456. else if (sizeof(TConstPtrUInt) = 8) then
  457. begin
  458. if (tordconstnode(left).value < low(int64)) or
  459. (tordconstnode(left).value > high(qword)) then
  460. CGMessage(parser_e_range_check_error);
  461. end
  462. else
  463. internalerror(2001020801);
  464. t:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value),resulttype);
  465. result:=t;
  466. end
  467. else
  468. internalerror(200104023);
  469. end;
  470. function ttypeconvnode.resulttype_chararray_to_string : tnode;
  471. begin
  472. result := ccallnode.createinternres(
  473. 'fpc_chararray_to_'+tstringdef(resulttype.def).stringtypname,
  474. ccallparanode.create(left,nil),resulttype);
  475. left := nil;
  476. end;
  477. function ttypeconvnode.resulttype_string_to_chararray : tnode;
  478. var
  479. arrsize: longint;
  480. begin
  481. with tarraydef(resulttype.def) do
  482. begin
  483. if highrange<lowrange then
  484. internalerror(75432653);
  485. arrsize := highrange-lowrange+1;
  486. end;
  487. if (left.nodetype = stringconstn) and
  488. { left.length+1 since there's always a terminating #0 character (JM) }
  489. (tstringconstnode(left).len+1 >= arrsize) and
  490. (tstringdef(left.resulttype.def).string_typ=st_shortstring) then
  491. begin
  492. { handled separately }
  493. result := nil;
  494. exit;
  495. end;
  496. result := ccallnode.createinternres(
  497. 'fpc_'+tstringdef(left.resulttype.def).stringtypname+
  498. '_to_chararray',ccallparanode.create(left,ccallparanode.create(
  499. cordconstnode.create(arrsize,s32bittype),nil)),resulttype);
  500. left := nil;
  501. end;
  502. function ttypeconvnode.resulttype_string_to_string : tnode;
  503. var
  504. procname: string[31];
  505. stringpara : tcallparanode;
  506. pw : pcompilerwidestring;
  507. pc : pchar;
  508. begin
  509. result:=nil;
  510. if left.nodetype=stringconstn then
  511. begin
  512. { convert ascii 2 unicode }
  513. if (tstringdef(resulttype.def).string_typ=st_widestring) and
  514. (tstringconstnode(left).st_type in [st_ansistring,st_shortstring,st_longstring]) then
  515. begin
  516. initwidestring(pw);
  517. ascii2unicode(tstringconstnode(left).value_str,tstringconstnode(left).len,pw);
  518. ansistringdispose(tstringconstnode(left).value_str,tstringconstnode(left).len);
  519. pcompilerwidestring(tstringconstnode(left).value_str):=pw;
  520. end
  521. else
  522. { convert unicode 2 ascii }
  523. if (tstringconstnode(left).st_type=st_widestring) and
  524. (tstringdef(resulttype.def).string_typ in [st_ansistring,st_shortstring,st_longstring]) then
  525. begin
  526. pw:=pcompilerwidestring(tstringconstnode(left).value_str);
  527. getmem(pc,getlengthwidestring(pw)+1);
  528. unicode2ascii(pw,pc);
  529. donewidestring(pw);
  530. tstringconstnode(left).value_str:=pc;
  531. end;
  532. tstringconstnode(left).st_type:=tstringdef(resulttype.def).string_typ;
  533. tstringconstnode(left).resulttype:=resulttype;
  534. result:=left;
  535. left:=nil;
  536. end
  537. else
  538. begin
  539. { get the correct procedure name }
  540. procname := 'fpc_'+tstringdef(left.resulttype.def).stringtypname+
  541. '_to_'+tstringdef(resulttype.def).stringtypname;
  542. { create parameter (and remove left node from typeconvnode }
  543. { since it's reused as parameter) }
  544. stringpara := ccallparanode.create(left,nil);
  545. left := nil;
  546. { when converting to shortstrings, we have to pass high(destination) too }
  547. if (tstringdef(resulttype.def).string_typ = st_shortstring) then
  548. stringpara.right := ccallparanode.create(cinlinenode.create(
  549. in_high_x,false,self.getcopy),nil);
  550. { and create the callnode }
  551. result := ccallnode.createinternres(procname,stringpara,resulttype);
  552. end;
  553. end;
  554. function ttypeconvnode.resulttype_char_to_string : tnode;
  555. var
  556. procname: string[31];
  557. para : tcallparanode;
  558. hp : tstringconstnode;
  559. ws : pcompilerwidestring;
  560. begin
  561. result:=nil;
  562. if left.nodetype=ordconstn then
  563. begin
  564. if tstringdef(resulttype.def).string_typ=st_widestring then
  565. begin
  566. initwidestring(ws);
  567. concatwidestringchar(ws,tcompilerwidechar(chr(tordconstnode(left).value)));
  568. hp:=cstringconstnode.createwstr(ws);
  569. donewidestring(ws);
  570. end
  571. else
  572. hp:=cstringconstnode.createstr(chr(tordconstnode(left).value),tstringdef(resulttype.def).string_typ);
  573. result:=hp;
  574. end
  575. else
  576. { shortstrings are handled 'inline' }
  577. if tstringdef(resulttype.def).string_typ <> st_shortstring then
  578. begin
  579. { create the parameter }
  580. para := ccallparanode.create(left,nil);
  581. left := nil;
  582. { and the procname }
  583. procname := 'fpc_char_to_' +tstringdef(resulttype.def).stringtypname;
  584. { and finally the call }
  585. result := ccallnode.createinternres(procname,para,resulttype);
  586. end
  587. else
  588. begin
  589. { create word(byte(char) shl 8 or 1) for litte endian machines }
  590. { and word(byte(char) or 256) for big endian machines }
  591. left := ctypeconvnode.create(left,u8bittype);
  592. left.toggleflag(nf_explizit);
  593. if (target_info.endian = endian_little) then
  594. left := caddnode.create(orn,
  595. cshlshrnode.create(shln,left,cordconstnode.create(8,s32bittype)),
  596. cordconstnode.create(1,s32bittype))
  597. else
  598. left := caddnode.create(orn,left,
  599. cordconstnode.create(1 shl 8,s32bittype));
  600. left := ctypeconvnode.create(left,u16bittype);
  601. left.toggleflag(nf_explizit);
  602. resulttypepass(left);
  603. end;
  604. end;
  605. function ttypeconvnode.resulttype_char_to_chararray : tnode;
  606. begin
  607. if resulttype.def.size <> 1 then
  608. begin
  609. { convert first to string, then to chararray }
  610. inserttypeconv(left,cshortstringtype);
  611. inserttypeconv(left,resulttype);
  612. result:=left;
  613. left := nil;
  614. exit;
  615. end;
  616. result := nil;
  617. end;
  618. function ttypeconvnode.resulttype_char_to_char : tnode;
  619. var
  620. hp : tordconstnode;
  621. begin
  622. result:=nil;
  623. if left.nodetype=ordconstn then
  624. begin
  625. if (torddef(resulttype.def).typ=uchar) and
  626. (torddef(left.resulttype.def).typ=uwidechar) then
  627. begin
  628. hp:=cordconstnode.create(
  629. ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value))),cchartype);
  630. result:=hp;
  631. end
  632. else if (torddef(resulttype.def).typ=uwidechar) and
  633. (torddef(left.resulttype.def).typ=uchar) then
  634. begin
  635. hp:=cordconstnode.create(
  636. asciichar2unicode(chr(tordconstnode(left).value)),cwidechartype);
  637. result:=hp;
  638. end
  639. else
  640. internalerror(200105131);
  641. exit;
  642. end;
  643. end;
  644. function ttypeconvnode.resulttype_int_to_real : tnode;
  645. var
  646. t : trealconstnode;
  647. begin
  648. result:=nil;
  649. if left.nodetype=ordconstn then
  650. begin
  651. t:=crealconstnode.create(tordconstnode(left).value,resulttype);
  652. result:=t;
  653. end;
  654. end;
  655. function ttypeconvnode.resulttype_real_to_real : tnode;
  656. var
  657. t : tnode;
  658. begin
  659. result:=nil;
  660. if is_currency(left.resulttype.def) and not(is_currency(resulttype.def)) then
  661. begin
  662. end
  663. else
  664. if is_currency(resulttype.def) then
  665. begin
  666. end;
  667. if left.nodetype=realconstn then
  668. begin
  669. t:=crealconstnode.create(trealconstnode(left).value_real,resulttype);
  670. result:=t;
  671. end;
  672. end;
  673. function ttypeconvnode.resulttype_cchar_to_pchar : tnode;
  674. begin
  675. result:=nil;
  676. if is_pwidechar(resulttype.def) then
  677. inserttypeconv(left,cwidestringtype)
  678. else
  679. inserttypeconv(left,cshortstringtype);
  680. { evaluate again, reset resulttype so the convert_typ
  681. will be calculated again and cstring_to_pchar will
  682. be used for futher conversion }
  683. result:=det_resulttype;
  684. end;
  685. function ttypeconvnode.resulttype_cstring_to_pchar : tnode;
  686. begin
  687. result:=nil;
  688. if is_pwidechar(resulttype.def) then
  689. inserttypeconv(left,cwidestringtype);
  690. end;
  691. function ttypeconvnode.resulttype_arrayconstructor_to_set : tnode;
  692. var
  693. hp : tnode;
  694. begin
  695. result:=nil;
  696. if left.nodetype<>arrayconstructorn then
  697. internalerror(5546);
  698. { remove typeconv node }
  699. hp:=left;
  700. left:=nil;
  701. { create a set constructor tree }
  702. arrayconstructor_to_set(hp);
  703. result:=hp;
  704. end;
  705. function ttypeconvnode.resulttype_pchar_to_string : tnode;
  706. begin
  707. result := ccallnode.createinternres(
  708. 'fpc_pchar_to_'+tstringdef(resulttype.def).stringtypname,
  709. ccallparanode.create(left,nil),resulttype);
  710. left := nil;
  711. end;
  712. function ttypeconvnode.resulttype_interface_to_guid : tnode;
  713. begin
  714. if tobjectdef(left.resulttype.def).isiidguidvalid then
  715. result:=cguidconstnode.create(tobjectdef(left.resulttype.def).iidguid);
  716. end;
  717. function ttypeconvnode.resulttype_dynarray_to_openarray : tnode;
  718. begin
  719. { a dynamic array is a pointer to an array, so to convert it to }
  720. { an open array, we have to dereference it (JM) }
  721. result := ctypeconvnode.create(left,voidpointertype);
  722. { left is reused }
  723. left := nil;
  724. result.toggleflag(nf_explizit);
  725. result := cderefnode.create(result);
  726. result.resulttype := resulttype;
  727. end;
  728. function ttypeconvnode.resulttype_call_helper(c : tconverttype) : tnode;
  729. const
  730. resulttypeconvert : array[tconverttype] of pointer = (
  731. {equal} nil,
  732. {not_possible} nil,
  733. { string_2_string } @ttypeconvnode.resulttype_string_to_string,
  734. { char_2_string } @ttypeconvnode.resulttype_char_to_string,
  735. { char_2_chararray } @ttypeconvnode.resulttype_char_to_chararray,
  736. { pchar_2_string } @ttypeconvnode.resulttype_pchar_to_string,
  737. { cchar_2_pchar } @ttypeconvnode.resulttype_cchar_to_pchar,
  738. { cstring_2_pchar } @ttypeconvnode.resulttype_cstring_to_pchar,
  739. { ansistring_2_pchar } nil,
  740. { string_2_chararray } @ttypeconvnode.resulttype_string_to_chararray,
  741. { chararray_2_string } @ttypeconvnode.resulttype_chararray_to_string,
  742. { array_2_pointer } nil,
  743. { pointer_2_array } nil,
  744. { int_2_int } nil,
  745. { int_2_bool } nil,
  746. { bool_2_bool } nil,
  747. { bool_2_int } nil,
  748. { real_2_real } @ttypeconvnode.resulttype_real_to_real,
  749. { int_2_real } @ttypeconvnode.resulttype_int_to_real,
  750. { proc_2_procvar } nil,
  751. { arrayconstructor_2_set } @ttypeconvnode.resulttype_arrayconstructor_to_set,
  752. { load_smallset } nil,
  753. { cord_2_pointer } @ttypeconvnode.resulttype_cord_to_pointer,
  754. { intf_2_string } nil,
  755. { intf_2_guid } @ttypeconvnode.resulttype_interface_to_guid,
  756. { class_2_intf } nil,
  757. { char_2_char } @ttypeconvnode.resulttype_char_to_char,
  758. { normal_2_smallset} nil,
  759. { dynarray_2_openarray} @resulttype_dynarray_to_openarray
  760. );
  761. type
  762. tprocedureofobject = function : tnode of object;
  763. var
  764. r : packed record
  765. proc : pointer;
  766. obj : pointer;
  767. end;
  768. begin
  769. result:=nil;
  770. { this is a little bit dirty but it works }
  771. { and should be quite portable too }
  772. r.proc:=resulttypeconvert[c];
  773. r.obj:=self;
  774. if assigned(r.proc) then
  775. result:=tprocedureofobject(r){$ifdef FPC}();{$endif FPC}
  776. end;
  777. function ttypeconvnode.det_resulttype:tnode;
  778. var
  779. hp : tnode;
  780. currprocdef,
  781. aprocdef : tprocdef;
  782. begin
  783. result:=nil;
  784. resulttype:=totype;
  785. resulttypepass(left);
  786. if codegenerror then
  787. exit;
  788. { remove obsolete type conversions }
  789. if is_equal(left.resulttype.def,resulttype.def) then
  790. begin
  791. { becuase is_equal only checks the basetype for sets we need to
  792. check here if we are loading a smallset into a normalset }
  793. if (resulttype.def.deftype=setdef) and
  794. (left.resulttype.def.deftype=setdef) and
  795. ((tsetdef(resulttype.def).settype = smallset) xor
  796. (tsetdef(left.resulttype.def).settype = smallset)) then
  797. begin
  798. { constant sets can be converted by changing the type only }
  799. if (left.nodetype=setconstn) then
  800. begin
  801. tsetdef(left.resulttype.def).changesettype(tsetdef(resulttype.def).settype);
  802. result:=left;
  803. left:=nil;
  804. exit;
  805. end;
  806. if (tsetdef(resulttype.def).settype <> smallset) then
  807. convtype:=tc_load_smallset
  808. else
  809. convtype := tc_normal_2_smallset;
  810. exit;
  811. end
  812. else
  813. begin
  814. left.resulttype:=resulttype;
  815. result:=left;
  816. left:=nil;
  817. exit;
  818. end;
  819. end;
  820. aprocdef:=assignment_overloaded(left.resulttype.def,resulttype.def);
  821. if assigned(aprocdef) then
  822. begin
  823. procinfo^.flags:=procinfo^.flags or pi_do_call;
  824. hp:=ccallnode.create(ccallparanode.create(left,nil),
  825. overloaded_operators[_assignment],nil,nil);
  826. { tell explicitly which def we must use !! (PM) }
  827. tcallnode(hp).procdefinition:=aprocdef;
  828. left:=nil;
  829. result:=hp;
  830. exit;
  831. end;
  832. if isconvertable(left.resulttype.def,resulttype.def,convtype,left.nodetype,nf_explizit in flags)=0 then
  833. begin
  834. {Procedures have a resulttype.def of voiddef and functions of their
  835. own resulttype.def. They will therefore always be incompatible with
  836. a procvar. Because isconvertable cannot check for procedures we
  837. use an extra check for them.}
  838. if (m_tp_procvar in aktmodeswitches) then
  839. begin
  840. if (resulttype.def.deftype=procvardef) and
  841. (is_procsym_load(left) or is_procsym_call(left)) then
  842. begin
  843. if is_procsym_call(left) then
  844. begin
  845. currprocdef:=Tprocsym(Tcallnode(left).symtableprocentry).search_procdef_byprocvardef(Tprocvardef(resulttype.def));
  846. hp:=cloadnode.create_procvar(tprocsym(tcallnode(left).symtableprocentry),
  847. currprocdef,tcallnode(left).symtableproc);
  848. if (tcallnode(left).symtableprocentry.owner.symtabletype=objectsymtable) and
  849. assigned(tcallnode(left).methodpointer) then
  850. tloadnode(hp).set_mp(tcallnode(left).methodpointer.getcopy);
  851. resulttypepass(hp);
  852. left.free;
  853. left:=hp;
  854. aprocdef:=tprocdef(left.resulttype.def);
  855. end
  856. else
  857. begin
  858. if (left.nodetype<>addrn) then
  859. aprocdef:=tprocsym(tloadnode(left).symtableentry).first_procdef;
  860. end;
  861. convtype:=tc_proc_2_procvar;
  862. { Now check if the procedure we are going to assign to
  863. the procvar, is compatible with the procvar's type }
  864. if assigned(aprocdef) then
  865. begin
  866. if not proc_to_procvar_equal(aprocdef,tprocvardef(resulttype.def),false) then
  867. CGMessage2(type_e_incompatible_types,aprocdef.typename,resulttype.def.typename);
  868. end
  869. else
  870. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  871. exit;
  872. end;
  873. end;
  874. if nf_explizit in flags then
  875. begin
  876. { check if the result could be in a register }
  877. if not(tstoreddef(resulttype.def).is_intregable) and
  878. not(tstoreddef(resulttype.def).is_fpuregable) then
  879. make_not_regable(left);
  880. { boolean to byte are special because the
  881. location can be different }
  882. if is_integer(resulttype.def) and
  883. is_boolean(left.resulttype.def) then
  884. begin
  885. convtype:=tc_bool_2_int;
  886. exit;
  887. end;
  888. if is_char(resulttype.def) and
  889. is_boolean(left.resulttype.def) then
  890. begin
  891. convtype:=tc_bool_2_int;
  892. exit;
  893. end;
  894. { ansistring to pchar }
  895. if is_pchar(resulttype.def) and
  896. is_ansistring(left.resulttype.def) then
  897. begin
  898. convtype:=tc_ansistring_2_pchar;
  899. exit;
  900. end;
  901. { do common tc_equal cast }
  902. convtype:=tc_equal;
  903. { enum to ordinal will always be s32bit }
  904. if (left.resulttype.def.deftype=enumdef) and
  905. is_ordinal(resulttype.def) then
  906. begin
  907. if left.nodetype=ordconstn then
  908. begin
  909. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  910. result:=hp;
  911. exit;
  912. end
  913. else
  914. begin
  915. if isconvertable(s32bittype.def,resulttype.def,convtype,ordconstn,false)=0 then
  916. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  917. end;
  918. end
  919. { ordinal to enumeration }
  920. else
  921. if (resulttype.def.deftype=enumdef) and
  922. is_ordinal(left.resulttype.def) then
  923. begin
  924. if left.nodetype=ordconstn then
  925. begin
  926. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  927. result:=hp;
  928. exit;
  929. end
  930. else
  931. begin
  932. if IsConvertable(left.resulttype.def,s32bittype.def,convtype,ordconstn,false)=0 then
  933. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  934. end;
  935. end
  936. { nil to ordinal node }
  937. else if (left.nodetype=niln) and is_ordinal(resulttype.def) then
  938. begin
  939. hp:=cordconstnode.create(0,resulttype);
  940. result:=hp;
  941. exit;
  942. end
  943. { constant pointer to ordinal }
  944. else if is_ordinal(resulttype.def) and
  945. (left.nodetype=pointerconstn) then
  946. begin
  947. hp:=cordconstnode.create(tpointerconstnode(left).value,resulttype);
  948. result:=hp;
  949. exit;
  950. end
  951. { class to class or object to object, with checkobject support }
  952. else if (resulttype.def.deftype=objectdef) and
  953. (left.resulttype.def.deftype=objectdef) then
  954. begin
  955. if (cs_check_object in aktlocalswitches) then
  956. begin
  957. if is_class_or_interface(resulttype.def) then
  958. begin
  959. { we can translate the typeconvnode to 'as' when
  960. typecasting to a class or interface }
  961. hp:=casnode.create(left,cloadvmtnode.create(ctypenode.create(resulttype)));
  962. left:=nil;
  963. result:=hp;
  964. exit;
  965. end;
  966. end
  967. else
  968. begin
  969. { check if the types are related }
  970. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(resulttype.def)))) and
  971. (not(tobjectdef(resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  972. CGMessage2(type_w_classes_not_related,left.resulttype.def.typename,resulttype.def.typename);
  973. end;
  974. end
  975. {Are we typecasting an ordconst to a char?}
  976. else
  977. if is_char(resulttype.def) and
  978. is_ordinal(left.resulttype.def) then
  979. begin
  980. if left.nodetype=ordconstn then
  981. begin
  982. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  983. result:=hp;
  984. exit;
  985. end
  986. else
  987. begin
  988. if IsConvertable(left.resulttype.def,u8bittype.def,convtype,ordconstn,false)=0 then
  989. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  990. end;
  991. end
  992. {Are we typecasting an ordconst to a wchar?}
  993. else
  994. if is_widechar(resulttype.def) and
  995. is_ordinal(left.resulttype.def) then
  996. begin
  997. if left.nodetype=ordconstn then
  998. begin
  999. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  1000. result:=hp;
  1001. exit;
  1002. end
  1003. else
  1004. begin
  1005. if IsConvertable(left.resulttype.def,u16bittype.def,convtype,ordconstn,false)=0 then
  1006. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1007. end;
  1008. end
  1009. { char to ordinal }
  1010. else
  1011. if is_char(left.resulttype.def) and
  1012. is_ordinal(resulttype.def) then
  1013. begin
  1014. if left.nodetype=ordconstn then
  1015. begin
  1016. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  1017. result:=hp;
  1018. exit;
  1019. end
  1020. else
  1021. begin
  1022. if IsConvertable(u8bittype.def,resulttype.def,convtype,ordconstn,false)=0 then
  1023. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1024. end;
  1025. end
  1026. { widechar to ordinal }
  1027. else
  1028. if is_widechar(left.resulttype.def) and
  1029. is_ordinal(resulttype.def) then
  1030. begin
  1031. if left.nodetype=ordconstn then
  1032. begin
  1033. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  1034. result:=hp;
  1035. exit;
  1036. end
  1037. else
  1038. begin
  1039. if IsConvertable(u16bittype.def,resulttype.def,convtype,ordconstn,false)=0 then
  1040. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1041. end;
  1042. end
  1043. { ordinal to pointer }
  1044. else
  1045. if (m_delphi in aktmodeswitches) and
  1046. is_ordinal(left.resulttype.def) and
  1047. (resulttype.def.deftype=pointerdef) then
  1048. begin
  1049. if left.nodetype=pointerconstn then
  1050. begin
  1051. hp:=cordconstnode.create(tpointerconstnode(left).value,resulttype);
  1052. result:=hp;
  1053. exit;
  1054. end
  1055. else
  1056. begin
  1057. if IsConvertable(left.resulttype.def,ordpointertype.def,convtype,ordconstn,false)=0 then
  1058. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1059. end;
  1060. end
  1061. { only if the same size or formal def }
  1062. { why do we allow typecasting of voiddef ?? (PM) }
  1063. else
  1064. begin
  1065. if not(
  1066. (left.resulttype.def.deftype=formaldef) or
  1067. (left.resulttype.def.size=resulttype.def.size) or
  1068. (is_void(left.resulttype.def) and
  1069. (left.nodetype=derefn))
  1070. ) then
  1071. CGMessage(cg_e_illegal_type_conversion);
  1072. if ((left.resulttype.def.deftype=orddef) and
  1073. (resulttype.def.deftype=pointerdef)) or
  1074. ((resulttype.def.deftype=orddef) and
  1075. (left.resulttype.def.deftype=pointerdef)) then
  1076. CGMessage(cg_d_pointer_to_longint_conv_not_portable);
  1077. end;
  1078. { the conversion into a strutured type is only }
  1079. { possible, if the source is not a register }
  1080. if ((resulttype.def.deftype in [recorddef,stringdef,arraydef]) or
  1081. ((resulttype.def.deftype=objectdef) and not(is_class(resulttype.def)))
  1082. ) and (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) { and
  1083. it also works if the assignment is overloaded
  1084. YES but this code is not executed if assignment is overloaded (PM)
  1085. not assigned(assignment_overloaded(left.resulttype.def,resulttype.def))} then
  1086. CGMessage(cg_e_illegal_type_conversion);
  1087. end
  1088. else
  1089. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1090. end;
  1091. { tp7 procvar support, when right is not a procvardef and we got a
  1092. loadn of a procvar then convert to a calln, the check for the
  1093. result is already done in is_convertible, also no conflict with
  1094. @procvar is here because that has an extra addrn }
  1095. if (m_tp_procvar in aktmodeswitches) and
  1096. (resulttype.def.deftype<>procvardef) and
  1097. (left.resulttype.def.deftype=procvardef) and
  1098. (left.nodetype=loadn) then
  1099. begin
  1100. hp:=ccallnode.create(nil,nil,nil,nil);
  1101. tcallnode(hp).set_procvar(left);
  1102. resulttypepass(hp);
  1103. left:=hp;
  1104. end;
  1105. { remove typeconv after niln, but not when the result is a
  1106. methodpointer. The typeconv of the methodpointer will then
  1107. take care of updateing size of niln to OS_64 }
  1108. if (left.nodetype=niln) and
  1109. not((resulttype.def.deftype=procvardef) and
  1110. (po_methodpointer in tprocvardef(resulttype.def).procoptions)) then
  1111. begin
  1112. left.resulttype:=resulttype;
  1113. result:=left;
  1114. left:=nil;
  1115. exit;
  1116. end;
  1117. { ordinal contants can be directly converted }
  1118. if (left.nodetype=ordconstn) and is_ordinal(resulttype.def) and
  1119. { but not char to char because it is a widechar to char or via versa }
  1120. { which needs extra code to do the code page transistion }
  1121. not(convtype=tc_char_2_char) then
  1122. begin
  1123. { replace the resulttype and recheck the range }
  1124. left.resulttype:=resulttype;
  1125. testrange(left.resulttype.def,tordconstnode(left).value,(nf_explizit in flags));
  1126. result:=left;
  1127. left:=nil;
  1128. exit;
  1129. end;
  1130. { fold nil to any pointer type }
  1131. if (left.nodetype=niln) and (resulttype.def.deftype=pointerdef) then
  1132. begin
  1133. hp:=cnilnode.create;
  1134. hp.resulttype:=resulttype;
  1135. result:=hp;
  1136. exit;
  1137. end;
  1138. { further, pointerconstn to any pointer is folded too }
  1139. if (left.nodetype=pointerconstn) and (resulttype.def.deftype=pointerdef) then
  1140. begin
  1141. left.resulttype:=resulttype;
  1142. result:=left;
  1143. left:=nil;
  1144. exit;
  1145. end;
  1146. { now call the resulttype helper to do constant folding }
  1147. result:=resulttype_call_helper(convtype);
  1148. end;
  1149. function ttypeconvnode.first_cord_to_pointer : tnode;
  1150. begin
  1151. result:=nil;
  1152. internalerror(200104043);
  1153. end;
  1154. function ttypeconvnode.first_int_to_int : tnode;
  1155. begin
  1156. first_int_to_int:=nil;
  1157. if (left.location.loc<>LOC_REGISTER) and
  1158. (resulttype.def.size>left.resulttype.def.size) then
  1159. location.loc:=LOC_REGISTER;
  1160. if is_64bitint(resulttype.def) then
  1161. registers32:=max(registers32,2)
  1162. else
  1163. registers32:=max(registers32,1);
  1164. end;
  1165. function ttypeconvnode.first_cstring_to_pchar : tnode;
  1166. begin
  1167. first_cstring_to_pchar:=nil;
  1168. registers32:=1;
  1169. location.loc:=LOC_REGISTER;
  1170. end;
  1171. function ttypeconvnode.first_string_to_chararray : tnode;
  1172. begin
  1173. first_string_to_chararray:=nil;
  1174. registers32:=1;
  1175. location.loc:=LOC_REGISTER;
  1176. end;
  1177. function ttypeconvnode.first_char_to_string : tnode;
  1178. begin
  1179. first_char_to_string:=nil;
  1180. location.loc:=LOC_CREFERENCE;
  1181. end;
  1182. function ttypeconvnode.first_nothing : tnode;
  1183. begin
  1184. first_nothing:=nil;
  1185. end;
  1186. function ttypeconvnode.first_array_to_pointer : tnode;
  1187. begin
  1188. first_array_to_pointer:=nil;
  1189. if registers32<1 then
  1190. registers32:=1;
  1191. location.loc:=LOC_REGISTER;
  1192. end;
  1193. function ttypeconvnode.first_int_to_real: tnode;
  1194. var
  1195. fname: string[19];
  1196. typname : string[12];
  1197. begin
  1198. { Get the type name }
  1199. { Normally the typename should be one of the following:
  1200. single, double - carl
  1201. }
  1202. typname := lower(pbestrealtype^.def.gettypename);
  1203. { converting a 64bit integer to a float requires a helper }
  1204. if is_64bitint(left.resulttype.def) then
  1205. begin
  1206. if is_signed(left.resulttype.def) then
  1207. fname := 'fpc_int64_to_'+typname
  1208. else
  1209. fname := 'fpc_qword_to_'+typname;
  1210. result := ccallnode.createintern(fname,ccallparanode.create(
  1211. left,nil));
  1212. left:=nil;
  1213. firstpass(result);
  1214. exit;
  1215. end
  1216. else
  1217. { other integers are supposed to be 32 bit }
  1218. begin
  1219. if is_signed(left.resulttype.def) then
  1220. fname := 'fpc_longint_to_'+typname
  1221. else
  1222. fname := 'fpc_cardinal_to_'+typname;
  1223. result := ccallnode.createintern(fname,ccallparanode.create(
  1224. left,nil));
  1225. left:=nil;
  1226. firstpass(result);
  1227. exit;
  1228. end;
  1229. end;
  1230. function ttypeconvnode.first_real_to_real : tnode;
  1231. begin
  1232. first_real_to_real:=nil;
  1233. { comp isn't a floating type }
  1234. {$ifdef i386}
  1235. if (tfloatdef(resulttype.def).typ=s64comp) and
  1236. (tfloatdef(left.resulttype.def).typ<>s64comp) and
  1237. not (nf_explizit in flags) then
  1238. CGMessage(type_w_convert_real_2_comp);
  1239. {$endif}
  1240. if registersfpu<1 then
  1241. registersfpu:=1;
  1242. location.loc:=LOC_FPUREGISTER;
  1243. end;
  1244. function ttypeconvnode.first_pointer_to_array : tnode;
  1245. begin
  1246. first_pointer_to_array:=nil;
  1247. if registers32<1 then
  1248. registers32:=1;
  1249. location.loc:=LOC_REFERENCE;
  1250. end;
  1251. function ttypeconvnode.first_cchar_to_pchar : tnode;
  1252. begin
  1253. first_cchar_to_pchar:=nil;
  1254. internalerror(200104021);
  1255. end;
  1256. function ttypeconvnode.first_bool_to_int : tnode;
  1257. begin
  1258. first_bool_to_int:=nil;
  1259. { byte(boolean) or word(wordbool) or longint(longbool) must
  1260. be accepted for var parameters }
  1261. if (nf_explizit in flags) and
  1262. (left.resulttype.def.size=resulttype.def.size) and
  1263. (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1264. exit;
  1265. { when converting to 64bit, first convert to a 32bit int and then }
  1266. { convert to a 64bit int (only necessary for 32bit processors) (JM) }
  1267. if resulttype.def.size > sizeof(aword) then
  1268. begin
  1269. result := ctypeconvnode.create(left,u32bittype);
  1270. result.toggleflag(nf_explizit);
  1271. result := ctypeconvnode.create(result,resulttype);
  1272. left := nil;
  1273. firstpass(result);
  1274. exit;
  1275. end;
  1276. location.loc:=LOC_REGISTER;
  1277. if registers32<1 then
  1278. registers32:=1;
  1279. end;
  1280. function ttypeconvnode.first_int_to_bool : tnode;
  1281. begin
  1282. first_int_to_bool:=nil;
  1283. { byte(boolean) or word(wordbool) or longint(longbool) must
  1284. be accepted for var parameters }
  1285. if (nf_explizit in flags) and
  1286. (left.resulttype.def.size=resulttype.def.size) and
  1287. (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1288. exit;
  1289. location.loc:=LOC_REGISTER;
  1290. { need if bool to bool !!
  1291. not very nice !!
  1292. insertypeconv(left,s32bittype);
  1293. left.explizit:=true;
  1294. firstpass(left); }
  1295. if registers32<1 then
  1296. registers32:=1;
  1297. end;
  1298. function ttypeconvnode.first_bool_to_bool : tnode;
  1299. begin
  1300. first_bool_to_bool:=nil;
  1301. location.loc:=LOC_REGISTER;
  1302. if registers32<1 then
  1303. registers32:=1;
  1304. end;
  1305. function ttypeconvnode.first_char_to_char : tnode;
  1306. begin
  1307. first_char_to_char:=nil;
  1308. location.loc:=LOC_REGISTER;
  1309. if registers32<1 then
  1310. registers32:=1;
  1311. end;
  1312. function ttypeconvnode.first_proc_to_procvar : tnode;
  1313. begin
  1314. first_proc_to_procvar:=nil;
  1315. if (left.location.loc<>LOC_REFERENCE) then
  1316. CGMessage(cg_e_illegal_expression);
  1317. registers32:=left.registers32;
  1318. if registers32<1 then
  1319. registers32:=1;
  1320. location.loc:=LOC_REGISTER;
  1321. end;
  1322. function ttypeconvnode.first_load_smallset : tnode;
  1323. var
  1324. srsym: ttypesym;
  1325. p: tcallparanode;
  1326. begin
  1327. if not searchsystype('FPC_SMALL_SET',srsym) then
  1328. internalerror(200108313);
  1329. p := ccallparanode.create(left,nil);
  1330. { reused }
  1331. left := nil;
  1332. { convert parameter explicitely to fpc_small_set }
  1333. p.left := ctypeconvnode.create(p.left,srsym.restype);
  1334. p.left.toggleflag(nf_explizit);
  1335. { create call, adjust resulttype }
  1336. result :=
  1337. ccallnode.createinternres('fpc_set_load_small',p,resulttype);
  1338. firstpass(result);
  1339. end;
  1340. function ttypeconvnode.first_ansistring_to_pchar : tnode;
  1341. begin
  1342. first_ansistring_to_pchar:=nil;
  1343. location.loc:=LOC_REGISTER;
  1344. if registers32<1 then
  1345. registers32:=1;
  1346. end;
  1347. function ttypeconvnode.first_arrayconstructor_to_set : tnode;
  1348. begin
  1349. first_arrayconstructor_to_set:=nil;
  1350. internalerror(200104022);
  1351. end;
  1352. function ttypeconvnode.first_class_to_intf : tnode;
  1353. begin
  1354. first_class_to_intf:=nil;
  1355. location.loc:=LOC_REFERENCE;
  1356. if registers32<1 then
  1357. registers32:=1;
  1358. end;
  1359. function ttypeconvnode._first_int_to_int : tnode;
  1360. begin
  1361. result:=first_int_to_int;
  1362. end;
  1363. function ttypeconvnode._first_cstring_to_pchar : tnode;
  1364. begin
  1365. result:=first_cstring_to_pchar;
  1366. end;
  1367. function ttypeconvnode._first_string_to_chararray : tnode;
  1368. begin
  1369. result:=first_string_to_chararray;
  1370. end;
  1371. function ttypeconvnode._first_char_to_string : tnode;
  1372. begin
  1373. result:=first_char_to_string;
  1374. end;
  1375. function ttypeconvnode._first_nothing : tnode;
  1376. begin
  1377. result:=first_nothing;
  1378. end;
  1379. function ttypeconvnode._first_array_to_pointer : tnode;
  1380. begin
  1381. result:=first_array_to_pointer;
  1382. end;
  1383. function ttypeconvnode._first_int_to_real : tnode;
  1384. begin
  1385. result:=first_int_to_real;
  1386. end;
  1387. function ttypeconvnode._first_real_to_real : tnode;
  1388. begin
  1389. result:=first_real_to_real;
  1390. end;
  1391. function ttypeconvnode._first_pointer_to_array : tnode;
  1392. begin
  1393. result:=first_pointer_to_array;
  1394. end;
  1395. function ttypeconvnode._first_cchar_to_pchar : tnode;
  1396. begin
  1397. result:=first_cchar_to_pchar;
  1398. end;
  1399. function ttypeconvnode._first_bool_to_int : tnode;
  1400. begin
  1401. result:=first_bool_to_int;
  1402. end;
  1403. function ttypeconvnode._first_int_to_bool : tnode;
  1404. begin
  1405. result:=first_int_to_bool;
  1406. end;
  1407. function ttypeconvnode._first_bool_to_bool : tnode;
  1408. begin
  1409. result:=first_bool_to_bool;
  1410. end;
  1411. function ttypeconvnode._first_proc_to_procvar : tnode;
  1412. begin
  1413. result:=first_proc_to_procvar;
  1414. end;
  1415. function ttypeconvnode._first_load_smallset : tnode;
  1416. begin
  1417. result:=first_load_smallset;
  1418. end;
  1419. function ttypeconvnode._first_cord_to_pointer : tnode;
  1420. begin
  1421. result:=first_cord_to_pointer;
  1422. end;
  1423. function ttypeconvnode._first_ansistring_to_pchar : tnode;
  1424. begin
  1425. result:=first_ansistring_to_pchar;
  1426. end;
  1427. function ttypeconvnode._first_arrayconstructor_to_set : tnode;
  1428. begin
  1429. result:=first_arrayconstructor_to_set;
  1430. end;
  1431. function ttypeconvnode._first_class_to_intf : tnode;
  1432. begin
  1433. result:=first_class_to_intf;
  1434. end;
  1435. function ttypeconvnode._first_char_to_char : tnode;
  1436. begin
  1437. result:=first_char_to_char;
  1438. end;
  1439. function ttypeconvnode.first_call_helper(c : tconverttype) : tnode;
  1440. const
  1441. firstconvert : array[tconverttype] of pointer = (
  1442. @ttypeconvnode._first_nothing, {equal}
  1443. @ttypeconvnode._first_nothing, {not_possible}
  1444. nil, { removed in resulttype_string_to_string }
  1445. @ttypeconvnode._first_char_to_string,
  1446. @ttypeconvnode._first_nothing, { char_2_chararray, needs nothing extra }
  1447. nil, { removed in resulttype_chararray_to_string }
  1448. @ttypeconvnode._first_cchar_to_pchar,
  1449. @ttypeconvnode._first_cstring_to_pchar,
  1450. @ttypeconvnode._first_ansistring_to_pchar,
  1451. @ttypeconvnode._first_string_to_chararray,
  1452. nil, { removed in resulttype_chararray_to_string }
  1453. @ttypeconvnode._first_array_to_pointer,
  1454. @ttypeconvnode._first_pointer_to_array,
  1455. @ttypeconvnode._first_int_to_int,
  1456. @ttypeconvnode._first_int_to_bool,
  1457. @ttypeconvnode._first_bool_to_bool,
  1458. @ttypeconvnode._first_bool_to_int,
  1459. @ttypeconvnode._first_real_to_real,
  1460. @ttypeconvnode._first_int_to_real,
  1461. @ttypeconvnode._first_proc_to_procvar,
  1462. @ttypeconvnode._first_arrayconstructor_to_set,
  1463. @ttypeconvnode._first_load_smallset,
  1464. @ttypeconvnode._first_cord_to_pointer,
  1465. @ttypeconvnode._first_nothing,
  1466. @ttypeconvnode._first_nothing,
  1467. @ttypeconvnode._first_class_to_intf,
  1468. @ttypeconvnode._first_char_to_char,
  1469. @ttypeconvnode._first_nothing,
  1470. @ttypeconvnode._first_nothing
  1471. );
  1472. type
  1473. tprocedureofobject = function : tnode of object;
  1474. var
  1475. r : packed record
  1476. proc : pointer;
  1477. obj : pointer;
  1478. end;
  1479. begin
  1480. { this is a little bit dirty but it works }
  1481. { and should be quite portable too }
  1482. r.proc:=firstconvert[c];
  1483. r.obj:=self;
  1484. first_call_helper:=tprocedureofobject(r){$ifdef FPC}();{$endif FPC}
  1485. end;
  1486. function ttypeconvnode.pass_1 : tnode;
  1487. begin
  1488. result:=nil;
  1489. firstpass(left);
  1490. if codegenerror then
  1491. exit;
  1492. { load the value_str from the left part }
  1493. registers32:=left.registers32;
  1494. registersfpu:=left.registersfpu;
  1495. {$ifdef SUPPORT_MMX}
  1496. registersmmx:=left.registersmmx;
  1497. {$endif}
  1498. location.loc:=left.location.loc;
  1499. if nf_explizit in flags then
  1500. begin
  1501. { check if the result could be in a register }
  1502. if not(tstoreddef(resulttype.def).is_intregable) and
  1503. not(tstoreddef(resulttype.def).is_fpuregable) then
  1504. make_not_regable(left);
  1505. end;
  1506. result:=first_call_helper(convtype);
  1507. end;
  1508. function ttypeconvnode.docompare(p: tnode) : boolean;
  1509. begin
  1510. docompare :=
  1511. inherited docompare(p) and
  1512. (convtype = ttypeconvnode(p).convtype);
  1513. end;
  1514. {*****************************************************************************
  1515. TISNODE
  1516. *****************************************************************************}
  1517. constructor tisnode.create(l,r : tnode);
  1518. begin
  1519. inherited create(isn,l,r);
  1520. end;
  1521. function tisnode.det_resulttype:tnode;
  1522. var
  1523. paras: tcallparanode;
  1524. begin
  1525. result:=nil;
  1526. resulttypepass(left);
  1527. resulttypepass(right);
  1528. set_varstate(left,true);
  1529. set_varstate(right,true);
  1530. if codegenerror then
  1531. exit;
  1532. if (right.resulttype.def.deftype=classrefdef) then
  1533. begin
  1534. { left must be a class }
  1535. if is_class(left.resulttype.def) then
  1536. begin
  1537. { the operands must be related }
  1538. if (not(tobjectdef(left.resulttype.def).is_related(
  1539. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1540. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1541. tobjectdef(left.resulttype.def)))) then
  1542. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1543. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1544. end
  1545. else
  1546. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1547. { call fpc_do_is helper }
  1548. paras := ccallparanode.create(
  1549. left,
  1550. ccallparanode.create(
  1551. right,nil));
  1552. result := ccallnode.createintern('fpc_do_is',paras);
  1553. left := nil;
  1554. right := nil;
  1555. end
  1556. else if is_interface(right.resulttype.def) then
  1557. begin
  1558. { left is a class }
  1559. if is_class(left.resulttype.def) then
  1560. begin
  1561. { the operands must be related }
  1562. if not(assigned(tobjectdef(left.resulttype.def).implementedinterfaces) and
  1563. (tobjectdef(left.resulttype.def).implementedinterfaces.searchintf(right.resulttype.def)<>-1)) then
  1564. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1565. end
  1566. { left is an interface }
  1567. else if is_interface(left.resulttype.def) then
  1568. begin
  1569. { the operands must be related }
  1570. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  1571. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1572. CGMessage(type_e_mismatch);
  1573. end
  1574. else
  1575. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1576. { call fpc_do_is helper }
  1577. paras := ccallparanode.create(
  1578. left,
  1579. ccallparanode.create(
  1580. right,nil));
  1581. result := ccallnode.createintern('fpc_do_is',paras);
  1582. left := nil;
  1583. right := nil;
  1584. end
  1585. else
  1586. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  1587. resulttype:=booltype;
  1588. end;
  1589. function tisnode.pass_1 : tnode;
  1590. begin
  1591. internalerror(200204254);
  1592. result:=nil;
  1593. end;
  1594. { dummy pass_2, it will never be called, but we need one since }
  1595. { you can't instantiate an abstract class }
  1596. procedure tisnode.pass_2;
  1597. begin
  1598. end;
  1599. {*****************************************************************************
  1600. TASNODE
  1601. *****************************************************************************}
  1602. constructor tasnode.create(l,r : tnode);
  1603. begin
  1604. inherited create(asn,l,r);
  1605. end;
  1606. function tasnode.det_resulttype:tnode;
  1607. begin
  1608. result:=nil;
  1609. resulttypepass(right);
  1610. resulttypepass(left);
  1611. set_varstate(right,true);
  1612. set_varstate(left,true);
  1613. if codegenerror then
  1614. exit;
  1615. if (right.resulttype.def.deftype=classrefdef) then
  1616. begin
  1617. { left must be a class }
  1618. if is_class(left.resulttype.def) then
  1619. begin
  1620. { the operands must be related }
  1621. if (not(tobjectdef(left.resulttype.def).is_related(
  1622. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1623. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1624. tobjectdef(left.resulttype.def)))) then
  1625. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1626. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1627. end
  1628. else
  1629. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1630. resulttype:=tclassrefdef(right.resulttype.def).pointertype;
  1631. end
  1632. else if is_interface(right.resulttype.def) then
  1633. begin
  1634. { left is a class }
  1635. if is_class(left.resulttype.def) then
  1636. begin
  1637. { the operands must be related }
  1638. if not(assigned(tobjectdef(left.resulttype.def).implementedinterfaces) and
  1639. (tobjectdef(left.resulttype.def).implementedinterfaces.searchintf(right.resulttype.def)<>-1)) then
  1640. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1641. end
  1642. { left is an interface }
  1643. else if is_interface(left.resulttype.def) then
  1644. begin
  1645. { the operands must be related }
  1646. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  1647. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1648. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1649. end
  1650. else
  1651. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1652. resulttype:=right.resulttype;
  1653. { load the GUID of the interface }
  1654. if (right.nodetype=typen) then
  1655. begin
  1656. if tobjectdef(left.resulttype.def).isiidguidvalid then
  1657. right:=cguidconstnode.create(tobjectdef(left.resulttype.def).iidguid)
  1658. else
  1659. internalerror(200206282);
  1660. resulttypepass(right);
  1661. end;
  1662. end
  1663. else
  1664. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  1665. end;
  1666. function tasnode.pass_1 : tnode;
  1667. begin
  1668. firstpass(left);
  1669. firstpass(right);
  1670. if codegenerror then
  1671. exit;
  1672. left_right_max;
  1673. location.loc:=left.location.loc;
  1674. result:=nil;
  1675. end;
  1676. begin
  1677. ctypeconvnode:=ttypeconvnode;
  1678. casnode:=tasnode;
  1679. cisnode:=tisnode;
  1680. end.
  1681. {
  1682. $Log$
  1683. Revision 1.69 2002-08-14 19:26:55 carl
  1684. + generic int_to_real type conversion
  1685. + generic unaryminus node
  1686. Revision 1.68 2002/08/11 16:08:55 florian
  1687. + support of explicit type case boolean->char
  1688. Revision 1.67 2002/08/11 15:28:00 florian
  1689. + support of explicit type case <any ordinal type>->pointer
  1690. (delphi mode only)
  1691. Revision 1.66 2002/08/09 07:33:01 florian
  1692. * a couple of interface related fixes
  1693. Revision 1.65 2002/07/29 21:23:42 florian
  1694. * more fixes for the ppc
  1695. + wrappers for the tcnvnode.first_* stuff introduced
  1696. Revision 1.64 2002/07/23 12:34:30 daniel
  1697. * Readded old set code. To use it define 'oldset'. Activated by default
  1698. for ppc.
  1699. Revision 1.63 2002/07/23 09:51:22 daniel
  1700. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  1701. are worth comitting.
  1702. Revision 1.62 2002/07/22 11:48:04 daniel
  1703. * Sets are now internally sets.
  1704. Revision 1.61 2002/07/20 17:16:02 florian
  1705. + source code page support
  1706. Revision 1.60 2002/07/20 11:57:54 florian
  1707. * types.pas renamed to defbase.pas because D6 contains a types
  1708. unit so this would conflicts if D6 programms are compiled
  1709. + Willamette/SSE2 instructions to assembler added
  1710. Revision 1.59 2002/07/01 16:23:53 peter
  1711. * cg64 patch
  1712. * basics for currency
  1713. * asnode updates for class and interface (not finished)
  1714. Revision 1.58 2002/05/18 13:34:09 peter
  1715. * readded missing revisions
  1716. Revision 1.57 2002/05/16 19:46:37 carl
  1717. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1718. + try to fix temp allocation (still in ifdef)
  1719. + generic constructor calls
  1720. + start of tassembler / tmodulebase class cleanup
  1721. Revision 1.55 2002/05/12 16:53:07 peter
  1722. * moved entry and exitcode to ncgutil and cgobj
  1723. * foreach gets extra argument for passing local data to the
  1724. iterator function
  1725. * -CR checks also class typecasts at runtime by changing them
  1726. into as
  1727. * fixed compiler to cycle with the -CR option
  1728. * fixed stabs with elf writer, finally the global variables can
  1729. be watched
  1730. * removed a lot of routines from cga unit and replaced them by
  1731. calls to cgobj
  1732. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1733. u32bit then the other is typecasted also to u32bit without giving
  1734. a rangecheck warning/error.
  1735. * fixed pascal calling method with reversing also the high tree in
  1736. the parast, detected by tcalcst3 test
  1737. Revision 1.54 2002/04/25 20:16:38 peter
  1738. * moved more routines from cga/n386util
  1739. Revision 1.53 2002/04/23 19:16:34 peter
  1740. * add pinline unit that inserts compiler supported functions using
  1741. one or more statements
  1742. * moved finalize and setlength from ninl to pinline
  1743. Revision 1.52 2002/04/21 19:02:03 peter
  1744. * removed newn and disposen nodes, the code is now directly
  1745. inlined from pexpr
  1746. * -an option that will write the secondpass nodes to the .s file, this
  1747. requires EXTDEBUG define to actually write the info
  1748. * fixed various internal errors and crashes due recent code changes
  1749. Revision 1.51 2002/04/06 18:10:42 jonas
  1750. * several powerpc-related additions and fixes
  1751. Revision 1.50 2002/04/04 19:05:58 peter
  1752. * removed unused units
  1753. * use tlocation.size in cg.a_*loc*() routines
  1754. Revision 1.49 2002/04/02 17:11:28 peter
  1755. * tlocation,treference update
  1756. * LOC_CONSTANT added for better constant handling
  1757. * secondadd splitted in multiple routines
  1758. * location_force_reg added for loading a location to a register
  1759. of a specified size
  1760. * secondassignment parses now first the right and then the left node
  1761. (this is compatible with Kylix). This saves a lot of push/pop especially
  1762. with string operations
  1763. * adapted some routines to use the new cg methods
  1764. Revision 1.48 2002/02/03 09:30:03 peter
  1765. * more fixes for protected handling
  1766. }