ncal.pas 61 KB

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