ncnv.pas 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023
  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. begin
  1195. first_int_to_real:=nil;
  1196. {$ifdef m68k}
  1197. if (cs_fp_emulation in aktmoduleswitches) or
  1198. (tfloatdef(resulttype.def).typ=s32real) then
  1199. begin
  1200. if registers32<1 then
  1201. registers32:=1;
  1202. end
  1203. else
  1204. if registersfpu<1 then
  1205. registersfpu:=1;
  1206. {$else not m68k}
  1207. if registersfpu<1 then
  1208. registersfpu:=1;
  1209. {$endif not m68k}
  1210. location.loc:=LOC_FPUREGISTER;
  1211. end;
  1212. function ttypeconvnode.first_real_to_real : tnode;
  1213. begin
  1214. first_real_to_real:=nil;
  1215. { comp isn't a floating type }
  1216. {$ifdef i386}
  1217. if (tfloatdef(resulttype.def).typ=s64comp) and
  1218. (tfloatdef(left.resulttype.def).typ<>s64comp) and
  1219. not (nf_explizit in flags) then
  1220. CGMessage(type_w_convert_real_2_comp);
  1221. {$endif}
  1222. if registersfpu<1 then
  1223. registersfpu:=1;
  1224. location.loc:=LOC_FPUREGISTER;
  1225. end;
  1226. function ttypeconvnode.first_pointer_to_array : tnode;
  1227. begin
  1228. first_pointer_to_array:=nil;
  1229. if registers32<1 then
  1230. registers32:=1;
  1231. location.loc:=LOC_REFERENCE;
  1232. end;
  1233. function ttypeconvnode.first_cchar_to_pchar : tnode;
  1234. begin
  1235. first_cchar_to_pchar:=nil;
  1236. internalerror(200104021);
  1237. end;
  1238. function ttypeconvnode.first_bool_to_int : tnode;
  1239. begin
  1240. first_bool_to_int:=nil;
  1241. { byte(boolean) or word(wordbool) or longint(longbool) must
  1242. be accepted for var parameters }
  1243. if (nf_explizit in flags) and
  1244. (left.resulttype.def.size=resulttype.def.size) and
  1245. (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1246. exit;
  1247. { when converting to 64bit, first convert to a 32bit int and then }
  1248. { convert to a 64bit int (only necessary for 32bit processors) (JM) }
  1249. if resulttype.def.size > sizeof(aword) then
  1250. begin
  1251. result := ctypeconvnode.create(left,u32bittype);
  1252. result.toggleflag(nf_explizit);
  1253. result := ctypeconvnode.create(result,resulttype);
  1254. left := nil;
  1255. firstpass(result);
  1256. exit;
  1257. end;
  1258. location.loc:=LOC_REGISTER;
  1259. if registers32<1 then
  1260. registers32:=1;
  1261. end;
  1262. function ttypeconvnode.first_int_to_bool : tnode;
  1263. begin
  1264. first_int_to_bool:=nil;
  1265. { byte(boolean) or word(wordbool) or longint(longbool) must
  1266. be accepted for var parameters }
  1267. if (nf_explizit in flags) and
  1268. (left.resulttype.def.size=resulttype.def.size) and
  1269. (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1270. exit;
  1271. location.loc:=LOC_REGISTER;
  1272. { need if bool to bool !!
  1273. not very nice !!
  1274. insertypeconv(left,s32bittype);
  1275. left.explizit:=true;
  1276. firstpass(left); }
  1277. if registers32<1 then
  1278. registers32:=1;
  1279. end;
  1280. function ttypeconvnode.first_bool_to_bool : tnode;
  1281. begin
  1282. first_bool_to_bool:=nil;
  1283. location.loc:=LOC_REGISTER;
  1284. if registers32<1 then
  1285. registers32:=1;
  1286. end;
  1287. function ttypeconvnode.first_char_to_char : tnode;
  1288. begin
  1289. first_char_to_char:=nil;
  1290. location.loc:=LOC_REGISTER;
  1291. if registers32<1 then
  1292. registers32:=1;
  1293. end;
  1294. function ttypeconvnode.first_proc_to_procvar : tnode;
  1295. begin
  1296. first_proc_to_procvar:=nil;
  1297. if (left.location.loc<>LOC_REFERENCE) then
  1298. CGMessage(cg_e_illegal_expression);
  1299. registers32:=left.registers32;
  1300. if registers32<1 then
  1301. registers32:=1;
  1302. location.loc:=LOC_REGISTER;
  1303. end;
  1304. function ttypeconvnode.first_load_smallset : tnode;
  1305. var
  1306. srsym: ttypesym;
  1307. p: tcallparanode;
  1308. begin
  1309. if not searchsystype('FPC_SMALL_SET',srsym) then
  1310. internalerror(200108313);
  1311. p := ccallparanode.create(left,nil);
  1312. { reused }
  1313. left := nil;
  1314. { convert parameter explicitely to fpc_small_set }
  1315. p.left := ctypeconvnode.create(p.left,srsym.restype);
  1316. p.left.toggleflag(nf_explizit);
  1317. { create call, adjust resulttype }
  1318. result :=
  1319. ccallnode.createinternres('fpc_set_load_small',p,resulttype);
  1320. firstpass(result);
  1321. end;
  1322. function ttypeconvnode.first_ansistring_to_pchar : tnode;
  1323. begin
  1324. first_ansistring_to_pchar:=nil;
  1325. location.loc:=LOC_REGISTER;
  1326. if registers32<1 then
  1327. registers32:=1;
  1328. end;
  1329. function ttypeconvnode.first_arrayconstructor_to_set : tnode;
  1330. begin
  1331. first_arrayconstructor_to_set:=nil;
  1332. internalerror(200104022);
  1333. end;
  1334. function ttypeconvnode.first_class_to_intf : tnode;
  1335. begin
  1336. first_class_to_intf:=nil;
  1337. location.loc:=LOC_REFERENCE;
  1338. if registers32<1 then
  1339. registers32:=1;
  1340. end;
  1341. function ttypeconvnode._first_int_to_int : tnode;
  1342. begin
  1343. result:=first_int_to_int;
  1344. end;
  1345. function ttypeconvnode._first_cstring_to_pchar : tnode;
  1346. begin
  1347. result:=first_cstring_to_pchar;
  1348. end;
  1349. function ttypeconvnode._first_string_to_chararray : tnode;
  1350. begin
  1351. result:=first_string_to_chararray;
  1352. end;
  1353. function ttypeconvnode._first_char_to_string : tnode;
  1354. begin
  1355. result:=first_char_to_string;
  1356. end;
  1357. function ttypeconvnode._first_nothing : tnode;
  1358. begin
  1359. result:=first_nothing;
  1360. end;
  1361. function ttypeconvnode._first_array_to_pointer : tnode;
  1362. begin
  1363. result:=first_array_to_pointer;
  1364. end;
  1365. function ttypeconvnode._first_int_to_real : tnode;
  1366. begin
  1367. result:=first_int_to_real;
  1368. end;
  1369. function ttypeconvnode._first_real_to_real : tnode;
  1370. begin
  1371. result:=first_real_to_real;
  1372. end;
  1373. function ttypeconvnode._first_pointer_to_array : tnode;
  1374. begin
  1375. result:=first_pointer_to_array;
  1376. end;
  1377. function ttypeconvnode._first_cchar_to_pchar : tnode;
  1378. begin
  1379. result:=first_cchar_to_pchar;
  1380. end;
  1381. function ttypeconvnode._first_bool_to_int : tnode;
  1382. begin
  1383. result:=first_bool_to_int;
  1384. end;
  1385. function ttypeconvnode._first_int_to_bool : tnode;
  1386. begin
  1387. result:=first_int_to_bool;
  1388. end;
  1389. function ttypeconvnode._first_bool_to_bool : tnode;
  1390. begin
  1391. result:=first_bool_to_bool;
  1392. end;
  1393. function ttypeconvnode._first_proc_to_procvar : tnode;
  1394. begin
  1395. result:=first_proc_to_procvar;
  1396. end;
  1397. function ttypeconvnode._first_load_smallset : tnode;
  1398. begin
  1399. result:=first_load_smallset;
  1400. end;
  1401. function ttypeconvnode._first_cord_to_pointer : tnode;
  1402. begin
  1403. result:=first_cord_to_pointer;
  1404. end;
  1405. function ttypeconvnode._first_ansistring_to_pchar : tnode;
  1406. begin
  1407. result:=first_ansistring_to_pchar;
  1408. end;
  1409. function ttypeconvnode._first_arrayconstructor_to_set : tnode;
  1410. begin
  1411. result:=first_arrayconstructor_to_set;
  1412. end;
  1413. function ttypeconvnode._first_class_to_intf : tnode;
  1414. begin
  1415. result:=first_class_to_intf;
  1416. end;
  1417. function ttypeconvnode._first_char_to_char : tnode;
  1418. begin
  1419. result:=first_char_to_char;
  1420. end;
  1421. function ttypeconvnode.first_call_helper(c : tconverttype) : tnode;
  1422. const
  1423. firstconvert : array[tconverttype] of pointer = (
  1424. @ttypeconvnode._first_nothing, {equal}
  1425. @ttypeconvnode._first_nothing, {not_possible}
  1426. nil, { removed in resulttype_string_to_string }
  1427. @ttypeconvnode._first_char_to_string,
  1428. @ttypeconvnode._first_nothing, { char_2_chararray, needs nothing extra }
  1429. nil, { removed in resulttype_chararray_to_string }
  1430. @ttypeconvnode._first_cchar_to_pchar,
  1431. @ttypeconvnode._first_cstring_to_pchar,
  1432. @ttypeconvnode._first_ansistring_to_pchar,
  1433. @ttypeconvnode._first_string_to_chararray,
  1434. nil, { removed in resulttype_chararray_to_string }
  1435. @ttypeconvnode._first_array_to_pointer,
  1436. @ttypeconvnode._first_pointer_to_array,
  1437. @ttypeconvnode._first_int_to_int,
  1438. @ttypeconvnode._first_int_to_bool,
  1439. @ttypeconvnode._first_bool_to_bool,
  1440. @ttypeconvnode._first_bool_to_int,
  1441. @ttypeconvnode._first_real_to_real,
  1442. @ttypeconvnode._first_int_to_real,
  1443. @ttypeconvnode._first_proc_to_procvar,
  1444. @ttypeconvnode._first_arrayconstructor_to_set,
  1445. @ttypeconvnode._first_load_smallset,
  1446. @ttypeconvnode._first_cord_to_pointer,
  1447. @ttypeconvnode._first_nothing,
  1448. @ttypeconvnode._first_nothing,
  1449. @ttypeconvnode._first_class_to_intf,
  1450. @ttypeconvnode._first_char_to_char,
  1451. @ttypeconvnode._first_nothing,
  1452. @ttypeconvnode._first_nothing
  1453. );
  1454. type
  1455. tprocedureofobject = function : tnode of object;
  1456. var
  1457. r : packed record
  1458. proc : pointer;
  1459. obj : pointer;
  1460. end;
  1461. begin
  1462. { this is a little bit dirty but it works }
  1463. { and should be quite portable too }
  1464. r.proc:=firstconvert[c];
  1465. r.obj:=self;
  1466. first_call_helper:=tprocedureofobject(r){$ifdef FPC}();{$endif FPC}
  1467. end;
  1468. function ttypeconvnode.pass_1 : tnode;
  1469. begin
  1470. result:=nil;
  1471. firstpass(left);
  1472. if codegenerror then
  1473. exit;
  1474. { load the value_str from the left part }
  1475. registers32:=left.registers32;
  1476. registersfpu:=left.registersfpu;
  1477. {$ifdef SUPPORT_MMX}
  1478. registersmmx:=left.registersmmx;
  1479. {$endif}
  1480. location.loc:=left.location.loc;
  1481. if nf_explizit in flags then
  1482. begin
  1483. { check if the result could be in a register }
  1484. if not(tstoreddef(resulttype.def).is_intregable) and
  1485. not(tstoreddef(resulttype.def).is_fpuregable) then
  1486. make_not_regable(left);
  1487. end;
  1488. result:=first_call_helper(convtype);
  1489. end;
  1490. function ttypeconvnode.docompare(p: tnode) : boolean;
  1491. begin
  1492. docompare :=
  1493. inherited docompare(p) and
  1494. (convtype = ttypeconvnode(p).convtype);
  1495. end;
  1496. {*****************************************************************************
  1497. TISNODE
  1498. *****************************************************************************}
  1499. constructor tisnode.create(l,r : tnode);
  1500. begin
  1501. inherited create(isn,l,r);
  1502. end;
  1503. function tisnode.det_resulttype:tnode;
  1504. var
  1505. paras: tcallparanode;
  1506. begin
  1507. result:=nil;
  1508. resulttypepass(left);
  1509. resulttypepass(right);
  1510. set_varstate(left,true);
  1511. set_varstate(right,true);
  1512. if codegenerror then
  1513. exit;
  1514. if (right.resulttype.def.deftype=classrefdef) then
  1515. begin
  1516. { left must be a class }
  1517. if is_class(left.resulttype.def) then
  1518. begin
  1519. { the operands must be related }
  1520. if (not(tobjectdef(left.resulttype.def).is_related(
  1521. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1522. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1523. tobjectdef(left.resulttype.def)))) then
  1524. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1525. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1526. end
  1527. else
  1528. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1529. { call fpc_do_is helper }
  1530. paras := ccallparanode.create(
  1531. left,
  1532. ccallparanode.create(
  1533. right,nil));
  1534. result := ccallnode.createintern('fpc_do_is',paras);
  1535. left := nil;
  1536. right := nil;
  1537. end
  1538. else if is_interface(right.resulttype.def) then
  1539. begin
  1540. { left is a class }
  1541. if is_class(left.resulttype.def) then
  1542. begin
  1543. { the operands must be related }
  1544. if not(assigned(tobjectdef(left.resulttype.def).implementedinterfaces) and
  1545. (tobjectdef(left.resulttype.def).implementedinterfaces.searchintf(right.resulttype.def)<>-1)) then
  1546. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1547. end
  1548. { left is an interface }
  1549. else if is_interface(left.resulttype.def) then
  1550. begin
  1551. { the operands must be related }
  1552. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  1553. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1554. CGMessage(type_e_mismatch);
  1555. end
  1556. else
  1557. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1558. { call fpc_do_is helper }
  1559. paras := ccallparanode.create(
  1560. left,
  1561. ccallparanode.create(
  1562. right,nil));
  1563. result := ccallnode.createintern('fpc_do_is',paras);
  1564. left := nil;
  1565. right := nil;
  1566. end
  1567. else
  1568. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  1569. resulttype:=booltype;
  1570. end;
  1571. function tisnode.pass_1 : tnode;
  1572. begin
  1573. internalerror(200204254);
  1574. result:=nil;
  1575. end;
  1576. { dummy pass_2, it will never be called, but we need one since }
  1577. { you can't instantiate an abstract class }
  1578. procedure tisnode.pass_2;
  1579. begin
  1580. end;
  1581. {*****************************************************************************
  1582. TASNODE
  1583. *****************************************************************************}
  1584. constructor tasnode.create(l,r : tnode);
  1585. begin
  1586. inherited create(asn,l,r);
  1587. end;
  1588. function tasnode.det_resulttype:tnode;
  1589. begin
  1590. result:=nil;
  1591. resulttypepass(right);
  1592. resulttypepass(left);
  1593. set_varstate(right,true);
  1594. set_varstate(left,true);
  1595. if codegenerror then
  1596. exit;
  1597. if (right.resulttype.def.deftype=classrefdef) then
  1598. begin
  1599. { left must be a class }
  1600. if is_class(left.resulttype.def) then
  1601. begin
  1602. { the operands must be related }
  1603. if (not(tobjectdef(left.resulttype.def).is_related(
  1604. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1605. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1606. tobjectdef(left.resulttype.def)))) then
  1607. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1608. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1609. end
  1610. else
  1611. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1612. resulttype:=tclassrefdef(right.resulttype.def).pointertype;
  1613. end
  1614. else if is_interface(right.resulttype.def) then
  1615. begin
  1616. { left is a class }
  1617. if is_class(left.resulttype.def) then
  1618. begin
  1619. { the operands must be related }
  1620. if not(assigned(tobjectdef(left.resulttype.def).implementedinterfaces) and
  1621. (tobjectdef(left.resulttype.def).implementedinterfaces.searchintf(right.resulttype.def)<>-1)) then
  1622. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1623. end
  1624. { left is an interface }
  1625. else if is_interface(left.resulttype.def) then
  1626. begin
  1627. { the operands must be related }
  1628. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  1629. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1630. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1631. end
  1632. else
  1633. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1634. resulttype:=right.resulttype;
  1635. { load the GUID of the interface }
  1636. if (right.nodetype=typen) then
  1637. begin
  1638. if tobjectdef(left.resulttype.def).isiidguidvalid then
  1639. right:=cguidconstnode.create(tobjectdef(left.resulttype.def).iidguid)
  1640. else
  1641. internalerror(200206282);
  1642. resulttypepass(right);
  1643. end;
  1644. end
  1645. else
  1646. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  1647. end;
  1648. function tasnode.pass_1 : tnode;
  1649. begin
  1650. firstpass(left);
  1651. firstpass(right);
  1652. if codegenerror then
  1653. exit;
  1654. left_right_max;
  1655. location.loc:=left.location.loc;
  1656. result:=nil;
  1657. end;
  1658. begin
  1659. ctypeconvnode:=ttypeconvnode;
  1660. casnode:=tasnode;
  1661. cisnode:=tisnode;
  1662. end.
  1663. {
  1664. $Log$
  1665. Revision 1.68 2002-08-11 16:08:55 florian
  1666. + support of explicit type case boolean->char
  1667. Revision 1.67 2002/08/11 15:28:00 florian
  1668. + support of explicit type case <any ordinal type>->pointer
  1669. (delphi mode only)
  1670. Revision 1.66 2002/08/09 07:33:01 florian
  1671. * a couple of interface related fixes
  1672. Revision 1.65 2002/07/29 21:23:42 florian
  1673. * more fixes for the ppc
  1674. + wrappers for the tcnvnode.first_* stuff introduced
  1675. Revision 1.64 2002/07/23 12:34:30 daniel
  1676. * Readded old set code. To use it define 'oldset'. Activated by default
  1677. for ppc.
  1678. Revision 1.63 2002/07/23 09:51:22 daniel
  1679. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  1680. are worth comitting.
  1681. Revision 1.62 2002/07/22 11:48:04 daniel
  1682. * Sets are now internally sets.
  1683. Revision 1.61 2002/07/20 17:16:02 florian
  1684. + source code page support
  1685. Revision 1.60 2002/07/20 11:57:54 florian
  1686. * types.pas renamed to defbase.pas because D6 contains a types
  1687. unit so this would conflicts if D6 programms are compiled
  1688. + Willamette/SSE2 instructions to assembler added
  1689. Revision 1.59 2002/07/01 16:23:53 peter
  1690. * cg64 patch
  1691. * basics for currency
  1692. * asnode updates for class and interface (not finished)
  1693. Revision 1.58 2002/05/18 13:34:09 peter
  1694. * readded missing revisions
  1695. Revision 1.57 2002/05/16 19:46:37 carl
  1696. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1697. + try to fix temp allocation (still in ifdef)
  1698. + generic constructor calls
  1699. + start of tassembler / tmodulebase class cleanup
  1700. Revision 1.55 2002/05/12 16:53:07 peter
  1701. * moved entry and exitcode to ncgutil and cgobj
  1702. * foreach gets extra argument for passing local data to the
  1703. iterator function
  1704. * -CR checks also class typecasts at runtime by changing them
  1705. into as
  1706. * fixed compiler to cycle with the -CR option
  1707. * fixed stabs with elf writer, finally the global variables can
  1708. be watched
  1709. * removed a lot of routines from cga unit and replaced them by
  1710. calls to cgobj
  1711. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1712. u32bit then the other is typecasted also to u32bit without giving
  1713. a rangecheck warning/error.
  1714. * fixed pascal calling method with reversing also the high tree in
  1715. the parast, detected by tcalcst3 test
  1716. Revision 1.54 2002/04/25 20:16:38 peter
  1717. * moved more routines from cga/n386util
  1718. Revision 1.53 2002/04/23 19:16:34 peter
  1719. * add pinline unit that inserts compiler supported functions using
  1720. one or more statements
  1721. * moved finalize and setlength from ninl to pinline
  1722. Revision 1.52 2002/04/21 19:02:03 peter
  1723. * removed newn and disposen nodes, the code is now directly
  1724. inlined from pexpr
  1725. * -an option that will write the secondpass nodes to the .s file, this
  1726. requires EXTDEBUG define to actually write the info
  1727. * fixed various internal errors and crashes due recent code changes
  1728. Revision 1.51 2002/04/06 18:10:42 jonas
  1729. * several powerpc-related additions and fixes
  1730. Revision 1.50 2002/04/04 19:05:58 peter
  1731. * removed unused units
  1732. * use tlocation.size in cg.a_*loc*() routines
  1733. Revision 1.49 2002/04/02 17:11:28 peter
  1734. * tlocation,treference update
  1735. * LOC_CONSTANT added for better constant handling
  1736. * secondadd splitted in multiple routines
  1737. * location_force_reg added for loading a location to a register
  1738. of a specified size
  1739. * secondassignment parses now first the right and then the left node
  1740. (this is compatible with Kylix). This saves a lot of push/pop especially
  1741. with string operations
  1742. * adapted some routines to use the new cg methods
  1743. Revision 1.48 2002/02/03 09:30:03 peter
  1744. * more fixes for protected handling
  1745. }