ncnv.pas 94 KB

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