tccal.pas 43 KB

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