ncnv.pas 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589
  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,
  24. defutil,defcmp,
  25. nld
  26. ;
  27. type
  28. ttypeconvnode = class(tunarynode)
  29. totype : ttype;
  30. convtype : tconverttype;
  31. constructor create(node : tnode;const t : ttype);virtual;
  32. constructor create_explicit(node : tnode;const t : ttype);
  33. constructor create_internal(node : tnode;const t : ttype);
  34. constructor create_proc_to_procvar(node : tnode);
  35. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  36. procedure ppuwrite(ppufile:tcompilerppufile);override;
  37. procedure buildderefimpl;override;
  38. procedure derefimpl;override;
  39. function getcopy : tnode;override;
  40. function pass_1 : tnode;override;
  41. function det_resulttype:tnode;override;
  42. procedure mark_write;override;
  43. function docompare(p: tnode) : boolean; override;
  44. function assign_allowed:boolean;
  45. procedure second_call_helper(c : tconverttype);
  46. private
  47. function resulttype_int_to_int : tnode;
  48. function resulttype_cord_to_pointer : tnode;
  49. function resulttype_chararray_to_string : tnode;
  50. function resulttype_string_to_chararray : tnode;
  51. function resulttype_string_to_string : tnode;
  52. function resulttype_char_to_string : tnode;
  53. function resulttype_char_to_chararray : tnode;
  54. function resulttype_int_to_real : tnode;
  55. function resulttype_real_to_real : tnode;
  56. function resulttype_real_to_currency : tnode;
  57. function resulttype_cchar_to_pchar : tnode;
  58. function resulttype_cstring_to_pchar : tnode;
  59. function resulttype_char_to_char : tnode;
  60. function resulttype_arrayconstructor_to_set : tnode;
  61. function resulttype_pchar_to_string : tnode;
  62. function resulttype_interface_to_guid : tnode;
  63. function resulttype_dynarray_to_openarray : tnode;
  64. function resulttype_pwchar_to_string : tnode;
  65. function resulttype_variant_to_dynarray : tnode;
  66. function resulttype_dynarray_to_variant : tnode;
  67. function resulttype_call_helper(c : tconverttype) : tnode;
  68. function resulttype_variant_to_enum : tnode;
  69. function resulttype_enum_to_variant : tnode;
  70. function resulttype_proc_to_procvar : tnode;
  71. protected
  72. function first_int_to_int : tnode;virtual;
  73. function first_cstring_to_pchar : tnode;virtual;
  74. function first_string_to_chararray : tnode;virtual;
  75. function first_char_to_string : tnode;virtual;
  76. function first_nothing : tnode;virtual;
  77. function first_array_to_pointer : tnode;virtual;
  78. function first_int_to_real : tnode;virtual;
  79. function first_real_to_real : tnode;virtual;
  80. function first_pointer_to_array : tnode;virtual;
  81. function first_cchar_to_pchar : tnode;virtual;
  82. function first_bool_to_int : tnode;virtual;
  83. function first_int_to_bool : tnode;virtual;
  84. function first_bool_to_bool : tnode;virtual;
  85. function first_proc_to_procvar : tnode;virtual;
  86. function first_load_smallset : tnode;virtual;
  87. function first_cord_to_pointer : tnode;virtual;
  88. function first_ansistring_to_pchar : tnode;virtual;
  89. function first_arrayconstructor_to_set : tnode;virtual;
  90. function first_class_to_intf : tnode;virtual;
  91. function first_char_to_char : tnode;virtual;
  92. function first_call_helper(c : tconverttype) : tnode;
  93. { these wrapper are necessary, because the first_* stuff is called }
  94. { through a table. Without the wrappers override wouldn't have }
  95. { any effect }
  96. function _first_int_to_int : tnode;
  97. function _first_cstring_to_pchar : tnode;
  98. function _first_string_to_chararray : tnode;
  99. function _first_char_to_string : tnode;
  100. function _first_nothing : tnode;
  101. function _first_array_to_pointer : tnode;
  102. function _first_int_to_real : tnode;
  103. function _first_real_to_real: tnode;
  104. function _first_pointer_to_array : tnode;
  105. function _first_cchar_to_pchar : tnode;
  106. function _first_bool_to_int : tnode;
  107. function _first_int_to_bool : tnode;
  108. function _first_bool_to_bool : tnode;
  109. function _first_proc_to_procvar : tnode;
  110. function _first_load_smallset : tnode;
  111. function _first_cord_to_pointer : tnode;
  112. function _first_ansistring_to_pchar : tnode;
  113. function _first_arrayconstructor_to_set : tnode;
  114. function _first_class_to_intf : tnode;
  115. function _first_char_to_char : tnode;
  116. procedure _second_int_to_int;virtual;
  117. procedure _second_string_to_string;virtual;
  118. procedure _second_cstring_to_pchar;virtual;
  119. procedure _second_string_to_chararray;virtual;
  120. procedure _second_array_to_pointer;virtual;
  121. procedure _second_pointer_to_array;virtual;
  122. procedure _second_chararray_to_string;virtual;
  123. procedure _second_char_to_string;virtual;
  124. procedure _second_int_to_real;virtual;
  125. procedure _second_real_to_real;virtual;
  126. procedure _second_cord_to_pointer;virtual;
  127. procedure _second_proc_to_procvar;virtual;
  128. procedure _second_bool_to_int;virtual;
  129. procedure _second_int_to_bool;virtual;
  130. procedure _second_bool_to_bool;virtual;
  131. procedure _second_load_smallset;virtual;
  132. procedure _second_ansistring_to_pchar;virtual;
  133. procedure _second_class_to_intf;virtual;
  134. procedure _second_char_to_char;virtual;
  135. procedure _second_nothing; virtual;
  136. procedure second_int_to_int;virtual;abstract;
  137. procedure second_string_to_string;virtual;abstract;
  138. procedure second_cstring_to_pchar;virtual;abstract;
  139. procedure second_string_to_chararray;virtual;abstract;
  140. procedure second_array_to_pointer;virtual;abstract;
  141. procedure second_pointer_to_array;virtual;abstract;
  142. procedure second_chararray_to_string;virtual;abstract;
  143. procedure second_char_to_string;virtual;abstract;
  144. procedure second_int_to_real;virtual;abstract;
  145. procedure second_real_to_real;virtual;abstract;
  146. procedure second_cord_to_pointer;virtual;abstract;
  147. procedure second_proc_to_procvar;virtual;abstract;
  148. procedure second_bool_to_int;virtual;abstract;
  149. procedure second_int_to_bool;virtual;abstract;
  150. procedure second_bool_to_bool;virtual;abstract;
  151. procedure second_load_smallset;virtual;abstract;
  152. procedure second_ansistring_to_pchar;virtual;abstract;
  153. procedure second_class_to_intf;virtual;abstract;
  154. procedure second_char_to_char;virtual;abstract;
  155. procedure second_nothing; virtual;abstract;
  156. end;
  157. ttypeconvnodeclass = class of ttypeconvnode;
  158. tasnode = class(tbinarynode)
  159. constructor create(l,r : tnode);virtual;
  160. function pass_1 : tnode;override;
  161. function det_resulttype:tnode;override;
  162. function getcopy: tnode;override;
  163. destructor destroy; override;
  164. protected
  165. call: tnode;
  166. end;
  167. tasnodeclass = class of tasnode;
  168. tisnode = class(tbinarynode)
  169. constructor create(l,r : tnode);virtual;
  170. function pass_1 : tnode;override;
  171. function det_resulttype:tnode;override;
  172. procedure pass_2;override;
  173. end;
  174. tisnodeclass = class of tisnode;
  175. var
  176. ctypeconvnode : ttypeconvnodeclass;
  177. casnode : tasnodeclass;
  178. cisnode : tisnodeclass;
  179. procedure inserttypeconv(var p:tnode;const t:ttype);
  180. procedure inserttypeconv_internal(var p:tnode;const t:ttype);
  181. procedure arrayconstructor_to_set(var p : tnode);
  182. implementation
  183. uses
  184. cclasses,globtype,systems,
  185. cutils,verbose,globals,widestr,
  186. symconst,symdef,symsym,symbase,symtable,
  187. ncon,ncal,nset,nadd,ninl,nmem,nmat,nutils,
  188. cgbase,procinfo,
  189. htypechk,pass_1,cpuinfo;
  190. {*****************************************************************************
  191. Helpers
  192. *****************************************************************************}
  193. procedure inserttypeconv(var p:tnode;const t:ttype);
  194. begin
  195. if not assigned(p.resulttype.def) then
  196. begin
  197. resulttypepass(p);
  198. if codegenerror then
  199. exit;
  200. end;
  201. { don't insert obsolete type conversions }
  202. if equal_defs(p.resulttype.def,t.def) and
  203. not ((p.resulttype.def.deftype=setdef) and
  204. (tsetdef(p.resulttype.def).settype <>
  205. tsetdef(t.def).settype)) then
  206. begin
  207. p.resulttype:=t;
  208. end
  209. else
  210. begin
  211. p:=ctypeconvnode.create(p,t);
  212. resulttypepass(p);
  213. end;
  214. end;
  215. procedure inserttypeconv_internal(var p:tnode;const t:ttype);
  216. begin
  217. if not assigned(p.resulttype.def) then
  218. begin
  219. resulttypepass(p);
  220. if codegenerror then
  221. exit;
  222. end;
  223. { don't insert obsolete type conversions }
  224. if equal_defs(p.resulttype.def,t.def) and
  225. not ((p.resulttype.def.deftype=setdef) and
  226. (tsetdef(p.resulttype.def).settype <>
  227. tsetdef(t.def).settype)) then
  228. begin
  229. p.resulttype:=t;
  230. end
  231. else
  232. begin
  233. p:=ctypeconvnode.create_internal(p,t);
  234. resulttypepass(p);
  235. end;
  236. end;
  237. {*****************************************************************************
  238. Array constructor to Set Conversion
  239. *****************************************************************************}
  240. procedure arrayconstructor_to_set(var p : tnode);
  241. var
  242. constp : tsetconstnode;
  243. buildp,
  244. p2,p3,p4 : tnode;
  245. htype : ttype;
  246. constset : Pconstset;
  247. constsetlo,
  248. constsethi : TConstExprInt;
  249. procedure update_constsethi(t:ttype);
  250. begin
  251. if ((t.def.deftype=orddef) and
  252. (torddef(t.def).high>=constsethi)) then
  253. begin
  254. if torddef(t.def).typ=uwidechar then
  255. begin
  256. constsethi:=255;
  257. if htype.def=nil then
  258. htype:=t;
  259. end
  260. else
  261. begin
  262. constsethi:=torddef(t.def).high;
  263. if htype.def=nil then
  264. begin
  265. if (constsethi>255) or
  266. (torddef(t.def).low<0) then
  267. htype:=u8inttype
  268. else
  269. htype:=t;
  270. end;
  271. if constsethi>255 then
  272. constsethi:=255;
  273. end;
  274. end
  275. else if ((t.def.deftype=enumdef) and
  276. (tenumdef(t.def).max>=constsethi)) then
  277. begin
  278. if htype.def=nil then
  279. htype:=t;
  280. constsethi:=tenumdef(t.def).max;
  281. end;
  282. end;
  283. procedure do_set(pos : longint);
  284. begin
  285. if (pos and not $ff)<>0 then
  286. Message(parser_e_illegal_set_expr);
  287. if pos>constsethi then
  288. constsethi:=pos;
  289. if pos<constsetlo then
  290. constsetlo:=pos;
  291. if pos in constset^ then
  292. Message(parser_e_illegal_set_expr);
  293. include(constset^,pos);
  294. end;
  295. var
  296. l : Longint;
  297. lr,hr : TConstExprInt;
  298. hp : tarrayconstructornode;
  299. begin
  300. if p.nodetype<>arrayconstructorn then
  301. internalerror(200205105);
  302. new(constset);
  303. constset^:=[];
  304. htype.reset;
  305. constsetlo:=0;
  306. constsethi:=0;
  307. constp:=csetconstnode.create(nil,htype);
  308. constp.value_set:=constset;
  309. buildp:=constp;
  310. hp:=tarrayconstructornode(p);
  311. if assigned(hp.left) then
  312. begin
  313. while assigned(hp) do
  314. begin
  315. p4:=nil; { will contain the tree to create the set }
  316. {split a range into p2 and p3 }
  317. if hp.left.nodetype=arrayconstructorrangen then
  318. begin
  319. p2:=tarrayconstructorrangenode(hp.left).left;
  320. p3:=tarrayconstructorrangenode(hp.left).right;
  321. tarrayconstructorrangenode(hp.left).left:=nil;
  322. tarrayconstructorrangenode(hp.left).right:=nil;
  323. end
  324. else
  325. begin
  326. p2:=hp.left;
  327. hp.left:=nil;
  328. p3:=nil;
  329. end;
  330. resulttypepass(p2);
  331. if assigned(p3) then
  332. resulttypepass(p3);
  333. if codegenerror then
  334. break;
  335. case p2.resulttype.def.deftype of
  336. enumdef,
  337. orddef:
  338. begin
  339. getrange(p2.resulttype.def,lr,hr);
  340. if assigned(p3) then
  341. begin
  342. { this isn't good, you'll get problems with
  343. type t010 = 0..10;
  344. ts = set of t010;
  345. var s : ts;b : t010
  346. begin s:=[1,2,b]; end.
  347. if is_integer(p3^.resulttype.def) then
  348. begin
  349. inserttypeconv(p3,u8bitdef);
  350. end;
  351. }
  352. if assigned(htype.def) and not(equal_defs(htype.def,p3.resulttype.def)) then
  353. begin
  354. aktfilepos:=p3.fileinfo;
  355. CGMessage(type_e_typeconflict_in_set);
  356. end
  357. else
  358. begin
  359. if (p2.nodetype=ordconstn) and (p3.nodetype=ordconstn) then
  360. begin
  361. if not(is_integer(p3.resulttype.def)) then
  362. htype:=p3.resulttype
  363. else
  364. begin
  365. inserttypeconv(p3,u8inttype);
  366. inserttypeconv(p2,u8inttype);
  367. end;
  368. for l:=tordconstnode(p2).value to tordconstnode(p3).value do
  369. do_set(l);
  370. p2.free;
  371. p3.free;
  372. end
  373. else
  374. begin
  375. update_constsethi(p2.resulttype);
  376. inserttypeconv(p2,htype);
  377. update_constsethi(p3.resulttype);
  378. inserttypeconv(p3,htype);
  379. if assigned(htype.def) then
  380. inserttypeconv(p3,htype)
  381. else
  382. inserttypeconv(p3,u8inttype);
  383. p4:=csetelementnode.create(p2,p3);
  384. end;
  385. end;
  386. end
  387. else
  388. begin
  389. { Single value }
  390. if p2.nodetype=ordconstn then
  391. begin
  392. if not(is_integer(p2.resulttype.def)) then
  393. update_constsethi(p2.resulttype)
  394. else
  395. inserttypeconv(p2,u8inttype);
  396. do_set(tordconstnode(p2).value);
  397. p2.free;
  398. end
  399. else
  400. begin
  401. update_constsethi(p2.resulttype);
  402. if assigned(htype.def) then
  403. inserttypeconv(p2,htype)
  404. else
  405. inserttypeconv(p2,u8inttype);
  406. p4:=csetelementnode.create(p2,nil);
  407. end;
  408. end;
  409. end;
  410. stringdef :
  411. begin
  412. { if we've already set elements which are constants }
  413. { throw an error }
  414. if ((htype.def=nil) and assigned(buildp)) or
  415. not(is_char(htype.def)) then
  416. CGMessage(type_e_typeconflict_in_set)
  417. else
  418. for l:=1 to length(pstring(tstringconstnode(p2).value_str)^) do
  419. do_set(ord(pstring(tstringconstnode(p2).value_str)^[l]));
  420. if htype.def=nil then
  421. htype:=cchartype;
  422. p2.free;
  423. end;
  424. else
  425. CGMessage(type_e_ordinal_expr_expected);
  426. end;
  427. { insert the set creation tree }
  428. if assigned(p4) then
  429. buildp:=caddnode.create(addn,buildp,p4);
  430. { load next and dispose current node }
  431. p2:=hp;
  432. hp:=tarrayconstructornode(tarrayconstructornode(p2).right);
  433. tarrayconstructornode(p2).right:=nil;
  434. p2.free;
  435. end;
  436. if (htype.def=nil) then
  437. htype:=u8inttype;
  438. end
  439. else
  440. begin
  441. { empty set [], only remove node }
  442. p.free;
  443. end;
  444. { set the initial set type }
  445. constp.resulttype.setdef(tsetdef.create(htype,constsethi));
  446. { determine the resulttype for the tree }
  447. resulttypepass(buildp);
  448. { set the new tree }
  449. p:=buildp;
  450. end;
  451. {*****************************************************************************
  452. TTYPECONVNODE
  453. *****************************************************************************}
  454. constructor ttypeconvnode.create(node : tnode;const t:ttype);
  455. begin
  456. inherited create(typeconvn,node);
  457. convtype:=tc_none;
  458. totype:=t;
  459. if t.def=nil then
  460. internalerror(200103281);
  461. fileinfo:=node.fileinfo;
  462. end;
  463. constructor ttypeconvnode.create_explicit(node : tnode;const t:ttype);
  464. begin
  465. self.create(node,t);
  466. include(flags,nf_explicit);
  467. end;
  468. constructor ttypeconvnode.create_internal(node : tnode;const t:ttype);
  469. begin
  470. self.create(node,t);
  471. { handle like explicit conversions }
  472. include(flags,nf_explicit);
  473. include(flags,nf_internal);
  474. end;
  475. constructor ttypeconvnode.create_proc_to_procvar(node : tnode);
  476. begin
  477. self.create(node,voidtype);
  478. convtype:=tc_proc_2_procvar;
  479. end;
  480. constructor ttypeconvnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  481. begin
  482. inherited ppuload(t,ppufile);
  483. ppufile.gettype(totype);
  484. convtype:=tconverttype(ppufile.getbyte);
  485. end;
  486. procedure ttypeconvnode.ppuwrite(ppufile:tcompilerppufile);
  487. begin
  488. inherited ppuwrite(ppufile);
  489. ppufile.puttype(totype);
  490. ppufile.putbyte(byte(convtype));
  491. end;
  492. procedure ttypeconvnode.buildderefimpl;
  493. begin
  494. inherited buildderefimpl;
  495. totype.buildderef;
  496. end;
  497. procedure ttypeconvnode.derefimpl;
  498. begin
  499. inherited derefimpl;
  500. totype.resolve;
  501. end;
  502. function ttypeconvnode.getcopy : tnode;
  503. var
  504. n : ttypeconvnode;
  505. begin
  506. n:=ttypeconvnode(inherited getcopy);
  507. n.convtype:=convtype;
  508. n.totype:=totype;
  509. getcopy:=n;
  510. end;
  511. function ttypeconvnode.resulttype_cord_to_pointer : tnode;
  512. var
  513. t : tnode;
  514. begin
  515. result:=nil;
  516. if left.nodetype=ordconstn then
  517. begin
  518. { check if we have a valid pointer constant (JM) }
  519. if (sizeof(pointer) > sizeof(TConstPtrUInt)) then
  520. if (sizeof(TConstPtrUInt) = 4) then
  521. begin
  522. if (tordconstnode(left).value < low(longint)) or
  523. (tordconstnode(left).value > high(cardinal)) then
  524. CGMessage(parser_e_range_check_error);
  525. end
  526. else if (sizeof(TConstPtrUInt) = 8) then
  527. begin
  528. if (tordconstnode(left).value < low(int64)) or
  529. (tordconstnode(left).value > high(qword)) then
  530. CGMessage(parser_e_range_check_error);
  531. end
  532. else
  533. internalerror(2001020801);
  534. t:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value),resulttype);
  535. result:=t;
  536. end
  537. else
  538. internalerror(200104023);
  539. end;
  540. function ttypeconvnode.resulttype_chararray_to_string : tnode;
  541. begin
  542. result := ccallnode.createinternres(
  543. 'fpc_chararray_to_'+tstringdef(resulttype.def).stringtypname,
  544. ccallparanode.create(left,nil),resulttype);
  545. left := nil;
  546. end;
  547. function ttypeconvnode.resulttype_string_to_chararray : tnode;
  548. var
  549. arrsize : aint;
  550. begin
  551. with tarraydef(resulttype.def) do
  552. begin
  553. if highrange<lowrange then
  554. internalerror(75432653);
  555. arrsize := highrange-lowrange+1;
  556. end;
  557. if (left.nodetype = stringconstn) and
  558. { left.length+1 since there's always a terminating #0 character (JM) }
  559. (tstringconstnode(left).len+1 >= arrsize) and
  560. (tstringdef(left.resulttype.def).string_typ=st_shortstring) then
  561. begin
  562. { handled separately }
  563. result := nil;
  564. exit;
  565. end;
  566. result := ccallnode.createinternres(
  567. 'fpc_'+tstringdef(left.resulttype.def).stringtypname+
  568. '_to_chararray',ccallparanode.create(left,ccallparanode.create(
  569. cordconstnode.create(arrsize,s32inttype,true),nil)),resulttype);
  570. left := nil;
  571. end;
  572. function ttypeconvnode.resulttype_string_to_string : tnode;
  573. var
  574. procname: string[31];
  575. stringpara : tcallparanode;
  576. pw : pcompilerwidestring;
  577. pc : pchar;
  578. begin
  579. result:=nil;
  580. if left.nodetype=stringconstn then
  581. begin
  582. { convert ascii 2 unicode }
  583. {$ifdef ansistring_bits}
  584. if (tstringdef(resulttype.def).string_typ=st_widestring) and
  585. (tstringconstnode(left).st_type in [st_ansistring16,st_ansistring32,
  586. st_ansistring64,st_shortstring,st_longstring]) then
  587. {$else}
  588. if (tstringdef(resulttype.def).string_typ=st_widestring) and
  589. (tstringconstnode(left).st_type in [st_ansistring,st_shortstring,st_longstring]) then
  590. {$endif}
  591. begin
  592. initwidestring(pw);
  593. ascii2unicode(tstringconstnode(left).value_str,tstringconstnode(left).len,pw);
  594. ansistringdispose(tstringconstnode(left).value_str,tstringconstnode(left).len);
  595. pcompilerwidestring(tstringconstnode(left).value_str):=pw;
  596. end
  597. else
  598. { convert unicode 2 ascii }
  599. {$ifdef ansistring_bits}
  600. if (tstringconstnode(left).st_type=st_widestring) and
  601. (tstringdef(resulttype.def).string_typ in [st_ansistring16,st_ansistring32,
  602. st_ansistring64,st_shortstring,st_longstring]) then
  603. {$else}
  604. if (tstringconstnode(left).st_type=st_widestring) and
  605. (tstringdef(resulttype.def).string_typ in [st_ansistring,st_shortstring,st_longstring]) then
  606. {$endif}
  607. begin
  608. pw:=pcompilerwidestring(tstringconstnode(left).value_str);
  609. getmem(pc,getlengthwidestring(pw)+1);
  610. unicode2ascii(pw,pc);
  611. donewidestring(pw);
  612. tstringconstnode(left).value_str:=pc;
  613. end;
  614. tstringconstnode(left).st_type:=tstringdef(resulttype.def).string_typ;
  615. tstringconstnode(left).resulttype:=resulttype;
  616. result:=left;
  617. left:=nil;
  618. end
  619. else
  620. begin
  621. { get the correct procedure name }
  622. procname := 'fpc_'+tstringdef(left.resulttype.def).stringtypname+
  623. '_to_'+tstringdef(resulttype.def).stringtypname;
  624. { create parameter (and remove left node from typeconvnode }
  625. { since it's reused as parameter) }
  626. stringpara := ccallparanode.create(left,nil);
  627. left := nil;
  628. { when converting to shortstrings, we have to pass high(destination) too }
  629. if (tstringdef(resulttype.def).string_typ = st_shortstring) then
  630. stringpara.right := ccallparanode.create(cinlinenode.create(
  631. in_high_x,false,self.getcopy),nil);
  632. { and create the callnode }
  633. result := ccallnode.createinternres(procname,stringpara,resulttype);
  634. end;
  635. end;
  636. function ttypeconvnode.resulttype_char_to_string : tnode;
  637. var
  638. procname: string[31];
  639. para : tcallparanode;
  640. hp : tstringconstnode;
  641. ws : pcompilerwidestring;
  642. begin
  643. result:=nil;
  644. if left.nodetype=ordconstn then
  645. begin
  646. if tstringdef(resulttype.def).string_typ=st_widestring then
  647. begin
  648. initwidestring(ws);
  649. concatwidestringchar(ws,tcompilerwidechar(chr(tordconstnode(left).value)));
  650. hp:=cstringconstnode.createwstr(ws);
  651. donewidestring(ws);
  652. end
  653. else
  654. hp:=cstringconstnode.createstr(chr(tordconstnode(left).value),tstringdef(resulttype.def).string_typ);
  655. result:=hp;
  656. end
  657. else
  658. { shortstrings are handled 'inline' }
  659. if tstringdef(resulttype.def).string_typ <> st_shortstring then
  660. begin
  661. { create the parameter }
  662. para := ccallparanode.create(left,nil);
  663. left := nil;
  664. { and the procname }
  665. procname := 'fpc_char_to_' +tstringdef(resulttype.def).stringtypname;
  666. { and finally the call }
  667. result := ccallnode.createinternres(procname,para,resulttype);
  668. end
  669. else
  670. begin
  671. { create word(byte(char) shl 8 or 1) for litte endian machines }
  672. { and word(byte(char) or 256) for big endian machines }
  673. left := ctypeconvnode.create_internal(left,u8inttype);
  674. if (target_info.endian = endian_little) then
  675. left := caddnode.create(orn,
  676. cshlshrnode.create(shln,left,cordconstnode.create(8,s32inttype,false)),
  677. cordconstnode.create(1,s32inttype,false))
  678. else
  679. left := caddnode.create(orn,left,
  680. cordconstnode.create(1 shl 8,s32inttype,false));
  681. left := ctypeconvnode.create_internal(left,u16inttype);
  682. resulttypepass(left);
  683. end;
  684. end;
  685. function ttypeconvnode.resulttype_char_to_chararray : tnode;
  686. begin
  687. if resulttype.def.size <> 1 then
  688. begin
  689. { convert first to string, then to chararray }
  690. inserttypeconv(left,cshortstringtype);
  691. inserttypeconv(left,resulttype);
  692. result:=left;
  693. left := nil;
  694. exit;
  695. end;
  696. result := nil;
  697. end;
  698. function ttypeconvnode.resulttype_char_to_char : tnode;
  699. var
  700. hp : tordconstnode;
  701. begin
  702. result:=nil;
  703. if left.nodetype=ordconstn then
  704. begin
  705. if (torddef(resulttype.def).typ=uchar) and
  706. (torddef(left.resulttype.def).typ=uwidechar) then
  707. begin
  708. hp:=cordconstnode.create(
  709. ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value))),
  710. cchartype,true);
  711. result:=hp;
  712. end
  713. else if (torddef(resulttype.def).typ=uwidechar) and
  714. (torddef(left.resulttype.def).typ=uchar) then
  715. begin
  716. hp:=cordconstnode.create(
  717. asciichar2unicode(chr(tordconstnode(left).value)),
  718. cwidechartype,true);
  719. result:=hp;
  720. end
  721. else
  722. internalerror(200105131);
  723. exit;
  724. end;
  725. end;
  726. function ttypeconvnode.resulttype_int_to_int : tnode;
  727. var
  728. v : TConstExprInt;
  729. begin
  730. result:=nil;
  731. if left.nodetype=ordconstn then
  732. begin
  733. v:=tordconstnode(left).value;
  734. if is_currency(resulttype.def) then
  735. v:=v*10000;
  736. if (resulttype.def.deftype=pointerdef) then
  737. result:=cpointerconstnode.create(TConstPtrUInt(v),resulttype)
  738. else
  739. begin
  740. if is_currency(left.resulttype.def) then
  741. v:=v div 10000;
  742. result:=cordconstnode.create(v,resulttype,false);
  743. end;
  744. end
  745. else if left.nodetype=pointerconstn then
  746. begin
  747. v:=tpointerconstnode(left).value;
  748. if (resulttype.def.deftype=pointerdef) then
  749. result:=cpointerconstnode.create(v,resulttype)
  750. else
  751. begin
  752. if is_currency(resulttype.def) then
  753. v:=v*10000;
  754. result:=cordconstnode.create(v,resulttype,false);
  755. end;
  756. end
  757. else
  758. begin
  759. { multiply by 10000 for currency. We need to use getcopy to pass
  760. the argument because the current node is always disposed. Only
  761. inserting the multiply in the left node is not possible because
  762. it'll get in an infinite loop to convert int->currency }
  763. if is_currency(resulttype.def) then
  764. begin
  765. result:=caddnode.create(muln,getcopy,cordconstnode.create(10000,resulttype,false));
  766. include(result.flags,nf_is_currency);
  767. end
  768. else if is_currency(left.resulttype.def) then
  769. begin
  770. result:=cmoddivnode.create(divn,getcopy,cordconstnode.create(10000,resulttype,false));
  771. include(result.flags,nf_is_currency);
  772. end;
  773. end;
  774. end;
  775. function ttypeconvnode.resulttype_int_to_real : tnode;
  776. var
  777. rv : bestreal;
  778. begin
  779. result:=nil;
  780. if left.nodetype=ordconstn then
  781. begin
  782. rv:=tordconstnode(left).value;
  783. if is_currency(resulttype.def) then
  784. rv:=rv*10000.0
  785. else if is_currency(left.resulttype.def) then
  786. rv:=rv/10000.0;
  787. result:=crealconstnode.create(rv,resulttype);
  788. end
  789. else
  790. begin
  791. { multiply by 10000 for currency. We need to use getcopy to pass
  792. the argument because the current node is always disposed. Only
  793. inserting the multiply in the left node is not possible because
  794. it'll get in an infinite loop to convert int->currency }
  795. if is_currency(resulttype.def) then
  796. begin
  797. result:=caddnode.create(muln,getcopy,crealconstnode.create(10000.0,resulttype));
  798. include(result.flags,nf_is_currency);
  799. end
  800. else if is_currency(left.resulttype.def) then
  801. begin
  802. result:=caddnode.create(slashn,getcopy,crealconstnode.create(10000.0,resulttype));
  803. include(result.flags,nf_is_currency);
  804. end;
  805. end;
  806. end;
  807. function ttypeconvnode.resulttype_real_to_currency : tnode;
  808. begin
  809. if not is_currency(resulttype.def) then
  810. internalerror(200304221);
  811. result:=nil;
  812. left:=caddnode.create(muln,left,crealconstnode.create(10000.0,left.resulttype));
  813. include(left.flags,nf_is_currency);
  814. resulttypepass(left);
  815. { Convert constants directly, else call Round() }
  816. if left.nodetype=realconstn then
  817. result:=cordconstnode.create(round(trealconstnode(left).value_real),resulttype,false)
  818. else
  819. result:=ccallnode.createinternres('fpc_round_real',
  820. ccallparanode.create(left,nil),resulttype);
  821. left:=nil;
  822. end;
  823. function ttypeconvnode.resulttype_real_to_real : tnode;
  824. begin
  825. result:=nil;
  826. if is_currency(left.resulttype.def) and not(is_currency(resulttype.def)) then
  827. begin
  828. left:=caddnode.create(slashn,left,crealconstnode.create(10000.0,left.resulttype));
  829. include(left.flags,nf_is_currency);
  830. resulttypepass(left);
  831. end
  832. else
  833. if is_currency(resulttype.def) and not(is_currency(left.resulttype.def)) then
  834. begin
  835. left:=caddnode.create(muln,left,crealconstnode.create(10000.0,left.resulttype));
  836. include(left.flags,nf_is_currency);
  837. resulttypepass(left);
  838. end;
  839. if left.nodetype=realconstn then
  840. result:=crealconstnode.create(trealconstnode(left).value_real,resulttype);
  841. end;
  842. function ttypeconvnode.resulttype_cchar_to_pchar : tnode;
  843. begin
  844. result:=nil;
  845. if is_pwidechar(resulttype.def) then
  846. inserttypeconv(left,cwidestringtype)
  847. else
  848. inserttypeconv(left,cshortstringtype);
  849. { evaluate again, reset resulttype so the convert_typ
  850. will be calculated again and cstring_to_pchar will
  851. be used for futher conversion }
  852. convtype:=tc_none;
  853. result:=det_resulttype;
  854. end;
  855. function ttypeconvnode.resulttype_cstring_to_pchar : tnode;
  856. begin
  857. result:=nil;
  858. if is_pwidechar(resulttype.def) then
  859. inserttypeconv(left,cwidestringtype);
  860. end;
  861. function ttypeconvnode.resulttype_arrayconstructor_to_set : tnode;
  862. var
  863. hp : tnode;
  864. begin
  865. result:=nil;
  866. if left.nodetype<>arrayconstructorn then
  867. internalerror(5546);
  868. { remove typeconv node }
  869. hp:=left;
  870. left:=nil;
  871. { create a set constructor tree }
  872. arrayconstructor_to_set(hp);
  873. result:=hp;
  874. end;
  875. function ttypeconvnode.resulttype_pchar_to_string : tnode;
  876. begin
  877. result := ccallnode.createinternres(
  878. 'fpc_pchar_to_'+tstringdef(resulttype.def).stringtypname,
  879. ccallparanode.create(left,nil),resulttype);
  880. left := nil;
  881. end;
  882. function ttypeconvnode.resulttype_interface_to_guid : tnode;
  883. begin
  884. if assigned(tobjectdef(left.resulttype.def).iidguid) then
  885. result:=cguidconstnode.create(tobjectdef(left.resulttype.def).iidguid^);
  886. end;
  887. function ttypeconvnode.resulttype_dynarray_to_openarray : tnode;
  888. begin
  889. { a dynamic array is a pointer to an array, so to convert it to }
  890. { an open array, we have to dereference it (JM) }
  891. result := ctypeconvnode.create_internal(left,voidpointertype);
  892. resulttypepass(result);
  893. { left is reused }
  894. left := nil;
  895. result := cderefnode.create(result);
  896. include(result.flags,nf_no_checkpointer);
  897. result.resulttype := resulttype;
  898. end;
  899. function ttypeconvnode.resulttype_pwchar_to_string : tnode;
  900. begin
  901. result := ccallnode.createinternres(
  902. 'fpc_pwidechar_to_'+tstringdef(resulttype.def).stringtypname,
  903. ccallparanode.create(left,nil),resulttype);
  904. left := nil;
  905. end;
  906. function ttypeconvnode.resulttype_variant_to_dynarray : tnode;
  907. begin
  908. result := ccallnode.createinternres(
  909. 'fpc_variant_to_dynarray',
  910. ccallparanode.create(caddrnode.create_internal(crttinode.create(tstoreddef(resulttype.def),initrtti)),
  911. ccallparanode.create(left,nil)
  912. ),resulttype);
  913. resulttypepass(result);
  914. left:=nil;
  915. end;
  916. function ttypeconvnode.resulttype_dynarray_to_variant : tnode;
  917. begin
  918. result := ccallnode.createinternres(
  919. 'fpc_dynarray_to_variant',
  920. ccallparanode.create(caddrnode.create_internal(crttinode.create(tstoreddef(resulttype.def),initrtti)),
  921. ccallparanode.create(ctypeconvnode.create_explicit(left,voidpointertype),nil)
  922. ),resulttype);
  923. resulttypepass(result);
  924. left:=nil;
  925. end;
  926. function ttypeconvnode.resulttype_variant_to_enum : tnode;
  927. begin
  928. result := ctypeconvnode.create_internal(left,sinttype);
  929. result := ctypeconvnode.create_internal(result,resulttype);
  930. resulttypepass(result);
  931. { left is reused }
  932. left := nil;
  933. end;
  934. function ttypeconvnode.resulttype_enum_to_variant : tnode;
  935. begin
  936. result := ctypeconvnode.create_internal(left,sinttype);
  937. result := ctypeconvnode.create_internal(result,cvarianttype);
  938. resulttypepass(result);
  939. { left is reused }
  940. left := nil;
  941. end;
  942. procedure copyparasym(p:TNamedIndexItem;arg:pointer);
  943. var
  944. newparast : tsymtable absolute arg;
  945. vs : tparavarsym;
  946. begin
  947. if tsym(p).typ<>paravarsym then
  948. exit;
  949. with tparavarsym(p) do
  950. begin
  951. vs:=tparavarsym.create(realname,paranr,varspez,vartype,varoptions);
  952. vs.defaultconstsym:=defaultconstsym;
  953. newparast.insert(vs);
  954. end;
  955. end;
  956. function ttypeconvnode.resulttype_proc_to_procvar : tnode;
  957. var
  958. pd : tabstractprocdef;
  959. begin
  960. result:=nil;
  961. pd:=tabstractprocdef(left.resulttype.def);
  962. { create procvardef }
  963. resulttype.setdef(tprocvardef.create(pd.parast.symtablelevel));
  964. tprocvardef(resulttype.def).proctypeoption:=pd.proctypeoption;
  965. tprocvardef(resulttype.def).proccalloption:=pd.proccalloption;
  966. tprocvardef(resulttype.def).procoptions:=pd.procoptions;
  967. tprocvardef(resulttype.def).rettype:=pd.rettype;
  968. { method ? then set the methodpointer flag }
  969. if (pd.owner.symtabletype=objectsymtable) then
  970. include(tprocvardef(resulttype.def).procoptions,po_methodpointer);
  971. { only need the address of the method? this is needed
  972. for @tobject.create. In this case there will be a loadn without
  973. a methodpointer. }
  974. if (left.nodetype=loadn) and
  975. not assigned(tloadnode(left).left) then
  976. include(tprocvardef(resulttype.def).procoptions,po_addressonly);
  977. { Add parameters use only references, we don't need to keep the
  978. parast. We use the parast from the original function to calculate
  979. our parameter data and reset it afterwards }
  980. pd.parast.foreach_static(@copyparasym,tprocvardef(resulttype.def).parast);
  981. tprocvardef(resulttype.def).calcparas;
  982. end;
  983. function ttypeconvnode.resulttype_call_helper(c : tconverttype) : tnode;
  984. {$ifdef fpc}
  985. const
  986. resulttypeconvert : array[tconverttype] of pointer = (
  987. {none} nil,
  988. {equal} nil,
  989. {not_possible} nil,
  990. { string_2_string } @ttypeconvnode.resulttype_string_to_string,
  991. { char_2_string } @ttypeconvnode.resulttype_char_to_string,
  992. { char_2_chararray } @ttypeconvnode.resulttype_char_to_chararray,
  993. { pchar_2_string } @ttypeconvnode.resulttype_pchar_to_string,
  994. { cchar_2_pchar } @ttypeconvnode.resulttype_cchar_to_pchar,
  995. { cstring_2_pchar } @ttypeconvnode.resulttype_cstring_to_pchar,
  996. { ansistring_2_pchar } nil,
  997. { string_2_chararray } @ttypeconvnode.resulttype_string_to_chararray,
  998. { chararray_2_string } @ttypeconvnode.resulttype_chararray_to_string,
  999. { array_2_pointer } nil,
  1000. { pointer_2_array } nil,
  1001. { int_2_int } @ttypeconvnode.resulttype_int_to_int,
  1002. { int_2_bool } nil,
  1003. { bool_2_bool } nil,
  1004. { bool_2_int } nil,
  1005. { real_2_real } @ttypeconvnode.resulttype_real_to_real,
  1006. { int_2_real } @ttypeconvnode.resulttype_int_to_real,
  1007. { real_2_currency } @ttypeconvnode.resulttype_real_to_currency,
  1008. { proc_2_procvar } @ttypeconvnode.resulttype_proc_to_procvar,
  1009. { arrayconstructor_2_set } @ttypeconvnode.resulttype_arrayconstructor_to_set,
  1010. { load_smallset } nil,
  1011. { cord_2_pointer } @ttypeconvnode.resulttype_cord_to_pointer,
  1012. { intf_2_string } nil,
  1013. { intf_2_guid } @ttypeconvnode.resulttype_interface_to_guid,
  1014. { class_2_intf } nil,
  1015. { char_2_char } @ttypeconvnode.resulttype_char_to_char,
  1016. { normal_2_smallset} nil,
  1017. { dynarray_2_openarray} @ttypeconvnode.resulttype_dynarray_to_openarray,
  1018. { pwchar_2_string} @ttypeconvnode.resulttype_pwchar_to_string,
  1019. { variant_2_dynarray} @ttypeconvnode.resulttype_variant_to_dynarray,
  1020. { dynarray_2_variant} @ttypeconvnode.resulttype_dynarray_to_variant,
  1021. { variant_2_enum} @ttypeconvnode.resulttype_variant_to_enum,
  1022. { enum_2_variant} @ttypeconvnode.resulttype_enum_to_variant
  1023. );
  1024. type
  1025. tprocedureofobject = function : tnode of object;
  1026. var
  1027. r : packed record
  1028. proc : pointer;
  1029. obj : pointer;
  1030. end;
  1031. begin
  1032. result:=nil;
  1033. { this is a little bit dirty but it works }
  1034. { and should be quite portable too }
  1035. r.proc:=resulttypeconvert[c];
  1036. r.obj:=self;
  1037. if assigned(r.proc) then
  1038. result:=tprocedureofobject(r)();
  1039. end;
  1040. {$else}
  1041. begin
  1042. case c of
  1043. tc_string_2_string: resulttype_string_to_string;
  1044. tc_char_2_string : resulttype_char_to_string;
  1045. tc_char_2_chararray: resulttype_char_to_chararray;
  1046. tc_pchar_2_string : resulttype_pchar_to_string;
  1047. tc_cchar_2_pchar : resulttype_cchar_to_pchar;
  1048. tc_cstring_2_pchar : resulttype_cstring_to_pchar;
  1049. tc_string_2_chararray : resulttype_string_to_chararray;
  1050. tc_chararray_2_string : resulttype_chararray_to_string;
  1051. tc_real_2_real : resulttype_real_to_real;
  1052. tc_int_2_real : resulttype_int_to_real;
  1053. tc_real_2_currency : resulttype_real_to_currency;
  1054. tc_arrayconstructor_2_set : resulttype_arrayconstructor_to_set;
  1055. tc_cord_2_pointer : resulttype_cord_to_pointer;
  1056. tc_intf_2_guid : resulttype_interface_to_guid;
  1057. tc_char_2_char : resulttype_char_to_char;
  1058. tc_dynarray_2_openarray : resulttype_dynarray_to_openarray;
  1059. tc_pwchar_2_string : resulttype_pwchar_to_string;
  1060. tc_variant_2_dynarray : resulttype_variant_to_dynarray;
  1061. tc_dynarray_2_variant : resulttype_dynarray_to_variant;
  1062. end;
  1063. end;
  1064. {$Endif fpc}
  1065. function ttypeconvnode.det_resulttype:tnode;
  1066. var
  1067. htype : ttype;
  1068. hp : tnode;
  1069. currprocdef : tabstractprocdef;
  1070. aprocdef : tprocdef;
  1071. eq : tequaltype;
  1072. cdoptions : tcompare_defs_options;
  1073. begin
  1074. result:=nil;
  1075. resulttype:=totype;
  1076. resulttypepass(left);
  1077. if codegenerror then
  1078. exit;
  1079. { When absolute force tc_equal }
  1080. if (nf_absolute in flags) then
  1081. begin
  1082. convtype:=tc_equal;
  1083. if not(tstoreddef(resulttype.def).is_intregable) and
  1084. not(tstoreddef(resulttype.def).is_fpuregable) then
  1085. make_not_regable(left);
  1086. exit;
  1087. end;
  1088. { tp procvar support. Skip typecasts to procvar, record or set. Those
  1089. convert on the procvar value. This is used to access the
  1090. fields of a methodpointer }
  1091. if not(nf_load_procvar in flags) and
  1092. not(resulttype.def.deftype in [procvardef,recorddef,setdef]) then
  1093. maybe_call_procvar(left,true);
  1094. { convert array constructors to sets, because there is no conversion
  1095. possible for array constructors }
  1096. if (resulttype.def.deftype<>arraydef) and
  1097. is_array_constructor(left.resulttype.def) then
  1098. begin
  1099. arrayconstructor_to_set(left);
  1100. resulttypepass(left);
  1101. end;
  1102. if convtype=tc_none then
  1103. begin
  1104. cdoptions:=[cdo_check_operator,cdo_allow_variant];
  1105. if nf_explicit in flags then
  1106. include(cdoptions,cdo_explicit);
  1107. if nf_internal in flags then
  1108. include(cdoptions,cdo_internal);
  1109. eq:=compare_defs_ext(left.resulttype.def,resulttype.def,left.nodetype,convtype,aprocdef,cdoptions);
  1110. case eq of
  1111. te_exact,
  1112. te_equal :
  1113. begin
  1114. { because is_equal only checks the basetype for sets we need to
  1115. check here if we are loading a smallset into a normalset }
  1116. if (resulttype.def.deftype=setdef) and
  1117. (left.resulttype.def.deftype=setdef) and
  1118. ((tsetdef(resulttype.def).settype = smallset) xor
  1119. (tsetdef(left.resulttype.def).settype = smallset)) then
  1120. begin
  1121. { constant sets can be converted by changing the type only }
  1122. if (left.nodetype=setconstn) then
  1123. begin
  1124. left.resulttype:=resulttype;
  1125. result:=left;
  1126. left:=nil;
  1127. exit;
  1128. end;
  1129. if (tsetdef(resulttype.def).settype <> smallset) then
  1130. convtype:=tc_load_smallset
  1131. else
  1132. convtype := tc_normal_2_smallset;
  1133. exit;
  1134. end
  1135. else
  1136. begin
  1137. { Only leave when there is no conversion to do.
  1138. We can still need to call a conversion routine,
  1139. like the routine to convert a stringconstnode }
  1140. if convtype in [tc_equal,tc_not_possible] then
  1141. begin
  1142. left.resulttype:=resulttype;
  1143. result:=left;
  1144. left:=nil;
  1145. exit;
  1146. end;
  1147. end;
  1148. end;
  1149. te_convert_l1,
  1150. te_convert_l2,
  1151. te_convert_l3 :
  1152. begin
  1153. { nothing to do }
  1154. end;
  1155. te_convert_operator :
  1156. begin
  1157. include(current_procinfo.flags,pi_do_call);
  1158. inc(aprocdef.procsym.refs);
  1159. hp:=ccallnode.create(ccallparanode.create(left,nil),Tprocsym(aprocdef.procsym),nil,nil,[]);
  1160. { tell explicitly which def we must use !! (PM) }
  1161. tcallnode(hp).procdefinition:=aprocdef;
  1162. left:=nil;
  1163. result:=hp;
  1164. exit;
  1165. end;
  1166. te_incompatible :
  1167. begin
  1168. { Procedures have a resulttype.def of voiddef and functions of their
  1169. own resulttype.def. They will therefore always be incompatible with
  1170. a procvar. Because isconvertable cannot check for procedures we
  1171. use an extra check for them.}
  1172. if (m_tp_procvar in aktmodeswitches) and
  1173. (resulttype.def.deftype=procvardef) then
  1174. begin
  1175. if (left.nodetype=calln) and
  1176. (tcallnode(left).para_count=0) then
  1177. begin
  1178. if assigned(tcallnode(left).right) then
  1179. begin
  1180. { this is already a procvar, if it is really equal
  1181. is checked below }
  1182. convtype:=tc_equal;
  1183. hp:=tcallnode(left).right.getcopy;
  1184. currprocdef:=tabstractprocdef(hp.resulttype.def);
  1185. end
  1186. else
  1187. begin
  1188. convtype:=tc_proc_2_procvar;
  1189. currprocdef:=Tprocsym(Tcallnode(left).symtableprocentry).search_procdef_byprocvardef(Tprocvardef(resulttype.def));
  1190. hp:=cloadnode.create_procvar(tprocsym(tcallnode(left).symtableprocentry),
  1191. tprocdef(currprocdef),tcallnode(left).symtableproc);
  1192. if (tcallnode(left).symtableprocentry.owner.symtabletype=objectsymtable) then
  1193. begin
  1194. if assigned(tcallnode(left).methodpointer) then
  1195. begin
  1196. { Under certain circumstances the methodpointer is a loadvmtaddrn
  1197. which isn't possible if it is used as a method pointer, so
  1198. fix this.
  1199. If you change this, ensure that tests/tbs/tw2669.pp still works }
  1200. if tcallnode(left).methodpointer.nodetype=loadvmtaddrn then
  1201. tloadnode(hp).set_mp(tloadvmtaddrnode(tcallnode(left).methodpointer).left.getcopy)
  1202. else
  1203. tloadnode(hp).set_mp(tcallnode(left).methodpointer.getcopy);
  1204. end
  1205. else
  1206. tloadnode(hp).set_mp(load_self_node);
  1207. end;
  1208. resulttypepass(hp);
  1209. end;
  1210. left.free;
  1211. left:=hp;
  1212. { Now check if the procedure we are going to assign to
  1213. the procvar, is compatible with the procvar's type }
  1214. if not(nf_explicit in flags) and
  1215. (proc_to_procvar_equal(currprocdef,
  1216. tprocvardef(resulttype.def),true)=te_incompatible) then
  1217. IncompatibleTypes(left.resulttype.def,resulttype.def);
  1218. exit;
  1219. end;
  1220. end;
  1221. { Handle explicit type conversions }
  1222. if nf_explicit in flags then
  1223. begin
  1224. { do common tc_equal cast }
  1225. convtype:=tc_equal;
  1226. { ordinal constants can be resized to 1,2,4,8 bytes }
  1227. if (left.nodetype=ordconstn) then
  1228. begin
  1229. { Insert typeconv for ordinal to the correct size first on left, after
  1230. that the other conversion can be done }
  1231. htype.reset;
  1232. case longint(resulttype.def.size) of
  1233. 1 :
  1234. htype:=s8inttype;
  1235. 2 :
  1236. htype:=s16inttype;
  1237. 4 :
  1238. htype:=s32inttype;
  1239. 8 :
  1240. htype:=s64inttype;
  1241. end;
  1242. { we need explicit, because it can also be an enum }
  1243. if assigned(htype.def) then
  1244. inserttypeconv_internal(left,htype)
  1245. else
  1246. CGMessage2(type_e_illegal_type_conversion,left.resulttype.def.gettypename,resulttype.def.gettypename);
  1247. end;
  1248. { check if the result could be in a register }
  1249. if (not(tstoreddef(resulttype.def).is_intregable) and
  1250. not(tstoreddef(resulttype.def).is_fpuregable)) or
  1251. ((left.resulttype.def.deftype = floatdef) and
  1252. (resulttype.def.deftype <> floatdef)) then
  1253. make_not_regable(left);
  1254. { class to class or object to object, with checkobject support }
  1255. if (resulttype.def.deftype=objectdef) and
  1256. (left.resulttype.def.deftype=objectdef) then
  1257. begin
  1258. if (cs_check_object in aktlocalswitches) then
  1259. begin
  1260. if is_class_or_interface(resulttype.def) then
  1261. begin
  1262. { we can translate the typeconvnode to 'as' when
  1263. typecasting to a class or interface }
  1264. hp:=casnode.create(left,cloadvmtaddrnode.create(ctypenode.create(resulttype)));
  1265. left:=nil;
  1266. result:=hp;
  1267. exit;
  1268. end;
  1269. end
  1270. else
  1271. begin
  1272. { check if the types are related }
  1273. if not(nf_internal in flags) and
  1274. (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(resulttype.def)))) and
  1275. (not(tobjectdef(resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1276. begin
  1277. { Give an error when typecasting class to interface, this is compatible
  1278. with delphi }
  1279. if is_interface(resulttype.def) and
  1280. not is_interface(left.resulttype.def) then
  1281. CGMessage2(type_e_classes_not_related,
  1282. FullTypeName(left.resulttype.def,resulttype.def),
  1283. FullTypeName(resulttype.def,left.resulttype.def))
  1284. else
  1285. CGMessage2(type_w_classes_not_related,
  1286. FullTypeName(left.resulttype.def,resulttype.def),
  1287. FullTypeName(resulttype.def,left.resulttype.def))
  1288. end;
  1289. end;
  1290. end
  1291. else
  1292. begin
  1293. { only if the same size or formal def }
  1294. if not(
  1295. (left.resulttype.def.deftype=formaldef) or
  1296. (
  1297. not(is_open_array(left.resulttype.def)) and
  1298. (left.resulttype.def.size=resulttype.def.size)
  1299. ) or
  1300. (
  1301. is_void(left.resulttype.def) and
  1302. (left.nodetype=derefn)
  1303. )
  1304. ) then
  1305. CGMessage2(type_e_illegal_type_conversion,left.resulttype.def.gettypename,resulttype.def.gettypename);
  1306. end;
  1307. end
  1308. else
  1309. IncompatibleTypes(left.resulttype.def,resulttype.def);
  1310. end;
  1311. else
  1312. internalerror(200211231);
  1313. end;
  1314. end;
  1315. { Give hint or warning for unportable code, exceptions are
  1316. - typecasts from constants
  1317. - void }
  1318. if not(nf_internal in flags) and
  1319. (left.nodetype<>ordconstn) and
  1320. not(is_void(left.resulttype.def)) and
  1321. (((left.resulttype.def.deftype=orddef) and
  1322. (resulttype.def.deftype in [pointerdef,procvardef,classrefdef])) or
  1323. ((resulttype.def.deftype=orddef) and
  1324. (left.resulttype.def.deftype in [pointerdef,procvardef,classrefdef]))) then
  1325. begin
  1326. { Give a warning when sizes don't match, because then info will be lost }
  1327. if left.resulttype.def.size=resulttype.def.size then
  1328. CGMessage(type_h_pointer_to_longint_conv_not_portable)
  1329. else
  1330. CGMessage(type_w_pointer_to_longint_conv_not_portable);
  1331. end;
  1332. { Constant folding and other node transitions to
  1333. remove the typeconv node }
  1334. case left.nodetype of
  1335. niln :
  1336. begin
  1337. { nil to ordinal node }
  1338. if (resulttype.def.deftype=orddef) then
  1339. begin
  1340. hp:=cordconstnode.create(0,resulttype,true);
  1341. result:=hp;
  1342. exit;
  1343. end
  1344. else
  1345. { fold nil to any pointer type }
  1346. if (resulttype.def.deftype=pointerdef) then
  1347. begin
  1348. hp:=cnilnode.create;
  1349. hp.resulttype:=resulttype;
  1350. result:=hp;
  1351. exit;
  1352. end
  1353. else
  1354. { remove typeconv after niln, but not when the result is a
  1355. methodpointer. The typeconv of the methodpointer will then
  1356. take care of updateing size of niln to OS_64 }
  1357. if not((resulttype.def.deftype=procvardef) and
  1358. (po_methodpointer in tprocvardef(resulttype.def).procoptions)) then
  1359. begin
  1360. left.resulttype:=resulttype;
  1361. result:=left;
  1362. left:=nil;
  1363. exit;
  1364. end;
  1365. end;
  1366. ordconstn :
  1367. begin
  1368. { ordinal contants can be directly converted }
  1369. { but not char to char because it is a widechar to char or via versa }
  1370. { which needs extra code to do the code page transistion }
  1371. { constant ordinal to pointer }
  1372. if (resulttype.def.deftype=pointerdef) and
  1373. (convtype<>tc_cchar_2_pchar) then
  1374. begin
  1375. hp:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value),resulttype);
  1376. result:=hp;
  1377. exit;
  1378. end
  1379. else if is_ordinal(resulttype.def) and
  1380. not(convtype=tc_char_2_char) then
  1381. begin
  1382. { replace the resulttype and recheck the range }
  1383. left.resulttype:=resulttype;
  1384. testrange(left.resulttype.def,tordconstnode(left).value,(nf_explicit in flags));
  1385. result:=left;
  1386. left:=nil;
  1387. exit;
  1388. end;
  1389. end;
  1390. pointerconstn :
  1391. begin
  1392. { pointerconstn to any pointer is folded too }
  1393. if (resulttype.def.deftype=pointerdef) then
  1394. begin
  1395. left.resulttype:=resulttype;
  1396. result:=left;
  1397. left:=nil;
  1398. exit;
  1399. end
  1400. { constant pointer to ordinal }
  1401. else if is_ordinal(resulttype.def) then
  1402. begin
  1403. hp:=cordconstnode.create(TConstExprInt(tpointerconstnode(left).value),
  1404. resulttype,true);
  1405. result:=hp;
  1406. exit;
  1407. end;
  1408. end;
  1409. end;
  1410. { check if the result could be in a register }
  1411. if not(tstoreddef(resulttype.def).is_intregable) and
  1412. not(tstoreddef(resulttype.def).is_fpuregable) then
  1413. make_not_regable(left);
  1414. { now call the resulttype helper to do constant folding }
  1415. result:=resulttype_call_helper(convtype);
  1416. end;
  1417. procedure Ttypeconvnode.mark_write;
  1418. begin
  1419. left.mark_write;
  1420. end;
  1421. function ttypeconvnode.first_cord_to_pointer : tnode;
  1422. begin
  1423. result:=nil;
  1424. internalerror(200104043);
  1425. end;
  1426. function ttypeconvnode.first_int_to_int : tnode;
  1427. begin
  1428. first_int_to_int:=nil;
  1429. expectloc:=left.expectloc;
  1430. if not is_void(left.resulttype.def) then
  1431. begin
  1432. if (left.expectloc<>LOC_REGISTER) and
  1433. (resulttype.def.size>left.resulttype.def.size) then
  1434. expectloc:=LOC_REGISTER
  1435. else
  1436. if (left.expectloc=LOC_CREGISTER) and
  1437. (resulttype.def.size<left.resulttype.def.size) then
  1438. expectloc:=LOC_REGISTER;
  1439. end;
  1440. {$ifndef cpu64bit}
  1441. if is_64bit(resulttype.def) then
  1442. registersint:=max(registersint,2)
  1443. else
  1444. {$endif cpu64bit}
  1445. registersint:=max(registersint,1);
  1446. end;
  1447. function ttypeconvnode.first_cstring_to_pchar : tnode;
  1448. begin
  1449. first_cstring_to_pchar:=nil;
  1450. registersint:=1;
  1451. expectloc:=LOC_REGISTER;
  1452. end;
  1453. function ttypeconvnode.first_string_to_chararray : tnode;
  1454. begin
  1455. first_string_to_chararray:=nil;
  1456. expectloc:=left.expectloc;
  1457. end;
  1458. function ttypeconvnode.first_char_to_string : tnode;
  1459. begin
  1460. first_char_to_string:=nil;
  1461. expectloc:=LOC_REFERENCE;
  1462. end;
  1463. function ttypeconvnode.first_nothing : tnode;
  1464. begin
  1465. first_nothing:=nil;
  1466. end;
  1467. function ttypeconvnode.first_array_to_pointer : tnode;
  1468. begin
  1469. first_array_to_pointer:=nil;
  1470. if registersint<1 then
  1471. registersint:=1;
  1472. expectloc:=LOC_REGISTER;
  1473. end;
  1474. function ttypeconvnode.first_int_to_real: tnode;
  1475. var
  1476. fname: string[32];
  1477. typname : string[12];
  1478. begin
  1479. { Get the type name }
  1480. { Normally the typename should be one of the following:
  1481. single, double - carl
  1482. }
  1483. typname := lower(pbestrealtype^.def.gettypename);
  1484. { converting a 64bit integer to a float requires a helper }
  1485. if is_64bit(left.resulttype.def) then
  1486. begin
  1487. if is_signed(left.resulttype.def) then
  1488. fname := 'fpc_int64_to_'+typname
  1489. else
  1490. {$warning generic conversion from int to float does not support unsigned integers}
  1491. fname := 'fpc_int64_to_'+typname;
  1492. result := ccallnode.createintern(fname,ccallparanode.create(
  1493. left,nil));
  1494. left:=nil;
  1495. firstpass(result);
  1496. exit;
  1497. end
  1498. else
  1499. { other integers are supposed to be 32 bit }
  1500. begin
  1501. {$warning generic conversion from int to float does not support unsigned integers}
  1502. if is_signed(left.resulttype.def) then
  1503. fname := 'fpc_longint_to_'+typname
  1504. else
  1505. fname := 'fpc_longint_to_'+typname;
  1506. result := ccallnode.createintern(fname,ccallparanode.create(
  1507. left,nil));
  1508. left:=nil;
  1509. firstpass(result);
  1510. exit;
  1511. end;
  1512. end;
  1513. function ttypeconvnode.first_real_to_real : tnode;
  1514. begin
  1515. first_real_to_real:=nil;
  1516. { comp isn't a floating type }
  1517. if registersfpu<1 then
  1518. registersfpu:=1;
  1519. expectloc:=LOC_FPUREGISTER;
  1520. end;
  1521. function ttypeconvnode.first_pointer_to_array : tnode;
  1522. begin
  1523. first_pointer_to_array:=nil;
  1524. if registersint<1 then
  1525. registersint:=1;
  1526. expectloc:=LOC_REFERENCE;
  1527. end;
  1528. function ttypeconvnode.first_cchar_to_pchar : tnode;
  1529. begin
  1530. first_cchar_to_pchar:=nil;
  1531. internalerror(200104021);
  1532. end;
  1533. function ttypeconvnode.first_bool_to_int : tnode;
  1534. begin
  1535. first_bool_to_int:=nil;
  1536. { byte(boolean) or word(wordbool) or longint(longbool) must
  1537. be accepted for var parameters }
  1538. if (nf_explicit in flags) and
  1539. (left.resulttype.def.size=resulttype.def.size) and
  1540. (left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1541. exit;
  1542. { when converting to 64bit, first convert to a 32bit int and then }
  1543. { convert to a 64bit int (only necessary for 32bit processors) (JM) }
  1544. if resulttype.def.size > sizeof(aint) then
  1545. begin
  1546. result := ctypeconvnode.create_internal(left,u32inttype);
  1547. result := ctypeconvnode.create(result,resulttype);
  1548. left := nil;
  1549. firstpass(result);
  1550. exit;
  1551. end;
  1552. expectloc:=LOC_REGISTER;
  1553. if registersint<1 then
  1554. registersint:=1;
  1555. end;
  1556. function ttypeconvnode.first_int_to_bool : tnode;
  1557. begin
  1558. first_int_to_bool:=nil;
  1559. { byte(boolean) or word(wordbool) or longint(longbool) must
  1560. be accepted for var parameters }
  1561. if (nf_explicit in flags) and
  1562. (left.resulttype.def.size=resulttype.def.size) and
  1563. (left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1564. exit;
  1565. expectloc:=LOC_REGISTER;
  1566. { need if bool to bool !!
  1567. not very nice !!
  1568. insertypeconv(left,s32inttype);
  1569. left.explizit:=true;
  1570. firstpass(left); }
  1571. if registersint<1 then
  1572. registersint:=1;
  1573. end;
  1574. function ttypeconvnode.first_bool_to_bool : tnode;
  1575. begin
  1576. first_bool_to_bool:=nil;
  1577. expectloc:=LOC_REGISTER;
  1578. if registersint<1 then
  1579. registersint:=1;
  1580. end;
  1581. function ttypeconvnode.first_char_to_char : tnode;
  1582. begin
  1583. first_char_to_char:=first_int_to_int;
  1584. end;
  1585. function ttypeconvnode.first_proc_to_procvar : tnode;
  1586. begin
  1587. first_proc_to_procvar:=nil;
  1588. if tabstractprocdef(resulttype.def).is_addressonly then
  1589. begin
  1590. registersint:=left.registersint;
  1591. if registersint<1 then
  1592. registersint:=1;
  1593. expectloc:=LOC_REGISTER;
  1594. end
  1595. else
  1596. begin
  1597. if not(left.expectloc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  1598. CGMessage(parser_e_illegal_expression);
  1599. registersint:=left.registersint;
  1600. expectloc:=left.expectloc
  1601. end
  1602. end;
  1603. function ttypeconvnode.first_load_smallset : tnode;
  1604. var
  1605. srsym: ttypesym;
  1606. p: tcallparanode;
  1607. begin
  1608. if not searchsystype('FPC_SMALL_SET',srsym) then
  1609. internalerror(200108313);
  1610. p := ccallparanode.create(left,nil);
  1611. { reused }
  1612. left := nil;
  1613. { convert parameter explicitely to fpc_small_set }
  1614. p.left := ctypeconvnode.create_internal(p.left,srsym.restype);
  1615. { create call, adjust resulttype }
  1616. result :=
  1617. ccallnode.createinternres('fpc_set_load_small',p,resulttype);
  1618. firstpass(result);
  1619. end;
  1620. function ttypeconvnode.first_ansistring_to_pchar : tnode;
  1621. begin
  1622. first_ansistring_to_pchar:=nil;
  1623. expectloc:=LOC_REGISTER;
  1624. if registersint<1 then
  1625. registersint:=1;
  1626. end;
  1627. function ttypeconvnode.first_arrayconstructor_to_set : tnode;
  1628. begin
  1629. first_arrayconstructor_to_set:=nil;
  1630. internalerror(200104022);
  1631. end;
  1632. function ttypeconvnode.first_class_to_intf : tnode;
  1633. begin
  1634. first_class_to_intf:=nil;
  1635. expectloc:=LOC_REGISTER;
  1636. if registersint<1 then
  1637. registersint:=1;
  1638. end;
  1639. function ttypeconvnode._first_int_to_int : tnode;
  1640. begin
  1641. result:=first_int_to_int;
  1642. end;
  1643. function ttypeconvnode._first_cstring_to_pchar : tnode;
  1644. begin
  1645. result:=first_cstring_to_pchar;
  1646. end;
  1647. function ttypeconvnode._first_string_to_chararray : tnode;
  1648. begin
  1649. result:=first_string_to_chararray;
  1650. end;
  1651. function ttypeconvnode._first_char_to_string : tnode;
  1652. begin
  1653. result:=first_char_to_string;
  1654. end;
  1655. function ttypeconvnode._first_nothing : tnode;
  1656. begin
  1657. result:=first_nothing;
  1658. end;
  1659. function ttypeconvnode._first_array_to_pointer : tnode;
  1660. begin
  1661. result:=first_array_to_pointer;
  1662. end;
  1663. function ttypeconvnode._first_int_to_real : tnode;
  1664. begin
  1665. result:=first_int_to_real;
  1666. end;
  1667. function ttypeconvnode._first_real_to_real : tnode;
  1668. begin
  1669. result:=first_real_to_real;
  1670. end;
  1671. function ttypeconvnode._first_pointer_to_array : tnode;
  1672. begin
  1673. result:=first_pointer_to_array;
  1674. end;
  1675. function ttypeconvnode._first_cchar_to_pchar : tnode;
  1676. begin
  1677. result:=first_cchar_to_pchar;
  1678. end;
  1679. function ttypeconvnode._first_bool_to_int : tnode;
  1680. begin
  1681. result:=first_bool_to_int;
  1682. end;
  1683. function ttypeconvnode._first_int_to_bool : tnode;
  1684. begin
  1685. result:=first_int_to_bool;
  1686. end;
  1687. function ttypeconvnode._first_bool_to_bool : tnode;
  1688. begin
  1689. result:=first_bool_to_bool;
  1690. end;
  1691. function ttypeconvnode._first_proc_to_procvar : tnode;
  1692. begin
  1693. result:=first_proc_to_procvar;
  1694. end;
  1695. function ttypeconvnode._first_load_smallset : tnode;
  1696. begin
  1697. result:=first_load_smallset;
  1698. end;
  1699. function ttypeconvnode._first_cord_to_pointer : tnode;
  1700. begin
  1701. result:=first_cord_to_pointer;
  1702. end;
  1703. function ttypeconvnode._first_ansistring_to_pchar : tnode;
  1704. begin
  1705. result:=first_ansistring_to_pchar;
  1706. end;
  1707. function ttypeconvnode._first_arrayconstructor_to_set : tnode;
  1708. begin
  1709. result:=first_arrayconstructor_to_set;
  1710. end;
  1711. function ttypeconvnode._first_class_to_intf : tnode;
  1712. begin
  1713. result:=first_class_to_intf;
  1714. end;
  1715. function ttypeconvnode._first_char_to_char : tnode;
  1716. begin
  1717. result:=first_char_to_char;
  1718. end;
  1719. function ttypeconvnode.first_call_helper(c : tconverttype) : tnode;
  1720. const
  1721. firstconvert : array[tconverttype] of pointer = (
  1722. nil, { none }
  1723. @ttypeconvnode._first_nothing, {equal}
  1724. @ttypeconvnode._first_nothing, {not_possible}
  1725. nil, { removed in resulttype_string_to_string }
  1726. @ttypeconvnode._first_char_to_string,
  1727. @ttypeconvnode._first_nothing, { char_2_chararray, needs nothing extra }
  1728. nil, { removed in resulttype_chararray_to_string }
  1729. @ttypeconvnode._first_cchar_to_pchar,
  1730. @ttypeconvnode._first_cstring_to_pchar,
  1731. @ttypeconvnode._first_ansistring_to_pchar,
  1732. @ttypeconvnode._first_string_to_chararray,
  1733. nil, { removed in resulttype_chararray_to_string }
  1734. @ttypeconvnode._first_array_to_pointer,
  1735. @ttypeconvnode._first_pointer_to_array,
  1736. @ttypeconvnode._first_int_to_int,
  1737. @ttypeconvnode._first_int_to_bool,
  1738. @ttypeconvnode._first_bool_to_bool,
  1739. @ttypeconvnode._first_bool_to_int,
  1740. @ttypeconvnode._first_real_to_real,
  1741. @ttypeconvnode._first_int_to_real,
  1742. nil, { removed in resulttype_real_to_currency }
  1743. @ttypeconvnode._first_proc_to_procvar,
  1744. @ttypeconvnode._first_arrayconstructor_to_set,
  1745. @ttypeconvnode._first_load_smallset,
  1746. @ttypeconvnode._first_cord_to_pointer,
  1747. @ttypeconvnode._first_nothing,
  1748. @ttypeconvnode._first_nothing,
  1749. @ttypeconvnode._first_class_to_intf,
  1750. @ttypeconvnode._first_char_to_char,
  1751. @ttypeconvnode._first_nothing,
  1752. @ttypeconvnode._first_nothing,
  1753. nil,
  1754. nil,
  1755. nil,
  1756. nil,
  1757. nil
  1758. );
  1759. type
  1760. tprocedureofobject = function : tnode of object;
  1761. var
  1762. r : packed record
  1763. proc : pointer;
  1764. obj : pointer;
  1765. end;
  1766. begin
  1767. { this is a little bit dirty but it works }
  1768. { and should be quite portable too }
  1769. r.proc:=firstconvert[c];
  1770. r.obj:=self;
  1771. if not assigned(r.proc) then
  1772. internalerror(200312081);
  1773. first_call_helper:=tprocedureofobject(r){$ifdef FPC}(){$endif FPC}
  1774. end;
  1775. function ttypeconvnode.pass_1 : tnode;
  1776. begin
  1777. result:=nil;
  1778. firstpass(left);
  1779. if codegenerror then
  1780. exit;
  1781. { load the value_str from the left part }
  1782. registersint:=left.registersint;
  1783. registersfpu:=left.registersfpu;
  1784. {$ifdef SUPPORT_MMX}
  1785. registersmmx:=left.registersmmx;
  1786. {$endif}
  1787. expectloc:=left.expectloc;
  1788. result:=first_call_helper(convtype);
  1789. end;
  1790. function ttypeconvnode.assign_allowed:boolean;
  1791. begin
  1792. result:=(convtype=tc_equal) or
  1793. { typecasting from void is always allowed }
  1794. is_void(left.resulttype.def) or
  1795. (left.resulttype.def.deftype=formaldef) or
  1796. { int 2 int with same size reuses same location, or for
  1797. tp7 mode also allow size < orignal size }
  1798. (
  1799. (convtype=tc_int_2_int) and
  1800. (
  1801. (resulttype.def.size=left.resulttype.def.size) or
  1802. ((m_tp7 in aktmodeswitches) and
  1803. (resulttype.def.size<left.resulttype.def.size))
  1804. )
  1805. ) or
  1806. { int 2 bool/bool 2 int, explicit typecast, see also nx86cnv }
  1807. ((convtype in [tc_int_2_bool,tc_bool_2_int]) and
  1808. (nf_explicit in flags) and
  1809. (resulttype.def.size=left.resulttype.def.size));
  1810. { When using only a part of the value it can't be in a register since
  1811. that will load the value in a new register first }
  1812. if (resulttype.def.size<left.resulttype.def.size) then
  1813. make_not_regable(left);
  1814. end;
  1815. function ttypeconvnode.docompare(p: tnode) : boolean;
  1816. begin
  1817. docompare :=
  1818. inherited docompare(p) and
  1819. (convtype = ttypeconvnode(p).convtype);
  1820. end;
  1821. procedure ttypeconvnode._second_int_to_int;
  1822. begin
  1823. second_int_to_int;
  1824. end;
  1825. procedure ttypeconvnode._second_string_to_string;
  1826. begin
  1827. second_string_to_string;
  1828. end;
  1829. procedure ttypeconvnode._second_cstring_to_pchar;
  1830. begin
  1831. second_cstring_to_pchar;
  1832. end;
  1833. procedure ttypeconvnode._second_string_to_chararray;
  1834. begin
  1835. second_string_to_chararray;
  1836. end;
  1837. procedure ttypeconvnode._second_array_to_pointer;
  1838. begin
  1839. second_array_to_pointer;
  1840. end;
  1841. procedure ttypeconvnode._second_pointer_to_array;
  1842. begin
  1843. second_pointer_to_array;
  1844. end;
  1845. procedure ttypeconvnode._second_chararray_to_string;
  1846. begin
  1847. second_chararray_to_string;
  1848. end;
  1849. procedure ttypeconvnode._second_char_to_string;
  1850. begin
  1851. second_char_to_string;
  1852. end;
  1853. procedure ttypeconvnode._second_int_to_real;
  1854. begin
  1855. second_int_to_real;
  1856. end;
  1857. procedure ttypeconvnode._second_real_to_real;
  1858. begin
  1859. second_real_to_real;
  1860. end;
  1861. procedure ttypeconvnode._second_cord_to_pointer;
  1862. begin
  1863. second_cord_to_pointer;
  1864. end;
  1865. procedure ttypeconvnode._second_proc_to_procvar;
  1866. begin
  1867. second_proc_to_procvar;
  1868. end;
  1869. procedure ttypeconvnode._second_bool_to_int;
  1870. begin
  1871. second_bool_to_int;
  1872. end;
  1873. procedure ttypeconvnode._second_int_to_bool;
  1874. begin
  1875. second_int_to_bool;
  1876. end;
  1877. procedure ttypeconvnode._second_bool_to_bool;
  1878. begin
  1879. second_bool_to_bool;
  1880. end;
  1881. procedure ttypeconvnode._second_load_smallset;
  1882. begin
  1883. second_load_smallset;
  1884. end;
  1885. procedure ttypeconvnode._second_ansistring_to_pchar;
  1886. begin
  1887. second_ansistring_to_pchar;
  1888. end;
  1889. procedure ttypeconvnode._second_class_to_intf;
  1890. begin
  1891. second_class_to_intf;
  1892. end;
  1893. procedure ttypeconvnode._second_char_to_char;
  1894. begin
  1895. second_char_to_char;
  1896. end;
  1897. procedure ttypeconvnode._second_nothing;
  1898. begin
  1899. second_nothing;
  1900. end;
  1901. procedure ttypeconvnode.second_call_helper(c : tconverttype);
  1902. const
  1903. secondconvert : array[tconverttype] of pointer = (
  1904. @ttypeconvnode._second_nothing, {none}
  1905. @ttypeconvnode._second_nothing, {equal}
  1906. @ttypeconvnode._second_nothing, {not_possible}
  1907. @ttypeconvnode._second_nothing, {second_string_to_string, handled in resulttype pass }
  1908. @ttypeconvnode._second_char_to_string,
  1909. @ttypeconvnode._second_nothing, {char_to_charray}
  1910. @ttypeconvnode._second_nothing, { pchar_to_string, handled in resulttype pass }
  1911. @ttypeconvnode._second_nothing, {cchar_to_pchar}
  1912. @ttypeconvnode._second_cstring_to_pchar,
  1913. @ttypeconvnode._second_ansistring_to_pchar,
  1914. @ttypeconvnode._second_string_to_chararray,
  1915. @ttypeconvnode._second_nothing, { chararray_to_string, handled in resulttype pass }
  1916. @ttypeconvnode._second_array_to_pointer,
  1917. @ttypeconvnode._second_pointer_to_array,
  1918. @ttypeconvnode._second_int_to_int,
  1919. @ttypeconvnode._second_int_to_bool,
  1920. @ttypeconvnode._second_bool_to_bool,
  1921. @ttypeconvnode._second_bool_to_int,
  1922. @ttypeconvnode._second_real_to_real,
  1923. @ttypeconvnode._second_int_to_real,
  1924. @ttypeconvnode._second_nothing, { real_to_currency, handled in resulttype pass }
  1925. @ttypeconvnode._second_proc_to_procvar,
  1926. @ttypeconvnode._second_nothing, { arrayconstructor_to_set }
  1927. @ttypeconvnode._second_nothing, { second_load_smallset, handled in first pass }
  1928. @ttypeconvnode._second_cord_to_pointer,
  1929. @ttypeconvnode._second_nothing, { interface 2 string }
  1930. @ttypeconvnode._second_nothing, { interface 2 guid }
  1931. @ttypeconvnode._second_class_to_intf,
  1932. @ttypeconvnode._second_char_to_char,
  1933. @ttypeconvnode._second_nothing, { normal_2_smallset }
  1934. @ttypeconvnode._second_nothing, { dynarray_2_openarray }
  1935. @ttypeconvnode._second_nothing, { pwchar_2_string }
  1936. @ttypeconvnode._second_nothing, { variant_2_dynarray }
  1937. @ttypeconvnode._second_nothing, { dynarray_2_variant}
  1938. @ttypeconvnode._second_nothing, { variant_2_enum }
  1939. @ttypeconvnode._second_nothing { enum_2_variant }
  1940. );
  1941. type
  1942. tprocedureofobject = procedure of object;
  1943. var
  1944. r : packed record
  1945. proc : pointer;
  1946. obj : pointer;
  1947. end;
  1948. begin
  1949. { this is a little bit dirty but it works }
  1950. { and should be quite portable too }
  1951. r.proc:=secondconvert[c];
  1952. r.obj:=self;
  1953. tprocedureofobject(r)();
  1954. end;
  1955. {*****************************************************************************
  1956. TISNODE
  1957. *****************************************************************************}
  1958. constructor tisnode.create(l,r : tnode);
  1959. begin
  1960. inherited create(isn,l,r);
  1961. end;
  1962. function tisnode.det_resulttype:tnode;
  1963. var
  1964. paras: tcallparanode;
  1965. begin
  1966. result:=nil;
  1967. resulttypepass(left);
  1968. resulttypepass(right);
  1969. set_varstate(left,vs_used,true);
  1970. set_varstate(right,vs_used,true);
  1971. if codegenerror then
  1972. exit;
  1973. if (right.resulttype.def.deftype=classrefdef) then
  1974. begin
  1975. { left must be a class }
  1976. if is_class(left.resulttype.def) then
  1977. begin
  1978. { the operands must be related }
  1979. if (not(tobjectdef(left.resulttype.def).is_related(
  1980. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1981. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1982. tobjectdef(left.resulttype.def)))) then
  1983. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1984. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1985. end
  1986. else
  1987. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1988. { call fpc_do_is helper }
  1989. paras := ccallparanode.create(
  1990. left,
  1991. ccallparanode.create(
  1992. right,nil));
  1993. result := ccallnode.createintern('fpc_do_is',paras);
  1994. left := nil;
  1995. right := nil;
  1996. end
  1997. else if is_interface(right.resulttype.def) then
  1998. begin
  1999. { left is a class }
  2000. if is_class(left.resulttype.def) then
  2001. begin
  2002. { the operands must be related }
  2003. if not(assigned(tobjectdef(left.resulttype.def).implementedinterfaces) and
  2004. (tobjectdef(left.resulttype.def).implementedinterfaces.searchintf(right.resulttype.def)<>-1)) then
  2005. CGMessage2(type_e_classes_not_related,
  2006. FullTypeName(left.resulttype.def,right.resulttype.def),
  2007. FullTypeName(right.resulttype.def,left.resulttype.def))
  2008. end
  2009. { left is an interface }
  2010. else if is_interface(left.resulttype.def) then
  2011. begin
  2012. { the operands must be related }
  2013. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  2014. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  2015. CGMessage2(type_e_classes_not_related,
  2016. FullTypeName(left.resulttype.def,right.resulttype.def),
  2017. FullTypeName(right.resulttype.def,left.resulttype.def));
  2018. end
  2019. else
  2020. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  2021. { call fpc_do_is helper }
  2022. paras := ccallparanode.create(
  2023. left,
  2024. ccallparanode.create(
  2025. right,nil));
  2026. result := ccallnode.createintern('fpc_do_is',paras);
  2027. left := nil;
  2028. right := nil;
  2029. end
  2030. else
  2031. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  2032. resulttype:=booltype;
  2033. end;
  2034. function tisnode.pass_1 : tnode;
  2035. begin
  2036. internalerror(200204254);
  2037. result:=nil;
  2038. end;
  2039. { dummy pass_2, it will never be called, but we need one since }
  2040. { you can't instantiate an abstract class }
  2041. procedure tisnode.pass_2;
  2042. begin
  2043. end;
  2044. {*****************************************************************************
  2045. TASNODE
  2046. *****************************************************************************}
  2047. constructor tasnode.create(l,r : tnode);
  2048. begin
  2049. inherited create(asn,l,r);
  2050. call := nil;
  2051. end;
  2052. destructor tasnode.destroy;
  2053. begin
  2054. call.free;
  2055. inherited destroy;
  2056. end;
  2057. function tasnode.det_resulttype:tnode;
  2058. var
  2059. hp : tnode;
  2060. begin
  2061. result:=nil;
  2062. resulttypepass(right);
  2063. resulttypepass(left);
  2064. set_varstate(right,vs_used,true);
  2065. set_varstate(left,vs_used,true);
  2066. if codegenerror then
  2067. exit;
  2068. if (right.resulttype.def.deftype=classrefdef) then
  2069. begin
  2070. { left must be a class }
  2071. if is_class(left.resulttype.def) then
  2072. begin
  2073. { the operands must be related }
  2074. if (not(tobjectdef(left.resulttype.def).is_related(
  2075. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  2076. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  2077. tobjectdef(left.resulttype.def)))) then
  2078. CGMessage2(type_e_classes_not_related,
  2079. FullTypeName(left.resulttype.def,tclassrefdef(right.resulttype.def).pointertype.def),
  2080. FullTypeName(tclassrefdef(right.resulttype.def).pointertype.def,left.resulttype.def));
  2081. end
  2082. else
  2083. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  2084. resulttype:=tclassrefdef(right.resulttype.def).pointertype;
  2085. end
  2086. else if is_interface(right.resulttype.def) then
  2087. begin
  2088. { left is a class }
  2089. if not(is_class(left.resulttype.def) or
  2090. is_interface(left.resulttype.def)) then
  2091. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  2092. resulttype:=right.resulttype;
  2093. { load the GUID of the interface }
  2094. if (right.nodetype=typen) then
  2095. begin
  2096. if assigned(tobjectdef(right.resulttype.def).iidguid) then
  2097. begin
  2098. hp:=cguidconstnode.create(tobjectdef(right.resulttype.def).iidguid^);
  2099. right.free;
  2100. right:=hp;
  2101. end
  2102. else
  2103. internalerror(200206282);
  2104. resulttypepass(right);
  2105. end;
  2106. end
  2107. else
  2108. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  2109. end;
  2110. function tasnode.getcopy: tnode;
  2111. begin
  2112. result := inherited getcopy;
  2113. if assigned(call) then
  2114. tasnode(result).call := call.getcopy
  2115. else
  2116. tasnode(result).call := nil;
  2117. end;
  2118. function tasnode.pass_1 : tnode;
  2119. var
  2120. procname: string;
  2121. begin
  2122. result:=nil;
  2123. if not assigned(call) then
  2124. begin
  2125. if is_class(left.resulttype.def) and
  2126. (right.resulttype.def.deftype=classrefdef) then
  2127. call := ccallnode.createinternres('fpc_do_as',
  2128. ccallparanode.create(left,ccallparanode.create(right,nil)),
  2129. resulttype)
  2130. else
  2131. begin
  2132. if is_class(left.resulttype.def) then
  2133. procname := 'fpc_class_as_intf'
  2134. else
  2135. procname := 'fpc_intf_as';
  2136. call := ccallnode.createinternres(procname,
  2137. ccallparanode.create(right,ccallparanode.create(left,nil)),
  2138. resulttype);
  2139. end;
  2140. left := nil;
  2141. right := nil;
  2142. firstpass(call);
  2143. if codegenerror then
  2144. exit;
  2145. expectloc:=call.expectloc;
  2146. registersint:=call.registersint;
  2147. registersfpu:=call.registersfpu;
  2148. {$ifdef SUPPORT_MMX}
  2149. registersmmx:=call.registersmmx;
  2150. {$endif SUPPORT_MMX}
  2151. end;
  2152. end;
  2153. begin
  2154. ctypeconvnode:=ttypeconvnode;
  2155. casnode:=tasnode;
  2156. cisnode:=tisnode;
  2157. end.
  2158. {
  2159. $Log$
  2160. Revision 1.169 2004-12-27 16:54:29 peter
  2161. * also don't call procvar when converting to procvar
  2162. Revision 1.168 2004/12/26 16:22:01 peter
  2163. * fix lineinfo for with blocks
  2164. Revision 1.167 2004/12/07 16:11:52 peter
  2165. * set vo_explicit_paraloc flag
  2166. Revision 1.166 2004/12/05 12:28:11 peter
  2167. * procvar handling for tp procvar mode fixed
  2168. * proc to procvar moved from addrnode to typeconvnode
  2169. * inlininginfo is now allocated only for inline routines that
  2170. can be inlined, introduced a new flag po_has_inlining_info
  2171. Revision 1.165 2004/12/05 12:15:11 florian
  2172. * fixed compiler side of variant <-> dyn. array conversion
  2173. Revision 1.164 2004/11/26 22:34:28 peter
  2174. * internal flag for compare_defs_ext
  2175. Revision 1.163 2004/11/21 15:35:23 peter
  2176. * float routines all use internproc and compilerproc helpers
  2177. Revision 1.162 2004/11/02 20:15:53 jonas
  2178. * copy totype field in ttypeconvnode.getcopy()
  2179. Revision 1.161 2004/11/02 12:55:16 peter
  2180. * nf_internal flag for internal inserted typeconvs. This will
  2181. supress the generation of warning/hints
  2182. Revision 1.160 2004/11/01 23:30:11 peter
  2183. * support > 32bit accesses for x86_64
  2184. * rewrote array size checking to support 64bit
  2185. Revision 1.159 2004/11/01 17:15:47 peter
  2186. * no checkpointer code for dynarr to openarr
  2187. Revision 1.158 2004/11/01 15:31:58 peter
  2188. * -Or fix for absolute
  2189. Revision 1.157 2004/10/24 11:44:28 peter
  2190. * small regvar fixes
  2191. * loadref parameter removed from concatcopy,incrrefcount,etc
  2192. Revision 1.156 2004/10/15 09:14:17 mazen
  2193. - remove $IFDEF DELPHI and related code
  2194. - remove $IFDEF FPCPROCVAR and related code
  2195. Revision 1.155 2004/10/12 14:33:41 peter
  2196. * give error when converting class to interface are not related
  2197. Revision 1.154 2004/10/11 15:48:15 peter
  2198. * small regvar for para fixes
  2199. * function tvarsym.is_regvar added
  2200. * tvarsym.getvaluesize removed, use getsize instead
  2201. Revision 1.153 2004/09/26 17:45:30 peter
  2202. * simple regvar support, not yet finished
  2203. Revision 1.152 2004/08/08 16:00:56 florian
  2204. * constant floating point assignments etc. are now overflow checked
  2205. if Q+ or R+ is turned on
  2206. Revision 1.151 2004/06/29 20:57:50 peter
  2207. * fix pchar:=char
  2208. * fix longint(smallset)
  2209. Revision 1.150 2004/06/23 16:22:45 peter
  2210. * include unit name in error messages when types are the same
  2211. Revision 1.149 2004/06/20 08:55:29 florian
  2212. * logs truncated
  2213. Revision 1.148 2004/06/16 20:07:08 florian
  2214. * dwarf branch merged
  2215. Revision 1.147 2004/05/23 18:28:41 peter
  2216. * methodpointer is loaded into a temp when it was a calln
  2217. Revision 1.146 2004/05/23 15:03:40 peter
  2218. * some typeconvs don't allow assignment or passing to var para
  2219. Revision 1.145 2004/05/23 14:14:18 florian
  2220. + added set of widechar support (limited to 256 chars, is delphi compatible)
  2221. Revision 1.144 2004/04/29 19:56:37 daniel
  2222. * Prepare compiler infrastructure for multiple ansistring types
  2223. }