ncal.pas 62 KB

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