tccal.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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. { check if the resulttype from tree p is equal with def, needed
  233. for stringconstn and formaldef }
  234. function is_equal(p:ptree;def:pdef) : boolean;
  235. begin
  236. { safety check }
  237. if not (assigned(def) or assigned(p^.resulttype)) then
  238. begin
  239. is_equal:=false;
  240. exit;
  241. end;
  242. { all types can be passed to a formaldef }
  243. is_equal:=(def^.deftype=formaldef) or
  244. (types.is_equal(p^.resulttype,def))
  245. { to support ansi/long/wide strings in a proper way }
  246. { string and string[10] are assumed as equal }
  247. { when searching the correct overloaded procedure }
  248. or
  249. (
  250. (def^.deftype=stringdef) and (p^.resulttype^.deftype=stringdef) and
  251. (pstringdef(def)^.string_typ=pstringdef(p^.resulttype)^.string_typ)
  252. )
  253. or
  254. (
  255. (p^.left^.treetype=stringconstn) and
  256. (is_ansistring(p^.resulttype) and is_pchar(def))
  257. )
  258. or
  259. (
  260. (p^.left^.treetype=ordconstn) and
  261. (is_char(p^.resulttype) and (is_shortstring(def) or is_ansistring(def)))
  262. )
  263. { set can also be a not yet converted array constructor }
  264. or
  265. (
  266. (def^.deftype=setdef) and (p^.resulttype^.deftype=arraydef) and
  267. (parraydef(p^.resulttype)^.IsConstructor) and not(parraydef(p^.resulttype)^.IsVariant)
  268. )
  269. ;
  270. end;
  271. function is_in_limit(def_from,def_to : pdef) : boolean;
  272. begin
  273. is_in_limit:=(def_from^.deftype = orddef) and
  274. (def_to^.deftype = orddef) and
  275. (porddef(def_from)^.low>porddef(def_to)^.low) and
  276. (porddef(def_from)^.high<porddef(def_to)^.high);
  277. end;
  278. var
  279. is_const : boolean;
  280. begin
  281. { release registers! }
  282. { if procdefinition<>nil then we called firstpass already }
  283. { it seems to be bad because of the registers }
  284. { at least we can avoid the overloaded search !! }
  285. procs:=nil;
  286. { made this global for disposing !! }
  287. store_valid:=must_be_valid;
  288. must_be_valid:=false;
  289. oldcallprocsym:=aktcallprocsym;
  290. aktcallprocsym:=nil;
  291. inlined:=false;
  292. if assigned(p^.procdefinition) and
  293. ((p^.procdefinition^.options and poinline)<>0) then
  294. begin
  295. inlinecode:=p^.right;
  296. if assigned(inlinecode) then
  297. begin
  298. inlined:=true;
  299. p^.procdefinition^.options:=p^.procdefinition^.options and (not poinline);
  300. end;
  301. p^.right:=nil;
  302. end;
  303. { procedure variable ? }
  304. if assigned(p^.right) then
  305. begin
  306. { procedure does a call }
  307. procinfo.flags:=procinfo.flags or pi_do_call;
  308. { calc the correture value for the register }
  309. {$ifdef i386}
  310. for regi:=R_EAX to R_EDI do
  311. inc(reg_pushes[regi],t_times*2);
  312. {$endif}
  313. {$ifdef m68k}
  314. for regi:=R_D0 to R_A6 do
  315. inc(reg_pushes[regi],t_times*2);
  316. {$endif}
  317. { calculate the type of the parameters }
  318. if assigned(p^.left) then
  319. begin
  320. old_count_ref:=count_ref;
  321. count_ref:=false;
  322. firstcallparan(p^.left,nil);
  323. count_ref:=old_count_ref;
  324. if codegenerror then
  325. exit;
  326. end;
  327. firstpass(p^.right);
  328. { check the parameters }
  329. pdc:=pprocvardef(p^.right^.resulttype)^.para1;
  330. pt:=p^.left;
  331. while assigned(pdc) and assigned(pt) do
  332. begin
  333. pt:=pt^.right;
  334. pdc:=pdc^.next;
  335. end;
  336. if assigned(pt) or assigned(pdc) then
  337. CGMessage(parser_e_illegal_parameter_list);
  338. { insert type conversions }
  339. if assigned(p^.left) then
  340. begin
  341. old_count_ref:=count_ref;
  342. count_ref:=true;
  343. firstcallparan(p^.left,pprocvardef(p^.right^.resulttype)^.para1);
  344. count_ref:=old_count_ref;
  345. if codegenerror then
  346. exit;
  347. end;
  348. p^.resulttype:=pprocvardef(p^.right^.resulttype)^.retdef;
  349. { this was missing, leads to a bug below if
  350. the procvar is a function }
  351. p^.procdefinition:=pprocdef(p^.right^.resulttype);
  352. end
  353. else
  354. { not a procedure variable }
  355. begin
  356. { determine the type of the parameters }
  357. if assigned(p^.left) then
  358. begin
  359. old_count_ref:=count_ref;
  360. count_ref:=false;
  361. store_valid:=must_be_valid;
  362. must_be_valid:=false;
  363. firstcallparan(p^.left,nil);
  364. count_ref:=old_count_ref;
  365. must_be_valid:=store_valid;
  366. if codegenerror then
  367. exit;
  368. end;
  369. aktcallprocsym:=pprocsym(p^.symtableprocentry);
  370. { do we know the procedure to call ? }
  371. if not(assigned(p^.procdefinition)) then
  372. begin
  373. {$ifdef TEST_PROCSYMS}
  374. if (p^.unit_specific) or
  375. assigned(p^.methodpointer) then
  376. nextprocsym:=nil
  377. else while not assigned(procs) do
  378. begin
  379. symt:=p^.symtableproc;
  380. srsym:=nil;
  381. while assigned(symt^.next) and not assigned(srsym) do
  382. begin
  383. symt:=symt^.next;
  384. getsymonlyin(symt,actprocsym^.name);
  385. if assigned(srsym) then
  386. if srsym^.typ<>procsym then
  387. begin
  388. { reject all that is not a procedure }
  389. srsym:=nil;
  390. { don't search elsewhere }
  391. while assigned(symt^.next) do
  392. symt:=symt^.next;
  393. end;
  394. end;
  395. nextprocsym:=srsym;
  396. end;
  397. {$else TEST_PROCSYMS}
  398. nextprocsym:=nil;
  399. {$endif TEST_PROCSYMS}
  400. { determine length of parameter list }
  401. pt:=p^.left;
  402. paralength:=0;
  403. while assigned(pt) do
  404. begin
  405. inc(paralength);
  406. pt:=pt^.right;
  407. end;
  408. { link all procedures which have the same # of parameters }
  409. pd:=aktcallprocsym^.definition;
  410. while assigned(pd) do
  411. begin
  412. { we should also check that the overloaded function
  413. has been declared in a unit that is in the uses !! }
  414. { pd^.owner should be in the symtablestack !! }
  415. { Laenge der deklarierten Parameterliste feststellen: }
  416. { not necessary why nextprocsym field }
  417. {st:=symtablestack;
  418. if (pd^.owner^.symtabletype<>objectsymtable) then
  419. while assigned(st) do
  420. begin
  421. if (st=pd^.owner) then break;
  422. st:=st^.next;
  423. end;
  424. if assigned(st) then }
  425. begin
  426. pdc:=pd^.para1;
  427. l:=0;
  428. while assigned(pdc) do
  429. begin
  430. inc(l);
  431. pdc:=pdc^.next;
  432. end;
  433. { only when the # of parameter are equal }
  434. if (l=paralength) then
  435. begin
  436. new(hp);
  437. hp^.data:=pd;
  438. hp^.next:=procs;
  439. hp^.nextpara:=pd^.para1;
  440. hp^.firstpara:=pd^.para1;
  441. procs:=hp;
  442. end;
  443. end;
  444. pd:=pd^.nextoverloaded;
  445. end;
  446. { no procedures found? then there is something wrong
  447. with the parameter size }
  448. if not assigned(procs) and
  449. ((parsing_para_level=0) or assigned(p^.left)) and
  450. (nextprocsym=nil) then
  451. begin
  452. CGMessage(parser_e_wrong_parameter_size);
  453. aktcallprocsym^.write_parameter_lists;
  454. exit;
  455. end;
  456. { now we can compare parameter after parameter }
  457. pt:=p^.left;
  458. while assigned(pt) do
  459. begin
  460. { matches a parameter of one procedure exact ? }
  461. exactmatch:=false;
  462. hp:=procs;
  463. while assigned(hp) do
  464. begin
  465. if is_equal(pt,hp^.nextpara^.data) then
  466. begin
  467. if hp^.nextpara^.data=pt^.resulttype then
  468. begin
  469. pt^.exact_match_found:=true;
  470. hp^.nextpara^.argconvtyp:=act_exact;
  471. end
  472. else
  473. hp^.nextpara^.argconvtyp:=act_equal;
  474. exactmatch:=true;
  475. end
  476. else
  477. hp^.nextpara^.argconvtyp:=act_convertable;
  478. hp:=hp^.next;
  479. end;
  480. { .... if yes, del all the other procedures }
  481. if exactmatch then
  482. begin
  483. { the first .... }
  484. while (assigned(procs)) and not(is_equal(pt,procs^.nextpara^.data)) do
  485. begin
  486. hp:=procs^.next;
  487. dispose(procs);
  488. procs:=hp;
  489. end;
  490. { and the others }
  491. hp:=procs;
  492. while (assigned(hp)) and assigned(hp^.next) do
  493. begin
  494. if not(is_equal(pt,hp^.next^.nextpara^.data)) then
  495. begin
  496. hp2:=hp^.next^.next;
  497. dispose(hp^.next);
  498. hp^.next:=hp2;
  499. end
  500. else
  501. hp:=hp^.next;
  502. end;
  503. end
  504. { when a parameter matches exact, remove all procs
  505. which need typeconvs }
  506. else
  507. begin
  508. { the first... }
  509. while (assigned(procs)) and
  510. not(isconvertable(pt^.resulttype,procs^.nextpara^.data,
  511. hcvt,pt^.left^.treetype,false)) do
  512. begin
  513. hp:=procs^.next;
  514. dispose(procs);
  515. procs:=hp;
  516. end;
  517. { and the others }
  518. hp:=procs;
  519. while (assigned(hp)) and assigned(hp^.next) do
  520. begin
  521. if not(isconvertable(pt^.resulttype,hp^.next^.nextpara^.data,
  522. hcvt,pt^.left^.treetype,false)) then
  523. begin
  524. hp2:=hp^.next^.next;
  525. dispose(hp^.next);
  526. hp^.next:=hp2;
  527. end
  528. else
  529. hp:=hp^.next;
  530. end;
  531. end;
  532. { update nextpara for all procedures }
  533. hp:=procs;
  534. while assigned(hp) do
  535. begin
  536. hp^.nextpara:=hp^.nextpara^.next;
  537. hp:=hp^.next;
  538. end;
  539. { load next parameter }
  540. pt:=pt^.right;
  541. end;
  542. if not assigned(procs) then
  543. begin
  544. { there is an error, must be wrong type, because
  545. wrong size is already checked (PFV) }
  546. if ((parsing_para_level=0) or (p^.left<>nil)) and
  547. (nextprocsym=nil) then
  548. begin
  549. CGMessage(parser_e_wrong_parameter_type);
  550. aktcallprocsym^.write_parameter_lists;
  551. exit;
  552. end
  553. else
  554. begin
  555. { try to convert to procvar }
  556. p^.treetype:=loadn;
  557. p^.resulttype:=pprocsym(p^.symtableprocentry)^.definition;
  558. p^.symtableentry:=p^.symtableprocentry;
  559. p^.is_first:=false;
  560. p^.disposetyp:=dt_nothing;
  561. firstpass(p);
  562. exit;
  563. end;
  564. end;
  565. { if there are several choices left then for orddef }
  566. { if a type is totally included in the other }
  567. { we don't fear an overflow , }
  568. { so we can do as if it is an exact match }
  569. { this will convert integer to longint }
  570. { rather than to words }
  571. { conversion of byte to integer or longint }
  572. {would still not be solved }
  573. if assigned(procs) and assigned(procs^.next) then
  574. begin
  575. hp:=procs;
  576. while assigned(hp) do
  577. begin
  578. hp^.nextpara:=hp^.firstpara;
  579. hp:=hp^.next;
  580. end;
  581. pt:=p^.left;
  582. while assigned(pt) do
  583. begin
  584. { matches a parameter of one procedure exact ? }
  585. exactmatch:=false;
  586. def_from:=pt^.resulttype;
  587. hp:=procs;
  588. while assigned(hp) do
  589. begin
  590. if not is_equal(pt,hp^.nextpara^.data) then
  591. begin
  592. def_to:=hp^.nextpara^.data;
  593. if ((def_from^.deftype=orddef) and (def_to^.deftype=orddef)) and
  594. (is_in_limit(def_from,def_to) or
  595. ((hp^.nextpara^.paratyp=vs_var) and
  596. (def_from^.size=def_to^.size))) then
  597. begin
  598. exactmatch:=true;
  599. conv_to:=def_to;
  600. end;
  601. end;
  602. hp:=hp^.next;
  603. end;
  604. { .... if yes, del all the other procedures }
  605. if exactmatch then
  606. begin
  607. { the first .... }
  608. while (assigned(procs)) and not(is_in_limit(def_from,procs^.nextpara^.data)) do
  609. begin
  610. hp:=procs^.next;
  611. dispose(procs);
  612. procs:=hp;
  613. end;
  614. { and the others }
  615. hp:=procs;
  616. while (assigned(hp)) and assigned(hp^.next) do
  617. begin
  618. if not(is_in_limit(def_from,hp^.next^.nextpara^.data)) then
  619. begin
  620. hp2:=hp^.next^.next;
  621. dispose(hp^.next);
  622. hp^.next:=hp2;
  623. end
  624. else
  625. begin
  626. def_to:=hp^.next^.nextpara^.data;
  627. if (conv_to^.size>def_to^.size) or
  628. ((porddef(conv_to)^.low<porddef(def_to)^.low) and
  629. (porddef(conv_to)^.high>porddef(def_to)^.high)) then
  630. begin
  631. hp2:=procs;
  632. procs:=hp;
  633. conv_to:=def_to;
  634. dispose(hp2);
  635. end
  636. else
  637. hp:=hp^.next;
  638. end;
  639. end;
  640. end;
  641. { update nextpara for all procedures }
  642. hp:=procs;
  643. while assigned(hp) do
  644. begin
  645. hp^.nextpara:=hp^.nextpara^.next;
  646. hp:=hp^.next;
  647. end;
  648. pt:=pt^.right;
  649. end;
  650. end;
  651. { reset nextpara for all procs left }
  652. hp:=procs;
  653. while assigned(hp) do
  654. begin
  655. hp^.nextpara:=hp^.firstpara;
  656. hp:=hp^.next;
  657. end;
  658. { let's try to eliminate equal is exact is there }
  659. if assigned(procs^.next) then
  660. begin
  661. pt:=p^.left;
  662. while assigned(pt) do
  663. begin
  664. if pt^.exact_match_found then
  665. begin
  666. hp:=procs;
  667. procs:=nil;
  668. while assigned(hp) do
  669. begin
  670. hp2:=hp^.next;
  671. { keep the exact matches, dispose the others }
  672. if (hp^.nextpara^.data=pt^.resulttype) then
  673. begin
  674. hp^.next:=procs;
  675. procs:=hp;
  676. end
  677. else
  678. begin
  679. dispose(hp);
  680. end;
  681. hp:=hp2;
  682. end;
  683. end;
  684. { update nextpara for all procedures }
  685. hp:=procs;
  686. while assigned(hp) do
  687. begin
  688. hp^.nextpara:=hp^.nextpara^.next;
  689. hp:=hp^.next;
  690. end;
  691. pt:=pt^.right;
  692. end;
  693. end;
  694. if assigned(procs^.next) then
  695. begin
  696. CGMessage(cg_e_cant_choose_overload_function);
  697. aktcallprocsym^.write_parameter_lists;
  698. end;
  699. {$ifdef TEST_PROCSYMS}
  700. if (procs=nil) and assigned(nextprocsym) then
  701. begin
  702. p^.symtableprocentry:=nextprocsym;
  703. p^.symtableproc:=symt;
  704. end;
  705. end ; { of while assigned(p^.symtableprocentry) do }
  706. {$endif TEST_PROCSYMS}
  707. {$ifdef UseBrowser}
  708. if make_ref then
  709. begin
  710. procs^.data^.lastref:=new(pref,init(procs^.data^.lastref,@p^.fileinfo));
  711. if procs^.data^.defref=nil then
  712. procs^.data^.defref:=procs^.data^.lastref;
  713. end;
  714. {$endif UseBrowser}
  715. p^.procdefinition:=procs^.data;
  716. p^.resulttype:=procs^.data^.retdef;
  717. { big error for with statements
  718. p^.symtableproc:=p^.procdefinition^.owner; }
  719. p^.location.loc:=LOC_MEM;
  720. {$ifdef CHAINPROCSYMS}
  721. { object with method read;
  722. call to read(x) will be a usual procedure call }
  723. if assigned(p^.methodpointer) and
  724. (p^.procdefinition^._class=nil) then
  725. begin
  726. { not ok for extended }
  727. case p^.methodpointer^.treetype of
  728. typen,hnewn : fatalerror(no_para_match);
  729. end;
  730. disposetree(p^.methodpointer);
  731. p^.methodpointer:=nil;
  732. end;
  733. {$endif CHAINPROCSYMS}
  734. end; { end of procedure to call determination }
  735. is_const:=((p^.procdefinition^.options and pointernconst)<>0) and
  736. ((block_type=bt_const) or
  737. (assigned(p^.left) and (p^.left^.left^.treetype in [realconstn,ordconstn])));
  738. { handle predefined procedures }
  739. if ((p^.procdefinition^.options and pointernproc)<>0) or is_const then
  740. begin
  741. if assigned(p^.left) then
  742. begin
  743. { settextbuf needs two args }
  744. if assigned(p^.left^.right) then
  745. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left)
  746. else
  747. begin
  748. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left^.left);
  749. putnode(p^.left);
  750. end;
  751. end
  752. else
  753. begin
  754. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,nil);
  755. end;
  756. putnode(p);
  757. firstpass(pt);
  758. p:=pt;
  759. must_be_valid:=store_valid;
  760. if codegenerror then
  761. exit;
  762. dispose(procs);
  763. exit;
  764. end
  765. else
  766. { no intern procedure => we do a call }
  767. { calc the correture value for the register }
  768. { handle predefined procedures }
  769. if (p^.procdefinition^.options and poinline)<>0 then
  770. begin
  771. if assigned(p^.methodpointer) then
  772. CGMessage(cg_e_unable_inline_object_methods);
  773. if assigned(p^.right) and (p^.right^.treetype<>procinlinen) then
  774. CGMessage(cg_e_unable_inline_procvar);
  775. { p^.treetype:=procinlinen; }
  776. if not assigned(p^.right) then
  777. begin
  778. if assigned(p^.procdefinition^.code) then
  779. inlinecode:=genprocinlinenode(p,ptree(p^.procdefinition^.code))
  780. else
  781. CGMessage(cg_e_no_code_for_inline_stored);
  782. if assigned(inlinecode) then
  783. begin
  784. { consider it has not inlined if called
  785. again inside the args }
  786. p^.procdefinition^.options:=p^.procdefinition^.options and (not poinline);
  787. firstpass(inlinecode);
  788. inlined:=true;
  789. end;
  790. end;
  791. end
  792. else
  793. procinfo.flags:=procinfo.flags or pi_do_call;
  794. { work trough all parameters to insert the type conversions }
  795. { !!! done now after internproc !! (PM) }
  796. if assigned(p^.left) then
  797. begin
  798. old_count_ref:=count_ref;
  799. count_ref:=true;
  800. firstcallparan(p^.left,p^.procdefinition^.para1);
  801. count_ref:=old_count_ref;
  802. end;
  803. {$ifdef i386}
  804. for regi:=R_EAX to R_EDI do
  805. begin
  806. if (p^.procdefinition^.usedregisters and ($80 shr word(regi)))<>0 then
  807. inc(reg_pushes[regi],t_times*2);
  808. end;
  809. {$endif}
  810. {$ifdef m68k}
  811. for regi:=R_D0 to R_A6 do
  812. begin
  813. if (p^.procdefinition^.usedregisters and ($800 shr word(regi)))<>0 then
  814. inc(reg_pushes[regi],t_times*2);
  815. end;
  816. {$endif}
  817. end;
  818. { ensure that the result type is set }
  819. p^.resulttype:=p^.procdefinition^.retdef;
  820. { get a register for the return value }
  821. if (p^.resulttype<>pdef(voiddef)) then
  822. begin
  823. if (p^.procdefinition^.options and poconstructor)<>0 then
  824. begin
  825. { extra handling of classes }
  826. { p^.methodpointer should be assigned! }
  827. if assigned(p^.methodpointer) and assigned(p^.methodpointer^.resulttype) and
  828. (p^.methodpointer^.resulttype^.deftype=classrefdef) then
  829. begin
  830. p^.location.loc:=LOC_REGISTER;
  831. p^.registers32:=1;
  832. { the result type depends on the classref }
  833. p^.resulttype:=pclassrefdef(p^.methodpointer^.resulttype)^.definition;
  834. end
  835. { a object constructor returns the result with the flags }
  836. else
  837. p^.location.loc:=LOC_FLAGS;
  838. end
  839. else
  840. begin
  841. {$ifdef SUPPORT_MMX}
  842. if (cs_mmx in aktlocalswitches) and
  843. is_mmx_able_array(p^.resulttype) then
  844. begin
  845. p^.location.loc:=LOC_MMXREGISTER;
  846. p^.registersmmx:=1;
  847. end
  848. else
  849. {$endif SUPPORT_MMX}
  850. if ret_in_acc(p^.resulttype) then
  851. begin
  852. p^.location.loc:=LOC_REGISTER;
  853. p^.registers32:=1;
  854. end
  855. else if (p^.resulttype^.deftype=floatdef) then
  856. begin
  857. p^.location.loc:=LOC_FPU;
  858. p^.registersfpu:=1;
  859. end
  860. end;
  861. end;
  862. { a fpu can be used in any procedure !! }
  863. p^.registersfpu:=p^.procdefinition^.fpu_used;
  864. { if this is a call to a method calc the registers }
  865. if (p^.methodpointer<>nil) then
  866. begin
  867. case p^.methodpointer^.treetype of
  868. { but only, if this is not a supporting node }
  869. typen,hnewn : ;
  870. else
  871. begin
  872. { R.Assign is not a constructor !!! }
  873. { but for R^.Assign, R must be valid !! }
  874. if ((p^.procdefinition^.options and poconstructor) <> 0) or
  875. ((p^.methodpointer^.treetype=loadn) and
  876. ((pobjectdef(p^.methodpointer^.resulttype)^.options and oo_hasvirtual) = 0)) then
  877. must_be_valid:=false
  878. else
  879. must_be_valid:=true;
  880. firstpass(p^.methodpointer);
  881. p^.registersfpu:=max(p^.methodpointer^.registersfpu,p^.registersfpu);
  882. p^.registers32:=max(p^.methodpointer^.registers32,p^.registers32);
  883. {$ifdef SUPPORT_MMX}
  884. p^.registersmmx:=max(p^.methodpointer^.registersmmx,p^.registersmmx);
  885. {$endif SUPPORT_MMX}
  886. end;
  887. end;
  888. end;
  889. if inlined then
  890. begin
  891. p^.right:=inlinecode;
  892. p^.procdefinition^.options:=p^.procdefinition^.options or poinline;
  893. end;
  894. { determine the registers of the procedure variable }
  895. { is this OK for inlined procs also ?? (PM) }
  896. if assigned(p^.right) then
  897. begin
  898. p^.registersfpu:=max(p^.right^.registersfpu,p^.registersfpu);
  899. p^.registers32:=max(p^.right^.registers32,p^.registers32);
  900. {$ifdef SUPPORT_MMX}
  901. p^.registersmmx:=max(p^.right^.registersmmx,p^.registersmmx);
  902. {$endif SUPPORT_MMX}
  903. end;
  904. { determine the registers of the procedure }
  905. if assigned(p^.left) then
  906. begin
  907. p^.registersfpu:=max(p^.left^.registersfpu,p^.registersfpu);
  908. p^.registers32:=max(p^.left^.registers32,p^.registers32);
  909. {$ifdef SUPPORT_MMX}
  910. p^.registersmmx:=max(p^.left^.registersmmx,p^.registersmmx);
  911. {$endif SUPPORT_MMX}
  912. end;
  913. if assigned(procs) then
  914. dispose(procs);
  915. aktcallprocsym:=oldcallprocsym;
  916. must_be_valid:=store_valid;
  917. end;
  918. {*****************************************************************************
  919. FirstProcInlineN
  920. *****************************************************************************}
  921. procedure firstprocinline(var p : ptree);
  922. begin
  923. { left contains the code in tree form }
  924. { but it has already been firstpassed }
  925. { so firstpass(p^.left); does not seem required }
  926. { might be required later if we change the arg handling !! }
  927. end;
  928. end.
  929. {
  930. $Log$
  931. Revision 1.13 1998-11-24 17:03:51 peter
  932. * fixed exactmatch removings
  933. Revision 1.12 1998/11/16 10:18:10 peter
  934. * fixes for ansistrings
  935. Revision 1.11 1998/11/10 10:09:17 peter
  936. * va_list -> array of const
  937. Revision 1.10 1998/11/09 11:44:41 peter
  938. + va_list for printf support
  939. Revision 1.9 1998/10/28 18:26:22 pierre
  940. * removed some erros after other errors (introduced by useexcept)
  941. * stabs works again correctly (for how long !)
  942. Revision 1.8 1998/10/09 16:36:09 pierre
  943. * some memory leaks specific to usebrowser define fixed
  944. * removed tmodule.implsymtable (was like tmodule.localsymtable)
  945. Revision 1.7 1998/10/06 20:49:09 peter
  946. * m68k compiler compiles again
  947. Revision 1.6 1998/10/02 09:24:22 peter
  948. * more constant expression evaluators
  949. Revision 1.5 1998/09/28 11:22:17 pierre
  950. * did not compile for browser
  951. * merge from fixes
  952. Revision 1.4 1998/09/27 10:16:24 florian
  953. * type casts pchar<->ansistring fixed
  954. * ansistring[..] calls does now an unique call
  955. Revision 1.3 1998/09/24 14:27:40 peter
  956. * some better support for openarray
  957. Revision 1.2 1998/09/24 09:02:16 peter
  958. * rewritten isconvertable to use case
  959. * array of .. and single variable are compatible
  960. Revision 1.1 1998/09/23 20:42:24 peter
  961. * splitted pass_1
  962. }