ncnv.pas 95 KB

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