htypechk.pas 73 KB

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