htypechk.pas 74 KB

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