ncnv.pas 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134
  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,
  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 to tordconstnode(p3).value 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);
  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,constsethi);
  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 < low(longint)) or
  728. (tordconstnode(left).value > 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 < low(int64)) or
  734. (tordconstnode(left).value > 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),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. ((tstringdef(left.resultdef).stringtype<>st_widestring) or
  829. (tstringdef(resultdef).stringtype=st_widestring) or
  830. { non-ascii chars would be replaced with '?' -> loses info }
  831. not hasnonasciichars(pcompilerwidestring(tstringconstnode(left).value_str))) then
  832. begin
  833. tstringconstnode(left).changestringtype(resultdef);
  834. result:=left;
  835. left:=nil;
  836. end
  837. else
  838. begin
  839. { get the correct procedure name }
  840. procname := 'fpc_'+tstringdef(left.resultdef).stringtypname+
  841. '_to_'+tstringdef(resultdef).stringtypname;
  842. { create parameter (and remove left node from typeconvnode }
  843. { since it's reused as parameter) }
  844. stringpara := ccallparanode.create(left,nil);
  845. left := nil;
  846. { when converting to shortstrings, we have to pass high(destination) too }
  847. if (tstringdef(resultdef).stringtype = st_shortstring) then
  848. stringpara.right := ccallparanode.create(cinlinenode.create(
  849. in_high_x,false,self.getcopy),nil);
  850. { and create the callnode }
  851. result := ccallnode.createinternres(procname,stringpara,resultdef);
  852. end;
  853. end;
  854. function ttypeconvnode.typecheck_char_to_string : tnode;
  855. var
  856. procname: string[31];
  857. para : tcallparanode;
  858. hp : tstringconstnode;
  859. ws : pcompilerwidestring;
  860. begin
  861. result:=nil;
  862. { we can't do widechar to ansichar conversions at compile time, since }
  863. { this maps all non-ascii chars to '?' -> loses information }
  864. if (left.nodetype=ordconstn) and
  865. ((tstringdef(resultdef).stringtype=st_widestring) or
  866. (torddef(left.resultdef).ordtype=uchar) or
  867. { >=128 is destroyed }
  868. (tordconstnode(left).value<128)) then
  869. begin
  870. if tstringdef(resultdef).stringtype=st_widestring then
  871. begin
  872. initwidestring(ws);
  873. if torddef(left.resultdef).ordtype=uwidechar then
  874. concatwidestringchar(ws,tcompilerwidechar(tordconstnode(left).value))
  875. else
  876. concatwidestringchar(ws,tcompilerwidechar(chr(tordconstnode(left).value)));
  877. hp:=cstringconstnode.createwstr(ws);
  878. donewidestring(ws);
  879. end
  880. else
  881. begin
  882. if torddef(left.resultdef).ordtype=uwidechar then
  883. hp:=cstringconstnode.createstr(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value)))
  884. else
  885. hp:=cstringconstnode.createstr(chr(tordconstnode(left).value));
  886. tstringconstnode(hp).changestringtype(resultdef);
  887. end;
  888. result:=hp;
  889. end
  890. else
  891. { shortstrings are handled 'inline' (except for widechars) }
  892. if (tstringdef(resultdef).stringtype <> st_shortstring) or
  893. (torddef(left.resultdef).ordtype = uwidechar) then
  894. begin
  895. { create the procname }
  896. if torddef(left.resultdef).ordtype<>uwidechar then
  897. procname := 'fpc_char_to_'
  898. else
  899. procname := 'fpc_wchar_to_';
  900. procname:=procname+tstringdef(resultdef).stringtypname;
  901. { and the parameter }
  902. para := ccallparanode.create(left,nil);
  903. left := nil;
  904. { and finally the call }
  905. result := ccallnode.createinternres(procname,para,resultdef);
  906. end
  907. else
  908. begin
  909. { create word(byte(char) shl 8 or 1) for litte endian machines }
  910. { and word(byte(char) or 256) for big endian machines }
  911. left := ctypeconvnode.create_internal(left,u8inttype);
  912. if (target_info.endian = endian_little) then
  913. left := caddnode.create(orn,
  914. cshlshrnode.create(shln,left,cordconstnode.create(8,s32inttype,false)),
  915. cordconstnode.create(1,s32inttype,false))
  916. else
  917. left := caddnode.create(orn,left,
  918. cordconstnode.create(1 shl 8,s32inttype,false));
  919. left := ctypeconvnode.create_internal(left,u16inttype);
  920. typecheckpass(left);
  921. end;
  922. end;
  923. function ttypeconvnode.typecheck_char_to_chararray : tnode;
  924. begin
  925. if resultdef.size <> 1 then
  926. begin
  927. { convert first to string, then to chararray }
  928. inserttypeconv(left,cshortstringtype);
  929. inserttypeconv(left,resultdef);
  930. result:=left;
  931. left := nil;
  932. exit;
  933. end;
  934. result := nil;
  935. end;
  936. function ttypeconvnode.typecheck_char_to_char : tnode;
  937. var
  938. hp : tordconstnode;
  939. begin
  940. result:=nil;
  941. if (left.nodetype=ordconstn) and
  942. ((torddef(resultdef).ordtype<>uchar) or
  943. (torddef(left.resultdef).ordtype<>uwidechar) or
  944. { >= 128 is replaced by '?' currently -> loses information }
  945. (tordconstnode(left).value<128)) then
  946. begin
  947. if (torddef(resultdef).ordtype=uchar) and
  948. (torddef(left.resultdef).ordtype=uwidechar) then
  949. begin
  950. hp:=cordconstnode.create(
  951. ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value))),
  952. cchartype,true);
  953. result:=hp;
  954. end
  955. else if (torddef(resultdef).ordtype=uwidechar) and
  956. (torddef(left.resultdef).ordtype=uchar) then
  957. begin
  958. hp:=cordconstnode.create(
  959. asciichar2unicode(chr(tordconstnode(left).value)),
  960. cwidechartype,true);
  961. result:=hp;
  962. end
  963. else
  964. internalerror(200105131);
  965. exit;
  966. end;
  967. end;
  968. function ttypeconvnode.typecheck_int_to_int : tnode;
  969. var
  970. v : TConstExprInt;
  971. begin
  972. result:=nil;
  973. if left.nodetype=ordconstn then
  974. begin
  975. v:=tordconstnode(left).value;
  976. if is_currency(resultdef) then
  977. v:=v*10000;
  978. if (resultdef.typ=pointerdef) then
  979. result:=cpointerconstnode.create(TConstPtrUInt(v),resultdef)
  980. else
  981. begin
  982. if is_currency(left.resultdef) then
  983. v:=v div 10000;
  984. result:=cordconstnode.create(v,resultdef,false);
  985. end;
  986. end
  987. else if left.nodetype=pointerconstn then
  988. begin
  989. v:=tpointerconstnode(left).value;
  990. if (resultdef.typ=pointerdef) then
  991. result:=cpointerconstnode.create(v,resultdef)
  992. else
  993. begin
  994. if is_currency(resultdef) then
  995. v:=v*10000;
  996. result:=cordconstnode.create(v,resultdef,false);
  997. end;
  998. end
  999. else
  1000. begin
  1001. { multiply by 10000 for currency. We need to use getcopy to pass
  1002. the argument because the current node is always disposed. Only
  1003. inserting the multiply in the left node is not possible because
  1004. it'll get in an infinite loop to convert int->currency }
  1005. if is_currency(resultdef) then
  1006. begin
  1007. result:=caddnode.create(muln,getcopy,cordconstnode.create(10000,resultdef,false));
  1008. include(result.flags,nf_is_currency);
  1009. end
  1010. else if is_currency(left.resultdef) then
  1011. begin
  1012. result:=cmoddivnode.create(divn,getcopy,cordconstnode.create(10000,resultdef,false));
  1013. include(result.flags,nf_is_currency);
  1014. end;
  1015. end;
  1016. end;
  1017. function ttypeconvnode.typecheck_int_to_real : tnode;
  1018. var
  1019. rv : bestreal;
  1020. begin
  1021. result:=nil;
  1022. if left.nodetype=ordconstn then
  1023. begin
  1024. rv:=tordconstnode(left).value;
  1025. if is_currency(resultdef) then
  1026. rv:=rv*10000.0
  1027. else if is_currency(left.resultdef) then
  1028. rv:=rv/10000.0;
  1029. result:=crealconstnode.create(rv,resultdef);
  1030. end
  1031. else
  1032. begin
  1033. { multiply by 10000 for currency. We need to use getcopy to pass
  1034. the argument because the current node is always disposed. Only
  1035. inserting the multiply in the left node is not possible because
  1036. it'll get in an infinite loop to convert int->currency }
  1037. if is_currency(resultdef) then
  1038. begin
  1039. result:=caddnode.create(muln,getcopy,crealconstnode.create(10000.0,resultdef));
  1040. include(result.flags,nf_is_currency);
  1041. end
  1042. else if is_currency(left.resultdef) then
  1043. begin
  1044. result:=caddnode.create(slashn,getcopy,crealconstnode.create(10000.0,resultdef));
  1045. include(result.flags,nf_is_currency);
  1046. end;
  1047. end;
  1048. end;
  1049. function ttypeconvnode.typecheck_real_to_currency : tnode;
  1050. begin
  1051. if not is_currency(resultdef) then
  1052. internalerror(200304221);
  1053. result:=nil;
  1054. left:=caddnode.create(muln,left,crealconstnode.create(10000.0,left.resultdef));
  1055. include(left.flags,nf_is_currency);
  1056. typecheckpass(left);
  1057. { Convert constants directly, else call Round() }
  1058. if left.nodetype=realconstn then
  1059. result:=cordconstnode.create(round(trealconstnode(left).value_real),resultdef,false)
  1060. else
  1061. begin
  1062. result:=ccallnode.createinternres('fpc_round_real',
  1063. ccallparanode.create(left,nil),resultdef);
  1064. left:=nil;
  1065. end;
  1066. end;
  1067. function ttypeconvnode.typecheck_real_to_real : tnode;
  1068. begin
  1069. result:=nil;
  1070. if is_currency(left.resultdef) and not(is_currency(resultdef)) then
  1071. begin
  1072. left:=caddnode.create(slashn,left,crealconstnode.create(10000.0,left.resultdef));
  1073. include(left.flags,nf_is_currency);
  1074. typecheckpass(left);
  1075. end
  1076. else
  1077. if is_currency(resultdef) and not(is_currency(left.resultdef)) then
  1078. begin
  1079. left:=caddnode.create(muln,left,crealconstnode.create(10000.0,left.resultdef));
  1080. include(left.flags,nf_is_currency);
  1081. typecheckpass(left);
  1082. end;
  1083. end;
  1084. function ttypeconvnode.typecheck_cchar_to_pchar : tnode;
  1085. begin
  1086. result:=nil;
  1087. if is_pwidechar(resultdef) then
  1088. inserttypeconv(left,cwidestringtype)
  1089. else
  1090. inserttypeconv(left,cshortstringtype);
  1091. { evaluate again, reset resultdef so the convert_typ
  1092. will be calculated again and cstring_to_pchar will
  1093. be used for futher conversion }
  1094. convtype:=tc_none;
  1095. result:=pass_typecheck;
  1096. end;
  1097. function ttypeconvnode.typecheck_cstring_to_pchar : tnode;
  1098. begin
  1099. result:=nil;
  1100. if is_pwidechar(resultdef) then
  1101. inserttypeconv(left,cwidestringtype)
  1102. else
  1103. if is_pchar(resultdef) and
  1104. is_widestring(left.resultdef) then
  1105. begin
  1106. inserttypeconv(left,cansistringtype);
  1107. { the second pass of second_cstring_to_pchar expects a }
  1108. { strinconstn, but this may become a call to the }
  1109. { widestring manager in case left contains "high ascii" }
  1110. if (left.nodetype<>stringconstn) then
  1111. begin
  1112. result:=left;
  1113. left:=nil;
  1114. end;
  1115. end;
  1116. end;
  1117. function ttypeconvnode.typecheck_cstring_to_int : tnode;
  1118. var
  1119. fcc : cardinal;
  1120. pb : pbyte;
  1121. begin
  1122. result:=nil;
  1123. if left.nodetype<>stringconstn then
  1124. internalerror(200510012);
  1125. if tstringconstnode(left).len=4 then
  1126. begin
  1127. pb:=pbyte(tstringconstnode(left).value_str);
  1128. fcc:=(pb[0] shl 24) or (pb[1] shl 16) or (pb[2] shl 8) or pb[3];
  1129. result:=cordconstnode.create(fcc,u32inttype,false);
  1130. end
  1131. else
  1132. CGMessage2(type_e_illegal_type_conversion,left.resultdef.GetTypeName,resultdef.GetTypeName);
  1133. end;
  1134. function ttypeconvnode.typecheck_arrayconstructor_to_set : tnode;
  1135. var
  1136. hp : tnode;
  1137. begin
  1138. result:=nil;
  1139. if left.nodetype<>arrayconstructorn then
  1140. internalerror(5546);
  1141. { remove typeconv node }
  1142. hp:=left;
  1143. left:=nil;
  1144. { create a set constructor tree }
  1145. arrayconstructor_to_set(hp);
  1146. result:=hp;
  1147. end;
  1148. function ttypeconvnode.typecheck_set_to_set : tnode;
  1149. begin
  1150. result:=nil;
  1151. { constant sets can be converted by changing the type only }
  1152. if (left.nodetype=setconstn) then
  1153. begin
  1154. left.resultdef:=resultdef;
  1155. result:=left;
  1156. left:=nil;
  1157. exit;
  1158. end;
  1159. end;
  1160. function ttypeconvnode.typecheck_pchar_to_string : tnode;
  1161. begin
  1162. result := ccallnode.createinternres(
  1163. 'fpc_pchar_to_'+tstringdef(resultdef).stringtypname,
  1164. ccallparanode.create(left,nil),resultdef);
  1165. left := nil;
  1166. end;
  1167. function ttypeconvnode.typecheck_interface_to_guid : tnode;
  1168. begin
  1169. if assigned(tobjectdef(left.resultdef).iidguid) then
  1170. result:=cguidconstnode.create(tobjectdef(left.resultdef).iidguid^);
  1171. end;
  1172. function ttypeconvnode.typecheck_dynarray_to_openarray : tnode;
  1173. begin
  1174. { a dynamic array is a pointer to an array, so to convert it to }
  1175. { an open array, we have to dereference it (JM) }
  1176. result := ctypeconvnode.create_internal(left,voidpointertype);
  1177. typecheckpass(result);
  1178. { left is reused }
  1179. left := nil;
  1180. result := cderefnode.create(result);
  1181. include(result.flags,nf_no_checkpointer);
  1182. result.resultdef := resultdef;
  1183. end;
  1184. function ttypeconvnode.typecheck_pwchar_to_string : tnode;
  1185. begin
  1186. result := ccallnode.createinternres(
  1187. 'fpc_pwidechar_to_'+tstringdef(resultdef).stringtypname,
  1188. ccallparanode.create(left,nil),resultdef);
  1189. left := nil;
  1190. end;
  1191. function ttypeconvnode.typecheck_variant_to_dynarray : tnode;
  1192. begin
  1193. result := ccallnode.createinternres(
  1194. 'fpc_variant_to_dynarray',
  1195. ccallparanode.create(caddrnode.create_internal(crttinode.create(tstoreddef(resultdef),initrtti)),
  1196. ccallparanode.create(left,nil)
  1197. ),resultdef);
  1198. typecheckpass(result);
  1199. left:=nil;
  1200. end;
  1201. function ttypeconvnode.typecheck_dynarray_to_variant : tnode;
  1202. begin
  1203. result := ccallnode.createinternres(
  1204. 'fpc_dynarray_to_variant',
  1205. ccallparanode.create(caddrnode.create_internal(crttinode.create(tstoreddef(left.resultdef),initrtti)),
  1206. ccallparanode.create(ctypeconvnode.create_explicit(left,voidpointertype),nil)
  1207. ),resultdef);
  1208. typecheckpass(result);
  1209. left:=nil;
  1210. end;
  1211. function ttypeconvnode.typecheck_variant_to_interface : tnode;
  1212. begin
  1213. if tobjectdef(resultdef).is_related(tobjectdef(search_system_type('IDISPATCH').typedef)) then
  1214. result := ccallnode.createinternres(
  1215. 'fpc_variant_to_idispatch',
  1216. ccallparanode.create(left,nil)
  1217. ,resultdef)
  1218. else
  1219. result := ccallnode.createinternres(
  1220. 'fpc_variant_to_interface',
  1221. ccallparanode.create(left,nil)
  1222. ,resultdef);
  1223. typecheckpass(result);
  1224. left:=nil;
  1225. end;
  1226. function ttypeconvnode.typecheck_interface_to_variant : tnode;
  1227. begin
  1228. if tobjectdef(left.resultdef).is_related(tobjectdef(search_system_type('IDISPATCH').typedef)) then
  1229. result := ccallnode.createinternres(
  1230. 'fpc_idispatch_to_variant',
  1231. ccallparanode.create(left,nil)
  1232. ,resultdef)
  1233. else
  1234. result := ccallnode.createinternres(
  1235. 'fpc_interface_to_variant',
  1236. ccallparanode.create(left,nil)
  1237. ,resultdef);
  1238. typecheckpass(result);
  1239. left:=nil;
  1240. end;
  1241. function ttypeconvnode.typecheck_variant_to_enum : tnode;
  1242. begin
  1243. result := ctypeconvnode.create_internal(left,sinttype);
  1244. result := ctypeconvnode.create_internal(result,resultdef);
  1245. typecheckpass(result);
  1246. { left is reused }
  1247. left := nil;
  1248. end;
  1249. function ttypeconvnode.typecheck_enum_to_variant : tnode;
  1250. begin
  1251. result := ctypeconvnode.create_internal(left,sinttype);
  1252. result := ctypeconvnode.create_internal(result,cvarianttype);
  1253. typecheckpass(result);
  1254. { left is reused }
  1255. left := nil;
  1256. end;
  1257. function ttypeconvnode.typecheck_array_2_dynarray : tnode;
  1258. var
  1259. newstatement : tstatementnode;
  1260. temp : ttempcreatenode;
  1261. temp2 : ttempcreatenode;
  1262. begin
  1263. { create statements with call to getmem+initialize }
  1264. result:=internalstatements(newstatement);
  1265. { create temp for result }
  1266. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  1267. addstatement(newstatement,temp);
  1268. { get temp for array of lengths }
  1269. temp2:=ctempcreatenode.create(sinttype,sinttype.size,tt_persistent,false);
  1270. addstatement(newstatement,temp2);
  1271. { one dimensional }
  1272. addstatement(newstatement,cassignmentnode.create(
  1273. ctemprefnode.create_offset(temp2,0),
  1274. cordconstnode.create
  1275. (tarraydef(left.resultdef).highrange+1,s32inttype,true)));
  1276. { create call to fpc_dynarr_setlength }
  1277. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',
  1278. ccallparanode.create(caddrnode.create_internal
  1279. (ctemprefnode.create(temp2)),
  1280. ccallparanode.create(cordconstnode.create
  1281. (1,s32inttype,true),
  1282. ccallparanode.create(caddrnode.create_internal
  1283. (crttinode.create(tstoreddef(resultdef),initrtti)),
  1284. ccallparanode.create(
  1285. ctypeconvnode.create_internal(
  1286. ctemprefnode.create(temp),voidpointertype),
  1287. nil))))
  1288. ));
  1289. addstatement(newstatement,ctempdeletenode.create(temp2));
  1290. { copy ... }
  1291. addstatement(newstatement,cassignmentnode.create(
  1292. ctypeconvnode.create_internal(cderefnode.create(ctypeconvnode.create_internal(ctemprefnode.create(temp),voidpointertype)),left.resultdef),
  1293. left
  1294. ));
  1295. { left is reused }
  1296. left:=nil;
  1297. { the last statement should return the value as
  1298. location and type, this is done be referencing the
  1299. temp and converting it first from a persistent temp to
  1300. normal temp }
  1301. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1302. addstatement(newstatement,ctemprefnode.create(temp));
  1303. end;
  1304. procedure copyparasym(p:TObject;arg:pointer);
  1305. var
  1306. newparast : TSymtable absolute arg;
  1307. vs : tparavarsym;
  1308. begin
  1309. if tsym(p).typ<>paravarsym then
  1310. exit;
  1311. with tparavarsym(p) do
  1312. begin
  1313. vs:=tparavarsym.create(realname,paranr,varspez,vardef,varoptions);
  1314. vs.defaultconstsym:=defaultconstsym;
  1315. newparast.insert(vs);
  1316. end;
  1317. end;
  1318. function ttypeconvnode.typecheck_proc_to_procvar : tnode;
  1319. var
  1320. pd : tabstractprocdef;
  1321. begin
  1322. result:=nil;
  1323. pd:=tabstractprocdef(left.resultdef);
  1324. { create procvardef }
  1325. resultdef:=tprocvardef.create(pd.parast.symtablelevel);
  1326. tprocvardef(resultdef).proctypeoption:=pd.proctypeoption;
  1327. tprocvardef(resultdef).proccalloption:=pd.proccalloption;
  1328. tprocvardef(resultdef).procoptions:=pd.procoptions;
  1329. tprocvardef(resultdef).returndef:=pd.returndef;
  1330. { method ? then set the methodpointer flag }
  1331. if (pd.owner.symtabletype=ObjectSymtable) then
  1332. include(tprocvardef(resultdef).procoptions,po_methodpointer);
  1333. { was it a local procedure? }
  1334. if (pd.owner.symtabletype=localsymtable) then
  1335. include(tprocvardef(resultdef).procoptions,po_local);
  1336. { only need the address of the method? this is needed
  1337. for @tobject.create. In this case there will be a loadn without
  1338. a methodpointer. }
  1339. if (left.nodetype=loadn) and
  1340. not assigned(tloadnode(left).left) then
  1341. include(tprocvardef(resultdef).procoptions,po_addressonly);
  1342. { Add parameters use only references, we don't need to keep the
  1343. parast. We use the parast from the original function to calculate
  1344. our parameter data and reset it afterwards }
  1345. pd.parast.SymList.ForEachCall(@copyparasym,tprocvardef(resultdef).parast);
  1346. tprocvardef(resultdef).calcparas;
  1347. end;
  1348. function ttypeconvnode.typecheck_call_helper(c : tconverttype) : tnode;
  1349. const
  1350. resultdefconvert : array[tconverttype] of pointer = (
  1351. {none} nil,
  1352. {equal} nil,
  1353. {not_possible} nil,
  1354. { string_2_string } @ttypeconvnode.typecheck_string_to_string,
  1355. { char_2_string } @ttypeconvnode.typecheck_char_to_string,
  1356. { char_2_chararray } @ttypeconvnode.typecheck_char_to_chararray,
  1357. { pchar_2_string } @ttypeconvnode.typecheck_pchar_to_string,
  1358. { cchar_2_pchar } @ttypeconvnode.typecheck_cchar_to_pchar,
  1359. { cstring_2_pchar } @ttypeconvnode.typecheck_cstring_to_pchar,
  1360. { cstring_2_int } @ttypeconvnode.typecheck_cstring_to_int,
  1361. { ansistring_2_pchar } nil,
  1362. { string_2_chararray } @ttypeconvnode.typecheck_string_to_chararray,
  1363. { chararray_2_string } @ttypeconvnode.typecheck_chararray_to_string,
  1364. { array_2_pointer } nil,
  1365. { pointer_2_array } nil,
  1366. { int_2_int } @ttypeconvnode.typecheck_int_to_int,
  1367. { int_2_bool } nil,
  1368. { bool_2_bool } nil,
  1369. { bool_2_int } nil,
  1370. { real_2_real } @ttypeconvnode.typecheck_real_to_real,
  1371. { int_2_real } @ttypeconvnode.typecheck_int_to_real,
  1372. { real_2_currency } @ttypeconvnode.typecheck_real_to_currency,
  1373. { proc_2_procvar } @ttypeconvnode.typecheck_proc_to_procvar,
  1374. { nil_2_methodprocvar } nil,
  1375. { arrayconstructor_2_set } @ttypeconvnode.typecheck_arrayconstructor_to_set,
  1376. { set_to_set } @ttypeconvnode.typecheck_set_to_set,
  1377. { cord_2_pointer } @ttypeconvnode.typecheck_cord_to_pointer,
  1378. { intf_2_string } nil,
  1379. { intf_2_guid } @ttypeconvnode.typecheck_interface_to_guid,
  1380. { class_2_intf } nil,
  1381. { char_2_char } @ttypeconvnode.typecheck_char_to_char,
  1382. { dynarray_2_openarray} @ttypeconvnode.typecheck_dynarray_to_openarray,
  1383. { pwchar_2_string} @ttypeconvnode.typecheck_pwchar_to_string,
  1384. { variant_2_dynarray} @ttypeconvnode.typecheck_variant_to_dynarray,
  1385. { dynarray_2_variant} @ttypeconvnode.typecheck_dynarray_to_variant,
  1386. { variant_2_enum} @ttypeconvnode.typecheck_variant_to_enum,
  1387. { enum_2_variant} @ttypeconvnode.typecheck_enum_to_variant,
  1388. { variant_2_interface} @ttypeconvnode.typecheck_interface_to_variant,
  1389. { interface_2_variant} @ttypeconvnode.typecheck_variant_to_interface,
  1390. { array_2_dynarray} @ttypeconvnode.typecheck_array_2_dynarray
  1391. );
  1392. type
  1393. tprocedureofobject = function : tnode of object;
  1394. var
  1395. r : packed record
  1396. proc : pointer;
  1397. obj : pointer;
  1398. end;
  1399. begin
  1400. result:=nil;
  1401. { this is a little bit dirty but it works }
  1402. { and should be quite portable too }
  1403. r.proc:=resultdefconvert[c];
  1404. r.obj:=self;
  1405. if assigned(r.proc) then
  1406. result:=tprocedureofobject(r)();
  1407. end;
  1408. function ttypeconvnode.pass_typecheck:tnode;
  1409. var
  1410. hdef : tdef;
  1411. hp : tnode;
  1412. currprocdef : tabstractprocdef;
  1413. aprocdef : tprocdef;
  1414. eq : tequaltype;
  1415. cdoptions : tcompare_defs_options;
  1416. newblock: tblocknode;
  1417. newstatement: tstatementnode;
  1418. tempnode: ttempcreatenode;
  1419. begin
  1420. result:=nil;
  1421. resultdef:=totypedef;
  1422. typecheckpass(left);
  1423. if codegenerror then
  1424. exit;
  1425. { When absolute force tc_equal }
  1426. if (nf_absolute in flags) then
  1427. begin
  1428. convtype:=tc_equal;
  1429. if not(tstoreddef(resultdef).is_intregable) and
  1430. not(tstoreddef(resultdef).is_fpuregable) then
  1431. make_not_regable(left,[ra_addr_regable]);
  1432. exit;
  1433. end;
  1434. { tp procvar support. Skip typecasts to procvar, record or set. Those
  1435. convert on the procvar value. This is used to access the
  1436. fields of a methodpointer }
  1437. if not(nf_load_procvar in flags) and
  1438. not(resultdef.typ in [procvardef,recorddef,setdef]) then
  1439. maybe_call_procvar(left,true);
  1440. { convert array constructors to sets, because there is no conversion
  1441. possible for array constructors }
  1442. if (resultdef.typ<>arraydef) and
  1443. is_array_constructor(left.resultdef) then
  1444. begin
  1445. arrayconstructor_to_set(left);
  1446. typecheckpass(left);
  1447. end;
  1448. if convtype=tc_none then
  1449. begin
  1450. cdoptions:=[cdo_check_operator,cdo_allow_variant];
  1451. if nf_explicit in flags then
  1452. include(cdoptions,cdo_explicit);
  1453. if nf_internal in flags then
  1454. include(cdoptions,cdo_internal);
  1455. eq:=compare_defs_ext(left.resultdef,resultdef,left.nodetype,convtype,aprocdef,cdoptions);
  1456. case eq of
  1457. te_exact,
  1458. te_equal :
  1459. begin
  1460. result := simplify;
  1461. if assigned(result) then
  1462. exit;
  1463. { Only leave when there is no conversion to do.
  1464. We can still need to call a conversion routine,
  1465. like the routine to convert a stringconstnode }
  1466. if convtype in [tc_equal,tc_not_possible] then
  1467. begin
  1468. left.resultdef:=resultdef;
  1469. if (nf_explicit in flags) and (left.nodetype = addrn) then
  1470. include(left.flags, nf_typedaddr);
  1471. result:=left;
  1472. left:=nil;
  1473. exit;
  1474. end;
  1475. end;
  1476. te_convert_l1,
  1477. te_convert_l2,
  1478. te_convert_l3 :
  1479. begin
  1480. result := simplify;
  1481. if assigned(result) then
  1482. exit;
  1483. { nothing to do }
  1484. end;
  1485. te_convert_operator :
  1486. begin
  1487. include(current_procinfo.flags,pi_do_call);
  1488. aprocdef.procsym.IncRefCountBy(1);
  1489. hp:=ccallnode.create(ccallparanode.create(left,nil),Tprocsym(aprocdef.procsym),nil,nil,[]);
  1490. { tell explicitly which def we must use !! (PM) }
  1491. tcallnode(hp).procdefinition:=aprocdef;
  1492. left:=nil;
  1493. result:=hp;
  1494. exit;
  1495. end;
  1496. te_incompatible :
  1497. begin
  1498. { Procedures have a resultdef of voiddef and functions of their
  1499. own resultdef. They will therefore always be incompatible with
  1500. a procvar. Because isconvertable cannot check for procedures we
  1501. use an extra check for them.}
  1502. if (left.nodetype=calln) and
  1503. (tcallnode(left).para_count=0) and
  1504. (resultdef.typ=procvardef) and
  1505. (
  1506. (m_tp_procvar in current_settings.modeswitches) or
  1507. (m_mac_procvar in current_settings.modeswitches)
  1508. ) then
  1509. begin
  1510. if assigned(tcallnode(left).right) then
  1511. begin
  1512. { this is already a procvar, if it is really equal
  1513. is checked below }
  1514. convtype:=tc_equal;
  1515. hp:=tcallnode(left).right.getcopy;
  1516. currprocdef:=tabstractprocdef(hp.resultdef);
  1517. end
  1518. else
  1519. begin
  1520. convtype:=tc_proc_2_procvar;
  1521. currprocdef:=Tprocsym(Tcallnode(left).symtableprocentry).Find_procdef_byprocvardef(Tprocvardef(resultdef));
  1522. hp:=cloadnode.create_procvar(tprocsym(tcallnode(left).symtableprocentry),
  1523. tprocdef(currprocdef),tcallnode(left).symtableproc);
  1524. if (tcallnode(left).symtableprocentry.owner.symtabletype=ObjectSymtable) then
  1525. begin
  1526. if assigned(tcallnode(left).methodpointer) then
  1527. tloadnode(hp).set_mp(tcallnode(left).get_load_methodpointer)
  1528. else
  1529. tloadnode(hp).set_mp(load_self_node);
  1530. end;
  1531. typecheckpass(hp);
  1532. end;
  1533. left.free;
  1534. left:=hp;
  1535. { Now check if the procedure we are going to assign to
  1536. the procvar, is compatible with the procvar's type }
  1537. if not(nf_explicit in flags) and
  1538. (proc_to_procvar_equal(currprocdef,tprocvardef(resultdef))=te_incompatible) then
  1539. IncompatibleTypes(left.resultdef,resultdef);
  1540. exit;
  1541. end;
  1542. { Handle explicit type conversions }
  1543. if nf_explicit in flags then
  1544. begin
  1545. { do common tc_equal cast }
  1546. convtype:=tc_equal;
  1547. { ordinal constants can be resized to 1,2,4,8 bytes }
  1548. if (left.nodetype=ordconstn) then
  1549. begin
  1550. { Insert typeconv for ordinal to the correct size first on left, after
  1551. that the other conversion can be done }
  1552. hdef:=nil;
  1553. case longint(resultdef.size) of
  1554. 1 :
  1555. hdef:=s8inttype;
  1556. 2 :
  1557. hdef:=s16inttype;
  1558. 4 :
  1559. hdef:=s32inttype;
  1560. 8 :
  1561. hdef:=s64inttype;
  1562. end;
  1563. { we need explicit, because it can also be an enum }
  1564. if assigned(hdef) then
  1565. inserttypeconv_internal(left,hdef)
  1566. else
  1567. CGMessage2(type_e_illegal_type_conversion,left.resultdef.GetTypeName,resultdef.GetTypeName);
  1568. end;
  1569. { check if the result could be in a register }
  1570. if (not(tstoreddef(resultdef).is_intregable) and
  1571. not(tstoreddef(resultdef).is_fpuregable)) or
  1572. ((left.resultdef.typ = floatdef) and
  1573. (resultdef.typ <> floatdef)) then
  1574. make_not_regable(left,[ra_addr_regable]);
  1575. { class/interface to class/interface, with checkobject support }
  1576. if is_class_or_interface(resultdef) and
  1577. is_class_or_interface(left.resultdef) then
  1578. begin
  1579. { check if the types are related }
  1580. if not(nf_internal in flags) and
  1581. (not(tobjectdef(left.resultdef).is_related(tobjectdef(resultdef)))) and
  1582. (not(tobjectdef(resultdef).is_related(tobjectdef(left.resultdef)))) then
  1583. begin
  1584. { Give an error when typecasting class to interface, this is compatible
  1585. with delphi }
  1586. if is_interface(resultdef) and
  1587. not is_interface(left.resultdef) then
  1588. CGMessage2(type_e_classes_not_related,
  1589. FullTypeName(left.resultdef,resultdef),
  1590. FullTypeName(resultdef,left.resultdef))
  1591. else
  1592. CGMessage2(type_w_classes_not_related,
  1593. FullTypeName(left.resultdef,resultdef),
  1594. FullTypeName(resultdef,left.resultdef))
  1595. end;
  1596. { Add runtime check? }
  1597. if (cs_check_object in current_settings.localswitches) and
  1598. not(nf_internal in flags) then
  1599. begin
  1600. { we can translate the typeconvnode to 'as' when
  1601. typecasting to a class or interface }
  1602. { we need to make sure the result can still be
  1603. passed as a var parameter }
  1604. newblock:=internalstatements(newstatement);
  1605. if (valid_for_var(left,false)) then
  1606. begin
  1607. tempnode:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  1608. addstatement(newstatement,tempnode);
  1609. addstatement(newstatement,cassignmentnode.create(
  1610. ctemprefnode.create(tempnode),
  1611. caddrnode.create_internal(left)));
  1612. left:=ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),left.resultdef);
  1613. end
  1614. else
  1615. begin
  1616. tempnode:=ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,true);
  1617. addstatement(newstatement,tempnode);
  1618. addstatement(newstatement,cassignmentnode.create(
  1619. ctemprefnode.create(tempnode),
  1620. left));
  1621. left:=ctemprefnode.create(tempnode);
  1622. end;
  1623. addstatement(newstatement,casnode.create(left.getcopy,cloadvmtaddrnode.create(ctypenode.create(resultdef))));
  1624. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempnode));
  1625. addstatement(newstatement,ctypeconvnode.create_internal(left,resultdef));
  1626. left:=nil;
  1627. result:=newblock;
  1628. exit;
  1629. end;
  1630. end
  1631. else
  1632. begin
  1633. { only if the same size or formal def, and }
  1634. { don't allow type casting of constants to }
  1635. { structured types }
  1636. if not(
  1637. (left.resultdef.typ=formaldef) or
  1638. (
  1639. not(is_open_array(left.resultdef)) and
  1640. not(is_array_constructor(left.resultdef)) and
  1641. (left.resultdef.size=resultdef.size) and
  1642. { disallow casts of const nodes }
  1643. (not is_constnode(left) or
  1644. { however, there are some exceptions }
  1645. (not(resultdef.typ in [arraydef,recorddef,setdef,stringdef,
  1646. filedef,variantdef,objectdef]) or
  1647. is_class_or_interface(resultdef) or
  1648. { the softfloat code generates casts <const. float> to record }
  1649. (nf_internal in flags)
  1650. ))
  1651. ) or
  1652. (
  1653. is_void(left.resultdef) and
  1654. (left.nodetype=derefn)
  1655. )
  1656. ) then
  1657. CGMessage2(type_e_illegal_type_conversion,left.resultdef.GetTypeName,resultdef.GetTypeName);
  1658. end;
  1659. end
  1660. else
  1661. IncompatibleTypes(left.resultdef,resultdef);
  1662. end;
  1663. else
  1664. internalerror(200211231);
  1665. end;
  1666. end;
  1667. { Give hint or warning for unportable code, exceptions are
  1668. - typecasts from constants
  1669. - void }
  1670. if not(nf_internal in flags) and
  1671. (left.nodetype<>ordconstn) and
  1672. not(is_void(left.resultdef)) and
  1673. (((left.resultdef.typ=orddef) and
  1674. (resultdef.typ in [pointerdef,procvardef,classrefdef])) or
  1675. ((resultdef.typ=orddef) and
  1676. (left.resultdef.typ in [pointerdef,procvardef,classrefdef]))) then
  1677. begin
  1678. { Give a warning when sizes don't match, because then info will be lost }
  1679. if left.resultdef.size=resultdef.size then
  1680. CGMessage(type_h_pointer_to_longint_conv_not_portable)
  1681. else
  1682. CGMessage(type_w_pointer_to_longint_conv_not_portable);
  1683. end;
  1684. result := simplify;
  1685. if assigned(result) then
  1686. exit;
  1687. { now call the resultdef helper to do constant folding }
  1688. result:=typecheck_call_helper(convtype);
  1689. end;
  1690. function ttypeconvnode.simplify: tnode;
  1691. var
  1692. hp: tnode;
  1693. begin
  1694. result := nil;
  1695. { Constant folding and other node transitions to
  1696. remove the typeconv node }
  1697. case left.nodetype of
  1698. realconstn :
  1699. begin
  1700. if (convtype = tc_real_2_currency) then
  1701. result := typecheck_real_to_currency
  1702. else if (convtype = tc_real_2_real) then
  1703. result := typecheck_real_to_real
  1704. else
  1705. exit;
  1706. if not(assigned(result)) then
  1707. begin
  1708. result := left;
  1709. left := nil;
  1710. end;
  1711. if (result.nodetype = realconstn) then
  1712. begin
  1713. hp:=result;
  1714. result:=crealconstnode.create(trealconstnode(hp).value_real,resultdef);
  1715. if ([nf_explicit,nf_internal] * flags <> []) then
  1716. include(result.flags, nf_explicit);
  1717. hp.free;
  1718. end;
  1719. end;
  1720. niln :
  1721. begin
  1722. { nil to ordinal node }
  1723. if (resultdef.typ=orddef) then
  1724. begin
  1725. hp:=cordconstnode.create(0,resultdef,true);
  1726. if ([nf_explicit,nf_internal] * flags <> []) then
  1727. include(hp.flags, nf_explicit);
  1728. result:=hp;
  1729. exit;
  1730. end
  1731. else
  1732. { fold nil to any pointer type }
  1733. if (resultdef.typ=pointerdef) then
  1734. begin
  1735. hp:=cnilnode.create;
  1736. hp.resultdef:=resultdef;
  1737. if ([nf_explicit,nf_internal] * flags <> []) then
  1738. include(hp.flags, nf_explicit);
  1739. result:=hp;
  1740. exit;
  1741. end
  1742. else
  1743. { remove typeconv after niln, but not when the result is a
  1744. methodpointer. The typeconv of the methodpointer will then
  1745. take care of updateing size of niln to OS_64 }
  1746. if not((resultdef.typ=procvardef) and
  1747. (po_methodpointer in tprocvardef(resultdef).procoptions)) then
  1748. begin
  1749. left.resultdef:=resultdef;
  1750. if ([nf_explicit,nf_internal] * flags <> []) then
  1751. include(left.flags, nf_explicit);
  1752. result:=left;
  1753. left:=nil;
  1754. exit;
  1755. end;
  1756. end;
  1757. ordconstn :
  1758. begin
  1759. { ordinal contants can be directly converted }
  1760. { but not char to char because it is a widechar to char or via versa }
  1761. { which needs extra code to do the code page transistion }
  1762. { constant ordinal to pointer }
  1763. if (resultdef.typ=pointerdef) and
  1764. (convtype<>tc_cchar_2_pchar) then
  1765. begin
  1766. hp:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value),resultdef);
  1767. if ([nf_explicit,nf_internal] * flags <> []) then
  1768. include(hp.flags, nf_explicit);
  1769. result:=hp;
  1770. exit;
  1771. end
  1772. else if is_ordinal(resultdef) and
  1773. not(convtype=tc_char_2_char) then
  1774. begin
  1775. { replace the resultdef and recheck the range }
  1776. if ([nf_explicit,nf_internal] * flags <> []) then
  1777. include(left.flags, nf_explicit);
  1778. testrange(left.resultdef,resultdef,tordconstnode(left).value,(nf_explicit in flags));
  1779. left.resultdef:=resultdef;
  1780. result:=left;
  1781. left:=nil;
  1782. exit;
  1783. end;
  1784. end;
  1785. pointerconstn :
  1786. begin
  1787. { pointerconstn to any pointer is folded too }
  1788. if (resultdef.typ=pointerdef) then
  1789. begin
  1790. left.resultdef:=resultdef;
  1791. if ([nf_explicit,nf_internal] * flags <> []) then
  1792. include(left.flags, nf_explicit);
  1793. result:=left;
  1794. left:=nil;
  1795. exit;
  1796. end
  1797. { constant pointer to ordinal }
  1798. else if is_ordinal(resultdef) then
  1799. begin
  1800. hp:=cordconstnode.create(TConstExprInt(tpointerconstnode(left).value),
  1801. resultdef,not(nf_explicit in flags));
  1802. if ([nf_explicit,nf_internal] * flags <> []) then
  1803. include(hp.flags, nf_explicit);
  1804. result:=hp;
  1805. exit;
  1806. end;
  1807. end;
  1808. end;
  1809. end;
  1810. procedure Ttypeconvnode.mark_write;
  1811. begin
  1812. left.mark_write;
  1813. end;
  1814. function ttypeconvnode.first_cord_to_pointer : tnode;
  1815. begin
  1816. result:=nil;
  1817. internalerror(200104043);
  1818. end;
  1819. function ttypeconvnode.first_int_to_int : tnode;
  1820. begin
  1821. first_int_to_int:=nil;
  1822. expectloc:=left.expectloc;
  1823. if not is_void(left.resultdef) then
  1824. begin
  1825. if (left.expectloc<>LOC_REGISTER) and
  1826. (resultdef.size>left.resultdef.size) then
  1827. expectloc:=LOC_REGISTER
  1828. else
  1829. if (left.expectloc=LOC_CREGISTER) and
  1830. (resultdef.size<left.resultdef.size) then
  1831. expectloc:=LOC_REGISTER;
  1832. end;
  1833. {$ifndef cpu64bit}
  1834. if is_64bit(resultdef) then
  1835. registersint:=max(registersint,2)
  1836. else
  1837. {$endif cpu64bit}
  1838. registersint:=max(registersint,1);
  1839. end;
  1840. function ttypeconvnode.first_cstring_to_pchar : tnode;
  1841. begin
  1842. result:=nil;
  1843. registersint:=1;
  1844. expectloc:=LOC_REGISTER;
  1845. end;
  1846. function ttypeconvnode.first_cstring_to_int : tnode;
  1847. begin
  1848. result:=nil;
  1849. internalerror(200510014);
  1850. end;
  1851. function ttypeconvnode.first_string_to_chararray : tnode;
  1852. begin
  1853. first_string_to_chararray:=nil;
  1854. expectloc:=left.expectloc;
  1855. end;
  1856. function ttypeconvnode.first_char_to_string : tnode;
  1857. begin
  1858. first_char_to_string:=nil;
  1859. expectloc:=LOC_REFERENCE;
  1860. end;
  1861. function ttypeconvnode.first_nothing : tnode;
  1862. begin
  1863. first_nothing:=nil;
  1864. end;
  1865. function ttypeconvnode.first_array_to_pointer : tnode;
  1866. begin
  1867. first_array_to_pointer:=nil;
  1868. if registersint<1 then
  1869. registersint:=1;
  1870. expectloc:=LOC_REGISTER;
  1871. end;
  1872. function ttypeconvnode.first_int_to_real: tnode;
  1873. var
  1874. fname: string[32];
  1875. begin
  1876. if target_info.system in system_wince then
  1877. begin
  1878. { converting a 64bit integer to a float requires a helper }
  1879. if is_64bitint(left.resultdef) or
  1880. is_currency(left.resultdef) then
  1881. begin
  1882. { hack to avoid double division by 10000, as it's
  1883. already done by typecheckpass.resultdef_int_to_real }
  1884. if is_currency(left.resultdef) then
  1885. left.resultdef := s64inttype;
  1886. if is_signed(left.resultdef) then
  1887. fname:='I64TO'
  1888. else
  1889. fname:='UI64TO';
  1890. end
  1891. else
  1892. { other integers are supposed to be 32 bit }
  1893. begin
  1894. if is_signed(left.resultdef) then
  1895. fname:='ITO'
  1896. else
  1897. fname:='UTO';
  1898. firstpass(left);
  1899. end;
  1900. if tfloatdef(resultdef).floattype=s64real then
  1901. fname:=fname+'D'
  1902. else
  1903. fname:=fname+'S';
  1904. result:=ccallnode.createintern(fname,ccallparanode.create(
  1905. left,nil));
  1906. left:=nil;
  1907. firstpass(result);
  1908. exit;
  1909. end
  1910. else
  1911. begin
  1912. { converting a 64bit integer to a float requires a helper }
  1913. if is_64bitint(left.resultdef) or
  1914. is_currency(left.resultdef) then
  1915. begin
  1916. { hack to avoid double division by 10000, as it's
  1917. already done by typecheckpass.resultdef_int_to_real }
  1918. if is_currency(left.resultdef) then
  1919. left.resultdef := s64inttype;
  1920. if is_signed(left.resultdef) then
  1921. fname:='int64_to_'
  1922. else
  1923. { we can't do better currently }
  1924. fname:='int64_to_';
  1925. end
  1926. else
  1927. { other integers are supposed to be 32 bit }
  1928. begin
  1929. if is_signed(left.resultdef) then
  1930. fname:='int32_to_'
  1931. else
  1932. { we can't do better currently }
  1933. fname:='int32_to_';
  1934. firstpass(left);
  1935. end;
  1936. if tfloatdef(resultdef).floattype=s64real then
  1937. fname:=fname+'float64'
  1938. else
  1939. fname:=fname+'float32';
  1940. result:=ctypeconvnode.create_internal(ccallnode.createintern(fname,ccallparanode.create(
  1941. left,nil)),resultdef);
  1942. left:=nil;
  1943. firstpass(result);
  1944. exit;
  1945. end;
  1946. end;
  1947. function ttypeconvnode.first_real_to_real : tnode;
  1948. begin
  1949. {$ifdef cpufpemu}
  1950. if cs_fp_emulation in current_settings.moduleswitches then
  1951. begin
  1952. if target_info.system in system_wince then
  1953. begin
  1954. case tfloatdef(left.resultdef).floattype of
  1955. s32real:
  1956. case tfloatdef(resultdef).floattype of
  1957. s64real:
  1958. result:=ccallnode.createintern('STOD',ccallparanode.create(left,nil));
  1959. s32real:
  1960. begin
  1961. result:=left;
  1962. left:=nil;
  1963. end;
  1964. else
  1965. internalerror(2005082704);
  1966. end;
  1967. s64real:
  1968. case tfloatdef(resultdef).floattype of
  1969. s32real:
  1970. result:=ccallnode.createintern('DTOS',ccallparanode.create(left,nil));
  1971. s64real:
  1972. begin
  1973. result:=left;
  1974. left:=nil;
  1975. end;
  1976. else
  1977. internalerror(2005082703);
  1978. end;
  1979. else
  1980. internalerror(2005082702);
  1981. end;
  1982. left:=nil;
  1983. firstpass(result);
  1984. exit;
  1985. end
  1986. else
  1987. begin
  1988. case tfloatdef(left.resultdef).floattype of
  1989. s32real:
  1990. case tfloatdef(resultdef).floattype of
  1991. s64real:
  1992. result:=ctypeconvnode.create_explicit(ccallnode.createintern('float32_to_float64',ccallparanode.create(
  1993. ctypeconvnode.create_internal(left,search_system_type('FLOAT32REC').typedef),nil)),resultdef);
  1994. s32real:
  1995. begin
  1996. result:=left;
  1997. left:=nil;
  1998. end;
  1999. else
  2000. internalerror(200610151);
  2001. end;
  2002. s64real:
  2003. case tfloatdef(resultdef).floattype of
  2004. s32real:
  2005. result:=ctypeconvnode.create_explicit(ccallnode.createintern('float64_to_float32',ccallparanode.create(
  2006. ctypeconvnode.create_internal(left,search_system_type('FLOAT64').typedef),nil)),resultdef);
  2007. s64real:
  2008. begin
  2009. result:=left;
  2010. left:=nil;
  2011. end;
  2012. else
  2013. internalerror(200610152);
  2014. end;
  2015. else
  2016. internalerror(200610153);
  2017. end;
  2018. left:=nil;
  2019. firstpass(result);
  2020. exit;
  2021. end;
  2022. end
  2023. else
  2024. {$endif cpufpemu}
  2025. begin
  2026. first_real_to_real:=nil;
  2027. if registersfpu<1 then
  2028. registersfpu:=1;
  2029. expectloc:=LOC_FPUREGISTER;
  2030. end;
  2031. end;
  2032. function ttypeconvnode.first_pointer_to_array : tnode;
  2033. begin
  2034. first_pointer_to_array:=nil;
  2035. if registersint<1 then
  2036. registersint:=1;
  2037. expectloc:=LOC_REFERENCE;
  2038. end;
  2039. function ttypeconvnode.first_cchar_to_pchar : tnode;
  2040. begin
  2041. first_cchar_to_pchar:=nil;
  2042. internalerror(200104021);
  2043. end;
  2044. function ttypeconvnode.first_bool_to_int : tnode;
  2045. begin
  2046. first_bool_to_int:=nil;
  2047. { byte(boolean) or word(wordbool) or longint(longbool) must
  2048. be accepted for var parameters }
  2049. if (nf_explicit in flags) and
  2050. (left.resultdef.size=resultdef.size) and
  2051. (left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  2052. exit;
  2053. { when converting to 64bit, first convert to a 32bit int and then }
  2054. { convert to a 64bit int (only necessary for 32bit processors) (JM) }
  2055. if resultdef.size > sizeof(aint) then
  2056. begin
  2057. result := ctypeconvnode.create_internal(left,u32inttype);
  2058. result := ctypeconvnode.create(result,resultdef);
  2059. left := nil;
  2060. firstpass(result);
  2061. exit;
  2062. end;
  2063. expectloc:=LOC_REGISTER;
  2064. if registersint<1 then
  2065. registersint:=1;
  2066. end;
  2067. function ttypeconvnode.first_int_to_bool : tnode;
  2068. begin
  2069. first_int_to_bool:=nil;
  2070. { byte(boolean) or word(wordbool) or longint(longbool) must
  2071. be accepted for var parameters }
  2072. if (nf_explicit in flags) and
  2073. (left.resultdef.size=resultdef.size) and
  2074. (left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  2075. exit;
  2076. expectloc:=LOC_REGISTER;
  2077. { need if bool to bool !!
  2078. not very nice !!
  2079. insertypeconv(left,s32inttype);
  2080. left.explizit:=true;
  2081. firstpass(left); }
  2082. if registersint<1 then
  2083. registersint:=1;
  2084. end;
  2085. function ttypeconvnode.first_bool_to_bool : tnode;
  2086. begin
  2087. first_bool_to_bool:=nil;
  2088. if (left.expectloc in [LOC_FLAGS,LOC_JUMP]) then
  2089. expectloc := left.expectloc
  2090. else
  2091. begin
  2092. expectloc:=LOC_REGISTER;
  2093. if registersint<1 then
  2094. registersint:=1;
  2095. end;
  2096. end;
  2097. function ttypeconvnode.first_char_to_char : tnode;
  2098. var
  2099. fname: string[18];
  2100. begin
  2101. if (torddef(resultdef).ordtype=uchar) and
  2102. (torddef(left.resultdef).ordtype=uwidechar) then
  2103. fname := 'fpc_wchar_to_char'
  2104. else if (torddef(resultdef).ordtype=uwidechar) and
  2105. (torddef(left.resultdef).ordtype=uchar) then
  2106. fname := 'fpc_char_to_wchar'
  2107. else
  2108. internalerror(2007081201);
  2109. result := ccallnode.createintern(fname,ccallparanode.create(left,nil));
  2110. left:=nil;
  2111. firstpass(result);
  2112. end;
  2113. function ttypeconvnode.first_proc_to_procvar : tnode;
  2114. begin
  2115. first_proc_to_procvar:=nil;
  2116. { if we take the address of a nested function, it'll }
  2117. { probably be used in a foreach() construct and then }
  2118. { the parent needs a stackframe }
  2119. if (tprocdef(left.resultdef).parast.symtablelevel>=normal_function_level) then
  2120. include(current_procinfo.flags,pi_needs_stackframe);
  2121. if tabstractprocdef(resultdef).is_addressonly then
  2122. begin
  2123. registersint:=left.registersint;
  2124. if registersint<1 then
  2125. registersint:=1;
  2126. expectloc:=LOC_REGISTER;
  2127. end
  2128. else
  2129. begin
  2130. if not(left.expectloc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  2131. CGMessage(parser_e_illegal_expression);
  2132. registersint:=left.registersint;
  2133. expectloc:=left.expectloc
  2134. end
  2135. end;
  2136. function ttypeconvnode.first_nil_to_methodprocvar : tnode;
  2137. begin
  2138. first_nil_to_methodprocvar:=nil;
  2139. registersint:=0;
  2140. expectloc:=LOC_REFERENCE;
  2141. end;
  2142. function ttypeconvnode.first_set_to_set : tnode;
  2143. var
  2144. newstatement : tstatementnode;
  2145. temp : ttempcreatenode;
  2146. begin
  2147. { in theory, we should do range checking here,
  2148. but Delphi doesn't do it either (FK) }
  2149. if left.nodetype=setconstn then
  2150. begin
  2151. left.resultdef:=resultdef;
  2152. result:=left;
  2153. end
  2154. { equal sets for the code generator? }
  2155. else if (left.resultdef.size=resultdef.size) and
  2156. (tsetdef(left.resultdef).setbase=tsetdef(resultdef).setbase) then
  2157. {$warning This causes wrong (but Delphi-compatible) results for disjoint subsets}
  2158. { e.g., this prints true because of this:
  2159. var
  2160. sa: set of 1..2;
  2161. sb: set of 5..6;
  2162. b: byte;
  2163. begin
  2164. b:=1;
  2165. sa:=[1..2];
  2166. sb:=sa;
  2167. writeln(b in sb);
  2168. end.
  2169. }
  2170. result:=left
  2171. else
  2172. // if is_varset(resultdef) then
  2173. begin
  2174. result:=internalstatements(newstatement);
  2175. { in case left is a smallset expression, it can be an addn or so. }
  2176. { fpc_varset_load expects a formal const parameter, which doesn't }
  2177. { accept set addn's -> assign to a temp first and pass the temp }
  2178. if not(left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  2179. begin
  2180. temp:=ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,false);
  2181. addstatement(newstatement,temp);
  2182. { temp := left }
  2183. addstatement(newstatement,cassignmentnode.create(
  2184. ctemprefnode.create(temp),left));
  2185. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2186. addstatement(newstatement,ctemprefnode.create(temp));
  2187. left:=result;
  2188. firstpass(left);
  2189. { recreate the result's internalstatements list }
  2190. result:=internalstatements(newstatement);
  2191. end;
  2192. { create temp for result }
  2193. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  2194. addstatement(newstatement,temp);
  2195. addstatement(newstatement,ccallnode.createintern('fpc_varset_load',
  2196. ccallparanode.create(cordconstnode.create(tsetdef(left.resultdef).setbase div 8 - tsetdef(resultdef).setbase div 8,sinttype,false),
  2197. ccallparanode.create(cordconstnode.create(resultdef.size,sinttype,false),
  2198. ccallparanode.create(ctemprefnode.create(temp),
  2199. ccallparanode.create(cordconstnode.create(left.resultdef.size,sinttype,false),
  2200. ccallparanode.create(left,nil))))))
  2201. );
  2202. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2203. addstatement(newstatement,ctemprefnode.create(temp));
  2204. end;
  2205. {
  2206. else
  2207. begin
  2208. srsym:=search_system_type('FPC_SMALL_SET');
  2209. result :=
  2210. ccallnode.createinternres('fpc_set_load_small',
  2211. ccallparanode.create(ctypeconvnode.create_internal(left,srsym.typedef),nil),resultdef);
  2212. end;
  2213. }
  2214. { reused }
  2215. left:=nil;
  2216. end;
  2217. function ttypeconvnode.first_ansistring_to_pchar : tnode;
  2218. begin
  2219. first_ansistring_to_pchar:=nil;
  2220. expectloc:=LOC_REGISTER;
  2221. if registersint<1 then
  2222. registersint:=1;
  2223. end;
  2224. function ttypeconvnode.first_arrayconstructor_to_set : tnode;
  2225. begin
  2226. first_arrayconstructor_to_set:=nil;
  2227. internalerror(200104022);
  2228. end;
  2229. function ttypeconvnode.first_class_to_intf : tnode;
  2230. begin
  2231. first_class_to_intf:=nil;
  2232. expectloc:=LOC_REGISTER;
  2233. if registersint<1 then
  2234. registersint:=1;
  2235. end;
  2236. function ttypeconvnode._first_int_to_int : tnode;
  2237. begin
  2238. result:=first_int_to_int;
  2239. end;
  2240. function ttypeconvnode._first_cstring_to_pchar : tnode;
  2241. begin
  2242. result:=first_cstring_to_pchar;
  2243. end;
  2244. function ttypeconvnode._first_cstring_to_int : tnode;
  2245. begin
  2246. result:=first_cstring_to_int;
  2247. end;
  2248. function ttypeconvnode._first_string_to_chararray : tnode;
  2249. begin
  2250. result:=first_string_to_chararray;
  2251. end;
  2252. function ttypeconvnode._first_char_to_string : tnode;
  2253. begin
  2254. result:=first_char_to_string;
  2255. end;
  2256. function ttypeconvnode._first_nothing : tnode;
  2257. begin
  2258. result:=first_nothing;
  2259. end;
  2260. function ttypeconvnode._first_array_to_pointer : tnode;
  2261. begin
  2262. result:=first_array_to_pointer;
  2263. end;
  2264. function ttypeconvnode._first_int_to_real : tnode;
  2265. begin
  2266. result:=first_int_to_real;
  2267. end;
  2268. function ttypeconvnode._first_real_to_real : tnode;
  2269. begin
  2270. result:=first_real_to_real;
  2271. end;
  2272. function ttypeconvnode._first_pointer_to_array : tnode;
  2273. begin
  2274. result:=first_pointer_to_array;
  2275. end;
  2276. function ttypeconvnode._first_cchar_to_pchar : tnode;
  2277. begin
  2278. result:=first_cchar_to_pchar;
  2279. end;
  2280. function ttypeconvnode._first_bool_to_int : tnode;
  2281. begin
  2282. result:=first_bool_to_int;
  2283. end;
  2284. function ttypeconvnode._first_int_to_bool : tnode;
  2285. begin
  2286. result:=first_int_to_bool;
  2287. end;
  2288. function ttypeconvnode._first_bool_to_bool : tnode;
  2289. begin
  2290. result:=first_bool_to_bool;
  2291. end;
  2292. function ttypeconvnode._first_proc_to_procvar : tnode;
  2293. begin
  2294. result:=first_proc_to_procvar;
  2295. end;
  2296. function ttypeconvnode._first_nil_to_methodprocvar : tnode;
  2297. begin
  2298. result:=first_nil_to_methodprocvar;
  2299. end;
  2300. function ttypeconvnode._first_set_to_set : tnode;
  2301. begin
  2302. result:=first_set_to_set;
  2303. end;
  2304. function ttypeconvnode._first_cord_to_pointer : tnode;
  2305. begin
  2306. result:=first_cord_to_pointer;
  2307. end;
  2308. function ttypeconvnode._first_ansistring_to_pchar : tnode;
  2309. begin
  2310. result:=first_ansistring_to_pchar;
  2311. end;
  2312. function ttypeconvnode._first_arrayconstructor_to_set : tnode;
  2313. begin
  2314. result:=first_arrayconstructor_to_set;
  2315. end;
  2316. function ttypeconvnode._first_class_to_intf : tnode;
  2317. begin
  2318. result:=first_class_to_intf;
  2319. end;
  2320. function ttypeconvnode._first_char_to_char : tnode;
  2321. begin
  2322. result:=first_char_to_char;
  2323. end;
  2324. function ttypeconvnode.first_call_helper(c : tconverttype) : tnode;
  2325. const
  2326. firstconvert : array[tconverttype] of pointer = (
  2327. nil, { none }
  2328. @ttypeconvnode._first_nothing, {equal}
  2329. @ttypeconvnode._first_nothing, {not_possible}
  2330. nil, { removed in typecheck_string_to_string }
  2331. @ttypeconvnode._first_char_to_string,
  2332. @ttypeconvnode._first_nothing, { char_2_chararray, needs nothing extra }
  2333. nil, { removed in typecheck_chararray_to_string }
  2334. @ttypeconvnode._first_cchar_to_pchar,
  2335. @ttypeconvnode._first_cstring_to_pchar,
  2336. @ttypeconvnode._first_cstring_to_int,
  2337. @ttypeconvnode._first_ansistring_to_pchar,
  2338. @ttypeconvnode._first_string_to_chararray,
  2339. nil, { removed in typecheck_chararray_to_string }
  2340. @ttypeconvnode._first_array_to_pointer,
  2341. @ttypeconvnode._first_pointer_to_array,
  2342. @ttypeconvnode._first_int_to_int,
  2343. @ttypeconvnode._first_int_to_bool,
  2344. @ttypeconvnode._first_bool_to_bool,
  2345. @ttypeconvnode._first_bool_to_int,
  2346. @ttypeconvnode._first_real_to_real,
  2347. @ttypeconvnode._first_int_to_real,
  2348. nil, { removed in typecheck_real_to_currency }
  2349. @ttypeconvnode._first_proc_to_procvar,
  2350. @ttypeconvnode._first_nil_to_methodprocvar,
  2351. @ttypeconvnode._first_arrayconstructor_to_set,
  2352. @ttypeconvnode._first_set_to_set,
  2353. @ttypeconvnode._first_cord_to_pointer,
  2354. @ttypeconvnode._first_nothing,
  2355. @ttypeconvnode._first_nothing,
  2356. @ttypeconvnode._first_class_to_intf,
  2357. @ttypeconvnode._first_char_to_char,
  2358. @ttypeconvnode._first_nothing,
  2359. @ttypeconvnode._first_nothing,
  2360. nil,
  2361. nil,
  2362. nil,
  2363. nil,
  2364. nil,
  2365. nil,
  2366. nil
  2367. );
  2368. type
  2369. tprocedureofobject = function : tnode of object;
  2370. var
  2371. r : packed record
  2372. proc : pointer;
  2373. obj : pointer;
  2374. end;
  2375. begin
  2376. { this is a little bit dirty but it works }
  2377. { and should be quite portable too }
  2378. r.proc:=firstconvert[c];
  2379. r.obj:=self;
  2380. if not assigned(r.proc) then
  2381. internalerror(200312081);
  2382. first_call_helper:=tprocedureofobject(r)()
  2383. end;
  2384. function ttypeconvnode.pass_1 : tnode;
  2385. begin
  2386. result:=nil;
  2387. firstpass(left);
  2388. if codegenerror then
  2389. exit;
  2390. { load the value_str from the left part }
  2391. registersint:=left.registersint;
  2392. registersfpu:=left.registersfpu;
  2393. {$ifdef SUPPORT_MMX}
  2394. registersmmx:=left.registersmmx;
  2395. {$endif}
  2396. expectloc:=left.expectloc;
  2397. result:=first_call_helper(convtype);
  2398. end;
  2399. function ttypeconvnode.assign_allowed:boolean;
  2400. begin
  2401. result:=(convtype=tc_equal) or
  2402. { typecasting from void is always allowed }
  2403. is_void(left.resultdef) or
  2404. (left.resultdef.typ=formaldef) or
  2405. { int 2 int with same size reuses same location, or for
  2406. tp7 mode also allow size < orignal size }
  2407. (
  2408. (convtype=tc_int_2_int) and
  2409. (
  2410. (resultdef.size=left.resultdef.size) or
  2411. ((m_tp7 in current_settings.modeswitches) and
  2412. (resultdef.size<left.resultdef.size))
  2413. )
  2414. ) or
  2415. { int 2 bool/bool 2 int, explicit typecast, see also nx86cnv }
  2416. ((convtype in [tc_int_2_bool,tc_bool_2_int]) and
  2417. (nf_explicit in flags) and
  2418. (resultdef.size=left.resultdef.size));
  2419. { When using only a part of the value it can't be in a register since
  2420. that will load the value in a new register first }
  2421. if (resultdef.size<left.resultdef.size) then
  2422. make_not_regable(left,[ra_addr_regable]);
  2423. end;
  2424. function ttypeconvnode.docompare(p: tnode) : boolean;
  2425. begin
  2426. docompare :=
  2427. inherited docompare(p) and
  2428. (convtype = ttypeconvnode(p).convtype);
  2429. end;
  2430. procedure ttypeconvnode._second_int_to_int;
  2431. begin
  2432. second_int_to_int;
  2433. end;
  2434. procedure ttypeconvnode._second_string_to_string;
  2435. begin
  2436. second_string_to_string;
  2437. end;
  2438. procedure ttypeconvnode._second_cstring_to_pchar;
  2439. begin
  2440. second_cstring_to_pchar;
  2441. end;
  2442. procedure ttypeconvnode._second_cstring_to_int;
  2443. begin
  2444. second_cstring_to_int;
  2445. end;
  2446. procedure ttypeconvnode._second_string_to_chararray;
  2447. begin
  2448. second_string_to_chararray;
  2449. end;
  2450. procedure ttypeconvnode._second_array_to_pointer;
  2451. begin
  2452. second_array_to_pointer;
  2453. end;
  2454. procedure ttypeconvnode._second_pointer_to_array;
  2455. begin
  2456. second_pointer_to_array;
  2457. end;
  2458. procedure ttypeconvnode._second_chararray_to_string;
  2459. begin
  2460. second_chararray_to_string;
  2461. end;
  2462. procedure ttypeconvnode._second_char_to_string;
  2463. begin
  2464. second_char_to_string;
  2465. end;
  2466. procedure ttypeconvnode._second_int_to_real;
  2467. begin
  2468. second_int_to_real;
  2469. end;
  2470. procedure ttypeconvnode._second_real_to_real;
  2471. begin
  2472. second_real_to_real;
  2473. end;
  2474. procedure ttypeconvnode._second_cord_to_pointer;
  2475. begin
  2476. second_cord_to_pointer;
  2477. end;
  2478. procedure ttypeconvnode._second_proc_to_procvar;
  2479. begin
  2480. second_proc_to_procvar;
  2481. end;
  2482. procedure ttypeconvnode._second_nil_to_methodprocvar;
  2483. begin
  2484. second_nil_to_methodprocvar;
  2485. end;
  2486. procedure ttypeconvnode._second_bool_to_int;
  2487. begin
  2488. second_bool_to_int;
  2489. end;
  2490. procedure ttypeconvnode._second_int_to_bool;
  2491. begin
  2492. second_int_to_bool;
  2493. end;
  2494. procedure ttypeconvnode._second_bool_to_bool;
  2495. begin
  2496. second_bool_to_bool;
  2497. end;
  2498. procedure ttypeconvnode._second_set_to_set;
  2499. begin
  2500. second_set_to_set;
  2501. end;
  2502. procedure ttypeconvnode._second_ansistring_to_pchar;
  2503. begin
  2504. second_ansistring_to_pchar;
  2505. end;
  2506. procedure ttypeconvnode._second_class_to_intf;
  2507. begin
  2508. second_class_to_intf;
  2509. end;
  2510. procedure ttypeconvnode._second_char_to_char;
  2511. begin
  2512. second_char_to_char;
  2513. end;
  2514. procedure ttypeconvnode._second_nothing;
  2515. begin
  2516. second_nothing;
  2517. end;
  2518. procedure ttypeconvnode.second_call_helper(c : tconverttype);
  2519. const
  2520. secondconvert : array[tconverttype] of pointer = (
  2521. @ttypeconvnode._second_nothing, {none}
  2522. @ttypeconvnode._second_nothing, {equal}
  2523. @ttypeconvnode._second_nothing, {not_possible}
  2524. @ttypeconvnode._second_nothing, {second_string_to_string, handled in resultdef pass }
  2525. @ttypeconvnode._second_char_to_string,
  2526. @ttypeconvnode._second_nothing, {char_to_charray}
  2527. @ttypeconvnode._second_nothing, { pchar_to_string, handled in resultdef pass }
  2528. @ttypeconvnode._second_nothing, {cchar_to_pchar}
  2529. @ttypeconvnode._second_cstring_to_pchar,
  2530. @ttypeconvnode._second_cstring_to_int,
  2531. @ttypeconvnode._second_ansistring_to_pchar,
  2532. @ttypeconvnode._second_string_to_chararray,
  2533. @ttypeconvnode._second_nothing, { chararray_to_string, handled in resultdef pass }
  2534. @ttypeconvnode._second_array_to_pointer,
  2535. @ttypeconvnode._second_pointer_to_array,
  2536. @ttypeconvnode._second_int_to_int,
  2537. @ttypeconvnode._second_int_to_bool,
  2538. @ttypeconvnode._second_bool_to_bool,
  2539. @ttypeconvnode._second_bool_to_int,
  2540. @ttypeconvnode._second_real_to_real,
  2541. @ttypeconvnode._second_int_to_real,
  2542. @ttypeconvnode._second_nothing, { real_to_currency, handled in resultdef pass }
  2543. @ttypeconvnode._second_proc_to_procvar,
  2544. @ttypeconvnode._second_nil_to_methodprocvar,
  2545. @ttypeconvnode._second_nothing, { arrayconstructor_to_set }
  2546. @ttypeconvnode._second_nothing, { second_set_to_set, handled in first pass }
  2547. @ttypeconvnode._second_cord_to_pointer,
  2548. @ttypeconvnode._second_nothing, { interface 2 string }
  2549. @ttypeconvnode._second_nothing, { interface 2 guid }
  2550. @ttypeconvnode._second_class_to_intf,
  2551. @ttypeconvnode._second_char_to_char,
  2552. @ttypeconvnode._second_nothing, { dynarray_2_openarray }
  2553. @ttypeconvnode._second_nothing, { pwchar_2_string }
  2554. @ttypeconvnode._second_nothing, { variant_2_dynarray }
  2555. @ttypeconvnode._second_nothing, { dynarray_2_variant}
  2556. @ttypeconvnode._second_nothing, { variant_2_enum }
  2557. @ttypeconvnode._second_nothing, { enum_2_variant }
  2558. @ttypeconvnode._second_nothing, { variant_2_interface }
  2559. @ttypeconvnode._second_nothing, { interface_2_variant }
  2560. @ttypeconvnode._second_nothing { array_2_dynarray }
  2561. );
  2562. type
  2563. tprocedureofobject = procedure of object;
  2564. var
  2565. r : packed record
  2566. proc : pointer;
  2567. obj : pointer;
  2568. end;
  2569. begin
  2570. { this is a little bit dirty but it works }
  2571. { and should be quite portable too }
  2572. r.proc:=secondconvert[c];
  2573. r.obj:=self;
  2574. tprocedureofobject(r)();
  2575. end;
  2576. {*****************************************************************************
  2577. TISNODE
  2578. *****************************************************************************}
  2579. constructor tisnode.create(l,r : tnode);
  2580. begin
  2581. inherited create(isn,l,r);
  2582. end;
  2583. function tisnode.pass_typecheck:tnode;
  2584. var
  2585. paras: tcallparanode;
  2586. begin
  2587. result:=nil;
  2588. typecheckpass(left);
  2589. typecheckpass(right);
  2590. set_varstate(left,vs_read,[vsf_must_be_valid]);
  2591. set_varstate(right,vs_read,[vsf_must_be_valid]);
  2592. if codegenerror then
  2593. exit;
  2594. if (right.resultdef.typ=classrefdef) then
  2595. begin
  2596. { left must be a class }
  2597. if is_class(left.resultdef) then
  2598. begin
  2599. { the operands must be related }
  2600. if (not(tobjectdef(left.resultdef).is_related(
  2601. tobjectdef(tclassrefdef(right.resultdef).pointeddef)))) and
  2602. (not(tobjectdef(tclassrefdef(right.resultdef).pointeddef).is_related(
  2603. tobjectdef(left.resultdef)))) then
  2604. CGMessage2(type_e_classes_not_related,left.resultdef.typename,
  2605. tclassrefdef(right.resultdef).pointeddef.typename);
  2606. end
  2607. else
  2608. CGMessage1(type_e_class_type_expected,left.resultdef.typename);
  2609. { call fpc_do_is helper }
  2610. paras := ccallparanode.create(
  2611. left,
  2612. ccallparanode.create(
  2613. right,nil));
  2614. result := ccallnode.createintern('fpc_do_is',paras);
  2615. left := nil;
  2616. right := nil;
  2617. end
  2618. else if is_interface(right.resultdef) then
  2619. begin
  2620. { left is a class }
  2621. if is_class(left.resultdef) then
  2622. begin
  2623. { the class must implement the interface }
  2624. if tobjectdef(left.resultdef).find_implemented_interface(tobjectdef(right.resultdef))=nil then
  2625. CGMessage2(type_e_classes_not_related,
  2626. FullTypeName(left.resultdef,right.resultdef),
  2627. FullTypeName(right.resultdef,left.resultdef))
  2628. end
  2629. { left is an interface }
  2630. else if is_interface(left.resultdef) then
  2631. begin
  2632. { the operands must be related }
  2633. if (not(tobjectdef(left.resultdef).is_related(tobjectdef(right.resultdef)))) and
  2634. (not(tobjectdef(right.resultdef).is_related(tobjectdef(left.resultdef)))) then
  2635. CGMessage2(type_e_classes_not_related,
  2636. FullTypeName(left.resultdef,right.resultdef),
  2637. FullTypeName(right.resultdef,left.resultdef));
  2638. end
  2639. else
  2640. CGMessage1(type_e_class_type_expected,left.resultdef.typename);
  2641. { call fpc_do_is helper }
  2642. paras := ccallparanode.create(
  2643. left,
  2644. ccallparanode.create(
  2645. right,nil));
  2646. result := ccallnode.createintern('fpc_do_is',paras);
  2647. left := nil;
  2648. right := nil;
  2649. end
  2650. else
  2651. CGMessage1(type_e_class_or_interface_type_expected,right.resultdef.typename);
  2652. resultdef:=booltype;
  2653. end;
  2654. function tisnode.pass_1 : tnode;
  2655. begin
  2656. internalerror(200204254);
  2657. result:=nil;
  2658. end;
  2659. { dummy pass_2, it will never be called, but we need one since }
  2660. { you can't instantiate an abstract class }
  2661. procedure tisnode.pass_generate_code;
  2662. begin
  2663. end;
  2664. {*****************************************************************************
  2665. TASNODE
  2666. *****************************************************************************}
  2667. constructor tasnode.create(l,r : tnode);
  2668. begin
  2669. inherited create(asn,l,r);
  2670. call := nil;
  2671. end;
  2672. destructor tasnode.destroy;
  2673. begin
  2674. call.free;
  2675. inherited destroy;
  2676. end;
  2677. function tasnode.pass_typecheck:tnode;
  2678. var
  2679. hp : tnode;
  2680. begin
  2681. result:=nil;
  2682. typecheckpass(right);
  2683. typecheckpass(left);
  2684. set_varstate(right,vs_read,[vsf_must_be_valid]);
  2685. set_varstate(left,vs_read,[vsf_must_be_valid]);
  2686. if codegenerror then
  2687. exit;
  2688. if (right.resultdef.typ=classrefdef) then
  2689. begin
  2690. { left must be a class }
  2691. if is_class(left.resultdef) then
  2692. begin
  2693. { the operands must be related }
  2694. if (not(tobjectdef(left.resultdef).is_related(
  2695. tobjectdef(tclassrefdef(right.resultdef).pointeddef)))) and
  2696. (not(tobjectdef(tclassrefdef(right.resultdef).pointeddef).is_related(
  2697. tobjectdef(left.resultdef)))) then
  2698. CGMessage2(type_e_classes_not_related,
  2699. FullTypeName(left.resultdef,tclassrefdef(right.resultdef).pointeddef),
  2700. FullTypeName(tclassrefdef(right.resultdef).pointeddef,left.resultdef));
  2701. end
  2702. else
  2703. CGMessage1(type_e_class_type_expected,left.resultdef.typename);
  2704. resultdef:=tclassrefdef(right.resultdef).pointeddef;
  2705. end
  2706. else if is_interface(right.resultdef) then
  2707. begin
  2708. { left is a class }
  2709. if not(is_class(left.resultdef) or
  2710. is_interfacecom(left.resultdef)) then
  2711. CGMessage1(type_e_class_or_cominterface_type_expected,left.resultdef.typename);
  2712. resultdef:=right.resultdef;
  2713. { load the GUID of the interface }
  2714. if (right.nodetype=typen) then
  2715. begin
  2716. if assigned(tobjectdef(right.resultdef).iidguid) then
  2717. begin
  2718. hp:=cguidconstnode.create(tobjectdef(right.resultdef).iidguid^);
  2719. right.free;
  2720. right:=hp;
  2721. end
  2722. else
  2723. internalerror(200206282);
  2724. typecheckpass(right);
  2725. end;
  2726. end
  2727. else
  2728. CGMessage1(type_e_class_or_interface_type_expected,right.resultdef.typename);
  2729. end;
  2730. function tasnode.dogetcopy: tnode;
  2731. begin
  2732. result := inherited dogetcopy;
  2733. if assigned(call) then
  2734. tasnode(result).call := call.getcopy
  2735. else
  2736. tasnode(result).call := nil;
  2737. end;
  2738. function tasnode.pass_1 : tnode;
  2739. var
  2740. procname: string;
  2741. begin
  2742. result:=nil;
  2743. if not assigned(call) then
  2744. begin
  2745. if is_class(left.resultdef) and
  2746. (right.resultdef.typ=classrefdef) then
  2747. call := ccallnode.createinternres('fpc_do_as',
  2748. ccallparanode.create(left,ccallparanode.create(right,nil)),
  2749. resultdef)
  2750. else
  2751. begin
  2752. if is_class(left.resultdef) then
  2753. procname := 'fpc_class_as_intf'
  2754. else
  2755. procname := 'fpc_intf_as';
  2756. call := ccallnode.createintern(procname,
  2757. ccallparanode.create(right,ccallparanode.create(left,nil)));
  2758. call := ctypeconvnode.create_internal(call,resultdef);
  2759. end;
  2760. left := nil;
  2761. right := nil;
  2762. firstpass(call);
  2763. if codegenerror then
  2764. exit;
  2765. expectloc:=call.expectloc;
  2766. registersint:=call.registersint;
  2767. registersfpu:=call.registersfpu;
  2768. {$ifdef SUPPORT_MMX}
  2769. registersmmx:=call.registersmmx;
  2770. {$endif SUPPORT_MMX}
  2771. end;
  2772. end;
  2773. begin
  2774. ctypeconvnode:=ttypeconvnode;
  2775. casnode:=tasnode;
  2776. cisnode:=tisnode;
  2777. end.