ncnv.pas 96 KB

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