htypechk.pas 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit exports some help routines for the type checking
  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 htypechk;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. tokens,cpuinfo,
  23. node,
  24. symconst,symtype,symdef,symsym,symbase;
  25. type
  26. Ttok2nodeRec=record
  27. tok : ttoken;
  28. nod : tnodetype;
  29. op_overloading_supported : boolean;
  30. end;
  31. pcandidate = ^tcandidate;
  32. tcandidate = record
  33. next : pcandidate;
  34. data : tprocdef;
  35. wrongpara,
  36. firstpara : tparaitem;
  37. exact_count,
  38. equal_count,
  39. cl1_count,
  40. cl2_count,
  41. cl3_count,
  42. coper_count : integer; { should be signed }
  43. ordinal_distance : bestreal;
  44. invalid : boolean;
  45. wrongparanr : byte;
  46. end;
  47. tcallcandidates = class
  48. private
  49. FProcSym : tprocsym;
  50. FProcs : pcandidate;
  51. FProcVisibleCnt,
  52. FProcCnt : integer;
  53. FParaNode : tnode;
  54. FParaLength : smallint;
  55. FAllowVariant : boolean;
  56. function proc_add(pd:tprocdef):pcandidate;
  57. public
  58. constructor create(sym:tprocsym;st:tsymtable;ppn:tnode;isprop:boolean);
  59. constructor create_operator(op:ttoken;ppn:tnode);
  60. destructor destroy;override;
  61. procedure list(all:boolean);
  62. {$ifdef EXTDEBUG}
  63. procedure dump_info(lvl:longint);
  64. {$endif EXTDEBUG}
  65. procedure get_information;
  66. function choose_best(var bestpd:tabstractprocdef):integer;
  67. procedure find_wrong_para;
  68. property Count:integer read FProcCnt;
  69. property VisibleCount:integer read FProcVisibleCnt;
  70. end;
  71. const
  72. tok2nodes=25;
  73. tok2node:array[1..tok2nodes] of ttok2noderec=(
  74. (tok:_PLUS ;nod:addn;op_overloading_supported:true), { binary overloading supported }
  75. (tok:_MINUS ;nod:subn;op_overloading_supported:true), { binary and unary overloading supported }
  76. (tok:_STAR ;nod:muln;op_overloading_supported:true), { binary overloading supported }
  77. (tok:_SLASH ;nod:slashn;op_overloading_supported:true), { binary overloading supported }
  78. (tok:_EQUAL ;nod:equaln;op_overloading_supported:true), { binary overloading supported }
  79. (tok:_GT ;nod:gtn;op_overloading_supported:true), { binary overloading supported }
  80. (tok:_LT ;nod:ltn;op_overloading_supported:true), { binary overloading supported }
  81. (tok:_GTE ;nod:gten;op_overloading_supported:true), { binary overloading supported }
  82. (tok:_LTE ;nod:lten;op_overloading_supported:true), { binary overloading supported }
  83. (tok:_SYMDIF ;nod:symdifn;op_overloading_supported:true), { binary overloading supported }
  84. (tok:_STARSTAR;nod:starstarn;op_overloading_supported:true), { binary overloading supported }
  85. (tok:_OP_AS ;nod:asn;op_overloading_supported:false), { binary overloading NOT supported }
  86. (tok:_OP_IN ;nod:inn;op_overloading_supported:false), { binary overloading NOT supported }
  87. (tok:_OP_IS ;nod:isn;op_overloading_supported:false), { binary overloading NOT supported }
  88. (tok:_OP_OR ;nod:orn;op_overloading_supported:true), { binary overloading supported }
  89. (tok:_OP_AND ;nod:andn;op_overloading_supported:true), { binary overloading supported }
  90. (tok:_OP_DIV ;nod:divn;op_overloading_supported:true), { binary overloading supported }
  91. (tok:_OP_NOT ;nod:notn;op_overloading_supported:true), { unary overloading supported }
  92. (tok:_OP_MOD ;nod:modn;op_overloading_supported:true), { binary overloading supported }
  93. (tok:_OP_SHL ;nod:shln;op_overloading_supported:true), { binary overloading supported }
  94. (tok:_OP_SHR ;nod:shrn;op_overloading_supported:true), { binary overloading supported }
  95. (tok:_OP_XOR ;nod:xorn;op_overloading_supported:true), { binary overloading supported }
  96. (tok:_ASSIGNMENT;nod:assignn;op_overloading_supported:true), { unary overloading supported }
  97. (tok:_CARET ;nod:caretn;op_overloading_supported:false), { binary overloading NOT supported }
  98. (tok:_UNEQUAL ;nod:unequaln;op_overloading_supported:false) { binary overloading NOT supported overload = instead }
  99. );
  100. const
  101. { firstcallparan without varspez we don't count the ref }
  102. {$ifdef extdebug}
  103. count_ref : boolean = true;
  104. {$endif def extdebug}
  105. allow_array_constructor : boolean = false;
  106. function node2opstr(nt:tnodetype):string;
  107. { check operator args and result type }
  108. function isbinaryoperatoroverloadable(treetyp:tnodetype;ld:tdef;lt:tnodetype;rd:tdef;rt:tnodetype) : boolean;
  109. function isoperatoracceptable(pf : tprocdef; optoken : ttoken) : boolean;
  110. function isunaryoverloaded(var t : tnode) : boolean;
  111. function isbinaryoverloaded(var t : tnode) : boolean;
  112. { Register Allocation }
  113. procedure make_not_regable(p : tnode);
  114. procedure calcregisters(p : tbinarynode;r32,fpu,mmx : word);
  115. { subroutine handling }
  116. function is_procsym_load(p:tnode):boolean;
  117. procedure test_local_to_procvar(from_def:tprocvardef;to_def:tdef);
  118. { sets varsym varstate field correctly }
  119. procedure set_varstate(p:tnode;newstate:tvarstate;must_be_valid:boolean);
  120. { sets the callunique flag, if the node is a vecn, }
  121. { takes care of type casts etc. }
  122. procedure set_unique(p : tnode);
  123. function valid_for_formal_var(p : tnode) : boolean;
  124. function valid_for_formal_const(p : tnode) : boolean;
  125. function valid_for_var(p:tnode):boolean;
  126. function valid_for_assignment(p:tnode):boolean;
  127. implementation
  128. uses
  129. globtype,systems,
  130. cutils,verbose,globals,
  131. symtable,
  132. defutil,defcmp,
  133. pass_1,nbas,ncnv,nld,nmem,ncal,nmat,nutils,
  134. cgbase,procinfo
  135. ;
  136. type
  137. TValidAssign=(Valid_Property,Valid_Void,Valid_Const);
  138. TValidAssigns=set of TValidAssign;
  139. function node2opstr(nt:tnodetype):string;
  140. var
  141. i : integer;
  142. begin
  143. result:='<unknown>';
  144. for i:=1 to tok2nodes do
  145. if tok2node[i].nod=nt then
  146. begin
  147. result:=tokeninfo^[tok2node[i].tok].str;
  148. break;
  149. end;
  150. end;
  151. function isbinaryoperatoroverloadable(treetyp:tnodetype;ld:tdef;lt:tnodetype;rd:tdef;rt:tnodetype) : boolean;
  152. function internal_check(treetyp:tnodetype;ld:tdef;lt:tnodetype;rd:tdef;rt:tnodetype;var allowed:boolean):boolean;
  153. begin
  154. internal_check:=true;
  155. case ld.deftype of
  156. formaldef,
  157. recorddef,
  158. variantdef :
  159. begin
  160. allowed:=true;
  161. end;
  162. procvardef :
  163. begin
  164. if (rd.deftype in [pointerdef,procdef,procvardef]) then
  165. begin
  166. allowed:=false;
  167. exit;
  168. end;
  169. allowed:=true;
  170. end;
  171. pointerdef :
  172. begin
  173. if ((rd.deftype in [orddef,enumdef,pointerdef,classrefdef,procvardef]) or
  174. is_class_or_interface(rd)) then
  175. begin
  176. allowed:=false;
  177. exit;
  178. end;
  179. { don't allow pchar+string }
  180. if (is_pchar(ld) or is_pwidechar(ld)) and
  181. ((rd.deftype=stringdef) or
  182. is_pchar(rd) or
  183. is_pwidechar(rd) or
  184. is_chararray(rd) or
  185. is_widechararray(rd)) then
  186. begin
  187. allowed:=false;
  188. exit;
  189. end;
  190. allowed:=true;
  191. end;
  192. arraydef :
  193. begin
  194. { not mmx }
  195. if (cs_mmx in aktlocalswitches) and
  196. is_mmx_able_array(ld) then
  197. begin
  198. allowed:=false;
  199. exit;
  200. end;
  201. { not chararray+[(wide)char,(wide)string,(wide)chararray] }
  202. if (is_chararray(ld) or is_widechararray(ld)) and
  203. ((rd.deftype in [stringdef,orddef,enumdef]) or
  204. is_pchar(rd) or
  205. is_pwidechar(rd) or
  206. is_chararray(rd) or
  207. is_widechararray(rd) or
  208. (rt=niln)) then
  209. begin
  210. allowed:=false;
  211. exit;
  212. end;
  213. { dynamic array compare with niln }
  214. if ((is_dynamic_array(ld) and
  215. (rt=niln)) or
  216. (is_dynamic_array(ld) and is_dynamic_array(rd)))
  217. and
  218. (treetyp in [equaln,unequaln]) then
  219. begin
  220. allowed:=false;
  221. exit;
  222. end;
  223. allowed:=true;
  224. end;
  225. objectdef :
  226. begin
  227. { <> and = are defined for classes }
  228. if (treetyp in [equaln,unequaln]) and
  229. is_class_or_interface(ld) then
  230. begin
  231. allowed:=false;
  232. exit;
  233. end;
  234. allowed:=true;
  235. end;
  236. stringdef :
  237. begin
  238. if ((rd.deftype in [orddef,enumdef,stringdef]) or
  239. is_pchar(rd) or
  240. is_pwidechar(rd) or
  241. is_chararray(rd) or
  242. is_widechararray(rd)) then
  243. begin
  244. allowed:=false;
  245. exit;
  246. end;
  247. allowed:=true;
  248. end;
  249. else
  250. internal_check:=false;
  251. end;
  252. end;
  253. var
  254. allowed : boolean;
  255. begin
  256. { power ** is always possible }
  257. if (treetyp=starstarn) then
  258. begin
  259. isbinaryoperatoroverloadable:=true;
  260. exit;
  261. end;
  262. { order of arguments does not matter so we have to check also
  263. the reversed order }
  264. allowed:=false;
  265. if not internal_check(treetyp,ld,lt,rd,rt,allowed) then
  266. internal_check(treetyp,rd,rt,ld,lt,allowed);
  267. isbinaryoperatoroverloadable:=allowed;
  268. end;
  269. function isunaryoperatoroverloadable(treetyp : tnodetype;ld : tdef) : boolean;
  270. begin
  271. result:=false;
  272. case treetyp of
  273. subn,
  274. unaryminusn :
  275. begin
  276. if is_integer(ld) or
  277. (ld.deftype=floatdef) then
  278. exit;
  279. {$ifdef SUPPORT_MMX}
  280. if (cs_mmx in aktlocalswitches) and
  281. is_mmx_able_array(ld) then
  282. exit;
  283. {$endif SUPPORT_MMX}
  284. result:=true;
  285. end;
  286. notn :
  287. begin
  288. if is_integer(ld) or
  289. is_boolean(ld) then
  290. exit;
  291. {$ifdef SUPPORT_MMX}
  292. if (cs_mmx in aktlocalswitches) and
  293. is_mmx_able_array(ld) then
  294. exit;
  295. {$endif SUPPORT_MMX}
  296. result:=true;
  297. end;
  298. end;
  299. end;
  300. function isoperatoracceptable(pf : tprocdef; optoken : ttoken) : boolean;
  301. var
  302. ld,rd : tdef;
  303. i : longint;
  304. eq : tequaltype;
  305. conv : tconverttype;
  306. pd : tprocdef;
  307. begin
  308. result:=false;
  309. case pf.parast.symindex.count of
  310. 1 : begin
  311. ld:=tvarsym(pf.parast.symindex.first).vartype.def;
  312. { assignment is a special case }
  313. if optoken=_ASSIGNMENT then
  314. begin
  315. eq:=compare_defs_ext(ld,pf.rettype.def,nothingn,conv,pd,[cdo_explicit]);
  316. result:=(eq=te_incompatible);
  317. end
  318. else
  319. begin
  320. for i:=1 to tok2nodes do
  321. if tok2node[i].tok=optoken then
  322. begin
  323. result:=
  324. tok2node[i].op_overloading_supported and
  325. isunaryoperatoroverloadable(tok2node[i].nod,ld);
  326. break;
  327. end;
  328. end;
  329. end;
  330. 2 : begin
  331. for i:=1 to tok2nodes do
  332. if tok2node[i].tok=optoken then
  333. begin
  334. ld:=tvarsym(pf.parast.symindex.first).vartype.def;
  335. rd:=tvarsym(pf.parast.symindex.first.indexnext).vartype.def;
  336. result:=
  337. tok2node[i].op_overloading_supported and
  338. isbinaryoperatoroverloadable(tok2node[i].nod,ld,nothingn,rd,nothingn);
  339. break;
  340. end;
  341. end;
  342. end;
  343. end;
  344. function isunaryoverloaded(var t : tnode) : boolean;
  345. var
  346. ld : tdef;
  347. optoken : ttoken;
  348. operpd : tprocdef;
  349. ppn : tcallparanode;
  350. candidates : tcallcandidates;
  351. cand_cnt : integer;
  352. begin
  353. result:=false;
  354. operpd:=nil;
  355. { load easier access variables }
  356. ld:=tunarynode(t).left.resulttype.def;
  357. if not isunaryoperatoroverloadable(t.nodetype,ld) then
  358. exit;
  359. { operator overload is possible }
  360. result:=true;
  361. case t.nodetype of
  362. notn:
  363. optoken:=_OP_NOT;
  364. unaryminusn:
  365. optoken:=_MINUS;
  366. else
  367. begin
  368. CGMessage(parser_e_operator_not_overloaded);
  369. t:=cnothingnode.create;
  370. exit;
  371. end;
  372. end;
  373. { generate parameter nodes }
  374. ppn:=ccallparanode.create(tunarynode(t).left.getcopy,nil);
  375. ppn.get_paratype;
  376. candidates:=tcallcandidates.create_operator(optoken,ppn);
  377. { stop when there are no operators found }
  378. if candidates.count=0 then
  379. begin
  380. CGMessage(parser_e_operator_not_overloaded);
  381. candidates.free;
  382. ppn.free;
  383. t:=cnothingnode.create;
  384. exit;
  385. end;
  386. { Retrieve information about the candidates }
  387. candidates.get_information;
  388. {$ifdef EXTDEBUG}
  389. { Display info when multiple candidates are found }
  390. candidates.dump_info(V_Debug);
  391. {$endif EXTDEBUG}
  392. cand_cnt:=candidates.choose_best(operpd);
  393. { exit when no overloads are found }
  394. if cand_cnt=0 then
  395. begin
  396. CGMessage(parser_e_operator_not_overloaded);
  397. candidates.free;
  398. ppn.free;
  399. t:=cnothingnode.create;
  400. exit;
  401. end;
  402. { Multiple candidates left? }
  403. if cand_cnt>1 then
  404. begin
  405. CGMessage(cg_e_cant_choose_overload_function);
  406. {$ifdef EXTDEBUG}
  407. candidates.dump_info(V_Hint);
  408. {$else EXTDEBUG}
  409. candidates.list(false);
  410. {$endif EXTDEBUG}
  411. { we'll just use the first candidate to make the
  412. call }
  413. end;
  414. candidates.free;
  415. inc(operpd.procsym.refs);
  416. { the nil as symtable signs firstcalln that this is
  417. an overloaded operator }
  418. t:=ccallnode.create(ppn,Tprocsym(operpd.procsym),nil,nil,[]);
  419. { we already know the procdef to use, so it can
  420. skip the overload choosing in callnode.det_resulttype }
  421. tcallnode(t).procdefinition:=operpd;
  422. end;
  423. function isbinaryoverloaded(var t : tnode) : boolean;
  424. var
  425. rd,ld : tdef;
  426. optoken : ttoken;
  427. operpd : tprocdef;
  428. ht : tnode;
  429. ppn : tcallparanode;
  430. candidates : tcallcandidates;
  431. cand_cnt : integer;
  432. begin
  433. isbinaryoverloaded:=false;
  434. operpd:=nil;
  435. { load easier access variables }
  436. ld:=tbinarynode(t).left.resulttype.def;
  437. rd:=tbinarynode(t).right.resulttype.def;
  438. if not isbinaryoperatoroverloadable(t.nodetype,ld,tbinarynode(t).left.nodetype,rd,tbinarynode(t).right.nodetype) then
  439. exit;
  440. { operator overload is possible }
  441. result:=true;
  442. case t.nodetype of
  443. equaln,
  444. unequaln :
  445. optoken:=_EQUAL;
  446. addn:
  447. optoken:=_PLUS;
  448. subn:
  449. optoken:=_MINUS;
  450. muln:
  451. optoken:=_STAR;
  452. starstarn:
  453. optoken:=_STARSTAR;
  454. slashn:
  455. optoken:=_SLASH;
  456. ltn:
  457. optoken:=_LT;
  458. gtn:
  459. optoken:=_GT;
  460. lten:
  461. optoken:=_LTE;
  462. gten:
  463. optoken:=_GTE;
  464. symdifn :
  465. optoken:=_SYMDIF;
  466. modn :
  467. optoken:=_OP_MOD;
  468. orn :
  469. optoken:=_OP_OR;
  470. xorn :
  471. optoken:=_OP_XOR;
  472. andn :
  473. optoken:=_OP_AND;
  474. divn :
  475. optoken:=_OP_DIV;
  476. shln :
  477. optoken:=_OP_SHL;
  478. shrn :
  479. optoken:=_OP_SHR;
  480. else
  481. begin
  482. CGMessage(parser_e_operator_not_overloaded);
  483. t:=cnothingnode.create;
  484. exit;
  485. end;
  486. end;
  487. { generate parameter nodes }
  488. ppn:=ccallparanode.create(tbinarynode(t).right.getcopy,ccallparanode.create(tbinarynode(t).left.getcopy,nil));
  489. ppn.get_paratype;
  490. candidates:=tcallcandidates.create_operator(optoken,ppn);
  491. { for commutative operators we can swap arguments and try again }
  492. if (candidates.count=0) and
  493. not(optoken in [_OP_SHL,_OP_SHR,_OP_DIV,_OP_MOD,_STARSTAR,_SLASH,_MINUS]) then
  494. begin
  495. candidates.free;
  496. reverseparameters(ppn);
  497. { reverse compare operators }
  498. case optoken of
  499. _LT:
  500. optoken:=_GTE;
  501. _GT:
  502. optoken:=_LTE;
  503. _LTE:
  504. optoken:=_GT;
  505. _GTE:
  506. optoken:=_LT;
  507. end;
  508. candidates:=tcallcandidates.create_operator(optoken,ppn);
  509. end;
  510. { stop when there are no operators found }
  511. if candidates.count=0 then
  512. begin
  513. CGMessage(parser_e_operator_not_overloaded);
  514. candidates.free;
  515. ppn.free;
  516. t:=cnothingnode.create;
  517. exit;
  518. end;
  519. { Retrieve information about the candidates }
  520. candidates.get_information;
  521. {$ifdef EXTDEBUG}
  522. { Display info when multiple candidates are found }
  523. candidates.dump_info(V_Debug);
  524. {$endif EXTDEBUG}
  525. cand_cnt:=candidates.choose_best(operpd);
  526. { exit when no overloads are found }
  527. if cand_cnt=0 then
  528. begin
  529. CGMessage(parser_e_operator_not_overloaded);
  530. candidates.free;
  531. ppn.free;
  532. t:=cnothingnode.create;
  533. exit;
  534. end;
  535. { Multiple candidates left? }
  536. if cand_cnt>1 then
  537. begin
  538. CGMessage(cg_e_cant_choose_overload_function);
  539. {$ifdef EXTDEBUG}
  540. candidates.dump_info(V_Hint);
  541. {$else EXTDEBUG}
  542. candidates.list(false);
  543. {$endif EXTDEBUG}
  544. { we'll just use the first candidate to make the
  545. call }
  546. end;
  547. candidates.free;
  548. inc(operpd.procsym.refs);
  549. { the nil as symtable signs firstcalln that this is
  550. an overloaded operator }
  551. ht:=ccallnode.create(ppn,Tprocsym(operpd.procsym),nil,nil,[]);
  552. { we already know the procdef to use, so it can
  553. skip the overload choosing in callnode.det_resulttype }
  554. tcallnode(ht).procdefinition:=operpd;
  555. if t.nodetype=unequaln then
  556. ht:=cnotnode.create(ht);
  557. t:=ht;
  558. end;
  559. {****************************************************************************
  560. Register Calculation
  561. ****************************************************************************}
  562. { marks an lvalue as "unregable" }
  563. procedure make_not_regable(p : tnode);
  564. begin
  565. case p.nodetype of
  566. typeconvn :
  567. make_not_regable(ttypeconvnode(p).left);
  568. loadn :
  569. if tloadnode(p).symtableentry.typ=varsym then
  570. tvarsym(tloadnode(p).symtableentry).varoptions:=tvarsym(tloadnode(p).symtableentry).varoptions-[vo_regable,vo_fpuregable];
  571. end;
  572. end;
  573. { calculates the needed registers for a binary operator }
  574. procedure calcregisters(p : tbinarynode;r32,fpu,mmx : word);
  575. begin
  576. p.left_right_max;
  577. { Only when the difference between the left and right registers < the
  578. wanted registers allocate the amount of registers }
  579. if assigned(p.left) then
  580. begin
  581. if assigned(p.right) then
  582. begin
  583. { the location must be already filled in because we need it to }
  584. { calculate the necessary number of registers (JM) }
  585. if p.expectloc = LOC_INVALID then
  586. internalerror(200110101);
  587. if (abs(p.left.registersint-p.right.registersint)<r32) or
  588. ((p.expectloc = LOC_FPUREGISTER) and
  589. (p.right.registersfpu <= p.left.registersfpu) and
  590. ((p.right.registersfpu <> 0) or (p.left.registersfpu <> 0)) and
  591. (p.left.registersint < p.right.registersint)) then
  592. inc(p.registersint,r32);
  593. if (abs(p.left.registersfpu-p.right.registersfpu)<fpu) then
  594. inc(p.registersfpu,fpu);
  595. {$ifdef SUPPORT_MMX}
  596. if (abs(p.left.registersmmx-p.right.registersmmx)<mmx) then
  597. inc(p.registersmmx,mmx);
  598. {$endif SUPPORT_MMX}
  599. { the following is a little bit guessing but I think }
  600. { it's the only way to solve same internalerrors: }
  601. { if the left and right node both uses registers }
  602. { and return a mem location, but the current node }
  603. { doesn't use an integer register we get probably }
  604. { trouble when restoring a node }
  605. if (p.left.registersint=p.right.registersint) and
  606. (p.registersint=p.left.registersint) and
  607. (p.registersint>0) and
  608. (p.left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE]) and
  609. (p.right.expectloc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  610. inc(p.registersint);
  611. end
  612. else
  613. begin
  614. if (p.left.registersint<r32) then
  615. inc(p.registersint,r32);
  616. if (p.left.registersfpu<fpu) then
  617. inc(p.registersfpu,fpu);
  618. {$ifdef SUPPORT_MMX}
  619. if (p.left.registersmmx<mmx) then
  620. inc(p.registersmmx,mmx);
  621. {$endif SUPPORT_MMX}
  622. end;
  623. end;
  624. { error CGMessage, if more than 8 floating point }
  625. { registers are needed }
  626. { if p.registersfpu>maxfpuregs then
  627. CGMessage(cg_e_too_complex_expr); now pushed if needed PM }
  628. end;
  629. {****************************************************************************
  630. Subroutine Handling
  631. ****************************************************************************}
  632. function is_procsym_load(p:tnode):boolean;
  633. begin
  634. { ignore vecn,subscriptn }
  635. repeat
  636. case p.nodetype of
  637. vecn :
  638. p:=tvecnode(p).left;
  639. subscriptn :
  640. p:=tsubscriptnode(p).left;
  641. else
  642. break;
  643. end;
  644. until false;
  645. is_procsym_load:=((p.nodetype=loadn) and (tloadnode(p).symtableentry.typ=procsym)) or
  646. ((p.nodetype=addrn) and (taddrnode(p).left.nodetype=loadn)
  647. and (tloadnode(taddrnode(p).left).symtableentry.typ=procsym)) ;
  648. end;
  649. { local routines can't be assigned to procvars }
  650. procedure test_local_to_procvar(from_def:tprocvardef;to_def:tdef);
  651. begin
  652. if (from_def.parast.symtablelevel>normal_function_level) and
  653. (to_def.deftype=procvardef) then
  654. CGMessage(type_e_cannot_local_proc_to_procvar);
  655. end;
  656. procedure set_varstate(p:tnode;newstate:tvarstate;must_be_valid:boolean);
  657. var
  658. hsym : tvarsym;
  659. begin
  660. while assigned(p) do
  661. begin
  662. case p.nodetype of
  663. typeconvn :
  664. begin
  665. case ttypeconvnode(p).convtype of
  666. tc_cchar_2_pchar,
  667. tc_cstring_2_pchar,
  668. tc_array_2_pointer :
  669. must_be_valid:=false;
  670. tc_pchar_2_string,
  671. tc_pointer_2_array :
  672. must_be_valid:=true;
  673. end;
  674. p:=tunarynode(p).left;
  675. end;
  676. subscriptn :
  677. p:=tunarynode(p).left;
  678. vecn:
  679. begin
  680. set_varstate(tbinarynode(p).right,vs_used,true);
  681. if not(tunarynode(p).left.resulttype.def.deftype in [stringdef,arraydef]) then
  682. must_be_valid:=true;
  683. p:=tunarynode(p).left;
  684. end;
  685. { do not parse calln }
  686. calln :
  687. break;
  688. loadn :
  689. begin
  690. if (tloadnode(p).symtableentry.typ=varsym) then
  691. begin
  692. hsym:=tvarsym(tloadnode(p).symtableentry);
  693. if must_be_valid and (hsym.varstate=vs_declared) then
  694. begin
  695. { Give warning/note for uninitialized locals }
  696. if assigned(hsym.owner) and
  697. not(vo_is_external in hsym.varoptions) and
  698. (hsym.owner.symtabletype in [localsymtable,staticsymtable]) and
  699. (hsym.owner=current_procinfo.procdef.localst) then
  700. begin
  701. if (vo_is_funcret in hsym.varoptions) then
  702. CGMessage(sym_w_function_result_not_set)
  703. else
  704. if tloadnode(p).symtable.symtabletype=localsymtable then
  705. CGMessage1(sym_n_uninitialized_local_variable,hsym.realname)
  706. else
  707. CGMessage1(sym_n_uninitialized_variable,hsym.realname);
  708. end;
  709. end;
  710. { don't override vs_used with vs_assigned }
  711. if hsym.varstate<>vs_used then
  712. hsym.varstate:=newstate;
  713. end;
  714. break;
  715. end;
  716. callparan :
  717. internalerror(200310081);
  718. else
  719. break;
  720. end;{case }
  721. end;
  722. end;
  723. procedure set_unique(p : tnode);
  724. begin
  725. while assigned(p) do
  726. begin
  727. case p.nodetype of
  728. vecn:
  729. begin
  730. include(p.flags,nf_callunique);
  731. break;
  732. end;
  733. typeconvn,
  734. subscriptn,
  735. derefn:
  736. p:=tunarynode(p).left;
  737. else
  738. break;
  739. end;
  740. end;
  741. end;
  742. function valid_for_assign(p:tnode;opts:TValidAssigns):boolean;
  743. var
  744. hp : tnode;
  745. gotwith,
  746. gotsubscript,
  747. gotpointer,
  748. gotvec,
  749. gotclass,
  750. gotderef : boolean;
  751. fromdef,
  752. todef : tdef;
  753. begin
  754. valid_for_assign:=false;
  755. gotsubscript:=false;
  756. gotvec:=false;
  757. gotderef:=false;
  758. gotclass:=false;
  759. gotpointer:=false;
  760. gotwith:=false;
  761. hp:=p;
  762. if not(valid_void in opts) and
  763. is_void(hp.resulttype.def) then
  764. begin
  765. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  766. exit;
  767. end;
  768. while assigned(hp) do
  769. begin
  770. { property allowed? calln has a property check itself }
  771. if (nf_isproperty in hp.flags) then
  772. begin
  773. if (valid_property in opts) then
  774. valid_for_assign:=true
  775. else
  776. begin
  777. { check return type }
  778. case hp.resulttype.def.deftype of
  779. pointerdef :
  780. gotpointer:=true;
  781. objectdef :
  782. gotclass:=is_class_or_interface(hp.resulttype.def);
  783. recorddef, { handle record like class it needs a subscription }
  784. classrefdef :
  785. gotclass:=true;
  786. end;
  787. { 1. if it returns a pointer and we've found a deref,
  788. 2. if it returns a class or record and a subscription or with is found }
  789. if (gotpointer and gotderef) or
  790. (gotclass and (gotsubscript or gotwith)) then
  791. valid_for_assign:=true
  792. else
  793. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  794. end;
  795. exit;
  796. end;
  797. if (Valid_Const in opts) and is_constnode(hp) then
  798. begin
  799. valid_for_assign:=true;
  800. exit;
  801. end;
  802. case hp.nodetype of
  803. temprefn :
  804. begin
  805. valid_for_assign := true;
  806. exit;
  807. end;
  808. derefn :
  809. begin
  810. gotderef:=true;
  811. hp:=tderefnode(hp).left;
  812. end;
  813. typeconvn :
  814. begin
  815. { typecast sizes must match, exceptions:
  816. - implicit typecast made by absolute
  817. - from formaldef
  818. - from void
  819. - from/to open array
  820. - typecast from pointer to array }
  821. fromdef:=ttypeconvnode(hp).left.resulttype.def;
  822. todef:=hp.resulttype.def;
  823. if not((nf_absolute in ttypeconvnode(hp).flags) or
  824. (fromdef.deftype=formaldef) or
  825. is_void(fromdef) or
  826. is_open_array(fromdef) or
  827. is_open_array(todef) or
  828. ((fromdef.deftype=pointerdef) and (todef.deftype=arraydef)) or
  829. ((fromdef.deftype = objectdef) and (todef.deftype = objectdef) and
  830. (tobjectdef(fromdef).is_related(tobjectdef(todef))))) and
  831. (fromdef.size<>todef.size) then
  832. begin
  833. { in TP it is allowed to typecast to smaller types }
  834. if not(m_tp7 in aktmodeswitches) or
  835. (todef.size>fromdef.size) then
  836. CGMessagePos2(hp.fileinfo,type_e_typecast_wrong_size_for_assignment,tostr(fromdef.size),tostr(todef.size));
  837. end;
  838. { don't allow assignments to typeconvs that need special code }
  839. if not(gotsubscript or gotvec or gotderef) and
  840. not(ttypeconvnode(hp).assign_allowed) then
  841. begin
  842. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  843. exit;
  844. end;
  845. case hp.resulttype.def.deftype of
  846. pointerdef :
  847. gotpointer:=true;
  848. objectdef :
  849. gotclass:=is_class_or_interface(hp.resulttype.def);
  850. classrefdef :
  851. gotclass:=true;
  852. arraydef :
  853. begin
  854. { pointer -> array conversion is done then we need to see it
  855. as a deref, because a ^ is then not required anymore }
  856. if (ttypeconvnode(hp).left.resulttype.def.deftype=pointerdef) then
  857. gotderef:=true;
  858. end;
  859. end;
  860. hp:=ttypeconvnode(hp).left;
  861. end;
  862. vecn :
  863. begin
  864. gotvec:=true;
  865. hp:=tunarynode(hp).left;
  866. end;
  867. asn :
  868. begin
  869. { asn can't be assigned directly, it returns the value in a register instead
  870. of reference. }
  871. if not(gotsubscript or gotderef or gotvec) then
  872. begin
  873. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  874. exit;
  875. end;
  876. hp:=tunarynode(hp).left;
  877. end;
  878. subscriptn :
  879. begin
  880. gotsubscript:=true;
  881. { a class/interface access is an implicit }
  882. { dereferencing }
  883. hp:=tsubscriptnode(hp).left;
  884. if is_class_or_interface(hp.resulttype.def) then
  885. gotderef:=true;
  886. end;
  887. subn,
  888. addn :
  889. begin
  890. { Allow add/sub operators on a pointer, or an integer
  891. and a pointer typecast and deref has been found }
  892. if ((hp.resulttype.def.deftype=pointerdef) or
  893. (is_integer(hp.resulttype.def) and gotpointer)) and
  894. gotderef then
  895. valid_for_assign:=true
  896. else
  897. CGMessagePos(hp.fileinfo,type_e_variable_id_expected);
  898. exit;
  899. end;
  900. addrn :
  901. begin
  902. if gotderef or
  903. (nf_procvarload in hp.flags) then
  904. valid_for_assign:=true
  905. else
  906. CGMessagePos(hp.fileinfo,type_e_no_assign_to_addr);
  907. exit;
  908. end;
  909. calln :
  910. begin
  911. { check return type }
  912. case hp.resulttype.def.deftype of
  913. arraydef :
  914. begin
  915. { dynamic arrays are allowed when there is also a
  916. vec node }
  917. if is_dynamic_array(hp.resulttype.def) and
  918. gotvec then
  919. begin
  920. gotderef:=true;
  921. gotpointer:=true;
  922. end;
  923. end;
  924. pointerdef :
  925. gotpointer:=true;
  926. objectdef :
  927. gotclass:=is_class_or_interface(hp.resulttype.def);
  928. recorddef, { handle record like class it needs a subscription }
  929. classrefdef :
  930. gotclass:=true;
  931. end;
  932. { 1. if it returns a pointer and we've found a deref,
  933. 2. if it returns a class or record and a subscription or with is found }
  934. if (gotpointer and gotderef) or
  935. (gotclass and (gotsubscript or gotwith)) then
  936. valid_for_assign:=true
  937. else
  938. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  939. exit;
  940. end;
  941. loadn :
  942. begin
  943. case tloadnode(hp).symtableentry.typ of
  944. absolutesym,
  945. varsym :
  946. begin
  947. if (tvarsym(tloadnode(hp).symtableentry).varspez=vs_const) then
  948. begin
  949. { allow p^:= constructions with p is const parameter }
  950. if gotderef or (Valid_Const in opts) then
  951. valid_for_assign:=true
  952. else
  953. CGMessagePos(tloadnode(hp).fileinfo,type_e_no_assign_to_const);
  954. exit;
  955. end;
  956. { Are we at a with symtable, then we need to process the
  957. withrefnode also to check for maybe a const load }
  958. if (tloadnode(hp).symtable.symtabletype=withsymtable) then
  959. begin
  960. { continue with processing the withref node }
  961. hp:=tnode(twithsymtable(tloadnode(hp).symtable).withrefnode);
  962. gotwith:=true;
  963. end
  964. else
  965. begin
  966. valid_for_assign:=true;
  967. exit;
  968. end;
  969. end;
  970. typedconstsym :
  971. begin
  972. if ttypedconstsym(tloadnode(hp).symtableentry).is_writable then
  973. valid_for_assign:=true
  974. else
  975. CGMessagePos(hp.fileinfo,type_e_no_assign_to_const);
  976. exit;
  977. end;
  978. else
  979. begin
  980. CGMessagePos(hp.fileinfo,type_e_variable_id_expected);
  981. exit;
  982. end;
  983. end;
  984. end;
  985. else
  986. begin
  987. CGMessagePos(hp.fileinfo,type_e_variable_id_expected);
  988. exit;
  989. end;
  990. end;
  991. end;
  992. end;
  993. function valid_for_var(p:tnode):boolean;
  994. begin
  995. valid_for_var:=valid_for_assign(p,[]);
  996. end;
  997. function valid_for_formal_var(p : tnode) : boolean;
  998. begin
  999. valid_for_formal_var:=valid_for_assign(p,[valid_void]);
  1000. end;
  1001. function valid_for_formal_const(p : tnode) : boolean;
  1002. begin
  1003. valid_for_formal_const:=is_procsym_load(p) or (p.resulttype.def.deftype=formaldef) or
  1004. valid_for_assign(p,[valid_void,valid_const,valid_property]);
  1005. end;
  1006. function valid_for_assignment(p:tnode):boolean;
  1007. begin
  1008. valid_for_assignment:=valid_for_assign(p,[valid_property]);
  1009. end;
  1010. procedure var_para_allowed(var eq:tequaltype;def_from,def_to:Tdef);
  1011. begin
  1012. { Note: eq must be already valid, it will only be updated! }
  1013. case def_to.deftype of
  1014. formaldef :
  1015. begin
  1016. { all types can be passed to a formaldef }
  1017. eq:=te_equal;
  1018. end;
  1019. orddef :
  1020. begin
  1021. { allows conversion from word to integer and
  1022. byte to shortint, but only for TP7 compatibility }
  1023. if (m_tp7 in aktmodeswitches) and
  1024. (def_from.deftype=orddef) and
  1025. (def_from.size=def_to.size) then
  1026. eq:=te_convert_l1;
  1027. end;
  1028. arraydef :
  1029. begin
  1030. if is_open_array(def_to) and
  1031. is_dynamic_array(def_from) and
  1032. equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  1033. eq:=te_convert_l2;
  1034. end;
  1035. pointerdef :
  1036. begin
  1037. { an implicit pointer conversion is allowed }
  1038. if (def_from.deftype=pointerdef) then
  1039. eq:=te_convert_l1;
  1040. end;
  1041. stringdef :
  1042. begin
  1043. { all shortstrings are allowed, size is not important }
  1044. if is_shortstring(def_from) and
  1045. is_shortstring(def_to) then
  1046. eq:=te_equal;
  1047. end;
  1048. objectdef :
  1049. begin
  1050. { child objects can be also passed }
  1051. { in non-delphi mode, otherwise }
  1052. { they must match exactly, except }
  1053. { if they are objects }
  1054. if (def_from.deftype=objectdef) and
  1055. (
  1056. not(m_delphi in aktmodeswitches) or
  1057. (
  1058. (tobjectdef(def_from).objecttype=odt_object) and
  1059. (tobjectdef(def_to).objecttype=odt_object)
  1060. )
  1061. ) and
  1062. (tobjectdef(def_from).is_related(tobjectdef(def_to))) then
  1063. eq:=te_convert_l1;
  1064. end;
  1065. filedef :
  1066. begin
  1067. { an implicit file conversion is also allowed }
  1068. { from a typed file to an untyped one }
  1069. if (def_from.deftype=filedef) and
  1070. (tfiledef(def_from).filetyp = ft_typed) and
  1071. (tfiledef(def_to).filetyp = ft_untyped) then
  1072. eq:=te_convert_l1;
  1073. end;
  1074. end;
  1075. end;
  1076. procedure para_allowed(var eq:tequaltype;p:tcallparanode;def_to:tdef);
  1077. begin
  1078. { Note: eq must be already valid, it will only be updated! }
  1079. case def_to.deftype of
  1080. formaldef :
  1081. begin
  1082. { all types can be passed to a formaldef }
  1083. eq:=te_equal;
  1084. end;
  1085. stringdef :
  1086. begin
  1087. { to support ansi/long/wide strings in a proper way }
  1088. { string and string[10] are assumed as equal }
  1089. { when searching the correct overloaded procedure }
  1090. if (p.resulttype.def.deftype=stringdef) and
  1091. (tstringdef(def_to).string_typ=tstringdef(p.resulttype.def).string_typ) then
  1092. eq:=te_equal
  1093. else
  1094. { Passing a constant char to ansistring or shortstring or
  1095. a widechar to widestring then handle it as equal. }
  1096. if (p.left.nodetype=ordconstn) and
  1097. (
  1098. is_char(p.resulttype.def) and
  1099. (is_shortstring(def_to) or is_ansistring(def_to))
  1100. ) or
  1101. (
  1102. is_widechar(p.resulttype.def) and
  1103. is_widestring(def_to)
  1104. ) then
  1105. eq:=te_equal
  1106. end;
  1107. setdef :
  1108. begin
  1109. { set can also be a not yet converted array constructor }
  1110. if (p.resulttype.def.deftype=arraydef) and
  1111. (tarraydef(p.resulttype.def).IsConstructor) and
  1112. not(tarraydef(p.resulttype.def).IsVariant) then
  1113. eq:=te_equal;
  1114. end;
  1115. procvardef :
  1116. begin
  1117. { in tp7 mode proc -> procvar is allowed }
  1118. if (m_tp_procvar in aktmodeswitches) and
  1119. (p.left.nodetype=calln) and
  1120. (proc_to_procvar_equal(tprocdef(tcallnode(p.left).procdefinition),tprocvardef(def_to),true)>=te_equal) then
  1121. eq:=te_equal;
  1122. end;
  1123. end;
  1124. end;
  1125. {****************************************************************************
  1126. TCallCandidates
  1127. ****************************************************************************}
  1128. constructor tcallcandidates.create(sym:tprocsym;st:tsymtable;ppn:tnode;isprop:boolean);
  1129. var
  1130. j : integer;
  1131. pd : tprocdef;
  1132. hp : pcandidate;
  1133. found,
  1134. has_overload_directive : boolean;
  1135. topclassh : tobjectdef;
  1136. srsymtable : tsymtable;
  1137. srprocsym : tprocsym;
  1138. pt : tcallparanode;
  1139. begin
  1140. FProcSym:=sym;
  1141. FProcs:=nil;
  1142. FProccnt:=0;
  1143. FProcvisiblecnt:=0;
  1144. FParanode:=ppn;
  1145. FAllowVariant:=true;
  1146. { determine length of parameter list }
  1147. pt:=tcallparanode(ppn);
  1148. FParalength:=0;
  1149. while assigned(pt) do
  1150. begin
  1151. inc(FParalength);
  1152. pt:=tcallparanode(pt.right);
  1153. end;
  1154. { when the definition has overload directive set, we search for
  1155. overloaded definitions in the class, this only needs to be done once
  1156. for class entries as the tree keeps always the same }
  1157. if (not sym.overloadchecked) and
  1158. (sym.owner.symtabletype=objectsymtable) and
  1159. (po_overload in sym.first_procdef.procoptions) then
  1160. search_class_overloads(sym);
  1161. { when the class passed is defined in this unit we
  1162. need to use the scope of that class. This is a trick
  1163. that can be used to access protected members in other
  1164. units. At least kylix supports it this way (PFV) }
  1165. if assigned(st) and
  1166. (st.symtabletype=objectsymtable) and
  1167. (st.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1168. (st.defowner.owner.unitid=0) then
  1169. topclassh:=tobjectdef(st.defowner)
  1170. else
  1171. begin
  1172. if assigned(current_procinfo) then
  1173. topclassh:=current_procinfo.procdef._class
  1174. else
  1175. topclassh:=nil;
  1176. end;
  1177. { link all procedures which have the same # of parameters }
  1178. for j:=1 to sym.procdef_count do
  1179. begin
  1180. pd:=sym.procdef[j];
  1181. { Is the procdef visible? This needs to be checked on
  1182. procdef level since a symbol can contain both private and
  1183. public declarations. But the check should not be done
  1184. when the callnode is generated by a property }
  1185. if isprop or
  1186. (pd.owner.symtabletype<>objectsymtable) or
  1187. pd.is_visible_for_object(topclassh) then
  1188. begin
  1189. { we have at least one procedure that is visible }
  1190. inc(FProcvisiblecnt);
  1191. { only when the # of parameter are supported by the
  1192. procedure }
  1193. if (FParalength>=pd.minparacount) and
  1194. ((po_varargs in pd.procoptions) or { varargs }
  1195. (FParalength<=pd.maxparacount)) then
  1196. proc_add(pd);
  1197. end;
  1198. end;
  1199. { remember if the procedure is declared with the overload directive,
  1200. it's information is still needed also after all procs are removed }
  1201. has_overload_directive:=(po_overload in sym.first_procdef.procoptions);
  1202. { when the definition has overload directive set, we search for
  1203. overloaded definitions in the symtablestack. The found
  1204. entries are only added to the procs list and not the procsym, because
  1205. the list can change in every situation }
  1206. if has_overload_directive and
  1207. (sym.owner.symtabletype<>objectsymtable) then
  1208. begin
  1209. srsymtable:=sym.owner.next;
  1210. while assigned(srsymtable) do
  1211. begin
  1212. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1213. begin
  1214. srprocsym:=tprocsym(srsymtable.speedsearch(sym.name,sym.speedvalue));
  1215. { process only visible procsyms }
  1216. if assigned(srprocsym) and
  1217. (srprocsym.typ=procsym) and
  1218. srprocsym.is_visible_for_object(topclassh) then
  1219. begin
  1220. { if this procedure doesn't have overload we can stop
  1221. searching }
  1222. if not(po_overload in srprocsym.first_procdef.procoptions) then
  1223. break;
  1224. { process all overloaded definitions }
  1225. for j:=1 to srprocsym.procdef_count do
  1226. begin
  1227. pd:=srprocsym.procdef[j];
  1228. { only when the # of parameter are supported by the
  1229. procedure }
  1230. if (FParalength>=pd.minparacount) and
  1231. ((po_varargs in pd.procoptions) or { varargs }
  1232. (FParalength<=pd.maxparacount)) then
  1233. begin
  1234. found:=false;
  1235. hp:=FProcs;
  1236. while assigned(hp) do
  1237. begin
  1238. { Only compare visible parameters for the user }
  1239. if compare_paras(hp^.data.para,pd.para,cp_value_equal_const,[cpo_ignorehidden])>=te_equal then
  1240. begin
  1241. found:=true;
  1242. break;
  1243. end;
  1244. hp:=hp^.next;
  1245. end;
  1246. if not found then
  1247. proc_add(pd);
  1248. end;
  1249. end;
  1250. end;
  1251. end;
  1252. srsymtable:=srsymtable.next;
  1253. end;
  1254. end;
  1255. end;
  1256. constructor tcallcandidates.create_operator(op:ttoken;ppn:tnode);
  1257. var
  1258. j : integer;
  1259. pd : tprocdef;
  1260. hp : pcandidate;
  1261. found : boolean;
  1262. srsymtable : tsymtable;
  1263. srprocsym : tprocsym;
  1264. pt : tcallparanode;
  1265. sv : cardinal;
  1266. begin
  1267. FProcSym:=nil;
  1268. FProcs:=nil;
  1269. FProccnt:=0;
  1270. FProcvisiblecnt:=0;
  1271. FParanode:=ppn;
  1272. FAllowVariant:=false;
  1273. { determine length of parameter list }
  1274. pt:=tcallparanode(ppn);
  1275. FParalength:=0;
  1276. while assigned(pt) do
  1277. begin
  1278. if pt.resulttype.def.deftype=variantdef then
  1279. FAllowVariant:=true;
  1280. inc(FParalength);
  1281. pt:=tcallparanode(pt.right);
  1282. end;
  1283. { we search all overloaded operator definitions in the symtablestack. The found
  1284. entries are only added to the procs list and not the procsym, because
  1285. the list can change in every situation }
  1286. sv:=getspeedvalue(overloaded_names[op]);
  1287. srsymtable:=symtablestack;
  1288. while assigned(srsymtable) do
  1289. begin
  1290. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1291. begin
  1292. srprocsym:=tprocsym(srsymtable.speedsearch(overloaded_names[op],sv));
  1293. if assigned(srprocsym) and
  1294. (srprocsym.typ=procsym) then
  1295. begin
  1296. { Store first procsym found }
  1297. if not assigned(FProcsym) then
  1298. FProcsym:=srprocsym;
  1299. { process all overloaded definitions }
  1300. for j:=1 to srprocsym.procdef_count do
  1301. begin
  1302. pd:=srprocsym.procdef[j];
  1303. { only when the # of parameter are supported by the
  1304. procedure }
  1305. if (FParalength>=pd.minparacount) and
  1306. (FParalength<=pd.maxparacount) then
  1307. begin
  1308. found:=false;
  1309. hp:=FProcs;
  1310. while assigned(hp) do
  1311. begin
  1312. { Only compare visible parameters for the user }
  1313. if compare_paras(hp^.data.para,pd.para,cp_value_equal_const,[cpo_ignorehidden])>=te_equal then
  1314. begin
  1315. found:=true;
  1316. break;
  1317. end;
  1318. hp:=hp^.next;
  1319. end;
  1320. if not found then
  1321. proc_add(pd);
  1322. end;
  1323. end;
  1324. end;
  1325. end;
  1326. srsymtable:=srsymtable.next;
  1327. end;
  1328. end;
  1329. destructor tcallcandidates.destroy;
  1330. var
  1331. hpnext,
  1332. hp : pcandidate;
  1333. begin
  1334. hp:=FProcs;
  1335. while assigned(hp) do
  1336. begin
  1337. hpnext:=hp^.next;
  1338. dispose(hp);
  1339. hp:=hpnext;
  1340. end;
  1341. end;
  1342. function tcallcandidates.proc_add(pd:tprocdef):pcandidate;
  1343. var
  1344. i : integer;
  1345. begin
  1346. { generate new candidate entry }
  1347. new(result);
  1348. fillchar(result^,sizeof(tcandidate),0);
  1349. result^.data:=pd;
  1350. result^.next:=FProcs;
  1351. FProcs:=result;
  1352. inc(FProccnt);
  1353. { Find last parameter, skip all default parameters
  1354. that are not passed. Ignore this skipping for varargs }
  1355. result^.firstpara:=tparaitem(pd.Para.last);
  1356. if not(po_varargs in pd.procoptions) then
  1357. begin
  1358. { ignore hidden parameters }
  1359. while assigned(result^.firstpara) and (result^.firstpara.is_hidden) do
  1360. result^.firstpara:=tparaitem(result^.firstpara.previous);
  1361. for i:=1 to pd.maxparacount-FParalength do
  1362. begin
  1363. if not assigned(result^.firstpara) then
  1364. internalerror(200401141);
  1365. result^.firstpara:=tparaitem(result^.firstPara.previous);
  1366. end;
  1367. end;
  1368. end;
  1369. procedure tcallcandidates.list(all:boolean);
  1370. var
  1371. hp : pcandidate;
  1372. begin
  1373. hp:=FProcs;
  1374. while assigned(hp) do
  1375. begin
  1376. if all or
  1377. (not hp^.invalid) then
  1378. MessagePos1(hp^.data.fileinfo,sym_h_param_list,hp^.data.fullprocname(false));
  1379. hp:=hp^.next;
  1380. end;
  1381. end;
  1382. {$ifdef EXTDEBUG}
  1383. procedure tcallcandidates.dump_info(lvl:longint);
  1384. function ParaTreeStr(p:tcallparanode):string;
  1385. begin
  1386. result:='';
  1387. while assigned(p) do
  1388. begin
  1389. if result<>'' then
  1390. result:=result+',';
  1391. result:=result+p.resulttype.def.typename;
  1392. p:=tcallparanode(p.right);
  1393. end;
  1394. end;
  1395. var
  1396. hp : pcandidate;
  1397. currpara : tparaitem;
  1398. begin
  1399. if not CheckVerbosity(lvl) then
  1400. exit;
  1401. Comment(lvl+V_LineInfo,'Overloaded callnode: '+FProcSym.name+'('+ParaTreeStr(tcallparanode(FParaNode))+')');
  1402. hp:=FProcs;
  1403. while assigned(hp) do
  1404. begin
  1405. Comment(lvl,' '+hp^.data.fullprocname(false));
  1406. if (hp^.invalid) then
  1407. Comment(lvl,' invalid')
  1408. else
  1409. begin
  1410. Comment(lvl,' ex: '+tostr(hp^.exact_count)+
  1411. ' eq: '+tostr(hp^.equal_count)+
  1412. ' l1: '+tostr(hp^.cl1_count)+
  1413. ' l2: '+tostr(hp^.cl2_count)+
  1414. ' l3: '+tostr(hp^.cl3_count)+
  1415. ' oper: '+tostr(hp^.coper_count)+
  1416. ' ord: '+realtostr(hp^.exact_count));
  1417. { Print parameters in left-right order }
  1418. currpara:=hp^.firstpara;
  1419. if assigned(currpara) then
  1420. begin
  1421. while assigned(currpara.next) do
  1422. currpara:=tparaitem(currpara.next);
  1423. end;
  1424. while assigned(currpara) do
  1425. begin
  1426. if (not currpara.is_hidden) then
  1427. Comment(lvl,' - '+currpara.paratype.def.typename+' : '+EqualTypeName[currpara.eqval]);
  1428. currpara:=tparaitem(currpara.previous);
  1429. end;
  1430. end;
  1431. hp:=hp^.next;
  1432. end;
  1433. end;
  1434. {$endif EXTDEBUG}
  1435. procedure tcallcandidates.get_information;
  1436. var
  1437. hp : pcandidate;
  1438. currpara : tparaitem;
  1439. currparanr : byte;
  1440. def_from,
  1441. def_to : tdef;
  1442. currpt,
  1443. pt : tcallparanode;
  1444. eq : tequaltype;
  1445. convtype : tconverttype;
  1446. pdoper : tprocdef;
  1447. releasecurrpt : boolean;
  1448. cdoptions : tcompare_defs_options;
  1449. begin
  1450. cdoptions:=[cdo_check_operator];
  1451. if FAllowVariant then
  1452. include(cdoptions,cdo_allow_variant);
  1453. { process all procs }
  1454. hp:=FProcs;
  1455. while assigned(hp) do
  1456. begin
  1457. { We compare parameters in reverse order (right to left),
  1458. the firstpara is already pointing to the last parameter
  1459. were we need to start comparing }
  1460. currparanr:=FParalength;
  1461. currpara:=hp^.firstpara;
  1462. while assigned(currpara) and (currpara.is_hidden) do
  1463. currpara:=tparaitem(currpara.previous);
  1464. pt:=tcallparanode(FParaNode);
  1465. while assigned(pt) and assigned(currpara) do
  1466. begin
  1467. { currpt can be changed from loadn to calln when a procvar
  1468. is passed. This is to prevent that the change is permanent }
  1469. currpt:=pt;
  1470. releasecurrpt:=false;
  1471. { retrieve current parameter definitions to compares }
  1472. eq:=te_incompatible;
  1473. def_from:=currpt.resulttype.def;
  1474. def_to:=currpara.paratype.def;
  1475. if not(assigned(def_from)) then
  1476. internalerror(200212091);
  1477. if not(
  1478. assigned(def_to) or
  1479. ((po_varargs in hp^.data.procoptions) and
  1480. (currparanr>hp^.data.minparacount))
  1481. ) then
  1482. internalerror(200212092);
  1483. { Convert tp procvars when not expecting a procvar }
  1484. if (def_to.deftype<>procvardef) and
  1485. (currpt.left.resulttype.def.deftype=procvardef) then
  1486. begin
  1487. releasecurrpt:=true;
  1488. currpt:=tcallparanode(pt.getcopy);
  1489. if maybe_call_procvar(currpt.left,true) then
  1490. begin
  1491. currpt.resulttype:=currpt.left.resulttype;
  1492. def_from:=currpt.left.resulttype.def;
  1493. end;
  1494. end;
  1495. { varargs are always equal, but not exact }
  1496. if (po_varargs in hp^.data.procoptions) and
  1497. (currparanr>hp^.data.minparacount) then
  1498. begin
  1499. eq:=te_equal;
  1500. end
  1501. else
  1502. { same definition -> exact }
  1503. if (def_from=def_to) then
  1504. begin
  1505. eq:=te_exact;
  1506. end
  1507. else
  1508. { for value and const parameters check if a integer is constant or
  1509. included in other integer -> equal and calc ordinal_distance }
  1510. if not(currpara.paratyp in [vs_var,vs_out]) and
  1511. is_integer(def_from) and
  1512. is_integer(def_to) and
  1513. is_in_limit(def_from,def_to) then
  1514. begin
  1515. eq:=te_equal;
  1516. hp^.ordinal_distance:=hp^.ordinal_distance+
  1517. abs(bestreal(torddef(def_from).low)-bestreal(torddef(def_to).low));
  1518. hp^.ordinal_distance:=hp^.ordinal_distance+
  1519. abs(bestreal(torddef(def_to).high)-bestreal(torddef(def_from).high));
  1520. { Give wrong sign a small penalty, this is need to get a diffrence
  1521. from word->[longword,longint] }
  1522. if is_signed(def_from)<>is_signed(def_to) then
  1523. hp^.ordinal_distance:=hp^.ordinal_distance+1.0;
  1524. end
  1525. else
  1526. { generic type comparision }
  1527. begin
  1528. eq:=compare_defs_ext(def_from,def_to,currpt.left.nodetype,convtype,pdoper,cdoptions);
  1529. { when the types are not equal we need to check
  1530. some special case for parameter passing }
  1531. if (eq<te_equal) then
  1532. begin
  1533. if currpara.paratyp in [vs_var,vs_out] then
  1534. begin
  1535. { para requires an equal type so the previous found
  1536. match was not good enough, reset to incompatible }
  1537. eq:=te_incompatible;
  1538. { var_para_allowed will return te_equal and te_convert_l1 to
  1539. make a difference for best matching }
  1540. var_para_allowed(eq,currpt.resulttype.def,currpara.paratype.def)
  1541. end
  1542. else
  1543. para_allowed(eq,currpt,def_to);
  1544. end;
  1545. end;
  1546. { when a procvar was changed to a call an exact much is
  1547. downgraded to equal. This way an overload call with the
  1548. procvar is choosen. See tb0471 (PFV) }
  1549. if (pt<>currpt) and (eq=te_exact) then
  1550. eq:=te_equal;
  1551. { increase correct counter }
  1552. case eq of
  1553. te_exact :
  1554. inc(hp^.exact_count);
  1555. te_equal :
  1556. inc(hp^.equal_count);
  1557. te_convert_l1 :
  1558. inc(hp^.cl1_count);
  1559. te_convert_l2 :
  1560. inc(hp^.cl2_count);
  1561. te_convert_l3 :
  1562. inc(hp^.cl3_count);
  1563. te_convert_operator :
  1564. inc(hp^.coper_count);
  1565. te_incompatible :
  1566. hp^.invalid:=true;
  1567. else
  1568. internalerror(200212072);
  1569. end;
  1570. { stop checking when an incompatible parameter is found }
  1571. if hp^.invalid then
  1572. begin
  1573. { store the current parameter info for
  1574. a nice error message when no procedure is found }
  1575. hp^.wrongpara:=currpara;
  1576. hp^.wrongparanr:=currparanr;
  1577. break;
  1578. end;
  1579. {$ifdef EXTDEBUG}
  1580. { store equal in node tree for dump }
  1581. currpara.eqval:=eq;
  1582. {$endif EXTDEBUG}
  1583. { maybe release temp currpt }
  1584. if releasecurrpt then
  1585. currpt.free;
  1586. { next parameter in the call tree }
  1587. pt:=tcallparanode(pt.right);
  1588. { next parameter for definition, only goto next para
  1589. if we're out of the varargs }
  1590. if not(po_varargs in hp^.data.procoptions) or
  1591. (currparanr<=hp^.data.maxparacount) then
  1592. begin
  1593. { Ignore vs_hidden parameters }
  1594. repeat
  1595. currpara:=tparaitem(currpara.previous);
  1596. until (not assigned(currpara)) or (not currpara.is_hidden);
  1597. end;
  1598. dec(currparanr);
  1599. end;
  1600. if not(hp^.invalid) and
  1601. (assigned(pt) or assigned(currpara) or (currparanr<>0)) then
  1602. internalerror(200212141);
  1603. { next candidate }
  1604. hp:=hp^.next;
  1605. end;
  1606. end;
  1607. function is_better_candidate(currpd,bestpd:pcandidate):integer;
  1608. var
  1609. res : integer;
  1610. begin
  1611. {
  1612. Return values:
  1613. > 0 when currpd is better than bestpd
  1614. < 0 when bestpd is better than currpd
  1615. = 0 when both are equal
  1616. To choose the best candidate we use the following order:
  1617. - Incompatible flag
  1618. - (Smaller) Number of convert operator parameters.
  1619. - (Smaller) Number of convertlevel 2 parameters.
  1620. - (Smaller) Number of convertlevel 1 parameters.
  1621. - (Bigger) Number of exact parameters.
  1622. - (Smaller) Number of equal parameters.
  1623. - (Smaller) Total of ordinal distance. For example, the distance of a word
  1624. to a byte is 65535-255=65280.
  1625. }
  1626. if bestpd^.invalid then
  1627. begin
  1628. if currpd^.invalid then
  1629. res:=0
  1630. else
  1631. res:=1;
  1632. end
  1633. else
  1634. if currpd^.invalid then
  1635. res:=-1
  1636. else
  1637. begin
  1638. { less operator parameters? }
  1639. res:=(bestpd^.coper_count-currpd^.coper_count);
  1640. if (res=0) then
  1641. begin
  1642. { less cl3 parameters? }
  1643. res:=(bestpd^.cl3_count-currpd^.cl3_count);
  1644. if (res=0) then
  1645. begin
  1646. { less cl2 parameters? }
  1647. res:=(bestpd^.cl2_count-currpd^.cl2_count);
  1648. if (res=0) then
  1649. begin
  1650. { less cl1 parameters? }
  1651. res:=(bestpd^.cl1_count-currpd^.cl1_count);
  1652. if (res=0) then
  1653. begin
  1654. { more exact parameters? }
  1655. res:=(currpd^.exact_count-bestpd^.exact_count);
  1656. if (res=0) then
  1657. begin
  1658. { less equal parameters? }
  1659. res:=(bestpd^.equal_count-currpd^.equal_count);
  1660. if (res=0) then
  1661. begin
  1662. { smaller ordinal distance? }
  1663. if (currpd^.ordinal_distance<bestpd^.ordinal_distance) then
  1664. res:=1
  1665. else
  1666. if (currpd^.ordinal_distance>bestpd^.ordinal_distance) then
  1667. res:=-1
  1668. else
  1669. res:=0;
  1670. end;
  1671. end;
  1672. end;
  1673. end;
  1674. end;
  1675. end;
  1676. end;
  1677. is_better_candidate:=res;
  1678. end;
  1679. function tcallcandidates.choose_best(var bestpd:tabstractprocdef):integer;
  1680. var
  1681. besthpstart,
  1682. hp : pcandidate;
  1683. cntpd,
  1684. res : integer;
  1685. begin
  1686. {
  1687. Returns the number of candidates left and the
  1688. first candidate is returned in pdbest
  1689. }
  1690. { Setup the first procdef as best, only count it as a result
  1691. when it is valid }
  1692. bestpd:=FProcs^.data;
  1693. if FProcs^.invalid then
  1694. cntpd:=0
  1695. else
  1696. cntpd:=1;
  1697. if assigned(FProcs^.next) then
  1698. begin
  1699. besthpstart:=FProcs;
  1700. hp:=FProcs^.next;
  1701. while assigned(hp) do
  1702. begin
  1703. res:=is_better_candidate(hp,besthpstart);
  1704. if (res>0) then
  1705. begin
  1706. { hp is better, flag all procs to be incompatible }
  1707. while (besthpstart<>hp) do
  1708. begin
  1709. besthpstart^.invalid:=true;
  1710. besthpstart:=besthpstart^.next;
  1711. end;
  1712. { besthpstart is already set to hp }
  1713. bestpd:=besthpstart^.data;
  1714. cntpd:=1;
  1715. end
  1716. else
  1717. if (res<0) then
  1718. begin
  1719. { besthpstart is better, flag current hp to be incompatible }
  1720. hp^.invalid:=true;
  1721. end
  1722. else
  1723. begin
  1724. { res=0, both are valid }
  1725. if not hp^.invalid then
  1726. inc(cntpd);
  1727. end;
  1728. hp:=hp^.next;
  1729. end;
  1730. end;
  1731. result:=cntpd;
  1732. end;
  1733. procedure tcallcandidates.find_wrong_para;
  1734. var
  1735. currparanr : smallint;
  1736. hp : pcandidate;
  1737. pt : tcallparanode;
  1738. begin
  1739. { Only process the first overloaded procdef }
  1740. hp:=FProcs;
  1741. { Find callparanode corresponding to the argument }
  1742. pt:=tcallparanode(FParanode);
  1743. currparanr:=FParalength;
  1744. while assigned(pt) and
  1745. (currparanr>hp^.wrongparanr) do
  1746. begin
  1747. pt:=tcallparanode(pt.right);
  1748. dec(currparanr);
  1749. end;
  1750. if (currparanr<>hp^.wrongparanr) or
  1751. not assigned(pt) then
  1752. internalerror(200212094);
  1753. { Show error message, when it was a var or out parameter
  1754. guess that it is a missing typeconv }
  1755. if hp^.wrongpara.paratyp in [vs_var,vs_out] then
  1756. CGMessagePos2(pt.fileinfo,parser_e_call_by_ref_without_typeconv,
  1757. pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename)
  1758. else
  1759. CGMessagePos3(pt.fileinfo,type_e_wrong_parameter_type,
  1760. tostr(hp^.wrongparanr),pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename);
  1761. end;
  1762. end.
  1763. {
  1764. $Log$
  1765. Revision 1.92 2004-05-25 21:27:35 florian
  1766. * fixed another formal const problem caused by yesterday's changes
  1767. Revision 1.91 2004/05/24 21:24:40 florian
  1768. * properties are allowed as formal const parameters as well
  1769. Revision 1.90 2004/05/24 21:04:31 florian
  1770. * fixed more formal const problems
  1771. Revision 1.89 2004/05/24 20:39:41 florian
  1772. * stricter handling of formal const parameters and IE fixed
  1773. Revision 1.88 2004/05/23 18:28:40 peter
  1774. * methodpointer is loaded into a temp when it was a calln
  1775. Revision 1.87 2004/05/23 15:03:40 peter
  1776. * some typeconvs don't allow assignment or passing to var para
  1777. Revision 1.86 2004/05/16 13:29:46 peter
  1778. * forbid more overloaded operators with orddef/enumdef
  1779. Revision 1.85 2004/04/18 07:52:43 florian
  1780. * fixed web bug 3048: comparision of dyn. arrays
  1781. Revision 1.84 2004/03/18 16:29:07 peter
  1782. * missing result initialization in node2opstr
  1783. Revision 1.83 2004/03/18 16:19:03 peter
  1784. * fixed operator overload allowing for pointer-string
  1785. * replaced some type_e_mismatch with more informational messages
  1786. Revision 1.82 2004/02/26 16:11:09 peter
  1787. * return cnothingn and give error when the operator is not overloaded
  1788. Revision 1.81 2004/02/24 16:12:39 peter
  1789. * operator overload chooses rewrite
  1790. * overload choosing is now generic and moved to htypechk
  1791. Revision 1.80 2004/02/20 21:55:19 peter
  1792. * widestring conversions added to allowed operator check
  1793. Revision 1.79 2004/02/13 15:42:21 peter
  1794. * compare_defs_ext has now a options argument
  1795. * fixes for variants
  1796. Revision 1.78 2004/02/12 15:54:03 peter
  1797. * make extcycle is working again
  1798. Revision 1.77 2004/02/04 22:15:15 daniel
  1799. * Rtti generation moved to ncgutil
  1800. * Assmtai usage of symsym removed
  1801. * operator overloading cleanup up
  1802. Revision 1.76 2004/02/03 22:32:53 peter
  1803. * renamed xNNbittype to xNNinttype
  1804. * renamed registers32 to registersint
  1805. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  1806. Revision 1.75 2003/11/12 15:48:27 peter
  1807. * fix set_varstate in for loops
  1808. * fix set_varstate from case statements
  1809. Revision 1.74 2003/10/30 19:20:05 peter
  1810. * fix IE when passing array to open array
  1811. Revision 1.73 2003/10/30 17:42:48 peter
  1812. * also check for uninited vars in staticsymtable
  1813. Revision 1.72 2003/10/28 15:36:01 peter
  1814. * absolute to object field supported, fixes tb0458
  1815. Revision 1.71 2003/10/21 18:16:13 peter
  1816. * IncompatibleTypes() added that will include unit names when
  1817. the typenames are the same
  1818. Revision 1.70 2003/10/20 19:29:12 peter
  1819. * fix check for typecasting wrong sizes in assignment left
  1820. Revision 1.69 2003/10/08 19:19:45 peter
  1821. * set_varstate cleanup
  1822. Revision 1.68 2003/10/05 21:21:52 peter
  1823. * c style array of const generates callparanodes
  1824. * varargs paraloc fixes
  1825. Revision 1.67 2003/10/01 20:34:48 peter
  1826. * procinfo unit contains tprocinfo
  1827. * cginfo renamed to cgbase
  1828. * moved cgmessage to verbose
  1829. * fixed ppc and sparc compiles
  1830. Revision 1.66 2003/08/23 18:52:18 peter
  1831. * don't check size for open array in valid_for_assign
  1832. Revision 1.65 2003/07/08 15:20:56 peter
  1833. * don't allow add/assignments for formaldef
  1834. * formaldef size changed to 0
  1835. Revision 1.64 2003/06/13 21:19:30 peter
  1836. * current_procdef removed, use current_procinfo.procdef instead
  1837. Revision 1.63 2003/05/09 17:47:02 peter
  1838. * self moved to hidden parameter
  1839. * removed hdisposen,hnewn,selfn
  1840. Revision 1.62 2003/04/27 11:21:32 peter
  1841. * aktprocdef renamed to current_procinfo.procdef
  1842. * procinfo renamed to current_procinfo
  1843. * procinfo will now be stored in current_module so it can be
  1844. cleaned up properly
  1845. * gen_main_procsym changed to create_main_proc and release_main_proc
  1846. to also generate a tprocinfo structure
  1847. * fixed unit implicit initfinal
  1848. Revision 1.61 2003/04/27 07:29:50 peter
  1849. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  1850. a new procdef declaration
  1851. * aktprocsym removed
  1852. * lexlevel removed, use symtable.symtablelevel instead
  1853. * implicit init/final code uses the normal genentry/genexit
  1854. * funcret state checking updated for new funcret handling
  1855. Revision 1.60 2003/04/25 20:59:33 peter
  1856. * removed funcretn,funcretsym, function result is now in varsym
  1857. and aliases for result and function name are added using absolutesym
  1858. * vs_hidden parameter for funcret passed in parameter
  1859. * vs_hidden fixes
  1860. * writenode changed to printnode and released from extdebug
  1861. * -vp option added to generate a tree.log with the nodetree
  1862. * nicer printnode for statements, callnode
  1863. Revision 1.59 2003/04/22 23:50:22 peter
  1864. * firstpass uses expectloc
  1865. * checks if there are differences between the expectloc and
  1866. location.loc from secondpass in EXTDEBUG
  1867. Revision 1.58 2003/01/03 17:17:26 peter
  1868. * use compare_def_ext to test if assignn operator is allowed
  1869. Revision 1.57 2003/01/02 22:21:19 peter
  1870. * fixed previous operator change
  1871. Revision 1.56 2003/01/02 19:50:21 peter
  1872. * fixed operator checking for objects
  1873. * made binary operator checking simpeler
  1874. Revision 1.55 2002/12/27 18:06:32 peter
  1875. * fix overload error for dynarr:=nil
  1876. Revision 1.54 2002/12/22 16:34:49 peter
  1877. * proc-procvar crash fixed (tw2277)
  1878. Revision 1.53 2002/12/11 22:39:24 peter
  1879. * better error message when no operator is found for equal
  1880. Revision 1.52 2002/11/27 22:11:59 peter
  1881. * rewrote isbinaryoverloadable to use a case. it's now much easier
  1882. to understand what is happening
  1883. Revision 1.51 2002/11/25 17:43:17 peter
  1884. * splitted defbase in defutil,symutil,defcmp
  1885. * merged isconvertable and is_equal into compare_defs(_ext)
  1886. * made operator search faster by walking the list only once
  1887. Revision 1.50 2002/10/07 20:12:08 peter
  1888. * ugly hack to fix tb0411
  1889. Revision 1.49 2002/10/05 00:47:03 peter
  1890. * support dynamicarray<>nil
  1891. Revision 1.48 2002/10/04 21:13:59 peter
  1892. * ignore vecn,subscriptn when checking for a procvar loadn
  1893. Revision 1.47 2002/09/16 18:09:34 peter
  1894. * set_funcret_valid fixed when result was already used in a nested
  1895. procedure
  1896. Revision 1.46 2002/07/20 11:57:53 florian
  1897. * types.pas renamed to defbase.pas because D6 contains a types
  1898. unit so this would conflicts if D6 programms are compiled
  1899. + Willamette/SSE2 instructions to assembler added
  1900. Revision 1.45 2002/05/18 13:34:08 peter
  1901. * readded missing revisions
  1902. Revision 1.44 2002/05/16 19:46:37 carl
  1903. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1904. + try to fix temp allocation (still in ifdef)
  1905. + generic constructor calls
  1906. + start of tassembler / tmodulebase class cleanup
  1907. Revision 1.42 2002/04/02 17:11:28 peter
  1908. * tlocation,treference update
  1909. * LOC_CONSTANT added for better constant handling
  1910. * secondadd splitted in multiple routines
  1911. * location_force_reg added for loading a location to a register
  1912. of a specified size
  1913. * secondassignment parses now first the right and then the left node
  1914. (this is compatible with Kylix). This saves a lot of push/pop especially
  1915. with string operations
  1916. * adapted some routines to use the new cg methods
  1917. Revision 1.41 2002/01/16 09:33:46 jonas
  1918. * no longer allow assignments to pointer expressions (unless there's a
  1919. deref), reported by John Lee
  1920. }