tccal.pas 58 KB

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