tccal.pas 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  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. cobjects,verbose,globals,systems,
  28. aasm,types,
  29. hcodegen,htypechk,pass_1
  30. {$ifdef i386}
  31. ,i386,tgeni386
  32. {$endif}
  33. {$ifdef m68k}
  34. ,m68k,tgeni386
  35. {$endif}
  36. ;
  37. {*****************************************************************************
  38. FirstCallParaN
  39. *****************************************************************************}
  40. procedure firstcallparan(var p : ptree;defcoll : pdefcoll);
  41. var
  42. old_array_constructor : boolean;
  43. store_valid : boolean;
  44. convtyp : tconverttype;
  45. begin
  46. inc(parsing_para_level);
  47. if assigned(p^.right) then
  48. begin
  49. if defcoll=nil then
  50. firstcallparan(p^.right,nil)
  51. else
  52. firstcallparan(p^.right,defcoll^.next);
  53. p^.registers32:=p^.right^.registers32;
  54. p^.registersfpu:=p^.right^.registersfpu;
  55. {$ifdef SUPPORT_MMX}
  56. p^.registersmmx:=p^.right^.registersmmx;
  57. {$endif}
  58. end;
  59. if defcoll=nil then
  60. begin
  61. old_array_constructor:=allow_array_constructor;
  62. allow_array_constructor:=true;
  63. if not(assigned(p^.resulttype)) or
  64. (p^.left^.treetype=typeconvn) then
  65. firstpass(p^.left);
  66. allow_array_constructor:=old_array_constructor;
  67. if codegenerror then
  68. begin
  69. dec(parsing_para_level);
  70. exit;
  71. end;
  72. p^.resulttype:=p^.left^.resulttype;
  73. end
  74. { if we know the routine which is called, then the type }
  75. { conversions are inserted }
  76. else
  77. begin
  78. if count_ref then
  79. begin
  80. store_valid:=must_be_valid;
  81. if (defcoll^.paratyp=vs_var) then
  82. test_protected(p^.left);
  83. if (defcoll^.paratyp<>vs_var) then
  84. must_be_valid:=true
  85. else
  86. must_be_valid:=false;
  87. { here we must add something for the implicit type }
  88. { conversion from array of char to pchar }
  89. if isconvertable(p^.left^.resulttype,defcoll^.data,convtyp,
  90. p^.left^.treetype,false) then
  91. if convtyp=tc_array_to_pointer then
  92. must_be_valid:=false;
  93. { only process typeconvn, else it will break other trees }
  94. old_array_constructor:=allow_array_constructor;
  95. allow_array_constructor:=true;
  96. if (p^.left^.treetype=typeconvn) then
  97. firstpass(p^.left);
  98. allow_array_constructor:=old_array_constructor;
  99. must_be_valid:=store_valid;
  100. end;
  101. if not(is_shortstring(p^.left^.resulttype) and
  102. is_shortstring(defcoll^.data)) and
  103. (defcoll^.data^.deftype<>formaldef) then
  104. begin
  105. if (defcoll^.paratyp=vs_var) and
  106. { allows conversion from word to integer and
  107. byte to shortint }
  108. (not(
  109. (p^.left^.resulttype^.deftype=orddef) and
  110. (defcoll^.data^.deftype=orddef) and
  111. (p^.left^.resulttype^.size=defcoll^.data^.size)
  112. ) and
  113. { an implicit pointer conversion is allowed }
  114. not(
  115. (p^.left^.resulttype^.deftype=pointerdef) and
  116. (defcoll^.data^.deftype=pointerdef)
  117. ) and
  118. { child classes can be also passed }
  119. not(
  120. (p^.left^.resulttype^.deftype=objectdef) and
  121. (defcoll^.data^.deftype=objectdef) and
  122. pobjectdef(p^.left^.resulttype)^.isrelated(pobjectdef(defcoll^.data))
  123. ) and
  124. { an implicit file conversion is also allowed }
  125. { from a typed file to an untyped one }
  126. not(
  127. (p^.left^.resulttype^.deftype=filedef) and
  128. (defcoll^.data^.deftype=filedef) and
  129. (pfiledef(defcoll^.data)^.filetype = ft_untyped) and
  130. (pfiledef(p^.left^.resulttype)^.filetype = ft_typed)
  131. ) and
  132. not(is_equal(p^.left^.resulttype,defcoll^.data))) then
  133. CGMessage(parser_e_call_by_ref_without_typeconv);
  134. { don't generate an type conversion for open arrays }
  135. { else we loss the ranges }
  136. if not(is_open_array(defcoll^.data)) then
  137. begin
  138. p^.left:=gentypeconvnode(p^.left,defcoll^.data);
  139. firstpass(p^.left);
  140. end;
  141. if codegenerror then
  142. begin
  143. dec(parsing_para_level);
  144. exit;
  145. end;
  146. end;
  147. { check var strings }
  148. if (cs_strict_var_strings in aktlocalswitches) and
  149. is_shortstring(p^.left^.resulttype) and
  150. is_shortstring(defcoll^.data) and
  151. (defcoll^.paratyp=vs_var) and
  152. not(is_equal(p^.left^.resulttype,defcoll^.data)) then
  153. CGMessage(type_e_strict_var_string_violation);
  154. { Variablen, die call by reference �bergeben werden, }
  155. { k”nnen nicht in ein Register kopiert werden }
  156. { is this usefull here ? }
  157. { this was missing in formal parameter list }
  158. if defcoll^.paratyp=vs_var then
  159. make_not_regable(p^.left);
  160. p^.resulttype:=defcoll^.data;
  161. end;
  162. if p^.left^.registers32>p^.registers32 then
  163. p^.registers32:=p^.left^.registers32;
  164. if p^.left^.registersfpu>p^.registersfpu then
  165. p^.registersfpu:=p^.left^.registersfpu;
  166. {$ifdef SUPPORT_MMX}
  167. if p^.left^.registersmmx>p^.registersmmx then
  168. p^.registersmmx:=p^.left^.registersmmx;
  169. {$endif SUPPORT_MMX}
  170. dec(parsing_para_level);
  171. end;
  172. {*****************************************************************************
  173. FirstCallN
  174. *****************************************************************************}
  175. procedure firstcalln(var p : ptree);
  176. type
  177. pprocdefcoll = ^tprocdefcoll;
  178. tprocdefcoll = record
  179. data : pprocdef;
  180. nextpara : pdefcoll;
  181. firstpara : pdefcoll;
  182. next : pprocdefcoll;
  183. end;
  184. var
  185. hp,procs,hp2 : pprocdefcoll;
  186. pd : pprocdef;
  187. actprocsym : pprocsym;
  188. def_from,def_to,conv_to : pdef;
  189. pt,inlinecode : ptree;
  190. exactmatch,inlined : boolean;
  191. paralength,l : longint;
  192. pdc : pdefcoll;
  193. { only Dummy }
  194. hcvt : tconverttype;
  195. regi : tregister;
  196. store_valid, old_count_ref : boolean;
  197. { types.is_equal can't handle a formaldef ! }
  198. function is_equal(def1,def2 : pdef) : boolean;
  199. begin
  200. { safety check }
  201. if not (assigned(def1) or assigned(def2)) then
  202. begin
  203. is_equal:=false;
  204. exit;
  205. end;
  206. { all types can be passed to a formaldef }
  207. is_equal:=(def1^.deftype=formaldef) or
  208. (types.is_equal(def1,def2))
  209. { to support ansi/long/wide strings in a proper way }
  210. { string and string[10] are assumed as equal }
  211. { when searching the correct overloaded procedure }
  212. or
  213. (
  214. (def1^.deftype=stringdef) and (def2^.deftype=stringdef) and
  215. (pstringdef(def1)^.string_typ=pstringdef(def2)^.string_typ)
  216. )
  217. { set can also be a not yet converted array constructor }
  218. or
  219. (
  220. (def1^.deftype=setdef) and (def2^.deftype=arraydef) and
  221. (parraydef(def2)^.IsConstructor) and not(parraydef(def2)^.IsVariant)
  222. )
  223. ;
  224. end;
  225. function is_in_limit(def_from,def_to : pdef) : boolean;
  226. begin
  227. is_in_limit:=(def_from^.deftype = orddef) and
  228. (def_to^.deftype = orddef) and
  229. (porddef(def_from)^.low>porddef(def_to)^.low) and
  230. (porddef(def_from)^.high<porddef(def_to)^.high);
  231. end;
  232. var
  233. is_const : boolean;
  234. begin
  235. { release registers! }
  236. { if procdefinition<>nil then we called firstpass already }
  237. { it seems to be bad because of the registers }
  238. { at least we can avoid the overloaded search !! }
  239. procs:=nil;
  240. { made this global for disposing !! }
  241. store_valid:=must_be_valid;
  242. must_be_valid:=false;
  243. inlined:=false;
  244. if assigned(p^.procdefinition) and
  245. ((p^.procdefinition^.options and poinline)<>0) then
  246. begin
  247. inlinecode:=p^.right;
  248. if assigned(inlinecode) then
  249. begin
  250. inlined:=true;
  251. p^.procdefinition^.options:=p^.procdefinition^.options and (not poinline);
  252. end;
  253. p^.right:=nil;
  254. end;
  255. { procedure variable ? }
  256. if assigned(p^.right) then
  257. begin
  258. { procedure does a call }
  259. procinfo.flags:=procinfo.flags or pi_do_call;
  260. { calc the correture value for the register }
  261. {$ifdef i386}
  262. for regi:=R_EAX to R_EDI do
  263. inc(reg_pushes[regi],t_times*2);
  264. {$endif}
  265. {$ifdef m68k}
  266. for regi:=R_D0 to R_A6 do
  267. inc(reg_pushes[regi],t_times*2);
  268. {$endif}
  269. { calculate the type of the parameters }
  270. if assigned(p^.left) then
  271. begin
  272. old_count_ref:=count_ref;
  273. count_ref:=false;
  274. firstcallparan(p^.left,nil);
  275. count_ref:=old_count_ref;
  276. if codegenerror then
  277. exit;
  278. end;
  279. firstpass(p^.right);
  280. { check the parameters }
  281. pdc:=pprocvardef(p^.right^.resulttype)^.para1;
  282. pt:=p^.left;
  283. while assigned(pdc) and assigned(pt) do
  284. begin
  285. pt:=pt^.right;
  286. pdc:=pdc^.next;
  287. end;
  288. if assigned(pt) or assigned(pdc) then
  289. CGMessage(parser_e_illegal_parameter_list);
  290. { insert type conversions }
  291. if assigned(p^.left) then
  292. begin
  293. old_count_ref:=count_ref;
  294. count_ref:=true;
  295. firstcallparan(p^.left,pprocvardef(p^.right^.resulttype)^.para1);
  296. count_ref:=old_count_ref;
  297. if codegenerror then
  298. exit;
  299. end;
  300. p^.resulttype:=pprocvardef(p^.right^.resulttype)^.retdef;
  301. { this was missing, leads to a bug below if
  302. the procvar is a function }
  303. p^.procdefinition:=pprocdef(p^.right^.resulttype);
  304. end
  305. else
  306. { not a procedure variable }
  307. begin
  308. { determine the type of the parameters }
  309. if assigned(p^.left) then
  310. begin
  311. old_count_ref:=count_ref;
  312. count_ref:=false;
  313. store_valid:=must_be_valid;
  314. must_be_valid:=false;
  315. firstcallparan(p^.left,nil);
  316. count_ref:=old_count_ref;
  317. must_be_valid:=store_valid;
  318. if codegenerror then
  319. exit;
  320. end;
  321. { do we know the procedure to call ? }
  322. if not(assigned(p^.procdefinition)) then
  323. begin
  324. actprocsym:=pprocsym(p^.symtableprocentry);
  325. { determine length of parameter list }
  326. pt:=p^.left;
  327. paralength:=0;
  328. while assigned(pt) do
  329. begin
  330. inc(paralength);
  331. pt:=pt^.right;
  332. end;
  333. { link all procedures which have the same # of parameters }
  334. pd:=actprocsym^.definition;
  335. while assigned(pd) do
  336. begin
  337. { we should also check that the overloaded function
  338. has been declared in a unit that is in the uses !! }
  339. { pd^.owner should be in the symtablestack !! }
  340. { Laenge der deklarierten Parameterliste feststellen: }
  341. { not necessary why nextprocsym field }
  342. {st:=symtablestack;
  343. if (pd^.owner^.symtabletype<>objectsymtable) then
  344. while assigned(st) do
  345. begin
  346. if (st=pd^.owner) then break;
  347. st:=st^.next;
  348. end;
  349. if assigned(st) then }
  350. begin
  351. pdc:=pd^.para1;
  352. l:=0;
  353. while assigned(pdc) do
  354. begin
  355. inc(l);
  356. pdc:=pdc^.next;
  357. end;
  358. { only when the # of parameter are equal }
  359. if l=paralength then
  360. begin
  361. new(hp);
  362. hp^.data:=pd;
  363. hp^.next:=procs;
  364. hp^.nextpara:=pd^.para1;
  365. hp^.firstpara:=pd^.para1;
  366. procs:=hp;
  367. end;
  368. end;
  369. pd:=pd^.nextoverloaded;
  370. {$ifdef CHAINPROCSYMS}
  371. if (pd=nil) and not (p^.unit_specific) then
  372. begin
  373. actprocsym:=actprocsym^.nextprocsym;
  374. if assigned(actprocsym) then
  375. pd:=actprocsym^.definition;
  376. end;
  377. {$endif CHAINPROCSYMS}
  378. end;
  379. { no procedures found? then there is something wrong
  380. with the parameter size }
  381. if not assigned(procs) and
  382. ((parsing_para_level=0) or assigned(p^.left)) then
  383. begin
  384. CGMessage(parser_e_wrong_parameter_size);
  385. actprocsym^.write_parameter_lists;
  386. exit;
  387. end;
  388. { now we can compare parameter after parameter }
  389. pt:=p^.left;
  390. while assigned(pt) do
  391. begin
  392. { matches a parameter of one procedure exact ? }
  393. exactmatch:=false;
  394. hp:=procs;
  395. while assigned(hp) do
  396. begin
  397. if is_equal(hp^.nextpara^.data,pt^.resulttype) then
  398. begin
  399. if hp^.nextpara^.data=pt^.resulttype then
  400. begin
  401. pt^.exact_match_found:=true;
  402. hp^.nextpara^.argconvtyp:=act_exact;
  403. end
  404. else
  405. hp^.nextpara^.argconvtyp:=act_equal;
  406. exactmatch:=true;
  407. end
  408. else
  409. hp^.nextpara^.argconvtyp:=act_convertable;
  410. hp:=hp^.next;
  411. end;
  412. { .... if yes, del all the other procedures }
  413. if exactmatch then
  414. begin
  415. { the first .... }
  416. while (assigned(procs)) and not(is_equal(procs^.nextpara^.data,pt^.resulttype)) do
  417. begin
  418. hp:=procs^.next;
  419. dispose(procs);
  420. procs:=hp;
  421. end;
  422. { and the others }
  423. hp:=procs;
  424. while (assigned(hp)) and assigned(hp^.next) do
  425. begin
  426. if not(is_equal(hp^.next^.nextpara^.data,pt^.resulttype)) then
  427. begin
  428. hp2:=hp^.next^.next;
  429. dispose(hp^.next);
  430. hp^.next:=hp2;
  431. end
  432. else
  433. hp:=hp^.next;
  434. end;
  435. end
  436. { when a parameter matches exact, remove all procs
  437. which need typeconvs }
  438. else
  439. begin
  440. { the first... }
  441. while (assigned(procs)) and
  442. not(isconvertable(pt^.resulttype,procs^.nextpara^.data,
  443. hcvt,pt^.left^.treetype,false)) do
  444. begin
  445. hp:=procs^.next;
  446. dispose(procs);
  447. procs:=hp;
  448. end;
  449. { and the others }
  450. hp:=procs;
  451. while (assigned(hp)) and assigned(hp^.next) do
  452. begin
  453. if not(isconvertable(pt^.resulttype,hp^.next^.nextpara^.data,
  454. hcvt,pt^.left^.treetype,false)) then
  455. begin
  456. hp2:=hp^.next^.next;
  457. dispose(hp^.next);
  458. hp^.next:=hp2;
  459. end
  460. else
  461. hp:=hp^.next;
  462. end;
  463. end;
  464. { update nextpara for all procedures }
  465. hp:=procs;
  466. while assigned(hp) do
  467. begin
  468. hp^.nextpara:=hp^.nextpara^.next;
  469. hp:=hp^.next;
  470. end;
  471. { load next parameter }
  472. pt:=pt^.right;
  473. end;
  474. if not assigned(procs) then
  475. begin
  476. { there is an error, must be wrong type, because
  477. wrong size is already checked (PFV) }
  478. if (parsing_para_level=0) or (p^.left<>nil) then
  479. begin
  480. CGMessage(parser_e_wrong_parameter_type);
  481. actprocsym^.write_parameter_lists;
  482. exit;
  483. end
  484. else
  485. begin
  486. { try to convert to procvar }
  487. p^.treetype:=loadn;
  488. p^.resulttype:=pprocsym(p^.symtableprocentry)^.definition;
  489. p^.symtableentry:=p^.symtableprocentry;
  490. p^.is_first:=false;
  491. p^.disposetyp:=dt_nothing;
  492. firstpass(p);
  493. exit;
  494. end;
  495. end;
  496. { if there are several choices left then for orddef }
  497. { if a type is totally included in the other }
  498. { we don't fear an overflow , }
  499. { so we can do as if it is an exact match }
  500. { this will convert integer to longint }
  501. { rather than to words }
  502. { conversion of byte to integer or longint }
  503. {would still not be solved }
  504. if assigned(procs^.next) then
  505. begin
  506. hp:=procs;
  507. while assigned(hp) do
  508. begin
  509. hp^.nextpara:=hp^.firstpara;
  510. hp:=hp^.next;
  511. end;
  512. pt:=p^.left;
  513. while assigned(pt) do
  514. begin
  515. { matches a parameter of one procedure exact ? }
  516. exactmatch:=false;
  517. def_from:=pt^.resulttype;
  518. hp:=procs;
  519. while assigned(hp) do
  520. begin
  521. if not is_equal(hp^.nextpara^.data,pt^.resulttype) then
  522. begin
  523. def_to:=hp^.nextpara^.data;
  524. if ((def_from^.deftype=orddef) and (def_to^.deftype=orddef)) and
  525. (is_in_limit(def_from,def_to) or
  526. ((hp^.nextpara^.paratyp=vs_var) and
  527. (def_from^.size=def_to^.size))) then
  528. begin
  529. exactmatch:=true;
  530. conv_to:=def_to;
  531. end;
  532. end;
  533. hp:=hp^.next;
  534. end;
  535. { .... if yes, del all the other procedures }
  536. if exactmatch then
  537. begin
  538. { the first .... }
  539. while (assigned(procs)) and not(is_in_limit(def_from,procs^.nextpara^.data)) do
  540. begin
  541. hp:=procs^.next;
  542. dispose(procs);
  543. procs:=hp;
  544. end;
  545. { and the others }
  546. hp:=procs;
  547. while (assigned(hp)) and assigned(hp^.next) do
  548. begin
  549. if not(is_in_limit(def_from,hp^.next^.nextpara^.data)) then
  550. begin
  551. hp2:=hp^.next^.next;
  552. dispose(hp^.next);
  553. hp^.next:=hp2;
  554. end
  555. else
  556. begin
  557. def_to:=hp^.next^.nextpara^.data;
  558. if (conv_to^.size>def_to^.size) or
  559. ((porddef(conv_to)^.low<porddef(def_to)^.low) and
  560. (porddef(conv_to)^.high>porddef(def_to)^.high)) then
  561. begin
  562. hp2:=procs;
  563. procs:=hp;
  564. conv_to:=def_to;
  565. dispose(hp2);
  566. end
  567. else
  568. hp:=hp^.next;
  569. end;
  570. end;
  571. end;
  572. { update nextpara for all procedures }
  573. hp:=procs;
  574. while assigned(hp) do
  575. begin
  576. hp^.nextpara:=hp^.nextpara^.next;
  577. hp:=hp^.next;
  578. end;
  579. pt:=pt^.right;
  580. end;
  581. end;
  582. { let's try to eliminate equal is exact is there }
  583. {if assigned(procs^.next) then
  584. begin
  585. pt:=p^.left;
  586. while assigned(pt) do
  587. begin
  588. if pt^.exact_match_found then
  589. begin
  590. hp:=procs;
  591. while (assigned(procs)) and (procs^.nextpara^.data<>pt^.resulttype) do
  592. begin
  593. hp:=procs^.next;
  594. dispose(procs);
  595. procs:=hp;
  596. end;
  597. end;
  598. pt:=pt^.right;
  599. end;
  600. end; }
  601. {$ifndef CHAINPROCSYMS}
  602. if assigned(procs^.next) then
  603. begin
  604. CGMessage(cg_e_cant_choose_overload_function);
  605. actprocsym^.write_parameter_lists;
  606. end;
  607. {$else CHAINPROCSYMS}
  608. if assigned(procs^.next) then
  609. { if the last retained is the only one }
  610. { from a unit it is OK PM }
  611. { the last is the one coming from the first symtable }
  612. { as the diff defcoll are inserted in front }
  613. begin
  614. hp2:=procs;
  615. while assigned(hp2^.next) and assigned(hp2^.next^.next) do
  616. hp2:=hp2^.next;
  617. if (hp2^.data^.owner<>hp2^.next^.data^.owner) then
  618. begin
  619. hp:=procs^.next;
  620. {hp2 is the correct one }
  621. hp2:=hp2^.next;
  622. while hp<>hp2 do
  623. begin
  624. dispose(procs);
  625. procs:=hp;
  626. hp:=procs^.next;
  627. end;
  628. procs:=hp2;
  629. end
  630. else
  631. begin
  632. CGMessage(cg_e_cant_choose_overload_function);
  633. actprocsym^.write_parameter_lists;
  634. error(too_much_matches);
  635. end;
  636. end;
  637. {$endif CHAINPROCSYMS}
  638. {$ifdef UseBrowser}
  639. if make_ref then
  640. begin
  641. procs^.data^.lastref:=new(pref,init(procs^.data^.lastref,@p^.fileinfo));
  642. end;
  643. {$endif UseBrowser}
  644. p^.procdefinition:=procs^.data;
  645. p^.resulttype:=procs^.data^.retdef;
  646. { big error for with statements
  647. p^.symtableproc:=p^.procdefinition^.owner; }
  648. p^.location.loc:=LOC_MEM;
  649. {$ifdef CHAINPROCSYMS}
  650. { object with method read;
  651. call to read(x) will be a usual procedure call }
  652. if assigned(p^.methodpointer) and
  653. (p^.procdefinition^._class=nil) then
  654. begin
  655. { not ok for extended }
  656. case p^.methodpointer^.treetype of
  657. typen,hnewn : fatalerror(no_para_match);
  658. end;
  659. disposetree(p^.methodpointer);
  660. p^.methodpointer:=nil;
  661. end;
  662. {$endif CHAINPROCSYMS}
  663. end;{ end of procedure to call determination }
  664. is_const:=((p^.procdefinition^.options and pointernconst)<>0) and
  665. (p^.left^.left^.treetype in [realconstn,ordconstn]);
  666. { handle predefined procedures }
  667. if ((p^.procdefinition^.options and pointernproc)<>0) or is_const then
  668. begin
  669. { settextbuf needs two args }
  670. if assigned(p^.left^.right) then
  671. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left)
  672. else
  673. begin
  674. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left^.left);
  675. putnode(p^.left);
  676. end;
  677. putnode(p);
  678. firstpass(pt);
  679. p:=pt;
  680. must_be_valid:=store_valid;
  681. if codegenerror then
  682. exit;
  683. dispose(procs);
  684. exit;
  685. end
  686. else
  687. { no intern procedure => we do a call }
  688. { calc the correture value for the register }
  689. { handle predefined procedures }
  690. if (p^.procdefinition^.options and poinline)<>0 then
  691. begin
  692. if assigned(p^.methodpointer) then
  693. CGMessage(cg_e_unable_inline_object_methods);
  694. if assigned(p^.right) and (p^.right^.treetype<>procinlinen) then
  695. CGMessage(cg_e_unable_inline_procvar);
  696. { p^.treetype:=procinlinen; }
  697. if not assigned(p^.right) then
  698. begin
  699. if assigned(p^.procdefinition^.code) then
  700. inlinecode:=genprocinlinenode(p,ptree(p^.procdefinition^.code))
  701. else
  702. CGMessage(cg_e_no_code_for_inline_stored);
  703. if assigned(inlinecode) then
  704. begin
  705. { consider it has not inlined if called
  706. again inside the args }
  707. p^.procdefinition^.options:=p^.procdefinition^.options and (not poinline);
  708. firstpass(inlinecode);
  709. inlined:=true;
  710. end;
  711. end;
  712. end
  713. else
  714. procinfo.flags:=procinfo.flags or pi_do_call;
  715. { work trough all parameters to insert the type conversions }
  716. { !!! done now after internproc !! (PM) }
  717. if assigned(p^.left) then
  718. begin
  719. old_count_ref:=count_ref;
  720. count_ref:=true;
  721. firstcallparan(p^.left,p^.procdefinition^.para1);
  722. count_ref:=old_count_ref;
  723. end;
  724. {$ifdef i386}
  725. for regi:=R_EAX to R_EDI do
  726. begin
  727. if (p^.procdefinition^.usedregisters and ($80 shr word(regi)))<>0 then
  728. inc(reg_pushes[regi],t_times*2);
  729. end;
  730. {$endif}
  731. {$ifdef m68k}
  732. for regi:=R_D0 to R_A6 do
  733. begin
  734. if (p^.procdefinition^.usedregisters and ($800 shr word(regi)))<>0 then
  735. inc(reg_pushes[regi],t_times*2);
  736. end;
  737. {$endif}
  738. end;
  739. { ensure that the result type is set }
  740. p^.resulttype:=p^.procdefinition^.retdef;
  741. { get a register for the return value }
  742. if (p^.resulttype<>pdef(voiddef)) then
  743. begin
  744. if (p^.procdefinition^.options and poconstructor)<>0 then
  745. begin
  746. { extra handling of classes }
  747. { p^.methodpointer should be assigned! }
  748. if assigned(p^.methodpointer) and assigned(p^.methodpointer^.resulttype) and
  749. (p^.methodpointer^.resulttype^.deftype=classrefdef) then
  750. begin
  751. p^.location.loc:=LOC_REGISTER;
  752. p^.registers32:=1;
  753. { the result type depends on the classref }
  754. p^.resulttype:=pclassrefdef(p^.methodpointer^.resulttype)^.definition;
  755. end
  756. { a object constructor returns the result with the flags }
  757. else
  758. p^.location.loc:=LOC_FLAGS;
  759. end
  760. else
  761. begin
  762. {$ifdef SUPPORT_MMX}
  763. if (cs_mmx in aktlocalswitches) and
  764. is_mmx_able_array(p^.resulttype) then
  765. begin
  766. p^.location.loc:=LOC_MMXREGISTER;
  767. p^.registersmmx:=1;
  768. end
  769. else
  770. {$endif SUPPORT_MMX}
  771. if ret_in_acc(p^.resulttype) then
  772. begin
  773. p^.location.loc:=LOC_REGISTER;
  774. p^.registers32:=1;
  775. end
  776. else if (p^.resulttype^.deftype=floatdef) then
  777. begin
  778. p^.location.loc:=LOC_FPU;
  779. p^.registersfpu:=1;
  780. end
  781. end;
  782. end;
  783. { a fpu can be used in any procedure !! }
  784. p^.registersfpu:=p^.procdefinition^.fpu_used;
  785. { if this is a call to a method calc the registers }
  786. if (p^.methodpointer<>nil) then
  787. begin
  788. case p^.methodpointer^.treetype of
  789. { but only, if this is not a supporting node }
  790. typen,hnewn : ;
  791. else
  792. begin
  793. { R.Assign is not a constructor !!! }
  794. { but for R^.Assign, R must be valid !! }
  795. if ((p^.procdefinition^.options and poconstructor) <> 0) or
  796. ((p^.methodpointer^.treetype=loadn) and
  797. ((pobjectdef(p^.methodpointer^.resulttype)^.options and oo_hasvirtual) = 0)) then
  798. must_be_valid:=false
  799. else
  800. must_be_valid:=true;
  801. firstpass(p^.methodpointer);
  802. p^.registersfpu:=max(p^.methodpointer^.registersfpu,p^.registersfpu);
  803. p^.registers32:=max(p^.methodpointer^.registers32,p^.registers32);
  804. {$ifdef SUPPORT_MMX}
  805. p^.registersmmx:=max(p^.methodpointer^.registersmmx,p^.registersmmx);
  806. {$endif SUPPORT_MMX}
  807. end;
  808. end;
  809. end;
  810. if inlined then
  811. begin
  812. p^.right:=inlinecode;
  813. p^.procdefinition^.options:=p^.procdefinition^.options or poinline;
  814. end;
  815. { determine the registers of the procedure variable }
  816. { is this OK for inlined procs also ?? (PM) }
  817. if assigned(p^.right) then
  818. begin
  819. p^.registersfpu:=max(p^.right^.registersfpu,p^.registersfpu);
  820. p^.registers32:=max(p^.right^.registers32,p^.registers32);
  821. {$ifdef SUPPORT_MMX}
  822. p^.registersmmx:=max(p^.right^.registersmmx,p^.registersmmx);
  823. {$endif SUPPORT_MMX}
  824. end;
  825. { determine the registers of the procedure }
  826. if assigned(p^.left) then
  827. begin
  828. p^.registersfpu:=max(p^.left^.registersfpu,p^.registersfpu);
  829. p^.registers32:=max(p^.left^.registers32,p^.registers32);
  830. {$ifdef SUPPORT_MMX}
  831. p^.registersmmx:=max(p^.left^.registersmmx,p^.registersmmx);
  832. {$endif SUPPORT_MMX}
  833. end;
  834. if assigned(procs) then
  835. dispose(procs);
  836. must_be_valid:=store_valid;
  837. end;
  838. {*****************************************************************************
  839. FirstProcInlineN
  840. *****************************************************************************}
  841. procedure firstprocinline(var p : ptree);
  842. begin
  843. { left contains the code in tree form }
  844. { but it has already been firstpassed }
  845. { so firstpass(p^.left); does not seem required }
  846. { might be required later if we change the arg handling !! }
  847. end;
  848. end.
  849. {
  850. $Log$
  851. Revision 1.1 1998-09-23 20:42:24 peter
  852. * splitted pass_1
  853. }