tccal.pas 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. Type checking and register allocation for call nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit tccal;
  19. interface
  20. uses
  21. symtable,tree;
  22. procedure firstcallparan(var p : ptree;defcoll : pdefcoll);
  23. procedure firstcalln(var p : ptree);
  24. procedure firstprocinline(var p : ptree);
  25. implementation
  26. uses
  27. globtype,systems,
  28. cobjects,verbose,globals,
  29. aasm,types,
  30. hcodegen,htypechk,pass_1
  31. {$ifdef i386}
  32. ,i386,tgeni386
  33. {$endif}
  34. {$ifdef m68k}
  35. ,m68k,tgen68k
  36. {$endif}
  37. ;
  38. {*****************************************************************************
  39. FirstCallParaN
  40. *****************************************************************************}
  41. procedure firstcallparan(var p : ptree;defcoll : pdefcoll);
  42. var
  43. old_array_constructor : boolean;
  44. store_valid : boolean;
  45. oldtype : pdef;
  46. {convtyp : tconverttype;}
  47. begin
  48. inc(parsing_para_level);
  49. if assigned(p^.right) then
  50. begin
  51. if defcoll=nil then
  52. firstcallparan(p^.right,nil)
  53. else
  54. firstcallparan(p^.right,defcoll^.next);
  55. p^.registers32:=p^.right^.registers32;
  56. p^.registersfpu:=p^.right^.registersfpu;
  57. {$ifdef SUPPORT_MMX}
  58. p^.registersmmx:=p^.right^.registersmmx;
  59. {$endif}
  60. end;
  61. if defcoll=nil then
  62. begin
  63. old_array_constructor:=allow_array_constructor;
  64. allow_array_constructor:=true;
  65. if not(assigned(p^.resulttype)) or
  66. (p^.left^.treetype=typeconvn) then
  67. firstpass(p^.left);
  68. allow_array_constructor:=old_array_constructor;
  69. if codegenerror then
  70. begin
  71. dec(parsing_para_level);
  72. exit;
  73. end;
  74. p^.resulttype:=p^.left^.resulttype;
  75. end
  76. { if we know the routine which is called, then the type }
  77. { conversions are inserted }
  78. else
  79. begin
  80. if count_ref then
  81. begin
  82. store_valid:=must_be_valid;
  83. if (defcoll^.paratyp=vs_var) then
  84. test_protected(p^.left);
  85. if (defcoll^.paratyp<>vs_var) then
  86. must_be_valid:=true
  87. else
  88. must_be_valid:=false;
  89. { here we must add something for the implicit type }
  90. { conversion from array of char to pchar }
  91. { if isconvertable(p^.left^.resulttype,defcoll^.data,convtyp,
  92. p^.left^.treetype,false) then
  93. if convtyp=tc_array_to_pointer then
  94. must_be_valid:=false; }
  95. { only process typeconvn, else it will break other trees }
  96. old_array_constructor:=allow_array_constructor;
  97. allow_array_constructor:=true;
  98. if (p^.left^.treetype=typeconvn) then
  99. firstpass(p^.left);
  100. allow_array_constructor:=old_array_constructor;
  101. must_be_valid:=store_valid;
  102. end;
  103. if not(is_shortstring(p^.left^.resulttype) and
  104. is_shortstring(defcoll^.data)) and
  105. (defcoll^.data^.deftype<>formaldef) then
  106. begin
  107. if (defcoll^.paratyp=vs_var) and
  108. { allows conversion from word to integer and
  109. byte to shortint }
  110. (not(
  111. (p^.left^.resulttype^.deftype=orddef) and
  112. (defcoll^.data^.deftype=orddef) and
  113. (p^.left^.resulttype^.size=defcoll^.data^.size)
  114. ) and
  115. { an implicit pointer conversion is allowed }
  116. not(
  117. (p^.left^.resulttype^.deftype=pointerdef) and
  118. (defcoll^.data^.deftype=pointerdef)
  119. ) and
  120. { child classes can be also passed }
  121. not(
  122. (p^.left^.resulttype^.deftype=objectdef) and
  123. (defcoll^.data^.deftype=objectdef) and
  124. pobjectdef(p^.left^.resulttype)^.isrelated(pobjectdef(defcoll^.data))
  125. ) and
  126. { passing a single element to a openarray of the same type }
  127. not(
  128. (is_open_array(defcoll^.data) and
  129. is_equal(parraydef(defcoll^.data)^.definition,p^.left^.resulttype))
  130. ) and
  131. { an implicit file conversion is also allowed }
  132. { from a typed file to an untyped one }
  133. not(
  134. (p^.left^.resulttype^.deftype=filedef) and
  135. (defcoll^.data^.deftype=filedef) and
  136. (pfiledef(defcoll^.data)^.filetype = ft_untyped) and
  137. (pfiledef(p^.left^.resulttype)^.filetype = ft_typed)
  138. ) and
  139. not(is_equal(p^.left^.resulttype,defcoll^.data))) then
  140. CGMessage(parser_e_call_by_ref_without_typeconv);
  141. { process cargs arrayconstructor }
  142. if is_array_constructor(p^.left^.resulttype) and
  143. (aktcallprocsym^.definition^.options and pocdecl<>0) and
  144. (aktcallprocsym^.definition^.options and poexternal<>0) then
  145. begin
  146. p^.left^.cargs:=true;
  147. old_array_constructor:=allow_array_constructor;
  148. allow_array_constructor:=true;
  149. firstpass(p^.left);
  150. allow_array_constructor:=old_array_constructor;
  151. end;
  152. { don't generate an type conversion for open arrays and
  153. openstring, else we loss the ranges }
  154. if is_open_array(defcoll^.data) or
  155. is_open_string(defcoll^.data) then
  156. begin
  157. { insert type conv but hold the ranges of the array }
  158. oldtype:=p^.left^.resulttype;
  159. p^.left:=gentypeconvnode(p^.left,defcoll^.data);
  160. firstpass(p^.left);
  161. p^.left^.resulttype:=oldtype;
  162. end
  163. else
  164. begin
  165. p^.left:=gentypeconvnode(p^.left,defcoll^.data);
  166. firstpass(p^.left);
  167. end;
  168. if codegenerror then
  169. begin
  170. dec(parsing_para_level);
  171. exit;
  172. end;
  173. end;
  174. { check var strings }
  175. if (cs_strict_var_strings in aktlocalswitches) and
  176. is_shortstring(p^.left^.resulttype) and
  177. is_shortstring(defcoll^.data) and
  178. (defcoll^.paratyp=vs_var) and
  179. not(is_open_string(defcoll^.data)) 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. if make_ref then
  708. begin
  709. procs^.data^.lastref:=new(pref,init(procs^.data^.lastref,@p^.fileinfo));
  710. if procs^.data^.defref=nil then
  711. procs^.data^.defref:=procs^.data^.lastref;
  712. end;
  713. p^.procdefinition:=procs^.data;
  714. p^.resulttype:=procs^.data^.retdef;
  715. { big error for with statements
  716. p^.symtableproc:=p^.procdefinition^.owner;
  717. but neede for overloaded operators !! }
  718. if p^.symtableproc=nil then
  719. p^.symtableproc:=p^.procdefinition^.owner;
  720. p^.location.loc:=LOC_MEM;
  721. {$ifdef CHAINPROCSYMS}
  722. { object with method read;
  723. call to read(x) will be a usual procedure call }
  724. if assigned(p^.methodpointer) and
  725. (p^.procdefinition^._class=nil) then
  726. begin
  727. { not ok for extended }
  728. case p^.methodpointer^.treetype of
  729. typen,hnewn : fatalerror(no_para_match);
  730. end;
  731. disposetree(p^.methodpointer);
  732. p^.methodpointer:=nil;
  733. end;
  734. {$endif CHAINPROCSYMS}
  735. end; { end of procedure to call determination }
  736. is_const:=((p^.procdefinition^.options and pointernconst)<>0) and
  737. ((block_type=bt_const) or
  738. (assigned(p^.left) and (p^.left^.left^.treetype in [realconstn,ordconstn])));
  739. { handle predefined procedures }
  740. if ((p^.procdefinition^.options and pointernproc)<>0) or is_const then
  741. begin
  742. if assigned(p^.left) then
  743. begin
  744. { settextbuf needs two args }
  745. if assigned(p^.left^.right) then
  746. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left)
  747. else
  748. begin
  749. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left^.left);
  750. putnode(p^.left);
  751. end;
  752. end
  753. else
  754. begin
  755. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,nil);
  756. end;
  757. putnode(p);
  758. firstpass(pt);
  759. p:=pt;
  760. must_be_valid:=store_valid;
  761. if codegenerror then
  762. exit;
  763. dispose(procs);
  764. exit;
  765. end
  766. else
  767. { no intern procedure => we do a call }
  768. { calc the correture value for the register }
  769. { handle predefined procedures }
  770. if (p^.procdefinition^.options and poinline)<>0 then
  771. begin
  772. if assigned(p^.methodpointer) then
  773. CGMessage(cg_e_unable_inline_object_methods);
  774. if assigned(p^.right) and (p^.right^.treetype<>procinlinen) then
  775. CGMessage(cg_e_unable_inline_procvar);
  776. { p^.treetype:=procinlinen; }
  777. if not assigned(p^.right) then
  778. begin
  779. if assigned(p^.procdefinition^.code) then
  780. inlinecode:=genprocinlinenode(p,ptree(p^.procdefinition^.code))
  781. else
  782. CGMessage(cg_e_no_code_for_inline_stored);
  783. if assigned(inlinecode) then
  784. begin
  785. { consider it has not inlined if called
  786. again inside the args }
  787. p^.procdefinition^.options:=p^.procdefinition^.options and (not poinline);
  788. firstpass(inlinecode);
  789. inlined:=true;
  790. end;
  791. end;
  792. end
  793. else
  794. procinfo.flags:=procinfo.flags or pi_do_call;
  795. { work trough all parameters to insert the type conversions }
  796. { !!! done now after internproc !! (PM) }
  797. if assigned(p^.left) then
  798. begin
  799. old_count_ref:=count_ref;
  800. count_ref:=true;
  801. firstcallparan(p^.left,p^.procdefinition^.para1);
  802. count_ref:=old_count_ref;
  803. end;
  804. {$ifdef i386}
  805. for regi:=R_EAX to R_EDI do
  806. begin
  807. if (p^.procdefinition^.usedregisters and ($80 shr word(regi)))<>0 then
  808. inc(reg_pushes[regi],t_times*2);
  809. end;
  810. {$endif}
  811. {$ifdef m68k}
  812. for regi:=R_D0 to R_A6 do
  813. begin
  814. if (p^.procdefinition^.usedregisters and ($800 shr word(regi)))<>0 then
  815. inc(reg_pushes[regi],t_times*2);
  816. end;
  817. {$endif}
  818. end;
  819. { ensure that the result type is set }
  820. p^.resulttype:=p^.procdefinition^.retdef;
  821. { get a register for the return value }
  822. if (p^.resulttype<>pdef(voiddef)) then
  823. begin
  824. if (p^.procdefinition^.options and poconstructor)<>0 then
  825. begin
  826. { extra handling of classes }
  827. { p^.methodpointer should be assigned! }
  828. if assigned(p^.methodpointer) and assigned(p^.methodpointer^.resulttype) and
  829. (p^.methodpointer^.resulttype^.deftype=classrefdef) then
  830. begin
  831. p^.location.loc:=LOC_REGISTER;
  832. p^.registers32:=1;
  833. { the result type depends on the classref }
  834. p^.resulttype:=pclassrefdef(p^.methodpointer^.resulttype)^.definition;
  835. end
  836. { a object constructor returns the result with the flags }
  837. else
  838. p^.location.loc:=LOC_FLAGS;
  839. end
  840. else
  841. begin
  842. {$ifdef SUPPORT_MMX}
  843. if (cs_mmx in aktlocalswitches) and
  844. is_mmx_able_array(p^.resulttype) then
  845. begin
  846. p^.location.loc:=LOC_MMXREGISTER;
  847. p^.registersmmx:=1;
  848. end
  849. else
  850. {$endif SUPPORT_MMX}
  851. if ret_in_acc(p^.resulttype) then
  852. begin
  853. p^.location.loc:=LOC_REGISTER;
  854. if is_64bitint(p^.resulttype) then
  855. p^.registers32:=2
  856. else
  857. p^.registers32:=1;
  858. end
  859. else if (p^.resulttype^.deftype=floatdef) then
  860. begin
  861. p^.location.loc:=LOC_FPU;
  862. p^.registersfpu:=1;
  863. end
  864. end;
  865. end;
  866. { a fpu can be used in any procedure !! }
  867. p^.registersfpu:=p^.procdefinition^.fpu_used;
  868. { if this is a call to a method calc the registers }
  869. if (p^.methodpointer<>nil) then
  870. begin
  871. case p^.methodpointer^.treetype of
  872. { but only, if this is not a supporting node }
  873. typen,hnewn : ;
  874. else
  875. begin
  876. { if ((p^.procdefinition^.options and (poconstructor or podestructor)) <> 0) and
  877. (assigned(p^.symtable) and (p^.symtable^.symtabletype=withsymtable) then
  878. begin
  879. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  880. end; Is accpeted by Delphi !! }
  881. { R.Assign is not a constructor !!! }
  882. { but for R^.Assign, R must be valid !! }
  883. if ((p^.procdefinition^.options and poconstructor) <> 0) or
  884. ((p^.methodpointer^.treetype=loadn) and
  885. ((pobjectdef(p^.methodpointer^.resulttype)^.options and oo_hasvirtual) = 0)) then
  886. must_be_valid:=false
  887. else
  888. must_be_valid:=true;
  889. firstpass(p^.methodpointer);
  890. p^.registersfpu:=max(p^.methodpointer^.registersfpu,p^.registersfpu);
  891. p^.registers32:=max(p^.methodpointer^.registers32,p^.registers32);
  892. {$ifdef SUPPORT_MMX}
  893. p^.registersmmx:=max(p^.methodpointer^.registersmmx,p^.registersmmx);
  894. {$endif SUPPORT_MMX}
  895. end;
  896. end;
  897. end;
  898. if inlined then
  899. begin
  900. p^.right:=inlinecode;
  901. p^.procdefinition^.options:=p^.procdefinition^.options or poinline;
  902. end;
  903. { determine the registers of the procedure variable }
  904. { is this OK for inlined procs also ?? (PM) }
  905. if assigned(p^.right) then
  906. begin
  907. p^.registersfpu:=max(p^.right^.registersfpu,p^.registersfpu);
  908. p^.registers32:=max(p^.right^.registers32,p^.registers32);
  909. {$ifdef SUPPORT_MMX}
  910. p^.registersmmx:=max(p^.right^.registersmmx,p^.registersmmx);
  911. {$endif SUPPORT_MMX}
  912. end;
  913. { determine the registers of the procedure }
  914. if assigned(p^.left) then
  915. begin
  916. p^.registersfpu:=max(p^.left^.registersfpu,p^.registersfpu);
  917. p^.registers32:=max(p^.left^.registers32,p^.registers32);
  918. {$ifdef SUPPORT_MMX}
  919. p^.registersmmx:=max(p^.left^.registersmmx,p^.registersmmx);
  920. {$endif SUPPORT_MMX}
  921. end;
  922. if assigned(procs) then
  923. dispose(procs);
  924. aktcallprocsym:=oldcallprocsym;
  925. must_be_valid:=store_valid;
  926. end;
  927. {*****************************************************************************
  928. FirstProcInlineN
  929. *****************************************************************************}
  930. procedure firstprocinline(var p : ptree);
  931. begin
  932. { left contains the code in tree form }
  933. { but it has already been firstpassed }
  934. { so firstpass(p^.left); does not seem required }
  935. { might be required later if we change the arg handling !! }
  936. end;
  937. end.
  938. {
  939. $Log$
  940. Revision 1.18 1999-01-12 14:25:40 peter
  941. + BrowserLog for browser.log generation
  942. + BrowserCol for browser info in TCollections
  943. * released all other UseBrowser
  944. Revision 1.17 1998/12/11 00:03:52 peter
  945. + globtype,tokens,version unit splitted from globals
  946. Revision 1.16 1998/12/10 14:57:52 pierre
  947. * fix for operators
  948. Revision 1.15 1998/12/10 09:47:32 florian
  949. + basic operations with int64/qord (compiler with -dint64)
  950. + rtti of enumerations extended: names are now written
  951. Revision 1.14 1998/11/27 14:50:52 peter
  952. + open strings, $P switch support
  953. Revision 1.13 1998/11/24 17:03:51 peter
  954. * fixed exactmatch removings
  955. Revision 1.12 1998/11/16 10:18:10 peter
  956. * fixes for ansistrings
  957. Revision 1.11 1998/11/10 10:09:17 peter
  958. * va_list -> array of const
  959. Revision 1.10 1998/11/09 11:44:41 peter
  960. + va_list for printf support
  961. Revision 1.9 1998/10/28 18:26:22 pierre
  962. * removed some erros after other errors (introduced by useexcept)
  963. * stabs works again correctly (for how long !)
  964. Revision 1.8 1998/10/09 16:36:09 pierre
  965. * some memory leaks specific to usebrowser define fixed
  966. * removed tmodule.implsymtable (was like tmodule.localsymtable)
  967. Revision 1.7 1998/10/06 20:49:09 peter
  968. * m68k compiler compiles again
  969. Revision 1.6 1998/10/02 09:24:22 peter
  970. * more constant expression evaluators
  971. Revision 1.5 1998/09/28 11:22:17 pierre
  972. * did not compile for browser
  973. * merge from fixes
  974. Revision 1.4 1998/09/27 10:16:24 florian
  975. * type casts pchar<->ansistring fixed
  976. * ansistring[..] calls does now an unique call
  977. Revision 1.3 1998/09/24 14:27:40 peter
  978. * some better support for openarray
  979. Revision 1.2 1998/09/24 09:02:16 peter
  980. * rewritten isconvertable to use case
  981. * array of .. and single variable are compatible
  982. Revision 1.1 1998/09/23 20:42:24 peter
  983. * splitted pass_1
  984. }