htypechk.pas 72 KB

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