tccal.pas 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. Type checking and register allocation for call nodes
  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 tccal;
  19. interface
  20. uses
  21. symtable,tree;
  22. procedure firstcallparan(var p : ptree;defcoll : pdefcoll);
  23. procedure firstcalln(var p : ptree);
  24. procedure firstprocinline(var p : ptree);
  25. implementation
  26. uses
  27. globtype,systems,
  28. cobjects,verbose,globals,
  29. aasm,types,
  30. hcodegen,htypechk,pass_1
  31. {$ifdef i386}
  32. ,i386,tgeni386
  33. {$endif}
  34. {$ifdef m68k}
  35. ,m68k,tgen68k
  36. {$endif}
  37. ;
  38. {*****************************************************************************
  39. FirstCallParaN
  40. *****************************************************************************}
  41. procedure firstcallparan(var p : ptree;defcoll : pdefcoll);
  42. var
  43. old_array_constructor : boolean;
  44. store_valid : boolean;
  45. oldtype : pdef;
  46. {convtyp : tconverttype;}
  47. begin
  48. inc(parsing_para_level);
  49. if assigned(p^.right) then
  50. begin
  51. if defcoll=nil then
  52. firstcallparan(p^.right,nil)
  53. else
  54. firstcallparan(p^.right,defcoll^.next);
  55. p^.registers32:=p^.right^.registers32;
  56. p^.registersfpu:=p^.right^.registersfpu;
  57. {$ifdef SUPPORT_MMX}
  58. p^.registersmmx:=p^.right^.registersmmx;
  59. {$endif}
  60. end;
  61. if defcoll=nil then
  62. begin
  63. old_array_constructor:=allow_array_constructor;
  64. allow_array_constructor:=true;
  65. if not(assigned(p^.resulttype)) or
  66. (p^.left^.treetype=typeconvn) then
  67. firstpass(p^.left);
  68. allow_array_constructor:=old_array_constructor;
  69. if codegenerror then
  70. begin
  71. dec(parsing_para_level);
  72. exit;
  73. end;
  74. p^.resulttype:=p^.left^.resulttype;
  75. end
  76. { if we know the routine which is called, then the type }
  77. { conversions are inserted }
  78. else
  79. begin
  80. if count_ref then
  81. begin
  82. store_valid:=must_be_valid;
  83. if (defcoll^.paratyp=vs_var) then
  84. test_protected(p^.left);
  85. if (defcoll^.paratyp<>vs_var) then
  86. must_be_valid:=true
  87. else
  88. must_be_valid:=false;
  89. { here we must add something for the implicit type }
  90. { conversion from array of char to pchar }
  91. { if isconvertable(p^.left^.resulttype,defcoll^.data,convtyp,
  92. p^.left^.treetype,false) then
  93. if convtyp=tc_array_to_pointer then
  94. must_be_valid:=false; }
  95. { only process typeconvn, else it will break other trees }
  96. old_array_constructor:=allow_array_constructor;
  97. allow_array_constructor:=true;
  98. if (p^.left^.treetype=typeconvn) then
  99. firstpass(p^.left);
  100. allow_array_constructor:=old_array_constructor;
  101. must_be_valid:=store_valid;
  102. end;
  103. if not(is_shortstring(p^.left^.resulttype) and
  104. is_shortstring(defcoll^.data)) and
  105. (defcoll^.data^.deftype<>formaldef) then
  106. begin
  107. if (defcoll^.paratyp=vs_var) and
  108. { allows conversion from word to integer and
  109. byte to shortint }
  110. (not(
  111. (p^.left^.resulttype^.deftype=orddef) and
  112. (defcoll^.data^.deftype=orddef) and
  113. (p^.left^.resulttype^.size=defcoll^.data^.size)
  114. ) and
  115. { an implicit pointer conversion is allowed }
  116. not(
  117. (p^.left^.resulttype^.deftype=pointerdef) and
  118. (defcoll^.data^.deftype=pointerdef)
  119. ) and
  120. { child classes can be also passed }
  121. not(
  122. (p^.left^.resulttype^.deftype=objectdef) and
  123. (defcoll^.data^.deftype=objectdef) and
  124. pobjectdef(p^.left^.resulttype)^.isrelated(pobjectdef(defcoll^.data))
  125. ) and
  126. { passing a single element to a openarray of the same type }
  127. not(
  128. (is_open_array(defcoll^.data) and
  129. is_equal(parraydef(defcoll^.data)^.definition,p^.left^.resulttype))
  130. ) and
  131. { an implicit file conversion is also allowed }
  132. { from a typed file to an untyped one }
  133. not(
  134. (p^.left^.resulttype^.deftype=filedef) and
  135. (defcoll^.data^.deftype=filedef) and
  136. (pfiledef(defcoll^.data)^.filetype = ft_untyped) and
  137. (pfiledef(p^.left^.resulttype)^.filetype = ft_typed)
  138. ) and
  139. not(is_equal(p^.left^.resulttype,defcoll^.data))) then
  140. CGMessage(parser_e_call_by_ref_without_typeconv);
  141. { process cargs arrayconstructor }
  142. if is_array_constructor(p^.left^.resulttype) and
  143. (aktcallprocsym^.definition^.options and pocdecl<>0) and
  144. (aktcallprocsym^.definition^.options and poexternal<>0) then
  145. begin
  146. p^.left^.cargs:=true;
  147. old_array_constructor:=allow_array_constructor;
  148. allow_array_constructor:=true;
  149. firstpass(p^.left);
  150. allow_array_constructor:=old_array_constructor;
  151. end;
  152. { don't generate an type conversion for open arrays and
  153. openstring, else we loss the ranges }
  154. if is_open_array(defcoll^.data) or
  155. is_open_string(defcoll^.data) then
  156. begin
  157. { insert type conv but hold the ranges of the array }
  158. oldtype:=p^.left^.resulttype;
  159. p^.left:=gentypeconvnode(p^.left,defcoll^.data);
  160. firstpass(p^.left);
  161. p^.left^.resulttype:=oldtype;
  162. end
  163. else
  164. begin
  165. p^.left:=gentypeconvnode(p^.left,defcoll^.data);
  166. firstpass(p^.left);
  167. { this is necessary if an arrayconstruct -> set is done
  168. first, then the set generation tree needs to be passed
  169. to get the end resulttype (PFV) }
  170. if not assigned(p^.left^.resulttype) then
  171. firstpass(p^.left);
  172. end;
  173. if codegenerror then
  174. begin
  175. dec(parsing_para_level);
  176. exit;
  177. end;
  178. end;
  179. { check var strings }
  180. if (cs_strict_var_strings in aktlocalswitches) and
  181. is_shortstring(p^.left^.resulttype) and
  182. is_shortstring(defcoll^.data) and
  183. (defcoll^.paratyp=vs_var) and
  184. not(is_open_string(defcoll^.data)) and
  185. not(is_equal(p^.left^.resulttype,defcoll^.data)) then
  186. CGMessage(type_e_strict_var_string_violation);
  187. { Variablen for call by reference may not be copied }
  188. { into a register }
  189. { is this usefull here ? }
  190. { this was missing in formal parameter list }
  191. if defcoll^.paratyp=vs_var then
  192. begin
  193. set_unique(p^.left);
  194. make_not_regable(p^.left);
  195. end;
  196. p^.resulttype:=defcoll^.data;
  197. end;
  198. if p^.left^.registers32>p^.registers32 then
  199. p^.registers32:=p^.left^.registers32;
  200. if p^.left^.registersfpu>p^.registersfpu then
  201. p^.registersfpu:=p^.left^.registersfpu;
  202. {$ifdef SUPPORT_MMX}
  203. if p^.left^.registersmmx>p^.registersmmx then
  204. p^.registersmmx:=p^.left^.registersmmx;
  205. {$endif SUPPORT_MMX}
  206. dec(parsing_para_level);
  207. end;
  208. {*****************************************************************************
  209. FirstCallN
  210. *****************************************************************************}
  211. procedure firstcalln(var p : ptree);
  212. type
  213. pprocdefcoll = ^tprocdefcoll;
  214. tprocdefcoll = record
  215. data : pprocdef;
  216. nextpara : pdefcoll;
  217. firstpara : pdefcoll;
  218. next : pprocdefcoll;
  219. end;
  220. var
  221. hp,procs,hp2 : pprocdefcoll;
  222. pd : pprocdef;
  223. oldcallprocsym : pprocsym;
  224. nextprocsym : pprocsym;
  225. def_from,def_to,conv_to : pdef;
  226. pt,inlinecode : ptree;
  227. exactmatch,inlined : boolean;
  228. paralength,l : longint;
  229. pdc : pdefcoll;
  230. {$ifdef TEST_PROCSYMS}
  231. symt : psymtable;
  232. {$endif TEST_PROCSYMS}
  233. { only Dummy }
  234. hcvt : tconverttype;
  235. regi : tregister;
  236. store_valid, old_count_ref : boolean;
  237. { check if the resulttype from tree p is equal with def, needed
  238. for stringconstn and formaldef }
  239. function is_equal(p:ptree;def:pdef) : boolean;
  240. begin
  241. { safety check }
  242. if not (assigned(def) or assigned(p^.resulttype)) then
  243. begin
  244. is_equal:=false;
  245. exit;
  246. end;
  247. { all types can be passed to a formaldef }
  248. is_equal:=(def^.deftype=formaldef) or
  249. (types.is_equal(p^.resulttype,def))
  250. { to support ansi/long/wide strings in a proper way }
  251. { string and string[10] are assumed as equal }
  252. { when searching the correct overloaded procedure }
  253. or
  254. (
  255. (def^.deftype=stringdef) and (p^.resulttype^.deftype=stringdef) and
  256. (pstringdef(def)^.string_typ=pstringdef(p^.resulttype)^.string_typ)
  257. )
  258. or
  259. (
  260. (p^.left^.treetype=stringconstn) and
  261. (is_ansistring(p^.resulttype) and is_pchar(def))
  262. )
  263. or
  264. (
  265. (p^.left^.treetype=ordconstn) and
  266. (is_char(p^.resulttype) and (is_shortstring(def) or is_ansistring(def)))
  267. )
  268. { set can also be a not yet converted array constructor }
  269. or
  270. (
  271. (def^.deftype=setdef) and (p^.resulttype^.deftype=arraydef) and
  272. (parraydef(p^.resulttype)^.IsConstructor) and not(parraydef(p^.resulttype)^.IsVariant)
  273. )
  274. ;
  275. end;
  276. function is_in_limit(def_from,def_to : pdef) : boolean;
  277. begin
  278. is_in_limit:=(def_from^.deftype = orddef) and
  279. (def_to^.deftype = orddef) and
  280. (porddef(def_from)^.low>porddef(def_to)^.low) and
  281. (porddef(def_from)^.high<porddef(def_to)^.high);
  282. end;
  283. var
  284. is_const : boolean;
  285. begin
  286. { release registers! }
  287. { if procdefinition<>nil then we called firstpass already }
  288. { it seems to be bad because of the registers }
  289. { at least we can avoid the overloaded search !! }
  290. procs:=nil;
  291. { made this global for disposing !! }
  292. store_valid:=must_be_valid;
  293. must_be_valid:=false;
  294. oldcallprocsym:=aktcallprocsym;
  295. aktcallprocsym:=nil;
  296. inlined:=false;
  297. if assigned(p^.procdefinition) and
  298. ((p^.procdefinition^.options and poinline)<>0) then
  299. begin
  300. inlinecode:=p^.right;
  301. if assigned(inlinecode) then
  302. begin
  303. inlined:=true;
  304. p^.procdefinition^.options:=p^.procdefinition^.options and (not poinline);
  305. end;
  306. p^.right:=nil;
  307. end;
  308. { procedure variable ? }
  309. if assigned(p^.right) then
  310. begin
  311. { procedure does a call }
  312. procinfo.flags:=procinfo.flags or pi_do_call;
  313. { calc the correture value for the register }
  314. {$ifdef i386}
  315. for regi:=R_EAX to R_EDI do
  316. inc(reg_pushes[regi],t_times*2);
  317. {$endif}
  318. {$ifdef m68k}
  319. for regi:=R_D0 to R_A6 do
  320. inc(reg_pushes[regi],t_times*2);
  321. {$endif}
  322. { calculate the type of the parameters }
  323. if assigned(p^.left) then
  324. begin
  325. old_count_ref:=count_ref;
  326. count_ref:=false;
  327. firstcallparan(p^.left,nil);
  328. count_ref:=old_count_ref;
  329. if codegenerror then
  330. exit;
  331. end;
  332. firstpass(p^.right);
  333. { check the parameters }
  334. pdc:=pprocvardef(p^.right^.resulttype)^.para1;
  335. pt:=p^.left;
  336. while assigned(pdc) and assigned(pt) do
  337. begin
  338. pt:=pt^.right;
  339. pdc:=pdc^.next;
  340. end;
  341. if assigned(pt) or assigned(pdc) then
  342. CGMessage(parser_e_illegal_parameter_list);
  343. { insert type conversions }
  344. if assigned(p^.left) then
  345. begin
  346. old_count_ref:=count_ref;
  347. count_ref:=true;
  348. firstcallparan(p^.left,pprocvardef(p^.right^.resulttype)^.para1);
  349. count_ref:=old_count_ref;
  350. if codegenerror then
  351. exit;
  352. end;
  353. p^.resulttype:=pprocvardef(p^.right^.resulttype)^.retdef;
  354. { this was missing, leads to a bug below if
  355. the procvar is a function }
  356. p^.procdefinition:=pprocdef(p^.right^.resulttype);
  357. end
  358. else
  359. { not a procedure variable }
  360. begin
  361. { determine the type of the parameters }
  362. if assigned(p^.left) then
  363. begin
  364. old_count_ref:=count_ref;
  365. count_ref:=false;
  366. store_valid:=must_be_valid;
  367. must_be_valid:=false;
  368. firstcallparan(p^.left,nil);
  369. count_ref:=old_count_ref;
  370. must_be_valid:=store_valid;
  371. if codegenerror then
  372. exit;
  373. end;
  374. aktcallprocsym:=pprocsym(p^.symtableprocentry);
  375. { do we know the procedure to call ? }
  376. if not(assigned(p^.procdefinition)) then
  377. begin
  378. {$ifdef TEST_PROCSYMS}
  379. if (p^.unit_specific) or
  380. assigned(p^.methodpointer) then
  381. nextprocsym:=nil
  382. else while not assigned(procs) do
  383. begin
  384. symt:=p^.symtableproc;
  385. srsym:=nil;
  386. while assigned(symt^.next) and not assigned(srsym) do
  387. begin
  388. symt:=symt^.next;
  389. getsymonlyin(symt,actprocsym^.name);
  390. if assigned(srsym) then
  391. if srsym^.typ<>procsym then
  392. begin
  393. { reject all that is not a procedure }
  394. srsym:=nil;
  395. { don't search elsewhere }
  396. while assigned(symt^.next) do
  397. symt:=symt^.next;
  398. end;
  399. end;
  400. nextprocsym:=srsym;
  401. end;
  402. {$else TEST_PROCSYMS}
  403. nextprocsym:=nil;
  404. {$endif TEST_PROCSYMS}
  405. { determine length of parameter list }
  406. pt:=p^.left;
  407. paralength:=0;
  408. while assigned(pt) do
  409. begin
  410. inc(paralength);
  411. pt:=pt^.right;
  412. end;
  413. { link all procedures which have the same # of parameters }
  414. pd:=aktcallprocsym^.definition;
  415. while assigned(pd) do
  416. begin
  417. { we should also check that the overloaded function
  418. has been declared in a unit that is in the uses !! }
  419. { pd^.owner should be in the symtablestack !! }
  420. { Laenge der deklarierten Parameterliste feststellen: }
  421. { not necessary why nextprocsym field }
  422. {st:=symtablestack;
  423. if (pd^.owner^.symtabletype<>objectsymtable) then
  424. while assigned(st) do
  425. begin
  426. if (st=pd^.owner) then break;
  427. st:=st^.next;
  428. end;
  429. if assigned(st) then }
  430. begin
  431. pdc:=pd^.para1;
  432. l:=0;
  433. while assigned(pdc) do
  434. begin
  435. inc(l);
  436. pdc:=pdc^.next;
  437. end;
  438. { only when the # of parameter are equal }
  439. if (l=paralength) then
  440. begin
  441. new(hp);
  442. hp^.data:=pd;
  443. hp^.next:=procs;
  444. hp^.nextpara:=pd^.para1;
  445. hp^.firstpara:=pd^.para1;
  446. procs:=hp;
  447. end;
  448. end;
  449. pd:=pd^.nextoverloaded;
  450. end;
  451. { no procedures found? then there is something wrong
  452. with the parameter size }
  453. if not assigned(procs) and
  454. ((parsing_para_level=0) or assigned(p^.left)) and
  455. (nextprocsym=nil) then
  456. begin
  457. CGMessage(parser_e_wrong_parameter_size);
  458. aktcallprocsym^.write_parameter_lists;
  459. exit;
  460. end;
  461. { now we can compare parameter after parameter }
  462. pt:=p^.left;
  463. while assigned(pt) do
  464. begin
  465. { matches a parameter of one procedure exact ? }
  466. exactmatch:=false;
  467. hp:=procs;
  468. while assigned(hp) do
  469. begin
  470. if is_equal(pt,hp^.nextpara^.data) then
  471. begin
  472. if hp^.nextpara^.data=pt^.resulttype then
  473. begin
  474. pt^.exact_match_found:=true;
  475. hp^.nextpara^.argconvtyp:=act_exact;
  476. end
  477. else
  478. hp^.nextpara^.argconvtyp:=act_equal;
  479. exactmatch:=true;
  480. end
  481. else
  482. hp^.nextpara^.argconvtyp:=act_convertable;
  483. hp:=hp^.next;
  484. end;
  485. { .... if yes, del all the other procedures }
  486. if exactmatch then
  487. begin
  488. { the first .... }
  489. while (assigned(procs)) and not(is_equal(pt,procs^.nextpara^.data)) do
  490. begin
  491. hp:=procs^.next;
  492. dispose(procs);
  493. procs:=hp;
  494. end;
  495. { and the others }
  496. hp:=procs;
  497. while (assigned(hp)) and assigned(hp^.next) do
  498. begin
  499. if not(is_equal(pt,hp^.next^.nextpara^.data)) then
  500. begin
  501. hp2:=hp^.next^.next;
  502. dispose(hp^.next);
  503. hp^.next:=hp2;
  504. end
  505. else
  506. hp:=hp^.next;
  507. end;
  508. end
  509. { when a parameter matches exact, remove all procs
  510. which need typeconvs }
  511. else
  512. begin
  513. { the first... }
  514. while (assigned(procs)) and
  515. not(isconvertable(pt^.resulttype,procs^.nextpara^.data,
  516. hcvt,pt^.left^.treetype,false)) do
  517. begin
  518. hp:=procs^.next;
  519. dispose(procs);
  520. procs:=hp;
  521. end;
  522. { and the others }
  523. hp:=procs;
  524. while (assigned(hp)) and assigned(hp^.next) do
  525. begin
  526. if not(isconvertable(pt^.resulttype,hp^.next^.nextpara^.data,
  527. hcvt,pt^.left^.treetype,false)) then
  528. begin
  529. hp2:=hp^.next^.next;
  530. dispose(hp^.next);
  531. hp^.next:=hp2;
  532. end
  533. else
  534. hp:=hp^.next;
  535. end;
  536. end;
  537. { update nextpara for all procedures }
  538. hp:=procs;
  539. while assigned(hp) do
  540. begin
  541. hp^.nextpara:=hp^.nextpara^.next;
  542. hp:=hp^.next;
  543. end;
  544. { load next parameter }
  545. pt:=pt^.right;
  546. end;
  547. if not assigned(procs) then
  548. begin
  549. { there is an error, must be wrong type, because
  550. wrong size is already checked (PFV) }
  551. if ((parsing_para_level=0) or (p^.left<>nil)) and
  552. (nextprocsym=nil) then
  553. begin
  554. CGMessage(parser_e_wrong_parameter_type);
  555. aktcallprocsym^.write_parameter_lists;
  556. exit;
  557. end
  558. else
  559. begin
  560. { try to convert to procvar }
  561. p^.treetype:=loadn;
  562. p^.resulttype:=pprocsym(p^.symtableprocentry)^.definition;
  563. p^.symtableentry:=p^.symtableprocentry;
  564. p^.is_first:=false;
  565. p^.disposetyp:=dt_nothing;
  566. firstpass(p);
  567. exit;
  568. end;
  569. end;
  570. { if there are several choices left then for orddef }
  571. { if a type is totally included in the other }
  572. { we don't fear an overflow , }
  573. { so we can do as if it is an exact match }
  574. { this will convert integer to longint }
  575. { rather than to words }
  576. { conversion of byte to integer or longint }
  577. {would still not be solved }
  578. if assigned(procs) and assigned(procs^.next) then
  579. begin
  580. hp:=procs;
  581. while assigned(hp) do
  582. begin
  583. hp^.nextpara:=hp^.firstpara;
  584. hp:=hp^.next;
  585. end;
  586. pt:=p^.left;
  587. while assigned(pt) do
  588. begin
  589. { matches a parameter of one procedure exact ? }
  590. exactmatch:=false;
  591. def_from:=pt^.resulttype;
  592. hp:=procs;
  593. while assigned(hp) do
  594. begin
  595. if not is_equal(pt,hp^.nextpara^.data) then
  596. begin
  597. def_to:=hp^.nextpara^.data;
  598. if ((def_from^.deftype=orddef) and (def_to^.deftype=orddef)) and
  599. (is_in_limit(def_from,def_to) or
  600. ((hp^.nextpara^.paratyp=vs_var) and
  601. (def_from^.size=def_to^.size))) then
  602. begin
  603. exactmatch:=true;
  604. conv_to:=def_to;
  605. end;
  606. end;
  607. hp:=hp^.next;
  608. end;
  609. { .... if yes, del all the other procedures }
  610. if exactmatch then
  611. begin
  612. { the first .... }
  613. while (assigned(procs)) and not(is_in_limit(def_from,procs^.nextpara^.data)) do
  614. begin
  615. hp:=procs^.next;
  616. dispose(procs);
  617. procs:=hp;
  618. end;
  619. { and the others }
  620. hp:=procs;
  621. while (assigned(hp)) and assigned(hp^.next) do
  622. begin
  623. if not(is_in_limit(def_from,hp^.next^.nextpara^.data)) then
  624. begin
  625. hp2:=hp^.next^.next;
  626. dispose(hp^.next);
  627. hp^.next:=hp2;
  628. end
  629. else
  630. begin
  631. def_to:=hp^.next^.nextpara^.data;
  632. if (conv_to^.size>def_to^.size) or
  633. ((porddef(conv_to)^.low<porddef(def_to)^.low) and
  634. (porddef(conv_to)^.high>porddef(def_to)^.high)) then
  635. begin
  636. hp2:=procs;
  637. procs:=hp;
  638. conv_to:=def_to;
  639. dispose(hp2);
  640. end
  641. else
  642. hp:=hp^.next;
  643. end;
  644. end;
  645. end;
  646. { update nextpara for all procedures }
  647. hp:=procs;
  648. while assigned(hp) do
  649. begin
  650. hp^.nextpara:=hp^.nextpara^.next;
  651. hp:=hp^.next;
  652. end;
  653. pt:=pt^.right;
  654. end;
  655. end;
  656. { reset nextpara for all procs left }
  657. hp:=procs;
  658. while assigned(hp) do
  659. begin
  660. hp^.nextpara:=hp^.firstpara;
  661. hp:=hp^.next;
  662. end;
  663. { let's try to eliminate equal is exact is there }
  664. if assigned(procs^.next) then
  665. begin
  666. pt:=p^.left;
  667. while assigned(pt) do
  668. begin
  669. if pt^.exact_match_found then
  670. begin
  671. hp:=procs;
  672. procs:=nil;
  673. while assigned(hp) do
  674. begin
  675. hp2:=hp^.next;
  676. { keep the exact matches, dispose the others }
  677. if (hp^.nextpara^.data=pt^.resulttype) then
  678. begin
  679. hp^.next:=procs;
  680. procs:=hp;
  681. end
  682. else
  683. begin
  684. dispose(hp);
  685. end;
  686. hp:=hp2;
  687. end;
  688. end;
  689. { update nextpara for all procedures }
  690. hp:=procs;
  691. while assigned(hp) do
  692. begin
  693. hp^.nextpara:=hp^.nextpara^.next;
  694. hp:=hp^.next;
  695. end;
  696. pt:=pt^.right;
  697. end;
  698. end;
  699. if assigned(procs^.next) then
  700. begin
  701. CGMessage(cg_e_cant_choose_overload_function);
  702. aktcallprocsym^.write_parameter_lists;
  703. end;
  704. {$ifdef TEST_PROCSYMS}
  705. if (procs=nil) and assigned(nextprocsym) then
  706. begin
  707. p^.symtableprocentry:=nextprocsym;
  708. p^.symtableproc:=symt;
  709. end;
  710. end ; { of while assigned(p^.symtableprocentry) do }
  711. {$endif TEST_PROCSYMS}
  712. if make_ref then
  713. begin
  714. procs^.data^.lastref:=new(pref,init(procs^.data^.lastref,@p^.fileinfo));
  715. if procs^.data^.defref=nil then
  716. procs^.data^.defref:=procs^.data^.lastref;
  717. end;
  718. p^.procdefinition:=procs^.data;
  719. p^.resulttype:=procs^.data^.retdef;
  720. { big error for with statements
  721. p^.symtableproc:=p^.procdefinition^.owner;
  722. but neede for overloaded operators !! }
  723. if p^.symtableproc=nil then
  724. p^.symtableproc:=p^.procdefinition^.owner;
  725. p^.location.loc:=LOC_MEM;
  726. {$ifdef CHAINPROCSYMS}
  727. { object with method read;
  728. call to read(x) will be a usual procedure call }
  729. if assigned(p^.methodpointer) and
  730. (p^.procdefinition^._class=nil) then
  731. begin
  732. { not ok for extended }
  733. case p^.methodpointer^.treetype of
  734. typen,hnewn : fatalerror(no_para_match);
  735. end;
  736. disposetree(p^.methodpointer);
  737. p^.methodpointer:=nil;
  738. end;
  739. {$endif CHAINPROCSYMS}
  740. end; { end of procedure to call determination }
  741. is_const:=((p^.procdefinition^.options and pointernconst)<>0) and
  742. ((block_type=bt_const) or
  743. (assigned(p^.left) and (p^.left^.left^.treetype in [realconstn,ordconstn])));
  744. { handle predefined procedures }
  745. if ((p^.procdefinition^.options and pointernproc)<>0) or is_const then
  746. begin
  747. if assigned(p^.left) then
  748. begin
  749. { settextbuf needs two args }
  750. if assigned(p^.left^.right) then
  751. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left)
  752. else
  753. begin
  754. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left^.left);
  755. putnode(p^.left);
  756. end;
  757. end
  758. else
  759. begin
  760. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,nil);
  761. end;
  762. putnode(p);
  763. firstpass(pt);
  764. p:=pt;
  765. must_be_valid:=store_valid;
  766. if codegenerror then
  767. exit;
  768. dispose(procs);
  769. exit;
  770. end
  771. else
  772. { no intern procedure => we do a call }
  773. { calc the correture value for the register }
  774. { handle predefined procedures }
  775. if (p^.procdefinition^.options and poinline)<>0 then
  776. begin
  777. if assigned(p^.methodpointer) then
  778. CGMessage(cg_e_unable_inline_object_methods);
  779. if assigned(p^.right) and (p^.right^.treetype<>procinlinen) then
  780. CGMessage(cg_e_unable_inline_procvar);
  781. { p^.treetype:=procinlinen; }
  782. if not assigned(p^.right) then
  783. begin
  784. if assigned(p^.procdefinition^.code) then
  785. inlinecode:=genprocinlinenode(p,ptree(p^.procdefinition^.code))
  786. else
  787. CGMessage(cg_e_no_code_for_inline_stored);
  788. if assigned(inlinecode) then
  789. begin
  790. { consider it has not inlined if called
  791. again inside the args }
  792. p^.procdefinition^.options:=p^.procdefinition^.options and (not poinline);
  793. firstpass(inlinecode);
  794. inlined:=true;
  795. end;
  796. end;
  797. end
  798. else
  799. procinfo.flags:=procinfo.flags or pi_do_call;
  800. { work trough all parameters to insert the type conversions }
  801. { !!! done now after internproc !! (PM) }
  802. if assigned(p^.left) then
  803. begin
  804. old_count_ref:=count_ref;
  805. count_ref:=true;
  806. firstcallparan(p^.left,p^.procdefinition^.para1);
  807. count_ref:=old_count_ref;
  808. end;
  809. {$ifdef i386}
  810. for regi:=R_EAX to R_EDI do
  811. begin
  812. if (p^.procdefinition^.usedregisters and ($80 shr word(regi)))<>0 then
  813. inc(reg_pushes[regi],t_times*2);
  814. end;
  815. {$endif}
  816. {$ifdef m68k}
  817. for regi:=R_D0 to R_A6 do
  818. begin
  819. if (p^.procdefinition^.usedregisters and ($800 shr word(regi)))<>0 then
  820. inc(reg_pushes[regi],t_times*2);
  821. end;
  822. {$endif}
  823. end;
  824. { ensure that the result type is set }
  825. p^.resulttype:=p^.procdefinition^.retdef;
  826. { get a register for the return value }
  827. if (p^.resulttype<>pdef(voiddef)) then
  828. begin
  829. if (p^.procdefinition^.options and poconstructor)<>0 then
  830. begin
  831. { extra handling of classes }
  832. { p^.methodpointer should be assigned! }
  833. if assigned(p^.methodpointer) and assigned(p^.methodpointer^.resulttype) and
  834. (p^.methodpointer^.resulttype^.deftype=classrefdef) then
  835. begin
  836. p^.location.loc:=LOC_REGISTER;
  837. p^.registers32:=1;
  838. { the result type depends on the classref }
  839. p^.resulttype:=pclassrefdef(p^.methodpointer^.resulttype)^.definition;
  840. end
  841. { a object constructor returns the result with the flags }
  842. else
  843. p^.location.loc:=LOC_FLAGS;
  844. end
  845. else
  846. begin
  847. {$ifdef SUPPORT_MMX}
  848. if (cs_mmx in aktlocalswitches) and
  849. is_mmx_able_array(p^.resulttype) then
  850. begin
  851. p^.location.loc:=LOC_MMXREGISTER;
  852. p^.registersmmx:=1;
  853. end
  854. else
  855. {$endif SUPPORT_MMX}
  856. if ret_in_acc(p^.resulttype) then
  857. begin
  858. p^.location.loc:=LOC_REGISTER;
  859. if is_64bitint(p^.resulttype) then
  860. p^.registers32:=2
  861. else
  862. p^.registers32:=1;
  863. end
  864. else if (p^.resulttype^.deftype=floatdef) then
  865. begin
  866. p^.location.loc:=LOC_FPU;
  867. p^.registersfpu:=1;
  868. end
  869. end;
  870. end;
  871. { a fpu can be used in any procedure !! }
  872. p^.registersfpu:=p^.procdefinition^.fpu_used;
  873. { if this is a call to a method calc the registers }
  874. if (p^.methodpointer<>nil) then
  875. begin
  876. case p^.methodpointer^.treetype of
  877. { but only, if this is not a supporting node }
  878. typen,hnewn : ;
  879. else
  880. begin
  881. { if ((p^.procdefinition^.options and (poconstructor or podestructor)) <> 0) and
  882. (assigned(p^.symtable) and (p^.symtable^.symtabletype=withsymtable) then
  883. begin
  884. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  885. end; Is accpeted by Delphi !! }
  886. { R.Assign is not a constructor !!! }
  887. { but for R^.Assign, R must be valid !! }
  888. if ((p^.procdefinition^.options and poconstructor) <> 0) or
  889. ((p^.methodpointer^.treetype=loadn) and
  890. ((pobjectdef(p^.methodpointer^.resulttype)^.options and oo_hasvirtual) = 0)) then
  891. must_be_valid:=false
  892. else
  893. must_be_valid:=true;
  894. firstpass(p^.methodpointer);
  895. p^.registersfpu:=max(p^.methodpointer^.registersfpu,p^.registersfpu);
  896. p^.registers32:=max(p^.methodpointer^.registers32,p^.registers32);
  897. {$ifdef SUPPORT_MMX}
  898. p^.registersmmx:=max(p^.methodpointer^.registersmmx,p^.registersmmx);
  899. {$endif SUPPORT_MMX}
  900. end;
  901. end;
  902. end;
  903. if inlined then
  904. begin
  905. p^.right:=inlinecode;
  906. p^.procdefinition^.options:=p^.procdefinition^.options or poinline;
  907. end;
  908. { determine the registers of the procedure variable }
  909. { is this OK for inlined procs also ?? (PM) }
  910. if assigned(p^.right) then
  911. begin
  912. p^.registersfpu:=max(p^.right^.registersfpu,p^.registersfpu);
  913. p^.registers32:=max(p^.right^.registers32,p^.registers32);
  914. {$ifdef SUPPORT_MMX}
  915. p^.registersmmx:=max(p^.right^.registersmmx,p^.registersmmx);
  916. {$endif SUPPORT_MMX}
  917. end;
  918. { determine the registers of the procedure }
  919. if assigned(p^.left) then
  920. begin
  921. p^.registersfpu:=max(p^.left^.registersfpu,p^.registersfpu);
  922. p^.registers32:=max(p^.left^.registers32,p^.registers32);
  923. {$ifdef SUPPORT_MMX}
  924. p^.registersmmx:=max(p^.left^.registersmmx,p^.registersmmx);
  925. {$endif SUPPORT_MMX}
  926. end;
  927. if assigned(procs) then
  928. dispose(procs);
  929. aktcallprocsym:=oldcallprocsym;
  930. must_be_valid:=store_valid;
  931. end;
  932. {*****************************************************************************
  933. FirstProcInlineN
  934. *****************************************************************************}
  935. procedure firstprocinline(var p : ptree);
  936. begin
  937. { left contains the code in tree form }
  938. { but it has already been firstpassed }
  939. { so firstpass(p^.left); does not seem required }
  940. { might be required later if we change the arg handling !! }
  941. end;
  942. end.
  943. {
  944. $Log$
  945. Revision 1.19 1999-01-19 14:20:16 peter
  946. * fixed [char] crash
  947. Revision 1.18 1999/01/12 14:25:40 peter
  948. + BrowserLog for browser.log generation
  949. + BrowserCol for browser info in TCollections
  950. * released all other UseBrowser
  951. Revision 1.17 1998/12/11 00:03:52 peter
  952. + globtype,tokens,version unit splitted from globals
  953. Revision 1.16 1998/12/10 14:57:52 pierre
  954. * fix for operators
  955. Revision 1.15 1998/12/10 09:47:32 florian
  956. + basic operations with int64/qord (compiler with -dint64)
  957. + rtti of enumerations extended: names are now written
  958. Revision 1.14 1998/11/27 14:50:52 peter
  959. + open strings, $P switch support
  960. Revision 1.13 1998/11/24 17:03:51 peter
  961. * fixed exactmatch removings
  962. Revision 1.12 1998/11/16 10:18:10 peter
  963. * fixes for ansistrings
  964. Revision 1.11 1998/11/10 10:09:17 peter
  965. * va_list -> array of const
  966. Revision 1.10 1998/11/09 11:44:41 peter
  967. + va_list for printf support
  968. Revision 1.9 1998/10/28 18:26:22 pierre
  969. * removed some erros after other errors (introduced by useexcept)
  970. * stabs works again correctly (for how long !)
  971. Revision 1.8 1998/10/09 16:36:09 pierre
  972. * some memory leaks specific to usebrowser define fixed
  973. * removed tmodule.implsymtable (was like tmodule.localsymtable)
  974. Revision 1.7 1998/10/06 20:49:09 peter
  975. * m68k compiler compiles again
  976. Revision 1.6 1998/10/02 09:24:22 peter
  977. * more constant expression evaluators
  978. Revision 1.5 1998/09/28 11:22:17 pierre
  979. * did not compile for browser
  980. * merge from fixes
  981. Revision 1.4 1998/09/27 10:16:24 florian
  982. * type casts pchar<->ansistring fixed
  983. * ansistring[..] calls does now an unique call
  984. Revision 1.3 1998/09/24 14:27:40 peter
  985. * some better support for openarray
  986. Revision 1.2 1998/09/24 09:02:16 peter
  987. * rewritten isconvertable to use case
  988. * array of .. and single variable are compatible
  989. Revision 1.1 1998/09/23 20:42:24 peter
  990. * splitted pass_1
  991. }