ncnv.pas 92 KB

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