ncnv.pas 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Type checking and register allocation for type converting nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ncnv;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,
  22. symtype,
  23. defutil,defcmp,
  24. nld
  25. ;
  26. type
  27. ttypeconvnode = class(tunarynode)
  28. totypedef : tdef;
  29. totypedefderef : tderef;
  30. convtype : tconverttype;
  31. constructor create(node : tnode;def:tdef);virtual;
  32. constructor create_explicit(node : tnode;def:tdef);
  33. constructor create_internal(node : tnode;def:tdef);
  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 dogetcopy : tnode;override;
  40. procedure printnodeinfo(var t : text);override;
  41. function pass_1 : tnode;override;
  42. function pass_typecheck:tnode;override;
  43. function simplify:tnode; override;
  44. procedure mark_write;override;
  45. function docompare(p: tnode) : boolean; override;
  46. function assign_allowed:boolean;
  47. procedure second_call_helper(c : tconverttype);
  48. private
  49. function typecheck_int_to_int : tnode;
  50. function typecheck_cord_to_pointer : tnode;
  51. function typecheck_chararray_to_string : tnode;
  52. function typecheck_string_to_chararray : tnode;
  53. function typecheck_string_to_string : tnode;
  54. function typecheck_char_to_string : tnode;
  55. function typecheck_char_to_chararray : tnode;
  56. function typecheck_int_to_real : tnode;
  57. function typecheck_real_to_real : tnode;
  58. function typecheck_real_to_currency : tnode;
  59. function typecheck_cchar_to_pchar : tnode;
  60. function typecheck_cstring_to_pchar : tnode;
  61. function typecheck_cstring_to_int : tnode;
  62. function typecheck_char_to_char : tnode;
  63. function typecheck_arrayconstructor_to_set : tnode;
  64. function typecheck_set_to_set : tnode;
  65. function typecheck_pchar_to_string : tnode;
  66. function typecheck_interface_to_guid : tnode;
  67. function typecheck_dynarray_to_openarray : tnode;
  68. function typecheck_pwchar_to_string : tnode;
  69. function typecheck_variant_to_dynarray : tnode;
  70. function typecheck_dynarray_to_variant : tnode;
  71. function typecheck_call_helper(c : tconverttype) : tnode;
  72. function typecheck_variant_to_enum : tnode;
  73. function typecheck_enum_to_variant : tnode;
  74. function typecheck_proc_to_procvar : tnode;
  75. function typecheck_variant_to_interface : tnode;
  76. function typecheck_interface_to_variant : tnode;
  77. function typecheck_array_2_dynarray : tnode;
  78. protected
  79. function first_int_to_int : tnode;virtual;
  80. function first_cstring_to_pchar : tnode;virtual;
  81. function first_cstring_to_int : tnode;virtual;
  82. function first_string_to_chararray : tnode;virtual;
  83. function first_char_to_string : tnode;virtual;
  84. function first_nothing : tnode;virtual;
  85. function first_array_to_pointer : tnode;virtual;
  86. function first_int_to_real : tnode;virtual;
  87. function first_real_to_real : tnode;virtual;
  88. function first_pointer_to_array : tnode;virtual;
  89. function first_cchar_to_pchar : tnode;virtual;
  90. function first_bool_to_int : tnode;virtual;
  91. function first_int_to_bool : tnode;virtual;
  92. function first_bool_to_bool : tnode;virtual;
  93. function first_proc_to_procvar : tnode;virtual;
  94. function first_nil_to_methodprocvar : tnode;virtual;
  95. function first_set_to_set : tnode;virtual;
  96. function first_cord_to_pointer : tnode;virtual;
  97. function first_ansistring_to_pchar : tnode;virtual;
  98. function first_arrayconstructor_to_set : tnode;virtual;
  99. function first_class_to_intf : tnode;virtual;
  100. function first_char_to_char : tnode;virtual;
  101. function first_call_helper(c : tconverttype) : tnode;
  102. { these wrapper are necessary, because the first_* stuff is called }
  103. { through a table. Without the wrappers override wouldn't have }
  104. { any effect }
  105. function _first_int_to_int : tnode;
  106. function _first_cstring_to_pchar : tnode;
  107. function _first_cstring_to_int : tnode;
  108. function _first_string_to_chararray : tnode;
  109. function _first_char_to_string : tnode;
  110. function _first_nothing : tnode;
  111. function _first_array_to_pointer : tnode;
  112. function _first_int_to_real : tnode;
  113. function _first_real_to_real: tnode;
  114. function _first_pointer_to_array : tnode;
  115. function _first_cchar_to_pchar : tnode;
  116. function _first_bool_to_int : tnode;
  117. function _first_int_to_bool : tnode;
  118. function _first_bool_to_bool : tnode;
  119. function _first_proc_to_procvar : tnode;
  120. function _first_nil_to_methodprocvar : tnode;
  121. function _first_cord_to_pointer : tnode;
  122. function _first_ansistring_to_pchar : tnode;
  123. function _first_arrayconstructor_to_set : tnode;
  124. function _first_class_to_intf : tnode;
  125. function _first_char_to_char : tnode;
  126. function _first_set_to_set : tnode;
  127. procedure _second_int_to_int;virtual;
  128. procedure _second_string_to_string;virtual;
  129. procedure _second_cstring_to_pchar;virtual;
  130. procedure _second_cstring_to_int;virtual;
  131. procedure _second_string_to_chararray;virtual;
  132. procedure _second_array_to_pointer;virtual;
  133. procedure _second_pointer_to_array;virtual;
  134. procedure _second_chararray_to_string;virtual;
  135. procedure _second_char_to_string;virtual;
  136. procedure _second_int_to_real;virtual;
  137. procedure _second_real_to_real;virtual;
  138. procedure _second_cord_to_pointer;virtual;
  139. procedure _second_proc_to_procvar;virtual;
  140. procedure _second_nil_to_methodprocvar;virtual;
  141. procedure _second_bool_to_int;virtual;
  142. procedure _second_int_to_bool;virtual;
  143. procedure _second_bool_to_bool;virtual;
  144. procedure _second_set_to_set;virtual;
  145. procedure _second_ansistring_to_pchar;virtual;
  146. procedure _second_class_to_intf;virtual;
  147. procedure _second_char_to_char;virtual;
  148. procedure _second_nothing; virtual;
  149. procedure second_int_to_int;virtual;abstract;
  150. procedure second_string_to_string;virtual;abstract;
  151. procedure second_cstring_to_pchar;virtual;abstract;
  152. procedure second_cstring_to_int;virtual;abstract;
  153. procedure second_string_to_chararray;virtual;abstract;
  154. procedure second_array_to_pointer;virtual;abstract;
  155. procedure second_pointer_to_array;virtual;abstract;
  156. procedure second_chararray_to_string;virtual;abstract;
  157. procedure second_char_to_string;virtual;abstract;
  158. procedure second_int_to_real;virtual;abstract;
  159. procedure second_real_to_real;virtual;abstract;
  160. procedure second_cord_to_pointer;virtual;abstract;
  161. procedure second_proc_to_procvar;virtual;abstract;
  162. procedure second_nil_to_methodprocvar;virtual;abstract;
  163. procedure second_bool_to_int;virtual;abstract;
  164. procedure second_int_to_bool;virtual;abstract;
  165. procedure second_bool_to_bool;virtual;abstract;
  166. procedure second_set_to_set;virtual;abstract;
  167. procedure second_ansistring_to_pchar;virtual;abstract;
  168. procedure second_class_to_intf;virtual;abstract;
  169. procedure second_char_to_char;virtual;abstract;
  170. procedure second_nothing; virtual;abstract;
  171. end;
  172. ttypeconvnodeclass = class of ttypeconvnode;
  173. tasnode = class(tbinarynode)
  174. constructor create(l,r : tnode);virtual;
  175. function pass_1 : tnode;override;
  176. function pass_typecheck:tnode;override;
  177. function dogetcopy: tnode;override;
  178. destructor destroy; override;
  179. call: tnode;
  180. end;
  181. tasnodeclass = class of tasnode;
  182. tisnode = class(tbinarynode)
  183. constructor create(l,r : tnode);virtual;
  184. function pass_1 : tnode;override;
  185. function pass_typecheck:tnode;override;
  186. procedure pass_generate_code;override;
  187. end;
  188. tisnodeclass = class of tisnode;
  189. var
  190. ctypeconvnode : ttypeconvnodeclass;
  191. casnode : tasnodeclass;
  192. cisnode : tisnodeclass;
  193. procedure inserttypeconv(var p:tnode;def:tdef);
  194. procedure inserttypeconv_internal(var p:tnode;def:tdef);
  195. procedure arrayconstructor_to_set(var p : tnode);
  196. procedure insert_varargstypeconv(var p : tnode; iscvarargs: boolean);
  197. implementation
  198. uses
  199. cclasses,globtype,systems,constexp,
  200. cutils,verbose,globals,widestr,
  201. symconst,symdef,symsym,symbase,symtable,
  202. ncon,ncal,nset,nadd,ninl,nmem,nmat,nbas,nutils,
  203. cgbase,procinfo,
  204. htypechk,pass_1,cpuinfo;
  205. {*****************************************************************************
  206. Helpers
  207. *****************************************************************************}
  208. procedure inserttypeconv(var p:tnode;def:tdef);
  209. begin
  210. if not assigned(p.resultdef) then
  211. begin
  212. typecheckpass(p);
  213. if codegenerror then
  214. exit;
  215. end;
  216. { don't insert obsolete type conversions }
  217. if equal_defs(p.resultdef,def) and
  218. not ((p.resultdef.typ=setdef) and
  219. (tsetdef(p.resultdef).settype <>
  220. tsetdef(def).settype)) then
  221. begin
  222. p.resultdef:=def;
  223. end
  224. else
  225. begin
  226. p:=ctypeconvnode.create(p,def);
  227. typecheckpass(p);
  228. end;
  229. end;
  230. procedure inserttypeconv_internal(var p:tnode;def:tdef);
  231. begin
  232. if not assigned(p.resultdef) then
  233. begin
  234. typecheckpass(p);
  235. if codegenerror then
  236. exit;
  237. end;
  238. { don't insert obsolete type conversions }
  239. if equal_defs(p.resultdef,def) and
  240. not ((p.resultdef.typ=setdef) and
  241. (tsetdef(p.resultdef).settype <>
  242. tsetdef(def).settype)) then
  243. begin
  244. p.resultdef:=def;
  245. end
  246. else
  247. begin
  248. p:=ctypeconvnode.create_internal(p,def);
  249. typecheckpass(p);
  250. end;
  251. end;
  252. {*****************************************************************************
  253. Array constructor to Set Conversion
  254. *****************************************************************************}
  255. procedure arrayconstructor_to_set(var p : tnode);
  256. var
  257. constp : tsetconstnode;
  258. buildp,
  259. p2,p3,p4 : tnode;
  260. hdef : tdef;
  261. constset : Pconstset;
  262. constsetlo,
  263. constsethi : TConstExprInt;
  264. procedure update_constsethi(def:tdef);
  265. begin
  266. if (def.typ=orddef) and
  267. ((torddef(def).high>=constsethi) or
  268. (torddef(def).low <=constsetlo)) then
  269. begin
  270. if torddef(def).ordtype=uwidechar then
  271. begin
  272. constsethi:=255;
  273. constsetlo:=0;
  274. if hdef=nil then
  275. hdef:=def;
  276. end
  277. else
  278. begin
  279. if (torddef(def).high>=constsethi) then
  280. constsethi:=torddef(def).high;
  281. if (torddef(def).low<=constsetlo) then
  282. constsetlo:=torddef(def).low;
  283. if hdef=nil then
  284. begin
  285. if (constsethi>255) or
  286. (torddef(def).low<0) then
  287. hdef:=u8inttype
  288. else
  289. hdef:=def;
  290. end;
  291. if constsethi>255 then
  292. constsethi:=255;
  293. if constsetlo<0 then
  294. constsetlo:=0;
  295. end;
  296. end
  297. else if (def.typ=enumdef) and
  298. ((tenumdef(def).max>=constsethi) or
  299. (tenumdef(def).min<=constsetlo)) then
  300. begin
  301. if hdef=nil then
  302. hdef:=def;
  303. if (tenumdef(def).max>=constsethi) then
  304. constsethi:=tenumdef(def).max;
  305. if (tenumdef(def).min<=constsetlo) then
  306. constsetlo:=tenumdef(def).min;
  307. end;
  308. end;
  309. procedure do_set(pos : longint);
  310. begin
  311. if (pos and not $ff)<>0 then
  312. Message(parser_e_illegal_set_expr);
  313. if pos>constsethi then
  314. constsethi:=pos;
  315. if pos<constsetlo then
  316. constsetlo:=pos;
  317. if pos in constset^ then
  318. Message(parser_e_illegal_set_expr);
  319. include(constset^,pos);
  320. end;
  321. var
  322. l : Longint;
  323. lr,hr : TConstExprInt;
  324. hp : tarrayconstructornode;
  325. begin
  326. if p.nodetype<>arrayconstructorn then
  327. internalerror(200205105);
  328. new(constset);
  329. constset^:=[];
  330. hdef:=nil;
  331. { make sure to set constsetlo correctly for empty sets }
  332. if assigned(tarrayconstructornode(p).left) then
  333. constsetlo:=high(aint)
  334. else
  335. constsetlo:=0;
  336. constsethi:=0;
  337. constp:=csetconstnode.create(nil,hdef);
  338. constp.value_set:=constset;
  339. buildp:=constp;
  340. hp:=tarrayconstructornode(p);
  341. if assigned(hp.left) then
  342. begin
  343. while assigned(hp) do
  344. begin
  345. p4:=nil; { will contain the tree to create the set }
  346. {split a range into p2 and p3 }
  347. if hp.left.nodetype=arrayconstructorrangen then
  348. begin
  349. p2:=tarrayconstructorrangenode(hp.left).left;
  350. p3:=tarrayconstructorrangenode(hp.left).right;
  351. tarrayconstructorrangenode(hp.left).left:=nil;
  352. tarrayconstructorrangenode(hp.left).right:=nil;
  353. end
  354. else
  355. begin
  356. p2:=hp.left;
  357. hp.left:=nil;
  358. p3:=nil;
  359. end;
  360. typecheckpass(p2);
  361. set_varstate(p2,vs_read,[vsf_must_be_valid]);
  362. if assigned(p3) then
  363. begin
  364. typecheckpass(p3);
  365. set_varstate(p3,vs_read,[vsf_must_be_valid]);
  366. end;
  367. if codegenerror then
  368. break;
  369. current_filepos:=p2.fileinfo;
  370. case p2.resultdef.typ of
  371. enumdef,
  372. orddef:
  373. begin
  374. { widechars are not yet supported }
  375. if is_widechar(p2.resultdef) then
  376. begin
  377. inserttypeconv(p2,cchartype);
  378. if (p2.nodetype<>ordconstn) then
  379. incompatibletypes(cwidechartype,cchartype);
  380. end;
  381. getrange(p2.resultdef,lr,hr);
  382. if assigned(p3) then
  383. begin
  384. if is_widechar(p3.resultdef) then
  385. begin
  386. inserttypeconv(p3,cchartype);
  387. if (p3.nodetype<>ordconstn) then
  388. begin
  389. current_filepos:=p3.fileinfo;
  390. incompatibletypes(cwidechartype,cchartype);
  391. end;
  392. end;
  393. { this isn't good, you'll get problems with
  394. type t010 = 0..10;
  395. ts = set of t010;
  396. var s : ts;b : t010
  397. begin s:=[1,2,b]; end.
  398. if is_integer(p3^.resultdef) then
  399. begin
  400. inserttypeconv(p3,u8bitdef);
  401. end;
  402. }
  403. if assigned(hdef) and not(equal_defs(hdef,p3.resultdef)) then
  404. begin
  405. CGMessagePos(p3.fileinfo,type_e_typeconflict_in_set);
  406. end
  407. else
  408. begin
  409. if (p2.nodetype=ordconstn) and (p3.nodetype=ordconstn) then
  410. begin
  411. if not(is_integer(p3.resultdef)) then
  412. hdef:=p3.resultdef
  413. else
  414. begin
  415. inserttypeconv(p3,u8inttype);
  416. inserttypeconv(p2,u8inttype);
  417. end;
  418. for l:=tordconstnode(p2).value.svalue to tordconstnode(p3).value.svalue do
  419. do_set(l);
  420. p2.free;
  421. p3.free;
  422. end
  423. else
  424. begin
  425. update_constsethi(p2.resultdef);
  426. inserttypeconv(p2,hdef);
  427. update_constsethi(p3.resultdef);
  428. inserttypeconv(p3,hdef);
  429. if assigned(hdef) then
  430. inserttypeconv(p3,hdef)
  431. else
  432. inserttypeconv(p3,u8inttype);
  433. p4:=csetelementnode.create(p2,p3);
  434. end;
  435. end;
  436. end
  437. else
  438. begin
  439. { Single value }
  440. if p2.nodetype=ordconstn then
  441. begin
  442. if not(is_integer(p2.resultdef)) then
  443. begin
  444. { for constant set elements, delphi allows the usage of elements of enumerations which
  445. have value>255 if there is no element with a value > 255 used }
  446. if (m_delphi in current_settings.modeswitches) and (p2.resultdef.typ=enumdef) then
  447. begin
  448. if tordconstnode(p2).value>constsethi then
  449. constsethi:=tordconstnode(p2).value;
  450. if hdef=nil then
  451. hdef:=p2.resultdef;
  452. end
  453. else
  454. update_constsethi(p2.resultdef);
  455. end;
  456. if assigned(hdef) then
  457. inserttypeconv(p2,hdef)
  458. else
  459. inserttypeconv(p2,u8inttype);
  460. do_set(tordconstnode(p2).value.svalue);
  461. p2.free;
  462. end
  463. else
  464. begin
  465. update_constsethi(p2.resultdef);
  466. if assigned(hdef) then
  467. inserttypeconv(p2,hdef)
  468. else
  469. inserttypeconv(p2,u8inttype);
  470. p4:=csetelementnode.create(p2,nil);
  471. end;
  472. end;
  473. end;
  474. stringdef :
  475. begin
  476. { if we've already set elements which are constants }
  477. { throw an error }
  478. if ((hdef=nil) and assigned(buildp)) or
  479. not(is_char(hdef)) then
  480. CGMessage(type_e_typeconflict_in_set)
  481. else
  482. for l:=1 to length(pshortstring(tstringconstnode(p2).value_str)^) do
  483. do_set(ord(pshortstring(tstringconstnode(p2).value_str)^[l]));
  484. if hdef=nil then
  485. hdef:=cchartype;
  486. p2.free;
  487. end;
  488. else
  489. CGMessage(type_e_ordinal_expr_expected);
  490. end;
  491. { insert the set creation tree }
  492. if assigned(p4) then
  493. buildp:=caddnode.create(addn,buildp,p4);
  494. { load next and dispose current node }
  495. p2:=hp;
  496. hp:=tarrayconstructornode(tarrayconstructornode(p2).right);
  497. tarrayconstructornode(p2).right:=nil;
  498. p2.free;
  499. end;
  500. if (hdef=nil) then
  501. hdef:=u8inttype;
  502. end
  503. else
  504. begin
  505. { empty set [], only remove node }
  506. p.free;
  507. end;
  508. { set the initial set type }
  509. constp.resultdef:=tsetdef.create(hdef,constsetlo.svalue,constsethi.svalue);
  510. { determine the resultdef for the tree }
  511. typecheckpass(buildp);
  512. { set the new tree }
  513. p:=buildp;
  514. end;
  515. procedure insert_varargstypeconv(var p : tnode; iscvarargs: boolean);
  516. begin
  517. if not(iscvarargs) and
  518. (p.nodetype=stringconstn) then
  519. p:=ctypeconvnode.create_internal(p,cansistringtype)
  520. else
  521. case p.resultdef.typ of
  522. enumdef :
  523. p:=ctypeconvnode.create_internal(p,s32inttype);
  524. arraydef :
  525. begin
  526. if is_chararray(p.resultdef) then
  527. p:=ctypeconvnode.create_internal(p,charpointertype)
  528. else
  529. if is_widechararray(p.resultdef) then
  530. p:=ctypeconvnode.create_internal(p,widecharpointertype)
  531. else
  532. CGMessagePos1(p.fileinfo,type_e_wrong_type_in_array_constructor,p.resultdef.typename);
  533. end;
  534. orddef :
  535. begin
  536. if is_integer(p.resultdef) and
  537. not(is_64bitint(p.resultdef)) then
  538. p:=ctypeconvnode.create(p,s32inttype)
  539. else if is_void(p.resultdef) then
  540. CGMessagePos1(p.fileinfo,type_e_wrong_type_in_array_constructor,p.resultdef.typename)
  541. else if iscvarargs and
  542. is_currency(p.resultdef) then
  543. p:=ctypeconvnode.create(p,s64floattype);
  544. end;
  545. floatdef :
  546. if not(iscvarargs) then
  547. begin
  548. if not(is_currency(p.resultdef)) then
  549. p:=ctypeconvnode.create(p,pbestrealtype^);
  550. end
  551. else
  552. begin
  553. if is_constrealnode(p) and
  554. not(nf_explicit in p.flags) then
  555. MessagePos(p.fileinfo,type_w_double_c_varargs);
  556. if (tfloatdef(p.resultdef).floattype in [{$ifndef x86_64}s32real,{$endif}s64currency]) or
  557. { win64 requires the double type cast for singles as well }
  558. ((tfloatdef(p.resultdef).floattype=s32real) and (target_info.system=system_x86_64_win64)) or
  559. (is_constrealnode(p) and
  560. not(nf_explicit in p.flags)) then
  561. p:=ctypeconvnode.create(p,s64floattype);
  562. end;
  563. procvardef :
  564. p:=ctypeconvnode.create(p,voidpointertype);
  565. stringdef:
  566. if iscvarargs then
  567. p:=ctypeconvnode.create(p,charpointertype);
  568. variantdef:
  569. if iscvarargs then
  570. CGMessagePos1(p.fileinfo,type_e_wrong_type_in_array_constructor,p.resultdef.typename);
  571. pointerdef:
  572. ;
  573. classrefdef:
  574. if iscvarargs then
  575. p:=ctypeconvnode.create(p,voidpointertype);
  576. objectdef :
  577. if iscvarargs or
  578. is_object(p.resultdef) then
  579. CGMessagePos1(p.fileinfo,type_e_wrong_type_in_array_constructor,p.resultdef.typename);
  580. else
  581. CGMessagePos1(p.fileinfo,type_e_wrong_type_in_array_constructor,p.resultdef.typename);
  582. end;
  583. typecheckpass(p);
  584. end;
  585. {*****************************************************************************
  586. TTYPECONVNODE
  587. *****************************************************************************}
  588. constructor ttypeconvnode.create(node : tnode;def:tdef);
  589. begin
  590. inherited create(typeconvn,node);
  591. convtype:=tc_none;
  592. totypedef:=def;
  593. if def=nil then
  594. internalerror(200103281);
  595. fileinfo:=node.fileinfo;
  596. {An attempt to convert the result of a floating point division
  597. (with the / operator) to an integer type will fail. Give a hint
  598. to use the div operator.}
  599. if (node.nodetype=slashn) and (def.typ=orddef) then
  600. cgmessage(type_h_use_div_for_int);
  601. {In expressions like int64:=longint+longint, an integer overflow could be avoided
  602. by simply converting the operands to int64 first. Give a hint to do this.}
  603. if (node.nodetype in [addn,subn,muln]) and
  604. (def.typ=orddef) and (node.resultdef<>nil) and (node.resultdef.typ=orddef) and
  605. ((Torddef(node.resultdef).low>=Torddef(def).low) and (Torddef(node.resultdef).high<=Torddef(def).high)) and
  606. ((Torddef(node.resultdef).low>Torddef(def).low) or (Torddef(node.resultdef).high<Torddef(def).high)) then
  607. case node.nodetype of
  608. addn:
  609. cgmessage1(type_h_convert_add_operands_to_prevent_overflow,def.gettypename);
  610. subn:
  611. cgmessage1(type_h_convert_sub_operands_to_prevent_overflow,def.gettypename);
  612. muln:
  613. cgmessage1(type_h_convert_mul_operands_to_prevent_overflow,def.gettypename);
  614. end;
  615. {Converting pointers to signed integers is a bad idea. Warn.}
  616. if (node.resultdef<>nil) and (node.resultdef.typ=pointerdef) and
  617. (def.typ=orddef) and (Torddef(def).ordtype in [s8bit,s16bit,s32bit,s64bit]) then
  618. cgmessage(type_w_pointer_to_signed);
  619. end;
  620. constructor ttypeconvnode.create_explicit(node : tnode;def:tdef);
  621. begin
  622. self.create(node,def);
  623. include(flags,nf_explicit);
  624. end;
  625. constructor ttypeconvnode.create_internal(node : tnode;def:tdef);
  626. begin
  627. self.create(node,def);
  628. { handle like explicit conversions }
  629. include(flags,nf_explicit);
  630. include(flags,nf_internal);
  631. end;
  632. constructor ttypeconvnode.create_proc_to_procvar(node : tnode);
  633. begin
  634. self.create(node,voidtype);
  635. convtype:=tc_proc_2_procvar;
  636. end;
  637. constructor ttypeconvnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  638. begin
  639. inherited ppuload(t,ppufile);
  640. ppufile.getderef(totypedefderef);
  641. convtype:=tconverttype(ppufile.getbyte);
  642. end;
  643. procedure ttypeconvnode.ppuwrite(ppufile:tcompilerppufile);
  644. begin
  645. inherited ppuwrite(ppufile);
  646. ppufile.putderef(totypedefderef);
  647. ppufile.putbyte(byte(convtype));
  648. end;
  649. procedure ttypeconvnode.buildderefimpl;
  650. begin
  651. inherited buildderefimpl;
  652. totypedefderef.build(totypedef);
  653. end;
  654. procedure ttypeconvnode.derefimpl;
  655. begin
  656. inherited derefimpl;
  657. totypedef:=tdef(totypedefderef.resolve);
  658. end;
  659. function ttypeconvnode.dogetcopy : tnode;
  660. var
  661. n : ttypeconvnode;
  662. begin
  663. n:=ttypeconvnode(inherited dogetcopy);
  664. n.convtype:=convtype;
  665. n.totypedef:=totypedef;
  666. dogetcopy:=n;
  667. end;
  668. procedure ttypeconvnode.printnodeinfo(var t : text);
  669. const
  670. convtyp2str : array[tconverttype] of pchar = (
  671. 'tc_none',
  672. 'tc_equal',
  673. 'tc_not_possible',
  674. 'tc_string_2_string',
  675. 'tc_char_2_string',
  676. 'tc_char_2_chararray',
  677. 'tc_pchar_2_string',
  678. 'tc_cchar_2_pchar',
  679. 'tc_cstring_2_pchar',
  680. 'tc_cstring_2_int',
  681. 'tc_ansistring_2_pchar',
  682. 'tc_string_2_chararray',
  683. 'tc_chararray_2_string',
  684. 'tc_array_2_pointer',
  685. 'tc_pointer_2_array',
  686. 'tc_int_2_int',
  687. 'tc_int_2_bool',
  688. 'tc_bool_2_bool',
  689. 'tc_bool_2_int',
  690. 'tc_real_2_real',
  691. 'tc_int_2_real',
  692. 'tc_real_2_currency',
  693. 'tc_proc_2_procvar',
  694. 'tc_nil_2_methodprocvar',
  695. 'tc_arrayconstructor_2_set',
  696. 'tc_set_2_set',
  697. 'tc_cord_2_pointer',
  698. 'tc_intf_2_string',
  699. 'tc_intf_2_guid',
  700. 'tc_class_2_intf',
  701. 'tc_char_2_char',
  702. 'tc_dynarray_2_openarray',
  703. 'tc_pwchar_2_string',
  704. 'tc_variant_2_dynarray',
  705. 'tc_dynarray_2_variant',
  706. 'tc_variant_2_enum',
  707. 'tc_enum_2_variant',
  708. 'tc_interface_2_variant',
  709. 'tc_variant_2_interface',
  710. 'tc_array_2_dynarray'
  711. );
  712. begin
  713. inherited printnodeinfo(t);
  714. write(t,', convtype = ',strpas(convtyp2str[convtype]));
  715. end;
  716. function ttypeconvnode.typecheck_cord_to_pointer : tnode;
  717. var
  718. t : tnode;
  719. begin
  720. result:=nil;
  721. if left.nodetype=ordconstn then
  722. begin
  723. { check if we have a valid pointer constant (JM) }
  724. if (sizeof(pointer) > sizeof(TConstPtrUInt)) then
  725. if (sizeof(TConstPtrUInt) = 4) then
  726. begin
  727. if (tordconstnode(left).value < int64(low(longint))) or
  728. (tordconstnode(left).value > int64(high(cardinal))) then
  729. CGMessage(parser_e_range_check_error);
  730. end
  731. else if (sizeof(TConstPtrUInt) = 8) then
  732. begin
  733. if (tordconstnode(left).value < int64(low(int64))) or
  734. (tordconstnode(left).value > int64(high(qword))) then
  735. CGMessage(parser_e_range_check_error);
  736. end
  737. else
  738. internalerror(2001020801);
  739. t:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value.uvalue),resultdef);
  740. result:=t;
  741. end
  742. else
  743. internalerror(200104023);
  744. end;
  745. function ttypeconvnode.typecheck_chararray_to_string : tnode;
  746. var
  747. chartype : string[8];
  748. begin
  749. if is_widechar(tarraydef(left.resultdef).elementdef) then
  750. chartype:='widechar'
  751. else
  752. chartype:='char';
  753. result := ccallnode.createinternres(
  754. 'fpc_'+chartype+'array_to_'+tstringdef(resultdef).stringtypname,
  755. ccallparanode.create(cordconstnode.create(
  756. ord(tarraydef(left.resultdef).lowrange=0),booltype,false),
  757. ccallparanode.create(left,nil)),resultdef);
  758. left := nil;
  759. end;
  760. function ttypeconvnode.typecheck_string_to_chararray : tnode;
  761. var
  762. newblock : tblocknode;
  763. newstat : tstatementnode;
  764. restemp : ttempcreatenode;
  765. pchtemp : pchar;
  766. arrsize : aint;
  767. chartype : string[8];
  768. begin
  769. result := nil;
  770. with tarraydef(resultdef) do
  771. begin
  772. if highrange<lowrange then
  773. internalerror(200501051);
  774. arrsize := highrange-lowrange+1;
  775. end;
  776. if (left.nodetype = stringconstn) and
  777. (tstringconstnode(left).cst_type=cst_conststring) then
  778. begin
  779. { if the array of char is large enough we can use the string
  780. constant directly. This is handled in ncgcnv }
  781. if (arrsize>=tstringconstnode(left).len) and
  782. is_char(tarraydef(resultdef).elementdef) then
  783. begin
  784. { pad the constant string with #0 to the array len }
  785. { (2.0.x compatible) }
  786. if (arrsize>tstringconstnode(left).len) then
  787. begin
  788. pchtemp:=concatansistrings(tstringconstnode(left).value_str,pchar(StringOfChar(#0,arrsize-tstringconstnode(left).len)),tstringconstnode(left).len,arrsize-tstringconstnode(left).len);
  789. left.free;
  790. left:=cstringconstnode.createpchar(pchtemp,arrsize);
  791. typecheckpass(left);
  792. end;
  793. exit;
  794. end;
  795. { Convert to wide/short/ansistring and call default helper }
  796. if is_widechar(tarraydef(resultdef).elementdef) then
  797. inserttypeconv(left,cwidestringtype)
  798. else
  799. begin
  800. if tstringconstnode(left).len>255 then
  801. inserttypeconv(left,cansistringtype)
  802. else
  803. inserttypeconv(left,cshortstringtype);
  804. end;
  805. end;
  806. if is_widechar(tarraydef(resultdef).elementdef) then
  807. chartype:='widechar'
  808. else
  809. chartype:='char';
  810. newblock:=internalstatements(newstat);
  811. restemp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,false);
  812. addstatement(newstat,restemp);
  813. addstatement(newstat,ccallnode.createintern('fpc_'+tstringdef(left.resultdef).stringtypname+
  814. '_to_'+chartype+'array',ccallparanode.create(left,ccallparanode.create(
  815. ctemprefnode.create(restemp),nil))));
  816. addstatement(newstat,ctempdeletenode.create_normal_temp(restemp));
  817. addstatement(newstat,ctemprefnode.create(restemp));
  818. result:=newblock;
  819. left:=nil;
  820. end;
  821. function ttypeconvnode.typecheck_string_to_string : tnode;
  822. var
  823. procname: string[31];
  824. stringpara : tcallparanode;
  825. begin
  826. result:=nil;
  827. if (left.nodetype=stringconstn) and
  828. ((not is_widechararray(left.resultdef) and
  829. not is_widestring(left.resultdef)) or
  830. (tstringdef(resultdef).stringtype=st_widestring) or
  831. { non-ascii chars would be replaced with '?' -> loses info }
  832. not hasnonasciichars(pcompilerwidestring(tstringconstnode(left).value_str))) then
  833. begin
  834. tstringconstnode(left).changestringtype(resultdef);
  835. result:=left;
  836. left:=nil;
  837. end
  838. else
  839. begin
  840. { get the correct procedure name }
  841. procname := 'fpc_'+tstringdef(left.resultdef).stringtypname+
  842. '_to_'+tstringdef(resultdef).stringtypname;
  843. { create parameter (and remove left node from typeconvnode }
  844. { since it's reused as parameter) }
  845. stringpara := ccallparanode.create(left,nil);
  846. left := nil;
  847. { when converting to shortstrings, we have to pass high(destination) too }
  848. if (tstringdef(resultdef).stringtype = st_shortstring) then
  849. stringpara.right := ccallparanode.create(cinlinenode.create(
  850. in_high_x,false,self.getcopy),nil);
  851. { and create the callnode }
  852. result := ccallnode.createinternres(procname,stringpara,resultdef);
  853. end;
  854. end;
  855. function ttypeconvnode.typecheck_char_to_string : tnode;
  856. var
  857. procname: string[31];
  858. para : tcallparanode;
  859. hp : tstringconstnode;
  860. ws : pcompilerwidestring;
  861. begin
  862. result:=nil;
  863. { we can't do widechar to ansichar conversions at compile time, since }
  864. { this maps all non-ascii chars to '?' -> loses information }
  865. if (left.nodetype=ordconstn) and
  866. ((tstringdef(resultdef).stringtype=st_widestring) or
  867. (torddef(left.resultdef).ordtype=uchar) or
  868. { >=128 is destroyed }
  869. (tordconstnode(left).value.uvalue<128)) then
  870. begin
  871. if tstringdef(resultdef).stringtype=st_widestring then
  872. begin
  873. initwidestring(ws);
  874. if torddef(left.resultdef).ordtype=uwidechar then
  875. concatwidestringchar(ws,tcompilerwidechar(tordconstnode(left).value.uvalue))
  876. else
  877. concatwidestringchar(ws,tcompilerwidechar(chr(tordconstnode(left).value.uvalue)));
  878. hp:=cstringconstnode.createwstr(ws);
  879. donewidestring(ws);
  880. end
  881. else
  882. begin
  883. if torddef(left.resultdef).ordtype=uwidechar then
  884. hp:=cstringconstnode.createstr(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value.uvalue)))
  885. else
  886. hp:=cstringconstnode.createstr(chr(tordconstnode(left).value.uvalue));
  887. tstringconstnode(hp).changestringtype(resultdef);
  888. end;
  889. result:=hp;
  890. end
  891. else
  892. { shortstrings are handled 'inline' (except for widechars) }
  893. if (tstringdef(resultdef).stringtype <> st_shortstring) or
  894. (torddef(left.resultdef).ordtype = uwidechar) then
  895. begin
  896. { create the procname }
  897. if torddef(left.resultdef).ordtype<>uwidechar then
  898. procname := 'fpc_char_to_'
  899. else
  900. procname := 'fpc_wchar_to_';
  901. procname:=procname+tstringdef(resultdef).stringtypname;
  902. { and the parameter }
  903. para := ccallparanode.create(left,nil);
  904. left := nil;
  905. { and finally the call }
  906. result := ccallnode.createinternres(procname,para,resultdef);
  907. end
  908. else
  909. begin
  910. { create word(byte(char) shl 8 or 1) for litte endian machines }
  911. { and word(byte(char) or 256) for big endian machines }
  912. left := ctypeconvnode.create_internal(left,u8inttype);
  913. if (target_info.endian = endian_little) then
  914. left := caddnode.create(orn,
  915. cshlshrnode.create(shln,left,cordconstnode.create(8,s32inttype,false)),
  916. cordconstnode.create(1,s32inttype,false))
  917. else
  918. left := caddnode.create(orn,left,
  919. cordconstnode.create(1 shl 8,s32inttype,false));
  920. left := ctypeconvnode.create_internal(left,u16inttype);
  921. typecheckpass(left);
  922. end;
  923. end;
  924. function ttypeconvnode.typecheck_char_to_chararray : tnode;
  925. begin
  926. if resultdef.size <> 1 then
  927. begin
  928. { convert first to string, then to chararray }
  929. inserttypeconv(left,cshortstringtype);
  930. inserttypeconv(left,resultdef);
  931. result:=left;
  932. left := nil;
  933. exit;
  934. end;
  935. result := nil;
  936. end;
  937. function ttypeconvnode.typecheck_char_to_char : tnode;
  938. var
  939. hp : tordconstnode;
  940. begin
  941. result:=nil;
  942. if (left.nodetype=ordconstn) and
  943. ((torddef(resultdef).ordtype<>uchar) or
  944. (torddef(left.resultdef).ordtype<>uwidechar) or
  945. { >= 128 is replaced by '?' currently -> loses information }
  946. (tordconstnode(left).value.uvalue<128)) then
  947. begin
  948. if (torddef(resultdef).ordtype=uchar) and
  949. (torddef(left.resultdef).ordtype=uwidechar) then
  950. begin
  951. hp:=cordconstnode.create(
  952. ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value.uvalue))),
  953. cchartype,true);
  954. result:=hp;
  955. end
  956. else if (torddef(resultdef).ordtype=uwidechar) and
  957. (torddef(left.resultdef).ordtype=uchar) then
  958. begin
  959. hp:=cordconstnode.create(
  960. asciichar2unicode(chr(tordconstnode(left).value.uvalue)),
  961. cwidechartype,true);
  962. result:=hp;
  963. end
  964. else
  965. internalerror(200105131);
  966. exit;
  967. end;
  968. end;
  969. function ttypeconvnode.typecheck_int_to_int : tnode;
  970. var
  971. v : TConstExprInt;
  972. begin
  973. result:=nil;
  974. if left.nodetype=ordconstn then
  975. begin
  976. v:=tordconstnode(left).value;
  977. if is_currency(resultdef) then
  978. v:=v*10000;
  979. if (resultdef.typ=pointerdef) then
  980. result:=cpointerconstnode.create(TConstPtrUInt(v.uvalue),resultdef)
  981. else
  982. begin
  983. if is_currency(left.resultdef) then
  984. v:=v div 10000;
  985. result:=cordconstnode.create(v,resultdef,false);
  986. end;
  987. end
  988. else if left.nodetype=pointerconstn then
  989. begin
  990. v:=tpointerconstnode(left).value;
  991. if (resultdef.typ=pointerdef) then
  992. result:=cpointerconstnode.create(v.uvalue,resultdef)
  993. else
  994. begin
  995. if is_currency(resultdef) then
  996. v:=v*10000;
  997. result:=cordconstnode.create(v,resultdef,false);
  998. end;
  999. end
  1000. else
  1001. begin
  1002. { multiply by 10000 for currency. We need to use getcopy to pass
  1003. the argument because the current node is always disposed. Only
  1004. inserting the multiply in the left node is not possible because
  1005. it'll get in an infinite loop to convert int->currency }
  1006. if is_currency(resultdef) then
  1007. begin
  1008. result:=caddnode.create(muln,getcopy,cordconstnode.create(10000,resultdef,false));
  1009. include(result.flags,nf_is_currency);
  1010. end
  1011. else if is_currency(left.resultdef) then
  1012. begin
  1013. result:=cmoddivnode.create(divn,getcopy,cordconstnode.create(10000,resultdef,false));
  1014. include(result.flags,nf_is_currency);
  1015. end;
  1016. end;
  1017. end;
  1018. function ttypeconvnode.typecheck_int_to_real : tnode;
  1019. var
  1020. rv : bestreal;
  1021. begin
  1022. result:=nil;
  1023. if left.nodetype=ordconstn then
  1024. begin
  1025. rv:=tordconstnode(left).value;
  1026. if is_currency(resultdef) then
  1027. rv:=rv*10000.0
  1028. else if is_currency(left.resultdef) then
  1029. rv:=rv/10000.0;
  1030. result:=crealconstnode.create(rv,resultdef);
  1031. end
  1032. else
  1033. begin
  1034. { multiply by 10000 for currency. We need to use getcopy to pass
  1035. the argument because the current node is always disposed. Only
  1036. inserting the multiply in the left node is not possible because
  1037. it'll get in an infinite loop to convert int->currency }
  1038. if is_currency(resultdef) then
  1039. begin
  1040. result:=caddnode.create(muln,getcopy,crealconstnode.create(10000.0,resultdef));
  1041. include(result.flags,nf_is_currency);
  1042. end
  1043. else if is_currency(left.resultdef) then
  1044. begin
  1045. result:=caddnode.create(slashn,getcopy,crealconstnode.create(10000.0,resultdef));
  1046. include(result.flags,nf_is_currency);
  1047. end;
  1048. end;
  1049. end;
  1050. function ttypeconvnode.typecheck_real_to_currency : tnode;
  1051. begin
  1052. if not is_currency(resultdef) then
  1053. internalerror(200304221);
  1054. result:=nil;
  1055. left:=caddnode.create(muln,left,crealconstnode.create(10000.0,left.resultdef));
  1056. include(left.flags,nf_is_currency);
  1057. typecheckpass(left);
  1058. { Convert constants directly, else call Round() }
  1059. if left.nodetype=realconstn then
  1060. result:=cordconstnode.create(round(trealconstnode(left).value_real),resultdef,false)
  1061. else
  1062. begin
  1063. result:=ccallnode.createinternres('fpc_round_real',
  1064. ccallparanode.create(left,nil),resultdef);
  1065. left:=nil;
  1066. end;
  1067. end;
  1068. function ttypeconvnode.typecheck_real_to_real : tnode;
  1069. begin
  1070. result:=nil;
  1071. if is_currency(left.resultdef) and not(is_currency(resultdef)) then
  1072. begin
  1073. left:=caddnode.create(slashn,left,crealconstnode.create(10000.0,left.resultdef));
  1074. include(left.flags,nf_is_currency);
  1075. typecheckpass(left);
  1076. end
  1077. else
  1078. if is_currency(resultdef) and not(is_currency(left.resultdef)) then
  1079. begin
  1080. left:=caddnode.create(muln,left,crealconstnode.create(10000.0,left.resultdef));
  1081. include(left.flags,nf_is_currency);
  1082. typecheckpass(left);
  1083. end;
  1084. end;
  1085. function ttypeconvnode.typecheck_cchar_to_pchar : tnode;
  1086. begin
  1087. result:=nil;
  1088. if is_pwidechar(resultdef) then
  1089. inserttypeconv(left,cwidestringtype)
  1090. else
  1091. inserttypeconv(left,cshortstringtype);
  1092. { evaluate again, reset resultdef so the convert_typ
  1093. will be calculated again and cstring_to_pchar will
  1094. be used for futher conversion }
  1095. convtype:=tc_none;
  1096. result:=pass_typecheck;
  1097. end;
  1098. function ttypeconvnode.typecheck_cstring_to_pchar : tnode;
  1099. begin
  1100. result:=nil;
  1101. if is_pwidechar(resultdef) then
  1102. inserttypeconv(left,cwidestringtype)
  1103. else
  1104. if is_pchar(resultdef) and
  1105. is_widestring(left.resultdef) then
  1106. begin
  1107. inserttypeconv(left,cansistringtype);
  1108. { the second pass of second_cstring_to_pchar expects a }
  1109. { strinconstn, but this may become a call to the }
  1110. { widestring manager in case left contains "high ascii" }
  1111. if (left.nodetype<>stringconstn) then
  1112. begin
  1113. result:=left;
  1114. left:=nil;
  1115. end;
  1116. end;
  1117. end;
  1118. function ttypeconvnode.typecheck_cstring_to_int : tnode;
  1119. var
  1120. fcc : cardinal;
  1121. pb : pbyte;
  1122. begin
  1123. result:=nil;
  1124. if left.nodetype<>stringconstn then
  1125. internalerror(200510012);
  1126. if tstringconstnode(left).len=4 then
  1127. begin
  1128. pb:=pbyte(tstringconstnode(left).value_str);
  1129. fcc:=(pb[0] shl 24) or (pb[1] shl 16) or (pb[2] shl 8) or pb[3];
  1130. result:=cordconstnode.create(fcc,u32inttype,false);
  1131. end
  1132. else
  1133. CGMessage2(type_e_illegal_type_conversion,left.resultdef.GetTypeName,resultdef.GetTypeName);
  1134. end;
  1135. function ttypeconvnode.typecheck_arrayconstructor_to_set : tnode;
  1136. var
  1137. hp : tnode;
  1138. begin
  1139. result:=nil;
  1140. if left.nodetype<>arrayconstructorn then
  1141. internalerror(5546);
  1142. { remove typeconv node }
  1143. hp:=left;
  1144. left:=nil;
  1145. { create a set constructor tree }
  1146. arrayconstructor_to_set(hp);
  1147. result:=hp;
  1148. end;
  1149. function ttypeconvnode.typecheck_set_to_set : tnode;
  1150. begin
  1151. result:=nil;
  1152. { constant sets can be converted by changing the type only }
  1153. if (left.nodetype=setconstn) then
  1154. begin
  1155. left.resultdef:=resultdef;
  1156. result:=left;
  1157. left:=nil;
  1158. exit;
  1159. end;
  1160. end;
  1161. function ttypeconvnode.typecheck_pchar_to_string : tnode;
  1162. begin
  1163. result := ccallnode.createinternres(
  1164. 'fpc_pchar_to_'+tstringdef(resultdef).stringtypname,
  1165. ccallparanode.create(left,nil),resultdef);
  1166. left := nil;
  1167. end;
  1168. function ttypeconvnode.typecheck_interface_to_guid : tnode;
  1169. begin
  1170. if assigned(tobjectdef(left.resultdef).iidguid) then
  1171. result:=cguidconstnode.create(tobjectdef(left.resultdef).iidguid^);
  1172. end;
  1173. function ttypeconvnode.typecheck_dynarray_to_openarray : tnode;
  1174. begin
  1175. { a dynamic array is a pointer to an array, so to convert it to }
  1176. { an open array, we have to dereference it (JM) }
  1177. result := ctypeconvnode.create_internal(left,voidpointertype);
  1178. typecheckpass(result);
  1179. { left is reused }
  1180. left := nil;
  1181. result := cderefnode.create(result);
  1182. include(result.flags,nf_no_checkpointer);
  1183. result.resultdef := resultdef;
  1184. end;
  1185. function ttypeconvnode.typecheck_pwchar_to_string : tnode;
  1186. begin
  1187. result := ccallnode.createinternres(
  1188. 'fpc_pwidechar_to_'+tstringdef(resultdef).stringtypname,
  1189. ccallparanode.create(left,nil),resultdef);
  1190. left := nil;
  1191. end;
  1192. function ttypeconvnode.typecheck_variant_to_dynarray : tnode;
  1193. begin
  1194. result := ccallnode.createinternres(
  1195. 'fpc_variant_to_dynarray',
  1196. ccallparanode.create(caddrnode.create_internal(crttinode.create(tstoreddef(resultdef),initrtti,rdt_normal)),
  1197. ccallparanode.create(left,nil)
  1198. ),resultdef);
  1199. typecheckpass(result);
  1200. left:=nil;
  1201. end;
  1202. function ttypeconvnode.typecheck_dynarray_to_variant : tnode;
  1203. begin
  1204. result := ccallnode.createinternres(
  1205. 'fpc_dynarray_to_variant',
  1206. ccallparanode.create(caddrnode.create_internal(crttinode.create(tstoreddef(left.resultdef),initrtti,rdt_normal)),
  1207. ccallparanode.create(ctypeconvnode.create_explicit(left,voidpointertype),nil)
  1208. ),resultdef);
  1209. typecheckpass(result);
  1210. left:=nil;
  1211. end;
  1212. function ttypeconvnode.typecheck_variant_to_interface : tnode;
  1213. begin
  1214. if tobjectdef(resultdef).is_related(tobjectdef(search_system_type('IDISPATCH').typedef)) then
  1215. result := ccallnode.createinternres(
  1216. 'fpc_variant_to_idispatch',
  1217. ccallparanode.create(left,nil)
  1218. ,resultdef)
  1219. else
  1220. result := ccallnode.createinternres(
  1221. 'fpc_variant_to_interface',
  1222. ccallparanode.create(left,nil)
  1223. ,resultdef);
  1224. typecheckpass(result);
  1225. left:=nil;
  1226. end;
  1227. function ttypeconvnode.typecheck_interface_to_variant : tnode;
  1228. begin
  1229. if tobjectdef(left.resultdef).is_related(tobjectdef(search_system_type('IDISPATCH').typedef)) then
  1230. result := ccallnode.createinternres(
  1231. 'fpc_idispatch_to_variant',
  1232. ccallparanode.create(left,nil)
  1233. ,resultdef)
  1234. else
  1235. result := ccallnode.createinternres(
  1236. 'fpc_interface_to_variant',
  1237. ccallparanode.create(left,nil)
  1238. ,resultdef);
  1239. typecheckpass(result);
  1240. left:=nil;
  1241. end;
  1242. function ttypeconvnode.typecheck_variant_to_enum : tnode;
  1243. begin
  1244. result := ctypeconvnode.create_internal(left,sinttype);
  1245. result := ctypeconvnode.create_internal(result,resultdef);
  1246. typecheckpass(result);
  1247. { left is reused }
  1248. left := nil;
  1249. end;
  1250. function ttypeconvnode.typecheck_enum_to_variant : tnode;
  1251. begin
  1252. result := ctypeconvnode.create_internal(left,sinttype);
  1253. result := ctypeconvnode.create_internal(result,cvarianttype);
  1254. typecheckpass(result);
  1255. { left is reused }
  1256. left := nil;
  1257. end;
  1258. function ttypeconvnode.typecheck_array_2_dynarray : tnode;
  1259. var
  1260. newstatement : tstatementnode;
  1261. temp : ttempcreatenode;
  1262. temp2 : ttempcreatenode;
  1263. begin
  1264. { create statements with call to getmem+initialize }
  1265. result:=internalstatements(newstatement);
  1266. { create temp for result }
  1267. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  1268. addstatement(newstatement,temp);
  1269. { get temp for array of lengths }
  1270. temp2:=ctempcreatenode.create(sinttype,sinttype.size,tt_persistent,false);
  1271. addstatement(newstatement,temp2);
  1272. { one dimensional }
  1273. addstatement(newstatement,cassignmentnode.create(
  1274. ctemprefnode.create_offset(temp2,0),
  1275. cordconstnode.create
  1276. (tarraydef(left.resultdef).highrange+1,s32inttype,true)));
  1277. { create call to fpc_dynarr_setlength }
  1278. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',
  1279. ccallparanode.create(caddrnode.create_internal
  1280. (ctemprefnode.create(temp2)),
  1281. ccallparanode.create(cordconstnode.create
  1282. (1,s32inttype,true),
  1283. ccallparanode.create(caddrnode.create_internal
  1284. (crttinode.create(tstoreddef(resultdef),initrtti,rdt_normal)),
  1285. ccallparanode.create(
  1286. ctypeconvnode.create_internal(
  1287. ctemprefnode.create(temp),voidpointertype),
  1288. nil))))
  1289. ));
  1290. addstatement(newstatement,ctempdeletenode.create(temp2));
  1291. { copy ... }
  1292. addstatement(newstatement,cassignmentnode.create(
  1293. ctypeconvnode.create_internal(cderefnode.create(ctypeconvnode.create_internal(ctemprefnode.create(temp),voidpointertype)),left.resultdef),
  1294. left
  1295. ));
  1296. { left is reused }
  1297. left:=nil;
  1298. { the last statement should return the value as
  1299. location and type, this is done be referencing the
  1300. temp and converting it first from a persistent temp to
  1301. normal temp }
  1302. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1303. addstatement(newstatement,ctemprefnode.create(temp));
  1304. end;
  1305. procedure copyparasym(p:TObject;arg:pointer);
  1306. var
  1307. newparast : TSymtable absolute arg;
  1308. vs : tparavarsym;
  1309. begin
  1310. if tsym(p).typ<>paravarsym then
  1311. exit;
  1312. with tparavarsym(p) do
  1313. begin
  1314. vs:=tparavarsym.create(realname,paranr,varspez,vardef,varoptions);
  1315. vs.defaultconstsym:=defaultconstsym;
  1316. newparast.insert(vs);
  1317. end;
  1318. end;
  1319. function ttypeconvnode.typecheck_proc_to_procvar : tnode;
  1320. var
  1321. pd : tabstractprocdef;
  1322. begin
  1323. result:=nil;
  1324. pd:=tabstractprocdef(left.resultdef);
  1325. { create procvardef }
  1326. resultdef:=tprocvardef.create(pd.parast.symtablelevel);
  1327. tprocvardef(resultdef).proctypeoption:=pd.proctypeoption;
  1328. tprocvardef(resultdef).proccalloption:=pd.proccalloption;
  1329. tprocvardef(resultdef).procoptions:=pd.procoptions;
  1330. tprocvardef(resultdef).returndef:=pd.returndef;
  1331. { method ? then set the methodpointer flag }
  1332. if (pd.owner.symtabletype=ObjectSymtable) then
  1333. include(tprocvardef(resultdef).procoptions,po_methodpointer);
  1334. { was it a local procedure? }
  1335. if (pd.owner.symtabletype=localsymtable) then
  1336. include(tprocvardef(resultdef).procoptions,po_local);
  1337. { only need the address of the method? this is needed
  1338. for @tobject.create. In this case there will be a loadn without
  1339. a methodpointer. }
  1340. if (left.nodetype=loadn) and
  1341. not assigned(tloadnode(left).left) then
  1342. include(tprocvardef(resultdef).procoptions,po_addressonly);
  1343. { Add parameters use only references, we don't need to keep the
  1344. parast. We use the parast from the original function to calculate
  1345. our parameter data and reset it afterwards }
  1346. pd.parast.SymList.ForEachCall(@copyparasym,tprocvardef(resultdef).parast);
  1347. tprocvardef(resultdef).calcparas;
  1348. end;
  1349. function ttypeconvnode.typecheck_call_helper(c : tconverttype) : tnode;
  1350. const
  1351. resultdefconvert : array[tconverttype] of pointer = (
  1352. {none} nil,
  1353. {equal} nil,
  1354. {not_possible} nil,
  1355. { string_2_string } @ttypeconvnode.typecheck_string_to_string,
  1356. { char_2_string } @ttypeconvnode.typecheck_char_to_string,
  1357. { char_2_chararray } @ttypeconvnode.typecheck_char_to_chararray,
  1358. { pchar_2_string } @ttypeconvnode.typecheck_pchar_to_string,
  1359. { cchar_2_pchar } @ttypeconvnode.typecheck_cchar_to_pchar,
  1360. { cstring_2_pchar } @ttypeconvnode.typecheck_cstring_to_pchar,
  1361. { cstring_2_int } @ttypeconvnode.typecheck_cstring_to_int,
  1362. { ansistring_2_pchar } nil,
  1363. { string_2_chararray } @ttypeconvnode.typecheck_string_to_chararray,
  1364. { chararray_2_string } @ttypeconvnode.typecheck_chararray_to_string,
  1365. { array_2_pointer } nil,
  1366. { pointer_2_array } nil,
  1367. { int_2_int } @ttypeconvnode.typecheck_int_to_int,
  1368. { int_2_bool } nil,
  1369. { bool_2_bool } nil,
  1370. { bool_2_int } nil,
  1371. { real_2_real } @ttypeconvnode.typecheck_real_to_real,
  1372. { int_2_real } @ttypeconvnode.typecheck_int_to_real,
  1373. { real_2_currency } @ttypeconvnode.typecheck_real_to_currency,
  1374. { proc_2_procvar } @ttypeconvnode.typecheck_proc_to_procvar,
  1375. { nil_2_methodprocvar } nil,
  1376. { arrayconstructor_2_set } @ttypeconvnode.typecheck_arrayconstructor_to_set,
  1377. { set_to_set } @ttypeconvnode.typecheck_set_to_set,
  1378. { cord_2_pointer } @ttypeconvnode.typecheck_cord_to_pointer,
  1379. { intf_2_string } nil,
  1380. { intf_2_guid } @ttypeconvnode.typecheck_interface_to_guid,
  1381. { class_2_intf } nil,
  1382. { char_2_char } @ttypeconvnode.typecheck_char_to_char,
  1383. { dynarray_2_openarray} @ttypeconvnode.typecheck_dynarray_to_openarray,
  1384. { pwchar_2_string} @ttypeconvnode.typecheck_pwchar_to_string,
  1385. { variant_2_dynarray} @ttypeconvnode.typecheck_variant_to_dynarray,
  1386. { dynarray_2_variant} @ttypeconvnode.typecheck_dynarray_to_variant,
  1387. { variant_2_enum} @ttypeconvnode.typecheck_variant_to_enum,
  1388. { enum_2_variant} @ttypeconvnode.typecheck_enum_to_variant,
  1389. { variant_2_interface} @ttypeconvnode.typecheck_interface_to_variant,
  1390. { interface_2_variant} @ttypeconvnode.typecheck_variant_to_interface,
  1391. { array_2_dynarray} @ttypeconvnode.typecheck_array_2_dynarray
  1392. );
  1393. type
  1394. tprocedureofobject = function : tnode of object;
  1395. var
  1396. r : packed record
  1397. proc : pointer;
  1398. obj : pointer;
  1399. end;
  1400. begin
  1401. result:=nil;
  1402. { this is a little bit dirty but it works }
  1403. { and should be quite portable too }
  1404. r.proc:=resultdefconvert[c];
  1405. r.obj:=self;
  1406. if assigned(r.proc) then
  1407. result:=tprocedureofobject(r)();
  1408. end;
  1409. function ttypeconvnode.pass_typecheck:tnode;
  1410. var
  1411. hdef : tdef;
  1412. hp : tnode;
  1413. currprocdef : tabstractprocdef;
  1414. aprocdef : tprocdef;
  1415. eq : tequaltype;
  1416. cdoptions : tcompare_defs_options;
  1417. newblock: tblocknode;
  1418. newstatement: tstatementnode;
  1419. tempnode: ttempcreatenode;
  1420. begin
  1421. result:=nil;
  1422. resultdef:=totypedef;
  1423. typecheckpass(left);
  1424. if codegenerror then
  1425. exit;
  1426. { When absolute force tc_equal }
  1427. if (nf_absolute in flags) then
  1428. begin
  1429. convtype:=tc_equal;
  1430. if not(tstoreddef(resultdef).is_intregable) and
  1431. not(tstoreddef(resultdef).is_fpuregable) then
  1432. make_not_regable(left,[ra_addr_regable]);
  1433. exit;
  1434. end;
  1435. { tp procvar support. Skip typecasts to procvar, record or set. Those
  1436. convert on the procvar value. This is used to access the
  1437. fields of a methodpointer }
  1438. if not(nf_load_procvar in flags) and
  1439. not(resultdef.typ in [procvardef,recorddef,setdef]) then
  1440. maybe_call_procvar(left,true);
  1441. { convert array constructors to sets, because there is no conversion
  1442. possible for array constructors }
  1443. if (resultdef.typ<>arraydef) and
  1444. is_array_constructor(left.resultdef) then
  1445. begin
  1446. arrayconstructor_to_set(left);
  1447. typecheckpass(left);
  1448. end;
  1449. if convtype=tc_none then
  1450. begin
  1451. cdoptions:=[cdo_check_operator,cdo_allow_variant];
  1452. if nf_explicit in flags then
  1453. include(cdoptions,cdo_explicit);
  1454. if nf_internal in flags then
  1455. include(cdoptions,cdo_internal);
  1456. eq:=compare_defs_ext(left.resultdef,resultdef,left.nodetype,convtype,aprocdef,cdoptions);
  1457. case eq of
  1458. te_exact,
  1459. te_equal :
  1460. begin
  1461. result := simplify;
  1462. if assigned(result) then
  1463. exit;
  1464. { Only leave when there is no conversion to do.
  1465. We can still need to call a conversion routine,
  1466. like the routine to convert a stringconstnode }
  1467. if convtype in [tc_equal,tc_not_possible] then
  1468. begin
  1469. left.resultdef:=resultdef;
  1470. if (nf_explicit in flags) and (left.nodetype = addrn) then
  1471. include(left.flags, nf_typedaddr);
  1472. result:=left;
  1473. left:=nil;
  1474. exit;
  1475. end;
  1476. end;
  1477. te_convert_l1,
  1478. te_convert_l2,
  1479. te_convert_l3 :
  1480. begin
  1481. result := simplify;
  1482. if assigned(result) then
  1483. exit;
  1484. { nothing to do }
  1485. end;
  1486. te_convert_operator :
  1487. begin
  1488. include(current_procinfo.flags,pi_do_call);
  1489. aprocdef.procsym.IncRefCountBy(1);
  1490. hp:=ccallnode.create(ccallparanode.create(left,nil),Tprocsym(aprocdef.procsym),nil,nil,[]);
  1491. { tell explicitly which def we must use !! (PM) }
  1492. tcallnode(hp).procdefinition:=aprocdef;
  1493. left:=nil;
  1494. result:=hp;
  1495. exit;
  1496. end;
  1497. te_incompatible :
  1498. begin
  1499. { Procedures have a resultdef of voiddef and functions of their
  1500. own resultdef. They will therefore always be incompatible with
  1501. a procvar. Because isconvertable cannot check for procedures we
  1502. use an extra check for them.}
  1503. if (left.nodetype=calln) and
  1504. (tcallnode(left).para_count=0) and
  1505. (resultdef.typ=procvardef) and
  1506. (
  1507. (m_tp_procvar in current_settings.modeswitches) or
  1508. (m_mac_procvar in current_settings.modeswitches)
  1509. ) then
  1510. begin
  1511. if assigned(tcallnode(left).right) then
  1512. begin
  1513. { this is already a procvar, if it is really equal
  1514. is checked below }
  1515. convtype:=tc_equal;
  1516. hp:=tcallnode(left).right.getcopy;
  1517. currprocdef:=tabstractprocdef(hp.resultdef);
  1518. end
  1519. else
  1520. begin
  1521. convtype:=tc_proc_2_procvar;
  1522. currprocdef:=Tprocsym(Tcallnode(left).symtableprocentry).Find_procdef_byprocvardef(Tprocvardef(resultdef));
  1523. hp:=cloadnode.create_procvar(tprocsym(tcallnode(left).symtableprocentry),
  1524. tprocdef(currprocdef),tcallnode(left).symtableproc);
  1525. if (tcallnode(left).symtableprocentry.owner.symtabletype=ObjectSymtable) then
  1526. begin
  1527. if assigned(tcallnode(left).methodpointer) then
  1528. tloadnode(hp).set_mp(tcallnode(left).methodpointer.getcopy)
  1529. else
  1530. tloadnode(hp).set_mp(load_self_node);
  1531. end;
  1532. typecheckpass(hp);
  1533. end;
  1534. left.free;
  1535. left:=hp;
  1536. { Now check if the procedure we are going to assign to
  1537. the procvar, is compatible with the procvar's type }
  1538. if not(nf_explicit in flags) and
  1539. (proc_to_procvar_equal(currprocdef,tprocvardef(resultdef))=te_incompatible) then
  1540. IncompatibleTypes(left.resultdef,resultdef);
  1541. exit;
  1542. end;
  1543. { Handle explicit type conversions }
  1544. if nf_explicit in flags then
  1545. begin
  1546. { do common tc_equal cast }
  1547. convtype:=tc_equal;
  1548. { ordinal constants can be resized to 1,2,4,8 bytes }
  1549. if (left.nodetype=ordconstn) then
  1550. begin
  1551. { Insert typeconv for ordinal to the correct size first on left, after
  1552. that the other conversion can be done }
  1553. hdef:=nil;
  1554. case longint(resultdef.size) of
  1555. 1 :
  1556. hdef:=s8inttype;
  1557. 2 :
  1558. hdef:=s16inttype;
  1559. 4 :
  1560. hdef:=s32inttype;
  1561. 8 :
  1562. hdef:=s64inttype;
  1563. end;
  1564. { we need explicit, because it can also be an enum }
  1565. if assigned(hdef) then
  1566. inserttypeconv_internal(left,hdef)
  1567. else
  1568. CGMessage2(type_e_illegal_type_conversion,left.resultdef.GetTypeName,resultdef.GetTypeName);
  1569. end;
  1570. { check if the result could be in a register }
  1571. if (not(tstoreddef(resultdef).is_intregable) and
  1572. not(tstoreddef(resultdef).is_fpuregable)) or
  1573. ((left.resultdef.typ = floatdef) and
  1574. (resultdef.typ <> floatdef)) then
  1575. make_not_regable(left,[ra_addr_regable]);
  1576. { class/interface to class/interface, with checkobject support }
  1577. if is_class_or_interface(resultdef) and
  1578. is_class_or_interface(left.resultdef) then
  1579. begin
  1580. { check if the types are related }
  1581. if not(nf_internal in flags) and
  1582. (not(tobjectdef(left.resultdef).is_related(tobjectdef(resultdef)))) and
  1583. (not(tobjectdef(resultdef).is_related(tobjectdef(left.resultdef)))) then
  1584. begin
  1585. { Give an error when typecasting class to interface, this is compatible
  1586. with delphi }
  1587. if is_interface(resultdef) and
  1588. not is_interface(left.resultdef) then
  1589. CGMessage2(type_e_classes_not_related,
  1590. FullTypeName(left.resultdef,resultdef),
  1591. FullTypeName(resultdef,left.resultdef))
  1592. else
  1593. CGMessage2(type_w_classes_not_related,
  1594. FullTypeName(left.resultdef,resultdef),
  1595. FullTypeName(resultdef,left.resultdef))
  1596. end;
  1597. { Add runtime check? }
  1598. if (cs_check_object in current_settings.localswitches) and
  1599. not(nf_internal in flags) then
  1600. begin
  1601. { we can translate the typeconvnode to 'as' when
  1602. typecasting to a class or interface }
  1603. { we need to make sure the result can still be
  1604. passed as a var parameter }
  1605. newblock:=internalstatements(newstatement);
  1606. if (valid_for_var(left,false)) then
  1607. begin
  1608. tempnode:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  1609. addstatement(newstatement,tempnode);
  1610. addstatement(newstatement,cassignmentnode.create(
  1611. ctemprefnode.create(tempnode),
  1612. caddrnode.create_internal(left)));
  1613. left:=ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),left.resultdef);
  1614. end
  1615. else
  1616. begin
  1617. tempnode:=ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,true);
  1618. addstatement(newstatement,tempnode);
  1619. addstatement(newstatement,cassignmentnode.create(
  1620. ctemprefnode.create(tempnode),
  1621. left));
  1622. left:=ctemprefnode.create(tempnode);
  1623. end;
  1624. addstatement(newstatement,casnode.create(left.getcopy,cloadvmtaddrnode.create(ctypenode.create(resultdef))));
  1625. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
  1626. addstatement(newstatement,ctypeconvnode.create_internal(left,resultdef));
  1627. left:=nil;
  1628. result:=newblock;
  1629. exit;
  1630. end;
  1631. end
  1632. else
  1633. begin
  1634. { only if the same size or formal def, and }
  1635. { don't allow type casting of constants to }
  1636. { structured types }
  1637. if not(
  1638. (left.resultdef.typ=formaldef) or
  1639. (
  1640. not(is_open_array(left.resultdef)) and
  1641. not(is_array_constructor(left.resultdef)) and
  1642. (left.resultdef.size=resultdef.size) and
  1643. { disallow casts of const nodes }
  1644. (not is_constnode(left) or
  1645. { however, there are some exceptions }
  1646. (not(resultdef.typ in [arraydef,recorddef,setdef,stringdef,
  1647. filedef,variantdef,objectdef]) or
  1648. is_class_or_interface(resultdef) or
  1649. { the softfloat code generates casts <const. float> to record }
  1650. (nf_internal in flags)
  1651. ))
  1652. ) or
  1653. (
  1654. is_void(left.resultdef) and
  1655. (left.nodetype=derefn)
  1656. )
  1657. ) then
  1658. CGMessage2(type_e_illegal_type_conversion,left.resultdef.GetTypeName,resultdef.GetTypeName);
  1659. end;
  1660. end
  1661. else
  1662. IncompatibleTypes(left.resultdef,resultdef);
  1663. end;
  1664. else
  1665. internalerror(200211231);
  1666. end;
  1667. end;
  1668. { Give hint or warning for unportable code, exceptions are
  1669. - typecasts from constants
  1670. - void }
  1671. if not(nf_internal in flags) and
  1672. (left.nodetype<>ordconstn) and
  1673. not(is_void(left.resultdef)) and
  1674. (((left.resultdef.typ=orddef) and
  1675. (resultdef.typ in [pointerdef,procvardef,classrefdef])) or
  1676. ((resultdef.typ=orddef) and
  1677. (left.resultdef.typ in [pointerdef,procvardef,classrefdef]))) then
  1678. begin
  1679. { Give a warning when sizes don't match, because then info will be lost }
  1680. if left.resultdef.size=resultdef.size then
  1681. CGMessage(type_h_pointer_to_longint_conv_not_portable)
  1682. else
  1683. CGMessage(type_w_pointer_to_longint_conv_not_portable);
  1684. end;
  1685. result := simplify;
  1686. if assigned(result) then
  1687. exit;
  1688. { now call the resultdef helper to do constant folding }
  1689. result:=typecheck_call_helper(convtype);
  1690. end;
  1691. function ttypeconvnode.simplify: tnode;
  1692. var
  1693. hp: tnode;
  1694. begin
  1695. result := nil;
  1696. { Constant folding and other node transitions to
  1697. remove the typeconv node }
  1698. case left.nodetype of
  1699. realconstn :
  1700. begin
  1701. if (convtype = tc_real_2_currency) then
  1702. result := typecheck_real_to_currency
  1703. else if (convtype = tc_real_2_real) then
  1704. result := typecheck_real_to_real
  1705. else
  1706. exit;
  1707. if not(assigned(result)) then
  1708. begin
  1709. result := left;
  1710. left := nil;
  1711. end;
  1712. if (result.nodetype = realconstn) then
  1713. begin
  1714. hp:=result;
  1715. result:=crealconstnode.create(trealconstnode(hp).value_real,resultdef);
  1716. if ([nf_explicit,nf_internal] * flags <> []) then
  1717. include(result.flags, nf_explicit);
  1718. hp.free;
  1719. end;
  1720. end;
  1721. niln :
  1722. begin
  1723. { nil to ordinal node }
  1724. if (resultdef.typ=orddef) then
  1725. begin
  1726. hp:=cordconstnode.create(0,resultdef,true);
  1727. if ([nf_explicit,nf_internal] * flags <> []) then
  1728. include(hp.flags, nf_explicit);
  1729. result:=hp;
  1730. exit;
  1731. end
  1732. else
  1733. { fold nil to any pointer type }
  1734. if (resultdef.typ=pointerdef) then
  1735. begin
  1736. hp:=cnilnode.create;
  1737. hp.resultdef:=resultdef;
  1738. if ([nf_explicit,nf_internal] * flags <> []) then
  1739. include(hp.flags, nf_explicit);
  1740. result:=hp;
  1741. exit;
  1742. end
  1743. else
  1744. { remove typeconv after niln, but not when the result is a
  1745. methodpointer. The typeconv of the methodpointer will then
  1746. take care of updateing size of niln to OS_64 }
  1747. if not((resultdef.typ=procvardef) and
  1748. (po_methodpointer in tprocvardef(resultdef).procoptions)) then
  1749. begin
  1750. left.resultdef:=resultdef;
  1751. if ([nf_explicit,nf_internal] * flags <> []) then
  1752. include(left.flags, nf_explicit);
  1753. result:=left;
  1754. left:=nil;
  1755. exit;
  1756. end;
  1757. end;
  1758. ordconstn :
  1759. begin
  1760. { ordinal contants can be directly converted }
  1761. { but not char to char because it is a widechar to char or via versa }
  1762. { which needs extra code to do the code page transistion }
  1763. { constant ordinal to pointer }
  1764. if (resultdef.typ=pointerdef) and
  1765. (convtype<>tc_cchar_2_pchar) then
  1766. begin
  1767. hp:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value.uvalue),resultdef);
  1768. if ([nf_explicit,nf_internal] * flags <> []) then
  1769. include(hp.flags, nf_explicit);
  1770. result:=hp;
  1771. exit;
  1772. end
  1773. else if is_ordinal(resultdef) and
  1774. not(convtype=tc_char_2_char) then
  1775. begin
  1776. { replace the resultdef and recheck the range }
  1777. if ([nf_explicit,nf_internal] * flags <> []) then
  1778. include(left.flags, nf_explicit);
  1779. testrange(resultdef,tordconstnode(left).value,(nf_explicit in flags));
  1780. left.resultdef:=resultdef;
  1781. result:=left;
  1782. left:=nil;
  1783. exit;
  1784. end;
  1785. end;
  1786. pointerconstn :
  1787. begin
  1788. { pointerconstn to any pointer is folded too }
  1789. if (resultdef.typ=pointerdef) then
  1790. begin
  1791. left.resultdef:=resultdef;
  1792. if ([nf_explicit,nf_internal] * flags <> []) then
  1793. include(left.flags, nf_explicit);
  1794. result:=left;
  1795. left:=nil;
  1796. exit;
  1797. end
  1798. { constant pointer to ordinal }
  1799. else if is_ordinal(resultdef) then
  1800. begin
  1801. hp:=cordconstnode.create(TConstExprInt(tpointerconstnode(left).value),
  1802. resultdef,not(nf_explicit in flags));
  1803. if ([nf_explicit,nf_internal] * flags <> []) then
  1804. include(hp.flags, nf_explicit);
  1805. result:=hp;
  1806. exit;
  1807. end;
  1808. end;
  1809. end;
  1810. end;
  1811. procedure Ttypeconvnode.mark_write;
  1812. begin
  1813. left.mark_write;
  1814. end;
  1815. function ttypeconvnode.first_cord_to_pointer : tnode;
  1816. begin
  1817. result:=nil;
  1818. internalerror(200104043);
  1819. end;
  1820. function ttypeconvnode.first_int_to_int : tnode;
  1821. begin
  1822. first_int_to_int:=nil;
  1823. expectloc:=left.expectloc;
  1824. if not is_void(left.resultdef) then
  1825. begin
  1826. if (left.expectloc<>LOC_REGISTER) and
  1827. (resultdef.size>left.resultdef.size) then
  1828. expectloc:=LOC_REGISTER
  1829. else
  1830. if (left.expectloc=LOC_CREGISTER) and
  1831. (resultdef.size<left.resultdef.size) then
  1832. expectloc:=LOC_REGISTER;
  1833. end;
  1834. {$ifndef cpu64bit}
  1835. if is_64bit(resultdef) then
  1836. registersint:=max(registersint,2)
  1837. else
  1838. {$endif cpu64bit}
  1839. registersint:=max(registersint,1);
  1840. end;
  1841. function ttypeconvnode.first_cstring_to_pchar : tnode;
  1842. begin
  1843. result:=nil;
  1844. registersint:=1;
  1845. expectloc:=LOC_REGISTER;
  1846. end;
  1847. function ttypeconvnode.first_cstring_to_int : tnode;
  1848. begin
  1849. result:=nil;
  1850. internalerror(200510014);
  1851. end;
  1852. function ttypeconvnode.first_string_to_chararray : tnode;
  1853. begin
  1854. first_string_to_chararray:=nil;
  1855. expectloc:=left.expectloc;
  1856. end;
  1857. function ttypeconvnode.first_char_to_string : tnode;
  1858. begin
  1859. first_char_to_string:=nil;
  1860. expectloc:=LOC_REFERENCE;
  1861. end;
  1862. function ttypeconvnode.first_nothing : tnode;
  1863. begin
  1864. first_nothing:=nil;
  1865. end;
  1866. function ttypeconvnode.first_array_to_pointer : tnode;
  1867. begin
  1868. first_array_to_pointer:=nil;
  1869. if registersint<1 then
  1870. registersint:=1;
  1871. expectloc:=LOC_REGISTER;
  1872. end;
  1873. function ttypeconvnode.first_int_to_real: tnode;
  1874. var
  1875. fname: string[32];
  1876. begin
  1877. if target_info.system in system_wince then
  1878. begin
  1879. { converting a 64bit integer to a float requires a helper }
  1880. if is_64bitint(left.resultdef) or
  1881. is_currency(left.resultdef) then
  1882. begin
  1883. { hack to avoid double division by 10000, as it's
  1884. already done by typecheckpass.resultdef_int_to_real }
  1885. if is_currency(left.resultdef) then
  1886. left.resultdef := s64inttype;
  1887. if is_signed(left.resultdef) then
  1888. fname:='I64TO'
  1889. else
  1890. fname:='UI64TO';
  1891. end
  1892. else
  1893. { other integers are supposed to be 32 bit }
  1894. begin
  1895. if is_signed(left.resultdef) then
  1896. fname:='ITO'
  1897. else
  1898. fname:='UTO';
  1899. firstpass(left);
  1900. end;
  1901. if tfloatdef(resultdef).floattype=s64real then
  1902. fname:=fname+'D'
  1903. else
  1904. fname:=fname+'S';
  1905. result:=ccallnode.createintern(fname,ccallparanode.create(
  1906. left,nil));
  1907. left:=nil;
  1908. firstpass(result);
  1909. exit;
  1910. end
  1911. else
  1912. begin
  1913. { converting a 64bit integer to a float requires a helper }
  1914. if is_64bitint(left.resultdef) or
  1915. is_currency(left.resultdef) then
  1916. begin
  1917. { hack to avoid double division by 10000, as it's
  1918. already done by typecheckpass.resultdef_int_to_real }
  1919. if is_currency(left.resultdef) then
  1920. left.resultdef := s64inttype;
  1921. if is_signed(left.resultdef) then
  1922. fname:='int64_to_'
  1923. else
  1924. { we can't do better currently }
  1925. fname:='int64_to_';
  1926. end
  1927. else
  1928. { other integers are supposed to be 32 bit }
  1929. begin
  1930. if is_signed(left.resultdef) then
  1931. fname:='int32_to_'
  1932. else
  1933. { we can't do better currently }
  1934. fname:='int32_to_';
  1935. firstpass(left);
  1936. end;
  1937. if tfloatdef(resultdef).floattype=s64real then
  1938. fname:=fname+'float64'
  1939. else
  1940. fname:=fname+'float32';
  1941. result:=ctypeconvnode.create_internal(ccallnode.createintern(fname,ccallparanode.create(
  1942. left,nil)),resultdef);
  1943. left:=nil;
  1944. firstpass(result);
  1945. exit;
  1946. end;
  1947. end;
  1948. function ttypeconvnode.first_real_to_real : tnode;
  1949. begin
  1950. {$ifdef cpufpemu}
  1951. if cs_fp_emulation in current_settings.moduleswitches then
  1952. begin
  1953. if target_info.system in system_wince then
  1954. begin
  1955. case tfloatdef(left.resultdef).floattype of
  1956. s32real:
  1957. case tfloatdef(resultdef).floattype of
  1958. s64real:
  1959. result:=ccallnode.createintern('STOD',ccallparanode.create(left,nil));
  1960. s32real:
  1961. begin
  1962. result:=left;
  1963. left:=nil;
  1964. end;
  1965. else
  1966. internalerror(2005082704);
  1967. end;
  1968. s64real:
  1969. case tfloatdef(resultdef).floattype of
  1970. s32real:
  1971. result:=ccallnode.createintern('DTOS',ccallparanode.create(left,nil));
  1972. s64real:
  1973. begin
  1974. result:=left;
  1975. left:=nil;
  1976. end;
  1977. else
  1978. internalerror(2005082703);
  1979. end;
  1980. else
  1981. internalerror(2005082702);
  1982. end;
  1983. left:=nil;
  1984. firstpass(result);
  1985. exit;
  1986. end
  1987. else
  1988. begin
  1989. case tfloatdef(left.resultdef).floattype of
  1990. s32real:
  1991. case tfloatdef(resultdef).floattype of
  1992. s64real:
  1993. result:=ctypeconvnode.create_explicit(ccallnode.createintern('float32_to_float64',ccallparanode.create(
  1994. ctypeconvnode.create_internal(left,search_system_type('FLOAT32REC').typedef),nil)),resultdef);
  1995. s32real:
  1996. begin
  1997. result:=left;
  1998. left:=nil;
  1999. end;
  2000. else
  2001. internalerror(200610151);
  2002. end;
  2003. s64real:
  2004. case tfloatdef(resultdef).floattype of
  2005. s32real:
  2006. result:=ctypeconvnode.create_explicit(ccallnode.createintern('float64_to_float32',ccallparanode.create(
  2007. ctypeconvnode.create_internal(left,search_system_type('FLOAT64').typedef),nil)),resultdef);
  2008. s64real:
  2009. begin
  2010. result:=left;
  2011. left:=nil;
  2012. end;
  2013. else
  2014. internalerror(200610152);
  2015. end;
  2016. else
  2017. internalerror(200610153);
  2018. end;
  2019. left:=nil;
  2020. firstpass(result);
  2021. exit;
  2022. end;
  2023. end
  2024. else
  2025. {$endif cpufpemu}
  2026. begin
  2027. first_real_to_real:=nil;
  2028. if registersfpu<1 then
  2029. registersfpu:=1;
  2030. expectloc:=LOC_FPUREGISTER;
  2031. end;
  2032. end;
  2033. function ttypeconvnode.first_pointer_to_array : tnode;
  2034. begin
  2035. first_pointer_to_array:=nil;
  2036. if registersint<1 then
  2037. registersint:=1;
  2038. expectloc:=LOC_REFERENCE;
  2039. end;
  2040. function ttypeconvnode.first_cchar_to_pchar : tnode;
  2041. begin
  2042. first_cchar_to_pchar:=nil;
  2043. internalerror(200104021);
  2044. end;
  2045. function ttypeconvnode.first_bool_to_int : tnode;
  2046. begin
  2047. first_bool_to_int:=nil;
  2048. { byte(boolean) or word(wordbool) or longint(longbool) must
  2049. be accepted for var parameters }
  2050. if (nf_explicit in flags) and
  2051. (left.resultdef.size=resultdef.size) and
  2052. (left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  2053. exit;
  2054. { when converting to 64bit, first convert to a 32bit int and then }
  2055. { convert to a 64bit int (only necessary for 32bit processors) (JM) }
  2056. if resultdef.size > sizeof(aint) then
  2057. begin
  2058. result := ctypeconvnode.create_internal(left,u32inttype);
  2059. result := ctypeconvnode.create(result,resultdef);
  2060. left := nil;
  2061. firstpass(result);
  2062. exit;
  2063. end;
  2064. expectloc:=LOC_REGISTER;
  2065. if registersint<1 then
  2066. registersint:=1;
  2067. end;
  2068. function ttypeconvnode.first_int_to_bool : tnode;
  2069. begin
  2070. first_int_to_bool:=nil;
  2071. { byte(boolean) or word(wordbool) or longint(longbool) must
  2072. be accepted for var parameters }
  2073. if (nf_explicit in flags) and
  2074. (left.resultdef.size=resultdef.size) and
  2075. (left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  2076. exit;
  2077. expectloc:=LOC_REGISTER;
  2078. { need if bool to bool !!
  2079. not very nice !!
  2080. insertypeconv(left,s32inttype);
  2081. left.explizit:=true;
  2082. firstpass(left); }
  2083. if registersint<1 then
  2084. registersint:=1;
  2085. end;
  2086. function ttypeconvnode.first_bool_to_bool : tnode;
  2087. begin
  2088. first_bool_to_bool:=nil;
  2089. if (left.expectloc in [LOC_FLAGS,LOC_JUMP]) then
  2090. expectloc := left.expectloc
  2091. else
  2092. begin
  2093. expectloc:=LOC_REGISTER;
  2094. if registersint<1 then
  2095. registersint:=1;
  2096. end;
  2097. end;
  2098. function ttypeconvnode.first_char_to_char : tnode;
  2099. var
  2100. fname: string[18];
  2101. begin
  2102. if (torddef(resultdef).ordtype=uchar) and
  2103. (torddef(left.resultdef).ordtype=uwidechar) then
  2104. fname := 'fpc_wchar_to_char'
  2105. else if (torddef(resultdef).ordtype=uwidechar) and
  2106. (torddef(left.resultdef).ordtype=uchar) then
  2107. fname := 'fpc_char_to_wchar'
  2108. else
  2109. internalerror(2007081201);
  2110. result := ccallnode.createintern(fname,ccallparanode.create(left,nil));
  2111. left:=nil;
  2112. firstpass(result);
  2113. end;
  2114. function ttypeconvnode.first_proc_to_procvar : tnode;
  2115. begin
  2116. first_proc_to_procvar:=nil;
  2117. { if we take the address of a nested function, it'll }
  2118. { probably be used in a foreach() construct and then }
  2119. { the parent needs a stackframe }
  2120. if (tprocdef(left.resultdef).parast.symtablelevel>=normal_function_level) then
  2121. include(current_procinfo.flags,pi_needs_stackframe);
  2122. if tabstractprocdef(resultdef).is_addressonly then
  2123. begin
  2124. registersint:=left.registersint;
  2125. if registersint<1 then
  2126. registersint:=1;
  2127. expectloc:=LOC_REGISTER;
  2128. end
  2129. else
  2130. begin
  2131. if not(left.expectloc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  2132. CGMessage(parser_e_illegal_expression);
  2133. registersint:=left.registersint;
  2134. expectloc:=left.expectloc
  2135. end
  2136. end;
  2137. function ttypeconvnode.first_nil_to_methodprocvar : tnode;
  2138. begin
  2139. first_nil_to_methodprocvar:=nil;
  2140. registersint:=0;
  2141. expectloc:=LOC_REFERENCE;
  2142. end;
  2143. function ttypeconvnode.first_set_to_set : tnode;
  2144. var
  2145. newstatement : tstatementnode;
  2146. temp : ttempcreatenode;
  2147. begin
  2148. { in theory, we should do range checking here,
  2149. but Delphi doesn't do it either (FK) }
  2150. if left.nodetype=setconstn then
  2151. begin
  2152. left.resultdef:=resultdef;
  2153. result:=left;
  2154. end
  2155. { equal sets for the code generator? }
  2156. else if (left.resultdef.size=resultdef.size) and
  2157. (tsetdef(left.resultdef).setbase=tsetdef(resultdef).setbase) then
  2158. {$warning This causes wrong (but Delphi-compatible) results for disjoint subsets}
  2159. { e.g., this prints true because of this:
  2160. var
  2161. sa: set of 1..2;
  2162. sb: set of 5..6;
  2163. b: byte;
  2164. begin
  2165. b:=1;
  2166. sa:=[1..2];
  2167. sb:=sa;
  2168. writeln(b in sb);
  2169. end.
  2170. }
  2171. result:=left
  2172. else
  2173. // if is_varset(resultdef) then
  2174. begin
  2175. result:=internalstatements(newstatement);
  2176. { in case left is a smallset expression, it can be an addn or so. }
  2177. { fpc_varset_load expects a formal const parameter, which doesn't }
  2178. { accept set addn's -> assign to a temp first and pass the temp }
  2179. if not(left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  2180. begin
  2181. temp:=ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,false);
  2182. addstatement(newstatement,temp);
  2183. { temp := left }
  2184. addstatement(newstatement,cassignmentnode.create(
  2185. ctemprefnode.create(temp),left));
  2186. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2187. addstatement(newstatement,ctemprefnode.create(temp));
  2188. left:=result;
  2189. firstpass(left);
  2190. { recreate the result's internalstatements list }
  2191. result:=internalstatements(newstatement);
  2192. end;
  2193. { create temp for result }
  2194. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2195. addstatement(newstatement,temp);
  2196. addstatement(newstatement,ccallnode.createintern('fpc_varset_load',
  2197. ccallparanode.create(cordconstnode.create(tsetdef(left.resultdef).setbase div 8 - tsetdef(resultdef).setbase div 8,sinttype,false),
  2198. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2199. ccallparanode.create(ctemprefnode.create(temp),
  2200. ccallparanode.create(cordconstnode.create(left.resultdef.size,sinttype,false),
  2201. ccallparanode.create(left,nil))))))
  2202. );
  2203. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2204. addstatement(newstatement,ctemprefnode.create(temp));
  2205. end;
  2206. {
  2207. else
  2208. begin
  2209. srsym:=search_system_type('FPC_SMALL_SET');
  2210. result :=
  2211. ccallnode.createinternres('fpc_set_load_small',
  2212. ccallparanode.create(ctypeconvnode.create_internal(left,srsym.typedef),nil),resultdef);
  2213. end;
  2214. }
  2215. { reused }
  2216. left:=nil;
  2217. end;
  2218. function ttypeconvnode.first_ansistring_to_pchar : tnode;
  2219. begin
  2220. first_ansistring_to_pchar:=nil;
  2221. expectloc:=LOC_REGISTER;
  2222. if registersint<1 then
  2223. registersint:=1;
  2224. end;
  2225. function ttypeconvnode.first_arrayconstructor_to_set : tnode;
  2226. begin
  2227. first_arrayconstructor_to_set:=nil;
  2228. internalerror(200104022);
  2229. end;
  2230. function ttypeconvnode.first_class_to_intf : tnode;
  2231. begin
  2232. first_class_to_intf:=nil;
  2233. expectloc:=LOC_REGISTER;
  2234. if registersint<1 then
  2235. registersint:=1;
  2236. end;
  2237. function ttypeconvnode._first_int_to_int : tnode;
  2238. begin
  2239. result:=first_int_to_int;
  2240. end;
  2241. function ttypeconvnode._first_cstring_to_pchar : tnode;
  2242. begin
  2243. result:=first_cstring_to_pchar;
  2244. end;
  2245. function ttypeconvnode._first_cstring_to_int : tnode;
  2246. begin
  2247. result:=first_cstring_to_int;
  2248. end;
  2249. function ttypeconvnode._first_string_to_chararray : tnode;
  2250. begin
  2251. result:=first_string_to_chararray;
  2252. end;
  2253. function ttypeconvnode._first_char_to_string : tnode;
  2254. begin
  2255. result:=first_char_to_string;
  2256. end;
  2257. function ttypeconvnode._first_nothing : tnode;
  2258. begin
  2259. result:=first_nothing;
  2260. end;
  2261. function ttypeconvnode._first_array_to_pointer : tnode;
  2262. begin
  2263. result:=first_array_to_pointer;
  2264. end;
  2265. function ttypeconvnode._first_int_to_real : tnode;
  2266. begin
  2267. result:=first_int_to_real;
  2268. end;
  2269. function ttypeconvnode._first_real_to_real : tnode;
  2270. begin
  2271. result:=first_real_to_real;
  2272. end;
  2273. function ttypeconvnode._first_pointer_to_array : tnode;
  2274. begin
  2275. result:=first_pointer_to_array;
  2276. end;
  2277. function ttypeconvnode._first_cchar_to_pchar : tnode;
  2278. begin
  2279. result:=first_cchar_to_pchar;
  2280. end;
  2281. function ttypeconvnode._first_bool_to_int : tnode;
  2282. begin
  2283. result:=first_bool_to_int;
  2284. end;
  2285. function ttypeconvnode._first_int_to_bool : tnode;
  2286. begin
  2287. result:=first_int_to_bool;
  2288. end;
  2289. function ttypeconvnode._first_bool_to_bool : tnode;
  2290. begin
  2291. result:=first_bool_to_bool;
  2292. end;
  2293. function ttypeconvnode._first_proc_to_procvar : tnode;
  2294. begin
  2295. result:=first_proc_to_procvar;
  2296. end;
  2297. function ttypeconvnode._first_nil_to_methodprocvar : tnode;
  2298. begin
  2299. result:=first_nil_to_methodprocvar;
  2300. end;
  2301. function ttypeconvnode._first_set_to_set : tnode;
  2302. begin
  2303. result:=first_set_to_set;
  2304. end;
  2305. function ttypeconvnode._first_cord_to_pointer : tnode;
  2306. begin
  2307. result:=first_cord_to_pointer;
  2308. end;
  2309. function ttypeconvnode._first_ansistring_to_pchar : tnode;
  2310. begin
  2311. result:=first_ansistring_to_pchar;
  2312. end;
  2313. function ttypeconvnode._first_arrayconstructor_to_set : tnode;
  2314. begin
  2315. result:=first_arrayconstructor_to_set;
  2316. end;
  2317. function ttypeconvnode._first_class_to_intf : tnode;
  2318. begin
  2319. result:=first_class_to_intf;
  2320. end;
  2321. function ttypeconvnode._first_char_to_char : tnode;
  2322. begin
  2323. result:=first_char_to_char;
  2324. end;
  2325. function ttypeconvnode.first_call_helper(c : tconverttype) : tnode;
  2326. const
  2327. firstconvert : array[tconverttype] of pointer = (
  2328. nil, { none }
  2329. @ttypeconvnode._first_nothing, {equal}
  2330. @ttypeconvnode._first_nothing, {not_possible}
  2331. nil, { removed in typecheck_string_to_string }
  2332. @ttypeconvnode._first_char_to_string,
  2333. @ttypeconvnode._first_nothing, { char_2_chararray, needs nothing extra }
  2334. nil, { removed in typecheck_chararray_to_string }
  2335. @ttypeconvnode._first_cchar_to_pchar,
  2336. @ttypeconvnode._first_cstring_to_pchar,
  2337. @ttypeconvnode._first_cstring_to_int,
  2338. @ttypeconvnode._first_ansistring_to_pchar,
  2339. @ttypeconvnode._first_string_to_chararray,
  2340. nil, { removed in typecheck_chararray_to_string }
  2341. @ttypeconvnode._first_array_to_pointer,
  2342. @ttypeconvnode._first_pointer_to_array,
  2343. @ttypeconvnode._first_int_to_int,
  2344. @ttypeconvnode._first_int_to_bool,
  2345. @ttypeconvnode._first_bool_to_bool,
  2346. @ttypeconvnode._first_bool_to_int,
  2347. @ttypeconvnode._first_real_to_real,
  2348. @ttypeconvnode._first_int_to_real,
  2349. nil, { removed in typecheck_real_to_currency }
  2350. @ttypeconvnode._first_proc_to_procvar,
  2351. @ttypeconvnode._first_nil_to_methodprocvar,
  2352. @ttypeconvnode._first_arrayconstructor_to_set,
  2353. @ttypeconvnode._first_set_to_set,
  2354. @ttypeconvnode._first_cord_to_pointer,
  2355. @ttypeconvnode._first_nothing,
  2356. @ttypeconvnode._first_nothing,
  2357. @ttypeconvnode._first_class_to_intf,
  2358. @ttypeconvnode._first_char_to_char,
  2359. @ttypeconvnode._first_nothing,
  2360. @ttypeconvnode._first_nothing,
  2361. nil,
  2362. nil,
  2363. nil,
  2364. nil,
  2365. nil,
  2366. nil,
  2367. nil
  2368. );
  2369. type
  2370. tprocedureofobject = function : tnode of object;
  2371. var
  2372. r : packed record
  2373. proc : pointer;
  2374. obj : pointer;
  2375. end;
  2376. begin
  2377. { this is a little bit dirty but it works }
  2378. { and should be quite portable too }
  2379. r.proc:=firstconvert[c];
  2380. r.obj:=self;
  2381. if not assigned(r.proc) then
  2382. internalerror(200312081);
  2383. first_call_helper:=tprocedureofobject(r)()
  2384. end;
  2385. function ttypeconvnode.pass_1 : tnode;
  2386. begin
  2387. result:=nil;
  2388. firstpass(left);
  2389. if codegenerror then
  2390. exit;
  2391. { load the value_str from the left part }
  2392. registersint:=left.registersint;
  2393. registersfpu:=left.registersfpu;
  2394. {$ifdef SUPPORT_MMX}
  2395. registersmmx:=left.registersmmx;
  2396. {$endif}
  2397. expectloc:=left.expectloc;
  2398. result:=first_call_helper(convtype);
  2399. end;
  2400. function ttypeconvnode.assign_allowed:boolean;
  2401. begin
  2402. result:=(convtype=tc_equal) or
  2403. { typecasting from void is always allowed }
  2404. is_void(left.resultdef) or
  2405. (left.resultdef.typ=formaldef) or
  2406. { int 2 int with same size reuses same location, or for
  2407. tp7 mode also allow size < orignal size }
  2408. (
  2409. (convtype=tc_int_2_int) and
  2410. (
  2411. (resultdef.size=left.resultdef.size) or
  2412. ((m_tp7 in current_settings.modeswitches) and
  2413. (resultdef.size<left.resultdef.size))
  2414. )
  2415. ) or
  2416. { int 2 bool/bool 2 int, explicit typecast, see also nx86cnv }
  2417. ((convtype in [tc_int_2_bool,tc_bool_2_int]) and
  2418. (nf_explicit in flags) and
  2419. (resultdef.size=left.resultdef.size));
  2420. { When using only a part of the value it can't be in a register since
  2421. that will load the value in a new register first }
  2422. if (resultdef.size<left.resultdef.size) then
  2423. make_not_regable(left,[ra_addr_regable]);
  2424. end;
  2425. function ttypeconvnode.docompare(p: tnode) : boolean;
  2426. begin
  2427. docompare :=
  2428. inherited docompare(p) and
  2429. (convtype = ttypeconvnode(p).convtype);
  2430. end;
  2431. procedure ttypeconvnode._second_int_to_int;
  2432. begin
  2433. second_int_to_int;
  2434. end;
  2435. procedure ttypeconvnode._second_string_to_string;
  2436. begin
  2437. second_string_to_string;
  2438. end;
  2439. procedure ttypeconvnode._second_cstring_to_pchar;
  2440. begin
  2441. second_cstring_to_pchar;
  2442. end;
  2443. procedure ttypeconvnode._second_cstring_to_int;
  2444. begin
  2445. second_cstring_to_int;
  2446. end;
  2447. procedure ttypeconvnode._second_string_to_chararray;
  2448. begin
  2449. second_string_to_chararray;
  2450. end;
  2451. procedure ttypeconvnode._second_array_to_pointer;
  2452. begin
  2453. second_array_to_pointer;
  2454. end;
  2455. procedure ttypeconvnode._second_pointer_to_array;
  2456. begin
  2457. second_pointer_to_array;
  2458. end;
  2459. procedure ttypeconvnode._second_chararray_to_string;
  2460. begin
  2461. second_chararray_to_string;
  2462. end;
  2463. procedure ttypeconvnode._second_char_to_string;
  2464. begin
  2465. second_char_to_string;
  2466. end;
  2467. procedure ttypeconvnode._second_int_to_real;
  2468. begin
  2469. second_int_to_real;
  2470. end;
  2471. procedure ttypeconvnode._second_real_to_real;
  2472. begin
  2473. second_real_to_real;
  2474. end;
  2475. procedure ttypeconvnode._second_cord_to_pointer;
  2476. begin
  2477. second_cord_to_pointer;
  2478. end;
  2479. procedure ttypeconvnode._second_proc_to_procvar;
  2480. begin
  2481. second_proc_to_procvar;
  2482. end;
  2483. procedure ttypeconvnode._second_nil_to_methodprocvar;
  2484. begin
  2485. second_nil_to_methodprocvar;
  2486. end;
  2487. procedure ttypeconvnode._second_bool_to_int;
  2488. begin
  2489. second_bool_to_int;
  2490. end;
  2491. procedure ttypeconvnode._second_int_to_bool;
  2492. begin
  2493. second_int_to_bool;
  2494. end;
  2495. procedure ttypeconvnode._second_bool_to_bool;
  2496. begin
  2497. second_bool_to_bool;
  2498. end;
  2499. procedure ttypeconvnode._second_set_to_set;
  2500. begin
  2501. second_set_to_set;
  2502. end;
  2503. procedure ttypeconvnode._second_ansistring_to_pchar;
  2504. begin
  2505. second_ansistring_to_pchar;
  2506. end;
  2507. procedure ttypeconvnode._second_class_to_intf;
  2508. begin
  2509. second_class_to_intf;
  2510. end;
  2511. procedure ttypeconvnode._second_char_to_char;
  2512. begin
  2513. second_char_to_char;
  2514. end;
  2515. procedure ttypeconvnode._second_nothing;
  2516. begin
  2517. second_nothing;
  2518. end;
  2519. procedure ttypeconvnode.second_call_helper(c : tconverttype);
  2520. const
  2521. secondconvert : array[tconverttype] of pointer = (
  2522. @ttypeconvnode._second_nothing, {none}
  2523. @ttypeconvnode._second_nothing, {equal}
  2524. @ttypeconvnode._second_nothing, {not_possible}
  2525. @ttypeconvnode._second_nothing, {second_string_to_string, handled in resultdef pass }
  2526. @ttypeconvnode._second_char_to_string,
  2527. @ttypeconvnode._second_nothing, {char_to_charray}
  2528. @ttypeconvnode._second_nothing, { pchar_to_string, handled in resultdef pass }
  2529. @ttypeconvnode._second_nothing, {cchar_to_pchar}
  2530. @ttypeconvnode._second_cstring_to_pchar,
  2531. @ttypeconvnode._second_cstring_to_int,
  2532. @ttypeconvnode._second_ansistring_to_pchar,
  2533. @ttypeconvnode._second_string_to_chararray,
  2534. @ttypeconvnode._second_nothing, { chararray_to_string, handled in resultdef pass }
  2535. @ttypeconvnode._second_array_to_pointer,
  2536. @ttypeconvnode._second_pointer_to_array,
  2537. @ttypeconvnode._second_int_to_int,
  2538. @ttypeconvnode._second_int_to_bool,
  2539. @ttypeconvnode._second_bool_to_bool,
  2540. @ttypeconvnode._second_bool_to_int,
  2541. @ttypeconvnode._second_real_to_real,
  2542. @ttypeconvnode._second_int_to_real,
  2543. @ttypeconvnode._second_nothing, { real_to_currency, handled in resultdef pass }
  2544. @ttypeconvnode._second_proc_to_procvar,
  2545. @ttypeconvnode._second_nil_to_methodprocvar,
  2546. @ttypeconvnode._second_nothing, { arrayconstructor_to_set }
  2547. @ttypeconvnode._second_nothing, { second_set_to_set, handled in first pass }
  2548. @ttypeconvnode._second_cord_to_pointer,
  2549. @ttypeconvnode._second_nothing, { interface 2 string }
  2550. @ttypeconvnode._second_nothing, { interface 2 guid }
  2551. @ttypeconvnode._second_class_to_intf,
  2552. @ttypeconvnode._second_char_to_char,
  2553. @ttypeconvnode._second_nothing, { dynarray_2_openarray }
  2554. @ttypeconvnode._second_nothing, { pwchar_2_string }
  2555. @ttypeconvnode._second_nothing, { variant_2_dynarray }
  2556. @ttypeconvnode._second_nothing, { dynarray_2_variant}
  2557. @ttypeconvnode._second_nothing, { variant_2_enum }
  2558. @ttypeconvnode._second_nothing, { enum_2_variant }
  2559. @ttypeconvnode._second_nothing, { variant_2_interface }
  2560. @ttypeconvnode._second_nothing, { interface_2_variant }
  2561. @ttypeconvnode._second_nothing { array_2_dynarray }
  2562. );
  2563. type
  2564. tprocedureofobject = procedure of object;
  2565. var
  2566. r : packed record
  2567. proc : pointer;
  2568. obj : pointer;
  2569. end;
  2570. begin
  2571. { this is a little bit dirty but it works }
  2572. { and should be quite portable too }
  2573. r.proc:=secondconvert[c];
  2574. r.obj:=self;
  2575. tprocedureofobject(r)();
  2576. end;
  2577. {*****************************************************************************
  2578. TISNODE
  2579. *****************************************************************************}
  2580. constructor tisnode.create(l,r : tnode);
  2581. begin
  2582. inherited create(isn,l,r);
  2583. end;
  2584. function tisnode.pass_typecheck:tnode;
  2585. var
  2586. paras: tcallparanode;
  2587. begin
  2588. result:=nil;
  2589. typecheckpass(left);
  2590. typecheckpass(right);
  2591. set_varstate(left,vs_read,[vsf_must_be_valid]);
  2592. set_varstate(right,vs_read,[vsf_must_be_valid]);
  2593. if codegenerror then
  2594. exit;
  2595. if (right.resultdef.typ=classrefdef) then
  2596. begin
  2597. { left must be a class }
  2598. if is_class(left.resultdef) then
  2599. begin
  2600. { the operands must be related }
  2601. if (not(tobjectdef(left.resultdef).is_related(
  2602. tobjectdef(tclassrefdef(right.resultdef).pointeddef)))) and
  2603. (not(tobjectdef(tclassrefdef(right.resultdef).pointeddef).is_related(
  2604. tobjectdef(left.resultdef)))) then
  2605. CGMessage2(type_e_classes_not_related,left.resultdef.typename,
  2606. tclassrefdef(right.resultdef).pointeddef.typename);
  2607. end
  2608. else
  2609. CGMessage1(type_e_class_type_expected,left.resultdef.typename);
  2610. { call fpc_do_is helper }
  2611. paras := ccallparanode.create(
  2612. left,
  2613. ccallparanode.create(
  2614. right,nil));
  2615. result := ccallnode.createintern('fpc_do_is',paras);
  2616. left := nil;
  2617. right := nil;
  2618. end
  2619. else if is_interface(right.resultdef) then
  2620. begin
  2621. { left is a class }
  2622. if is_class(left.resultdef) then
  2623. begin
  2624. { the class must implement the interface }
  2625. if tobjectdef(left.resultdef).find_implemented_interface(tobjectdef(right.resultdef))=nil then
  2626. CGMessage2(type_e_classes_not_related,
  2627. FullTypeName(left.resultdef,right.resultdef),
  2628. FullTypeName(right.resultdef,left.resultdef))
  2629. end
  2630. { left is an interface }
  2631. else if is_interface(left.resultdef) then
  2632. begin
  2633. { the operands must be related }
  2634. if (not(tobjectdef(left.resultdef).is_related(tobjectdef(right.resultdef)))) and
  2635. (not(tobjectdef(right.resultdef).is_related(tobjectdef(left.resultdef)))) then
  2636. CGMessage2(type_e_classes_not_related,
  2637. FullTypeName(left.resultdef,right.resultdef),
  2638. FullTypeName(right.resultdef,left.resultdef));
  2639. end
  2640. else
  2641. CGMessage1(type_e_class_type_expected,left.resultdef.typename);
  2642. { call fpc_do_is helper }
  2643. paras := ccallparanode.create(
  2644. left,
  2645. ccallparanode.create(
  2646. right,nil));
  2647. result := ccallnode.createintern('fpc_do_is',paras);
  2648. left := nil;
  2649. right := nil;
  2650. end
  2651. else
  2652. CGMessage1(type_e_class_or_interface_type_expected,right.resultdef.typename);
  2653. resultdef:=booltype;
  2654. end;
  2655. function tisnode.pass_1 : tnode;
  2656. begin
  2657. internalerror(200204254);
  2658. result:=nil;
  2659. end;
  2660. { dummy pass_2, it will never be called, but we need one since }
  2661. { you can't instantiate an abstract class }
  2662. procedure tisnode.pass_generate_code;
  2663. begin
  2664. end;
  2665. {*****************************************************************************
  2666. TASNODE
  2667. *****************************************************************************}
  2668. constructor tasnode.create(l,r : tnode);
  2669. begin
  2670. inherited create(asn,l,r);
  2671. call := nil;
  2672. end;
  2673. destructor tasnode.destroy;
  2674. begin
  2675. call.free;
  2676. inherited destroy;
  2677. end;
  2678. function tasnode.pass_typecheck:tnode;
  2679. var
  2680. hp : tnode;
  2681. begin
  2682. result:=nil;
  2683. typecheckpass(right);
  2684. typecheckpass(left);
  2685. set_varstate(right,vs_read,[vsf_must_be_valid]);
  2686. set_varstate(left,vs_read,[vsf_must_be_valid]);
  2687. if codegenerror then
  2688. exit;
  2689. if (right.resultdef.typ=classrefdef) then
  2690. begin
  2691. { left must be a class }
  2692. if is_class(left.resultdef) then
  2693. begin
  2694. { the operands must be related }
  2695. if (not(tobjectdef(left.resultdef).is_related(
  2696. tobjectdef(tclassrefdef(right.resultdef).pointeddef)))) and
  2697. (not(tobjectdef(tclassrefdef(right.resultdef).pointeddef).is_related(
  2698. tobjectdef(left.resultdef)))) then
  2699. CGMessage2(type_e_classes_not_related,
  2700. FullTypeName(left.resultdef,tclassrefdef(right.resultdef).pointeddef),
  2701. FullTypeName(tclassrefdef(right.resultdef).pointeddef,left.resultdef));
  2702. end
  2703. else
  2704. CGMessage1(type_e_class_type_expected,left.resultdef.typename);
  2705. resultdef:=tclassrefdef(right.resultdef).pointeddef;
  2706. end
  2707. else if is_interface(right.resultdef) then
  2708. begin
  2709. { left is a class }
  2710. if not(is_class(left.resultdef) or
  2711. is_interfacecom(left.resultdef)) then
  2712. CGMessage1(type_e_class_or_cominterface_type_expected,left.resultdef.typename);
  2713. resultdef:=right.resultdef;
  2714. { load the GUID of the interface }
  2715. if (right.nodetype=typen) then
  2716. begin
  2717. if assigned(tobjectdef(right.resultdef).iidguid) then
  2718. begin
  2719. hp:=cguidconstnode.create(tobjectdef(right.resultdef).iidguid^);
  2720. right.free;
  2721. right:=hp;
  2722. end
  2723. else
  2724. internalerror(200206282);
  2725. typecheckpass(right);
  2726. end;
  2727. end
  2728. else
  2729. CGMessage1(type_e_class_or_interface_type_expected,right.resultdef.typename);
  2730. end;
  2731. function tasnode.dogetcopy: tnode;
  2732. begin
  2733. result := inherited dogetcopy;
  2734. if assigned(call) then
  2735. tasnode(result).call := call.getcopy
  2736. else
  2737. tasnode(result).call := nil;
  2738. end;
  2739. function tasnode.pass_1 : tnode;
  2740. var
  2741. procname: string;
  2742. begin
  2743. result:=nil;
  2744. if not assigned(call) then
  2745. begin
  2746. if is_class(left.resultdef) and
  2747. (right.resultdef.typ=classrefdef) then
  2748. call := ccallnode.createinternres('fpc_do_as',
  2749. ccallparanode.create(left,ccallparanode.create(right,nil)),
  2750. resultdef)
  2751. else
  2752. begin
  2753. if is_class(left.resultdef) then
  2754. procname := 'fpc_class_as_intf'
  2755. else
  2756. procname := 'fpc_intf_as';
  2757. call := ccallnode.createintern(procname,
  2758. ccallparanode.create(right,ccallparanode.create(left,nil)));
  2759. call := ctypeconvnode.create_internal(call,resultdef);
  2760. end;
  2761. left := nil;
  2762. right := nil;
  2763. firstpass(call);
  2764. if codegenerror then
  2765. exit;
  2766. expectloc:=call.expectloc;
  2767. registersint:=call.registersint;
  2768. registersfpu:=call.registersfpu;
  2769. {$ifdef SUPPORT_MMX}
  2770. registersmmx:=call.registersmmx;
  2771. {$endif SUPPORT_MMX}
  2772. end;
  2773. end;
  2774. begin
  2775. ctypeconvnode:=ttypeconvnode;
  2776. casnode:=tasnode;
  2777. cisnode:=tisnode;
  2778. end.