ncal.pas 192 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603
  1. {
  2. This file implements the node for sub procedure calling.
  3. Copyright (c) 1998-2002 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 fpcdefs.inc}
  19. { $define DEBUGINLINE}
  20. interface
  21. uses
  22. cutils,cclasses,
  23. globtype,constexp,
  24. paramgr,parabase,cgbase,
  25. node,nbas,nutils,
  26. {$ifdef state_tracking}
  27. nstate,
  28. {$endif state_tracking}
  29. symbase,symtype,symsym,symdef,symtable;
  30. type
  31. tcallnodeflag = (
  32. cnf_typedefset,
  33. cnf_return_value_used,
  34. cnf_do_inline,
  35. cnf_inherited,
  36. cnf_anon_inherited,
  37. cnf_new_call,
  38. cnf_dispose_call,
  39. cnf_member_call, { called with implicit methodpointer tree }
  40. cnf_uses_varargs, { varargs are used in the declaration }
  41. cnf_create_failed, { exception thrown in constructor -> don't call beforedestruction }
  42. cnf_objc_processed, { the procedure name has been set to the appropriate objc_msgSend* variant -> don't process again }
  43. cnf_objc_id_call, { the procedure is a member call via id -> any ObjC method of any ObjC type in scope is fair game }
  44. cnf_unit_specified, { the unit in which the procedure has to be searched has been specified }
  45. cnf_call_never_returns { information for the dfa that a subroutine never returns }
  46. );
  47. tcallnodeflags = set of tcallnodeflag;
  48. tcallparanode = class;
  49. tcallnode = class(tbinarynode)
  50. private
  51. { number of parameters passed from the source, this does not include the hidden parameters }
  52. paralength : smallint;
  53. function is_simple_para_load(p:tnode; may_be_in_reg: boolean):boolean;
  54. procedure maybe_load_in_temp(var p:tnode);
  55. function gen_high_tree(var p:tnode;paradef:tdef):tnode;
  56. function gen_procvar_context_tree_self:tnode;
  57. function gen_procvar_context_tree_parentfp:tnode;
  58. function gen_self_tree:tnode;
  59. function gen_vmt_tree:tnode;
  60. function gen_block_context:tnode;
  61. procedure gen_hidden_parameters;
  62. function funcret_can_be_reused:boolean;
  63. procedure maybe_create_funcret_node;
  64. procedure bind_parasym;
  65. procedure add_init_statement(n:tnode);
  66. procedure add_done_statement(n:tnode);
  67. procedure convert_carg_array_of_const;
  68. procedure order_parameters;
  69. procedure check_inlining;
  70. function pass1_normal:tnode;
  71. procedure register_created_object_types;
  72. function get_expect_loc: tcgloc;
  73. protected
  74. procedure gen_syscall_para(para: tcallparanode); virtual;
  75. procedure objc_convert_to_message_send;virtual;
  76. protected
  77. { inlining support }
  78. inlinelocals : TFPObjectList;
  79. inlineinitstatement,
  80. inlinecleanupstatement : tstatementnode;
  81. procedure createinlineparas;
  82. procedure wrapcomplexinlinepara(para: tcallparanode); virtual;
  83. function replaceparaload(var n: tnode; arg: pointer): foreachnoderesult;
  84. procedure createlocaltemps(p:TObject;arg:pointer);
  85. function optimize_funcret_assignment(inlineblock: tblocknode): tnode;
  86. function pass1_inline:tnode;
  87. protected
  88. pushedparasize : longint;
  89. { Objective-C support: force the call node to call the routine with
  90. this name rather than the name of symtableprocentry (don't store
  91. to ppu, is set while processing the node). Also used on the JVM
  92. target for calling virtual methods, as this is name-based and not
  93. based on VMT entry locations }
  94. {$ifdef symansistr}
  95. fforcedprocname: TSymStr;
  96. {$else symansistr}
  97. fforcedprocname: pshortstring;
  98. {$endif symansistr}
  99. public
  100. { the symbol containing the definition of the procedure }
  101. { to call }
  102. symtableprocentry : tprocsym;
  103. symtableprocentryderef : tderef;
  104. { symtable where the entry was found, needed for with support }
  105. symtableproc : TSymtable;
  106. { the definition of the procedure to call }
  107. procdefinition : tabstractprocdef;
  108. procdefinitionderef : tderef;
  109. { tree that contains the pointer to the object for this method }
  110. methodpointer : tnode;
  111. { tree that contains the self/vmt parameter when this node was created
  112. (so it's still valid when this node is processed in an inline
  113. context)
  114. }
  115. call_self_node,
  116. call_vmt_node: tnode;
  117. { initialize/finalization of temps }
  118. callinitblock,
  119. callcleanupblock : tblocknode;
  120. { function return node for initialized types or supplied return variable.
  121. When the result is passed in a parameter then it is set to nil }
  122. funcretnode : tnode;
  123. { varargs parasyms }
  124. varargsparas : tvarargsparalist;
  125. { separately specified resultdef for some compilerprocs (e.g. }
  126. { you can't have a function with an "array of char" resultdef }
  127. { the RTL) (JM) }
  128. typedef: tdef;
  129. callnodeflags : tcallnodeflags;
  130. { only the processor specific nodes need to override this }
  131. { constructor }
  132. constructor create(l:tnode; v : tprocsym;st : TSymtable; mp: tnode; callflags:tcallnodeflags);virtual;
  133. constructor create_procvar(l,r:tnode);
  134. constructor createintern(const name: string; params: tnode);
  135. constructor createinternfromunit(const fromunit, procname: string; params: tnode);
  136. constructor createinternres(const name: string; params: tnode; res:tdef);
  137. constructor createinternresfromunit(const fromunit, procname: string; params: tnode; res:tdef);
  138. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  139. constructor createinternmethod(mp: tnode; const name: string; params: tnode);
  140. constructor createinternmethodres(mp: tnode; const name: string; params: tnode; res:tdef);
  141. destructor destroy;override;
  142. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  143. procedure ppuwrite(ppufile:tcompilerppufile);override;
  144. procedure buildderefimpl;override;
  145. procedure derefimpl;override;
  146. function dogetcopy : tnode;override;
  147. { Goes through all symbols in a class and subclasses and calls
  148. verify abstract for each .
  149. }
  150. procedure verifyabstractcalls;
  151. { called for each definition in a class and verifies if a method
  152. is abstract or not, if it is abstract, give out a warning
  153. }
  154. procedure verifyabstract(sym:TObject;arg:pointer);
  155. procedure insertintolist(l : tnodelist);override;
  156. function pass_1 : tnode;override;
  157. function pass_typecheck:tnode;override;
  158. {$ifdef state_tracking}
  159. function track_state_pass(exec_known:boolean):boolean;override;
  160. {$endif state_tracking}
  161. function docompare(p: tnode): boolean; override;
  162. procedure printnodedata(var t:text);override;
  163. function para_count:longint;
  164. function required_para_count:longint;
  165. { checks if there are any parameters which end up at the stack, i.e.
  166. which have LOC_REFERENCE and set pi_has_stackparameter if this applies }
  167. procedure check_stack_parameters;
  168. { force the name of the to-be-called routine to a particular string,
  169. used for Objective-C message sending. }
  170. property parameters : tnode read left write left;
  171. property pushed_parasize: longint read pushedparasize;
  172. private
  173. AbstractMethodsList : TFPHashList;
  174. end;
  175. tcallnodeclass = class of tcallnode;
  176. tcallparaflag = (
  177. cpf_is_colon_para,
  178. cpf_varargs_para { belongs this para to varargs }
  179. );
  180. tcallparaflags = set of tcallparaflag;
  181. tcallparanode = class(ttertiarynode)
  182. private
  183. fcontains_stack_tainting_call_cached,
  184. ffollowed_by_stack_tainting_call_cached : boolean;
  185. protected
  186. { in case of copy-out parameters: initialization code, and the code to
  187. copy back the parameter value after the call (including any required
  188. finalization code }
  189. fparainit,
  190. fparacopyback: tnode;
  191. procedure handlemanagedbyrefpara(orgparadef: tdef);virtual;abstract;
  192. { on some targets, value parameters that are passed by reference must
  193. be copied to a temp location by the caller (and then a reference to
  194. this temp location must be passed) }
  195. procedure copy_value_by_ref_para;
  196. public
  197. callparaflags : tcallparaflags;
  198. parasym : tparavarsym;
  199. { only the processor specific nodes need to override this }
  200. { constructor }
  201. constructor create(expr,next : tnode);virtual;
  202. destructor destroy;override;
  203. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  204. procedure ppuwrite(ppufile:tcompilerppufile);override;
  205. procedure buildderefimpl; override;
  206. procedure derefimpl; override;
  207. function dogetcopy : tnode;override;
  208. procedure insertintolist(l : tnodelist);override;
  209. function pass_typecheck : tnode;override;
  210. function pass_1 : tnode;override;
  211. procedure get_paratype;
  212. procedure firstcallparan;
  213. procedure insert_typeconv;
  214. procedure secondcallparan;virtual;abstract;
  215. function docompare(p: tnode): boolean; override;
  216. procedure printnodetree(var t:text);override;
  217. { returns whether a parameter contains a type conversion from }
  218. { a refcounted into a non-refcounted type }
  219. function can_be_inlined: boolean;
  220. property paravalue : tnode read left write left;
  221. property nextpara : tnode read right write right;
  222. { third is reused to store the parameter name (only while parsing
  223. vardispatch calls, never in real node tree) and copy of 'high'
  224. parameter tree when the parameter is an open array of managed type }
  225. property parametername : tnode read third write third;
  226. { returns whether the evaluation of this parameter involves a
  227. stack tainting call }
  228. function contains_stack_tainting_call: boolean;
  229. { initialises the fcontains_stack_tainting_call_cached field with the
  230. result of contains_stack_tainting_call so that it can be quickly
  231. accessed via the contains_stack_tainting_call_cached property }
  232. procedure init_contains_stack_tainting_call_cache;
  233. { returns result of contains_stack_tainting_call cached during last
  234. call to init_contains_stack_tainting_call_cache }
  235. property contains_stack_tainting_call_cached: boolean read fcontains_stack_tainting_call_cached;
  236. { returns whether this parameter is followed by at least one other
  237. parameter whose evaluation involves a stack tainting parameter
  238. (result is only valid after order_parameters has been called) }
  239. property followed_by_stack_tainting_call_cached: boolean read ffollowed_by_stack_tainting_call_cached;
  240. property paracopyback: tnode read fparacopyback;
  241. end;
  242. tcallparanodeclass = class of tcallparanode;
  243. tdispcalltype = (
  244. dct_method,
  245. dct_propget,
  246. dct_propput
  247. );
  248. function reverseparameters(p: tcallparanode): tcallparanode;
  249. function translate_disp_call(selfnode,parametersnode: tnode; calltype: tdispcalltype; const methodname : ansistring;
  250. dispid : longint;resultdef : tdef) : tnode;
  251. var
  252. ccallnode : tcallnodeclass = tcallnode;
  253. ccallparanode : tcallparanodeclass = tcallparanode;
  254. { Current callnode, this is needed for having a link
  255. between the callparanodes and the callnode they belong to }
  256. aktcallnode : tcallnode;
  257. const
  258. { track current inlining depth }
  259. inlinelevel : longint = 0;
  260. implementation
  261. uses
  262. systems,
  263. verbose,globals,
  264. symconst,defutil,defcmp,
  265. htypechk,pass_1,
  266. ncnv,nld,ninl,nadd,ncon,nmem,nset,nobjc,
  267. ngenutil,objcutil,
  268. procinfo,cpuinfo,
  269. wpobase;
  270. type
  271. tobjectinfoitem = class(tlinkedlistitem)
  272. objinfo : tobjectdef;
  273. constructor create(def : tobjectdef);
  274. end;
  275. {****************************************************************************
  276. HELPERS
  277. ****************************************************************************}
  278. function reverseparameters(p: tcallparanode): tcallparanode;
  279. var
  280. hp1, hp2: tcallparanode;
  281. begin
  282. hp1:=nil;
  283. while assigned(p) do
  284. begin
  285. { pull out }
  286. hp2:=p;
  287. p:=tcallparanode(p.right);
  288. { pull in }
  289. hp2.right:=hp1;
  290. hp1:=hp2;
  291. end;
  292. reverseparameters:=hp1;
  293. end;
  294. function translate_disp_call(selfnode,parametersnode: tnode; calltype: tdispcalltype; const methodname : ansistring;
  295. dispid : longint;resultdef : tdef) : tnode;
  296. const
  297. DISPATCH_METHOD = $1;
  298. DISPATCH_PROPERTYGET = $2;
  299. DISPATCH_PROPERTYPUT = $4;
  300. DISPATCH_PROPERTYPUTREF = $8;
  301. DISPATCH_CONSTRUCT = $4000;
  302. calltypes: array[tdispcalltype] of byte = (
  303. DISPATCH_METHOD, DISPATCH_PROPERTYGET, DISPATCH_PROPERTYPUT
  304. );
  305. var
  306. statements : tstatementnode;
  307. result_data,
  308. params : ttempcreatenode;
  309. paramssize : cardinal;
  310. calldescnode : tdataconstnode;
  311. resultvalue : tnode;
  312. para : tcallparanode;
  313. namedparacount,
  314. paracount : longint;
  315. assignmenttype,
  316. vardatadef,
  317. pvardatadef : tdef;
  318. useresult: boolean;
  319. restype: byte;
  320. selftemp: ttempcreatenode;
  321. selfpara: tnode;
  322. names : ansistring;
  323. variantdispatch : boolean;
  324. function is_byref_para(out assign_type: tdef): boolean;
  325. begin
  326. result:=(assigned(para.parasym) and (para.parasym.varspez in [vs_var,vs_out,vs_constref])) or
  327. (variantdispatch and valid_for_var(para.left,false));
  328. if result or (para.left.resultdef.typ in [variantdef]) then
  329. assign_type:=voidpointertype
  330. else
  331. case para.left.resultdef.size of
  332. 1..4:
  333. assign_type:=u32inttype;
  334. 8:
  335. assign_type:=u64inttype;
  336. else
  337. internalerror(2007042801);
  338. end;
  339. end;
  340. function getvardef(sourcedef: TDef): longint;
  341. begin
  342. if is_ansistring(sourcedef) then
  343. result:=varStrArg
  344. else
  345. if is_unicodestring(sourcedef) then
  346. result:=varUStrArg
  347. else
  348. if is_interfacecom_or_dispinterface(sourcedef) then
  349. begin
  350. { distinct IDispatch and IUnknown interfaces }
  351. if def_is_related(tobjectdef(sourcedef),interface_idispatch) then
  352. result:=vardispatch
  353. else
  354. result:=varunknown;
  355. end
  356. else
  357. result:=sourcedef.getvardef;
  358. end;
  359. begin
  360. variantdispatch:=selfnode.resultdef.typ=variantdef;
  361. result:=internalstatements(statements);
  362. result_data:=nil;
  363. selftemp:=nil;
  364. selfpara:=nil;
  365. useresult := assigned(resultdef) and not is_void(resultdef);
  366. if useresult then
  367. begin
  368. { get temp for the result }
  369. result_data:=ctempcreatenode.create(colevarianttype,colevarianttype.size,tt_persistent,true);
  370. addstatement(statements,result_data);
  371. end;
  372. { first, count and check parameters }
  373. para:=tcallparanode(parametersnode);
  374. paracount:=0;
  375. namedparacount:=0;
  376. while assigned(para) do
  377. begin
  378. typecheckpass(para.left);
  379. { skip hidden dispinterface parameters like $self, $result,
  380. but count skipped variantdispatch parameters. }
  381. if (not variantdispatch) and (para.left.nodetype=nothingn) then
  382. begin
  383. para:=tcallparanode(para.nextpara);
  384. continue;
  385. end;
  386. inc(paracount);
  387. if assigned(para.parametername) then
  388. inc(namedparacount);
  389. { insert some extra casts }
  390. if para.left.nodetype=stringconstn then
  391. inserttypeconv_internal(para.left,cwidestringtype)
  392. { force automatable boolean type }
  393. else if is_boolean(para.left.resultdef) then
  394. inserttypeconv_internal(para.left,bool16type)
  395. { force automatable float type }
  396. else if is_extended(para.left.resultdef)
  397. and (current_settings.fputype<>fpu_none) then
  398. inserttypeconv_internal(para.left,s64floattype)
  399. else if is_shortstring(para.left.resultdef) then
  400. inserttypeconv_internal(para.left,cwidestringtype)
  401. { skip this check if we've already typecasted to automatable type }
  402. else if (para.left.nodetype<>nothingn) and (not is_automatable(para.left.resultdef)) then
  403. CGMessagePos1(para.left.fileinfo,type_e_not_automatable,para.left.resultdef.typename);
  404. para:=tcallparanode(para.nextpara);
  405. end;
  406. { create a temp to store parameter values }
  407. params:=ctempcreatenode.create(cformaltype,0,tt_persistent,false);
  408. addstatement(statements,params);
  409. calldescnode:=cdataconstnode.create;
  410. if not variantdispatch then { generate a tdispdesc record }
  411. begin
  412. { dispid }
  413. calldescnode.append(dispid,sizeof(dispid));
  414. { restype }
  415. if useresult then
  416. restype:=getvardef(resultdef)
  417. else
  418. restype:=0;
  419. calldescnode.appendbyte(restype);
  420. end;
  421. calldescnode.appendbyte(calltypes[calltype]);
  422. calldescnode.appendbyte(paracount);
  423. calldescnode.appendbyte(namedparacount);
  424. { build up parameters and description }
  425. para:=tcallparanode(parametersnode);
  426. paramssize:=0;
  427. names := '';
  428. while assigned(para) do
  429. begin
  430. { Skipped parameters are actually (varType=varError, vError=DISP_E_PARAMNOTFOUND).
  431. Generate only varType here, the value will be added by RTL. }
  432. if para.left.nodetype=nothingn then
  433. begin
  434. if variantdispatch then
  435. calldescnode.appendbyte(varError);
  436. para:=tcallparanode(para.nextpara);
  437. continue;
  438. end;
  439. if assigned(para.parametername) then
  440. begin
  441. if para.parametername.nodetype=stringconstn then
  442. names:=names+tstringconstnode(para.parametername).value_str+#0
  443. else
  444. internalerror(200611041);
  445. end;
  446. restype:=getvardef(para.left.resultdef);
  447. if is_byref_para(assignmenttype) then
  448. restype:=restype or $80;
  449. { assign the argument/parameter to the temporary location }
  450. { for Variants, we always pass a pointer, RTL helpers must handle it
  451. depending on byref bit }
  452. if assignmenttype=voidpointertype then
  453. addstatement(statements,cassignmentnode.create(
  454. ctypeconvnode.create_internal(ctemprefnode.create_offset(params,paramssize),
  455. voidpointertype),
  456. ctypeconvnode.create_internal(caddrnode.create_internal(para.left),voidpointertype)))
  457. else
  458. addstatement(statements,cassignmentnode.create(
  459. ctypeconvnode.create_internal(ctemprefnode.create_offset(params,paramssize),
  460. assignmenttype),
  461. ctypeconvnode.create_internal(para.left,assignmenttype)));
  462. inc(paramssize,max(voidpointertype.size,assignmenttype.size));
  463. calldescnode.appendbyte(restype);
  464. para.left:=nil;
  465. para:=tcallparanode(para.nextpara);
  466. end;
  467. { Set final size for parameter block }
  468. params.size:=paramssize;
  469. { old argument list skeleton isn't needed anymore }
  470. parametersnode.free;
  471. pvardatadef:=tpointerdef(search_system_type('PVARDATA').typedef);
  472. if useresult then
  473. resultvalue:=caddrnode.create(ctemprefnode.create(result_data))
  474. else
  475. resultvalue:=cpointerconstnode.create(0,voidpointertype);
  476. if variantdispatch then
  477. begin
  478. calldescnode.append(pointer(methodname)^,length(methodname));
  479. calldescnode.appendbyte(0);
  480. calldescnode.append(pointer(names)^,length(names));
  481. { actual call }
  482. vardatadef:=trecorddef(search_system_type('TVARDATA').typedef);
  483. { the Variant should behave similar to hidden 'self' parameter of objects/records,
  484. see issues #26773 and #27044 }
  485. if not valid_for_var(selfnode,false) then
  486. begin
  487. selftemp:=ctempcreatenode.create(selfnode.resultdef,selfnode.resultdef.size,tt_persistent,false);
  488. addstatement(statements,selftemp);
  489. addstatement(statements,cassignmentnode.create(ctemprefnode.create(selftemp),selfnode));
  490. selfpara:=ctemprefnode.create(selftemp);
  491. end
  492. else
  493. selfpara:=selfnode;
  494. addstatement(statements,ccallnode.createintern('fpc_dispinvoke_variant',
  495. { parameters are passed always reverted, i.e. the last comes first }
  496. ccallparanode.create(caddrnode.create(ctemprefnode.create(params)),
  497. ccallparanode.create(caddrnode.create(calldescnode),
  498. ccallparanode.create(ctypeconvnode.create_internal(selfpara,vardatadef),
  499. ccallparanode.create(ctypeconvnode.create_internal(resultvalue,pvardatadef),nil)))))
  500. );
  501. if assigned(selftemp) then
  502. addstatement(statements,ctempdeletenode.create(selftemp));
  503. end
  504. else
  505. begin
  506. addstatement(statements,ccallnode.createintern('fpc_dispatch_by_id',
  507. { parameters are passed always reverted, i.e. the last comes first }
  508. ccallparanode.create(caddrnode.create(ctemprefnode.create(params)),
  509. ccallparanode.create(caddrnode.create(calldescnode),
  510. ccallparanode.create(ctypeconvnode.create_internal(selfnode,voidpointertype),
  511. ccallparanode.create(ctypeconvnode.create_internal(resultvalue,pvardatadef),nil)))))
  512. );
  513. end;
  514. addstatement(statements,ctempdeletenode.create(params));
  515. if useresult then
  516. begin
  517. { clean up }
  518. addstatement(statements,ctempdeletenode.create_normal_temp(result_data));
  519. addstatement(statements,ctemprefnode.create(result_data));
  520. end;
  521. end;
  522. {****************************************************************************
  523. TOBJECTINFOITEM
  524. ****************************************************************************}
  525. constructor tobjectinfoitem.create(def : tobjectdef);
  526. begin
  527. inherited create;
  528. objinfo := def;
  529. end;
  530. {****************************************************************************
  531. TCALLPARANODE
  532. ****************************************************************************}
  533. procedure tcallparanode.copy_value_by_ref_para;
  534. var
  535. initstat,
  536. copybackstat,
  537. finistat: tstatementnode;
  538. finiblock: tblocknode;
  539. paratemp: ttempcreatenode;
  540. arraysize,
  541. arraybegin: tnode;
  542. lefttemp: ttempcreatenode;
  543. vardatatype,
  544. temparraydef: tdef;
  545. begin
  546. { this routine is for targets where by-reference value parameters need
  547. to be copied by the caller. It's basically the node-level equivalent
  548. of thlcgobj.g_copyvalueparas }
  549. { in case of an array constructor, we don't need a copy since the array
  550. constructor itself is already constructed on the fly (and hence if
  551. it's modified by the caller, that's no problem) }
  552. if not is_array_constructor(left.resultdef) then
  553. begin
  554. fparainit:=internalstatements(initstat);
  555. fparacopyback:=internalstatements(copybackstat);
  556. finiblock:=internalstatements(finistat);
  557. paratemp:=nil;
  558. { making a copy of an open array, an array of const or a dynamic
  559. array requires dynamic memory allocation since we don't know the
  560. size at compile time }
  561. if is_open_array(left.resultdef) or
  562. is_array_of_const(left.resultdef) or
  563. (is_dynamic_array(left.resultdef) and
  564. is_open_array(parasym.vardef)) then
  565. begin
  566. paratemp:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  567. if is_dynamic_array(left.resultdef) then
  568. begin
  569. { note that in insert_typeconv, this dynamic array was
  570. already converted into an open array (-> dereferenced)
  571. and then its resultdef was restored to the original
  572. dynamic array one -> get the address before treating it
  573. as a dynamic array here }
  574. { first restore the actual resultdef of left }
  575. temparraydef:=left.resultdef;
  576. left.resultdef:=parasym.vardef;
  577. { get its address }
  578. lefttemp:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  579. addstatement(initstat,lefttemp);
  580. addstatement(finistat,ctempdeletenode.create(lefttemp));
  581. addstatement(initstat,
  582. cassignmentnode.create(
  583. ctemprefnode.create(lefttemp),
  584. caddrnode.create_internal(left)
  585. )
  586. );
  587. { restore the resultdef }
  588. left.resultdef:=temparraydef;
  589. { now treat that address (correctly) as the original
  590. dynamic array to get its start and length }
  591. arraybegin:=cvecnode.create(
  592. ctypeconvnode.create_explicit(ctemprefnode.create(lefttemp),
  593. left.resultdef),
  594. genintconstnode(0)
  595. );
  596. arraysize:=caddnode.create(muln,
  597. geninlinenode(in_length_x,false,
  598. ctypeconvnode.create_explicit(ctemprefnode.create(lefttemp),
  599. left.resultdef)
  600. ),
  601. genintconstnode(tarraydef(left.resultdef).elementdef.size)
  602. );
  603. end
  604. else
  605. begin
  606. { no problem here that left is used multiple times, as
  607. sizeof() will simply evaluate to the high parameter }
  608. arraybegin:=left.getcopy;
  609. arraysize:=geninlinenode(in_sizeof_x,false,left);
  610. end;
  611. addstatement(initstat,paratemp);
  612. { paratemp:=getmem(sizeof(para)) }
  613. addstatement(initstat,
  614. cassignmentnode.create(
  615. ctemprefnode.create(paratemp),
  616. ccallnode.createintern('fpc_getmem',
  617. ccallparanode.create(
  618. arraysize.getcopy,nil
  619. )
  620. )
  621. )
  622. );
  623. { move(para,temp,sizeof(arr)) (no "left.getcopy" below because
  624. we replace left afterwards) }
  625. addstatement(initstat,
  626. ccallnode.createintern('MOVE',
  627. ccallparanode.create(
  628. arraysize,
  629. ccallparanode.create(
  630. cderefnode.create(ctemprefnode.create(paratemp)),
  631. ccallparanode.create(
  632. arraybegin,nil
  633. )
  634. )
  635. )
  636. )
  637. );
  638. { no reference count increases, that's still done on the callee
  639. side because for compatibility with targets that perform this
  640. copy on the callee side, that should only be done for non-
  641. assember functions (and we can't know that 100% certain here,
  642. e.g. in case of external declarations) (*) }
  643. { free the memory again after the call: freemem(paratemp) }
  644. addstatement(finistat,
  645. ccallnode.createintern('fpc_freemem',
  646. ccallparanode.create(
  647. ctemprefnode.create(paratemp),nil
  648. )
  649. )
  650. );
  651. { replace the original parameter with a dereference of the
  652. temp typecasted to the same type as the original parameter
  653. (don't free left, it has been reused above) }
  654. left:=ctypeconvnode.create_internal(
  655. cderefnode.create(ctemprefnode.create(paratemp)),
  656. left.resultdef);
  657. end
  658. else if is_shortstring(parasym.vardef) then
  659. begin
  660. { the shortstring parameter may have a different size than the
  661. parameter type -> assign and truncate/extend }
  662. paratemp:=ctempcreatenode.create(parasym.vardef,parasym.vardef.size,tt_persistent,false);
  663. addstatement(initstat,paratemp);
  664. { assign shortstring }
  665. addstatement(initstat,
  666. cassignmentnode.create(
  667. ctemprefnode.create(paratemp),left
  668. )
  669. );
  670. { replace parameter with temp (don't free left, it has been
  671. reused above) }
  672. left:=ctemprefnode.create(paratemp);
  673. end
  674. else if parasym.vardef.typ=variantdef then
  675. begin
  676. vardatatype:=search_system_type('TVARDATA').typedef;
  677. paratemp:=ctempcreatenode.create(vardatatype,vardatatype.size,tt_persistent,false);
  678. addstatement(initstat,paratemp);
  679. addstatement(initstat,
  680. ccallnode.createintern('fpc_variant_copy_overwrite',
  681. ccallparanode.create(
  682. ctypeconvnode.create_explicit(ctemprefnode.create(paratemp),
  683. vardatatype
  684. ),
  685. ccallparanode.create(ctypeconvnode.create_explicit(left,
  686. vardatatype),
  687. nil
  688. )
  689. )
  690. )
  691. );
  692. { replace parameter with temp (don't free left, it has been
  693. reused above) }
  694. left:=ctypeconvnode.create_explicit(ctemprefnode.create(paratemp),parasym.vardef);
  695. end
  696. else if is_managed_type(left.resultdef) then
  697. begin
  698. { don't increase/decrease the reference count here, will be done by
  699. the callee (see (*) above) -> typecast to array of byte
  700. for the assignment to the temp }
  701. temparraydef:=getarraydef(u8inttype,left.resultdef.size);
  702. paratemp:=ctempcreatenode.create(temparraydef,temparraydef.size,tt_persistent,false);
  703. addstatement(initstat,paratemp);
  704. addstatement(initstat,
  705. cassignmentnode.create(
  706. ctemprefnode.create(paratemp),
  707. ctypeconvnode.create_internal(left,temparraydef)
  708. )
  709. );
  710. left:=ctypeconvnode.create_explicit(ctemprefnode.create(paratemp),left.resultdef);
  711. end
  712. else
  713. begin
  714. paratemp:=ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,false);
  715. addstatement(initstat,paratemp);
  716. addstatement(initstat,
  717. cassignmentnode.create(ctemprefnode.create(paratemp),left)
  718. );
  719. { replace parameter with temp (don't free left, it has been
  720. reused above) }
  721. left:=ctemprefnode.create(paratemp);
  722. end;
  723. addstatement(finistat,ctempdeletenode.create(paratemp));
  724. addstatement(copybackstat,finiblock);
  725. firstpass(fparainit);
  726. firstpass(left);
  727. firstpass(fparacopyback);
  728. end;
  729. end;
  730. constructor tcallparanode.create(expr,next : tnode);
  731. begin
  732. inherited create(callparan,expr,next,nil);
  733. if not assigned(expr) then
  734. internalerror(200305091);
  735. expr.fileinfo:=fileinfo;
  736. callparaflags:=[];
  737. if expr.nodetype = typeconvn then
  738. ttypeconvnode(expr).warn_pointer_to_signed:=false;
  739. end;
  740. destructor tcallparanode.destroy;
  741. begin
  742. fparainit.free;
  743. fparacopyback.free;
  744. inherited destroy;
  745. end;
  746. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  747. begin
  748. inherited ppuload(t,ppufile);
  749. ppufile.getsmallset(callparaflags);
  750. fparainit:=ppuloadnode(ppufile);
  751. fparacopyback:=ppuloadnode(ppufile);
  752. end;
  753. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  754. begin
  755. inherited ppuwrite(ppufile);
  756. ppufile.putsmallset(callparaflags);
  757. ppuwritenode(ppufile,fparainit);
  758. ppuwritenode(ppufile,fparacopyback);
  759. end;
  760. procedure tcallparanode.buildderefimpl;
  761. begin
  762. inherited buildderefimpl;
  763. if assigned(fparainit) then
  764. fparainit.buildderefimpl;
  765. if assigned(fparacopyback) then
  766. fparacopyback.buildderefimpl;
  767. end;
  768. procedure tcallparanode.derefimpl;
  769. begin
  770. inherited derefimpl;
  771. if assigned(fparainit) then
  772. fparainit.derefimpl;
  773. if assigned(fparacopyback) then
  774. fparacopyback.derefimpl;
  775. end;
  776. function tcallparanode.dogetcopy : tnode;
  777. var
  778. n : tcallparanode;
  779. initcopy: tnode;
  780. begin
  781. initcopy:=nil;
  782. { must be done before calling inherited getcopy, because can create
  783. tempcreatenodes for values used in left }
  784. if assigned(fparainit) then
  785. initcopy:=fparainit.getcopy;
  786. n:=tcallparanode(inherited dogetcopy);
  787. n.callparaflags:=callparaflags;
  788. n.parasym:=parasym;
  789. n.fparainit:=initcopy;
  790. if assigned(fparacopyback) then
  791. n.fparacopyback:=fparacopyback.getcopy;
  792. result:=n;
  793. end;
  794. procedure tcallparanode.insertintolist(l : tnodelist);
  795. begin
  796. end;
  797. function tcallparanode.pass_typecheck : tnode;
  798. begin
  799. { need to use get_paratype }
  800. internalerror(200709251);
  801. result:=nil;
  802. end;
  803. function tcallparanode.pass_1 : tnode;
  804. begin
  805. { need to use firstcallparan }
  806. internalerror(200709252);
  807. result:=nil;
  808. end;
  809. procedure tcallparanode.get_paratype;
  810. var
  811. old_array_constructor : boolean;
  812. begin
  813. if assigned(right) then
  814. tcallparanode(right).get_paratype;
  815. old_array_constructor:=allow_array_constructor;
  816. allow_array_constructor:=true;
  817. if assigned(fparainit) then
  818. typecheckpass(fparainit);
  819. typecheckpass(left);
  820. if assigned(third) then
  821. typecheckpass(third);
  822. if assigned(fparacopyback) then
  823. typecheckpass(fparacopyback);
  824. allow_array_constructor:=old_array_constructor;
  825. if codegenerror then
  826. resultdef:=generrordef
  827. else
  828. resultdef:=left.resultdef;
  829. end;
  830. procedure tcallparanode.firstcallparan;
  831. begin
  832. if assigned(right) then
  833. tcallparanode(right).firstcallparan;
  834. if not assigned(left.resultdef) then
  835. get_paratype;
  836. if assigned(parasym) and
  837. (target_info.system in systems_managed_vm) and
  838. (parasym.varspez in [vs_var,vs_out,vs_constref]) and
  839. (parasym.vardef.typ<>formaldef) and
  840. { for record constructors }
  841. (left.nodetype<>nothingn) then
  842. handlemanagedbyrefpara(left.resultdef);
  843. { for targets that have to copy "value parameters by reference" on the
  844. caller side
  845. aktcallnode may not be assigned in case firstcallparan is called for
  846. fake parameters to inline nodes (in that case, we don't have a real
  847. call and hence no "caller side" either)
  848. }
  849. if assigned(aktcallnode) and
  850. (target_info.system in systems_caller_copy_addr_value_para) and
  851. ((assigned(parasym) and
  852. (parasym.varspez=vs_value)) or
  853. (cpf_varargs_para in callparaflags)) and
  854. (left.nodetype<>nothingn) and
  855. not(vo_has_local_copy in parasym.varoptions) and
  856. ((not is_open_array(parasym.vardef) and
  857. not is_array_of_const(parasym.vardef)) or
  858. not(aktcallnode.procdefinition.proccalloption in cdecl_pocalls)) and
  859. paramanager.push_addr_param(vs_value,parasym.vardef,
  860. aktcallnode.procdefinition.proccalloption) then
  861. copy_value_by_ref_para;
  862. { does it need to load RTTI? }
  863. if assigned(parasym) and (parasym.varspez=vs_out) and
  864. (cs_create_pic in current_settings.moduleswitches) and
  865. (
  866. is_rtti_managed_type(left.resultdef) or
  867. (
  868. is_open_array(resultdef) and
  869. is_managed_type(tarraydef(resultdef).elementdef)
  870. )
  871. ) and
  872. not(target_info.system in systems_garbage_collected_managed_types) then
  873. include(current_procinfo.flags,pi_needs_got);
  874. if assigned(fparainit) then
  875. firstpass(fparainit);
  876. firstpass(left);
  877. if assigned(fparacopyback) then
  878. firstpass(fparacopyback);
  879. if assigned(third) then
  880. firstpass(third);
  881. expectloc:=left.expectloc;
  882. end;
  883. procedure tcallparanode.insert_typeconv;
  884. var
  885. olddef : tdef;
  886. hp : tnode;
  887. block : tblocknode;
  888. statements : tstatementnode;
  889. temp : ttempcreatenode;
  890. owningprocdef: tprocdef;
  891. begin
  892. { Be sure to have the resultdef }
  893. if not assigned(left.resultdef) then
  894. typecheckpass(left);
  895. if (left.nodetype<>nothingn) then
  896. begin
  897. { convert loads of the function result variable into procvars
  898. representing the current function in case the formal parameter is
  899. a procvar (CodeWarrior Pascal contains the same kind of
  900. automatic disambiguation; you can use the function name in both
  901. meanings, so we cannot statically pick either the function result
  902. or the function definition in pexpr) }
  903. if (m_mac in current_settings.modeswitches) and
  904. (parasym.vardef.typ=procvardef) and
  905. is_ambiguous_funcret_load(left,owningprocdef) then
  906. begin
  907. hp:=cloadnode.create_procvar(owningprocdef.procsym,owningprocdef,owningprocdef.procsym.owner);
  908. typecheckpass(hp);
  909. left.free;
  910. left:=hp;
  911. end;
  912. { Convert tp procvars, this is needs to be done
  913. here to make the change permanent. in the overload
  914. choosing the changes are only made temporarily }
  915. if (left.resultdef.typ=procvardef) and
  916. not(parasym.vardef.typ in [procvardef,formaldef]) then
  917. begin
  918. if maybe_call_procvar(left,true) then
  919. resultdef:=left.resultdef
  920. end;
  921. { Remove implicitly inserted typecast to pointer for
  922. @procvar in macpas }
  923. if (m_mac_procvar in current_settings.modeswitches) and
  924. (parasym.vardef.typ=procvardef) and
  925. (left.nodetype=typeconvn) and
  926. is_voidpointer(left.resultdef) and
  927. (ttypeconvnode(left).left.nodetype=typeconvn) and
  928. (ttypeconvnode(ttypeconvnode(left).left).convtype=tc_proc_2_procvar) then
  929. begin
  930. hp:=left;
  931. left:=ttypeconvnode(left).left;
  932. ttypeconvnode(hp).left:=nil;
  933. hp.free;
  934. end;
  935. maybe_global_proc_to_nested(left,parasym.vardef);
  936. { Handle varargs and hidden paras directly, no typeconvs or }
  937. { pass_typechecking needed }
  938. if (cpf_varargs_para in callparaflags) then
  939. begin
  940. { this should only happen vor C varargs }
  941. { the necessary conversions have already been performed in }
  942. { tarrayconstructornode.insert_typeconvs }
  943. set_varstate(left,vs_read,[vsf_must_be_valid]);
  944. insert_varargstypeconv(left,true);
  945. resultdef:=left.resultdef;
  946. { also update parasym type to get the correct parameter location
  947. for the new types }
  948. parasym.vardef:=left.resultdef;
  949. end
  950. else
  951. if (vo_is_hidden_para in parasym.varoptions) then
  952. begin
  953. set_varstate(left,vs_read,[vsf_must_be_valid]);
  954. resultdef:=left.resultdef;
  955. end
  956. else
  957. begin
  958. { Do we need arrayconstructor -> set conversion, then insert
  959. it here before the arrayconstructor node breaks the tree
  960. with its conversions of enum->ord }
  961. if (left.nodetype=arrayconstructorn) and
  962. (parasym.vardef.typ=setdef) then
  963. inserttypeconv(left,parasym.vardef);
  964. { set some settings needed for arrayconstructor }
  965. if is_array_constructor(left.resultdef) then
  966. begin
  967. if left.nodetype<>arrayconstructorn then
  968. internalerror(200504041);
  969. if is_array_of_const(parasym.vardef) then
  970. begin
  971. { force variant array }
  972. include(left.flags,nf_forcevaria);
  973. end
  974. else
  975. begin
  976. include(left.flags,nf_novariaallowed);
  977. { now that the resultting type is know we can insert the required
  978. typeconvs for the array constructor }
  979. if parasym.vardef.typ=arraydef then
  980. tarrayconstructornode(left).force_type(tarraydef(parasym.vardef).elementdef);
  981. end;
  982. end;
  983. { check if local proc/func is assigned to procvar }
  984. if left.resultdef.typ=procvardef then
  985. test_local_to_procvar(tprocvardef(left.resultdef),parasym.vardef);
  986. { test conversions }
  987. if not(is_shortstring(left.resultdef) and
  988. is_shortstring(parasym.vardef)) and
  989. (parasym.vardef.typ<>formaldef) and
  990. not(parasym.univpara) then
  991. begin
  992. { Process open parameters }
  993. if paramanager.keep_para_array_range(parasym.varspez,parasym.vardef,aktcallnode.procdefinition.proccalloption) then
  994. begin
  995. { insert type conv but hold the ranges of the array }
  996. olddef:=left.resultdef;
  997. inserttypeconv(left,parasym.vardef);
  998. left.resultdef:=olddef;
  999. end
  1000. else
  1001. begin
  1002. check_ranges(left.fileinfo,left,parasym.vardef);
  1003. inserttypeconv(left,parasym.vardef);
  1004. end;
  1005. if codegenerror then
  1006. exit;
  1007. end;
  1008. { truncate shortstring value parameters at the caller side if }
  1009. { they are passed by value (if passed by reference, then the }
  1010. { callee will truncate when copying in the string) }
  1011. { This happens e.g. on x86_64 for small strings }
  1012. if is_shortstring(left.resultdef) and
  1013. is_shortstring(parasym.vardef) and
  1014. (parasym.varspez=vs_value) and
  1015. not paramanager.push_addr_param(parasym.varspez,parasym.vardef,
  1016. aktcallnode.procdefinition.proccalloption) and
  1017. ((is_open_string(left.resultdef) and
  1018. (tstringdef(parasym.vardef).len < 255)) or
  1019. (not is_open_string(left.resultdef) and
  1020. { when a stringconstn is typeconverted, then only its }
  1021. { def is modified, not the contents (needed because in }
  1022. { Delphi/TP, if you pass a longer string to a const }
  1023. { parameter, then the callee has to see this longer }
  1024. { string) }
  1025. (((left.nodetype<>stringconstn) and
  1026. (tstringdef(parasym.vardef).len<tstringdef(left.resultdef).len)) or
  1027. ((left.nodetype=stringconstn) and
  1028. (tstringdef(parasym.vardef).len<tstringconstnode(left).len))))) then
  1029. begin
  1030. block:=internalstatements(statements);
  1031. { temp for the new string }
  1032. temp:=ctempcreatenode.create(parasym.vardef,parasym.vardef.size,
  1033. tt_persistent,true);
  1034. addstatement(statements,temp);
  1035. { assign parameter to temp }
  1036. addstatement(statements,cassignmentnode.create(ctemprefnode.create(temp),left));
  1037. left:=nil;
  1038. { release temp after next use }
  1039. addstatement(statements,ctempdeletenode.create_normal_temp(temp));
  1040. addstatement(statements,ctemprefnode.create(temp));
  1041. typecheckpass(tnode(block));
  1042. left:=block;
  1043. end;
  1044. { check var strings }
  1045. if (cs_strict_var_strings in current_settings.localswitches) and
  1046. is_shortstring(left.resultdef) and
  1047. is_shortstring(parasym.vardef) and
  1048. (parasym.varspez in [vs_out,vs_var,vs_constref]) and
  1049. not(is_open_string(parasym.vardef)) and
  1050. not(equal_defs(left.resultdef,parasym.vardef)) then
  1051. begin
  1052. CGMessagePos(left.fileinfo,type_e_strict_var_string_violation);
  1053. end;
  1054. { passing a value to an "univ" parameter implies an explicit
  1055. typecast to the parameter type. Must be done before the
  1056. valid_for_var() check, since the typecast can result in
  1057. an invalid lvalue in case of var/out parameters. }
  1058. if (parasym.univpara) then
  1059. begin
  1060. { load procvar if a procedure is passed }
  1061. if ((m_tp_procvar in current_settings.modeswitches) or
  1062. (m_mac_procvar in current_settings.modeswitches)) and
  1063. (left.nodetype=calln) and
  1064. (is_void(left.resultdef)) then
  1065. begin
  1066. load_procvar_from_calln(left);
  1067. { load_procvar_from_calln() creates a loadn for a
  1068. a procedure, which means that the type conversion
  1069. below will type convert the first instruction
  1070. bytes of the procedure -> convert to a procvar }
  1071. left:=ctypeconvnode.create_proc_to_procvar(left);
  1072. typecheckpass(left);
  1073. end;
  1074. inserttypeconv_explicit(left,parasym.vardef);
  1075. end;
  1076. { Handle formal parameters separate }
  1077. if (parasym.vardef.typ=formaldef) then
  1078. begin
  1079. { load procvar if a procedure is passed }
  1080. if ((m_tp_procvar in current_settings.modeswitches) or
  1081. (m_mac_procvar in current_settings.modeswitches)) and
  1082. (left.nodetype=calln) and
  1083. (is_void(left.resultdef)) then
  1084. load_procvar_from_calln(left);
  1085. case parasym.varspez of
  1086. vs_var,
  1087. vs_constref,
  1088. vs_out :
  1089. begin
  1090. if not valid_for_formal_var(left,true) then
  1091. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list)
  1092. else if (target_info.system in systems_managed_vm) then
  1093. handlemanagedbyrefpara(left.resultdef);
  1094. end;
  1095. vs_const :
  1096. begin
  1097. if not valid_for_formal_const(left,true) then
  1098. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list)
  1099. else if (target_info.system in systems_managed_vm) and
  1100. (left.resultdef.typ in [orddef,floatdef]) then
  1101. begin
  1102. left:=cinlinenode.create(in_box_x,false,ccallparanode.create(left,nil));
  1103. typecheckpass(left);
  1104. end;
  1105. end;
  1106. end;
  1107. end
  1108. else
  1109. begin
  1110. { check if the argument is allowed }
  1111. if (parasym.varspez in [vs_out,vs_var]) then
  1112. valid_for_var(left,true);
  1113. end;
  1114. if parasym.varspez in [vs_var,vs_out,vs_constref] then
  1115. set_unique(left);
  1116. case parasym.varspez of
  1117. vs_out :
  1118. begin
  1119. { first set written separately to avoid false }
  1120. { uninitialized warnings (tbs/tb0542) }
  1121. set_varstate(left,vs_written,[]);
  1122. set_varstate(left,vs_readwritten,[]);
  1123. make_not_regable(left,[ra_addr_regable,ra_addr_taken]);
  1124. end;
  1125. vs_var,
  1126. vs_constref:
  1127. begin
  1128. set_varstate(left,vs_readwritten,[vsf_must_be_valid,vsf_use_hints]);
  1129. { constref takes also the address, but storing it is actually the compiler
  1130. is not supposed to expect }
  1131. if parasym.varspez=vs_var then
  1132. make_not_regable(left,[ra_addr_regable,ra_addr_taken]);
  1133. end;
  1134. else
  1135. set_varstate(left,vs_read,[vsf_must_be_valid]);
  1136. end;
  1137. { must only be done after typeconv PM }
  1138. resultdef:=parasym.vardef;
  1139. end;
  1140. end;
  1141. { process next node }
  1142. if assigned(right) then
  1143. tcallparanode(right).insert_typeconv;
  1144. end;
  1145. function tcallparanode.can_be_inlined: boolean;
  1146. var
  1147. n: tnode;
  1148. begin
  1149. n:=left;
  1150. result:=false;
  1151. while assigned(n) and
  1152. (n.nodetype=typeconvn) do
  1153. begin
  1154. { look for type conversion nodes which convert a }
  1155. { refcounted type into a non-refcounted type }
  1156. if not is_managed_type(n.resultdef) and
  1157. is_managed_type(ttypeconvnode(n).left.resultdef) then
  1158. exit;
  1159. n:=ttypeconvnode(n).left;
  1160. end;
  1161. { also check for dereferencing constant pointers, like }
  1162. { tsomerecord(nil^) passed to a const r: tsomerecord }
  1163. { parameter }
  1164. if (n.nodetype=derefn) then
  1165. begin
  1166. repeat
  1167. n:=tunarynode(n).left;
  1168. until (n.nodetype<>typeconvn);
  1169. if (n.nodetype in [niln,pointerconstn]) then
  1170. exit
  1171. end;
  1172. result:=true;
  1173. end;
  1174. function check_contains_stack_tainting_call(var n: tnode; arg: pointer): foreachnoderesult;
  1175. begin
  1176. if (n.nodetype=calln) and
  1177. tcallnode(n).procdefinition.stack_tainting_parameter(callerside) then
  1178. result:=fen_norecurse_true
  1179. else
  1180. result:=fen_false;
  1181. end;
  1182. function tcallparanode.contains_stack_tainting_call: boolean;
  1183. begin
  1184. result:=foreachnodestatic(pm_postprocess,left,@check_contains_stack_tainting_call,nil);
  1185. end;
  1186. procedure tcallparanode.init_contains_stack_tainting_call_cache;
  1187. begin
  1188. fcontains_stack_tainting_call_cached:=contains_stack_tainting_call;
  1189. end;
  1190. function tcallparanode.docompare(p: tnode): boolean;
  1191. begin
  1192. docompare :=
  1193. inherited docompare(p) and
  1194. fparainit.isequal(tcallparanode(p).fparainit) and
  1195. fparacopyback.isequal(tcallparanode(p).fparacopyback) and
  1196. (callparaflags = tcallparanode(p).callparaflags)
  1197. ;
  1198. end;
  1199. procedure tcallparanode.printnodetree(var t:text);
  1200. begin
  1201. printnodelist(t);
  1202. end;
  1203. {****************************************************************************
  1204. TCALLNODE
  1205. ****************************************************************************}
  1206. constructor tcallnode.create(l:tnode;v : tprocsym;st : TSymtable; mp: tnode; callflags:tcallnodeflags);
  1207. begin
  1208. inherited create(calln,l,nil);
  1209. symtableprocentry:=v;
  1210. symtableproc:=st;
  1211. callnodeflags:=callflags+[cnf_return_value_used];
  1212. methodpointer:=mp;
  1213. callinitblock:=nil;
  1214. callcleanupblock:=nil;
  1215. procdefinition:=nil;
  1216. funcretnode:=nil;
  1217. paralength:=-1;
  1218. varargsparas:=nil;
  1219. if assigned(current_structdef) and
  1220. assigned(mp) then
  1221. begin
  1222. { can't determine now yet if it will be necessary or not, so
  1223. always create it if there is a 'self' symbol in the current
  1224. context }
  1225. if get_local_or_para_sym('self')<>nil then
  1226. call_self_node:=load_self_node;
  1227. { only needed when calling a destructor from an exception block in a
  1228. contructor of a TP-style object }
  1229. if is_object(current_structdef) and
  1230. (current_procinfo.procdef.proctypeoption=potype_constructor) and
  1231. (cnf_create_failed in callflags) then
  1232. call_vmt_node:=load_vmt_pointer_node;
  1233. end;
  1234. end;
  1235. constructor tcallnode.create_procvar(l,r:tnode);
  1236. begin
  1237. create(l,nil,nil,nil,[]);
  1238. right:=r;
  1239. end;
  1240. constructor tcallnode.createintern(const name: string; params: tnode);
  1241. var
  1242. srsym: tsym;
  1243. begin
  1244. srsym := tsym(systemunit.Find(name));
  1245. if not assigned(srsym) and
  1246. (cs_compilesystem in current_settings.moduleswitches) then
  1247. srsym := tsym(systemunit.Find(upper(name)));
  1248. if not assigned(srsym) or
  1249. (srsym.typ<>procsym) then
  1250. Message1(cg_f_unknown_compilerproc,name);
  1251. create(params,tprocsym(srsym),srsym.owner,nil,[]);
  1252. end;
  1253. constructor tcallnode.createinternfromunit(const fromunit, procname: string; params: tnode);
  1254. var
  1255. srsym: tsym;
  1256. srsymtable: tsymtable;
  1257. begin
  1258. srsym:=nil;
  1259. if not searchsym_in_named_module(fromunit,procname,srsym,srsymtable) or
  1260. (srsym.typ<>procsym) then
  1261. Message1(cg_f_unknown_compilerproc,fromunit+'.'+procname);
  1262. create(params,tprocsym(srsym),srsymtable,nil,[]);
  1263. end;
  1264. constructor tcallnode.createinternres(const name: string; params: tnode; res:tdef);
  1265. var
  1266. pd : tprocdef;
  1267. begin
  1268. createintern(name,params);
  1269. typedef:=res;
  1270. include(callnodeflags,cnf_typedefset);
  1271. pd:=tprocdef(symtableprocentry.ProcdefList[0]);
  1272. { both the normal and specified resultdef either have to be returned via a }
  1273. { parameter or not, but no mixing (JM) }
  1274. if paramanager.ret_in_param(typedef,pd) xor
  1275. paramanager.ret_in_param(pd.returndef,pd) then
  1276. internalerror(2001082911);
  1277. end;
  1278. constructor tcallnode.createinternresfromunit(const fromunit, procname: string; params: tnode; res:tdef);
  1279. var
  1280. pd : tprocdef;
  1281. begin
  1282. createinternfromunit(fromunit,procname,params);
  1283. typedef:=res;
  1284. include(callnodeflags,cnf_typedefset);
  1285. pd:=tprocdef(symtableprocentry.ProcdefList[0]);
  1286. { both the normal and specified resultdef either have to be returned via a }
  1287. { parameter or not, but no mixing (JM) }
  1288. if paramanager.ret_in_param(typedef,pd) xor
  1289. paramanager.ret_in_param(pd.returndef,pd) then
  1290. internalerror(200108291);
  1291. end;
  1292. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  1293. begin
  1294. createintern(name,params);
  1295. funcretnode:=returnnode;
  1296. end;
  1297. constructor tcallnode.createinternmethod(mp: tnode; const name: string; params: tnode);
  1298. var
  1299. ps: tsym;
  1300. recdef: tabstractrecorddef;
  1301. begin
  1302. typecheckpass(mp);
  1303. if mp.resultdef.typ=classrefdef then
  1304. recdef:=tabstractrecorddef(tclassrefdef(mp.resultdef).pointeddef)
  1305. else
  1306. recdef:=tabstractrecorddef(mp.resultdef);
  1307. ps:=search_struct_member(recdef,name);
  1308. if not assigned(ps) or
  1309. (ps.typ<>procsym) then
  1310. internalerror(2011062806);
  1311. create(params,tprocsym(ps),ps.owner,mp,[]);
  1312. end;
  1313. constructor tcallnode.createinternmethodres(mp: tnode; const name: string; params: tnode; res: tdef);
  1314. begin
  1315. createinternmethod(mp,name,params);
  1316. typedef:=res;
  1317. include(callnodeflags,cnf_typedefset)
  1318. end;
  1319. destructor tcallnode.destroy;
  1320. begin
  1321. methodpointer.free;
  1322. callinitblock.free;
  1323. callcleanupblock.free;
  1324. funcretnode.free;
  1325. if assigned(varargsparas) then
  1326. varargsparas.free;
  1327. call_self_node.free;
  1328. call_vmt_node.free;
  1329. {$ifndef symansistr}
  1330. stringdispose(fforcedprocname);
  1331. {$endif symansistr}
  1332. inherited destroy;
  1333. end;
  1334. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1335. begin
  1336. callinitblock:=tblocknode(ppuloadnode(ppufile));
  1337. methodpointer:=ppuloadnode(ppufile);
  1338. call_self_node:=ppuloadnode(ppufile);
  1339. call_vmt_node:=ppuloadnode(ppufile);
  1340. callcleanupblock:=tblocknode(ppuloadnode(ppufile));
  1341. funcretnode:=ppuloadnode(ppufile);
  1342. inherited ppuload(t,ppufile);
  1343. ppufile.getderef(symtableprocentryderef);
  1344. { TODO: FIXME: No withsymtable support}
  1345. symtableproc:=nil;
  1346. ppufile.getderef(procdefinitionderef);
  1347. ppufile.getsmallset(callnodeflags);
  1348. end;
  1349. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  1350. begin
  1351. ppuwritenode(ppufile,callinitblock);
  1352. ppuwritenode(ppufile,methodpointer);
  1353. ppuwritenode(ppufile,call_self_node);
  1354. ppuwritenode(ppufile,call_vmt_node);
  1355. ppuwritenode(ppufile,callcleanupblock);
  1356. ppuwritenode(ppufile,funcretnode);
  1357. inherited ppuwrite(ppufile);
  1358. ppufile.putderef(symtableprocentryderef);
  1359. ppufile.putderef(procdefinitionderef);
  1360. ppufile.putsmallset(callnodeflags);
  1361. end;
  1362. procedure tcallnode.buildderefimpl;
  1363. begin
  1364. inherited buildderefimpl;
  1365. symtableprocentryderef.build(symtableprocentry);
  1366. procdefinitionderef.build(procdefinition);
  1367. if assigned(methodpointer) then
  1368. methodpointer.buildderefimpl;
  1369. if assigned(call_self_node) then
  1370. call_self_node.buildderefimpl;
  1371. if assigned(call_vmt_node) then
  1372. call_vmt_node.buildderefimpl;
  1373. if assigned(callinitblock) then
  1374. callinitblock.buildderefimpl;
  1375. if assigned(callcleanupblock) then
  1376. callcleanupblock.buildderefimpl;
  1377. if assigned(funcretnode) then
  1378. funcretnode.buildderefimpl;
  1379. end;
  1380. procedure tcallnode.derefimpl;
  1381. var
  1382. pt : tcallparanode;
  1383. i : integer;
  1384. begin
  1385. inherited derefimpl;
  1386. symtableprocentry:=tprocsym(symtableprocentryderef.resolve);
  1387. if assigned(symtableprocentry) then
  1388. symtableproc:=symtableprocentry.owner;
  1389. procdefinition:=tabstractprocdef(procdefinitionderef.resolve);
  1390. if assigned(methodpointer) then
  1391. methodpointer.derefimpl;
  1392. if assigned(call_self_node) then
  1393. call_self_node.derefimpl;
  1394. if assigned(call_vmt_node) then
  1395. call_vmt_node.derefimpl;
  1396. if assigned(callinitblock) then
  1397. callinitblock.derefimpl;
  1398. if assigned(callcleanupblock) then
  1399. callcleanupblock.derefimpl;
  1400. if assigned(funcretnode) then
  1401. funcretnode.derefimpl;
  1402. { generic method has no procdefinition }
  1403. if assigned(procdefinition) then
  1404. begin
  1405. { Connect parasyms }
  1406. pt:=tcallparanode(left);
  1407. while assigned(pt) and
  1408. (cpf_varargs_para in pt.callparaflags) do
  1409. pt:=tcallparanode(pt.right);
  1410. for i:=procdefinition.paras.count-1 downto 0 do
  1411. begin
  1412. if not assigned(pt) then
  1413. internalerror(200311077);
  1414. pt.parasym:=tparavarsym(procdefinition.paras[i]);
  1415. pt:=tcallparanode(pt.right);
  1416. end;
  1417. if assigned(pt) then
  1418. internalerror(200311078);
  1419. end;
  1420. end;
  1421. function tcallnode.dogetcopy : tnode;
  1422. var
  1423. n : tcallnode;
  1424. i : integer;
  1425. hp,hpn : tparavarsym;
  1426. oldleft : tnode;
  1427. para: tcallparanode;
  1428. begin
  1429. { Need to use a hack here to prevent the parameters from being copied.
  1430. The parameters must be copied between callinitblock/callcleanupblock because
  1431. they can reference methodpointer }
  1432. oldleft:=left;
  1433. left:=nil;
  1434. n:=tcallnode(inherited dogetcopy);
  1435. left:=oldleft;
  1436. n.symtableprocentry:=symtableprocentry;
  1437. n.symtableproc:=symtableproc;
  1438. n.procdefinition:=procdefinition;
  1439. n.typedef := typedef;
  1440. n.callnodeflags := callnodeflags;
  1441. if assigned(callinitblock) then
  1442. n.callinitblock:=tblocknode(callinitblock.dogetcopy)
  1443. else
  1444. n.callinitblock:=nil;
  1445. { callinitblock is copied, now references to the temp will also be copied
  1446. correctly. We can now copy the parameters, funcret and methodpointer }
  1447. if assigned(left) then
  1448. n.left:=left.dogetcopy
  1449. else
  1450. n.left:=nil;
  1451. if assigned(methodpointer) then
  1452. n.methodpointer:=methodpointer.dogetcopy
  1453. else
  1454. n.methodpointer:=nil;
  1455. if assigned(call_self_node) then
  1456. n.call_self_node:=call_self_node.dogetcopy
  1457. else
  1458. n.call_self_node:=nil;
  1459. if assigned(call_vmt_node) then
  1460. n.call_vmt_node:=call_vmt_node.dogetcopy
  1461. else
  1462. n.call_vmt_node:=nil;
  1463. { must be copied before the funcretnode, because the callcleanup block
  1464. may contain a ttempdeletenode that sets the tempinfo of the
  1465. corresponding temp to ti_nextref_set_hookoncopy_nil, and this nextref
  1466. itself may be the funcretnode }
  1467. if assigned(callcleanupblock) then
  1468. n.callcleanupblock:=tblocknode(callcleanupblock.dogetcopy)
  1469. else
  1470. n.callcleanupblock:=nil;
  1471. if assigned(funcretnode) then
  1472. n.funcretnode:=funcretnode.dogetcopy
  1473. else
  1474. n.funcretnode:=nil;
  1475. if assigned(varargsparas) then
  1476. begin
  1477. n.varargsparas:=tvarargsparalist.create(true);
  1478. for i:=0 to varargsparas.count-1 do
  1479. begin
  1480. hp:=tparavarsym(varargsparas[i]);
  1481. hpn:=cparavarsym.create(hp.realname,hp.paranr,hp.varspez,hp.vardef,[]);
  1482. n.varargsparas.add(hpn);
  1483. para:=tcallparanode(n.left);
  1484. while assigned(para) do
  1485. begin
  1486. if (para.parasym=hp) then
  1487. para.parasym:=hpn;
  1488. para:=tcallparanode(para.right);
  1489. end;
  1490. end;
  1491. end
  1492. else
  1493. n.varargsparas:=nil;
  1494. {$ifdef symansistr}
  1495. n.fforcedprocname:=fforcedprocname;
  1496. {$else symansistr}
  1497. if assigned(fforcedprocname) then
  1498. n.fforcedprocname:=stringdup(fforcedprocname^)
  1499. else
  1500. n.fforcedprocname:=nil;
  1501. {$endif symansistr}
  1502. result:=n;
  1503. end;
  1504. function tcallnode.docompare(p: tnode): boolean;
  1505. begin
  1506. docompare :=
  1507. inherited docompare(p) and
  1508. (symtableprocentry = tcallnode(p).symtableprocentry) and
  1509. (procdefinition = tcallnode(p).procdefinition) and
  1510. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  1511. (((cnf_typedefset in callnodeflags) and (cnf_typedefset in tcallnode(p).callnodeflags) and
  1512. (equal_defs(typedef,tcallnode(p).typedef))) or
  1513. (not(cnf_typedefset in callnodeflags) and not(cnf_typedefset in tcallnode(p).callnodeflags)));
  1514. end;
  1515. procedure tcallnode.printnodedata(var t:text);
  1516. begin
  1517. if assigned(procdefinition) and
  1518. (procdefinition.typ=procdef) then
  1519. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  1520. else
  1521. begin
  1522. if assigned(symtableprocentry) then
  1523. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  1524. else
  1525. writeln(t,printnodeindention,'proc = <nil>');
  1526. end;
  1527. if assigned(methodpointer) then
  1528. begin
  1529. writeln(t,printnodeindention,'methodpointer =');
  1530. printnode(t,methodpointer);
  1531. end;
  1532. if assigned(callinitblock) then
  1533. begin
  1534. writeln(t,printnodeindention,'callinitblock =');
  1535. printnode(t,callinitblock);
  1536. end;
  1537. if assigned(callcleanupblock) then
  1538. begin
  1539. writeln(t,printnodeindention,'callcleanupblock =');
  1540. printnode(t,callcleanupblock);
  1541. end;
  1542. if assigned(right) then
  1543. begin
  1544. writeln(t,printnodeindention,'right =');
  1545. printnode(t,right);
  1546. end;
  1547. if assigned(left) then
  1548. begin
  1549. writeln(t,printnodeindention,'left =');
  1550. printnode(t,left);
  1551. end;
  1552. end;
  1553. procedure tcallnode.insertintolist(l : tnodelist);
  1554. begin
  1555. end;
  1556. procedure tcallnode.add_init_statement(n:tnode);
  1557. var
  1558. lastinitstatement : tstatementnode;
  1559. begin
  1560. if not assigned(callinitblock) then
  1561. callinitblock:=internalstatements(lastinitstatement)
  1562. else
  1563. lastinitstatement:=laststatement(callinitblock);
  1564. { all these nodes must be immediately typechecked, because this routine }
  1565. { can be called from pass_1 (i.e., after typecheck has already run) and }
  1566. { moreover, the entire blocks themselves are also only typechecked in }
  1567. { pass_1, while the the typeinfo is already required after the }
  1568. { typecheck pass for simplify purposes (not yet perfect, because the }
  1569. { statementnodes themselves are not typechecked this way) }
  1570. typecheckpass(n);
  1571. addstatement(lastinitstatement,n);
  1572. end;
  1573. procedure tcallnode.add_done_statement(n:tnode);
  1574. var
  1575. lastdonestatement : tstatementnode;
  1576. begin
  1577. if not assigned(callcleanupblock) then
  1578. callcleanupblock:=internalstatements(lastdonestatement)
  1579. else
  1580. lastdonestatement:=laststatement(callcleanupblock);
  1581. { see comments in add_init_statement }
  1582. typecheckpass(n);
  1583. addstatement(lastdonestatement,n);
  1584. end;
  1585. function tcallnode.para_count:longint;
  1586. var
  1587. ppn : tcallparanode;
  1588. begin
  1589. result:=0;
  1590. ppn:=tcallparanode(left);
  1591. while assigned(ppn) do
  1592. begin
  1593. if not(assigned(ppn.parasym) and
  1594. (vo_is_hidden_para in ppn.parasym.varoptions)) then
  1595. inc(result);
  1596. ppn:=tcallparanode(ppn.right);
  1597. end;
  1598. end;
  1599. function tcallnode.required_para_count: longint;
  1600. var
  1601. ppn : tcallparanode;
  1602. begin
  1603. result:=0;
  1604. ppn:=tcallparanode(left);
  1605. while assigned(ppn) do
  1606. begin
  1607. if not(assigned(ppn.parasym) and
  1608. ((vo_is_hidden_para in ppn.parasym.varoptions) or
  1609. assigned(ppn.parasym.defaultconstsym))) then
  1610. inc(result);
  1611. ppn:=tcallparanode(ppn.right);
  1612. end;
  1613. end;
  1614. function tcallnode.is_simple_para_load(p:tnode; may_be_in_reg: boolean):boolean;
  1615. var
  1616. hp : tnode;
  1617. begin
  1618. hp:=p;
  1619. while assigned(hp) and
  1620. (hp.nodetype=typeconvn) and
  1621. (ttypeconvnode(hp).convtype=tc_equal) do
  1622. hp:=tunarynode(hp).left;
  1623. result:=(hp.nodetype in [typen,loadvmtaddrn,loadn,temprefn,arrayconstructorn,addrn]);
  1624. if result and
  1625. not(may_be_in_reg) then
  1626. case hp.nodetype of
  1627. loadn:
  1628. result:=(tabstractvarsym(tloadnode(hp).symtableentry).varregable in [vr_none,vr_addr]);
  1629. temprefn:
  1630. result:=not(ti_may_be_in_reg in ttemprefnode(hp).tempinfo^.flags);
  1631. end;
  1632. end;
  1633. function look_for_call(var n: tnode; arg: pointer): foreachnoderesult;
  1634. begin
  1635. case n.nodetype of
  1636. calln,asn:
  1637. result := fen_norecurse_true;
  1638. typen,loadvmtaddrn,loadn,temprefn,arrayconstructorn:
  1639. result := fen_norecurse_false;
  1640. else
  1641. result := fen_false;
  1642. end;
  1643. end;
  1644. procedure tcallnode.maybe_load_in_temp(var p:tnode);
  1645. var
  1646. loadp,
  1647. refp : tnode;
  1648. hdef : tdef;
  1649. ptemp : ttempcreatenode;
  1650. usederef : boolean;
  1651. begin
  1652. { Load all complex loads into a temp to prevent
  1653. double calls to a function. We can't simply check for a hp.nodetype=calln }
  1654. if assigned(p) and
  1655. foreachnodestatic(p,@look_for_call,nil) then
  1656. begin
  1657. { temp create }
  1658. usederef:=(p.resultdef.typ in [arraydef,recorddef]) or
  1659. is_shortstring(p.resultdef) or
  1660. is_object(p.resultdef);
  1661. if usederef then
  1662. hdef:=getpointerdef(p.resultdef)
  1663. else
  1664. hdef:=p.resultdef;
  1665. ptemp:=ctempcreatenode.create(hdef,hdef.size,tt_persistent,true);
  1666. if usederef then
  1667. begin
  1668. loadp:=caddrnode.create_internal(p);
  1669. refp:=cderefnode.create(ctemprefnode.create(ptemp));
  1670. end
  1671. else
  1672. begin
  1673. loadp:=p;
  1674. refp:=ctemprefnode.create(ptemp)
  1675. end;
  1676. add_init_statement(ptemp);
  1677. add_init_statement(cassignmentnode.create(
  1678. ctemprefnode.create(ptemp),
  1679. loadp));
  1680. add_done_statement(ctempdeletenode.create(ptemp));
  1681. { new tree is only a temp reference }
  1682. p:=refp;
  1683. typecheckpass(p);
  1684. end;
  1685. end;
  1686. function tcallnode.gen_high_tree(var p:tnode;paradef:tdef):tnode;
  1687. { When passing an array to an open array, or a string to an open string,
  1688. some code is needed that generates the high bound of the array. This
  1689. function returns a tree containing the nodes for it. }
  1690. var
  1691. temp: tnode;
  1692. len : integer;
  1693. loadconst : boolean;
  1694. hightree,l,r : tnode;
  1695. defkind: tdeftyp;
  1696. begin
  1697. len:=-1;
  1698. loadconst:=true;
  1699. hightree:=nil;
  1700. { constant strings are internally stored as array of char, but if the
  1701. parameter is a string also treat it like one }
  1702. defkind:=p.resultdef.typ;
  1703. if (p.nodetype=stringconstn) and
  1704. (paradef.typ=stringdef) then
  1705. defkind:=stringdef;
  1706. case defkind of
  1707. arraydef :
  1708. begin
  1709. if (paradef.typ<>arraydef) then
  1710. internalerror(200405241);
  1711. { passing a string to an array of char }
  1712. if (p.nodetype=stringconstn) and
  1713. is_char(tarraydef(paradef).elementdef) then
  1714. begin
  1715. len:=tstringconstnode(p).len;
  1716. if len>0 then
  1717. dec(len);
  1718. end
  1719. else
  1720. { handle special case of passing an single array to an array of array }
  1721. if compare_defs(tarraydef(paradef).elementdef,p.resultdef,nothingn)>=te_equal then
  1722. len:=0
  1723. else
  1724. begin
  1725. { handle via a normal inline in_high_x node }
  1726. loadconst:=false;
  1727. { slice? }
  1728. if (p.nodetype=inlinen) and (tinlinenode(p).inlinenumber=in_slice_x) then
  1729. with Tcallparanode(Tinlinenode(p).left) do
  1730. begin
  1731. {Array slice using slice builtin function.}
  1732. l:=Tcallparanode(right).left;
  1733. hightree:=caddnode.create(subn,l,genintconstnode(1));
  1734. Tcallparanode(right).left:=nil;
  1735. {Remove the inline node.}
  1736. temp:=p;
  1737. p:=left;
  1738. Tcallparanode(tinlinenode(temp).left).left:=nil;
  1739. temp.free;
  1740. typecheckpass(hightree);
  1741. end
  1742. else if (p.nodetype=vecn) and (Tvecnode(p).right.nodetype=rangen) then
  1743. begin
  1744. {Array slice using .. operator.}
  1745. with Trangenode(Tvecnode(p).right) do
  1746. begin
  1747. l:=left; {Get lower bound.}
  1748. r:=right; {Get upper bound.}
  1749. end;
  1750. {In the procedure the array range is 0..(upper_bound-lower_bound).}
  1751. hightree:=caddnode.create(subn,r,l);
  1752. {Replace the rangnode in the tree by its lower_bound, and
  1753. dispose the rangenode.}
  1754. temp:=Tvecnode(p).right;
  1755. Tvecnode(p).right:=l.getcopy;
  1756. {Typecheckpass can only be performed *after* the l.getcopy since it
  1757. can modify the tree, and l is in the hightree.}
  1758. typecheckpass(hightree);
  1759. with Trangenode(temp) do
  1760. begin
  1761. left:=nil;
  1762. right:=nil;
  1763. end;
  1764. temp.free;
  1765. {Tree changed from p[l..h] to p[l], recalculate resultdef.}
  1766. p.resultdef:=nil;
  1767. typecheckpass(p);
  1768. end
  1769. else
  1770. begin
  1771. maybe_load_in_temp(p);
  1772. hightree:=geninlinenode(in_high_x,false,p.getcopy);
  1773. typecheckpass(hightree);
  1774. { only substract low(array) if it's <> 0 }
  1775. temp:=geninlinenode(in_low_x,false,p.getcopy);
  1776. typecheckpass(temp);
  1777. if (temp.nodetype <> ordconstn) or
  1778. (tordconstnode(temp).value <> 0) then
  1779. begin
  1780. hightree:=caddnode.create(subn,hightree,temp);
  1781. include(hightree.flags,nf_internal);
  1782. end
  1783. else
  1784. temp.free;
  1785. end;
  1786. end;
  1787. end;
  1788. stringdef :
  1789. begin
  1790. if is_open_string(paradef) then
  1791. begin
  1792. { a stringconstn is not a simple parameter and hence would be
  1793. loaded in a temp, but in that case the high() node
  1794. a) goes wrong (it cannot deal with a temp node)
  1795. b) would give a generic result instead of one specific to
  1796. this constant string
  1797. }
  1798. if p.nodetype<>stringconstn then
  1799. maybe_load_in_temp(p);
  1800. { handle via a normal inline in_high_x node }
  1801. loadconst := false;
  1802. hightree := geninlinenode(in_high_x,false,p.getcopy);
  1803. end
  1804. else
  1805. { handle special case of passing an single string to an array of string }
  1806. if compare_defs(tarraydef(paradef).elementdef,p.resultdef,nothingn)>=te_equal then
  1807. len:=0
  1808. else
  1809. { passing a string to an array of char }
  1810. if (p.nodetype=stringconstn) and
  1811. is_char(tarraydef(paradef).elementdef) then
  1812. begin
  1813. len:=tstringconstnode(p).len;
  1814. if len>0 then
  1815. dec(len);
  1816. end
  1817. else
  1818. begin
  1819. maybe_load_in_temp(p);
  1820. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
  1821. cordconstnode.create(1,sinttype,false));
  1822. loadconst:=false;
  1823. end;
  1824. end;
  1825. else
  1826. len:=0;
  1827. end;
  1828. if loadconst then
  1829. hightree:=cordconstnode.create(len,sinttype,true)
  1830. else
  1831. begin
  1832. if not assigned(hightree) then
  1833. internalerror(200304071);
  1834. { Need to use explicit, because it can also be a enum }
  1835. hightree:=ctypeconvnode.create_internal(hightree,sinttype);
  1836. end;
  1837. result:=hightree;
  1838. end;
  1839. function tcallnode.gen_procvar_context_tree_self:tnode;
  1840. begin
  1841. { Load tmehodpointer(right).self }
  1842. result:=genloadfield(ctypeconvnode.create_internal(
  1843. right.getcopy,methodpointertype),
  1844. 'self');
  1845. end;
  1846. function tcallnode.gen_procvar_context_tree_parentfp: tnode;
  1847. begin
  1848. { Load tnestedprocpointer(right).parentfp }
  1849. result:=genloadfield(ctypeconvnode.create_internal(
  1850. right.getcopy,nestedprocpointertype),
  1851. 'parentfp');
  1852. end;
  1853. function tcallnode.gen_self_tree:tnode;
  1854. var
  1855. selftree : tnode;
  1856. selfdef : tdef;
  1857. temp : ttempcreatenode;
  1858. begin
  1859. selftree:=nil;
  1860. { When methodpointer was a callnode we must load it first into a
  1861. temp to prevent processing the callnode twice }
  1862. if (methodpointer.nodetype=calln) then
  1863. internalerror(200405121);
  1864. { Objective-C: objc_convert_to_message_send() already did all necessary
  1865. transformation on the methodpointer }
  1866. if (procdefinition.typ=procdef) and
  1867. (po_objc in tprocdef(procdefinition).procoptions) then
  1868. selftree:=methodpointer.getcopy
  1869. { inherited }
  1870. else if (cnf_inherited in callnodeflags) then
  1871. begin
  1872. selftree:=call_self_node.getcopy;
  1873. { we can call an inherited class static/method from a regular method
  1874. -> self node must change from instance pointer to vmt pointer)
  1875. }
  1876. if (procdefinition.procoptions*[po_classmethod,po_staticmethod] <> []) and
  1877. (selftree.resultdef.typ<>classrefdef) then
  1878. selftree:=cloadvmtaddrnode.create(selftree);
  1879. end
  1880. else
  1881. { constructors }
  1882. if (procdefinition.proctypeoption=potype_constructor) then
  1883. begin
  1884. if (methodpointer.resultdef.typ=classrefdef) or
  1885. (cnf_new_call in callnodeflags) then
  1886. if not is_javaclass(tdef(procdefinition.owner.defowner)) then
  1887. begin
  1888. if (cnf_new_call in callnodeflags) then
  1889. { old-style object: push 0 as self }
  1890. selftree:=cpointerconstnode.create(0,voidpointertype)
  1891. else
  1892. begin
  1893. { class-style: push classtype }
  1894. selftree:=methodpointer.getcopy;
  1895. if selftree.nodetype=typen then
  1896. begin
  1897. selftree:=cloadvmtaddrnode.create(selftree);
  1898. tloadvmtaddrnode(selftree).forcall:=true;
  1899. end;
  1900. end;
  1901. end
  1902. else
  1903. { special handling for Java constructors, handled in
  1904. tjvmcallnode.extra_pre_call_code }
  1905. selftree:=cnothingnode.create
  1906. else
  1907. begin
  1908. if methodpointer.nodetype=typen then
  1909. if (methodpointer.resultdef.typ<>objectdef) then
  1910. begin
  1911. if not(target_info.system in systems_jvm) then
  1912. begin
  1913. { TSomeRecord.Constructor call. We need to allocate }
  1914. { self node as a temp node of the result type }
  1915. temp:=ctempcreatenode.create(methodpointer.resultdef,methodpointer.resultdef.size,tt_persistent,false);
  1916. add_init_statement(temp);
  1917. add_done_statement(ctempdeletenode.create_normal_temp(temp));
  1918. selftree:=ctemprefnode.create(temp);
  1919. end
  1920. else
  1921. begin
  1922. { special handling for Java constructors, handled in
  1923. tjvmcallnode.extra_pre_call_code }
  1924. selftree:=cnothingnode.create
  1925. end;
  1926. end
  1927. else
  1928. selftree:=call_self_node.getcopy
  1929. else
  1930. selftree:=methodpointer.getcopy;
  1931. end;
  1932. end
  1933. else
  1934. { Calling a static/class method }
  1935. if (po_classmethod in procdefinition.procoptions) or
  1936. (po_staticmethod in procdefinition.procoptions) then
  1937. begin
  1938. if (procdefinition.typ<>procdef) then
  1939. internalerror(200305062);
  1940. { if the method belongs to a helper then we need to use the
  1941. extended type for references to Self }
  1942. if is_objectpascal_helper(tprocdef(procdefinition).struct) then
  1943. selfdef:=tobjectdef(tprocdef(procdefinition).struct).extendeddef
  1944. else
  1945. selfdef:=tprocdef(procdefinition).struct;
  1946. if ((selfdef.typ in [recorddef,objectdef]) and
  1947. (oo_has_vmt in tabstractrecorddef(selfdef).objectoptions)) or
  1948. { all Java classes have a "VMT" }
  1949. (target_info.system in systems_jvm) then
  1950. begin
  1951. { we only need the vmt, loading self is not required and there is no
  1952. need to check for typen, because that will always get the
  1953. loadvmtaddrnode added }
  1954. selftree:=methodpointer.getcopy;
  1955. if (methodpointer.resultdef.typ<>classrefdef) or
  1956. (methodpointer.nodetype = typen) then
  1957. selftree:=cloadvmtaddrnode.create(selftree);
  1958. end
  1959. else
  1960. selftree:=cpointerconstnode.create(0,voidpointertype);
  1961. end
  1962. else
  1963. begin
  1964. if methodpointer.nodetype=typen then
  1965. selftree:=call_self_node.getcopy
  1966. else
  1967. selftree:=methodpointer.getcopy;
  1968. end;
  1969. result:=selftree;
  1970. end;
  1971. procedure tcallnode.register_created_object_types;
  1972. function checklive(def: tdef): boolean;
  1973. begin
  1974. if assigned(current_procinfo) and
  1975. not(po_inline in current_procinfo.procdef.procoptions) and
  1976. not wpoinfomanager.symbol_live(current_procinfo.procdef.mangledname) then
  1977. begin
  1978. {$ifdef debug_deadcode}
  1979. writeln(' NOT adding creadion of ',def.typename,' because performed in dead stripped proc: ',current_procinfo.procdef.typename);
  1980. {$endif debug_deadcode}
  1981. result:=false;
  1982. end
  1983. else
  1984. result:=true;
  1985. end;
  1986. var
  1987. crefdef,
  1988. systobjectdef : tdef;
  1989. begin
  1990. { only makes sense for methods }
  1991. if not assigned(methodpointer) then
  1992. exit;
  1993. if (methodpointer.resultdef.typ=classrefdef) then
  1994. begin
  1995. { constructor call via classreference => allocate memory }
  1996. if (procdefinition.proctypeoption=potype_constructor) then
  1997. begin
  1998. { Only a typenode can be passed when it is called with <class of xx>.create }
  1999. if (methodpointer.nodetype=typen) then
  2000. begin
  2001. if checklive(methodpointer.resultdef) then
  2002. { we know the exact class type being created }
  2003. tclassrefdef(methodpointer.resultdef).pointeddef.register_created_object_type
  2004. end
  2005. else
  2006. begin
  2007. { the loadvmtaddrnode is already created in case of classtype.create }
  2008. if (methodpointer.nodetype=loadvmtaddrn) and
  2009. (tloadvmtaddrnode(methodpointer).left.nodetype=typen) then
  2010. begin
  2011. if checklive(methodpointer.resultdef) then
  2012. tclassrefdef(methodpointer.resultdef).pointeddef.register_created_object_type
  2013. end
  2014. else
  2015. begin
  2016. if checklive(methodpointer.resultdef) then
  2017. begin
  2018. { special case: if the classref comes from x.classtype (with classtype,
  2019. being tobject.classtype) then the created instance is x or a descendant
  2020. of x (rather than tobject or a descendant of tobject)
  2021. }
  2022. systobjectdef:=search_system_type('TOBJECT').typedef;
  2023. if (methodpointer.nodetype=calln) and
  2024. { not a procvar call }
  2025. not assigned(right) and
  2026. { procdef is owned by system.tobject }
  2027. (tprocdef(tcallnode(methodpointer).procdefinition).owner.defowner=systobjectdef) and
  2028. { we're calling system.tobject.classtype }
  2029. (tcallnode(methodpointer).symtableprocentry.name='CLASSTYPE') and
  2030. { could again be a classrefdef, but unlikely }
  2031. (tcallnode(methodpointer).methodpointer.resultdef.typ=objectdef) and
  2032. { don't go through this trouble if it was already a tobject }
  2033. (tcallnode(methodpointer).methodpointer.resultdef<>systobjectdef) then
  2034. begin
  2035. { register this object type as classref, so all descendents will also
  2036. be marked as instantiatable (only the pointeddef will actually be
  2037. recorded, so it's no problem that the clasrefdef is only temporary)
  2038. }
  2039. crefdef:=cclassrefdef.create(tcallnode(methodpointer).methodpointer.resultdef);
  2040. { and register it }
  2041. crefdef.register_created_object_type;
  2042. end
  2043. else
  2044. { the created class can be any child class as well -> register classrefdef }
  2045. methodpointer.resultdef.register_created_object_type;
  2046. end;
  2047. end;
  2048. end;
  2049. end
  2050. end
  2051. else
  2052. { Old style object }
  2053. if is_object(methodpointer.resultdef) then
  2054. begin
  2055. { constructor with extended syntax called from new }
  2056. if (cnf_new_call in callnodeflags) then
  2057. begin
  2058. if checklive(methodpointer.resultdef) then
  2059. methodpointer.resultdef.register_created_object_type;
  2060. end
  2061. else
  2062. { normal object call like obj.proc }
  2063. if not(cnf_dispose_call in callnodeflags) and
  2064. not(cnf_inherited in callnodeflags) and
  2065. not(cnf_member_call in callnodeflags) then
  2066. begin
  2067. if (procdefinition.proctypeoption=potype_constructor) then
  2068. begin
  2069. if (methodpointer.nodetype<>typen) and
  2070. checklive(methodpointer.resultdef) then
  2071. methodpointer.resultdef.register_created_object_type;
  2072. end
  2073. end;
  2074. end;
  2075. end;
  2076. function tcallnode.get_expect_loc: tcgloc;
  2077. var
  2078. realresdef: tstoreddef;
  2079. begin
  2080. if not assigned(typedef) then
  2081. realresdef:=tstoreddef(resultdef)
  2082. else
  2083. realresdef:=tstoreddef(typedef);
  2084. if realresdef.is_intregable then
  2085. result:=LOC_REGISTER
  2086. else if (realresdef.typ=floatdef) and
  2087. not(cs_fp_emulation in current_settings.moduleswitches) then
  2088. if use_vectorfpu(realresdef) then
  2089. result:=LOC_MMREGISTER
  2090. else
  2091. result:=LOC_FPUREGISTER
  2092. else
  2093. result:=LOC_REFERENCE
  2094. end;
  2095. procedure tcallnode.gen_syscall_para(para: tcallparanode);
  2096. begin
  2097. { unsupported }
  2098. internalerror(2014040101);
  2099. end;
  2100. procedure tcallnode.objc_convert_to_message_send;
  2101. var
  2102. block,
  2103. selftree : tnode;
  2104. statements : tstatementnode;
  2105. field : tfieldvarsym;
  2106. temp : ttempcreatenode;
  2107. selfrestype,
  2108. objcsupertype : tdef;
  2109. srsym : tsym;
  2110. srsymtable : tsymtable;
  2111. msgsendname : string;
  2112. begin
  2113. if not(m_objectivec1 in current_settings.modeswitches) then
  2114. Message(parser_f_modeswitch_objc_required);
  2115. { typecheck pass must already have run on the call node,
  2116. because pass1 calls this method
  2117. }
  2118. { default behaviour: call objc_msgSend and friends;
  2119. 64 bit targets for Mac OS X can override this as they
  2120. can call messages via an indirect function call similar to
  2121. dynamically linked functions, ARM maybe as well (not checked)
  2122. Which variant of objc_msgSend is used depends on the
  2123. result type, and on whether or not it's an inherited call.
  2124. }
  2125. { make sure we don't perform this transformation twice in case
  2126. firstpass would be called multiple times }
  2127. include(callnodeflags,cnf_objc_processed);
  2128. { make sure the methodpointer doesn't get translated into a call
  2129. as well (endless loop) }
  2130. if methodpointer.nodetype=loadvmtaddrn then
  2131. tloadvmtaddrnode(methodpointer).forcall:=true;
  2132. { A) set the appropriate objc_msgSend* variant to call }
  2133. { The AArch64 abi does not require special handling for struct returns }
  2134. {$ifndef aarch64}
  2135. { record returned via implicit pointer }
  2136. if paramanager.ret_in_param(resultdef,procdefinition) then
  2137. begin
  2138. if not(cnf_inherited in callnodeflags) then
  2139. msgsendname:='OBJC_MSGSEND_STRET'
  2140. {$if defined(onlymacosx10_6) or defined(arm) }
  2141. else if (target_info.system in systems_objc_nfabi) then
  2142. msgsendname:='OBJC_MSGSENDSUPER2_STRET'
  2143. {$endif onlymacosx10_6 or arm}
  2144. else
  2145. msgsendname:='OBJC_MSGSENDSUPER_STRET'
  2146. end
  2147. {$ifdef i386}
  2148. { special case for fpu results on i386 for non-inherited calls }
  2149. { TODO: also for x86_64 "extended" results }
  2150. else if (resultdef.typ=floatdef) and
  2151. not(cnf_inherited in callnodeflags) then
  2152. msgsendname:='OBJC_MSGSEND_FPRET'
  2153. {$endif i386}
  2154. { default }
  2155. else
  2156. {$endif aarch64}
  2157. if not(cnf_inherited in callnodeflags) then
  2158. msgsendname:='OBJC_MSGSEND'
  2159. {$if defined(onlymacosx10_6) or defined(arm) or defined(aarch64)}
  2160. else if (target_info.system in systems_objc_nfabi) then
  2161. msgsendname:='OBJC_MSGSENDSUPER2'
  2162. {$endif onlymacosx10_6 or arm}
  2163. else
  2164. msgsendname:='OBJC_MSGSENDSUPER';
  2165. { get the mangled name }
  2166. srsym:=nil;
  2167. if not searchsym_in_named_module('OBJC',msgsendname,srsym,srsymtable) or
  2168. (srsym.typ<>procsym) or
  2169. (tprocsym(srsym).ProcdefList.count<>1) then
  2170. Message1(cg_f_unknown_compilerproc,'objc.'+msgsendname);
  2171. {$ifdef symansistr}
  2172. fforcedprocname:=tprocdef(tprocsym(srsym).ProcdefList[0]).mangledname;
  2173. {$else symansistr}
  2174. fforcedprocname:=stringdup(tprocdef(tprocsym(srsym).ProcdefList[0]).mangledname);
  2175. {$endif symansistr}
  2176. { B) Handle self }
  2177. { 1) in case of sending a message to a superclass, self is a pointer to
  2178. an objc_super record
  2179. }
  2180. if (cnf_inherited in callnodeflags) then
  2181. begin
  2182. block:=internalstatements(statements);
  2183. objcsupertype:=search_named_unit_globaltype('OBJC','OBJC_SUPER',true).typedef;
  2184. if (objcsupertype.typ<>recorddef) then
  2185. internalerror(2009032901);
  2186. { temp for the for the objc_super record }
  2187. temp:=ctempcreatenode.create(objcsupertype,objcsupertype.size,tt_persistent,false);
  2188. addstatement(statements,temp);
  2189. { initialize objc_super record }
  2190. selftree:=call_self_node.getcopy;
  2191. { we can call an inherited class static/method from a regular method
  2192. -> self node must change from instance pointer to vmt pointer)
  2193. }
  2194. if (po_classmethod in procdefinition.procoptions) and
  2195. (selftree.resultdef.typ<>classrefdef) then
  2196. begin
  2197. selftree:=cloadvmtaddrnode.create(selftree);
  2198. { since we're in a class method of the current class, its
  2199. information has already been initialized (and that of all of
  2200. its parent classes too) }
  2201. tloadvmtaddrnode(selftree).forcall:=true;
  2202. typecheckpass(selftree);
  2203. end;
  2204. selfrestype:=selftree.resultdef;
  2205. field:=tfieldvarsym(trecorddef(objcsupertype).symtable.find('RECEIVER'));
  2206. if not assigned(field) then
  2207. internalerror(2009032902);
  2208. { first the destination object/class instance }
  2209. addstatement(statements,
  2210. cassignmentnode.create(
  2211. csubscriptnode.create(field,ctemprefnode.create(temp)),
  2212. selftree
  2213. )
  2214. );
  2215. { and secondly, the class type in which the selector must be looked
  2216. up (the parent class in case of an instance method, the parent's
  2217. metaclass in case of a class method) }
  2218. field:=tfieldvarsym(trecorddef(objcsupertype).symtable.find('_CLASS'));
  2219. if not assigned(field) then
  2220. internalerror(2009032903);
  2221. addstatement(statements,
  2222. cassignmentnode.create(
  2223. csubscriptnode.create(field,ctemprefnode.create(temp)),
  2224. objcsuperclassnode(selftree.resultdef)
  2225. )
  2226. );
  2227. { result of this block is the address of this temp }
  2228. addstatement(statements,ctypeconvnode.create_internal(
  2229. caddrnode.create_internal(ctemprefnode.create(temp)),selfrestype)
  2230. );
  2231. { replace the method pointer with the address of this temp }
  2232. methodpointer.free;
  2233. methodpointer:=block;
  2234. typecheckpass(block);
  2235. end
  2236. else
  2237. { 2) regular call (not inherited) }
  2238. begin
  2239. { a) If we're calling a class method, use a class ref. }
  2240. if (po_classmethod in procdefinition.procoptions) and
  2241. ((methodpointer.nodetype=typen) or
  2242. (methodpointer.resultdef.typ<>classrefdef)) then
  2243. begin
  2244. methodpointer:=cloadvmtaddrnode.create(methodpointer);
  2245. { no need to obtain the class ref by calling class(), sending
  2246. this message will initialize it if necessary }
  2247. tloadvmtaddrnode(methodpointer).forcall:=true;
  2248. firstpass(methodpointer);
  2249. end;
  2250. end;
  2251. end;
  2252. function tcallnode.gen_vmt_tree:tnode;
  2253. var
  2254. vmttree : tnode;
  2255. begin
  2256. vmttree:=nil;
  2257. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  2258. internalerror(200305051);
  2259. { When methodpointer was a callnode we must load it first into a
  2260. temp to prevent the processing callnode twice }
  2261. if (methodpointer.nodetype=calln) then
  2262. internalerror(200405122);
  2263. { Handle classes and legacy objects separate to make it
  2264. more maintainable }
  2265. if (methodpointer.resultdef.typ=classrefdef) then
  2266. begin
  2267. if not is_class(tclassrefdef(methodpointer.resultdef).pointeddef) then
  2268. internalerror(200501041);
  2269. { constructor call via classreference => allocate memory }
  2270. if (procdefinition.proctypeoption=potype_constructor) then
  2271. begin
  2272. vmttree:=cpointerconstnode.create(1,voidpointertype);
  2273. end
  2274. else { <class of xx>.destroy is not valid }
  2275. InternalError(2014020601);
  2276. end
  2277. else
  2278. { Class style objects }
  2279. if is_class(methodpointer.resultdef) then
  2280. begin
  2281. { inherited call, no create/destroy }
  2282. if (cnf_inherited in callnodeflags) then
  2283. vmttree:=cpointerconstnode.create(0,voidpointertype)
  2284. else
  2285. { do not create/destroy when called from member function
  2286. without specifying self explicit }
  2287. if (cnf_member_call in callnodeflags) then
  2288. begin
  2289. { destructor (in the same class, since cnf_member_call):
  2290. if not called from a destructor then
  2291. call beforedestruction and release instance, vmt=1
  2292. else
  2293. don't release instance, vmt=0
  2294. constructor (in the same class, since cnf_member_call):
  2295. if called from a constructor then
  2296. don't call afterconstruction, vmt=0
  2297. else
  2298. call afterconstrution but not NewInstance, vmt=-1 }
  2299. if (procdefinition.proctypeoption=potype_destructor) then
  2300. if (current_procinfo.procdef.proctypeoption<>potype_constructor) then
  2301. vmttree:=cpointerconstnode.create(1,voidpointertype)
  2302. else
  2303. vmttree:=cpointerconstnode.create(0,voidpointertype)
  2304. else if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  2305. (procdefinition.proctypeoption=potype_constructor) then
  2306. vmttree:=cpointerconstnode.create(0,voidpointertype)
  2307. else
  2308. vmttree:=cpointerconstnode.create(TConstPtrUInt(-1),voidpointertype);
  2309. end
  2310. else
  2311. { normal call to method like cl1.proc }
  2312. begin
  2313. { destructor:
  2314. if not called from exception block in constructor
  2315. call beforedestruction and release instance, vmt=1
  2316. else
  2317. don't call beforedestruction and release instance, vmt=-1
  2318. constructor:
  2319. if called from a constructor in the same class using self.create then
  2320. don't call afterconstruction, vmt=0
  2321. else
  2322. call afterconstruction, vmt=1 }
  2323. if (procdefinition.proctypeoption=potype_destructor) then
  2324. if not(cnf_create_failed in callnodeflags) then
  2325. vmttree:=cpointerconstnode.create(1,voidpointertype)
  2326. else
  2327. vmttree:=cpointerconstnode.create(TConstPtrUInt(-1),voidpointertype)
  2328. else
  2329. begin
  2330. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  2331. (procdefinition.proctypeoption=potype_constructor) and
  2332. (methodpointer.nodetype=loadn) and
  2333. (loadnf_is_self in tloadnode(methodpointer).loadnodeflags) then
  2334. vmttree:=cpointerconstnode.create(0,voidpointertype)
  2335. else
  2336. vmttree:=cpointerconstnode.create(TConstPtrUInt(-1),voidpointertype);
  2337. end;
  2338. end;
  2339. end
  2340. else
  2341. { Old style object }
  2342. begin
  2343. { constructor with extended syntax called from new }
  2344. if (cnf_new_call in callnodeflags) then
  2345. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resultdef))
  2346. else
  2347. { destructor with extended syntax called from dispose }
  2348. { value -1 is what fpc_help_constructor() changes VMT to when it allocates memory }
  2349. if (cnf_dispose_call in callnodeflags) then
  2350. vmttree:=cpointerconstnode.create(TConstPtrUInt(-1),voidpointertype)
  2351. else
  2352. { destructor called from exception block in constructor }
  2353. if (cnf_create_failed in callnodeflags) then
  2354. vmttree:=ctypeconvnode.create_internal(call_vmt_node.getcopy,voidpointertype)
  2355. else
  2356. { inherited call, no create/destroy }
  2357. if (cnf_inherited in callnodeflags) then
  2358. vmttree:=cpointerconstnode.create(0,voidpointertype)
  2359. else
  2360. { do not create/destroy when called from member function
  2361. without specifying self explicit }
  2362. if (cnf_member_call in callnodeflags) then
  2363. begin
  2364. { destructor: don't release instance, vmt=0
  2365. constructor: don't initialize instance, vmt=0 }
  2366. vmttree:=cpointerconstnode.create(0,voidpointertype)
  2367. end
  2368. else
  2369. { normal object call like obj.proc }
  2370. begin
  2371. { destructor: direct call, no dispose, vmt=0
  2372. constructor: initialize object, load vmt }
  2373. if (procdefinition.proctypeoption=potype_constructor) then
  2374. begin
  2375. { old styled inherited call? }
  2376. if (methodpointer.nodetype=typen) then
  2377. vmttree:=cpointerconstnode.create(0,voidpointertype)
  2378. else
  2379. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resultdef))
  2380. end
  2381. else
  2382. vmttree:=cpointerconstnode.create(0,voidpointertype);
  2383. end;
  2384. end;
  2385. result:=vmttree;
  2386. end;
  2387. function tcallnode.gen_block_context: tnode;
  2388. begin
  2389. { the self parameter of a block invocation is that address of the
  2390. block literal (which is what right contains) }
  2391. result:=right.getcopy;
  2392. end;
  2393. function check_funcret_used_as_para(var n: tnode; arg: pointer): foreachnoderesult;
  2394. var
  2395. destsym : tsym absolute arg;
  2396. begin
  2397. result := fen_false;
  2398. if (n.nodetype=loadn) and
  2399. (tloadnode(n).symtableentry = destsym) then
  2400. result := fen_norecurse_true;
  2401. end;
  2402. function tcallnode.funcret_can_be_reused:boolean;
  2403. var
  2404. realassignmenttarget: tnode;
  2405. alignment: longint;
  2406. begin
  2407. result:=false;
  2408. { we are processing an assignment node? }
  2409. if not(assigned(aktassignmentnode) and
  2410. (aktassignmentnode.right=self) and
  2411. (aktassignmentnode.left.resultdef=resultdef)) then
  2412. exit;
  2413. { destination must be able to be passed as var parameter }
  2414. if not valid_for_var(aktassignmentnode.left,false) then
  2415. exit;
  2416. { destination must be a simple load so it doesn't need a temp when
  2417. it is evaluated }
  2418. if not is_simple_para_load(aktassignmentnode.left,false) then
  2419. exit;
  2420. { remove possible typecasts }
  2421. realassignmenttarget:=actualtargetnode(@aktassignmentnode.left)^;
  2422. { when it is not passed in a parameter it will only be used after the
  2423. function call }
  2424. if not paramanager.ret_in_param(resultdef,procdefinition) then
  2425. begin
  2426. { don't replace the function result if we are inlining and if the destination is complex, this
  2427. could lead to lengthy code in case the function result is used often and it is assigned e.g.
  2428. to a threadvar }
  2429. result:=not(cnf_do_inline in callnodeflags) or
  2430. (node_complexity(aktassignmentnode.left)<=1);
  2431. exit;
  2432. end;
  2433. { if the result is the same as the self parameter (in case of objects),
  2434. we can't optimise. We have to check this explicitly becaise
  2435. hidden parameters such as self have not yet been inserted at this
  2436. point
  2437. }
  2438. if assigned(methodpointer) and
  2439. realassignmenttarget.isequal(actualtargetnode(@methodpointer)^) then
  2440. exit;
  2441. { when we substitute a function result inside an inlined function,
  2442. we may take the address of this function result. Therefore the
  2443. substituted function result may not be in a register, as we cannot
  2444. take its address in that case }
  2445. if (realassignmenttarget.nodetype=temprefn) and
  2446. not(ti_addr_taken in ttemprefnode(realassignmenttarget).tempinfo^.flags) and
  2447. not(ti_may_be_in_reg in ttemprefnode(realassignmenttarget).tempinfo^.flags) then
  2448. begin
  2449. result:=true;
  2450. exit;
  2451. end;
  2452. if (realassignmenttarget.nodetype=loadn) and
  2453. { nested procedures may access the current procedure's locals }
  2454. (procdefinition.parast.symtablelevel=normal_function_level) and
  2455. { must be a local variable, a value para or a hidden function result }
  2456. { parameter (which can be passed by address, but in that case it got }
  2457. { through these same checks at the caller side and is thus safe }
  2458. (
  2459. (tloadnode(realassignmenttarget).symtableentry.typ=localvarsym) or
  2460. (
  2461. (tloadnode(realassignmenttarget).symtableentry.typ=paravarsym) and
  2462. ((tparavarsym(tloadnode(realassignmenttarget).symtableentry).varspez = vs_value) or
  2463. (vo_is_funcret in tparavarsym(tloadnode(realassignmenttarget).symtableentry).varoptions))
  2464. )
  2465. ) and
  2466. { the address may not have been taken of the variable/parameter, because }
  2467. { otherwise it's possible that the called function can access it via a }
  2468. { global variable or other stored state }
  2469. (
  2470. not(tabstractvarsym(tloadnode(realassignmenttarget).symtableentry).addr_taken) and
  2471. (tabstractvarsym(tloadnode(realassignmenttarget).symtableentry).varregable in [vr_none,vr_addr])
  2472. ) then
  2473. begin
  2474. { If the funcret is also used as a parameter we can't optimize because the funcret
  2475. and the parameter will point to the same address. That means that a change of the result variable
  2476. will result also in a change of the parameter value }
  2477. result:=not foreachnodestatic(left,@check_funcret_used_as_para,tloadnode(realassignmenttarget).symtableentry);
  2478. { ensure that it is aligned using the default alignment }
  2479. alignment:=tabstractvarsym(tloadnode(realassignmenttarget).symtableentry).vardef.alignment;
  2480. if (used_align(alignment,target_info.alignment.localalignmin,target_info.alignment.localalignmax)<>
  2481. used_align(alignment,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax)) then
  2482. result:=false;
  2483. exit;
  2484. end;
  2485. end;
  2486. procedure tcallnode.maybe_create_funcret_node;
  2487. var
  2488. temp : ttempcreatenode;
  2489. begin
  2490. if procdefinition.proctypeoption=potype_constructor then
  2491. exit;
  2492. { For the function result we need to create a temp node for:
  2493. - Inlined functions
  2494. - Types requiring initialization/finalization
  2495. - Types passed in parameters }
  2496. if not is_void(resultdef) and
  2497. not assigned(funcretnode) and
  2498. (
  2499. (cnf_do_inline in callnodeflags) or
  2500. is_managed_type(resultdef) or
  2501. paramanager.ret_in_param(resultdef,procdefinition)
  2502. ) then
  2503. begin
  2504. { Optimize calls like x:=f() where we can use x directly as
  2505. result instead of using a temp. Condition is that x cannot be accessed from f().
  2506. This implies that x is a local variable or value parameter of the current block
  2507. and its address is not passed to f. One problem: what if someone takes the
  2508. address of x, puts it in a pointer variable/field and then accesses it that way
  2509. from within the function? This is solved (in a conservative way) using the
  2510. ti_addr_taken flag.
  2511. When the result is not not passed in a parameter there are no problem because
  2512. then it means only reference counted types (eg. ansistrings) that need a decr
  2513. of the refcount before being assigned. This is all done after the call so there
  2514. is no issue with exceptions and possible use of the old value in the called
  2515. function }
  2516. if funcret_can_be_reused then
  2517. begin
  2518. funcretnode:=aktassignmentnode.left.getcopy;
  2519. include(funcretnode.flags,nf_is_funcret);
  2520. { notify the assignment node that the assignment can be removed }
  2521. include(aktassignmentnode.flags,nf_assign_done_in_right);
  2522. end
  2523. else
  2524. begin
  2525. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,
  2526. (cnf_do_inline in callnodeflags) and
  2527. not(tabstractvarsym(tprocdef(procdefinition).funcretsym).varregable in [vr_none,vr_addr]));
  2528. include(temp.flags,nf_is_funcret);
  2529. { if a managed type is returned by reference, assigning something
  2530. to the result on the caller side will take care of decreasing
  2531. the reference count }
  2532. if paramanager.ret_in_param(resultdef,procdefinition) then
  2533. include(temp.tempinfo^.flags,ti_nofini);
  2534. add_init_statement(temp);
  2535. { When the function result is not used in an inlined function
  2536. we need to delete the temp. This can currently only be done by
  2537. a tempdeletenode and not after converting it to a normal temp }
  2538. if not(cnf_return_value_used in callnodeflags) and
  2539. (cnf_do_inline in callnodeflags) then
  2540. add_done_statement(ctempdeletenode.create(temp))
  2541. else
  2542. add_done_statement(ctempdeletenode.create_normal_temp(temp));
  2543. funcretnode:=ctemprefnode.create(temp);
  2544. include(funcretnode.flags,nf_is_funcret);
  2545. end;
  2546. end;
  2547. end;
  2548. procedure tcallnode.gen_hidden_parameters;
  2549. var
  2550. para : tcallparanode;
  2551. begin
  2552. para:=tcallparanode(left);
  2553. while assigned(para) do
  2554. begin
  2555. { The processing of high() and typeinfo() is already
  2556. done in the typecheckpass. We only need to process the
  2557. nodes that still have a nothingn }
  2558. if (vo_is_hidden_para in para.parasym.varoptions) and
  2559. (para.left.nodetype=nothingn) then
  2560. begin
  2561. { remove dummy nothingn }
  2562. para.left.free;
  2563. para.left:=nil;
  2564. { generate the corresponding nodes for the hidden parameter type }
  2565. if (vo_is_funcret in para.parasym.varoptions) then
  2566. begin
  2567. if not assigned(funcretnode) then
  2568. internalerror(200709083);
  2569. para.left:=funcretnode;
  2570. funcretnode:=nil;
  2571. end
  2572. else
  2573. if vo_is_self in para.parasym.varoptions then
  2574. begin
  2575. if assigned(right) then
  2576. para.left:=gen_procvar_context_tree_self
  2577. else
  2578. para.left:=gen_self_tree;
  2579. { make sure that e.g. the self pointer of an advanced
  2580. record does not become a regvar, because it's a vs_var
  2581. parameter }
  2582. if paramanager.push_addr_param(para.parasym.varspez,para.parasym.vardef,
  2583. procdefinition.proccalloption) then
  2584. make_not_regable(para.left,[ra_addr_regable]);
  2585. end
  2586. else
  2587. if vo_is_vmt in para.parasym.varoptions then
  2588. begin
  2589. para.left:=gen_vmt_tree;
  2590. end
  2591. else
  2592. if vo_is_syscall_lib in para.parasym.varoptions then
  2593. gen_syscall_para(para)
  2594. else
  2595. if vo_is_parentfp in para.parasym.varoptions then
  2596. begin
  2597. if not assigned(right) then
  2598. begin
  2599. if assigned(procdefinition.owner.defowner) then
  2600. para.left:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner),lpf_forpara)
  2601. { exceptfilters called from main level are not owned }
  2602. else if procdefinition.proctypeoption=potype_exceptfilter then
  2603. para.left:=cloadparentfpnode.create(current_procinfo.procdef,lpf_forpara)
  2604. else
  2605. internalerror(200309287);
  2606. end
  2607. else if not(po_is_block in procdefinition.procoptions) then
  2608. para.left:=gen_procvar_context_tree_parentfp
  2609. else
  2610. para.left:=gen_block_context
  2611. end
  2612. else
  2613. if vo_is_range_check in para.parasym.varoptions then
  2614. begin
  2615. para.left:=cordconstnode.create(Ord(cs_check_range in current_settings.localswitches),pasbool8type,false);
  2616. end
  2617. else
  2618. if vo_is_overflow_check in para.parasym.varoptions then
  2619. begin
  2620. para.left:=cordconstnode.create(Ord(cs_check_overflow in current_settings.localswitches),pasbool8type,false);
  2621. end
  2622. else
  2623. if vo_is_msgsel in para.parasym.varoptions then
  2624. begin
  2625. para.left:=cobjcselectornode.create(cstringconstnode.createstr(tprocdef(procdefinition).messageinf.str^));
  2626. end;
  2627. end;
  2628. if not assigned(para.left) then
  2629. internalerror(200709084);
  2630. para:=tcallparanode(para.right);
  2631. end;
  2632. end;
  2633. procedure tcallnode.verifyabstract(sym:TObject;arg:pointer);
  2634. var
  2635. pd : tprocdef;
  2636. i : longint;
  2637. j : integer;
  2638. hs : string;
  2639. begin
  2640. if (tsym(sym).typ<>procsym) then
  2641. exit;
  2642. for i:=0 to tprocsym(sym).ProcdefList.Count-1 do
  2643. begin
  2644. pd:=tprocdef(tprocsym(sym).ProcdefList[i]);
  2645. hs:=pd.procsym.name+pd.typename_paras([]);
  2646. j:=AbstractMethodsList.FindIndexOf(hs);
  2647. if j<>-1 then
  2648. AbstractMethodsList[j]:=pd
  2649. else
  2650. AbstractMethodsList.Add(hs,pd);
  2651. end;
  2652. end;
  2653. procedure tcallnode.verifyabstractcalls;
  2654. var
  2655. objectdf : tobjectdef;
  2656. parents : tlinkedlist;
  2657. objectinfo : tobjectinfoitem;
  2658. pd : tprocdef;
  2659. i : integer;
  2660. begin
  2661. objectdf := nil;
  2662. { verify if trying to create an instance of a class which contains
  2663. non-implemented abstract methods }
  2664. { first verify this class type, no class than exit }
  2665. { also, this checking can only be done if the constructor is directly
  2666. called, indirect constructor calls cannot be checked.
  2667. }
  2668. if assigned(methodpointer) and
  2669. not((methodpointer.nodetype=loadn) and
  2670. (loadnf_is_self in tloadnode(methodpointer).loadnodeflags)) then
  2671. begin
  2672. if (methodpointer.resultdef.typ = objectdef) then
  2673. objectdf:=tobjectdef(methodpointer.resultdef)
  2674. else
  2675. if (methodpointer.resultdef.typ = classrefdef) and
  2676. (tclassrefdef(methodpointer.resultdef).pointeddef.typ = objectdef) and
  2677. (methodpointer.nodetype in [typen,loadvmtaddrn]) then
  2678. objectdf:=tobjectdef(tclassrefdef(methodpointer.resultdef).pointeddef);
  2679. end;
  2680. if not assigned(objectdf) then
  2681. exit;
  2682. { quick exit if nothing to check }
  2683. if objectdf.abstractcnt = 0 then
  2684. exit;
  2685. parents := tlinkedlist.create;
  2686. AbstractMethodsList := TFPHashList.create;
  2687. { insert all parents in this class : the first item in the
  2688. list will be the base parent of the class .
  2689. }
  2690. while assigned(objectdf) do
  2691. begin
  2692. objectinfo:=tobjectinfoitem.create(objectdf);
  2693. parents.insert(objectinfo);
  2694. objectdf := objectdf.childof;
  2695. end;
  2696. { now all parents are in the correct order
  2697. insert all abstract methods in the list, and remove
  2698. those which are overridden by parent classes.
  2699. }
  2700. objectinfo:=tobjectinfoitem(parents.first);
  2701. while assigned(objectinfo) do
  2702. begin
  2703. objectdf := objectinfo.objinfo;
  2704. if assigned(objectdf.symtable) then
  2705. objectdf.symtable.SymList.ForEachCall(@verifyabstract,nil);
  2706. objectinfo:=tobjectinfoitem(objectinfo.next);
  2707. end;
  2708. if assigned(parents) then
  2709. parents.free;
  2710. { Finally give out a warning for each abstract method still in the list }
  2711. for i:=0 to AbstractMethodsList.Count-1 do
  2712. begin
  2713. pd:=tprocdef(AbstractMethodsList[i]);
  2714. if po_abstractmethod in pd.procoptions then
  2715. begin
  2716. Message2(type_w_instance_with_abstract,objectdf.objrealname^,pd.procsym.RealName);
  2717. MessagePos1(pd.fileinfo,sym_h_abstract_method_list,pd.fullprocname(true));
  2718. end;
  2719. end;
  2720. if assigned(AbstractMethodsList) then
  2721. AbstractMethodsList.Free;
  2722. end;
  2723. procedure tcallnode.convert_carg_array_of_const;
  2724. var
  2725. hp : tarrayconstructornode;
  2726. oldleft : tcallparanode;
  2727. begin
  2728. oldleft:=tcallparanode(left);
  2729. if oldleft.left.nodetype<>arrayconstructorn then
  2730. begin
  2731. CGMessage1(type_e_wrong_type_in_array_constructor,oldleft.left.resultdef.typename);
  2732. exit;
  2733. end;
  2734. include(callnodeflags,cnf_uses_varargs);
  2735. { Get arrayconstructor node and insert typeconvs }
  2736. hp:=tarrayconstructornode(oldleft.left);
  2737. { Add c args parameters }
  2738. { It could be an empty set }
  2739. if assigned(hp) and
  2740. assigned(hp.left) then
  2741. begin
  2742. while assigned(hp) do
  2743. begin
  2744. left:=ccallparanode.create(hp.left,left);
  2745. { set callparanode resultdef and flags }
  2746. left.resultdef:=hp.left.resultdef;
  2747. include(tcallparanode(left).callparaflags,cpf_varargs_para);
  2748. hp.left:=nil;
  2749. hp:=tarrayconstructornode(hp.right);
  2750. end;
  2751. end;
  2752. { Remove value of old array of const parameter, but keep it
  2753. in the list because it is required for bind_parasym.
  2754. Generate a nothign to keep callparanoed.left valid }
  2755. oldleft.left.free;
  2756. oldleft.left:=cnothingnode.create;
  2757. end;
  2758. procedure tcallnode.bind_parasym;
  2759. type
  2760. pcallparanode = ^tcallparanode;
  2761. var
  2762. i : integer;
  2763. pt : tcallparanode;
  2764. oldppt : pcallparanode;
  2765. varargspara,
  2766. currpara : tparavarsym;
  2767. hiddentree : tnode;
  2768. paradef : tdef;
  2769. begin
  2770. pt:=tcallparanode(left);
  2771. oldppt:=pcallparanode(@left);
  2772. { flag all callparanodes that belong to the varargs }
  2773. i:=paralength;
  2774. while (i>procdefinition.maxparacount) do
  2775. begin
  2776. include(pt.callparaflags,cpf_varargs_para);
  2777. oldppt:=pcallparanode(@pt.right);
  2778. pt:=tcallparanode(pt.right);
  2779. dec(i);
  2780. end;
  2781. { skip varargs that are inserted by array of const }
  2782. while assigned(pt) and
  2783. (cpf_varargs_para in pt.callparaflags) do
  2784. pt:=tcallparanode(pt.right);
  2785. { process normal parameters and insert hidden parameter nodes, the content
  2786. of the hidden parameters will be updated in pass1 }
  2787. for i:=procdefinition.paras.count-1 downto 0 do
  2788. begin
  2789. currpara:=tparavarsym(procdefinition.paras[i]);
  2790. if vo_is_hidden_para in currpara.varoptions then
  2791. begin
  2792. { Here we handle only the parameters that depend on
  2793. the types of the previous parameter. The typeconversion
  2794. can change the type in the next step. For example passing
  2795. an array can be change to a pointer and a deref }
  2796. if vo_is_high_para in currpara.varoptions then
  2797. begin
  2798. if not assigned(pt) or (i=0) then
  2799. internalerror(200304081);
  2800. { we need the information of the previous parameter }
  2801. paradef:=tparavarsym(procdefinition.paras[i-1]).vardef;
  2802. hiddentree:=gen_high_tree(pt.left,paradef);
  2803. { for open array of managed type, a copy of high parameter is
  2804. necessary to properly initialize before the call }
  2805. if is_open_array(paradef) and
  2806. (tparavarsym(procdefinition.paras[i-1]).varspez=vs_out) and
  2807. is_managed_type(tarraydef(paradef).elementdef) then
  2808. begin
  2809. typecheckpass(hiddentree);
  2810. {this eliminates double call to fpc_dynarray_high, if any}
  2811. maybe_load_in_temp(hiddentree);
  2812. oldppt^.third:=hiddentree.getcopy;
  2813. end;
  2814. end
  2815. else
  2816. if vo_is_typinfo_para in currpara.varoptions then
  2817. begin
  2818. if not assigned(pt) or (i=0) then
  2819. internalerror(200304082);
  2820. hiddentree:=caddrnode.create_internal(
  2821. crttinode.create(Tstoreddef(pt.resultdef),fullrtti,rdt_normal)
  2822. );
  2823. end
  2824. else
  2825. hiddentree:=cnothingnode.create;
  2826. pt:=ccallparanode.create(hiddentree,oldppt^);
  2827. oldppt^:=pt;
  2828. end;
  2829. if not assigned(pt) then
  2830. internalerror(200310052);
  2831. pt.parasym:=currpara;
  2832. oldppt:=pcallparanode(@pt.right);
  2833. pt:=tcallparanode(pt.right);
  2834. end;
  2835. { Create parasyms for varargs, first count the number of varargs paras,
  2836. then insert the parameters with numbering in reverse order. The SortParas
  2837. will set the correct order at the end}
  2838. pt:=tcallparanode(left);
  2839. i:=0;
  2840. while assigned(pt) do
  2841. begin
  2842. if cpf_varargs_para in pt.callparaflags then
  2843. inc(i);
  2844. pt:=tcallparanode(pt.right);
  2845. end;
  2846. if (i>0) then
  2847. begin
  2848. include(current_procinfo.flags,pi_calls_c_varargs);
  2849. varargsparas:=tvarargsparalist.create;
  2850. pt:=tcallparanode(left);
  2851. while assigned(pt) do
  2852. begin
  2853. if cpf_varargs_para in pt.callparaflags then
  2854. begin
  2855. varargspara:=cparavarsym.create('va'+tostr(i),i,vs_value,pt.resultdef,[]);
  2856. dec(i);
  2857. { varargspara is left-right, use insert
  2858. instead of concat }
  2859. varargsparas.add(varargspara);
  2860. pt.parasym:=varargspara;
  2861. end;
  2862. pt:=tcallparanode(pt.right);
  2863. end;
  2864. varargsparas.sortparas;
  2865. end;
  2866. end;
  2867. function tcallnode.pass_typecheck:tnode;
  2868. var
  2869. candidates : tcallcandidates;
  2870. oldcallnode : tcallnode;
  2871. hpt : tnode;
  2872. pt : tcallparanode;
  2873. lastpara : longint;
  2874. paraidx,
  2875. cand_cnt : integer;
  2876. i : longint;
  2877. ignorevisibility,
  2878. is_const : boolean;
  2879. statements : tstatementnode;
  2880. converted_result_data : ttempcreatenode;
  2881. calltype: tdispcalltype;
  2882. begin
  2883. result:=nil;
  2884. candidates:=nil;
  2885. oldcallnode:=aktcallnode;
  2886. aktcallnode:=self;
  2887. try
  2888. { determine length of parameter list }
  2889. pt:=tcallparanode(left);
  2890. paralength:=0;
  2891. while assigned(pt) do
  2892. begin
  2893. inc(paralength);
  2894. pt:=tcallparanode(pt.right);
  2895. end;
  2896. { determine the type of the parameters }
  2897. if assigned(left) then
  2898. begin
  2899. tcallparanode(left).get_paratype;
  2900. if codegenerror then
  2901. exit;
  2902. end;
  2903. if assigned(methodpointer) then
  2904. typecheckpass(methodpointer);
  2905. { procedure variable ? }
  2906. if assigned(right) then
  2907. begin
  2908. set_varstate(right,vs_read,[vsf_must_be_valid]);
  2909. typecheckpass(right);
  2910. if codegenerror then
  2911. exit;
  2912. procdefinition:=tabstractprocdef(right.resultdef);
  2913. { Compare parameters from right to left }
  2914. paraidx:=procdefinition.Paras.count-1;
  2915. { Skip default parameters }
  2916. if not(po_varargs in procdefinition.procoptions) then
  2917. begin
  2918. { ignore hidden parameters }
  2919. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  2920. dec(paraidx);
  2921. for i:=1 to procdefinition.maxparacount-paralength do
  2922. begin
  2923. if paraidx<0 then
  2924. internalerror(200402265);
  2925. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  2926. begin
  2927. CGMessage1(parser_e_wrong_parameter_size,'<Procedure Variable>');
  2928. exit;
  2929. end;
  2930. dec(paraidx);
  2931. end;
  2932. end;
  2933. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  2934. dec(paraidx);
  2935. pt:=tcallparanode(left);
  2936. lastpara:=paralength;
  2937. while (paraidx>=0) and assigned(pt) do
  2938. begin
  2939. { only goto next para if we're out of the varargs }
  2940. if not(po_varargs in procdefinition.procoptions) or
  2941. (lastpara<=procdefinition.maxparacount) then
  2942. begin
  2943. repeat
  2944. dec(paraidx);
  2945. until (paraidx<0) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  2946. end;
  2947. pt:=tcallparanode(pt.right);
  2948. dec(lastpara);
  2949. end;
  2950. if assigned(pt) or
  2951. ((paraidx>=0) and
  2952. not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)) then
  2953. begin
  2954. if assigned(pt) then
  2955. current_filepos:=pt.fileinfo;
  2956. CGMessage1(parser_e_wrong_parameter_size,'<Procedure Variable>');
  2957. exit;
  2958. end;
  2959. end
  2960. else
  2961. { not a procedure variable }
  2962. begin
  2963. { do we know the procedure to call ? }
  2964. if not(assigned(procdefinition)) then
  2965. begin
  2966. { ignore possible private for properties or in delphi mode for anon. inherited (FK) }
  2967. ignorevisibility:=(nf_isproperty in flags) or
  2968. ((m_delphi in current_settings.modeswitches) and (cnf_anon_inherited in callnodeflags));
  2969. candidates:=tcallcandidates.create(symtableprocentry,symtableproc,left,ignorevisibility,
  2970. not(nf_isproperty in flags),cnf_objc_id_call in callnodeflags,cnf_unit_specified in callnodeflags,
  2971. callnodeflags*[cnf_anon_inherited,cnf_inherited]=[],cnf_anon_inherited in callnodeflags);
  2972. { no procedures found? then there is something wrong
  2973. with the parameter size or the procedures are
  2974. not accessible }
  2975. if candidates.count=0 then
  2976. begin
  2977. { when it's an auto inherited call and there
  2978. is no procedure found, but the procedures
  2979. were defined with overload directive and at
  2980. least two procedures are defined then we ignore
  2981. this inherited by inserting a nothingn. Only
  2982. do this ugly hack in Delphi mode as it looks more
  2983. like a bug. It's also not documented }
  2984. if (m_delphi in current_settings.modeswitches) and
  2985. (cnf_anon_inherited in callnodeflags) and
  2986. (symtableprocentry.owner.symtabletype=ObjectSymtable) and
  2987. (po_overload in tprocdef(symtableprocentry.ProcdefList[0]).procoptions) and
  2988. (symtableprocentry.ProcdefList.Count>=2) then
  2989. result:=cnothingnode.create
  2990. else
  2991. begin
  2992. { in tp mode we can try to convert to procvar if
  2993. there are no parameters specified }
  2994. if not(assigned(left)) and
  2995. not(cnf_inherited in callnodeflags) and
  2996. ((m_tp_procvar in current_settings.modeswitches) or
  2997. (m_mac_procvar in current_settings.modeswitches)) and
  2998. (not assigned(methodpointer) or
  2999. (methodpointer.nodetype <> typen)) then
  3000. begin
  3001. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  3002. if assigned(methodpointer) then
  3003. tloadnode(hpt).set_mp(methodpointer.getcopy);
  3004. typecheckpass(hpt);
  3005. result:=hpt;
  3006. end
  3007. else
  3008. begin
  3009. CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,symtableprocentry.realname);
  3010. symtableprocentry.write_parameter_lists(nil);
  3011. end;
  3012. end;
  3013. candidates.free;
  3014. exit;
  3015. end;
  3016. { Retrieve information about the candidates }
  3017. candidates.get_information;
  3018. {$ifdef EXTDEBUG}
  3019. { Display info when multiple candidates are found }
  3020. if candidates.count>1 then
  3021. candidates.dump_info(V_Debug);
  3022. {$endif EXTDEBUG}
  3023. { Choose the best candidate and count the number of
  3024. candidates left }
  3025. cand_cnt:=candidates.choose_best(procdefinition,
  3026. assigned(left) and
  3027. not assigned(tcallparanode(left).right) and
  3028. (tcallparanode(left).left.resultdef.typ=variantdef));
  3029. { All parameters are checked, check if there are any
  3030. procedures left }
  3031. if cand_cnt>0 then
  3032. begin
  3033. { Multiple candidates left? }
  3034. if cand_cnt>1 then
  3035. begin
  3036. CGMessage(type_e_cant_choose_overload_function);
  3037. {$ifdef EXTDEBUG}
  3038. candidates.dump_info(V_Hint);
  3039. {$else EXTDEBUG}
  3040. candidates.list(false);
  3041. {$endif EXTDEBUG}
  3042. { we'll just use the first candidate to make the
  3043. call }
  3044. end;
  3045. { assign procdefinition }
  3046. if symtableproc=nil then
  3047. symtableproc:=procdefinition.owner;
  3048. end
  3049. else
  3050. begin
  3051. { No candidates left, this must be a type error,
  3052. because wrong size is already checked. procdefinition
  3053. is filled with the first (random) definition that is
  3054. found. We use this definition to display a nice error
  3055. message that the wrong type is passed }
  3056. candidates.find_wrong_para;
  3057. candidates.list(true);
  3058. {$ifdef EXTDEBUG}
  3059. candidates.dump_info(V_Hint);
  3060. {$endif EXTDEBUG}
  3061. { We can not proceed, release all procs and exit }
  3062. candidates.free;
  3063. exit;
  3064. end;
  3065. candidates.free;
  3066. end; { end of procedure to call determination }
  3067. end;
  3068. { check for hints (deprecated etc) }
  3069. if procdefinition.typ = procdef then
  3070. check_hints(tprocdef(procdefinition).procsym,tprocdef(procdefinition).symoptions,tprocdef(procdefinition).deprecatedmsg);
  3071. { add reference to corresponding procsym; may not be the one
  3072. originally found/passed to the constructor because of overloads }
  3073. if procdefinition.typ = procdef then
  3074. addsymref(tprocdef(procdefinition).procsym);
  3075. { add needed default parameters }
  3076. if (paralength<procdefinition.maxparacount) then
  3077. begin
  3078. paraidx:=0;
  3079. i:=0;
  3080. while (i<paralength) do
  3081. begin
  3082. if paraidx>=procdefinition.Paras.count then
  3083. internalerror(200306181);
  3084. if not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) then
  3085. inc(i);
  3086. inc(paraidx);
  3087. end;
  3088. while (paraidx<procdefinition.paras.count) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  3089. inc(paraidx);
  3090. while (paraidx<procdefinition.paras.count) do
  3091. begin
  3092. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  3093. internalerror(200212142);
  3094. left:=ccallparanode.create(genconstsymtree(
  3095. tconstsym(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)),left);
  3096. { Ignore vs_hidden parameters }
  3097. repeat
  3098. inc(paraidx);
  3099. until (paraidx>=procdefinition.paras.count) or
  3100. not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  3101. end;
  3102. end;
  3103. { recursive call? }
  3104. if assigned(current_procinfo) and
  3105. (procdefinition=current_procinfo.procdef) then
  3106. include(current_procinfo.flags,pi_is_recursive);
  3107. { handle predefined procedures }
  3108. is_const:=(po_internconst in procdefinition.procoptions) and
  3109. ((block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
  3110. (assigned(left) and ((tcallparanode(left).left.nodetype in [realconstn,ordconstn])
  3111. and (not assigned(tcallparanode(left).right) or (tcallparanode(left).right.nodetype in [realconstn,ordconstn])))));
  3112. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  3113. begin
  3114. if assigned(left) then
  3115. begin
  3116. { convert types to those of the prototype, this is required by functions like ror, rol, sar
  3117. some use however a dummy type (Typedfile) so this would break them }
  3118. if not(tprocdef(procdefinition).extnumber in [fpc_in_Reset_TypedFile,fpc_in_Rewrite_TypedFile]) then
  3119. begin
  3120. { bind parasyms to the callparanodes and insert hidden parameters }
  3121. bind_parasym;
  3122. { insert type conversions for parameters }
  3123. if assigned(left) then
  3124. tcallparanode(left).insert_typeconv;
  3125. end;
  3126. { ptr and settextbuf need two args }
  3127. if assigned(tcallparanode(left).right) then
  3128. begin
  3129. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  3130. left:=nil;
  3131. end
  3132. else
  3133. begin
  3134. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  3135. tcallparanode(left).left:=nil;
  3136. end;
  3137. end
  3138. else
  3139. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  3140. result:=hpt;
  3141. exit;
  3142. end;
  3143. { ensure that the result type is set }
  3144. if not(cnf_typedefset in callnodeflags) then
  3145. begin
  3146. { constructors return their current class type, not the type where the
  3147. constructor is declared, this can be different because of inheritance }
  3148. if (procdefinition.proctypeoption=potype_constructor) and
  3149. assigned(methodpointer) and
  3150. assigned(methodpointer.resultdef) and
  3151. (methodpointer.resultdef.typ=classrefdef) then
  3152. resultdef:=tclassrefdef(methodpointer.resultdef).pointeddef
  3153. else
  3154. { Member call to a (inherited) constructor from the class, the return
  3155. value is always self, so we change it to voidtype to generate an
  3156. error and to prevent users from generating non-working code
  3157. when they expect to clone the current instance, see bug 3662 (PFV) }
  3158. if (procdefinition.proctypeoption=potype_constructor) and
  3159. is_class(tprocdef(procdefinition).struct) and
  3160. assigned(methodpointer) and
  3161. (methodpointer.nodetype=loadn) and
  3162. (loadnf_is_self in tloadnode(methodpointer).loadnodeflags) then
  3163. resultdef:=voidtype
  3164. else
  3165. resultdef:=procdefinition.returndef;
  3166. end
  3167. else
  3168. resultdef:=typedef;
  3169. { Check object/class for methods }
  3170. if assigned(methodpointer) then
  3171. begin
  3172. { direct call to inherited abstract method, then we
  3173. can already give a error in the compiler instead
  3174. of a runtime error }
  3175. if (cnf_inherited in callnodeflags) and
  3176. (po_abstractmethod in procdefinition.procoptions) then
  3177. begin
  3178. if (m_delphi in current_settings.modeswitches) and
  3179. (cnf_anon_inherited in callnodeflags) then
  3180. begin
  3181. CGMessage(cg_h_inherited_ignored);
  3182. result:=cnothingnode.create;
  3183. exit;
  3184. end
  3185. else
  3186. CGMessage(cg_e_cant_call_abstract_method);
  3187. end;
  3188. { directly calling an interface/protocol/category/class helper
  3189. method via its type is not possible (always must be called via
  3190. the actual instance) }
  3191. if (methodpointer.nodetype=typen) and
  3192. (is_interface(methodpointer.resultdef) or
  3193. is_objc_protocol_or_category(methodpointer.resultdef)) then
  3194. CGMessage1(type_e_class_type_expected,methodpointer.resultdef.typename);
  3195. { if an inherited con- or destructor should be }
  3196. { called in a con- or destructor then a warning }
  3197. { will be made }
  3198. { con- and destructors need a pointer to the vmt }
  3199. if (cnf_inherited in callnodeflags) and
  3200. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  3201. is_object(methodpointer.resultdef) and
  3202. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  3203. CGMessage(cg_w_member_cd_call_from_method);
  3204. if methodpointer.nodetype<>typen then
  3205. begin
  3206. { Remove all postfix operators }
  3207. hpt:=methodpointer;
  3208. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  3209. hpt:=tunarynode(hpt).left;
  3210. if ((hpt.nodetype=loadvmtaddrn) or
  3211. ((hpt.nodetype=loadn) and assigned(tloadnode(hpt).resultdef) and (tloadnode(hpt).resultdef.typ=classrefdef))) and
  3212. not (procdefinition.proctypeoption=potype_constructor) and
  3213. not (po_classmethod in procdefinition.procoptions) and
  3214. not (po_staticmethod in procdefinition.procoptions) then
  3215. { error: we are calling instance method from the class method/static method }
  3216. CGMessage(parser_e_only_class_members);
  3217. if (procdefinition.proctypeoption=potype_constructor) and
  3218. assigned(symtableproc) and
  3219. (symtableproc.symtabletype=withsymtable) and
  3220. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  3221. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  3222. { skip (absolute and other simple) type conversions -- only now,
  3223. because the checks above have to take type conversions into
  3224. e.g. class reference types account }
  3225. hpt:=actualtargetnode(@hpt)^;
  3226. { R.Init then R will be initialized by the constructor,
  3227. Also allow it for simple loads }
  3228. if (procdefinition.proctypeoption=potype_constructor) or
  3229. ((hpt.nodetype=loadn) and
  3230. (((methodpointer.resultdef.typ=objectdef) and
  3231. not(oo_has_virtual in tobjectdef(methodpointer.resultdef).objectoptions)) or
  3232. (methodpointer.resultdef.typ=recorddef)
  3233. )
  3234. ) then
  3235. { a constructor will and a method may write something to }
  3236. { the fields }
  3237. set_varstate(methodpointer,vs_readwritten,[])
  3238. else
  3239. set_varstate(methodpointer,vs_read,[vsf_must_be_valid]);
  3240. end;
  3241. { if we are calling the constructor check for abstract
  3242. methods. Ignore inherited and member calls, because the
  3243. class is then already created }
  3244. if (procdefinition.proctypeoption=potype_constructor) and
  3245. not(cnf_inherited in callnodeflags) and
  3246. not(cnf_member_call in callnodeflags) then
  3247. verifyabstractcalls;
  3248. end
  3249. else
  3250. begin
  3251. { When this is method the methodpointer must be available }
  3252. if (right=nil) and
  3253. (procdefinition.owner.symtabletype in [ObjectSymtable,recordsymtable]) and
  3254. not procdefinition.no_self_node then
  3255. internalerror(200305061);
  3256. end;
  3257. { Set flag that the procedure uses varargs, also if they are not passed it is still
  3258. needed for x86_64 to pass the number of SSE registers used }
  3259. if po_varargs in procdefinition.procoptions then
  3260. include(callnodeflags,cnf_uses_varargs);
  3261. { set the appropriate node flag if the call never returns }
  3262. if po_noreturn in procdefinition.procoptions then
  3263. include(callnodeflags,cnf_call_never_returns);
  3264. { Change loading of array of const to varargs }
  3265. if assigned(left) and
  3266. is_array_of_const(tparavarsym(procdefinition.paras[procdefinition.paras.count-1]).vardef) and
  3267. (procdefinition.proccalloption in cdecl_pocalls) then
  3268. convert_carg_array_of_const;
  3269. { bind parasyms to the callparanodes and insert hidden parameters }
  3270. bind_parasym;
  3271. { insert type conversions for parameters }
  3272. if assigned(left) then
  3273. tcallparanode(left).insert_typeconv;
  3274. { dispinterface methode invoke? }
  3275. if assigned(methodpointer) and is_dispinterface(methodpointer.resultdef) then
  3276. begin
  3277. case procdefinition.proctypeoption of
  3278. potype_propgetter: calltype:=dct_propget;
  3279. potype_propsetter: calltype:=dct_propput;
  3280. else
  3281. calltype:=dct_method;
  3282. end;
  3283. { if the result is used, we've to insert a call to convert the type to be on the "safe side" }
  3284. if (cnf_return_value_used in callnodeflags) and not is_void(procdefinition.returndef) then
  3285. begin
  3286. result:=internalstatements(statements);
  3287. converted_result_data:=ctempcreatenode.create(procdefinition.returndef,sizeof(procdefinition.returndef),
  3288. tt_persistent,true);
  3289. addstatement(statements,converted_result_data);
  3290. addstatement(statements,cassignmentnode.create(ctemprefnode.create(converted_result_data),
  3291. ctypeconvnode.create_internal(
  3292. translate_disp_call(methodpointer,parameters,calltype,'',tprocdef(procdefinition).dispid,procdefinition.returndef),
  3293. procdefinition.returndef)));
  3294. addstatement(statements,ctempdeletenode.create_normal_temp(converted_result_data));
  3295. addstatement(statements,ctemprefnode.create(converted_result_data));
  3296. end
  3297. else
  3298. result:=translate_disp_call(methodpointer,parameters,calltype,'',tprocdef(procdefinition).dispid,voidtype);
  3299. { don't free reused nodes }
  3300. methodpointer:=nil;
  3301. parameters:=nil;
  3302. end;
  3303. if assigned(call_self_node) then
  3304. typecheckpass(call_self_node);
  3305. if assigned(call_vmt_node) then
  3306. typecheckpass(call_vmt_node);
  3307. finally
  3308. aktcallnode:=oldcallnode;
  3309. end;
  3310. end;
  3311. procedure tcallnode.order_parameters;
  3312. var
  3313. hp,hpcurr,hpnext,hpfirst,hpprev : tcallparanode;
  3314. currloc : tcgloc;
  3315. begin
  3316. hpfirst:=nil;
  3317. hpcurr:=tcallparanode(left);
  3318. { cache all info about parameters containing stack tainting calls,
  3319. since we will need it a lot below and calculting it can be expensive }
  3320. while assigned(hpcurr) do
  3321. begin
  3322. hpcurr.init_contains_stack_tainting_call_cache;
  3323. hpcurr:=tcallparanode(hpcurr.right);
  3324. end;
  3325. hpcurr:=tcallparanode(left);
  3326. while assigned(hpcurr) do
  3327. begin
  3328. { pull out }
  3329. hpnext:=tcallparanode(hpcurr.right);
  3330. { pull in at the correct place.
  3331. Used order:
  3332. 1. LOC_REFERENCE with smallest offset (i386 only)
  3333. 2. LOC_REFERENCE with least complexity (non-i386 only)
  3334. 3. LOC_REFERENCE with most complexity (non-i386 only)
  3335. 4. LOC_REGISTER with most complexity
  3336. 5. LOC_REGISTER with least complexity
  3337. For the moment we only look at the first parameter field. Combining it
  3338. with multiple parameter fields will make things a lot complexer (PFV)
  3339. The reason for the difference regarding complexity ordering
  3340. between LOC_REFERENCE and LOC_REGISTER is mainly for calls:
  3341. we first want to treat the LOC_REFERENCE destinations whose
  3342. calculation does not require a call, because their location
  3343. may contain registers which might otherwise have to be saved
  3344. if a call has to be evaluated first. The calculated value is
  3345. stored on the stack and will thus no longer occupy any
  3346. register.
  3347. Similarly, for the register parameters we first want to
  3348. evaluate the calls, because otherwise the already loaded
  3349. register parameters will have to be saved so the intermediate
  3350. call can be evaluated (JM) }
  3351. if not assigned(hpcurr.parasym.paraloc[callerside].location) then
  3352. internalerror(200412152);
  3353. currloc:=hpcurr.parasym.paraloc[callerside].location^.loc;
  3354. hpprev:=nil;
  3355. hp:=hpfirst;
  3356. { on fixed_stack targets, always evaluate parameters containing
  3357. a call with stack parameters before all other parameters,
  3358. because they will prevent any other parameters from being put
  3359. in their final place; if both the current and the next para
  3360. contain a stack tainting call, don't do anything to prevent
  3361. them from keeping on chasing eachother's tail }
  3362. while assigned(hp) do
  3363. begin
  3364. if paramanager.use_fixed_stack and
  3365. hpcurr.contains_stack_tainting_call_cached then
  3366. break;
  3367. case currloc of
  3368. LOC_REFERENCE :
  3369. begin
  3370. case hp.parasym.paraloc[callerside].location^.loc of
  3371. LOC_REFERENCE :
  3372. begin
  3373. { Offset is calculated like:
  3374. sub esp,12
  3375. mov [esp+8],para3
  3376. mov [esp+4],para2
  3377. mov [esp],para1
  3378. call function
  3379. That means the for pushes the para with the
  3380. highest offset (see para3) needs to be pushed first
  3381. }
  3382. {$if defined(i386) or defined(i8086) or defined(m68k)}
  3383. { the i386, i8086, m68k and jvm code generators expect all reference }
  3384. { parameters to be in this order so they can use }
  3385. { pushes in case of no fixed stack }
  3386. if (not paramanager.use_fixed_stack and
  3387. (hpcurr.parasym.paraloc[callerside].location^.reference.offset>
  3388. hp.parasym.paraloc[callerside].location^.reference.offset)) or
  3389. (paramanager.use_fixed_stack and
  3390. (node_complexity(hpcurr)<node_complexity(hp))) then
  3391. {$elseif defined(jvm)}
  3392. if (hpcurr.parasym.paraloc[callerside].location^.reference.offset<hp.parasym.paraloc[callerside].location^.reference.offset) then
  3393. {$else jvm}
  3394. if (node_complexity(hpcurr)<node_complexity(hp)) then
  3395. {$endif jvm}
  3396. break;
  3397. end;
  3398. LOC_MMREGISTER,
  3399. LOC_REGISTER,
  3400. LOC_FPUREGISTER :
  3401. break;
  3402. end;
  3403. end;
  3404. LOC_MMREGISTER,
  3405. LOC_FPUREGISTER,
  3406. LOC_REGISTER :
  3407. begin
  3408. if (hp.parasym.paraloc[callerside].location^.loc<>LOC_REFERENCE) and
  3409. (node_complexity(hpcurr)>node_complexity(hp)) then
  3410. break;
  3411. end;
  3412. end;
  3413. hpprev:=hp;
  3414. hp:=tcallparanode(hp.right);
  3415. end;
  3416. hpcurr.right:=hp;
  3417. if assigned(hpprev) then
  3418. hpprev.right:=hpcurr
  3419. else
  3420. hpfirst:=hpcurr;
  3421. { next }
  3422. hpcurr:=hpnext;
  3423. end;
  3424. left:=hpfirst;
  3425. { now mark each parameter that is followed by a stack-tainting call,
  3426. to determine on use_fixed_stack targets which ones can immediately be
  3427. put in their final destination. Unforunately we can never put register
  3428. parameters immediately in their final destination (even on register-
  3429. rich architectures such as the PowerPC), because the code generator
  3430. can still insert extra calls that only make use of register
  3431. parameters (fpc_move() etc. }
  3432. hpcurr:=hpfirst;
  3433. while assigned(hpcurr) do
  3434. begin
  3435. if hpcurr.contains_stack_tainting_call_cached then
  3436. begin
  3437. { all parameters before this one are followed by a stack
  3438. tainting call }
  3439. hp:=hpfirst;
  3440. while hp<>hpcurr do
  3441. begin
  3442. hp.ffollowed_by_stack_tainting_call_cached:=true;
  3443. hp:=tcallparanode(hp.right);
  3444. end;
  3445. hpfirst:=hpcurr;
  3446. end;
  3447. hpcurr:=tcallparanode(hpcurr.right);
  3448. end;
  3449. end;
  3450. procedure tcallnode.check_stack_parameters;
  3451. var
  3452. hp : tcallparanode;
  3453. begin
  3454. hp:=tcallparanode(left);
  3455. while assigned(hp) do
  3456. begin
  3457. if assigned(hp.parasym) and
  3458. assigned(hp.parasym.paraloc[callerside].location) and
  3459. (hp.parasym.paraloc[callerside].location^.loc=LOC_REFERENCE) then
  3460. include(current_procinfo.flags,pi_has_stackparameter);
  3461. hp:=tcallparanode(hp.right);
  3462. end;
  3463. end;
  3464. procedure tcallnode.check_inlining;
  3465. var
  3466. st : tsymtable;
  3467. para : tcallparanode;
  3468. begin
  3469. { Can we inline the procedure? }
  3470. if (po_inline in procdefinition.procoptions) and
  3471. (procdefinition.typ=procdef) and
  3472. tprocdef(procdefinition).has_inlininginfo and
  3473. { Prevent too deep inlining recursion and code bloat by inlining
  3474. The actual formuala is
  3475. inlinelevel+1 /-------
  3476. node count < -------------\/ 10000
  3477. This allows exponential grow of the code only to a certain limit.
  3478. Remarks
  3479. - The current approach calculates the inlining level top down, so outer call nodes (nodes closer to the leaf) might not be inlined
  3480. if the max. complexity is reached. This is done because it makes the implementation easier and because
  3481. there might be situations were it is more beneficial to inline inner nodes and do the calls to the outer nodes
  3482. if the outer nodes are in a seldomly used code path
  3483. - The code avoids to use functions from the math unit
  3484. }
  3485. (node_count(tprocdef(procdefinition).inlininginfo^.code)<round(exp((1.0/(inlinelevel+1))*ln(10000)))) then
  3486. begin
  3487. include(callnodeflags,cnf_do_inline);
  3488. { Check if we can inline the procedure when it references proc/var that
  3489. are not in the globally available }
  3490. st:=procdefinition.owner;
  3491. while (st.symtabletype in [ObjectSymtable,recordsymtable]) do
  3492. st:=st.defowner.owner;
  3493. if (pi_uses_static_symtable in tprocdef(procdefinition).inlininginfo^.flags) and
  3494. (st.symtabletype=globalsymtable) and
  3495. (not st.iscurrentunit) then
  3496. begin
  3497. Comment(V_lineinfo+V_Debug,'Not inlining "'+tprocdef(procdefinition).procsym.realname+'", references static symtable');
  3498. exclude(callnodeflags,cnf_do_inline);
  3499. end;
  3500. para:=tcallparanode(parameters);
  3501. while assigned(para) do
  3502. begin
  3503. if not para.can_be_inlined then
  3504. begin
  3505. Comment(V_lineinfo+V_Debug,'Not inlining "'+tprocdef(procdefinition).procsym.realname+
  3506. '", invocation parameter contains an unsafe/unsupported construct');
  3507. exclude(callnodeflags,cnf_do_inline);
  3508. break;
  3509. end;
  3510. para:=tcallparanode(para.nextpara);
  3511. end;
  3512. end;
  3513. end;
  3514. function tcallnode.pass_1 : tnode;
  3515. procedure mark_unregable_parameters;
  3516. var
  3517. hp : tcallparanode;
  3518. begin
  3519. hp:=tcallparanode(left);
  3520. while assigned(hp) do
  3521. begin
  3522. do_typecheckpass(hp.left);
  3523. { When the address needs to be pushed then the register is
  3524. not regable. Exception is when the location is also a var
  3525. parameter and we can pass the address transparently (but
  3526. that is handled by make_not_regable if ra_addr_regable is
  3527. passed, and make_not_regable always needs to called for
  3528. the ra_addr_taken info for non-invisble parameters) }
  3529. if (not (cpf_varargs_para in hp.callparaflags)) and (
  3530. not(
  3531. (vo_is_hidden_para in hp.parasym.varoptions) and
  3532. (hp.left.resultdef.typ in [pointerdef,classrefdef])
  3533. ) and
  3534. paramanager.push_addr_param(hp.parasym.varspez,hp.parasym.vardef,
  3535. self.procdefinition.proccalloption)
  3536. ) then
  3537. { pushing the address of a variable to take the place of a temp
  3538. as the complex function result of a function does not make its
  3539. address escape the current block, as the "address of the
  3540. function result" is not something which can be stored
  3541. persistently by the callee (it becomes invalid when the callee
  3542. returns) }
  3543. if not(vo_is_funcret in hp.parasym.varoptions) then
  3544. make_not_regable(hp.left,[ra_addr_regable,ra_addr_taken])
  3545. else
  3546. make_not_regable(hp.left,[ra_addr_regable]);
  3547. hp:=tcallparanode(hp.right);
  3548. end;
  3549. end;
  3550. var
  3551. para: tcallparanode;
  3552. oldcallnode: tcallnode;
  3553. begin
  3554. result:=nil;
  3555. oldcallnode:=aktcallnode;
  3556. aktcallnode:=self;
  3557. try
  3558. { as pass_1 is never called on the methodpointer node, we must check
  3559. here that it's not a helper type }
  3560. if assigned(methodpointer) and
  3561. (methodpointer.nodetype=typen) and
  3562. is_objectpascal_helper(ttypenode(methodpointer).typedef) and
  3563. not ttypenode(methodpointer).helperallowed then
  3564. begin
  3565. CGMessage(parser_e_no_category_as_types);
  3566. { we get an internal error when trying to insert the hidden
  3567. parameters in this case }
  3568. exit;
  3569. end;
  3570. { can we get rid of the call? }
  3571. if (cs_opt_remove_emtpy_proc in current_settings.optimizerswitches) and
  3572. not(cnf_return_value_used in callnodeflags) and
  3573. (procdefinition.typ=procdef) and
  3574. tprocdef(procdefinition).isempty and
  3575. { allow only certain proc options }
  3576. ((tprocdef(procdefinition).procoptions-[po_none,po_classmethod,po_staticmethod,
  3577. po_interrupt,po_iocheck,po_assembler,po_msgstr,po_msgint,po_exports,po_external,po_overload,
  3578. po_nostackframe,po_has_mangledname,po_has_public_name,po_forward,po_global,
  3579. po_inline,po_compilerproc,po_has_importdll,po_has_importname,po_kylixlocal,po_dispid,po_delphi_nested_cc,
  3580. po_rtlproc,po_ignore_for_overload_resolution,po_auto_raised_visibility])=[]) then
  3581. begin
  3582. { check parameters for side effects }
  3583. para:=tcallparanode(left);
  3584. while assigned(para) do
  3585. begin
  3586. if (para.parasym.typ = paravarsym) and
  3587. ((para.parasym.refs>0) or
  3588. { array of consts are converted later on so we need to skip them here
  3589. else no error detection is done }
  3590. is_array_of_const(para.parasym.vardef) or
  3591. not(cs_opt_dead_values in current_settings.optimizerswitches) or
  3592. might_have_sideeffects(para.left)) then
  3593. break;
  3594. para:=tcallparanode(para.right);
  3595. end;
  3596. { finally, remove it if no parameter with side effect has been found }
  3597. if para=nil then
  3598. begin
  3599. result:=cnothingnode.create;
  3600. exit;
  3601. end;
  3602. end;
  3603. { convert Objective-C calls into a message call }
  3604. if (procdefinition.typ=procdef) and
  3605. (po_objc in tprocdef(procdefinition).procoptions) then
  3606. begin
  3607. if not(cnf_objc_processed in callnodeflags) then
  3608. objc_convert_to_message_send;
  3609. end
  3610. else
  3611. begin
  3612. { The following don't apply to obj-c: obj-c methods can never be
  3613. inlined because they're always virtual and the destination can
  3614. change at run, and for the same reason we also can't perform
  3615. WPO on them (+ they have no constructors) }
  3616. { Check if the call can be inlined, sets the cnf_do_inline flag }
  3617. check_inlining;
  3618. { must be called before maybe_load_in_temp(methodpointer), because
  3619. it converts the methodpointer into a temp in case it's a call
  3620. (and we want to know the original call)
  3621. }
  3622. register_created_object_types;
  3623. end;
  3624. { Maybe optimize the loading of the methodpointer using a temp. When the methodpointer
  3625. is a calln this is even required to not execute the calln twice.
  3626. This needs to be done after the resulttype pass, because in the resulttype we can still convert the
  3627. calln to a loadn (PFV) }
  3628. if assigned(methodpointer) then
  3629. maybe_load_in_temp(methodpointer);
  3630. { Create destination (temp or assignment-variable reuse) for function result if it not yet set }
  3631. maybe_create_funcret_node;
  3632. { Insert the self,vmt,function result in the parameters }
  3633. gen_hidden_parameters;
  3634. { Remove useless nodes from init/final blocks }
  3635. { (simplify depends on typecheck info) }
  3636. if assigned(callinitblock) then
  3637. begin
  3638. typecheckpass(tnode(callinitblock));
  3639. doinlinesimplify(tnode(callinitblock));
  3640. end;
  3641. if assigned(callcleanupblock) then
  3642. begin
  3643. typecheckpass(tnode(callcleanupblock));
  3644. doinlinesimplify(tnode(callcleanupblock));
  3645. end;
  3646. { If a constructor calls another constructor of the same or of an
  3647. inherited class, some targets (jvm) have to generate different
  3648. entry code for the constructor. }
  3649. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  3650. (procdefinition.typ=procdef) and
  3651. (tprocdef(procdefinition).proctypeoption=potype_constructor) and
  3652. ([cnf_member_call,cnf_inherited] * callnodeflags <> []) then
  3653. current_procinfo.ConstructorCallingConstructor:=true;
  3654. { object check helper will load VMT -> needs GOT }
  3655. if (cs_check_object in current_settings.localswitches) and
  3656. (cs_create_pic in current_settings.moduleswitches) then
  3657. include(current_procinfo.flags,pi_needs_got);
  3658. { Continue with checking a normal call or generate the inlined code }
  3659. if cnf_do_inline in callnodeflags then
  3660. result:=pass1_inline
  3661. else
  3662. begin
  3663. mark_unregable_parameters;
  3664. result:=pass1_normal;
  3665. end;
  3666. finally
  3667. aktcallnode:=oldcallnode;
  3668. end;
  3669. end;
  3670. function tcallnode.pass1_normal : tnode;
  3671. begin
  3672. result:=nil;
  3673. { calculate the parameter info for the procdef }
  3674. procdefinition.init_paraloc_info(callerside);
  3675. { calculate the parameter size needed for this call include varargs if they are available }
  3676. if assigned(varargsparas) then
  3677. pushedparasize:=paramanager.create_varargs_paraloc_info(procdefinition,varargsparas)
  3678. else
  3679. pushedparasize:=procdefinition.callerargareasize;
  3680. { record maximum parameter size used in this proc }
  3681. current_procinfo.allocate_push_parasize(pushedparasize);
  3682. { check for stacked parameters }
  3683. if assigned(left) and
  3684. (current_settings.optimizerswitches*[cs_opt_stackframe,cs_opt_level1]<>[]) then
  3685. check_stack_parameters;
  3686. if assigned(callinitblock) then
  3687. firstpass(tnode(callinitblock));
  3688. { function result node (tempref or simple load) }
  3689. if assigned(funcretnode) then
  3690. firstpass(funcretnode);
  3691. { parameters }
  3692. if assigned(left) then
  3693. tcallparanode(left).firstcallparan;
  3694. { procedure variable ? }
  3695. if assigned(right) then
  3696. firstpass(right);
  3697. if assigned(methodpointer) and
  3698. (methodpointer.nodetype<>typen) then
  3699. firstpass(methodpointer);
  3700. if assigned(callcleanupblock) then
  3701. firstpass(tnode(callcleanupblock));
  3702. if not (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) then
  3703. include(current_procinfo.flags,pi_do_call);
  3704. { order parameters }
  3705. order_parameters;
  3706. { get a register for the return value }
  3707. if (not is_void(resultdef)) then
  3708. begin
  3709. if paramanager.ret_in_param(resultdef,procdefinition) then
  3710. begin
  3711. expectloc:=LOC_REFERENCE;
  3712. end
  3713. else
  3714. { ansi/widestrings must be registered, so we can dispose them }
  3715. if is_ansistring(resultdef) or
  3716. is_widestring(resultdef) or
  3717. is_unicodestring(resultdef) then
  3718. begin
  3719. expectloc:=LOC_REFERENCE;
  3720. end
  3721. else
  3722. { we have only to handle the result if it is used }
  3723. if (cnf_return_value_used in callnodeflags) then
  3724. expectloc:=get_expect_loc
  3725. else
  3726. expectloc:=LOC_VOID;
  3727. end
  3728. else
  3729. expectloc:=LOC_VOID;
  3730. end;
  3731. {$ifdef state_tracking}
  3732. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  3733. var hp:Tcallparanode;
  3734. value:Tnode;
  3735. begin
  3736. track_state_pass:=false;
  3737. hp:=Tcallparanode(left);
  3738. while assigned(hp) do
  3739. begin
  3740. if left.track_state_pass(exec_known) then
  3741. begin
  3742. left.resultdef:=nil;
  3743. do_typecheckpass(left);
  3744. end;
  3745. value:=aktstate.find_fact(hp.left);
  3746. if value<>nil then
  3747. begin
  3748. track_state_pass:=true;
  3749. hp.left.destroy;
  3750. hp.left:=value.getcopy;
  3751. do_typecheckpass(hp.left);
  3752. end;
  3753. hp:=Tcallparanode(hp.right);
  3754. end;
  3755. end;
  3756. {$endif}
  3757. {**************************************************************************
  3758. INLINING SUPPORT
  3759. **************************************************************************}
  3760. function tcallnode.replaceparaload(var n: tnode; arg: pointer): foreachnoderesult;
  3761. var
  3762. paras: tcallparanode;
  3763. temp: tnode;
  3764. indexnr : integer;
  3765. begin
  3766. result := fen_false;
  3767. n.fileinfo := pfileposinfo(arg)^;
  3768. if (n.nodetype = loadn) then
  3769. begin
  3770. case tloadnode(n).symtableentry.typ of
  3771. paravarsym :
  3772. begin
  3773. paras := tcallparanode(left);
  3774. while assigned(paras) and
  3775. (paras.parasym <> tloadnode(n).symtableentry) do
  3776. paras := tcallparanode(paras.right);
  3777. if assigned(paras) then
  3778. begin
  3779. temp:=paras.left.getcopy;
  3780. { inherit modification information, this is needed by the dfa/cse }
  3781. temp.flags:=temp.flags+(n.flags*[nf_modify,nf_write,nf_address_taken]);
  3782. n.free;
  3783. n:=temp;
  3784. typecheckpass(n);
  3785. result := fen_true;
  3786. end;
  3787. end;
  3788. localvarsym :
  3789. begin
  3790. { local? }
  3791. if (tloadnode(n).symtableentry.owner <> tprocdef(procdefinition).localst) then
  3792. exit;
  3793. indexnr:=tloadnode(n).symtableentry.owner.SymList.IndexOf(tloadnode(n).symtableentry);
  3794. if (indexnr >= inlinelocals.count) or
  3795. not assigned(inlinelocals[indexnr]) then
  3796. internalerror(20040720);
  3797. temp := tnode(inlinelocals[indexnr]).getcopy;
  3798. { inherit modification information, this is needed by the dfa/cse }
  3799. temp.flags:=temp.flags+(n.flags*[nf_modify,nf_write,nf_address_taken]);
  3800. n.free;
  3801. n:=temp;
  3802. typecheckpass(n);
  3803. result := fen_true;
  3804. end;
  3805. end;
  3806. end;
  3807. end;
  3808. procedure tcallnode.createlocaltemps(p:TObject;arg:pointer);
  3809. var
  3810. tempnode: ttempcreatenode;
  3811. indexnr : integer;
  3812. begin
  3813. if (TSym(p).typ <> localvarsym) then
  3814. exit;
  3815. indexnr:=TSym(p).Owner.SymList.IndexOf(p);
  3816. if (indexnr >= inlinelocals.count) then
  3817. inlinelocals.count:=indexnr+10;
  3818. if (vo_is_funcret in tabstractvarsym(p).varoptions) then
  3819. begin
  3820. if not assigned(funcretnode) then
  3821. internalerror(200709081);
  3822. inlinelocals[indexnr] := funcretnode.getcopy
  3823. end
  3824. else
  3825. begin
  3826. tempnode :=ctempcreatenode.create(tabstractvarsym(p).vardef,
  3827. tabstractvarsym(p).vardef.size,tt_persistent,tabstractvarsym(p).is_regvar(false));
  3828. addstatement(inlineinitstatement,tempnode);
  3829. if localvartrashing <> -1 then
  3830. cnodeutils.maybe_trash_variable(inlineinitstatement,tabstractnormalvarsym(p),ctemprefnode.create(tempnode));
  3831. addstatement(inlinecleanupstatement,ctempdeletenode.create(tempnode));
  3832. { inherit addr_taken flag }
  3833. if (tabstractvarsym(p).addr_taken) then
  3834. include(tempnode.tempinfo^.flags,ti_addr_taken);
  3835. inlinelocals[indexnr] := ctemprefnode.create(tempnode);
  3836. end;
  3837. end;
  3838. function nonlocalvars(var n: tnode; arg: pointer): foreachnoderesult;
  3839. begin
  3840. result := fen_false;
  3841. { this is just to play it safe, there are more safe situations }
  3842. if (n.nodetype = derefn) or
  3843. ((n.nodetype = loadn) and
  3844. { globals and fields of (possibly global) objects could always be changed in the callee }
  3845. ((tloadnode(n).symtable.symtabletype in [globalsymtable,ObjectSymtable]) or
  3846. { statics can only be modified by functions in the same unit }
  3847. ((tloadnode(n).symtable.symtabletype = staticsymtable) and
  3848. (tloadnode(n).symtable = TSymtable(arg))) or
  3849. { if the addr of the symbol is taken somewhere, it can be also non-local }
  3850. (tabstractvarsym(tloadnode(n).symtableentry).addr_taken)
  3851. )) or
  3852. ((n.nodetype = subscriptn) and
  3853. (tsubscriptnode(n).vs.owner.symtabletype = ObjectSymtable)) then
  3854. result := fen_norecurse_true;
  3855. end;
  3856. procedure tcallnode.createinlineparas;
  3857. var
  3858. para: tcallparanode;
  3859. tempnode: ttempcreatenode;
  3860. n: tnode;
  3861. paracomplexity: longint;
  3862. pushconstaddr: boolean;
  3863. trytotakeaddress : Boolean;
  3864. begin
  3865. { parameters }
  3866. para := tcallparanode(left);
  3867. pushconstaddr := false;
  3868. while assigned(para) do
  3869. begin
  3870. if (para.parasym.typ = paravarsym) and
  3871. ((para.parasym.refs>0) or
  3872. not(cs_opt_dead_values in current_settings.optimizerswitches) or
  3873. might_have_sideeffects(para.left)) then
  3874. begin
  3875. { must take copy of para.left, because if it contains a }
  3876. { temprefn pointing to a copied temp (e.g. methodpointer), }
  3877. { then this parameter must be changed to point to the copy of }
  3878. { that temp (JM) }
  3879. n := para.left.getcopy;
  3880. para.left.free;
  3881. para.left := n;
  3882. firstpass(para.left);
  3883. { determine how a parameter is passed to the inlined body
  3884. There are three options:
  3885. - insert the node tree of the callparanode directly
  3886. If a parameter is used only once, this is the best option if we can do so
  3887. - get the address of the argument, store it in a temp and insert a dereference to this temp
  3888. If the node tree cannot be inserted directly, taking the address of the argument and using it
  3889. is the second best option, but even this is not always possible
  3890. - assign the value of the argument to a newly created temp
  3891. This is the fall back which works always
  3892. Notes:
  3893. - we need to take care that we use the type of the defined parameter and not of the
  3894. passed parameter, because these can be different in case of a formaldef (PFV)
  3895. }
  3896. { pre-compute some values }
  3897. paracomplexity:=node_complexity(para.left);
  3898. if para.parasym.varspez=vs_const then
  3899. pushconstaddr:=paramanager.push_addr_param(vs_const,para.parasym.vardef,procdefinition.proccalloption);
  3900. { if the parameter is "complex", try to take the address
  3901. of the parameter expression, store it in a temp and replace
  3902. occurrences of the parameter with dereferencings of this
  3903. temp
  3904. }
  3905. trytotakeaddress:=
  3906. { don't create a temp. for function results }
  3907. not(nf_is_funcret in para.left.flags) and
  3908. { this makes only sense if the parameter is reasonable complex else inserting directly is a better solution }
  3909. ((paracomplexity>2) or
  3910. { don't create a temp. for the often seen case that p^ is passed to a var parameter }
  3911. ((paracomplexity>1) and not((para.left.nodetype=derefn) and (para.parasym.varspez = vs_var))));
  3912. { check if we have to create a temp, assign the parameter's
  3913. contents to that temp and then substitute the parameter
  3914. with the temp everywhere in the function }
  3915. if
  3916. ((tparavarsym(para.parasym).varregable in [vr_none,vr_addr]) and
  3917. not(para.left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE])) or
  3918. { we can't assign to formaldef temps }
  3919. ((para.parasym.vardef.typ<>formaldef) and
  3920. (
  3921. { can we take the address of the argument? }
  3922. (trytotakeaddress and not(para.left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE])) or
  3923. (trytotakeaddress and
  3924. (not valid_for_addr(para.left,false) or
  3925. (para.left.nodetype = calln) or
  3926. is_constnode(para.left))) or
  3927. { we do not need to create a temp for value parameters }
  3928. { which are not modified in the inlined function }
  3929. { const parameters can get vs_readwritten if their }
  3930. { address is taken }
  3931. ((((para.parasym.varspez = vs_value) and
  3932. (para.parasym.varstate in [vs_initialised,vs_declared,vs_read])) or
  3933. { in case of const, this is only necessary if the
  3934. variable would be passed by value normally and if it is modified or if
  3935. there is such a variable somewhere in an expression }
  3936. ((para.parasym.varspez = vs_const) and
  3937. (not pushconstaddr))) and
  3938. { however, if we pass a global variable, an object field or}
  3939. { an expression containing a pointer dereference as }
  3940. { parameter, this value could be modified in other ways as }
  3941. { well and in such cases create a temp to be on the safe }
  3942. { side }
  3943. foreachnodestatic(para.left,@nonlocalvars,pointer(symtableproc))) or
  3944. { value parameters of which we know they are modified by }
  3945. { definition have to be copied to a temp }
  3946. { the same goes for cases of "x:=f(x)" where x is passed }
  3947. { as value parameter to f(), at least if we optimized }
  3948. { invocation by setting the funcretnode to x to avoid }
  3949. { assignment afterwards (since x may be read inside the }
  3950. { function after it modified result==x) }
  3951. ((para.parasym.varspez = vs_value) and
  3952. (not(para.parasym.varstate in [vs_initialised,vs_declared,vs_read]) or
  3953. (assigned(aktassignmentnode) and
  3954. (aktassignmentnode.right=self) and
  3955. (nf_assign_done_in_right in aktassignmentnode.flags) and
  3956. actualtargetnode(@aktassignmentnode.left)^.isequal(actualtargetnode(@para.left)^)))) or
  3957. { the compiler expects that it can take the address of parameters passed by reference in
  3958. the case of const so we can't replace the node simply by a constant node
  3959. When playing with this code, ensure that
  3960. function f(const a,b : longint) : longint;inline;
  3961. begin
  3962. result:=a*b;
  3963. end;
  3964. [...]
  3965. ...:=f(10,20));
  3966. [...]
  3967. is still folded. (FK)
  3968. }
  3969. ((para.parasym.varspez = vs_const) and
  3970. { const para's can get vs_readwritten if their address }
  3971. { is taken -> in case they are not passed by reference, }
  3972. { to keep the same behaviour as without inlining we have }
  3973. { to make a copy in case the originally passed parameter }
  3974. { value gets changed inside the callee }
  3975. ((not pushconstaddr and
  3976. (para.parasym.varstate = vs_readwritten)
  3977. ) or
  3978. { call-by-reference const's may need to be passed by }
  3979. { reference to function called in the inlined code }
  3980. (pushconstaddr and
  3981. not valid_for_addr(para.left,false))
  3982. )
  3983. )
  3984. )
  3985. ) then
  3986. begin
  3987. { don't create a new temp unnecessarily, but make sure we
  3988. do create a new one if the old one could be a regvar and
  3989. the new one cannot be one }
  3990. if not(tparavarsym(para.parasym).varspez in [vs_out,vs_var]) and (((para.left.nodetype<>temprefn) or
  3991. (((tparavarsym(para.parasym).varregable in [vr_none,vr_addr])) and
  3992. (ti_may_be_in_reg in ttemprefnode(para.left).tempinfo^.flags)))) then
  3993. begin
  3994. tempnode := ctempcreatenode.create(para.parasym.vardef,para.parasym.vardef.size,
  3995. tt_persistent,tparavarsym(para.parasym).is_regvar(false));
  3996. addstatement(inlineinitstatement,tempnode);
  3997. if localvartrashing <> -1 then
  3998. cnodeutils.maybe_trash_variable(inlineinitstatement,para.parasym,ctemprefnode.create(tempnode));
  3999. addstatement(inlinecleanupstatement,ctempdeletenode.create(tempnode));
  4000. addstatement(inlineinitstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  4001. para.left));
  4002. para.left := ctemprefnode.create(tempnode);
  4003. { inherit addr_taken flag }
  4004. if (tabstractvarsym(para.parasym).addr_taken) then
  4005. include(tempnode.tempinfo^.flags,ti_addr_taken);
  4006. end;
  4007. end
  4008. else if trytotakeaddress then
  4009. wrapcomplexinlinepara(para);
  4010. end;
  4011. para := tcallparanode(para.right);
  4012. end;
  4013. { local variables }
  4014. if not assigned(tprocdef(procdefinition).localst) or
  4015. (tprocdef(procdefinition).localst.SymList.count = 0) then
  4016. exit;
  4017. inlinelocals.count:=tprocdef(procdefinition).localst.SymList.count;
  4018. tprocdef(procdefinition).localst.SymList.ForEachCall(@createlocaltemps,nil);
  4019. end;
  4020. procedure tcallnode.wrapcomplexinlinepara(para: tcallparanode);
  4021. var
  4022. ptrtype: tdef;
  4023. tempnode: ttempcreatenode;
  4024. paraaddr: taddrnode;
  4025. begin
  4026. ptrtype:=getpointerdef(para.left.resultdef);
  4027. tempnode:=ctempcreatenode.create(ptrtype,ptrtype.size,tt_persistent,true);
  4028. addstatement(inlineinitstatement,tempnode);
  4029. addstatement(inlinecleanupstatement,ctempdeletenode.create(tempnode));
  4030. { inherit addr_taken flag }
  4031. if (tabstractvarsym(para.parasym).addr_taken) then
  4032. include(tempnode.tempinfo^.flags,ti_addr_taken);
  4033. { inherit read only }
  4034. if tabstractvarsym(para.parasym).varspez=vs_const then
  4035. include(tempnode.tempinfo^.flags,ti_const);
  4036. paraaddr:=caddrnode.create_internal(para.left);
  4037. include(paraaddr.flags,nf_typedaddr);
  4038. addstatement(inlineinitstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  4039. paraaddr));
  4040. para.left:=cderefnode.create(ctemprefnode.create(tempnode));
  4041. end;
  4042. function tcallnode.optimize_funcret_assignment(inlineblock: tblocknode): tnode;
  4043. var
  4044. hp : tstatementnode;
  4045. hp2 : tnode;
  4046. resassign : tassignmentnode;
  4047. begin
  4048. result:=nil;
  4049. if not assigned(funcretnode) or
  4050. not(cnf_return_value_used in callnodeflags) then
  4051. exit;
  4052. { tempcreatenode for the function result }
  4053. hp:=tstatementnode(inlineblock.left);
  4054. if not(assigned(hp)) or
  4055. (hp.left.nodetype <> tempcreaten) or
  4056. not(nf_is_funcret in hp.left.flags) then
  4057. exit;
  4058. { constant assignment? right must be a constant (mainly to avoid trying
  4059. to reuse local temps which may already be freed afterwards once these
  4060. checks are made looser) }
  4061. hp:=tstatementnode(hp.right);
  4062. if not(assigned(hp)) or
  4063. (hp.left.nodetype<>assignn) or
  4064. not is_constnode(tassignmentnode(hp.left).right) then
  4065. exit;
  4066. { left must be function result }
  4067. resassign:=tassignmentnode(hp.left);
  4068. hp2:=resassign.left;
  4069. { can have extra type conversion due to absolute mapping
  4070. of <fucntionname> on function result var }
  4071. if (hp2.nodetype=typeconvn) and (ttypeconvnode(hp2).convtype=tc_equal) then
  4072. hp2:=ttypeconvnode(hp2).left;
  4073. if (hp2.nodetype<>temprefn) or
  4074. not(nf_is_funcret in hp2.flags) then
  4075. exit;
  4076. { tempdelete to normal of the function result }
  4077. hp:=tstatementnode(hp.right);
  4078. if not(assigned(hp)) or
  4079. (hp.left.nodetype <> tempdeleten) then
  4080. exit;
  4081. { the function result once more }
  4082. hp:=tstatementnode(hp.right);
  4083. if not(assigned(hp)) or
  4084. (hp.left.nodetype<>temprefn) or
  4085. not(nf_is_funcret in hp.left.flags) then
  4086. exit;
  4087. { should be the end }
  4088. if assigned(hp.right) then
  4089. exit;
  4090. { we made it! }
  4091. result:=tassignmentnode(resassign).right.getcopy;
  4092. firstpass(result);
  4093. end;
  4094. { this procedure removes the user code flag because it prevents optimizations }
  4095. function removeusercodeflag(var n : tnode; arg : pointer) : foreachnoderesult;
  4096. begin
  4097. result:=fen_false;
  4098. if nf_usercode_entry in n.flags then
  4099. begin
  4100. exclude(n.flags,nf_usercode_entry);
  4101. result:=fen_norecurse_true;
  4102. end;
  4103. end;
  4104. function tcallnode.pass1_inline:tnode;
  4105. var
  4106. n,
  4107. body : tnode;
  4108. para : tcallparanode;
  4109. inlineblock,
  4110. inlinecleanupblock : tblocknode;
  4111. begin
  4112. inc(inlinelevel);
  4113. result:=nil;
  4114. if not(assigned(tprocdef(procdefinition).inlininginfo) and
  4115. assigned(tprocdef(procdefinition).inlininginfo^.code)) then
  4116. internalerror(200412021);
  4117. inlinelocals:=TFPObjectList.create(true);
  4118. { inherit flags }
  4119. current_procinfo.flags:=current_procinfo.flags+
  4120. ((procdefinition as tprocdef).inlininginfo^.flags*inherited_inlining_flags);
  4121. { Create new code block for inlining }
  4122. inlineblock:=internalstatements(inlineinitstatement);
  4123. { make sure that valid_for_assign() returns false for this block
  4124. (otherwise assigning values to the block will result in assigning
  4125. values to the inlined function's result) }
  4126. include(inlineblock.flags,nf_no_lvalue);
  4127. inlinecleanupblock:=internalstatements(inlinecleanupstatement);
  4128. if assigned(callinitblock) then
  4129. addstatement(inlineinitstatement,callinitblock.getcopy);
  4130. { replace complex parameters with temps }
  4131. createinlineparas;
  4132. { create a copy of the body and replace parameter loads with the parameter values }
  4133. body:=tprocdef(procdefinition).inlininginfo^.code.getcopy;
  4134. foreachnodestatic(pm_postprocess,body,@removeusercodeflag,nil);
  4135. foreachnode(pm_preprocess,body,@replaceparaload,@fileinfo);
  4136. { Concat the body and finalization parts }
  4137. addstatement(inlineinitstatement,body);
  4138. addstatement(inlineinitstatement,inlinecleanupblock);
  4139. inlinecleanupblock:=nil;
  4140. if assigned(callcleanupblock) then
  4141. addstatement(inlineinitstatement,callcleanupblock.getcopy);
  4142. { the last statement of the new inline block must return the
  4143. location and type of the function result.
  4144. This is not needed when the result is not used, also the tempnode is then
  4145. already destroyed by a tempdelete in the callcleanupblock tree }
  4146. if not is_void(resultdef) and
  4147. (cnf_return_value_used in callnodeflags) then
  4148. begin
  4149. if assigned(funcretnode) then
  4150. addstatement(inlineinitstatement,funcretnode.getcopy)
  4151. else
  4152. begin
  4153. para:=tcallparanode(left);
  4154. while assigned(para) do
  4155. begin
  4156. if (vo_is_hidden_para in para.parasym.varoptions) and
  4157. (vo_is_funcret in para.parasym.varoptions) then
  4158. begin
  4159. addstatement(inlineinitstatement,para.left.getcopy);
  4160. break;
  4161. end;
  4162. para:=tcallparanode(para.right);
  4163. end;
  4164. end;
  4165. end;
  4166. { consider it must not be inlined if called
  4167. again inside the args or itself }
  4168. exclude(procdefinition.procoptions,po_inline);
  4169. typecheckpass(tnode(inlineblock));
  4170. doinlinesimplify(tnode(inlineblock));
  4171. firstpass(tnode(inlineblock));
  4172. include(procdefinition.procoptions,po_inline);
  4173. result:=inlineblock;
  4174. { if the function result is used then verify that the blocknode
  4175. returns the same result type as the original callnode }
  4176. if (cnf_return_value_used in callnodeflags) and
  4177. (result.resultdef<>resultdef) then
  4178. internalerror(200709171);
  4179. { free the temps for the locals }
  4180. inlinelocals.free;
  4181. inlinelocals:=nil;
  4182. inlineinitstatement:=nil;
  4183. inlinecleanupstatement:=nil;
  4184. { if all that's left of the inlined function is an constant assignment
  4185. to the result, replace the whole block with the constant only }
  4186. n:=optimize_funcret_assignment(inlineblock);
  4187. if assigned(n) then
  4188. begin
  4189. inlineblock.free;
  4190. result:=n;
  4191. end;
  4192. {$ifdef DEBUGINLINE}
  4193. writeln;
  4194. writeln('**************************',tprocdef(procdefinition).mangledname);
  4195. printnode(output,result);
  4196. {$endif DEBUGINLINE}
  4197. dec(inlinelevel);
  4198. end;
  4199. end.