htypechk.pas 74 KB

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