htypechk.pas 74 KB

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