ncnv.pas 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  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. { ansistring to pchar }
  889. if is_pchar(resulttype.def) and
  890. is_ansistring(left.resulttype.def) then
  891. begin
  892. convtype:=tc_ansistring_2_pchar;
  893. exit;
  894. end;
  895. { do common tc_equal cast }
  896. convtype:=tc_equal;
  897. { enum to ordinal will always be s32bit }
  898. if (left.resulttype.def.deftype=enumdef) and
  899. is_ordinal(resulttype.def) then
  900. begin
  901. if left.nodetype=ordconstn then
  902. begin
  903. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  904. result:=hp;
  905. exit;
  906. end
  907. else
  908. begin
  909. if isconvertable(s32bittype.def,resulttype.def,convtype,ordconstn,false)=0 then
  910. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  911. end;
  912. end
  913. { ordinal to enumeration }
  914. else
  915. if (resulttype.def.deftype=enumdef) and
  916. is_ordinal(left.resulttype.def) then
  917. begin
  918. if left.nodetype=ordconstn then
  919. begin
  920. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  921. result:=hp;
  922. exit;
  923. end
  924. else
  925. begin
  926. if IsConvertable(left.resulttype.def,s32bittype.def,convtype,ordconstn,false)=0 then
  927. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  928. end;
  929. end
  930. { nil to ordinal node }
  931. else if (left.nodetype=niln) and is_ordinal(resulttype.def) then
  932. begin
  933. hp:=cordconstnode.create(0,resulttype);
  934. result:=hp;
  935. exit;
  936. end
  937. { constant pointer to ordinal }
  938. else if is_ordinal(resulttype.def) and
  939. (left.nodetype=pointerconstn) then
  940. begin
  941. hp:=cordconstnode.create(tpointerconstnode(left).value,resulttype);
  942. result:=hp;
  943. exit;
  944. end
  945. { class to class or object to object, with checkobject support }
  946. else if (resulttype.def.deftype=objectdef) and
  947. (left.resulttype.def.deftype=objectdef) then
  948. begin
  949. if (cs_check_object in aktlocalswitches) then
  950. begin
  951. if is_class_or_interface(resulttype.def) then
  952. begin
  953. { we can translate the typeconvnode to 'as' when
  954. typecasting to a class or interface }
  955. hp:=casnode.create(left,cloadvmtnode.create(ctypenode.create(resulttype)));
  956. left:=nil;
  957. result:=hp;
  958. exit;
  959. end;
  960. end
  961. else
  962. begin
  963. { check if the types are related }
  964. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(resulttype.def)))) and
  965. (not(tobjectdef(resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  966. CGMessage2(type_w_classes_not_related,left.resulttype.def.typename,resulttype.def.typename);
  967. end;
  968. end
  969. {Are we typecasting an ordconst to a char?}
  970. else
  971. if is_char(resulttype.def) and
  972. is_ordinal(left.resulttype.def) then
  973. begin
  974. if left.nodetype=ordconstn then
  975. begin
  976. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  977. result:=hp;
  978. exit;
  979. end
  980. else
  981. begin
  982. if IsConvertable(left.resulttype.def,u8bittype.def,convtype,ordconstn,false)=0 then
  983. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  984. end;
  985. end
  986. {Are we typecasting an ordconst to a wchar?}
  987. else
  988. if is_widechar(resulttype.def) and
  989. is_ordinal(left.resulttype.def) then
  990. begin
  991. if left.nodetype=ordconstn then
  992. begin
  993. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  994. result:=hp;
  995. exit;
  996. end
  997. else
  998. begin
  999. if IsConvertable(left.resulttype.def,u16bittype.def,convtype,ordconstn,false)=0 then
  1000. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1001. end;
  1002. end
  1003. { char to ordinal }
  1004. else
  1005. if is_char(left.resulttype.def) and
  1006. is_ordinal(resulttype.def) then
  1007. begin
  1008. if left.nodetype=ordconstn then
  1009. begin
  1010. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  1011. result:=hp;
  1012. exit;
  1013. end
  1014. else
  1015. begin
  1016. if IsConvertable(u8bittype.def,resulttype.def,convtype,ordconstn,false)=0 then
  1017. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1018. end;
  1019. end
  1020. { widechar to ordinal }
  1021. else
  1022. if is_widechar(left.resulttype.def) and
  1023. is_ordinal(resulttype.def) then
  1024. begin
  1025. if left.nodetype=ordconstn then
  1026. begin
  1027. hp:=cordconstnode.create(tordconstnode(left).value,resulttype);
  1028. result:=hp;
  1029. exit;
  1030. end
  1031. else
  1032. begin
  1033. if IsConvertable(u16bittype.def,resulttype.def,convtype,ordconstn,false)=0 then
  1034. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1035. end;
  1036. end
  1037. { only if the same size or formal def }
  1038. { why do we allow typecasting of voiddef ?? (PM) }
  1039. else
  1040. begin
  1041. if not(
  1042. (left.resulttype.def.deftype=formaldef) or
  1043. (left.resulttype.def.size=resulttype.def.size) or
  1044. (is_void(left.resulttype.def) and
  1045. (left.nodetype=derefn))
  1046. ) then
  1047. CGMessage(cg_e_illegal_type_conversion);
  1048. if ((left.resulttype.def.deftype=orddef) and
  1049. (resulttype.def.deftype=pointerdef)) or
  1050. ((resulttype.def.deftype=orddef) and
  1051. (left.resulttype.def.deftype=pointerdef)) then
  1052. CGMessage(cg_d_pointer_to_longint_conv_not_portable);
  1053. end;
  1054. { the conversion into a strutured type is only }
  1055. { possible, if the source is not a register }
  1056. if ((resulttype.def.deftype in [recorddef,stringdef,arraydef]) or
  1057. ((resulttype.def.deftype=objectdef) and not(is_class(resulttype.def)))
  1058. ) and (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) { and
  1059. it also works if the assignment is overloaded
  1060. YES but this code is not executed if assignment is overloaded (PM)
  1061. not assigned(assignment_overloaded(left.resulttype.def,resulttype.def))} then
  1062. CGMessage(cg_e_illegal_type_conversion);
  1063. end
  1064. else
  1065. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1066. end;
  1067. { tp7 procvar support, when right is not a procvardef and we got a
  1068. loadn of a procvar then convert to a calln, the check for the
  1069. result is already done in is_convertible, also no conflict with
  1070. @procvar is here because that has an extra addrn }
  1071. if (m_tp_procvar in aktmodeswitches) and
  1072. (resulttype.def.deftype<>procvardef) and
  1073. (left.resulttype.def.deftype=procvardef) and
  1074. (left.nodetype=loadn) then
  1075. begin
  1076. hp:=ccallnode.create(nil,nil,nil,nil);
  1077. tcallnode(hp).set_procvar(left);
  1078. resulttypepass(hp);
  1079. left:=hp;
  1080. end;
  1081. { remove typeconv after niln, but not when the result is a
  1082. methodpointer. The typeconv of the methodpointer will then
  1083. take care of updateing size of niln to OS_64 }
  1084. if (left.nodetype=niln) and
  1085. not((resulttype.def.deftype=procvardef) and
  1086. (po_methodpointer in tprocvardef(resulttype.def).procoptions)) then
  1087. begin
  1088. left.resulttype:=resulttype;
  1089. result:=left;
  1090. left:=nil;
  1091. exit;
  1092. end;
  1093. { ordinal contants can be directly converted }
  1094. if (left.nodetype=ordconstn) and is_ordinal(resulttype.def) and
  1095. { but not char to char because it is a widechar to char or via versa }
  1096. { which needs extra code to do the code page transistion }
  1097. not(convtype=tc_char_2_char) then
  1098. begin
  1099. { replace the resulttype and recheck the range }
  1100. left.resulttype:=resulttype;
  1101. testrange(left.resulttype.def,tordconstnode(left).value,(nf_explizit in flags));
  1102. result:=left;
  1103. left:=nil;
  1104. exit;
  1105. end;
  1106. { fold nil to any pointer type }
  1107. if (left.nodetype=niln) and (resulttype.def.deftype=pointerdef) then
  1108. begin
  1109. hp:=cnilnode.create;
  1110. hp.resulttype:=resulttype;
  1111. result:=hp;
  1112. exit;
  1113. end;
  1114. { further, pointerconstn to any pointer is folded too }
  1115. if (left.nodetype=pointerconstn) and (resulttype.def.deftype=pointerdef) then
  1116. begin
  1117. left.resulttype:=resulttype;
  1118. result:=left;
  1119. left:=nil;
  1120. exit;
  1121. end;
  1122. { now call the resulttype helper to do constant folding }
  1123. result:=resulttype_call_helper(convtype);
  1124. end;
  1125. function ttypeconvnode.first_cord_to_pointer : tnode;
  1126. begin
  1127. result:=nil;
  1128. internalerror(200104043);
  1129. end;
  1130. function ttypeconvnode.first_int_to_int : tnode;
  1131. begin
  1132. first_int_to_int:=nil;
  1133. if (left.location.loc<>LOC_REGISTER) and
  1134. (resulttype.def.size>left.resulttype.def.size) then
  1135. location.loc:=LOC_REGISTER;
  1136. if is_64bitint(resulttype.def) then
  1137. registers32:=max(registers32,2)
  1138. else
  1139. registers32:=max(registers32,1);
  1140. end;
  1141. function ttypeconvnode.first_cstring_to_pchar : tnode;
  1142. begin
  1143. first_cstring_to_pchar:=nil;
  1144. registers32:=1;
  1145. location.loc:=LOC_REGISTER;
  1146. end;
  1147. function ttypeconvnode.first_string_to_chararray : tnode;
  1148. begin
  1149. first_string_to_chararray:=nil;
  1150. registers32:=1;
  1151. location.loc:=LOC_REGISTER;
  1152. end;
  1153. function ttypeconvnode.first_char_to_string : tnode;
  1154. begin
  1155. first_char_to_string:=nil;
  1156. location.loc:=LOC_CREFERENCE;
  1157. end;
  1158. function ttypeconvnode.first_nothing : tnode;
  1159. begin
  1160. first_nothing:=nil;
  1161. end;
  1162. function ttypeconvnode.first_array_to_pointer : tnode;
  1163. begin
  1164. first_array_to_pointer:=nil;
  1165. if registers32<1 then
  1166. registers32:=1;
  1167. location.loc:=LOC_REGISTER;
  1168. end;
  1169. function ttypeconvnode.first_int_to_real : tnode;
  1170. begin
  1171. first_int_to_real:=nil;
  1172. {$ifdef m68k}
  1173. if (cs_fp_emulation in aktmoduleswitches) or
  1174. (tfloatdef(resulttype.def).typ=s32real) then
  1175. begin
  1176. if registers32<1 then
  1177. registers32:=1;
  1178. end
  1179. else
  1180. if registersfpu<1 then
  1181. registersfpu:=1;
  1182. {$else not m68k}
  1183. if registersfpu<1 then
  1184. registersfpu:=1;
  1185. {$endif not m68k}
  1186. location.loc:=LOC_FPUREGISTER;
  1187. end;
  1188. function ttypeconvnode.first_real_to_real : tnode;
  1189. begin
  1190. first_real_to_real:=nil;
  1191. { comp isn't a floating type }
  1192. {$ifdef i386}
  1193. if (tfloatdef(resulttype.def).typ=s64comp) and
  1194. (tfloatdef(left.resulttype.def).typ<>s64comp) and
  1195. not (nf_explizit in flags) then
  1196. CGMessage(type_w_convert_real_2_comp);
  1197. {$endif}
  1198. if registersfpu<1 then
  1199. registersfpu:=1;
  1200. location.loc:=LOC_FPUREGISTER;
  1201. end;
  1202. function ttypeconvnode.first_pointer_to_array : tnode;
  1203. begin
  1204. first_pointer_to_array:=nil;
  1205. if registers32<1 then
  1206. registers32:=1;
  1207. location.loc:=LOC_REFERENCE;
  1208. end;
  1209. function ttypeconvnode.first_cchar_to_pchar : tnode;
  1210. begin
  1211. first_cchar_to_pchar:=nil;
  1212. internalerror(200104021);
  1213. end;
  1214. function ttypeconvnode.first_bool_to_int : tnode;
  1215. begin
  1216. first_bool_to_int:=nil;
  1217. { byte(boolean) or word(wordbool) or longint(longbool) must
  1218. be accepted for var parameters }
  1219. if (nf_explizit in flags) and
  1220. (left.resulttype.def.size=resulttype.def.size) and
  1221. (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1222. exit;
  1223. { when converting to 64bit, first convert to a 32bit int and then }
  1224. { convert to a 64bit int (only necessary for 32bit processors) (JM) }
  1225. if resulttype.def.size > sizeof(aword) then
  1226. begin
  1227. result := ctypeconvnode.create(left,u32bittype);
  1228. result.toggleflag(nf_explizit);
  1229. result := ctypeconvnode.create(result,resulttype);
  1230. left := nil;
  1231. firstpass(result);
  1232. exit;
  1233. end;
  1234. location.loc:=LOC_REGISTER;
  1235. if registers32<1 then
  1236. registers32:=1;
  1237. end;
  1238. function ttypeconvnode.first_int_to_bool : tnode;
  1239. begin
  1240. first_int_to_bool:=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. location.loc:=LOC_REGISTER;
  1248. { need if bool to bool !!
  1249. not very nice !!
  1250. insertypeconv(left,s32bittype);
  1251. left.explizit:=true;
  1252. firstpass(left); }
  1253. if registers32<1 then
  1254. registers32:=1;
  1255. end;
  1256. function ttypeconvnode.first_bool_to_bool : tnode;
  1257. begin
  1258. first_bool_to_bool:=nil;
  1259. location.loc:=LOC_REGISTER;
  1260. if registers32<1 then
  1261. registers32:=1;
  1262. end;
  1263. function ttypeconvnode.first_char_to_char : tnode;
  1264. begin
  1265. first_char_to_char:=nil;
  1266. location.loc:=LOC_REGISTER;
  1267. if registers32<1 then
  1268. registers32:=1;
  1269. end;
  1270. function ttypeconvnode.first_proc_to_procvar : tnode;
  1271. begin
  1272. first_proc_to_procvar:=nil;
  1273. if (left.location.loc<>LOC_REFERENCE) then
  1274. CGMessage(cg_e_illegal_expression);
  1275. registers32:=left.registers32;
  1276. if registers32<1 then
  1277. registers32:=1;
  1278. location.loc:=LOC_REGISTER;
  1279. end;
  1280. function ttypeconvnode.first_load_smallset : tnode;
  1281. var
  1282. srsym: ttypesym;
  1283. p: tcallparanode;
  1284. begin
  1285. if not searchsystype('FPC_SMALL_SET',srsym) then
  1286. internalerror(200108313);
  1287. p := ccallparanode.create(left,nil);
  1288. { reused }
  1289. left := nil;
  1290. { convert parameter explicitely to fpc_small_set }
  1291. p.left := ctypeconvnode.create(p.left,srsym.restype);
  1292. p.left.toggleflag(nf_explizit);
  1293. { create call, adjust resulttype }
  1294. result :=
  1295. ccallnode.createinternres('fpc_set_load_small',p,resulttype);
  1296. firstpass(result);
  1297. end;
  1298. function ttypeconvnode.first_ansistring_to_pchar : tnode;
  1299. begin
  1300. first_ansistring_to_pchar:=nil;
  1301. location.loc:=LOC_REGISTER;
  1302. if registers32<1 then
  1303. registers32:=1;
  1304. end;
  1305. function ttypeconvnode.first_arrayconstructor_to_set : tnode;
  1306. begin
  1307. first_arrayconstructor_to_set:=nil;
  1308. internalerror(200104022);
  1309. end;
  1310. function ttypeconvnode.first_class_to_intf : tnode;
  1311. begin
  1312. first_class_to_intf:=nil;
  1313. location.loc:=LOC_REFERENCE;
  1314. if registers32<1 then
  1315. registers32:=1;
  1316. end;
  1317. function ttypeconvnode._first_int_to_int : tnode;
  1318. begin
  1319. result:=first_int_to_int;
  1320. end;
  1321. function ttypeconvnode._first_cstring_to_pchar : tnode;
  1322. begin
  1323. result:=first_cstring_to_pchar;
  1324. end;
  1325. function ttypeconvnode._first_string_to_chararray : tnode;
  1326. begin
  1327. result:=first_string_to_chararray;
  1328. end;
  1329. function ttypeconvnode._first_char_to_string : tnode;
  1330. begin
  1331. result:=first_char_to_string;
  1332. end;
  1333. function ttypeconvnode._first_nothing : tnode;
  1334. begin
  1335. result:=first_nothing;
  1336. end;
  1337. function ttypeconvnode._first_array_to_pointer : tnode;
  1338. begin
  1339. result:=first_array_to_pointer;
  1340. end;
  1341. function ttypeconvnode._first_int_to_real : tnode;
  1342. begin
  1343. result:=first_int_to_real;
  1344. end;
  1345. function ttypeconvnode._first_real_to_real : tnode;
  1346. begin
  1347. result:=first_real_to_real;
  1348. end;
  1349. function ttypeconvnode._first_pointer_to_array : tnode;
  1350. begin
  1351. result:=first_pointer_to_array;
  1352. end;
  1353. function ttypeconvnode._first_cchar_to_pchar : tnode;
  1354. begin
  1355. result:=first_cchar_to_pchar;
  1356. end;
  1357. function ttypeconvnode._first_bool_to_int : tnode;
  1358. begin
  1359. result:=first_bool_to_int;
  1360. end;
  1361. function ttypeconvnode._first_int_to_bool : tnode;
  1362. begin
  1363. result:=first_int_to_bool;
  1364. end;
  1365. function ttypeconvnode._first_bool_to_bool : tnode;
  1366. begin
  1367. result:=first_bool_to_bool;
  1368. end;
  1369. function ttypeconvnode._first_proc_to_procvar : tnode;
  1370. begin
  1371. result:=first_proc_to_procvar;
  1372. end;
  1373. function ttypeconvnode._first_load_smallset : tnode;
  1374. begin
  1375. result:=first_load_smallset;
  1376. end;
  1377. function ttypeconvnode._first_cord_to_pointer : tnode;
  1378. begin
  1379. result:=first_cord_to_pointer;
  1380. end;
  1381. function ttypeconvnode._first_ansistring_to_pchar : tnode;
  1382. begin
  1383. result:=first_ansistring_to_pchar;
  1384. end;
  1385. function ttypeconvnode._first_arrayconstructor_to_set : tnode;
  1386. begin
  1387. result:=first_arrayconstructor_to_set;
  1388. end;
  1389. function ttypeconvnode._first_class_to_intf : tnode;
  1390. begin
  1391. result:=first_class_to_intf;
  1392. end;
  1393. function ttypeconvnode._first_char_to_char : tnode;
  1394. begin
  1395. result:=first_char_to_char;
  1396. end;
  1397. function ttypeconvnode.first_call_helper(c : tconverttype) : tnode;
  1398. const
  1399. firstconvert : array[tconverttype] of pointer = (
  1400. @ttypeconvnode._first_nothing, {equal}
  1401. @ttypeconvnode._first_nothing, {not_possible}
  1402. nil, { removed in resulttype_string_to_string }
  1403. @ttypeconvnode._first_char_to_string,
  1404. @ttypeconvnode._first_nothing, { char_2_chararray, needs nothing extra }
  1405. nil, { removed in resulttype_chararray_to_string }
  1406. @ttypeconvnode._first_cchar_to_pchar,
  1407. @ttypeconvnode._first_cstring_to_pchar,
  1408. @ttypeconvnode._first_ansistring_to_pchar,
  1409. @ttypeconvnode._first_string_to_chararray,
  1410. nil, { removed in resulttype_chararray_to_string }
  1411. @ttypeconvnode._first_array_to_pointer,
  1412. @ttypeconvnode._first_pointer_to_array,
  1413. @ttypeconvnode._first_int_to_int,
  1414. @ttypeconvnode._first_int_to_bool,
  1415. @ttypeconvnode._first_bool_to_bool,
  1416. @ttypeconvnode._first_bool_to_int,
  1417. @ttypeconvnode._first_real_to_real,
  1418. @ttypeconvnode._first_int_to_real,
  1419. @ttypeconvnode._first_proc_to_procvar,
  1420. @ttypeconvnode._first_arrayconstructor_to_set,
  1421. @ttypeconvnode._first_load_smallset,
  1422. @ttypeconvnode._first_cord_to_pointer,
  1423. @ttypeconvnode._first_nothing,
  1424. @ttypeconvnode._first_nothing,
  1425. @ttypeconvnode._first_class_to_intf,
  1426. @ttypeconvnode._first_char_to_char,
  1427. @ttypeconvnode._first_nothing,
  1428. @ttypeconvnode._first_nothing
  1429. );
  1430. type
  1431. tprocedureofobject = function : tnode of object;
  1432. var
  1433. r : packed record
  1434. proc : pointer;
  1435. obj : pointer;
  1436. end;
  1437. begin
  1438. { this is a little bit dirty but it works }
  1439. { and should be quite portable too }
  1440. r.proc:=firstconvert[c];
  1441. r.obj:=self;
  1442. first_call_helper:=tprocedureofobject(r){$ifdef FPC}();{$endif FPC}
  1443. end;
  1444. function ttypeconvnode.pass_1 : tnode;
  1445. begin
  1446. result:=nil;
  1447. firstpass(left);
  1448. if codegenerror then
  1449. exit;
  1450. { load the value_str from the left part }
  1451. registers32:=left.registers32;
  1452. registersfpu:=left.registersfpu;
  1453. {$ifdef SUPPORT_MMX}
  1454. registersmmx:=left.registersmmx;
  1455. {$endif}
  1456. location.loc:=left.location.loc;
  1457. if nf_explizit in flags then
  1458. begin
  1459. { check if the result could be in a register }
  1460. if not(tstoreddef(resulttype.def).is_intregable) and
  1461. not(tstoreddef(resulttype.def).is_fpuregable) then
  1462. make_not_regable(left);
  1463. end;
  1464. result:=first_call_helper(convtype);
  1465. end;
  1466. function ttypeconvnode.docompare(p: tnode) : boolean;
  1467. begin
  1468. docompare :=
  1469. inherited docompare(p) and
  1470. (convtype = ttypeconvnode(p).convtype);
  1471. end;
  1472. {*****************************************************************************
  1473. TISNODE
  1474. *****************************************************************************}
  1475. constructor tisnode.create(l,r : tnode);
  1476. begin
  1477. inherited create(isn,l,r);
  1478. end;
  1479. function tisnode.det_resulttype:tnode;
  1480. var
  1481. paras: tcallparanode;
  1482. begin
  1483. result:=nil;
  1484. resulttypepass(left);
  1485. resulttypepass(right);
  1486. set_varstate(left,true);
  1487. set_varstate(right,true);
  1488. if codegenerror then
  1489. exit;
  1490. if (right.resulttype.def.deftype=classrefdef) then
  1491. begin
  1492. { left must be a class }
  1493. if is_class(left.resulttype.def) then
  1494. begin
  1495. { the operands must be related }
  1496. if (not(tobjectdef(left.resulttype.def).is_related(
  1497. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1498. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1499. tobjectdef(left.resulttype.def)))) then
  1500. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1501. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1502. end
  1503. else
  1504. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1505. { call fpc_do_is helper }
  1506. paras := ccallparanode.create(
  1507. left,
  1508. ccallparanode.create(
  1509. right,nil));
  1510. result := ccallnode.createintern('fpc_do_is',paras);
  1511. left := nil;
  1512. right := nil;
  1513. end
  1514. else if is_interface(right.resulttype.def) then
  1515. begin
  1516. { left is a class }
  1517. if is_class(left.resulttype.def) then
  1518. begin
  1519. { the operands must be related }
  1520. if not(assigned(tobjectdef(left.resulttype.def).implementedinterfaces) and
  1521. (tobjectdef(left.resulttype.def).implementedinterfaces.searchintf(right.resulttype.def)<>-1)) then
  1522. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1523. end
  1524. { left is an interface }
  1525. else if is_interface(left.resulttype.def) then
  1526. begin
  1527. { the operands must be related }
  1528. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  1529. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1530. CGMessage(type_e_mismatch);
  1531. end
  1532. else
  1533. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1534. { call fpc_do_is helper }
  1535. paras := ccallparanode.create(
  1536. left,
  1537. ccallparanode.create(
  1538. right,nil));
  1539. result := ccallnode.createintern('fpc_do_is',paras);
  1540. left := nil;
  1541. right := nil;
  1542. end
  1543. else
  1544. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  1545. resulttype:=booltype;
  1546. end;
  1547. function tisnode.pass_1 : tnode;
  1548. begin
  1549. internalerror(200204254);
  1550. result:=nil;
  1551. end;
  1552. { dummy pass_2, it will never be called, but we need one since }
  1553. { you can't instantiate an abstract class }
  1554. procedure tisnode.pass_2;
  1555. begin
  1556. end;
  1557. {*****************************************************************************
  1558. TASNODE
  1559. *****************************************************************************}
  1560. constructor tasnode.create(l,r : tnode);
  1561. begin
  1562. inherited create(asn,l,r);
  1563. end;
  1564. function tasnode.det_resulttype:tnode;
  1565. begin
  1566. result:=nil;
  1567. resulttypepass(right);
  1568. resulttypepass(left);
  1569. set_varstate(right,true);
  1570. set_varstate(left,true);
  1571. if codegenerror then
  1572. exit;
  1573. if (right.resulttype.def.deftype=classrefdef) then
  1574. begin
  1575. { left must be a class }
  1576. if is_class(left.resulttype.def) then
  1577. begin
  1578. { the operands must be related }
  1579. if (not(tobjectdef(left.resulttype.def).is_related(
  1580. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1581. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1582. tobjectdef(left.resulttype.def)))) then
  1583. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1584. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1585. end
  1586. else
  1587. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1588. resulttype:=tclassrefdef(right.resulttype.def).pointertype;
  1589. end
  1590. else if is_interface(right.resulttype.def) then
  1591. begin
  1592. { left is a class }
  1593. if is_class(left.resulttype.def) then
  1594. begin
  1595. { the operands must be related }
  1596. if not(assigned(tobjectdef(left.resulttype.def).implementedinterfaces) and
  1597. (tobjectdef(left.resulttype.def).implementedinterfaces.searchintf(right.resulttype.def)<>-1)) then
  1598. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1599. end
  1600. { left is an interface }
  1601. else if is_interface(left.resulttype.def) then
  1602. begin
  1603. { the operands must be related }
  1604. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  1605. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1606. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1607. end
  1608. else
  1609. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1610. resulttype:=right.resulttype;
  1611. { load the GUID of the interface }
  1612. if (right.nodetype=typen) then
  1613. begin
  1614. if tobjectdef(left.resulttype.def).isiidguidvalid then
  1615. right:=cguidconstnode.create(tobjectdef(left.resulttype.def).iidguid)
  1616. else
  1617. internalerror(200206282);
  1618. resulttypepass(right);
  1619. end;
  1620. end
  1621. else
  1622. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  1623. end;
  1624. function tasnode.pass_1 : tnode;
  1625. begin
  1626. firstpass(left);
  1627. firstpass(right);
  1628. if codegenerror then
  1629. exit;
  1630. left_right_max;
  1631. location.loc:=left.location.loc;
  1632. result:=nil;
  1633. end;
  1634. begin
  1635. ctypeconvnode:=ttypeconvnode;
  1636. casnode:=tasnode;
  1637. cisnode:=tisnode;
  1638. end.
  1639. {
  1640. $Log$
  1641. Revision 1.66 2002-08-09 07:33:01 florian
  1642. * a couple of interface related fixes
  1643. Revision 1.65 2002/07/29 21:23:42 florian
  1644. * more fixes for the ppc
  1645. + wrappers for the tcnvnode.first_* stuff introduced
  1646. Revision 1.64 2002/07/23 12:34:30 daniel
  1647. * Readded old set code. To use it define 'oldset'. Activated by default
  1648. for ppc.
  1649. Revision 1.63 2002/07/23 09:51:22 daniel
  1650. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  1651. are worth comitting.
  1652. Revision 1.62 2002/07/22 11:48:04 daniel
  1653. * Sets are now internally sets.
  1654. Revision 1.61 2002/07/20 17:16:02 florian
  1655. + source code page support
  1656. Revision 1.60 2002/07/20 11:57:54 florian
  1657. * types.pas renamed to defbase.pas because D6 contains a types
  1658. unit so this would conflicts if D6 programms are compiled
  1659. + Willamette/SSE2 instructions to assembler added
  1660. Revision 1.59 2002/07/01 16:23:53 peter
  1661. * cg64 patch
  1662. * basics for currency
  1663. * asnode updates for class and interface (not finished)
  1664. Revision 1.58 2002/05/18 13:34:09 peter
  1665. * readded missing revisions
  1666. Revision 1.57 2002/05/16 19:46:37 carl
  1667. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1668. + try to fix temp allocation (still in ifdef)
  1669. + generic constructor calls
  1670. + start of tassembler / tmodulebase class cleanup
  1671. Revision 1.55 2002/05/12 16:53:07 peter
  1672. * moved entry and exitcode to ncgutil and cgobj
  1673. * foreach gets extra argument for passing local data to the
  1674. iterator function
  1675. * -CR checks also class typecasts at runtime by changing them
  1676. into as
  1677. * fixed compiler to cycle with the -CR option
  1678. * fixed stabs with elf writer, finally the global variables can
  1679. be watched
  1680. * removed a lot of routines from cga unit and replaced them by
  1681. calls to cgobj
  1682. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1683. u32bit then the other is typecasted also to u32bit without giving
  1684. a rangecheck warning/error.
  1685. * fixed pascal calling method with reversing also the high tree in
  1686. the parast, detected by tcalcst3 test
  1687. Revision 1.54 2002/04/25 20:16:38 peter
  1688. * moved more routines from cga/n386util
  1689. Revision 1.53 2002/04/23 19:16:34 peter
  1690. * add pinline unit that inserts compiler supported functions using
  1691. one or more statements
  1692. * moved finalize and setlength from ninl to pinline
  1693. Revision 1.52 2002/04/21 19:02:03 peter
  1694. * removed newn and disposen nodes, the code is now directly
  1695. inlined from pexpr
  1696. * -an option that will write the secondpass nodes to the .s file, this
  1697. requires EXTDEBUG define to actually write the info
  1698. * fixed various internal errors and crashes due recent code changes
  1699. Revision 1.51 2002/04/06 18:10:42 jonas
  1700. * several powerpc-related additions and fixes
  1701. Revision 1.50 2002/04/04 19:05:58 peter
  1702. * removed unused units
  1703. * use tlocation.size in cg.a_*loc*() routines
  1704. Revision 1.49 2002/04/02 17:11:28 peter
  1705. * tlocation,treference update
  1706. * LOC_CONSTANT added for better constant handling
  1707. * secondadd splitted in multiple routines
  1708. * location_force_reg added for loading a location to a register
  1709. of a specified size
  1710. * secondassignment parses now first the right and then the left node
  1711. (this is compatible with Kylix). This saves a lot of push/pop especially
  1712. with string operations
  1713. * adapted some routines to use the new cg methods
  1714. Revision 1.48 2002/02/03 09:30:03 peter
  1715. * more fixes for protected handling
  1716. }