tccal.pas 41 KB

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