tccal.pas 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. {$ifdef FPC}
  19. {$goto on}
  20. {$endif FPC}
  21. unit tccal;
  22. interface
  23. uses
  24. symtable,tree;
  25. procedure gen_high_tree(p:ptree;openstring:boolean);
  26. procedure firstcallparan(var p : ptree;defcoll : pparaitem;do_count : boolean);
  27. procedure firstcalln(var p : ptree);
  28. procedure firstprocinline(var p : ptree);
  29. implementation
  30. uses
  31. globtype,systems,
  32. cobjects,verbose,globals,
  33. symconst,aasm,types,
  34. htypechk,pass_1,cpubase
  35. {$ifdef newcg}
  36. ,cgbase
  37. ,tgobj
  38. {$else newcg}
  39. ,hcodegen
  40. {$ifdef i386}
  41. ,tgeni386
  42. {$endif}
  43. {$ifdef m68k}
  44. ,tgen68k
  45. {$endif m68k}
  46. {$endif newcg}
  47. ;
  48. {*****************************************************************************
  49. FirstCallParaN
  50. *****************************************************************************}
  51. procedure gen_high_tree(p:ptree;openstring:boolean);
  52. var
  53. len : longint;
  54. st : psymtable;
  55. loadconst : boolean;
  56. begin
  57. if assigned(p^.hightree) then
  58. exit;
  59. len:=-1;
  60. loadconst:=true;
  61. case p^.left^.resulttype^.deftype of
  62. arraydef :
  63. begin
  64. if is_open_array(p^.left^.resulttype) or
  65. is_array_of_const(p^.left^.resulttype) then
  66. begin
  67. st:=p^.left^.symtable;
  68. getsymonlyin(st,'high'+pvarsym(p^.left^.symtableentry)^.name);
  69. p^.hightree:=genloadnode(pvarsym(srsym),st);
  70. loadconst:=false;
  71. end
  72. else
  73. begin
  74. { this is an empty constructor }
  75. len:=parraydef(p^.left^.resulttype)^.highrange-
  76. parraydef(p^.left^.resulttype)^.lowrange;
  77. end;
  78. end;
  79. stringdef :
  80. begin
  81. if openstring then
  82. begin
  83. if is_open_string(p^.left^.resulttype) then
  84. begin
  85. st:=p^.left^.symtable;
  86. getsymonlyin(st,'high'+pvarsym(p^.left^.symtableentry)^.name);
  87. p^.hightree:=genloadnode(pvarsym(srsym),st);
  88. loadconst:=false;
  89. end
  90. else
  91. len:=pstringdef(p^.left^.resulttype)^.len;
  92. end
  93. else
  94. { passing a string to an array of char }
  95. begin
  96. if (p^.left^.treetype=stringconstn) then
  97. begin
  98. len:=str_length(p^.left);
  99. if len>0 then
  100. dec(len);
  101. end
  102. else
  103. begin
  104. p^.hightree:=gennode(subn,geninlinenode(in_length_string,false,getcopy(p^.left)),
  105. genordinalconstnode(1,s32bitdef));
  106. firstpass(p^.hightree);
  107. p^.hightree:=gentypeconvnode(p^.hightree,s32bitdef);
  108. loadconst:=false;
  109. end;
  110. end;
  111. end;
  112. else
  113. len:=0;
  114. end;
  115. if loadconst then
  116. p^.hightree:=genordinalconstnode(len,s32bitdef);
  117. firstpass(p^.hightree);
  118. end;
  119. procedure firstcallparan(var p : ptree;defcoll : pparaitem;do_count : boolean);
  120. var
  121. old_get_para_resulttype : boolean;
  122. old_array_constructor : boolean;
  123. oldtype : pdef;
  124. {$ifdef extdebug}
  125. store_count_ref : boolean;
  126. {$endif def extdebug}
  127. {convtyp : tconverttype;}
  128. begin
  129. inc(parsing_para_level);
  130. {$ifdef extdebug}
  131. if do_count then
  132. begin
  133. store_count_ref:=count_ref;
  134. count_ref:=true;
  135. end;
  136. {$endif def extdebug}
  137. if assigned(p^.right) then
  138. begin
  139. if defcoll=nil then
  140. firstcallparan(p^.right,nil,do_count)
  141. else
  142. firstcallparan(p^.right,pparaitem(defcoll^.next),do_count);
  143. p^.registers32:=p^.right^.registers32;
  144. p^.registersfpu:=p^.right^.registersfpu;
  145. {$ifdef SUPPORT_MMX}
  146. p^.registersmmx:=p^.right^.registersmmx;
  147. {$endif}
  148. end;
  149. if defcoll=nil then
  150. begin
  151. old_array_constructor:=allow_array_constructor;
  152. old_get_para_resulttype:=get_para_resulttype;
  153. get_para_resulttype:=true;
  154. allow_array_constructor:=true;
  155. firstpass(p^.left);
  156. get_para_resulttype:=old_get_para_resulttype;
  157. allow_array_constructor:=old_array_constructor;
  158. if codegenerror then
  159. begin
  160. dec(parsing_para_level);
  161. exit;
  162. end;
  163. p^.resulttype:=p^.left^.resulttype;
  164. end
  165. { if we know the routine which is called, then the type }
  166. { conversions are inserted }
  167. else
  168. begin
  169. { Do we need arrayconstructor -> set conversion, then insert
  170. it here before the arrayconstructor node breaks the tree
  171. with its conversions of enum->ord }
  172. if (p^.left^.treetype=arrayconstructn) and
  173. (defcoll^.paratype.def^.deftype=setdef) then
  174. p^.left:=gentypeconvnode(p^.left,defcoll^.paratype.def);
  175. { set some settings needed for arrayconstructor }
  176. if is_array_constructor(p^.left^.resulttype) then
  177. begin
  178. if is_array_of_const(defcoll^.paratype.def) then
  179. begin
  180. if assigned(aktcallprocsym) and
  181. (pocall_cdecl in aktcallprocsym^.definition^.proccalloptions) and
  182. (po_external in aktcallprocsym^.definition^.procoptions) then
  183. p^.left^.cargs:=true;
  184. { force variant array }
  185. p^.left^.forcevaria:=true;
  186. end
  187. else
  188. begin
  189. p^.left^.novariaallowed:=true;
  190. p^.left^.constructdef:=parraydef(defcoll^.paratype.def)^.elementtype.def;
  191. end;
  192. end;
  193. if do_count then
  194. begin
  195. { not completly proper, but avoids some warnings }
  196. if (defcoll^.paratyp=vs_var) then
  197. set_funcret_is_valid(p^.left);
  198. { protected has nothing to do with read/write
  199. if (defcoll^.paratyp=vs_var) then
  200. test_protected(p^.left);
  201. }
  202. { set_varstate(p^.left,defcoll^.paratyp<>vs_var);
  203. must only be done after typeconv PM }
  204. { only process typeconvn and arrayconstructn, else it will
  205. break other trees }
  206. { But this is need to get correct varstate !! PM }
  207. old_array_constructor:=allow_array_constructor;
  208. old_get_para_resulttype:=get_para_resulttype;
  209. allow_array_constructor:=true;
  210. get_para_resulttype:=false;
  211. if (p^.left^.treetype in [arrayconstructn,typeconvn]) then
  212. firstpass(p^.left);
  213. if not assigned(p^.resulttype) then
  214. p^.resulttype:=p^.left^.resulttype;
  215. get_para_resulttype:=old_get_para_resulttype;
  216. allow_array_constructor:=old_array_constructor;
  217. end;
  218. { check if local proc/func is assigned to procvar }
  219. if p^.left^.resulttype^.deftype=procvardef then
  220. test_local_to_procvar(pprocvardef(p^.left^.resulttype),defcoll^.paratype.def);
  221. { property is not allowed as var parameter }
  222. if (defcoll^.paratyp in [vs_out,vs_var]) and
  223. (p^.left^.isproperty) then
  224. CGMessagePos(p^.left^.fileinfo,type_e_argument_cant_be_assigned);
  225. { generate the high() value tree }
  226. if push_high_param(defcoll^.paratype.def) then
  227. gen_high_tree(p,is_open_string(defcoll^.paratype.def));
  228. if not(is_shortstring(p^.left^.resulttype) and
  229. is_shortstring(defcoll^.paratype.def)) and
  230. (defcoll^.paratype.def^.deftype<>formaldef) then
  231. begin
  232. if (defcoll^.paratyp in [vs_var,vs_out]) and
  233. { allows conversion from word to integer and
  234. byte to shortint }
  235. (not(
  236. (p^.left^.resulttype^.deftype=orddef) and
  237. (defcoll^.paratype.def^.deftype=orddef) and
  238. (p^.left^.resulttype^.size=defcoll^.paratype.def^.size)
  239. ) and
  240. { an implicit pointer conversion is allowed }
  241. not(
  242. (p^.left^.resulttype^.deftype=pointerdef) and
  243. (defcoll^.paratype.def^.deftype=pointerdef)
  244. ) and
  245. { child classes can be also passed }
  246. not(
  247. (p^.left^.resulttype^.deftype=objectdef) and
  248. (defcoll^.paratype.def^.deftype=objectdef) and
  249. pobjectdef(p^.left^.resulttype)^.is_related(pobjectdef(defcoll^.paratype.def))
  250. ) and
  251. { passing a single element to a openarray of the same type }
  252. not(
  253. (is_open_array(defcoll^.paratype.def) and
  254. is_equal(parraydef(defcoll^.paratype.def)^.elementtype.def,p^.left^.resulttype))
  255. ) and
  256. { an implicit file conversion is also allowed }
  257. { from a typed file to an untyped one }
  258. not(
  259. (p^.left^.resulttype^.deftype=filedef) and
  260. (defcoll^.paratype.def^.deftype=filedef) and
  261. (pfiledef(defcoll^.paratype.def)^.filetyp = ft_untyped) and
  262. (pfiledef(p^.left^.resulttype)^.filetyp = ft_typed)
  263. ) and
  264. not(is_equal(p^.left^.resulttype,defcoll^.paratype.def))) then
  265. begin
  266. CGMessagePos2(p^.left^.fileinfo,parser_e_call_by_ref_without_typeconv,
  267. p^.left^.resulttype^.typename,defcoll^.paratype.def^.typename);
  268. end;
  269. { Process open parameters }
  270. if push_high_param(defcoll^.paratype.def) then
  271. begin
  272. { insert type conv but hold the ranges of the array }
  273. oldtype:=p^.left^.resulttype;
  274. p^.left:=gentypeconvnode(p^.left,defcoll^.paratype.def);
  275. firstpass(p^.left);
  276. p^.left^.resulttype:=oldtype;
  277. end
  278. else
  279. begin
  280. p^.left:=gentypeconvnode(p^.left,defcoll^.paratype.def);
  281. firstpass(p^.left);
  282. end;
  283. if codegenerror then
  284. begin
  285. dec(parsing_para_level);
  286. exit;
  287. end;
  288. end;
  289. { check var strings }
  290. if (cs_strict_var_strings in aktlocalswitches) and
  291. is_shortstring(p^.left^.resulttype) and
  292. is_shortstring(defcoll^.paratype.def) and
  293. (defcoll^.paratyp in [vs_out,vs_var]) and
  294. not(is_open_string(defcoll^.paratype.def)) and
  295. not(is_equal(p^.left^.resulttype,defcoll^.paratype.def)) then
  296. begin
  297. aktfilepos:=p^.left^.fileinfo;
  298. CGMessage(type_e_strict_var_string_violation);
  299. end;
  300. { Variablen for call by reference may not be copied }
  301. { into a register }
  302. { is this usefull here ? }
  303. { this was missing in formal parameter list }
  304. if (defcoll^.paratype.def=pdef(cformaldef)) then
  305. begin
  306. if defcoll^.paratyp=vs_var then
  307. begin
  308. if not valid_for_formal_var(p^.left) then
  309. begin
  310. aktfilepos:=p^.left^.fileinfo;
  311. CGMessage(parser_e_illegal_parameter_list);
  312. end;
  313. end;
  314. if defcoll^.paratyp=vs_const then
  315. begin
  316. if not valid_for_formal_const(p^.left) then
  317. begin
  318. aktfilepos:=p^.left^.fileinfo;
  319. CGMessage(parser_e_illegal_parameter_list);
  320. end;
  321. end;
  322. end;
  323. if defcoll^.paratyp in [vs_var,vs_const] then
  324. begin
  325. { Causes problems with const ansistrings if also }
  326. { done for vs_const (JM) }
  327. if defcoll^.paratyp = vs_var then
  328. set_unique(p^.left);
  329. make_not_regable(p^.left);
  330. end;
  331. { ansistrings out paramaters doesn't need to be }
  332. { unique, they are finalized }
  333. if defcoll^.paratyp=vs_out then
  334. make_not_regable(p^.left);
  335. if do_count then
  336. set_varstate(p^.left,defcoll^.paratyp <> vs_var);
  337. { must only be done after typeconv PM }
  338. p^.resulttype:=defcoll^.paratype.def;
  339. end;
  340. if p^.left^.registers32>p^.registers32 then
  341. p^.registers32:=p^.left^.registers32;
  342. if p^.left^.registersfpu>p^.registersfpu then
  343. p^.registersfpu:=p^.left^.registersfpu;
  344. {$ifdef SUPPORT_MMX}
  345. if p^.left^.registersmmx>p^.registersmmx then
  346. p^.registersmmx:=p^.left^.registersmmx;
  347. {$endif SUPPORT_MMX}
  348. dec(parsing_para_level);
  349. {$ifdef extdebug}
  350. if do_count then
  351. count_ref:=store_count_ref;
  352. {$endif def extdebug}
  353. end;
  354. {*****************************************************************************
  355. FirstCallN
  356. *****************************************************************************}
  357. procedure firstcalln(var p : ptree);
  358. type
  359. pprocdefcoll = ^tprocdefcoll;
  360. tprocdefcoll = record
  361. data : pprocdef;
  362. nextpara : pparaitem;
  363. firstpara : pparaitem;
  364. next : pprocdefcoll;
  365. end;
  366. var
  367. hp,procs,hp2 : pprocdefcoll;
  368. pd : pprocdef;
  369. oldcallprocsym : pprocsym;
  370. def_from,def_to,conv_to : pdef;
  371. hpt,pt,inlinecode : ptree;
  372. exactmatch,inlined : boolean;
  373. paralength,lastpara : longint;
  374. lastparatype : pdef;
  375. pdc : pparaitem;
  376. {$ifdef TEST_PROCSYMS}
  377. nextprocsym : pprocsym;
  378. symt : psymtable;
  379. {$endif TEST_PROCSYMS}
  380. { only Dummy }
  381. hcvt : tconverttype;
  382. {$ifdef m68k}
  383. regi : tregister;
  384. {$endif}
  385. method_must_be_valid : boolean;
  386. label
  387. errorexit;
  388. { check if the resulttype from tree p is equal with def, needed
  389. for stringconstn and formaldef }
  390. function is_equal(p:ptree;def:pdef) : boolean;
  391. begin
  392. { safety check }
  393. if not (assigned(def) or assigned(p^.resulttype)) then
  394. begin
  395. is_equal:=false;
  396. exit;
  397. end;
  398. { all types can be passed to a formaldef }
  399. is_equal:=(def^.deftype=formaldef) or
  400. (types.is_equal(p^.resulttype,def))
  401. { integer constants are compatible with all integer parameters if
  402. the specified value matches the range }
  403. or
  404. (
  405. (p^.left^.treetype=ordconstn) and
  406. is_integer(p^.resulttype) and
  407. is_integer(def) and
  408. (p^.left^.value>=porddef(def)^.low) and
  409. (p^.left^.value<=porddef(def)^.high)
  410. )
  411. { to support ansi/long/wide strings in a proper way }
  412. { string and string[10] are assumed as equal }
  413. { when searching the correct overloaded procedure }
  414. or
  415. (
  416. (def^.deftype=stringdef) and (p^.resulttype^.deftype=stringdef) and
  417. (pstringdef(def)^.string_typ=pstringdef(p^.resulttype)^.string_typ)
  418. )
  419. or
  420. (
  421. (p^.left^.treetype=stringconstn) and
  422. (is_ansistring(p^.resulttype) and is_pchar(def))
  423. )
  424. or
  425. (
  426. (p^.left^.treetype=ordconstn) and
  427. (is_char(p^.resulttype) and (is_shortstring(def) or is_ansistring(def)))
  428. )
  429. { set can also be a not yet converted array constructor }
  430. or
  431. (
  432. (def^.deftype=setdef) and (p^.resulttype^.deftype=arraydef) and
  433. (parraydef(p^.resulttype)^.IsConstructor) and not(parraydef(p^.resulttype)^.IsVariant)
  434. )
  435. { in tp7 mode proc -> procvar is allowed }
  436. or
  437. (
  438. (m_tp_procvar in aktmodeswitches) and
  439. (def^.deftype=procvardef) and (p^.left^.treetype=calln) and
  440. (proc_to_procvar_equal(pprocdef(p^.left^.procdefinition),pprocvardef(def)))
  441. )
  442. ;
  443. end;
  444. function is_in_limit(def_from,def_to : pdef) : boolean;
  445. begin
  446. is_in_limit:=(def_from^.deftype = orddef) and
  447. (def_to^.deftype = orddef) and
  448. (porddef(def_from)^.low>porddef(def_to)^.low) and
  449. (porddef(def_from)^.high<porddef(def_to)^.high);
  450. end;
  451. var
  452. is_const : boolean;
  453. i : longint;
  454. bestord : porddef;
  455. begin
  456. { release registers! }
  457. { if procdefinition<>nil then we called firstpass already }
  458. { it seems to be bad because of the registers }
  459. { at least we can avoid the overloaded search !! }
  460. procs:=nil;
  461. { made this global for disposing !! }
  462. oldcallprocsym:=aktcallprocsym;
  463. aktcallprocsym:=nil;
  464. inlined:=false;
  465. if assigned(p^.procdefinition) and
  466. (pocall_inline in p^.procdefinition^.proccalloptions) then
  467. begin
  468. inlinecode:=p^.right;
  469. if assigned(inlinecode) then
  470. begin
  471. inlined:=true;
  472. exclude(p^.procdefinition^.proccalloptions,pocall_inline);
  473. end;
  474. p^.right:=nil;
  475. end;
  476. if assigned(p^.procdefinition) and
  477. (po_containsself in p^.procdefinition^.procoptions) then
  478. message(cg_e_cannot_call_message_direct);
  479. { procedure variable ? }
  480. if assigned(p^.right) then
  481. begin
  482. { procedure does a call }
  483. procinfo^.flags:=procinfo^.flags or pi_do_call;
  484. {$ifndef newcg}
  485. { calc the correture value for the register }
  486. {$ifdef i386}
  487. incrementregisterpushed($ff);
  488. {$endif}
  489. {$ifdef m68k}
  490. for regi:=R_D0 to R_A6 do
  491. inc(reg_pushes[regi],t_times*2);
  492. {$endif}
  493. {$endif newcg}
  494. { calculate the type of the parameters }
  495. if assigned(p^.left) then
  496. begin
  497. firstcallparan(p^.left,nil,false);
  498. if codegenerror then
  499. goto errorexit;
  500. end;
  501. firstpass(p^.right);
  502. set_varstate(p^.right,true);
  503. { check the parameters }
  504. pdc:=pparaitem(pprocvardef(p^.right^.resulttype)^.para^.first);
  505. pt:=p^.left;
  506. while assigned(pdc) and assigned(pt) do
  507. begin
  508. pt:=pt^.right;
  509. pdc:=pparaitem(pdc^.next);
  510. end;
  511. if assigned(pt) or assigned(pdc) then
  512. begin
  513. if assigned(pt) then
  514. aktfilepos:=pt^.fileinfo;
  515. CGMessage(parser_e_illegal_parameter_list);
  516. end;
  517. { insert type conversions }
  518. if assigned(p^.left) then
  519. begin
  520. firstcallparan(p^.left,pparaitem(pprocvardef(p^.right^.resulttype)^.para^.first),true);
  521. if codegenerror then
  522. goto errorexit;
  523. end;
  524. p^.resulttype:=pprocvardef(p^.right^.resulttype)^.rettype.def;
  525. { this was missing, leads to a bug below if
  526. the procvar is a function }
  527. p^.procdefinition:=pabstractprocdef(p^.right^.resulttype);
  528. end
  529. else
  530. { not a procedure variable }
  531. begin
  532. { determine the type of the parameters }
  533. if assigned(p^.left) then
  534. begin
  535. firstcallparan(p^.left,nil,false);
  536. if codegenerror then
  537. goto errorexit;
  538. end;
  539. aktcallprocsym:=pprocsym(p^.symtableprocentry);
  540. { do we know the procedure to call ? }
  541. if not(assigned(p^.procdefinition)) then
  542. begin
  543. {$ifdef TEST_PROCSYMS}
  544. if (p^.unit_specific) or
  545. assigned(p^.methodpointer) then
  546. nextprocsym:=nil
  547. else while not assigned(procs) do
  548. begin
  549. symt:=p^.symtableproc;
  550. srsym:=nil;
  551. while assigned(symt^.next) and not assigned(srsym) do
  552. begin
  553. symt:=symt^.next;
  554. getsymonlyin(symt,actprocsym^.name);
  555. if assigned(srsym) then
  556. if srsym^.typ<>procsym then
  557. begin
  558. { reject all that is not a procedure }
  559. srsym:=nil;
  560. { don't search elsewhere }
  561. while assigned(symt^.next) do
  562. symt:=symt^.next;
  563. end;
  564. end;
  565. nextprocsym:=srsym;
  566. end;
  567. {$endif TEST_PROCSYMS}
  568. { determine length of parameter list }
  569. pt:=p^.left;
  570. paralength:=0;
  571. while assigned(pt) do
  572. begin
  573. inc(paralength);
  574. pt:=pt^.right;
  575. end;
  576. { link all procedures which have the same # of parameters }
  577. pd:=aktcallprocsym^.definition;
  578. while assigned(pd) do
  579. begin
  580. { only when the # of parameter are supported by the
  581. procedure }
  582. if (paralength>=pd^.minparacount) and (paralength<=pd^.maxparacount) then
  583. begin
  584. new(hp);
  585. hp^.data:=pd;
  586. hp^.next:=procs;
  587. hp^.firstpara:=pparaitem(pd^.para^.first);
  588. { if not all parameters are given, then skip the
  589. default parameters }
  590. for i:=1 to pd^.maxparacount-paralength do
  591. hp^.firstpara:=pparaitem(hp^.firstpara^.next);
  592. hp^.nextpara:=hp^.firstpara;
  593. procs:=hp;
  594. end;
  595. pd:=pd^.nextoverloaded;
  596. end;
  597. { no procedures found? then there is something wrong
  598. with the parameter size }
  599. if not assigned(procs) then
  600. begin
  601. { in tp mode we can try to convert to procvar if
  602. there are no parameters specified }
  603. if not(assigned(p^.left)) and
  604. (m_tp_procvar in aktmodeswitches) then
  605. begin
  606. if (p^.symtableprocentry^.owner^.symtabletype=objectsymtable) and
  607. (pobjectdef(p^.symtableprocentry^.owner^.defowner)^.is_class) then
  608. hpt:=genloadmethodcallnode(pprocsym(p^.symtableprocentry),p^.symtableproc,
  609. getcopy(p^.methodpointer))
  610. else
  611. hpt:=genloadcallnode(pprocsym(p^.symtableprocentry),p^.symtableproc);
  612. disposetree(p);
  613. firstpass(hpt);
  614. p:=hpt;
  615. end
  616. else
  617. begin
  618. if assigned(p^.left) then
  619. aktfilepos:=p^.left^.fileinfo;
  620. CGMessage(parser_e_wrong_parameter_size);
  621. aktcallprocsym^.write_parameter_lists(nil);
  622. end;
  623. goto errorexit;
  624. end;
  625. { now we can compare parameter after parameter }
  626. pt:=p^.left;
  627. { we start with the last parameter }
  628. lastpara:=paralength+1;
  629. lastparatype:=nil;
  630. while assigned(pt) do
  631. begin
  632. dec(lastpara);
  633. { walk all procedures and determine how this parameter matches and set:
  634. 1. pt^.exact_match_found if one parameter has an exact match
  635. 2. exactmatch if an equal or exact match is found
  636. 3. para^.argconvtyp to exact,equal or convertable
  637. (when convertable then also convertlevel is set)
  638. 4. pt^.convlevel1found if there is a convertlevel=1
  639. 5. pt^.convlevel2found if there is a convertlevel=2
  640. }
  641. exactmatch:=false;
  642. hp:=procs;
  643. while assigned(hp) do
  644. begin
  645. if is_equal(pt,hp^.nextpara^.paratype.def) then
  646. begin
  647. if hp^.nextpara^.paratype.def=pt^.resulttype then
  648. begin
  649. pt^.exact_match_found:=true;
  650. hp^.nextpara^.argconvtyp:=act_exact;
  651. end
  652. else
  653. hp^.nextpara^.argconvtyp:=act_equal;
  654. exactmatch:=true;
  655. end
  656. else
  657. begin
  658. hp^.nextpara^.argconvtyp:=act_convertable;
  659. hp^.nextpara^.convertlevel:=isconvertable(pt^.resulttype,hp^.nextpara^.paratype.def,
  660. hcvt,pt^.left^.treetype,false);
  661. case hp^.nextpara^.convertlevel of
  662. 1 : pt^.convlevel1found:=true;
  663. 2 : pt^.convlevel2found:=true;
  664. end;
  665. end;
  666. hp:=hp^.next;
  667. end;
  668. { If there was an exactmatch then delete all convertables }
  669. if exactmatch then
  670. begin
  671. hp:=procs;
  672. procs:=nil;
  673. while assigned(hp) do
  674. begin
  675. hp2:=hp^.next;
  676. { keep if not convertable }
  677. if (hp^.nextpara^.argconvtyp<>act_convertable) then
  678. begin
  679. hp^.next:=procs;
  680. procs:=hp;
  681. end
  682. else
  683. dispose(hp);
  684. hp:=hp2;
  685. end;
  686. end
  687. else
  688. { No exact match was found, remove all procedures that are
  689. not convertable (convertlevel=0) }
  690. begin
  691. hp:=procs;
  692. procs:=nil;
  693. while assigned(hp) do
  694. begin
  695. hp2:=hp^.next;
  696. { keep if not convertable }
  697. if (hp^.nextpara^.convertlevel<>0) then
  698. begin
  699. hp^.next:=procs;
  700. procs:=hp;
  701. end
  702. else
  703. begin
  704. { save the type for nice error message }
  705. lastparatype:=hp^.nextpara^.paratype.def;
  706. dispose(hp);
  707. end;
  708. hp:=hp2;
  709. end;
  710. end;
  711. { update nextpara for all procedures }
  712. hp:=procs;
  713. while assigned(hp) do
  714. begin
  715. hp^.nextpara:=pparaitem(hp^.nextpara^.next);
  716. hp:=hp^.next;
  717. end;
  718. { load next parameter or quit loop if no procs left }
  719. if assigned(procs) then
  720. pt:=pt^.right
  721. else
  722. break;
  723. end;
  724. { All parameters are checked, check if there are any
  725. procedures left }
  726. if not assigned(procs) then
  727. begin
  728. { there is an error, must be wrong type, because
  729. wrong size is already checked (PFV) }
  730. if (not assigned(lastparatype)) or
  731. (not assigned(pt)) or
  732. (not assigned(pt^.resulttype)) then
  733. internalerror(39393)
  734. else
  735. begin
  736. aktfilepos:=pt^.fileinfo;
  737. CGMessage3(type_e_wrong_parameter_type,tostr(lastpara),
  738. pt^.resulttype^.typename,lastparatype^.typename);
  739. end;
  740. aktcallprocsym^.write_parameter_lists(nil);
  741. goto errorexit;
  742. end;
  743. { if there are several choices left then for orddef }
  744. { if a type is totally included in the other }
  745. { we don't fear an overflow , }
  746. { so we can do as if it is an exact match }
  747. { this will convert integer to longint }
  748. { rather than to words }
  749. { conversion of byte to integer or longint }
  750. {would still not be solved }
  751. if assigned(procs) and assigned(procs^.next) then
  752. begin
  753. hp:=procs;
  754. while assigned(hp) do
  755. begin
  756. hp^.nextpara:=hp^.firstpara;
  757. hp:=hp^.next;
  758. end;
  759. pt:=p^.left;
  760. while assigned(pt) do
  761. begin
  762. { matches a parameter of one procedure exact ? }
  763. exactmatch:=false;
  764. def_from:=pt^.resulttype;
  765. hp:=procs;
  766. while assigned(hp) do
  767. begin
  768. if not is_equal(pt,hp^.nextpara^.paratype.def) then
  769. begin
  770. def_to:=hp^.nextpara^.paratype.def;
  771. if ((def_from^.deftype=orddef) and (def_to^.deftype=orddef)) and
  772. (is_in_limit(def_from,def_to) or
  773. ((hp^.nextpara^.paratyp in [vs_var,vs_out]) and
  774. (def_from^.size=def_to^.size))) then
  775. begin
  776. exactmatch:=true;
  777. conv_to:=def_to;
  778. end;
  779. end;
  780. hp:=hp^.next;
  781. end;
  782. { .... if yes, del all the other procedures }
  783. if exactmatch then
  784. begin
  785. { the first .... }
  786. while (assigned(procs)) and not(is_in_limit(def_from,procs^.nextpara^.paratype.def)) do
  787. begin
  788. hp:=procs^.next;
  789. dispose(procs);
  790. procs:=hp;
  791. end;
  792. { and the others }
  793. hp:=procs;
  794. while (assigned(hp)) and assigned(hp^.next) do
  795. begin
  796. if not(is_in_limit(def_from,hp^.next^.nextpara^.paratype.def)) then
  797. begin
  798. hp2:=hp^.next^.next;
  799. dispose(hp^.next);
  800. hp^.next:=hp2;
  801. end
  802. else
  803. begin
  804. def_to:=hp^.next^.nextpara^.paratype.def;
  805. if (conv_to^.size>def_to^.size) or
  806. ((porddef(conv_to)^.low<porddef(def_to)^.low) and
  807. (porddef(conv_to)^.high>porddef(def_to)^.high)) then
  808. begin
  809. hp2:=procs;
  810. procs:=hp;
  811. conv_to:=def_to;
  812. dispose(hp2);
  813. end
  814. else
  815. hp:=hp^.next;
  816. end;
  817. end;
  818. end;
  819. { update nextpara for all procedures }
  820. hp:=procs;
  821. while assigned(hp) do
  822. begin
  823. hp^.nextpara:=pparaitem(hp^.nextpara^.next);
  824. hp:=hp^.next;
  825. end;
  826. pt:=pt^.right;
  827. end;
  828. end;
  829. { let's try to eliminate equal if there is an exact match
  830. is there }
  831. if assigned(procs) and assigned(procs^.next) then
  832. begin
  833. { reset nextpara for all procs left }
  834. hp:=procs;
  835. while assigned(hp) do
  836. begin
  837. hp^.nextpara:=hp^.firstpara;
  838. hp:=hp^.next;
  839. end;
  840. pt:=p^.left;
  841. while assigned(pt) do
  842. begin
  843. if pt^.exact_match_found then
  844. begin
  845. hp:=procs;
  846. procs:=nil;
  847. while assigned(hp) do
  848. begin
  849. hp2:=hp^.next;
  850. { keep the exact matches, dispose the others }
  851. if (hp^.nextpara^.argconvtyp=act_exact) then
  852. begin
  853. hp^.next:=procs;
  854. procs:=hp;
  855. end
  856. else
  857. dispose(hp);
  858. hp:=hp2;
  859. end;
  860. end;
  861. { update nextpara for all procedures }
  862. hp:=procs;
  863. while assigned(hp) do
  864. begin
  865. hp^.nextpara:=pparaitem(hp^.nextpara^.next);
  866. hp:=hp^.next;
  867. end;
  868. pt:=pt^.right;
  869. end;
  870. end;
  871. { Check if there are integer constant to integer
  872. parameters then choose the best matching integer
  873. parameter and remove the others, this is Delphi
  874. compatible. 1 = byte, 256 = word, etc. }
  875. if assigned(procs) and assigned(procs^.next) then
  876. begin
  877. { reset nextpara for all procs left }
  878. hp:=procs;
  879. while assigned(hp) do
  880. begin
  881. hp^.nextpara:=hp^.firstpara;
  882. hp:=hp^.next;
  883. end;
  884. pt:=p^.left;
  885. while assigned(pt) do
  886. begin
  887. bestord:=nil;
  888. if (pt^.left^.treetype=ordconstn) and
  889. is_integer(pt^.resulttype) then
  890. begin
  891. hp:=procs;
  892. while assigned(hp) do
  893. begin
  894. def_to:=hp^.nextpara^.paratype.def;
  895. { to be sure, it couldn't be something else,
  896. also the defs here are all in the range
  897. so now find the closest range }
  898. if not is_integer(def_to) then
  899. internalerror(43297815);
  900. if (not assigned(bestord)) or
  901. ((porddef(def_to)^.low>bestord^.low) or
  902. (porddef(def_to)^.high<bestord^.high)) then
  903. bestord:=porddef(def_to);
  904. hp:=hp^.next;
  905. end;
  906. end;
  907. { if a bestmatch is found then remove the other
  908. procs which don't match the bestord }
  909. if assigned(bestord) then
  910. begin
  911. hp:=procs;
  912. procs:=nil;
  913. while assigned(hp) do
  914. begin
  915. hp2:=hp^.next;
  916. { keep matching bestord, dispose the others }
  917. if (porddef(hp^.nextpara^.paratype.def)=bestord) then
  918. begin
  919. hp^.next:=procs;
  920. procs:=hp;
  921. end
  922. else
  923. dispose(hp);
  924. hp:=hp2;
  925. end;
  926. end;
  927. { update nextpara for all procedures }
  928. hp:=procs;
  929. while assigned(hp) do
  930. begin
  931. hp^.nextpara:=pparaitem(hp^.nextpara^.next);
  932. hp:=hp^.next;
  933. end;
  934. pt:=pt^.right;
  935. end;
  936. end;
  937. { Check if there are convertlevel 1 and 2 differences
  938. left for the parameters, then discard all convertlevel
  939. 2 procedures. The value of convlevelXfound can still
  940. be used, because all convertables are still here or
  941. not }
  942. if assigned(procs) and assigned(procs^.next) then
  943. begin
  944. { reset nextpara for all procs left }
  945. hp:=procs;
  946. while assigned(hp) do
  947. begin
  948. hp^.nextpara:=hp^.firstpara;
  949. hp:=hp^.next;
  950. end;
  951. pt:=p^.left;
  952. while assigned(pt) do
  953. begin
  954. if pt^.convlevel1found and pt^.convlevel2found then
  955. begin
  956. hp:=procs;
  957. procs:=nil;
  958. while assigned(hp) do
  959. begin
  960. hp2:=hp^.next;
  961. { keep all not act_convertable and all convertlevels=1 }
  962. if (hp^.nextpara^.argconvtyp<>act_convertable) or
  963. (hp^.nextpara^.convertlevel=1) then
  964. begin
  965. hp^.next:=procs;
  966. procs:=hp;
  967. end
  968. else
  969. dispose(hp);
  970. hp:=hp2;
  971. end;
  972. end;
  973. { update nextpara for all procedures }
  974. hp:=procs;
  975. while assigned(hp) do
  976. begin
  977. hp^.nextpara:=pparaitem(hp^.nextpara^.next);
  978. hp:=hp^.next;
  979. end;
  980. pt:=pt^.right;
  981. end;
  982. end;
  983. if not(assigned(procs)) or assigned(procs^.next) then
  984. begin
  985. CGMessage(cg_e_cant_choose_overload_function);
  986. aktcallprocsym^.write_parameter_lists(nil);
  987. goto errorexit;
  988. end;
  989. {$ifdef TEST_PROCSYMS}
  990. if (procs=nil) and assigned(nextprocsym) then
  991. begin
  992. p^.symtableprocentry:=nextprocsym;
  993. p^.symtableproc:=symt;
  994. end;
  995. end ; { of while assigned(p^.symtableprocentry) do }
  996. {$endif TEST_PROCSYMS}
  997. if make_ref then
  998. begin
  999. procs^.data^.lastref:=new(pref,init(procs^.data^.lastref,@p^.fileinfo));
  1000. inc(procs^.data^.refcount);
  1001. if procs^.data^.defref=nil then
  1002. procs^.data^.defref:=procs^.data^.lastref;
  1003. end;
  1004. p^.procdefinition:=procs^.data;
  1005. p^.resulttype:=procs^.data^.rettype.def;
  1006. { big error for with statements
  1007. p^.symtableproc:=p^.procdefinition^.owner;
  1008. but neede for overloaded operators !! }
  1009. if p^.symtableproc=nil then
  1010. p^.symtableproc:=p^.procdefinition^.owner;
  1011. p^.location.loc:=LOC_MEM;
  1012. {$ifdef CHAINPROCSYMS}
  1013. { object with method read;
  1014. call to read(x) will be a usual procedure call }
  1015. if assigned(p^.methodpointer) and
  1016. (p^.procdefinition^._class=nil) then
  1017. begin
  1018. { not ok for extended }
  1019. case p^.methodpointer^.treetype of
  1020. typen,hnewn : fatalerror(no_para_match);
  1021. end;
  1022. disposetree(p^.methodpointer);
  1023. p^.methodpointer:=nil;
  1024. end;
  1025. {$endif CHAINPROCSYMS}
  1026. end; { end of procedure to call determination }
  1027. is_const:=(pocall_internconst in p^.procdefinition^.proccalloptions) and
  1028. ((block_type=bt_const) or
  1029. (assigned(p^.left) and (p^.left^.left^.treetype in [realconstn,ordconstn])));
  1030. { handle predefined procedures }
  1031. if (pocall_internproc in p^.procdefinition^.proccalloptions) or is_const then
  1032. begin
  1033. if assigned(p^.left) then
  1034. begin
  1035. { settextbuf needs two args }
  1036. if assigned(p^.left^.right) then
  1037. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left)
  1038. else
  1039. begin
  1040. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,p^.left^.left);
  1041. putnode(p^.left);
  1042. end;
  1043. end
  1044. else
  1045. begin
  1046. pt:=geninlinenode(pprocdef(p^.procdefinition)^.extnumber,is_const,nil);
  1047. end;
  1048. putnode(p);
  1049. firstpass(pt);
  1050. p:=pt;
  1051. goto errorexit;
  1052. end
  1053. else
  1054. { no intern procedure => we do a call }
  1055. { calc the correture value for the register }
  1056. { handle predefined procedures }
  1057. if (pocall_inline in p^.procdefinition^.proccalloptions) then
  1058. begin
  1059. if assigned(p^.methodpointer) then
  1060. CGMessage(cg_e_unable_inline_object_methods);
  1061. if assigned(p^.right) and (p^.right^.treetype<>procinlinen) then
  1062. CGMessage(cg_e_unable_inline_procvar);
  1063. { p^.treetype:=procinlinen; }
  1064. if not assigned(p^.right) then
  1065. begin
  1066. if assigned(pprocdef(p^.procdefinition)^.code) then
  1067. inlinecode:=genprocinlinenode(p,ptree(pprocdef(p^.procdefinition)^.code))
  1068. else
  1069. CGMessage(cg_e_no_code_for_inline_stored);
  1070. if assigned(inlinecode) then
  1071. begin
  1072. { consider it has not inlined if called
  1073. again inside the args }
  1074. exclude(p^.procdefinition^.proccalloptions,pocall_inline);
  1075. firstpass(inlinecode);
  1076. inlined:=true;
  1077. end;
  1078. end;
  1079. end
  1080. else
  1081. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1082. { add needed default parameters }
  1083. if assigned(procs) and
  1084. (paralength<p^.procdefinition^.maxparacount) then
  1085. begin
  1086. { add default parameters, just read back the skipped
  1087. paras starting from firstpara^.previous, when not available
  1088. (all parameters are default) then start with the last
  1089. parameter and read backward (PFV) }
  1090. if not assigned(procs^.firstpara) then
  1091. pdc:=pparaitem(procs^.data^.para^.last)
  1092. else
  1093. pdc:=pparaitem(procs^.firstpara^.previous);
  1094. while assigned(pdc) do
  1095. begin
  1096. if not assigned(pdc^.defaultvalue) then
  1097. internalerror(751349858);
  1098. p^.left:=gencallparanode(genconstsymtree(pconstsym(pdc^.defaultvalue)),p^.left);
  1099. pdc:=pparaitem(pdc^.previous);
  1100. end;
  1101. end;
  1102. { work trough all parameters to insert the type conversions }
  1103. if assigned(p^.left) then
  1104. begin
  1105. firstcallparan(p^.left,pparaitem(p^.procdefinition^.para^.first),true);
  1106. end;
  1107. {$ifndef newcg}
  1108. {$ifdef i386}
  1109. incrementregisterpushed(pprocdef(p^.procdefinition)^.usedregisters);
  1110. {$endif}
  1111. {$ifdef m68k}
  1112. for regi:=R_D0 to R_A6 do
  1113. begin
  1114. if (pprocdef(p^.procdefinition)^.usedregisters and ($800 shr word(regi)))<>0 then
  1115. inc(reg_pushes[regi],t_times*2);
  1116. end;
  1117. {$endif}
  1118. {$endif newcg}
  1119. end;
  1120. { ensure that the result type is set }
  1121. p^.resulttype:=p^.procdefinition^.rettype.def;
  1122. { get a register for the return value }
  1123. if (p^.resulttype<>pdef(voiddef)) then
  1124. begin
  1125. if (p^.procdefinition^.proctypeoption=potype_constructor) then
  1126. begin
  1127. { extra handling of classes }
  1128. { p^.methodpointer should be assigned! }
  1129. if assigned(p^.methodpointer) and assigned(p^.methodpointer^.resulttype) and
  1130. (p^.methodpointer^.resulttype^.deftype=classrefdef) then
  1131. begin
  1132. p^.location.loc:=LOC_REGISTER;
  1133. p^.registers32:=1;
  1134. { the result type depends on the classref }
  1135. p^.resulttype:=pclassrefdef(p^.methodpointer^.resulttype)^.pointertype.def;
  1136. end
  1137. { a object constructor returns the result with the flags }
  1138. else
  1139. p^.location.loc:=LOC_FLAGS;
  1140. end
  1141. else
  1142. begin
  1143. {$ifdef SUPPORT_MMX}
  1144. if (cs_mmx in aktlocalswitches) and
  1145. is_mmx_able_array(p^.resulttype) then
  1146. begin
  1147. p^.location.loc:=LOC_MMXREGISTER;
  1148. p^.registersmmx:=1;
  1149. end
  1150. else
  1151. {$endif SUPPORT_MMX}
  1152. if ret_in_acc(p^.resulttype) then
  1153. begin
  1154. p^.location.loc:=LOC_REGISTER;
  1155. if is_64bitint(p^.resulttype) then
  1156. p^.registers32:=2
  1157. else
  1158. p^.registers32:=1;
  1159. { wide- and ansistrings are returned in EAX }
  1160. { but they are imm. moved to a memory location }
  1161. if is_widestring(p^.resulttype) or
  1162. is_ansistring(p^.resulttype) then
  1163. begin
  1164. p^.location.loc:=LOC_MEM;
  1165. { this is wrong we still need one register PM
  1166. p^.registers32:=0; }
  1167. { we use ansistrings so no fast exit here }
  1168. procinfo^.no_fast_exit:=true;
  1169. p^.registers32:=1;
  1170. end;
  1171. end
  1172. else if (p^.resulttype^.deftype=floatdef) then
  1173. begin
  1174. p^.location.loc:=LOC_FPU;
  1175. p^.registersfpu:=1;
  1176. end
  1177. else
  1178. p^.location.loc:=LOC_MEM;
  1179. end;
  1180. end;
  1181. { a fpu can be used in any procedure !! }
  1182. p^.registersfpu:=p^.procdefinition^.fpu_used;
  1183. { if this is a call to a method calc the registers }
  1184. if (p^.methodpointer<>nil) then
  1185. begin
  1186. case p^.methodpointer^.treetype of
  1187. { but only, if this is not a supporting node }
  1188. typen: ;
  1189. { we need one register for new return value PM }
  1190. hnewn : if p^.registers32=0 then
  1191. p^.registers32:=1;
  1192. else
  1193. begin
  1194. if (p^.procdefinition^.proctypeoption in [potype_constructor,potype_destructor]) and
  1195. assigned(p^.symtable) and (p^.symtable^.symtabletype=withsymtable) and
  1196. not pwithsymtable(p^.symtable)^.direct_with then
  1197. begin
  1198. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1199. end; { Is accepted by Delphi !! }
  1200. { this is not a good reason to accept it in FPC if we produce
  1201. wrong code for it !!! (PM) }
  1202. { R.Assign is not a constructor !!! }
  1203. { but for R^.Assign, R must be valid !! }
  1204. if (p^.procdefinition^.proctypeoption=potype_constructor) or
  1205. ((p^.methodpointer^.treetype=loadn) and
  1206. (not(oo_has_virtual in pobjectdef(p^.methodpointer^.resulttype)^.objectoptions))) then
  1207. method_must_be_valid:=false
  1208. else
  1209. method_must_be_valid:=true;
  1210. firstpass(p^.methodpointer);
  1211. set_varstate(p^.methodpointer,method_must_be_valid);
  1212. { The object is already used ven if it is called once }
  1213. if (p^.methodpointer^.treetype=loadn) and
  1214. (p^.methodpointer^.symtableentry^.typ=varsym) then
  1215. pvarsym(p^.methodpointer^.symtableentry)^.varstate:=vs_used;
  1216. p^.registersfpu:=max(p^.methodpointer^.registersfpu,p^.registersfpu);
  1217. p^.registers32:=max(p^.methodpointer^.registers32,p^.registers32);
  1218. {$ifdef SUPPORT_MMX}
  1219. p^.registersmmx:=max(p^.methodpointer^.registersmmx,p^.registersmmx);
  1220. {$endif SUPPORT_MMX}
  1221. end;
  1222. end;
  1223. end;
  1224. if inlined then
  1225. p^.right:=inlinecode;
  1226. { determine the registers of the procedure variable }
  1227. { is this OK for inlined procs also ?? (PM) }
  1228. if assigned(p^.right) then
  1229. begin
  1230. p^.registersfpu:=max(p^.right^.registersfpu,p^.registersfpu);
  1231. p^.registers32:=max(p^.right^.registers32,p^.registers32);
  1232. {$ifdef SUPPORT_MMX}
  1233. p^.registersmmx:=max(p^.right^.registersmmx,p^.registersmmx);
  1234. {$endif SUPPORT_MMX}
  1235. end;
  1236. { determine the registers of the procedure }
  1237. if assigned(p^.left) then
  1238. begin
  1239. p^.registersfpu:=max(p^.left^.registersfpu,p^.registersfpu);
  1240. p^.registers32:=max(p^.left^.registers32,p^.registers32);
  1241. {$ifdef SUPPORT_MMX}
  1242. p^.registersmmx:=max(p^.left^.registersmmx,p^.registersmmx);
  1243. {$endif SUPPORT_MMX}
  1244. end;
  1245. errorexit:
  1246. { Reset some settings back }
  1247. if assigned(procs) then
  1248. dispose(procs);
  1249. if inlined then
  1250. include(p^.procdefinition^.proccalloptions,pocall_inline);
  1251. aktcallprocsym:=oldcallprocsym;
  1252. end;
  1253. {*****************************************************************************
  1254. FirstProcInlineN
  1255. *****************************************************************************}
  1256. procedure firstprocinline(var p : ptree);
  1257. begin
  1258. { left contains the code in tree form }
  1259. { but it has already been firstpassed }
  1260. { so firstpass(p^.left); does not seem required }
  1261. { might be required later if we change the arg handling !! }
  1262. end;
  1263. end.
  1264. {
  1265. $Log$
  1266. Revision 1.8 2000-08-15 03:43:24 peter
  1267. * integer constant -> integer para enhanced to search the best matching
  1268. procedure, just like delphi does (merged)
  1269. Revision 1.7 2000/08/13 14:53:32 peter
  1270. * integer constant is equal with all integer type arguments (merged)
  1271. Revision 1.6 2000/08/13 12:54:56 peter
  1272. * class member decl wrong then no other error after it
  1273. * -vb has now also line numbering
  1274. * -vb is also used for interface/implementation different decls and
  1275. doesn't list the current function (merged)
  1276. Revision 1.5 2000/08/08 19:23:28 peter
  1277. * crash fix for default para when all parameters were omitted
  1278. Revision 1.4 2000/08/06 19:39:28 peter
  1279. * default parameters working !
  1280. Revision 1.3 2000/07/13 12:08:28 michael
  1281. + patched to 1.1.0 with former 1.09patch from peter
  1282. Revision 1.2 2000/07/13 11:32:51 michael
  1283. + removed logs
  1284. }