2
0

symdef.pas 332 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786
  1. {
  2. Symbol table implementation for the definitions
  3. Copyright (c) 1998-2005 by Florian Klaempfl, Pierre Muller
  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 symdef;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,widestr,
  23. { global }
  24. globtype,globals,tokens,constexp,
  25. { symtable }
  26. symconst,symbase,symtype,
  27. { node }
  28. node,
  29. { aasm }
  30. aasmtai,
  31. cpuinfo,
  32. cgbase,
  33. parabase
  34. ;
  35. type
  36. {************************************************
  37. TDef
  38. ************************************************}
  39. tgenericconstraintdata=class
  40. interfaces : tfpobjectlist;
  41. interfacesderef : tfplist;
  42. flags : tgenericconstraintflags;
  43. { only required while parsing }
  44. fileinfo : tfileposinfo;
  45. constructor create;
  46. destructor destroy;override;
  47. procedure ppuload(ppufile:tcompilerppufile);
  48. procedure ppuwrite(ppufile:tcompilerppufile);
  49. procedure buildderef;
  50. procedure deref;
  51. end;
  52. { trtti_attribute_list }
  53. trtti_attribute = class
  54. typesym : tsym;
  55. typesymderef : tderef;
  56. typeconstr : tdef;
  57. typeconstrderef : tderef;
  58. { these two are not stored in PPU }
  59. constructorcall : tnode;
  60. constructorpd : tdef;
  61. paras : array of tnode;
  62. constructor ppuload(ppufile:tcompilerppufile);
  63. procedure ppuwrite(ppufile:tcompilerppufile);
  64. procedure ppuload_subentries(ppufile:tcompilerppufile);
  65. procedure ppuwrite_subentries(ppufile:tcompilerppufile);
  66. destructor destroy;override;
  67. procedure buildderef;
  68. procedure deref;
  69. end;
  70. trtti_attribute_list = class
  71. rtti_attributes : TFPObjectList;
  72. { if the attribute list is bound to a def or symbol }
  73. is_bound : Boolean;
  74. class procedure bind(var dangling,owned:trtti_attribute_list);
  75. class procedure copyandbind(alist :trtti_attribute_list; var owned : trtti_attribute_list);
  76. procedure addattribute(atypesym:tsym;typeconstr:tdef;constructorcall:tnode;constref paras:array of tnode);
  77. procedure addattribute(attr:trtti_attribute);
  78. destructor destroy; override;
  79. function get_attribute_count:longint;
  80. procedure buildderef;
  81. procedure deref;
  82. class function ppuload(ppufile:tcompilerppufile):trtti_attribute_list;
  83. class procedure ppuwrite(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  84. class procedure ppuload_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  85. class procedure ppuwrite_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  86. end;
  87. { tstoreddef }
  88. tstoreddef = class(tdef)
  89. private
  90. {$ifdef symansistr}
  91. _fullownerhierarchyname : ansistring;
  92. {$else symansistr}
  93. _fullownerhierarchyname : pshortstring;
  94. {$endif symansistr}
  95. procedure writeentry(ppufile: tcompilerppufile; ibnr: byte);
  96. protected
  97. typesymderef : tderef;
  98. procedure ppuwrite_platform(ppufile:tcompilerppufile);virtual;
  99. procedure ppuload_platform(ppufile:tcompilerppufile);virtual;
  100. { a (possibly) reusable def is always created on the basis of another
  101. def, and contains a reference to this other def. If this other
  102. def is in a non-persistent symboltable, the new def cannot actually
  103. be safely reused everywhere in the current module. This routine
  104. abtracts that checking, and also restores the symtable stack
  105. (which had to be reset before creating the new def, so that the new
  106. def did not automatically get added to its top) }
  107. class procedure setup_reusable_def(origdef, newdef: tdef; res: PHashSetItem; oldsymtablestack: tsymtablestack);
  108. public
  109. {$ifdef EXTDEBUG}
  110. fileinfo : tfileposinfo;
  111. {$endif}
  112. { generic support }
  113. genericdef : tstoreddef;
  114. genericdefderef : tderef;
  115. generictokenbuf : tdynamicarray;
  116. { this list contains references to the symbols that make up the
  117. generic parameters; the symbols are not owned by this list
  118. Note: this list is allocated on demand! }
  119. genericparas : tfphashobjectlist;
  120. genericparaderefs : tfplist;
  121. { contains additional data if this def is a generic constraint
  122. Note: this class is allocated on demand! }
  123. genconstraintdata : tgenericconstraintdata;
  124. { this is Nil if the def has no RTTI attributes }
  125. rtti_attribute_list : trtti_attribute_list;
  126. { original def for "type <name>" declarations }
  127. orgdef : tstoreddef;
  128. orgdefderef : tderef;
  129. constructor create(dt:tdeftyp;doregister:boolean);
  130. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  131. destructor destroy;override;
  132. function getcopy : tstoreddef;virtual;
  133. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  134. { this is called directly after ppuload }
  135. procedure ppuload_subentries(ppufile:tcompilerppufile);virtual;
  136. { this is called directly after ppuwrite }
  137. procedure ppuwrite_subentries(ppufile:tcompilerppufile);virtual;
  138. procedure buildderef;override;
  139. procedure buildderefimpl;override;
  140. procedure deref;override;
  141. procedure derefimpl;override;
  142. function size:asizeint;override;
  143. function getvardef:longint;override;
  144. function alignment:shortint;override;
  145. function is_publishable : tpublishproperty;override;
  146. function needs_inittable : boolean;override;
  147. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  148. function rtti_mangledname(rt:trttitype):TSymStr;override;
  149. function OwnerHierarchyName: string; override;
  150. function OwnerHierarchyPrettyName: string; override;
  151. function fullownerhierarchyname(skipprocparams:boolean):TSymStr;override;
  152. function needs_separate_initrtti:boolean;override;
  153. function in_currentunit: boolean;
  154. { regvars }
  155. function is_intregable : boolean;
  156. function is_fpuregable : boolean;
  157. { def can be put into a register if it is const/immutable }
  158. function is_const_intregable : boolean;
  159. { generics }
  160. procedure initgeneric;
  161. { this function can be used to determine whether a def is really a
  162. generic declaration or just a normal type declared inside another
  163. generic }
  164. function is_generic:boolean;
  165. { same as above for specializations }
  166. function is_specialization:boolean;
  167. { generic utilities }
  168. function is_generic_param_const(index:integer):boolean;inline;
  169. function get_generic_param_def(index:integer):tdef;inline;
  170. { registers this def in the unit's deflist; no-op if already registered }
  171. procedure register_def; override;
  172. { add the def to the top of the symtable stack if it's not yet owned
  173. by another symtable }
  174. procedure maybe_put_in_symtable_stack;
  175. private
  176. savesize : asizeuint;
  177. end;
  178. tfiletyp = (ft_text,ft_typed,ft_untyped);
  179. tfiledef = class(tstoreddef)
  180. filetyp : tfiletyp;
  181. typedfiledef : tdef;
  182. typedfiledefderef : tderef;
  183. constructor createtext;virtual;
  184. constructor createuntyped;virtual;
  185. constructor createtyped(def : tdef);virtual;
  186. constructor ppuload(ppufile:tcompilerppufile);
  187. function getcopy : tstoreddef;override;
  188. { do not override this routine in platform-specific subclasses,
  189. override ppuwrite_platform instead }
  190. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  191. procedure buildderef;override;
  192. procedure deref;override;
  193. function GetTypeName:string;override;
  194. function getmangledparaname:TSymStr;override;
  195. function size:asizeint;override;
  196. procedure setsize;
  197. function alignment: shortint; override;
  198. end;
  199. tfiledefclass = class of tfiledef;
  200. tvariantdef = class(tstoreddef)
  201. varianttype : tvarianttype;
  202. constructor create(v : tvarianttype);virtual;
  203. constructor ppuload(ppufile:tcompilerppufile);
  204. function getcopy : tstoreddef;override;
  205. function GetTypeName:string;override;
  206. function alignment : shortint;override;
  207. { do not override this routine in platform-specific subclasses,
  208. override ppuwrite_platform instead }
  209. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  210. function getvardef:longint;override;
  211. procedure setsize;
  212. function is_publishable : tpublishproperty;override;
  213. function needs_inittable : boolean;override;
  214. end;
  215. tvariantdefclass = class of tvariantdef;
  216. tformaldef = class(tstoreddef)
  217. typed:boolean;
  218. constructor create(Atyped:boolean);virtual;
  219. constructor ppuload(ppufile:tcompilerppufile);
  220. { do not override this routine in platform-specific subclasses,
  221. override ppuwrite_platform instead }
  222. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  223. function GetTypeName:string;override;
  224. end;
  225. tformaldefclass = class of tformaldef;
  226. tforwarddef = class(tstoreddef)
  227. tosymname : pshortstring;
  228. forwardpos : tfileposinfo;
  229. constructor create(const s:string;const pos:tfileposinfo);virtual;
  230. destructor destroy;override;
  231. function getcopy:tstoreddef;override;
  232. function GetTypeName:string;override;
  233. end;
  234. tforwarddefclass = class of tforwarddef;
  235. tundefineddef = class(tstoreddef)
  236. constructor create(doregister:boolean);virtual;
  237. constructor ppuload(ppufile:tcompilerppufile);
  238. { do not override this routine in platform-specific subclasses,
  239. override ppuwrite_platform instead }
  240. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  241. function GetTypeName:string;override;
  242. end;
  243. tundefineddefclass = class of tundefineddef;
  244. terrordef = class(tstoreddef)
  245. constructor create;virtual;
  246. { do not override this routine in platform-specific subclasses,
  247. override ppuwrite_platform instead }
  248. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  249. function GetTypeName:string;override;
  250. function getmangledparaname : TSymStr;override;
  251. end;
  252. terrordefclass = class of terrordef;
  253. tabstractpointerdef = class(tstoreddef)
  254. pointeddef : tdef;
  255. pointeddefderef : tderef;
  256. constructor create(dt:tdeftyp;def:tdef);
  257. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  258. procedure ppuwrite(ppufile:tcompilerppufile);override;
  259. procedure buildderef;override;
  260. procedure deref;override;
  261. function size:asizeint;override;
  262. function alignment:shortint;override;
  263. end;
  264. tpointerdef = class(tabstractpointerdef)
  265. has_pointer_math : boolean;
  266. constructor create(def:tdef);virtual;
  267. { returns a pointerdef for def, reusing an existing one in case it
  268. exists in the current module }
  269. class function getreusable(def: tdef): tpointerdef; virtual;
  270. { same as above, but in case the def must never be freed after the
  271. current module has been compiled -- even if the def was not written
  272. to the ppu file (for defs in para locations, as we don't reset them
  273. so we don't have to recalculate them all the time) }
  274. class function getreusable_no_free(def: tdef): tpointerdef;
  275. function size:asizeint;override;
  276. function getcopy:tstoreddef;override;
  277. constructor ppuload(ppufile:tcompilerppufile);
  278. { do not override this routine in platform-specific subclasses,
  279. override ppuwrite_platform instead }
  280. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  281. function GetTypeName:string;override;
  282. {# returns the appropriate int type for pointer arithmetic with the given pointer type.
  283. When adding or subtracting a number to/from a pointer, this function returns the
  284. int type to which that number has to be converted, before the operation can be performed.
  285. Normally, this is sinttype, except on i8086, where it takes into account the
  286. special i8086 pointer types (near, far, huge). }
  287. function pointer_arithmetic_int_type:tdef;virtual;
  288. {# the unsigned version of pointer_arithmetic_int_type. Used with inc/dec. }
  289. function pointer_arithmetic_uint_type:tdef;virtual;
  290. {# returns the int type produced when subtracting two pointers of the given type.
  291. Normally, this is sinttype, except on i8086, where it takes into account the
  292. special i8086 pointer types (near, far, huge). }
  293. function pointer_subtraction_result_type:tdef;virtual;
  294. function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual;
  295. {# the integer index type used to convert the pointer to array (i.e. denotes int_type in: ptr[int_type]) }
  296. function converted_pointer_to_array_range_type:tdef;virtual;
  297. end;
  298. tpointerdefclass = class of tpointerdef;
  299. tprocdef = class;
  300. tabstractrecorddef= class(tstoreddef)
  301. private
  302. rttistring : string;
  303. {$ifdef DEBUG_NODE_XML}
  304. protected
  305. procedure XMLPrintDefData(var T: Text; Sym: TSym); override;
  306. {$endif DEBUG_NODE_XML}
  307. public
  308. objname,
  309. objrealname : PShortString;
  310. { for C++ classes: name of the library this class is imported from }
  311. { for Java classes/records: package name }
  312. import_lib : PShortString;
  313. symtable : TSymtable;
  314. cloneddef : tabstractrecorddef;
  315. cloneddefderef : tderef;
  316. objectoptions : tobjectoptions;
  317. rtti : trtti_directive;
  318. { for targets that initialise typed constants via explicit assignments
  319. instead of by generating an initialised data sectino }
  320. tcinitcode : tnode;
  321. constructor create(const n:string; dt:tdeftyp;doregister:boolean);
  322. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  323. procedure ppuwrite(ppufile:tcompilerppufile);override;
  324. destructor destroy; override;
  325. procedure buildderefimpl;override;
  326. procedure derefimpl;override;
  327. procedure check_forwards; virtual;
  328. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  329. function GetSymtable(t:tGetSymtable):TSymtable;override;
  330. function is_packed:boolean;
  331. function RttiName: string;
  332. { enumerator support }
  333. function search_enumerator_get: tprocdef; virtual;
  334. function search_enumerator_move: tprocdef; virtual;
  335. function search_enumerator_current: tsym; virtual;
  336. { JVM }
  337. function jvm_full_typename(with_package_name: boolean): string;
  338. { check if the symtable contains a float field }
  339. function contains_float_field : boolean;
  340. { check if the symtable contains a field that spans an aword boundary }
  341. function contains_cross_aword_field: boolean;
  342. { extended RTTI }
  343. procedure apply_rtti_directive(dir: trtti_directive); virtual;
  344. function is_visible_for_rtti(option: trtti_option; vis: tvisibility): boolean; inline;
  345. function rtti_visibilities_for_option(option: trtti_option): tvisibilities; inline;
  346. function has_extended_rtti: boolean; inline;
  347. end;
  348. pvariantrecdesc = ^tvariantrecdesc;
  349. tvariantrecbranch = record
  350. { we store only single values here and no ranges because tvariantrecdesc is only needed in iso mode
  351. which does not support range expressions in variant record definitions }
  352. values : array of Tconstexprint;
  353. nestedvariant : pvariantrecdesc;
  354. end;
  355. ppvariantrecdesc = ^pvariantrecdesc;
  356. tvariantrecdesc = record
  357. variantselector : tsym;
  358. variantselectorderef : tderef;
  359. branches : array of tvariantrecbranch;
  360. end;
  361. trecorddef = class(tabstractrecorddef)
  362. {$ifdef DEBUG_NODE_XML}
  363. protected
  364. function XMLPrintType: ansistring; override;
  365. {$endif DEBUG_NODE_XML}
  366. public
  367. variantrecdesc : pvariantrecdesc;
  368. isunion : boolean;
  369. constructor create(const n:string; p:TSymtable);virtual;
  370. constructor create_global_internal(const n: string; packrecords, recordalignmin: shortint); virtual;
  371. constructor create_internal(const n: string; packrecords, recordalignmin: shortint; where: tsymtable); virtual;
  372. function add_field_by_def(const optionalname: TIDString; def: tdef): tsym;
  373. procedure add_fields_from_deflist(fieldtypes: tfplist);
  374. constructor ppuload(ppufile:tcompilerppufile);
  375. destructor destroy;override;
  376. function getcopy : tstoreddef;override;
  377. { do not override this routine in platform-specific subclasses,
  378. override ppuwrite_platform instead }
  379. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  380. procedure buildderef;override;
  381. procedure deref;override;
  382. function size:asizeint;override;
  383. function alignment : shortint;override;
  384. function padalignment: shortint;
  385. function GetTypeName:string;override;
  386. { debug }
  387. function needs_inittable : boolean;override;
  388. function needs_separate_initrtti:boolean;override;
  389. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  390. end;
  391. trecorddefclass = class of trecorddef;
  392. tobjectdef = class;
  393. { TImplementedInterface }
  394. TImplementedInterface = class
  395. private
  396. fIOffset : longint;
  397. function GetIOffset: longint;
  398. public
  399. IntfDef : tobjectdef;
  400. IntfDefDeref : tderef;
  401. IType : tinterfaceentrytype;
  402. VtblImplIntf : TImplementedInterface;
  403. NameMappings : TFPHashList;
  404. ProcDefs : TFPObjectList;
  405. ImplementsGetter : tsym;
  406. ImplementsGetterDeref : tderef;
  407. ImplementsField : tsym;
  408. constructor create(aintf: tobjectdef);virtual;
  409. constructor create_deref(intfd,getterd:tderef);virtual;
  410. destructor destroy; override;
  411. function getcopy:TImplementedInterface;
  412. procedure buildderef;
  413. procedure deref;
  414. procedure AddMapping(const origname, newname: string);
  415. function GetMapping(const origname: string):string;
  416. procedure AddImplProc(pd:tprocdef);
  417. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  418. property IOffset: longint read GetIOffset write fIOffset;
  419. end;
  420. timplementedinterfaceclass = class of timplementedinterface;
  421. { tvmtentry }
  422. tvmtentry = record
  423. procdef : tprocdef;
  424. procdefderef : tderef;
  425. visibility : tvisibility;
  426. end;
  427. pvmtentry = ^tvmtentry;
  428. { tobjectdef }
  429. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  430. pmvcallstaticinfo = ^tmvcallstaticinfo;
  431. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  432. tobjectdef = class(tabstractrecorddef)
  433. private
  434. fcurrent_dispid: longint;
  435. {$ifdef DEBUG_NODE_XML}
  436. protected
  437. function XMLPrintType: ansistring; override;
  438. procedure XMLPrintDefInfo(var T: Text; Sym: TSym); override;
  439. procedure XMLPrintDefData(var T: Text; Sym: TSym); override;
  440. {$endif DEBUG_NODE_XML}
  441. public
  442. childof : tobjectdef;
  443. childofderef : tderef;
  444. { for Object Pascal helpers }
  445. extendeddef : tdef;
  446. extendeddefderef: tderef;
  447. helpertype : thelpertype;
  448. { for Objective-C: protocols and classes can have the same name there }
  449. objextname : pshortstring;
  450. { to be able to have a variable vmt position }
  451. { and no vmt field for objects without virtuals }
  452. vmtentries : TFPList;
  453. vmcallstaticinfo : pmvcallstaticinfo;
  454. vmt_field : tsym;
  455. vmt_fieldderef : tderef;
  456. iidguid : pguid;
  457. iidstr : pshortstring;
  458. { store implemented interfaces defs and name mappings }
  459. ImplementedInterfaces : TFPObjectList;
  460. { number of abstract methods (used by JVM target to determine whether
  461. or not the class should be marked as abstract: must be done if 1 or
  462. more abstract methods) }
  463. abstractcnt : longint;
  464. writing_class_record_dbginfo,
  465. { a class of this type has been created in this module }
  466. created_in_current_module,
  467. { a loadvmtnode for this class has been created in this
  468. module, so if a classrefdef variable of this or a parent
  469. class is used somewhere to instantiate a class, then this
  470. class may be instantiated
  471. }
  472. maybe_created_in_current_module,
  473. { a "class of" this particular class has been created in
  474. this module
  475. }
  476. classref_created_in_current_module : boolean;
  477. objecttype : tobjecttyp;
  478. { for interfaces that can be invoked using Invoke(),
  479. this is the definition of the hidden class that is generated by the compiler.
  480. we need this definition to reference it in the RTTI.
  481. Since interfaces can inherit, so can these hidden classes,
  482. so we need to write this to the ppu to be able to reference the parents.
  483. }
  484. hiddenclassdef : tobjectdef;
  485. hiddenclassdefref : tderef;
  486. constructor create(ot:tobjecttyp;const n:string;c:tobjectdef;doregister:boolean);virtual;
  487. constructor ppuload(ppufile:tcompilerppufile);
  488. destructor destroy;override;
  489. function getcopy : tstoreddef;override;
  490. { do not override this routine in platform-specific subclasses,
  491. override ppuwrite_platform instead }
  492. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  493. function GetTypeName:string;override;
  494. procedure buildderef;override;
  495. procedure deref;override;
  496. procedure derefimpl;override;
  497. procedure copyvmtentries(objdef:tobjectdef);
  498. function getparentdef:tdef;override;
  499. function size : asizeint;override;
  500. function alignment:shortint;override;
  501. function vmtmethodoffset(index:longint):longint;
  502. function members_need_inittable : boolean;
  503. { this should be called when this class implements an interface }
  504. procedure prepareguid;
  505. function is_publishable : tpublishproperty;override;
  506. function needs_inittable : boolean;override;
  507. function needs_separate_initrtti : boolean;override;
  508. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  509. function rtti_mangledname(rt:trttitype):TSymStr;override;
  510. function is_unique_objpasdef: boolean;
  511. function vmt_mangledname : TSymStr;
  512. function vmt_def: trecorddef;
  513. procedure check_forwards; override;
  514. procedure insertvmt;
  515. function vmt_offset: asizeint;
  516. procedure set_parent(c : tobjectdef);
  517. function find_destructor: tprocdef;
  518. function implements_any_interfaces: boolean;
  519. function register_implemented_interface(intfdef:tobjectdef;useguid:boolean):timplementedinterface;
  520. { dispinterface support }
  521. function get_next_dispid: longint;
  522. { enumerator support }
  523. function search_enumerator_get: tprocdef; override;
  524. function search_enumerator_move: tprocdef; override;
  525. function search_enumerator_current: tsym; override;
  526. { WPO }
  527. procedure register_created_object_type;override;
  528. procedure register_maybe_created_object_type;
  529. procedure register_created_classref_type;
  530. procedure register_vmt_call(index:longint);
  531. { ObjC }
  532. procedure finish_objc_data;
  533. function check_objc_types: boolean;
  534. { C++ }
  535. procedure finish_cpp_data;
  536. procedure apply_rtti_directive(dir: trtti_directive); override;
  537. end;
  538. tobjectdefclass = class of tobjectdef;
  539. tclassrefdef = class(tabstractpointerdef)
  540. constructor create(def:tdef);virtual;
  541. constructor ppuload(ppufile:tcompilerppufile);
  542. { do not override this routine in platform-specific subclasses,
  543. override ppuwrite_platform instead }
  544. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  545. function getcopy:tstoreddef;override;
  546. function GetTypeName:string;override;
  547. function is_publishable : tpublishproperty;override;
  548. function rtti_mangledname(rt:trttitype):TSymStr;override;
  549. procedure register_created_object_type;override;
  550. end;
  551. tclassrefdefclass = class of tclassrefdef;
  552. tarraydef = class(tstoreddef)
  553. lowrange,
  554. highrange : asizeint;
  555. rangedef : tdef;
  556. rangedefderef : tderef;
  557. arrayoptions : tarraydefoptions;
  558. symtable : TSymtable;
  559. protected
  560. _elementdef : tdef;
  561. _elementdefderef : tderef;
  562. procedure setelementdef(def:tdef);
  563. class function getreusable_intern(def: tdef; elems: asizeint; const options: tarraydefoptions): tarraydef;
  564. public
  565. function elesize : asizeint;
  566. function elepackedbitsize : asizeint;
  567. function elecount : asizeuint;
  568. constructor create_from_pointer(def: tpointerdef);virtual;
  569. constructor create(l, h: asizeint; def: tdef);virtual;
  570. constructor create_vector(l,h:asizeint; def:tdef);
  571. constructor create_openarray;virtual;
  572. class function getreusable(def: tdef; elems: asizeint): tarraydef;
  573. class function getreusable_vector(def: tdef; elems: asizeint): tarraydef;
  574. { same as above, but in case the def must never be freed after the
  575. current module has been compiled -- even if the def was not written
  576. to the ppu file (for defs in para locations, as we don't reset them
  577. so we don't have to recalculate them all the time) }
  578. class function getreusable_no_free(def: tdef; elems: asizeint): tarraydef;
  579. class function getreusable_no_free_vector(def: tdef; elems: asizeint): tarraydef;
  580. constructor ppuload(ppufile:tcompilerppufile);
  581. destructor destroy; override;
  582. function getcopy : tstoreddef;override;
  583. { do not override this routine in platform-specific subclasses,
  584. override ppuwrite_platform instead }
  585. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  586. function GetTypeName:string;override;
  587. function getmangledparaname : TSymStr;override;
  588. procedure buildderef;override;
  589. procedure deref;override;
  590. function size : asizeint;override;
  591. function alignment : shortint;override;
  592. { returns the label of the range check string }
  593. function needs_inittable : boolean;override;
  594. function needs_separate_initrtti : boolean;override;
  595. property elementdef : tdef read _elementdef write setelementdef;
  596. function is_publishable : tpublishproperty;override;
  597. function is_hwvector: boolean;
  598. end;
  599. tarraydefclass = class of tarraydef;
  600. torddef = class(tstoreddef)
  601. low,high : TConstExprInt;
  602. ordtype : tordtype;
  603. constructor create(t : tordtype;v,b : TConstExprInt; doregister: boolean);virtual;
  604. constructor ppuload(ppufile:tcompilerppufile);
  605. function getcopy : tstoreddef;override;
  606. { do not override this routine in platform-specific subclasses,
  607. override ppuwrite_platform instead }
  608. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  609. function is_publishable : tpublishproperty;override;
  610. function GetTypeName:string;override;
  611. function alignment:shortint;override;
  612. procedure setsize;
  613. function packedbitsize: asizeint; override;
  614. function getvardef : longint;override;
  615. end;
  616. torddefclass = class of torddef;
  617. tfloatdef = class(tstoreddef)
  618. floattype : tfloattype;
  619. constructor create(t: tfloattype; doregister: boolean);virtual;
  620. constructor ppuload(ppufile:tcompilerppufile);
  621. function getcopy : tstoreddef;override;
  622. { do not override this routine in platform-specific subclasses,
  623. override ppuwrite_platform instead }
  624. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  625. function GetTypeName:string;override;
  626. function is_publishable : tpublishproperty;override;
  627. function alignment:shortint;override;
  628. function structalignment: shortint;override;
  629. procedure setsize;
  630. function getvardef:longint;override;
  631. end;
  632. tfloatdefclass = class of tfloatdef;
  633. { tabstractprocdef }
  634. tprocnameoption = (pno_showhidden, pno_proctypeoption, pno_paranames,
  635. pno_ownername, pno_noclassmarker, pno_noleadingdollar,
  636. pno_mangledname, pno_noparams, pno_prettynames);
  637. tprocnameoptions = set of tprocnameoption;
  638. tproccopytyp = (pc_normal,
  639. {$ifdef i8086}
  640. { the address in a far format }
  641. pc_far_address,
  642. { the offset part of the far address }
  643. pc_offset,
  644. {$endif i8086}
  645. { creates a procvardef describing only the code pointer
  646. of a method/netsted function/... }
  647. pc_address_only,
  648. { everything except for hidden parameters }
  649. pc_normal_no_hidden,
  650. { everything except for the parameters (because they
  651. might be moved over to the copy) }
  652. pc_normal_no_paras,
  653. { always creates a top-level function, removes all
  654. special parameters (self, vmt, parentfp, ...) }
  655. pc_bareproc
  656. );
  657. tcacheableproccopytyp = pc_normal..pc_address_only;
  658. tabstractprocdef = class(tstoreddef)
  659. { saves a definition to the return type }
  660. returndef : tdef;
  661. returndefderef : tderef;
  662. parast : TSymtable;
  663. paras : tparalist;
  664. proctypeoption : tproctypeoption;
  665. proccalloption : tproccalloption;
  666. procoptions : tprocoptions;
  667. callerargareasize,
  668. calleeargareasize: pint;
  669. {$ifdef m68k}
  670. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  671. {$endif}
  672. funcretloc : array[callerside..calleeside] of TCGPara;
  673. has_paraloc_info : tcallercallee; { paraloc info is available }
  674. { number of user visible parameters }
  675. maxparacount,
  676. minparacount : byte;
  677. constructor create(dt:tdeftyp;level:byte;doregister:boolean);
  678. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  679. destructor destroy;override;
  680. procedure ppuwrite(ppufile:tcompilerppufile);override;
  681. procedure buildderef;override;
  682. procedure deref;override;
  683. procedure calcparas;
  684. function mangledprocparanames(oldlen : longint) : string;
  685. function typename_paras(pno: tprocnameoptions): ansistring;
  686. function is_methodpointer:boolean;virtual;
  687. function is_addressonly:boolean;virtual;
  688. function no_self_node:boolean;
  689. { get either a copy as a procdef or procvardef }
  690. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef; virtual;
  691. function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual;
  692. procedure check_mark_as_nested;
  693. procedure init_paraloc_info(side: tcallercallee);
  694. procedure done_paraloc_info(side: tcallercallee);
  695. function stack_tainting_parameter(side: tcallercallee): boolean;
  696. function is_pushleftright: boolean;virtual;
  697. function address_type:tdef;virtual;
  698. { address type, generated for ofs() }
  699. function ofs_address_type:tdef;virtual;
  700. procedure declared_far;virtual;
  701. procedure declared_near;virtual;
  702. function generate_safecall_wrapper: boolean; virtual;
  703. { returns true if the def is a generic param of the procdef }
  704. function is_generic_param(def:tdef): boolean;
  705. function wpo_may_create_instance(optionalmethodpointer: tnode): boolean;
  706. private
  707. procedure count_para(p:TObject;arg:pointer);
  708. procedure insert_para(p:TObject;arg:pointer);
  709. end;
  710. tprocvardef = class(tabstractprocdef)
  711. constructor create(level:byte;doregister:boolean);virtual;
  712. { returns a procvardef that represents the address of a proc(var)def }
  713. class function getreusableprocaddr(def: tabstractprocdef; copytyp: tcacheableproccopytyp): tprocvardef; virtual;
  714. { same as above, but in case the def must never be freed after the
  715. current module has been compiled -- even if the def was not written
  716. to the ppu file (for defs in para locations, as we don't reset them
  717. so we don't have to recalculate them all the time) }
  718. class function getreusableprocaddr_no_free(def: tabstractprocdef): tprocvardef;
  719. constructor ppuload(ppufile:tcompilerppufile);
  720. function getcopy : tstoreddef;override;
  721. { do not override this routine in platform-specific subclasses,
  722. override ppuwrite_platform instead }
  723. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  724. function GetSymtable(t:tGetSymtable):TSymtable;override;
  725. function size : asizeint;override;
  726. function GetTypeName:string;override;
  727. function is_publishable : tpublishproperty;override;
  728. function is_methodpointer:boolean;override;
  729. function is_addressonly:boolean;override;
  730. function getmangledparaname:TSymStr;override;
  731. function getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef; override;
  732. end;
  733. tprocvardefclass = class of tprocvardef;
  734. tmessageinf = record
  735. case integer of
  736. 0 : (str : pshortstring);
  737. 1 : (i : longint);
  738. end;
  739. tinlininginfo = record
  740. { node tree }
  741. code : tnode;
  742. flags : tprocinfoflags;
  743. end;
  744. pinlininginfo = ^tinlininginfo;
  745. tcapturedsyminfo = record
  746. sym : tsym;
  747. def : tdef;
  748. { the location where the symbol was first encountered }
  749. fileinfo : tfileposinfo;
  750. end;
  751. pcapturedsyminfo = ^tcapturedsyminfo;
  752. timplprocdefinfo = record
  753. resultname : pshortstring;
  754. parentfpstruct: tsym;
  755. parentfpstructptrtype: tdef;
  756. parentfpinitblock: tnode;
  757. procstarttai,
  758. procendtai : tai;
  759. skpara: pointer;
  760. personality: tprocdef;
  761. was_anonymous,
  762. has_capturer,
  763. forwarddef,
  764. interfacedef : boolean;
  765. hasforward : boolean;
  766. is_implemented : boolean;
  767. capturedsyms : tfplist;
  768. end;
  769. pimplprocdefinfo = ^timplprocdefinfo;
  770. { tprocdef }
  771. tprocdef = class(tabstractprocdef)
  772. protected
  773. {$ifdef symansistr}
  774. _mangledname : ansistring;
  775. {$else symansistr}
  776. _mangledname : pshortstring;
  777. {$endif}
  778. _parentfpsym : tsym;
  779. { information that is only required until the implementation of the
  780. procdef has been handled }
  781. implprocdefinfo : pimplprocdefinfo;
  782. function store_localst:boolean;
  783. function GetResultName: PShortString;
  784. procedure SetResultName(AValue: PShortString);
  785. function GetParentFPStruct: tsym;
  786. procedure SetParentFPStruct(AValue: tsym);
  787. function GetParentFPStructPtrType: tdef;
  788. procedure SetParentFPStructPtrType(AValue: tdef);
  789. function GetParentFPInitBlock: tnode;
  790. procedure SetParentFPInitBlock(AValue: tnode);
  791. function Getprocstarttai: tai;
  792. procedure Setprocstarttai(AValue: tai);
  793. function Getprocendtai: tai;
  794. procedure Setprocendtai(AValue: tai);
  795. function Getskpara: pointer;
  796. procedure Setskpara(AValue: pointer);
  797. function Getpersonality: tprocdef;
  798. procedure Setpersonality(AValue: tprocdef);
  799. function Getforwarddef: boolean;
  800. procedure Setforwarddef(AValue: boolean);
  801. function Getinterfacedef: boolean;
  802. procedure Setinterfacedef(AValue: boolean);virtual;
  803. function Gethasforward: boolean;
  804. procedure Sethasforward(AValue: boolean);
  805. function GetIsEmpty: boolean;
  806. procedure SetIsEmpty(AValue: boolean);
  807. function GetHasInliningInfo: boolean;
  808. procedure SetHasInliningInfo(AValue: boolean);
  809. function Getis_implemented: boolean;
  810. procedure Setis_implemented(AValue: boolean);
  811. function getwas_anonymous:boolean;
  812. procedure setwas_anonymous(avalue:boolean);
  813. function gethas_capturer:boolean;
  814. procedure sethas_capturer(avalue:boolean);
  815. function Getcapturedsyms:tfplist;
  816. function getparentfpsym: tsym;
  817. public
  818. messageinf : tmessageinf;
  819. dispid : longint;
  820. {$ifndef EXTDEBUG}
  821. { where is this function defined and what were the symbol
  822. flags, needed here because there
  823. is only one symbol for all overloaded functions
  824. EXTDEBUG has fileinfo in tdef (PFV) }
  825. fileinfo : tfileposinfo;
  826. {$endif}
  827. symoptions : tsymoptions;
  828. deprecatedmsg : pshortstring;
  829. { generic support }
  830. genericdecltokenbuf : tdynamicarray;
  831. { symbol owning this definition }
  832. procsym : tsym;
  833. procsymderef : tderef;
  834. { alias names }
  835. aliasnames : TCmdStrList;
  836. { symtables }
  837. localst : TSymtable;
  838. funcretsym : tsym;
  839. funcretsymderef : tderef;
  840. struct : tabstractrecorddef;
  841. structderef : tderef;
  842. implprocoptions: timplprocoptions;
  843. { import info }
  844. import_dll,
  845. import_name : pshortstring;
  846. { info for inlining the subroutine, if this pointer is nil,
  847. the procedure can't be inlined }
  848. inlininginfo : pinlininginfo;
  849. import_nr : word;
  850. extnumber : word;
  851. { set to a value different from tsk_none in case this procdef is for
  852. a routine that has to be internally generated by the compiler }
  853. synthetickind: tsynthetickind;
  854. visibility : tvisibility;
  855. {$ifndef DISABLE_FAST_OVERLOAD_PATCH}
  856. seenmarker : pointer; // used for filtering in tcandidate
  857. {$endif}
  858. {$ifdef symansistr}
  859. section: ansistring;
  860. {$else symansistr}
  861. section: pshortstring;
  862. {$endif}
  863. { only needed when actually compiling a unit, no need to save/load from ppu }
  864. invoke_helper : tprocdef;
  865. copied_from : tprocdef;
  866. constructor create(level:byte;doregister:boolean);virtual;
  867. constructor ppuload(ppufile:tcompilerppufile);
  868. destructor destroy;override;
  869. procedure freeimplprocdefinfo;
  870. { do not override this routine in platform-specific subclasses,
  871. override ppuwrite_platform instead }
  872. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  873. procedure buildderef;override;
  874. procedure buildderefimpl;override;
  875. procedure deref;override;
  876. procedure derefimpl;override;
  877. function GetSymtable(t:tGetSymtable):TSymtable;override;
  878. { warnings:
  879. * the symtablestack top has to be the symtable to which the copy
  880. should be added
  881. * getcopy does not create a finished/ready-to-use procdef; it
  882. needs to be finalised afterwards by calling
  883. symcreat.finish_copied_procdef() afterwards
  884. }
  885. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef; override;
  886. function getcopy: tstoreddef; override;
  887. function GetTypeName : string;override;
  888. function mangledname : TSymStr; virtual;
  889. procedure setmangledname(const s : TSymStr);
  890. function needsglobalasmsym: boolean;
  891. procedure setcompilerprocname;
  892. function fullprocname(showhidden:boolean):string;
  893. function customprocname(pno: tprocnameoptions):ansistring;
  894. function defaultmangledname: TSymStr;
  895. function cplusplusmangledname : TSymStr;
  896. function objcmangledname : TSymStr;
  897. function is_methodpointer:boolean;override;
  898. function is_addressonly:boolean;override;
  899. procedure make_external;
  900. procedure init_genericdecl;
  901. function get_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean; virtual;
  902. function get_safecall_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean; virtual;
  903. procedure add_captured_sym(sym:tsym;def:tdef;const filepos:tfileposinfo);
  904. { returns whether the mangled name or any of its aliases is equal to
  905. s }
  906. function has_alias_name(const s: TSymStr):boolean;
  907. { aliases to fields only required when a function is implemented in
  908. the current unit }
  909. property resultname: PShortString read GetResultName write SetResultName;
  910. { temporary reference to structure containing copies of all local
  911. variables and parameters accessed by nested routines; reference to
  912. this structure is passed as "parent frame pointer" on targets that
  913. lack this concept (at least JVM and LLVM); no need to save to/
  914. restore from ppu, since nested routines are always in the same
  915. unit }
  916. property parentfpstruct: tsym read GetParentFPStruct write SetParentFPStruct;
  917. { pointer to parentfpstruct's type (not yet valid during parsing, so
  918. cannot be used for $parentfp parameter) (no need to save to ppu) }
  919. property parentfpstructptrtype: tdef read GetParentFPStructPtrType write SetParentFPStructPtrType;
  920. { code to copy the parameters accessed from nested routines into the
  921. parentfpstruct (no need to save to ppu) }
  922. property parentfpinitblock: tnode read GetParentFPInitBlock write SetParentFPInitBlock;
  923. { First/last assembler symbol/instruction in aasmoutput list.
  924. Note: initialised after compiling the code for the procdef, but
  925. not saved to/restored from ppu. Used when inserting debug info }
  926. property procstarttai: tai read Getprocstarttai write Setprocstarttai;
  927. property procendtai: tai read Getprocendtai write Setprocendtai;
  928. { optional parameter for the synthetic routine generation logic }
  929. property skpara: pointer read Getskpara write Setskpara;
  930. { ABI-conformant exception handling personality function }
  931. property personality: tprocdef read Getpersonality write Setpersonality;
  932. { true, if the procedure is only declared
  933. (forward procedure) }
  934. property forwarddef: boolean read Getforwarddef write Setforwarddef;
  935. { true if the procedure is declared in the interface }
  936. property interfacedef: boolean read Getinterfacedef write Setinterfacedef;
  937. { true if the procedure has a forward declaration }
  938. property hasforward: boolean read Gethasforward write Sethasforward;
  939. { true if the routine's body is empty }
  940. property isempty: boolean read GetIsEmpty write SetIsEmpty;
  941. { true if all information required to inline this routine is available }
  942. property has_inlininginfo: boolean read GetHasInliningInfo write SetHasInliningInfo;
  943. { returns the $parentfp parameter for nested routines }
  944. property parentfpsym: tsym read getparentfpsym;
  945. { true if the implementation part for this procdef has been handled }
  946. property is_implemented: boolean read Getis_implemented write Setis_implemented;
  947. { valid if the procdef captures any symbols from outer scopes }
  948. property capturedsyms:tfplist read Getcapturedsyms;
  949. { true if this procdef was originally an anonymous function }
  950. property was_anonymous:boolean read getwas_anonymous write setwas_anonymous;
  951. { true if the procdef has a capturer for anonymous functions }
  952. property has_capturer:boolean read gethas_capturer write sethas_capturer;
  953. end;
  954. tprocdefclass = class of tprocdef;
  955. { single linked list of overloaded procs }
  956. pprocdeflist = ^tprocdeflist;
  957. tprocdeflist = record
  958. def : tprocdef;
  959. defderef : tderef;
  960. next : pprocdeflist;
  961. end;
  962. tstringdef = class(tstoreddef)
  963. encoding : tstringencoding;
  964. stringtype : tstringtype;
  965. len : asizeint;
  966. constructor createshort(l: byte; doregister: boolean);virtual;
  967. constructor loadshort(ppufile:tcompilerppufile);
  968. constructor createlong(l: asizeint; doregister: boolean);virtual;
  969. constructor loadlong(ppufile:tcompilerppufile);
  970. constructor createansi(aencoding: tstringencoding; doregister: boolean);virtual;
  971. constructor loadansi(ppufile:tcompilerppufile);
  972. constructor createwide(doregister: boolean);virtual;
  973. constructor loadwide(ppufile:tcompilerppufile);
  974. constructor createunicode(doregister: boolean);virtual;
  975. constructor loadunicode(ppufile:tcompilerppufile);virtual;
  976. function getcopy : tstoreddef;override;
  977. function stringtypname:string;
  978. { do not override this routine in platform-specific subclasses,
  979. override ppuwrite_platform instead }
  980. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  981. function GetTypeName:string;override;
  982. function getmangledparaname:TSymStr;override;
  983. function is_publishable : tpublishproperty;override;
  984. function size:asizeint;override;
  985. function alignment : shortint;override;
  986. function needs_inittable : boolean;override;
  987. function getvardef:longint;override;
  988. { returns the default char type def for the string }
  989. function get_default_char_type: tdef;
  990. { returns the default string type }
  991. function get_default_string_type: tdef;
  992. end;
  993. tstringdefclass = class of tstringdef;
  994. tenumdef = class(tstoreddef)
  995. minval,
  996. maxval : asizeint;
  997. basedef : tenumdef;
  998. basedefderef : tderef;
  999. symtable : TSymtable;
  1000. has_jumps : boolean;
  1001. constructor create;virtual;
  1002. constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);virtual;
  1003. constructor ppuload(ppufile:tcompilerppufile);
  1004. destructor destroy;override;
  1005. function getcopy : tstoreddef;override;
  1006. { do not override this routine in platform-specific subclasses,
  1007. override ppuwrite_platform instead }
  1008. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  1009. procedure buildderef;override;
  1010. procedure deref;override;
  1011. function GetTypeName:string;override;
  1012. function is_publishable : tpublishproperty;override;
  1013. procedure calcsavesize(packenum: shortint);
  1014. function packedbitsize: asizeint; override;
  1015. procedure setmax(_max:asizeint);
  1016. procedure setmin(_min:asizeint);
  1017. function min:asizeint;
  1018. function max:asizeint;
  1019. function getfirstsym:tsym;
  1020. function int2enumsym(l: asizeint): tsym;
  1021. { returns basedef if assigned, otherwise self }
  1022. function getbasedef: tenumdef;
  1023. end;
  1024. tenumdefclass = class of tenumdef;
  1025. tsetdef = class(tstoreddef)
  1026. elementdef : tdef;
  1027. elementdefderef : tderef;
  1028. { setbase is the value of the lowest value being representable by the set, this could
  1029. be lower then the lowest value being a valid value from the declaration: a set [3..4] might
  1030. have a setbase of 0 for code generation/alignment reasons }
  1031. setbase,
  1032. { setlow is the lowest value valid according to the declaration of a set, i.e. for a set [3..4] it is really 3 }
  1033. setlow,
  1034. setmax : asizeint;
  1035. constructor create(def: tdef; low, high: asizeint; doregister: boolean);virtual;
  1036. constructor ppuload(ppufile:tcompilerppufile);
  1037. function getcopy : tstoreddef;override;
  1038. { do not override this routine in platform-specific subclasses,
  1039. override ppuwrite_platform instead }
  1040. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  1041. procedure buildderef;override;
  1042. procedure deref;override;
  1043. function GetTypeName:string;override;
  1044. function is_publishable : tpublishproperty;override;
  1045. function alignment: shortint; override;
  1046. end;
  1047. tsetdefclass = class of tsetdef;
  1048. tgenericdummyentry = class
  1049. dummysym : tsym;
  1050. resolvedsym : tsym;
  1051. end;
  1052. tdefawaresymtablestack = class(TSymtablestack)
  1053. private
  1054. procedure add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  1055. procedure remove_helpers_and_generics(st:tsymtable);inline;
  1056. procedure remove_helpers(st:tsymtable);
  1057. procedure remove_generics(st:tsymtable);
  1058. procedure pushcommon(st:tsymtable);inline;
  1059. public
  1060. procedure push(st: TSymtable); override;
  1061. procedure pushafter(st,afterst:TSymtable); override;
  1062. procedure pop(st: TSymtable); override;
  1063. end;
  1064. var
  1065. current_structdef: tabstractrecorddef; { used for private functions check !! }
  1066. current_genericdef: tstoreddef; { used to reject declaration of generic class inside generic class }
  1067. current_specializedef: tstoreddef; { used to implement usage of generic class in itself }
  1068. cfiledef: tfiledefclass;
  1069. cvariantdef: tvariantdefclass;
  1070. cformaldef: tformaldefclass;
  1071. cforwarddef: tforwarddefclass;
  1072. cundefineddef: tundefineddefclass;
  1073. cerrordef: terrordefclass;
  1074. cpointerdef: tpointerdefclass;
  1075. crecorddef: trecorddefclass;
  1076. cimplementedinterface: timplementedinterfaceclass;
  1077. cobjectdef: tobjectdefclass;
  1078. cclassrefdef: tclassrefdefclass;
  1079. carraydef: tarraydefclass;
  1080. corddef: torddefclass;
  1081. cfloatdef: tfloatdefclass;
  1082. cprocvardef: tprocvardefclass;
  1083. cprocdef: tprocdefclass;
  1084. cstringdef: tstringdefclass;
  1085. cenumdef: tenumdefclass;
  1086. csetdef: tsetdefclass;
  1087. { default types }
  1088. generrordef, { error in definition }
  1089. voidpointertype, { pointer for Void-pointeddef }
  1090. charpointertype, { pointer for Char-pointeddef }
  1091. widecharpointertype, { pointer for WideChar-pointeddef }
  1092. voidcodepointertype, { pointer to code; corresponds to System.CodePointer }
  1093. voidstackpointertype, { the pointer type used for accessing parameters and local vars on the stack }
  1094. parentfpvoidpointertype, { void pointer with the size of the hidden parentfp parameter, passed to nested functions }
  1095. {$ifdef x86}
  1096. voidnearpointertype,
  1097. voidnearcspointertype,
  1098. voidneardspointertype,
  1099. voidnearsspointertype,
  1100. voidnearespointertype,
  1101. voidnearfspointertype,
  1102. voidneargspointertype,
  1103. {$ifdef i8086}
  1104. voidfarpointertype,
  1105. voidhugepointertype,
  1106. charnearpointertype,
  1107. charfarpointertype,
  1108. charhugepointertype,
  1109. bytefarpointertype, { used for Mem[] }
  1110. wordfarpointertype, { used for MemW[] }
  1111. longintfarpointertype, { used for MemL[] }
  1112. {$endif i8086}
  1113. {$endif x86}
  1114. {$ifdef wasm}
  1115. wasmvoidexternreftype,
  1116. {$endif wasm}
  1117. cundefinedtype,
  1118. cformaltype, { unique formal definition }
  1119. ctypedformaltype, { unique typed formal definition }
  1120. voidtype, { Void (procedure) }
  1121. cansichartype, { Char }
  1122. cwidechartype, { WideChar }
  1123. cchartype, { either cansichartype or cwidechartype. Do not free }
  1124. pasbool1type, { boolean type }
  1125. pasbool8type,
  1126. pasbool16type,
  1127. pasbool32type,
  1128. pasbool64type,
  1129. bool8type,
  1130. bool16type,
  1131. bool32type,
  1132. bool64type, { implement me }
  1133. {$ifdef llvm}
  1134. llvmbool1type, { LLVM i1 type }
  1135. {$endif llvm}
  1136. u8inttype, { 8-Bit unsigned integer }
  1137. s8inttype, { 8-Bit signed integer }
  1138. u16inttype, { 16-Bit unsigned integer }
  1139. s16inttype, { 16-Bit signed integer }
  1140. u24inttype, { 24-Bit unsigned integer }
  1141. s24inttype, { 24-Bit signed integer }
  1142. u32inttype, { 32-Bit unsigned integer }
  1143. s32inttype, { 32-Bit signed integer }
  1144. u40inttype, { 40-Bit unsigned integer }
  1145. s40inttype, { 40-Bit signed integer }
  1146. u48inttype, { 48-Bit unsigned integer }
  1147. s48inttype, { 48-Bit signed integer }
  1148. u56inttype, { 56-Bit unsigned integer }
  1149. s56inttype, { 56-Bit signed integer }
  1150. u64inttype, { 64-bit unsigned integer }
  1151. s64inttype, { 64-bit signed integer }
  1152. u128inttype, { 128-bit unsigned integer }
  1153. s128inttype, { 128-bit signed integer }
  1154. s32floattype, { 32 bit floating point number }
  1155. s64floattype, { 64 bit floating point number }
  1156. s80floattype, { 80 bit floating point number }
  1157. sc80floattype, { 80 bit floating point number but stored like in C }
  1158. s64currencytype, { pointer to a currency type }
  1159. cshortstringtype, { pointer to type of short string const }
  1160. clongstringtype, { pointer to type of long string const }
  1161. cansistringtype, { pointer to type of ansi string const }
  1162. cwidestringtype, { pointer to type of wide string const }
  1163. cunicodestringtype,
  1164. openshortstringtype, { pointer to type of an open shortstring,
  1165. needed for readln() }
  1166. openchararraytype, { pointer to type of an open array of char,
  1167. needed for readln() }
  1168. cfiletype, { get the same definition for all file }
  1169. { used for stabs }
  1170. methodpointertype, { typecasting of methodpointers to extract self }
  1171. nestedprocpointertype, { typecasting of nestedprocpointers to extract parentfp }
  1172. hresultdef,
  1173. typekindtype, { def of TTypeKind for correct handling of GetTypeKind parameters }
  1174. { we use only one variant def for every variant class }
  1175. cvarianttype,
  1176. colevarianttype,
  1177. { default integer type, normally s32inttype on 32 bit systems and s64bittype on 64 bit systems }
  1178. sinttype,
  1179. uinttype,
  1180. { integer types corresponding to OS_SINT/OS_INT }
  1181. ossinttype,
  1182. osuinttype,
  1183. { integer types corresponding to the ALU size, sizeof(aint) and the ALUSInt/ALUUInt types in the system unit }
  1184. alusinttype,
  1185. aluuinttype,
  1186. { integer types corresponding to SizeInt and SizeUInt for the target platform }
  1187. sizeuinttype,
  1188. sizesinttype,
  1189. { unsigned and signed ord type with the same size as a pointer }
  1190. ptruinttype,
  1191. ptrsinttype,
  1192. { unsigned and signed ord type with the same size as a codepointer }
  1193. codeptruinttype,
  1194. codeptrsinttype,
  1195. { several types to simulate more or less C++ objects for GDB }
  1196. vmttype,
  1197. vmtarraytype,
  1198. { type of classrefs, used for stabs }
  1199. pvmttype,
  1200. { return type of the setjmp function }
  1201. exceptionreasontype : tdef;
  1202. { pointer to the anchestor of all classes }
  1203. class_tobject : tobjectdef;
  1204. { pointer to the base type for custom attributes }
  1205. class_tcustomattribute : tobjectdef;
  1206. { pointer to the ancestor of all COM interfaces }
  1207. interface_iunknown : tobjectdef;
  1208. { pointer to the ancestor of all dispinterfaces }
  1209. interface_idispatch : tobjectdef;
  1210. { pointer to the TGUID type
  1211. of all interfaces }
  1212. rec_tguid : trecorddef;
  1213. { jump buffer type, used by setjmp }
  1214. rec_jmp_buf : trecorddef;
  1215. { system.texceptaddr type, used by fpc_pushexceptaddr }
  1216. rec_exceptaddr: trecorddef;
  1217. { Objective-C base types }
  1218. objc_metaclasstype,
  1219. objc_superclasstype,
  1220. objc_idtype,
  1221. objc_seltype : tpointerdef;
  1222. objc_objecttype : trecorddef;
  1223. { base type of @protocol(protocolname) Objective-C statements }
  1224. objc_protocoltype : tobjectdef;
  1225. { helper types for for-in "fast enumeration" support in Objective-C 2.0 }
  1226. objc_fastenumeration : tobjectdef;
  1227. objc_fastenumerationstate : trecorddef;
  1228. {$ifdef llvm}
  1229. { llvm types }
  1230. { a unique def to identify any kind of metadata }
  1231. llvm_metadatatype : tdef;
  1232. {$endif llvm}
  1233. { Java base types }
  1234. { java.lang.Object }
  1235. java_jlobject : tobjectdef;
  1236. { java.lang.Throwable }
  1237. java_jlthrowable : tobjectdef;
  1238. { FPC base type for records }
  1239. java_fpcbaserecordtype : tobjectdef;
  1240. { java.lang.String }
  1241. java_jlstring : tobjectdef;
  1242. { java.lang.Enum }
  1243. java_jlenum : tobjectdef;
  1244. { java.util.EnumSet }
  1245. java_juenumset : tobjectdef;
  1246. { java.util.BitSet }
  1247. java_jubitset : tobjectdef;
  1248. { FPC java implementation of ansistrings }
  1249. java_ansistring : tobjectdef;
  1250. { FPC java implementation of shortstrings }
  1251. java_shortstring : tobjectdef;
  1252. { FPC java procvar base class }
  1253. java_procvarbase : tobjectdef;
  1254. { x86 vector types }
  1255. x86_m64type,
  1256. x86_m128type,
  1257. x86_m128dtype,
  1258. x86_m128itype,
  1259. x86_m256type,
  1260. x86_m256dtype,
  1261. x86_m256itype : tdef;
  1262. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1263. function make_dllmangledname(const dllname,importname:TSymStr;
  1264. import_nr : word; pco : tproccalloption):TSymStr;
  1265. { should be in the types unit, but the types unit uses the node stuff :( }
  1266. function is_interfacecom(def: tdef): boolean;
  1267. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  1268. function is_any_interface_kind(def: tdef): boolean;
  1269. function is_interfacecorba(def: tdef): boolean;
  1270. function is_interface(def: tdef): boolean;
  1271. function is_dispinterface(def: tdef): boolean;
  1272. function is_object(def: tdef): boolean;
  1273. function is_class(def: tdef): boolean;
  1274. function is_cppclass(def: tdef): boolean;
  1275. function is_objectpascal_helper(def: tdef): boolean;
  1276. function is_objcclass(def: tdef): boolean;
  1277. function is_objcclassref(def: tdef): boolean;
  1278. function is_objcprotocol(def: tdef): boolean;
  1279. function is_objccategory(def: tdef): boolean;
  1280. function is_objc_class_or_protocol(def: tdef): boolean;
  1281. function is_objc_protocol_or_category(def: tdef): boolean;
  1282. function is_classhelper(def: tdef): boolean;
  1283. function is_class_or_interface(def: tdef): boolean;
  1284. function is_class_or_interface_or_objc(def: tdef): boolean;
  1285. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  1286. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  1287. function is_class_or_interface_or_object(def: tdef): boolean;
  1288. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  1289. function is_implicit_pointer_object_type(def: tdef): boolean;
  1290. { returns true, if def is a type which is an implicit pointer to an array (dyn. array or dyn. string) }
  1291. function is_implicit_array_pointer(def: tdef): boolean;
  1292. function is_class_or_object(def: tdef): boolean;
  1293. function is_record(def: tdef): boolean;
  1294. function is_javaclass(def: tdef): boolean;
  1295. function is_javaclassref(def: tdef): boolean;
  1296. function is_javainterface(def: tdef): boolean;
  1297. function is_java_class_or_interface(def: tdef): boolean;
  1298. procedure loadobjctypes;
  1299. procedure maybeloadcocoatypes;
  1300. function use_vectorfpu(def : tdef) : boolean;
  1301. function getansistringcodepage:tstringencoding; inline;
  1302. function getansistringdef:tstringdef;
  1303. function getparaencoding(def:tdef):tstringencoding; inline;
  1304. function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
  1305. function get_recorddef(prefix:tinternaltypeprefix;const fields:array of tdef; packrecords:shortint): trecorddef;
  1306. { get a table def of the form
  1307. record
  1308. count: countdef;
  1309. elements: array[0..count-1] of elementdef
  1310. end;
  1311. Returns both the outer record and the inner arraydef
  1312. }
  1313. procedure get_tabledef(prefix:tinternaltypeprefix;countdef,elementdef:tdef;count:longint;packrecords:shortint;out recdef:trecorddef;out arrdef:tarraydef);
  1314. function fileinfo_of_typesym_in_def(def:tdef;sym:tsym;out filepos:tfileposinfo):boolean;
  1315. procedure reset_all_default_types; {housekeeping for Textmode IDE sanity}
  1316. implementation
  1317. uses
  1318. SysUtils,
  1319. cutils,
  1320. { global }
  1321. verbose,
  1322. { target }
  1323. systems,paramgr,
  1324. { symtable }
  1325. symsym,symtable,defutil,objcdef,
  1326. { parser }
  1327. pgenutil,
  1328. { module }
  1329. fmodule,ppu,
  1330. { other }
  1331. aasmbase,
  1332. gendef,
  1333. fpchash,
  1334. entfile
  1335. ;
  1336. {****************************************************************************
  1337. Helpers
  1338. ****************************************************************************}
  1339. function fileinfo_of_typesym_in_def(def:tdef;sym:tsym;out filepos:tfileposinfo):boolean;
  1340. var
  1341. gst : tgetsymtable;
  1342. st : tsymtable;
  1343. i : longint;
  1344. srsym : tsym;
  1345. begin
  1346. result:=false;
  1347. if sym.typ<>typesym then
  1348. exit;
  1349. for gst:=low(tgetsymtable) to high(tgetsymtable) do
  1350. begin
  1351. st:=def.getsymtable(gst);
  1352. if not assigned(st) then
  1353. continue;
  1354. for i:=0 to st.symlist.count-1 do
  1355. begin
  1356. srsym:=tsym(st.symlist[i]);
  1357. case srsym.typ of
  1358. fieldvarsym,
  1359. paravarsym:
  1360. if tabstractvarsym(srsym).vardef.typesym=sym then
  1361. begin
  1362. filepos:=srsym.fileinfo;
  1363. result:=true;
  1364. break;
  1365. end;
  1366. typesym:
  1367. begin
  1368. result:=fileinfo_of_typesym_in_def(ttypesym(srsym).typedef,sym,filepos);
  1369. if result then
  1370. break;
  1371. end
  1372. else
  1373. ;
  1374. end;
  1375. end;
  1376. if result then
  1377. break;
  1378. end;
  1379. { for this we would need the position of the result declaration :/ }
  1380. {if not result and
  1381. (def.typ in [procdef,procvardef]) and
  1382. assigned(tabstractprocdef(def).returndef) and
  1383. (tabstractprocdef(def).returndef.typesym=sym) then
  1384. begin
  1385. result:=true;
  1386. end;}
  1387. end;
  1388. function getansistringcodepage:tstringencoding; inline;
  1389. begin
  1390. if ([cs_explicit_codepage,cs_system_codepage]*current_settings.moduleswitches)<>[] then
  1391. result:=current_settings.sourcecodepage
  1392. else
  1393. result:=0;
  1394. end;
  1395. function getansistringdef:tstringdef;
  1396. var
  1397. symtable:tsymtable;
  1398. oldstack : tsymtablestack;
  1399. begin
  1400. { if a codepage is explicitly defined in this mudule we need to return
  1401. a replacement for ansistring def }
  1402. if ([cs_explicit_codepage,cs_system_codepage]*current_settings.moduleswitches)<>[] then
  1403. begin
  1404. if not assigned(current_module) then
  1405. internalerror(2011101301);
  1406. { codepage can be redeclared only once per unit so we don't need a list of
  1407. redefined ansistring but only one pointer }
  1408. if not assigned(current_module.ansistrdef) then
  1409. begin
  1410. { if we did not create it yet we need to do this now }
  1411. if current_module.in_interface then
  1412. symtable:=current_module.globalsymtable
  1413. else
  1414. symtable:=current_module.localsymtable;
  1415. { create a temporary stack as it's not good (TM) to mess around
  1416. with the order if the unit contains generics or helpers; don't
  1417. use a def aware symtablestack though }
  1418. oldstack:=symtablestack;
  1419. symtablestack:=tsymtablestack.create;
  1420. symtablestack.push(symtable);
  1421. current_module.ansistrdef:=cstringdef.createansi(current_settings.sourcecodepage,true);
  1422. symtablestack.pop(symtable);
  1423. symtablestack.free;
  1424. symtablestack:=oldstack;
  1425. end;
  1426. result:=tstringdef(current_module.ansistrdef);
  1427. end
  1428. else
  1429. result:=tstringdef(cansistringtype);
  1430. end;
  1431. function getparaencoding(def:tdef):tstringencoding; inline;
  1432. begin
  1433. { don't pass CP_NONE encoding to internal functions
  1434. they expect 0 encoding instead
  1435. exception: result of string concatenation, because if you pass the
  1436. result of a string concatenation to a rawbytestring, the result of
  1437. that concatenation shouldn't be converted to defaultsystemcodepage
  1438. if all strings have the same type }
  1439. result:=tstringdef(def).encoding;
  1440. if result=globals.CP_NONE then
  1441. result:=0
  1442. end;
  1443. function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
  1444. var
  1445. typ: ttypesym;
  1446. name: string;
  1447. begin
  1448. name:=internaltypeprefixName[itp_threadvar_record]+def.unique_id_str;
  1449. typ:=try_search_current_module_type(name);
  1450. if assigned(typ) then
  1451. begin
  1452. result:=trecorddef(ttypesym(typ).typedef);
  1453. index_field:=tsym(result.symtable.symlist[0]);
  1454. non_mt_data_field:=tsym(result.symtable.symlist[1]);
  1455. exit;
  1456. end;
  1457. { set recordalinmin to sizeof(pint), so the second field gets put at
  1458. offset = sizeof(pint) as expected }
  1459. result:=crecorddef.create_global_internal(
  1460. name,sizeof(pint),sizeof(pint));
  1461. {$ifdef cpu16bitaddr}
  1462. index_field:=result.add_field_by_def('',u16inttype);
  1463. {$else cpu16bitaddr}
  1464. index_field:=result.add_field_by_def('',u32inttype);
  1465. {$endif cpu16bitaddr}
  1466. non_mt_data_field:=result.add_field_by_def('',def);
  1467. { no need to add alignment padding, we won't create arrays of these }
  1468. end;
  1469. function get_recorddef(prefix:tinternaltypeprefix; const fields:array of tdef; packrecords:shortint): trecorddef;
  1470. var
  1471. fieldlist: tfplist;
  1472. srsym: tsym;
  1473. srsymtable: tsymtable;
  1474. i: longint;
  1475. name : TIDString;
  1476. begin
  1477. name:=copy(internaltypeprefixName[prefix],2,length(internaltypeprefixName[prefix]));
  1478. if searchsym_type(name,srsym,srsymtable) then
  1479. begin
  1480. result:=trecorddef(ttypesym(srsym).typedef);
  1481. exit
  1482. end;
  1483. { also always search in the current module (symtables are popped for
  1484. RTTI related code already) }
  1485. if searchsym_in_module(pointer(current_module),name,srsym,srsymtable) then
  1486. begin
  1487. result:=trecorddef(ttypesym(srsym).typedef);
  1488. exit;
  1489. end;
  1490. fieldlist:=tfplist.create;
  1491. for i:=low(fields) to high(fields) do
  1492. fieldlist.add(fields[i]);
  1493. result:=crecorddef.create_global_internal(internaltypeprefixName[prefix],packrecords,
  1494. targetinfos[target_info.system]^.alignment.recordalignmin);
  1495. result.add_fields_from_deflist(fieldlist);
  1496. fieldlist.free;
  1497. end;
  1498. procedure get_tabledef(prefix:tinternaltypeprefix;countdef,elementdef:tdef;count:longint;packrecords:shortint;out recdef:trecorddef;out arrdef:tarraydef);
  1499. var
  1500. fields: tfplist;
  1501. name: TIDString;
  1502. srsym: tsym;
  1503. fieldvarsym: tfieldvarsym;
  1504. srsymtable: tsymtable;
  1505. begin
  1506. { already created a message string table with this number of elements
  1507. in this unit -> reuse the def }
  1508. name:=internaltypeprefixName[prefix]+tostr(count);
  1509. if searchsym_type(copy(name,2,length(name)),srsym,srsymtable) then
  1510. begin
  1511. recdef:=trecorddef(ttypesym(srsym).typedef);
  1512. fieldvarsym:=trecordsymtable(recdef.symtable).findfieldbyoffset(countdef.size);
  1513. if fieldvarsym<>nil then
  1514. arrdef:=tarraydef(fieldvarsym.vardef)
  1515. else
  1516. arrdef:=nil;
  1517. exit
  1518. end;
  1519. { also always search in the current module (symtables are popped for
  1520. RTTI related code already) }
  1521. if searchsym_in_module(pointer(current_module),copy(name,2,length(name)),srsym,srsymtable) then
  1522. begin
  1523. recdef:=trecorddef(ttypesym(srsym).typedef);
  1524. fieldvarsym:=trecordsymtable(recdef.symtable).findfieldbyoffset(countdef.size);
  1525. if fieldvarsym<>nil then
  1526. arrdef:=tarraydef(fieldvarsym.vardef)
  1527. else
  1528. arrdef:=nil;
  1529. exit;
  1530. end;
  1531. recdef:=crecorddef.create_global_internal(name,packrecords,
  1532. targetinfos[target_info.system]^.alignment.recordalignmin);
  1533. fields:=tfplist.create;
  1534. fields.add(countdef);
  1535. if count>0 then
  1536. begin
  1537. arrdef:=carraydef.create(0,count-1,sizeuinttype);
  1538. arrdef.elementdef:=elementdef;
  1539. fields.add(arrdef);
  1540. end
  1541. else
  1542. arrdef:=nil;
  1543. recdef.add_fields_from_deflist(fields);
  1544. fields.free;
  1545. end;
  1546. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1547. var
  1548. s,t,
  1549. prefix : TSymStr;
  1550. hash : qword;
  1551. begin
  1552. prefix:='';
  1553. if not assigned(st) then
  1554. internalerror(200204212);
  1555. repeat
  1556. { sub procedures }
  1557. while (st.symtabletype in [localsymtable,parasymtable]) do
  1558. begin
  1559. if st.defowner.typ<>procdef then
  1560. internalerror(200204173);
  1561. { Add the full mangledname of the routine to prevent
  1562. conflicts with two overloads both having a local entity
  1563. -- routine (tb0314), class, interface -- with the same name }
  1564. s:=tprocdef(st.defowner).procsym.name;
  1565. s:=s+tprocdef(st.defowner).mangledprocparanames(Length(s));
  1566. if prefix<>'' then
  1567. begin
  1568. if length(prefix)>(maxidlen-length(s)-1) then
  1569. begin
  1570. hash:=InitFnv64;
  1571. hash:=UpdateFnv64(hash,prefix[1],length(prefix));
  1572. prefix:='$H'+Base64Mangle(hash);
  1573. end;
  1574. prefix:=s+'_'+prefix
  1575. end
  1576. else
  1577. prefix:=s;
  1578. st:=st.defowner.owner;
  1579. end;
  1580. { object/classes symtable, nested type definitions in classes require the while loop }
  1581. while st.symtabletype in [ObjectSymtable,recordsymtable] do
  1582. begin
  1583. if not (st.defowner.typ in [objectdef,recorddef]) then
  1584. internalerror(200204174);
  1585. if length(prefix)>(maxidlen-length(tabstractrecorddef(st.defowner).objname^)-3) then
  1586. begin
  1587. hash:=InitFnv64;
  1588. hash:=UpdateFnv64(hash,prefix[1],length(prefix));
  1589. prefix:='$H'+Base64Mangle(hash);
  1590. end;
  1591. prefix:=tabstractrecorddef(st.defowner).objname^+'_$_'+prefix;
  1592. st:=st.defowner.owner;
  1593. end;
  1594. { local classes & interfaces are possible (because of closures)
  1595. or parasymtable for this case:
  1596. class function Trace<TResult>(const Func: TFunc<TLogToken, TResult>): TResult;
  1597. }
  1598. if not (st.symtabletype in [localsymtable,parasymtable]) then
  1599. break;
  1600. prefix:='$'+prefix;
  1601. until false;
  1602. { symtable must now be static or global }
  1603. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  1604. internalerror(200204175);
  1605. { The mangled name is made out of at most 4 parts:
  1606. 1) Optional typeprefix given as first parameter
  1607. with '_$' appended if not empty
  1608. 2) Unit name or 'P$'+program name (never empty)
  1609. 3) optional prefix variable that contains a unique
  1610. name for the local symbol table (prepended with '$_$'
  1611. if not empty)
  1612. 4) suffix as given as third parameter,
  1613. also optional (i.e. can be empty)
  1614. prepended by '_$$_' if not empty }
  1615. result:='';
  1616. if typeprefix<>'' then
  1617. result:=result+typeprefix+'_$';
  1618. { Add P$ for program, which can have the same name as
  1619. a unit }
  1620. if (TSymtable(main_module.localsymtable)=st) and
  1621. (not main_module.is_unit) then
  1622. result:=result+'P$'+st.name^
  1623. else
  1624. result:=result+st.name^;
  1625. if prefix<>'' then
  1626. result:=result+'$_$'+prefix;
  1627. if suffix<>'' then
  1628. result:=result+'_$$_'+suffix;
  1629. if length(result)>(maxidlen-1) then
  1630. begin
  1631. hash:=InitFnv64;
  1632. hash:=UpdateFnv64(hash,result[1],length(result));
  1633. result:=copy(result,1,maxidlen-(high(Base64OfUint64String)-low(Base64OfUint64String)+1)-2)+'$H'+Base64Mangle(hash);
  1634. end;
  1635. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  1636. { Further, the Mac OS X 10.5 linker does not consider symbols which do not }
  1637. { start with '_' as regular symbols (it does not generate N_GSYM entries }
  1638. { those in the debug map, leading to troubles with dsymutil). So always }
  1639. { add an underscore on darwin. }
  1640. if (target_info.system in systems_darwin) then
  1641. result := '_' + result;
  1642. end;
  1643. function make_dllmangledname(const dllname,importname:TSymStr;import_nr : word; pco : tproccalloption):TSymStr;
  1644. var
  1645. crc : cardinal;
  1646. i : longint;
  1647. use_crc : boolean;
  1648. dllprefix : TSymStr;
  1649. begin
  1650. if (target_info.system in (systems_all_windows + systems_nativent +
  1651. [system_i386_emx, system_i386_os2]))
  1652. and (dllname <> '') then
  1653. begin
  1654. dllprefix:=lower(ExtractFileName(dllname));
  1655. { Remove .dll suffix if present }
  1656. if copy(dllprefix,length(dllprefix)-3,length(dllprefix))='.dll' then
  1657. dllprefix:=copy(dllprefix,1,length(dllprefix)-4);
  1658. use_crc:=false;
  1659. for i:=1 to length(dllprefix) do
  1660. if not (dllprefix[i] in ['a'..'z','A'..'Z','_','0'..'9']) then
  1661. begin
  1662. use_crc:=true;
  1663. break;
  1664. end;
  1665. if use_crc then
  1666. begin
  1667. crc:=0;
  1668. crc:=UpdateCrc32(crc,dllprefix[1],length(dllprefix));
  1669. dllprefix:='_$dll$crc$'+hexstr(crc,8)+'$';
  1670. end
  1671. else
  1672. dllprefix:='_$dll$'+dllprefix+'$';
  1673. if importname<>'' then
  1674. result:=dllprefix+importname
  1675. else
  1676. result:=dllprefix+'_index_'+tostr(import_nr);
  1677. { Replace ? and @ in import name, since GNU AS does not allow these characters in symbol names. }
  1678. { This allows to import VC++ mangled names from DLLs. }
  1679. { Do not perform replacement, if external symbol is not imported from DLL. }
  1680. if (dllname<>'') then
  1681. begin
  1682. Replace(result,'?','__q$$');
  1683. {$ifdef arm}
  1684. { @ symbol is not allowed in ARM assembler only }
  1685. Replace(result,'@','__a$$');
  1686. {$endif arm}
  1687. end;
  1688. end
  1689. else
  1690. begin
  1691. if importname<>'' then
  1692. begin
  1693. if not(pco in [pocall_cdecl,pocall_cppdecl]) then
  1694. result:=importname
  1695. else
  1696. result:=target_info.Cprefix+importname;
  1697. end
  1698. else
  1699. result:='_index_'+tostr(import_nr);
  1700. end;
  1701. end;
  1702. {****************************************************************************
  1703. TDEFAWARESYMTABLESTACK
  1704. (symtablestack descendant that does some special actions on
  1705. the pushed/popped symtables)
  1706. ****************************************************************************}
  1707. procedure tdefawaresymtablestack.add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  1708. var
  1709. s: TSymStr;
  1710. list: TFPObjectList;
  1711. def: tdef;
  1712. sym : tsym;
  1713. i: integer;
  1714. begin
  1715. { search the symtable from first to last; the helper to use will be the
  1716. last one in the list }
  1717. for i:=0 to st.symlist.count-1 do
  1718. begin
  1719. sym:=tsym(st.symlist[i]);
  1720. if not (sym.typ in [typesym,procsym]) then
  1721. continue;
  1722. if sym.typ=typesym then
  1723. def:=ttypesym(st.SymList[i]).typedef
  1724. else
  1725. def:=nil;
  1726. if is_objectpascal_helper(def) then
  1727. begin
  1728. s:=generate_objectpascal_helper_key(tobjectdef(def).extendeddef);
  1729. Message1(sym_d_adding_helper_for,s);
  1730. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  1731. if not assigned(list) then
  1732. begin
  1733. list:=TFPObjectList.Create(false);
  1734. current_module.extendeddefs.Add(s,list);
  1735. end;
  1736. list.Add(def);
  1737. end
  1738. else
  1739. begin
  1740. if addgenerics then
  1741. add_generic_dummysym(sym);
  1742. { add nested helpers as well }
  1743. if assigned(def) and
  1744. (def.typ in [recorddef,objectdef]) and
  1745. (sto_has_helper in tabstractrecorddef(def).symtable.tableoptions) and
  1746. not is_owned_by(def,tdef(st.defowner)) then
  1747. add_helpers_and_generics(tabstractrecorddef(def).symtable,false);
  1748. end;
  1749. end;
  1750. end;
  1751. procedure tdefawaresymtablestack.remove_helpers_and_generics(st:tsymtable);
  1752. begin
  1753. if sto_has_helper in st.tableoptions then
  1754. remove_helpers(st);
  1755. if sto_has_generic in st.tableoptions then
  1756. remove_generics(st);
  1757. end;
  1758. procedure tdefawaresymtablestack.remove_helpers(st:TSymtable);
  1759. var
  1760. i, j: integer;
  1761. tmpst: TSymtable;
  1762. list: TFPObjectList;
  1763. begin
  1764. for i:=current_module.extendeddefs.count-1 downto 0 do
  1765. begin
  1766. list:=TFPObjectList(current_module.extendeddefs[i]);
  1767. for j:=list.count-1 downto 0 do
  1768. begin
  1769. if not (list[j] is tobjectdef) then
  1770. Internalerror(2011031501);
  1771. tmpst:=tobjectdef(list[j]).owner;
  1772. repeat
  1773. if tmpst=st then
  1774. begin
  1775. list.delete(j);
  1776. break;
  1777. end
  1778. else
  1779. begin
  1780. if assigned(tmpst.defowner) then
  1781. tmpst:=tmpst.defowner.owner
  1782. else
  1783. tmpst:=nil;
  1784. end;
  1785. until not assigned(tmpst) or (tmpst.symtabletype in [globalsymtable,staticsymtable]);
  1786. end;
  1787. if list.count=0 then
  1788. current_module.extendeddefs.delete(i);
  1789. end;
  1790. end;
  1791. procedure tdefawaresymtablestack.remove_generics(st:tsymtable);
  1792. var
  1793. i,j : longint;
  1794. entry : tgenericdummyentry;
  1795. list : tfpobjectlist;
  1796. begin
  1797. for i:=current_module.genericdummysyms.count-1 downto 0 do
  1798. begin
  1799. list:=tfpobjectlist(current_module.genericdummysyms[i]);
  1800. if not assigned(list) then
  1801. continue;
  1802. for j:=list.count-1 downto 0 do
  1803. begin
  1804. entry:=tgenericdummyentry(list[j]);
  1805. if entry.dummysym.owner=st then
  1806. list.delete(j);
  1807. end;
  1808. if list.count=0 then
  1809. current_module.genericdummysyms.delete(i);
  1810. end;
  1811. end;
  1812. procedure tdefawaresymtablestack.pushcommon(st:tsymtable);
  1813. begin
  1814. if (sto_has_generic in st.tableoptions) or
  1815. (
  1816. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1817. (sto_has_helper in st.tableoptions)
  1818. ) then
  1819. { nested helpers will be added as well }
  1820. add_helpers_and_generics(st,true);
  1821. end;
  1822. procedure tdefawaresymtablestack.push(st: TSymtable);
  1823. begin
  1824. pushcommon(st);
  1825. inherited push(st);
  1826. end;
  1827. procedure tdefawaresymtablestack.pushafter(st,afterst:TSymtable);
  1828. begin
  1829. pushcommon(st);
  1830. inherited pushafter(st,afterst);
  1831. end;
  1832. procedure tdefawaresymtablestack.pop(st: TSymtable);
  1833. begin
  1834. inherited pop(st);
  1835. if (sto_has_generic in st.tableoptions) or
  1836. (
  1837. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1838. (sto_has_helper in st.tableoptions)
  1839. ) then
  1840. { nested helpers will be removed as well }
  1841. remove_helpers_and_generics(st);
  1842. end;
  1843. {****************************************************************************
  1844. TDEF (base class for definitions)
  1845. ****************************************************************************}
  1846. constructor tgenericconstraintdata.create;
  1847. begin
  1848. interfaces:=tfpobjectlist.create(false);
  1849. interfacesderef:=tfplist.create;
  1850. end;
  1851. destructor tgenericconstraintdata.destroy;
  1852. begin
  1853. TFPList.FreeAndNilDisposing(interfacesderef,typeinfo(tderef));
  1854. interfaces.free;
  1855. inherited destroy;
  1856. end;
  1857. procedure tgenericconstraintdata.ppuload(ppufile: tcompilerppufile);
  1858. var
  1859. cnt,i : longint;
  1860. intfderef : pderef;
  1861. begin
  1862. ppufile.getset(tppuset1(flags));
  1863. cnt:=ppufile.getlongint;
  1864. for i:=0 to cnt-1 do
  1865. begin
  1866. new(intfderef);
  1867. ppufile.getderef(intfderef^);
  1868. interfacesderef.add(intfderef);
  1869. end;
  1870. end;
  1871. procedure tgenericconstraintdata.ppuwrite(ppufile: tcompilerppufile);
  1872. var
  1873. i : longint;
  1874. begin
  1875. ppufile.putset(tppuset1(flags));
  1876. ppufile.putlongint(interfacesderef.count);
  1877. for i:=0 to interfacesderef.count-1 do
  1878. ppufile.putderef(pderef(interfacesderef[i])^);
  1879. end;
  1880. procedure tgenericconstraintdata.buildderef;
  1881. var
  1882. intfderef : pderef;
  1883. i : longint;
  1884. begin
  1885. interfacesderef.capacity:=interfacesderef.count+interfaces.count;
  1886. for i:=0 to interfaces.count-1 do
  1887. begin
  1888. new(intfderef);
  1889. intfderef^.build(tobjectdef(interfaces[i]));
  1890. interfacesderef.add(intfderef);
  1891. end;
  1892. end;
  1893. procedure tgenericconstraintdata.deref;
  1894. var
  1895. i : longint;
  1896. begin
  1897. interfaces.capacity:=interfaces.count+interfacesderef.count;
  1898. for i:=0 to interfacesderef.count-1 do
  1899. interfaces.add(pderef(interfacesderef[i])^.resolve);
  1900. end;
  1901. procedure tstoreddef.writeentry(ppufile: tcompilerppufile; ibnr: byte);
  1902. begin
  1903. ppuwrite_platform(ppufile);
  1904. ppufile.writeentry(ibnr);
  1905. end;
  1906. procedure tstoreddef.ppuwrite_platform(ppufile: tcompilerppufile);
  1907. begin
  1908. { by default: do nothing }
  1909. end;
  1910. procedure tstoreddef.ppuload_platform(ppufile: tcompilerppufile);
  1911. begin
  1912. { by default: do nothing }
  1913. end;
  1914. class procedure tstoreddef.setup_reusable_def(origdef, newdef: tdef; res: PHashSetItem; oldsymtablestack: tsymtablestack);
  1915. var
  1916. reusablesymtab: tsymtable;
  1917. begin
  1918. { must not yet belong to a symtable }
  1919. if assigned(newdef.owner) then
  1920. internalerror(2015111503);
  1921. reusablesymtab:=origdef.getreusablesymtab;
  1922. res^.Data:=newdef;
  1923. reusablesymtab.insertdef(newdef);
  1924. symtablestack:=oldsymtablestack;
  1925. end;
  1926. constructor tstoreddef.create(dt:tdeftyp;doregister:boolean);
  1927. begin
  1928. inherited create(dt);
  1929. savesize := 0;
  1930. {$ifdef EXTDEBUG}
  1931. fileinfo := current_filepos;
  1932. {$endif}
  1933. generictokenbuf:=nil;
  1934. genericdef:=nil;
  1935. typesymderef.reset;
  1936. genericdefderef.reset;
  1937. { Don't register forwarddefs, they are disposed at the
  1938. end of an type block }
  1939. if (dt=forwarddef) then
  1940. exit;
  1941. { Register in symtable stack }
  1942. if doregister then
  1943. begin
  1944. { immediately register interface defs, as they will always be
  1945. written to the ppu, their defid influences the interface crc and
  1946. if we wait, depending on e.g. compiler defines they may get a
  1947. different defid (e.g. when a function is called, its procdef is
  1948. registered, so depending on whether or not, or when, an interface
  1949. procedure is called in the implementation, that may change its
  1950. defid otherwise) }
  1951. if assigned(current_module) and
  1952. current_module.in_interface then
  1953. register_def
  1954. else
  1955. maybe_put_in_symtable_stack;
  1956. end;
  1957. end;
  1958. destructor tstoreddef.destroy;
  1959. begin
  1960. { Direct calls are not allowed, use symtable.deletedef() }
  1961. if assigned(owner) then
  1962. internalerror(200612311);
  1963. if assigned(generictokenbuf) then
  1964. begin
  1965. generictokenbuf.free;
  1966. generictokenbuf:=nil;
  1967. end;
  1968. rtti_attribute_list.free;
  1969. genericparas.free;
  1970. TFPList.FreeAndNilDisposing(genericparaderefs,typeinfo(tderef));
  1971. genconstraintdata.free;
  1972. {$ifndef symansistr}
  1973. stringdispose(_fullownerhierarchyname);
  1974. {$endif not symansistr}
  1975. inherited destroy;
  1976. end;
  1977. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1978. var
  1979. sizeleft,i,cnt : longint;
  1980. buf : array[0..255] of byte;
  1981. symderef : pderef;
  1982. begin
  1983. inherited create(dt);
  1984. DefId:=ppufile.getlongint;
  1985. current_module.deflist[DefId]:=self;
  1986. {$ifdef EXTDEBUG}
  1987. fillchar(fileinfo,sizeof(fileinfo),0);
  1988. {$endif}
  1989. { load }
  1990. ppufile.getderef(typesymderef);
  1991. ppufile.getset(tppuset2(defoptions));
  1992. ppufile.getset(tppuset1(defstates));
  1993. if df_unique in defoptions then
  1994. ppufile.getderef(orgdefderef);
  1995. if df_genconstraint in defoptions then
  1996. begin
  1997. genconstraintdata:=tgenericconstraintdata.create;
  1998. genconstraintdata.ppuload(ppufile);
  1999. end;
  2000. if [df_generic,df_specialization]*defoptions<>[] then
  2001. begin
  2002. cnt:=ppufile.getlongint;
  2003. if cnt>0 then
  2004. begin
  2005. genericparas:=tfphashobjectlist.create(false);
  2006. genericparaderefs:=tfplist.create;
  2007. for i:=0 to cnt-1 do
  2008. begin
  2009. genericparas.add(ppufile.getstring,nil);
  2010. New(symderef);
  2011. ppufile.getderef(symderef^);
  2012. genericparaderefs.add(symderef);
  2013. end;
  2014. end;
  2015. end;
  2016. if df_generic in defoptions then
  2017. begin
  2018. sizeleft:=ppufile.getlongint;
  2019. initgeneric;
  2020. while sizeleft>0 do
  2021. begin
  2022. if sizeleft>sizeof(buf) then
  2023. i:=sizeof(buf)
  2024. else
  2025. i:=sizeleft;
  2026. ppufile.getdata(buf,i);
  2027. generictokenbuf.write(buf,i);
  2028. dec(sizeleft,i);
  2029. end;
  2030. end;
  2031. if df_specialization in defoptions then
  2032. ppufile.getderef(genericdefderef);
  2033. rtti_attribute_list:=trtti_attribute_list.ppuload(ppufile);
  2034. end;
  2035. function tstoreddef.needs_separate_initrtti:boolean;
  2036. begin
  2037. result:=false;
  2038. end;
  2039. function tstoreddef.rtti_mangledname(rt : trttitype) : TSymStr;
  2040. var
  2041. prefix : string[4];
  2042. begin
  2043. if (rt=fullrtti) or (not needs_separate_initrtti) then
  2044. begin
  2045. prefix:='RTTI';
  2046. include(defstates,ds_rtti_table_used);
  2047. end
  2048. else
  2049. begin
  2050. prefix:='INIT';
  2051. include(defstates,ds_init_table_used);
  2052. end;
  2053. if assigned(typesym) and
  2054. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  2055. result:=make_mangledname(prefix,typesym.owner,typesym.name)
  2056. else
  2057. result:=make_mangledname(prefix,findunitsymtable(owner),'def'+unique_id_str)
  2058. end;
  2059. function tstoreddef.OwnerHierarchyName: string;
  2060. var
  2061. tmp: tdef;
  2062. begin
  2063. tmp:=self;
  2064. result:='';
  2065. repeat
  2066. { can be not assigned in case of a forwarddef }
  2067. if assigned(tmp.owner) and
  2068. (tmp.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2069. tmp:=tdef(tmp.owner.defowner)
  2070. else
  2071. break;
  2072. result:=tabstractrecorddef(tmp).objrealname^+'.'+result;
  2073. until tmp=nil;
  2074. end;
  2075. function tstoreddef.OwnerHierarchyPrettyName: string;
  2076. var
  2077. tmp: tdef;
  2078. begin
  2079. tmp:=self;
  2080. result:='';
  2081. repeat
  2082. { can be not assigned in case of a forwarddef }
  2083. if assigned(tmp.owner) and
  2084. (tmp.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2085. tmp:=tdef(tmp.owner.defowner)
  2086. else
  2087. break;
  2088. result:=tabstractrecorddef(tmp).typesymbolprettyname+'.'+result;
  2089. until tmp=nil;
  2090. end;
  2091. function tstoreddef.fullownerhierarchyname(skipprocparams:boolean): TSymStr;
  2092. var
  2093. lastowner: tsymtable;
  2094. tmp: tdef;
  2095. pno: tprocnameoptions;
  2096. begin
  2097. {$ifdef symansistr}
  2098. if not skipprocparams and (_fullownerhierarchyname<>'') then
  2099. exit(_fullownerhierarchyname);
  2100. {$else symansistr}
  2101. if not skipprocparams and assigned(_fullownerhierarchyname) then
  2102. exit(_fullownerhierarchyname^);
  2103. {$endif symansistr}
  2104. { the def can only reside inside structured types or
  2105. procedures/functions/methods }
  2106. tmp:=self;
  2107. result:='';
  2108. repeat
  2109. lastowner:=tmp.owner;
  2110. { can be not assigned in case of a forwarddef }
  2111. if not assigned(lastowner) then
  2112. break
  2113. else
  2114. tmp:=tdef(lastowner.defowner);
  2115. if not assigned(tmp) then
  2116. break;
  2117. if tmp.typ in [recorddef,objectdef] then
  2118. result:=tabstractrecorddef(tmp).objrealname^+'.'+result
  2119. else
  2120. if tmp.typ=procdef then
  2121. begin
  2122. pno:=[pno_paranames,pno_proctypeoption];
  2123. if skipprocparams then
  2124. include(pno,pno_noparams);
  2125. result:=tprocdef(tmp).customprocname(pno)+'.'+result;
  2126. end;
  2127. until tmp=nil;
  2128. { add the unit name }
  2129. if assigned(lastowner) and
  2130. assigned(lastowner.realname) then
  2131. result:=lastowner.realname^+'.'+result;
  2132. if not skipprocparams then
  2133. { don't store the name in this case }
  2134. {$ifdef symansistr}
  2135. _fullownerhierarchyname:=result;
  2136. {$else symansistr}
  2137. _fullownerhierarchyname:=stringdup(result);
  2138. {$endif symansistr}
  2139. end;
  2140. function tstoreddef.in_currentunit: boolean;
  2141. var
  2142. st: tsymtable;
  2143. begin
  2144. st:=owner;
  2145. while not(st.symtabletype in [globalsymtable,staticsymtable]) do
  2146. st:=st.defowner.owner;
  2147. result:=st.iscurrentunit;
  2148. end;
  2149. function tstoreddef.getcopy : tstoreddef;
  2150. begin
  2151. Message(sym_e_cant_create_unique_type);
  2152. getcopy:=cerrordef.create;
  2153. end;
  2154. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  2155. var
  2156. sizeleft,i : longint;
  2157. buf : array[0..255] of byte;
  2158. oldintfcrc : boolean;
  2159. begin
  2160. if defid<0 then
  2161. internalerror(2015101401);
  2162. ppufile.putlongint(DefId);
  2163. ppufile.putderef(typesymderef);
  2164. ppufile.putset(tppuset2(defoptions));
  2165. oldintfcrc:=ppufile.do_crc;
  2166. ppufile.do_crc:=false;
  2167. ppufile.putset(tppuset1(defstates));
  2168. if df_unique in defoptions then
  2169. ppufile.putderef(orgdefderef);
  2170. if df_genconstraint in defoptions then
  2171. genconstraintdata.ppuwrite(ppufile);
  2172. if [df_generic,df_specialization]*defoptions<>[] then
  2173. begin
  2174. if not assigned(genericparas) then
  2175. ppufile.putlongint(0)
  2176. else
  2177. begin
  2178. if not assigned(genericparaderefs) then
  2179. internalerror(2014052305);
  2180. ppufile.putlongint(genericparas.count);
  2181. for i:=0 to genericparas.count-1 do
  2182. begin
  2183. ppufile.putstring(genericparas.nameofindex(i));
  2184. ppufile.putderef(pderef(genericparaderefs[i])^);
  2185. end;
  2186. end;
  2187. end;
  2188. if df_generic in defoptions then
  2189. begin
  2190. if assigned(generictokenbuf) then
  2191. begin
  2192. sizeleft:=generictokenbuf.size;
  2193. generictokenbuf.seek(0);
  2194. end
  2195. else
  2196. sizeleft:=0;
  2197. ppufile.putlongint(sizeleft);
  2198. while sizeleft>0 do
  2199. begin
  2200. if sizeleft>sizeof(buf) then
  2201. i:=sizeof(buf)
  2202. else
  2203. i:=sizeleft;
  2204. generictokenbuf.read(buf,i);
  2205. ppufile.putdata(buf,i);
  2206. dec(sizeleft,i);
  2207. end;
  2208. end;
  2209. ppufile.do_crc:=oldintfcrc;
  2210. if df_specialization in defoptions then
  2211. ppufile.putderef(genericdefderef);
  2212. trtti_attribute_list.ppuwrite(rtti_attribute_list,ppufile);
  2213. end;
  2214. procedure tstoreddef.ppuload_subentries(ppufile: tcompilerppufile);
  2215. begin
  2216. trtti_attribute_list.ppuload_subentries(rtti_attribute_list,ppufile);
  2217. end;
  2218. procedure tstoreddef.ppuwrite_subentries(ppufile: tcompilerppufile);
  2219. begin
  2220. trtti_attribute_list.ppuwrite_subentries(rtti_attribute_list,ppufile);
  2221. end;
  2222. procedure tstoreddef.buildderef;
  2223. var
  2224. i : longint;
  2225. sym : tsym;
  2226. symderef : pderef;
  2227. begin
  2228. if not registered then
  2229. register_def;
  2230. typesymderef.build(typesym);
  2231. orgdefderef.build(orgdef);
  2232. genericdefderef.build(genericdef);
  2233. if assigned(rtti_attribute_list) then
  2234. rtti_attribute_list.buildderef;
  2235. if assigned(genconstraintdata) then
  2236. genconstraintdata.buildderef;
  2237. if assigned(genericparas) then
  2238. begin
  2239. if not assigned(genericparaderefs) then
  2240. genericparaderefs:=tfplist.create;
  2241. genericparaderefs.capacity:=genericparaderefs.count+genericparas.count;
  2242. for i:=0 to genericparas.count-1 do
  2243. begin
  2244. sym:=tsym(genericparas.items[i]);
  2245. new(symderef);
  2246. symderef^.build(sym);
  2247. genericparaderefs.add(symderef);
  2248. end;
  2249. end;
  2250. end;
  2251. procedure tstoreddef.buildderefimpl;
  2252. begin
  2253. end;
  2254. procedure tstoreddef.deref;
  2255. var
  2256. symderef : pderef;
  2257. i : longint;
  2258. begin
  2259. typesym:=ttypesym(typesymderef.resolve);
  2260. if df_unique in defoptions then
  2261. orgdef:=tstoreddef(orgdefderef.resolve);
  2262. if df_specialization in defoptions then
  2263. genericdef:=tstoreddef(genericdefderef.resolve);
  2264. if assigned(rtti_attribute_list) then
  2265. rtti_attribute_list.deref;
  2266. if assigned(genconstraintdata) then
  2267. genconstraintdata.deref;
  2268. if assigned(genericparas) then
  2269. begin
  2270. if not assigned(genericparaderefs) then
  2271. internalerror(2014052302);
  2272. if genericparas.count<>genericparaderefs.count then
  2273. internalerror(2014052303);
  2274. for i:=0 to genericparaderefs.count-1 do
  2275. begin
  2276. symderef:=pderef(genericparaderefs[i]);
  2277. genericparas.items[i]:=symderef^.resolve;
  2278. end;
  2279. end;
  2280. end;
  2281. procedure tstoreddef.derefimpl;
  2282. begin
  2283. end;
  2284. function tstoreddef.size : asizeint;
  2285. begin
  2286. size:=savesize;
  2287. end;
  2288. function tstoreddef.getvardef:longint;
  2289. begin
  2290. result:=varUndefined;
  2291. end;
  2292. function tstoreddef.alignment : shortint;
  2293. begin
  2294. { natural alignment by default }
  2295. alignment:=size_2_align(savesize);
  2296. { can happen if savesize = 0, e.g. for voiddef or
  2297. an empty record
  2298. }
  2299. if (alignment=0) then
  2300. alignment:=1;
  2301. end;
  2302. { returns true, if the definition can be published }
  2303. function tstoreddef.is_publishable : tpublishproperty;
  2304. begin
  2305. is_publishable:=pp_error;
  2306. end;
  2307. { needs an init table }
  2308. function tstoreddef.needs_inittable : boolean;
  2309. begin
  2310. needs_inittable:=false;
  2311. end;
  2312. function tstoreddef.has_non_trivial_init_child(check_parent:boolean):boolean;
  2313. begin
  2314. result:=false;
  2315. end;
  2316. function tstoreddef.is_intregable : boolean;
  2317. {$ifndef cpuhighleveltarget}
  2318. var
  2319. recsize,temp: longint;
  2320. {$endif cpuhighleveltarget}
  2321. begin
  2322. case typ of
  2323. orddef,
  2324. pointerdef,
  2325. enumdef,
  2326. classrefdef:
  2327. is_intregable:=true;
  2328. procvardef :
  2329. is_intregable:=tprocvardef(self).is_addressonly or (po_methodpointer in tprocvardef(self).procoptions);
  2330. objectdef:
  2331. is_intregable:=(is_implicit_pointer_object_type(self)) and not needs_inittable;
  2332. setdef:
  2333. is_intregable:=is_smallset(self);
  2334. arraydef:
  2335. {$ifdef cpuhighleveltarget}
  2336. is_intregable:=false
  2337. {$else cpuhighleveltarget}
  2338. is_intregable:=not(is_special_array(self)) and
  2339. (tarraydef(self).size<=8) and (tarraydef(self).size in [1,2,4,8]) and
  2340. tstoreddef(tarraydef(self).elementdef).is_intregable
  2341. {$ifdef SUPPORT_MMX}
  2342. and not((cs_mmx in current_settings.localswitches) and
  2343. is_mmx_able_array(self))
  2344. {$endif SUPPORT_MMX}
  2345. {$endif cpuhighleveltarget}
  2346. ;
  2347. recorddef:
  2348. begin
  2349. {$ifdef cpuhighleveltarget}
  2350. is_intregable:=false;
  2351. {$else cpuhighleveltarget}
  2352. recsize:=size;
  2353. is_intregable:=
  2354. ispowerof2(recsize,temp) and
  2355. ((recsize<=sizeof(aint)*2) and
  2356. not trecorddef(self).contains_cross_aword_field and
  2357. { records cannot go into registers on 16 bit targets for now }
  2358. (sizeof(aint)>2) and
  2359. not trecorddef(self).contains_float_field
  2360. ) and
  2361. not needs_inittable;
  2362. {$endif cpuhighleveltarget}
  2363. end;
  2364. else
  2365. is_intregable:=false;
  2366. end;
  2367. end;
  2368. function tstoreddef.is_fpuregable : boolean;
  2369. begin
  2370. {$ifdef x86}
  2371. result:=use_vectorfpu(self);
  2372. {$else x86}
  2373. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches)
  2374. {$ifdef xtensa}
  2375. and (FPUXTENSA_SINGLE in fpu_capabilities[init_settings.fputype]) and (tfloatdef(self).floattype=s32real)
  2376. {$endif xtensa}
  2377. {$ifdef arm}
  2378. and (((FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]) and (tfloatdef(self).floattype=s32real)) or
  2379. (FPUARM_HAS_VFP_DOUBLE in fpu_capabilities[init_settings.fputype]))
  2380. {$endif arm}
  2381. ;
  2382. {$endif x86}
  2383. end;
  2384. function tstoreddef.is_const_intregable : boolean;
  2385. begin
  2386. case typ of
  2387. stringdef:
  2388. result:=tstringdef(self).stringtype in [st_ansistring,st_unicodestring,st_widestring];
  2389. arraydef:
  2390. result:=is_dynamic_array(self);
  2391. objectdef:
  2392. result:=is_interface(self);
  2393. else
  2394. result:=false;
  2395. end;
  2396. end;
  2397. procedure tstoreddef.initgeneric;
  2398. begin
  2399. if assigned(generictokenbuf) then
  2400. internalerror(200512131);
  2401. generictokenbuf:=tdynamicarray.create(256);
  2402. end;
  2403. function tstoreddef.is_generic: boolean;
  2404. var
  2405. sym: tsym;
  2406. i: longint;
  2407. begin
  2408. result:=assigned(genericparas) and
  2409. (genericparas.count>0) and
  2410. (df_generic in defoptions);
  2411. if result then
  2412. { if any of the type parameters does *not* belong to us (meaning it was passed
  2413. in from outside) then we aren't a generic, but a specialization }
  2414. for i:=0 to genericparas.count-1 do
  2415. begin
  2416. sym:=tsym(genericparas[i]);
  2417. { sym must be either a type or const }
  2418. if not (sym.typ in [symconst.typesym,symconst.constsym]) then
  2419. internalerror(2014050903);
  2420. if (sym.owner.defowner<>self) or (sp_generic_unnamed_type in sym.symoptions) then
  2421. exit(false);
  2422. if (sym.typ=symconst.constsym) and (sp_generic_const in sym.symoptions) then
  2423. exit(false);
  2424. end;
  2425. end;
  2426. function tstoreddef.is_generic_param_const(index:integer):boolean;
  2427. begin
  2428. result:=tsym(genericparas[index]).typ=constsym;
  2429. end;
  2430. function tstoreddef.get_generic_param_def(index:integer):tdef;
  2431. begin
  2432. if tsym(genericparas[index]).typ=constsym then
  2433. result:=tconstsym(genericparas[index]).constdef
  2434. else
  2435. result:=ttypesym(genericparas[index]).typedef;
  2436. end;
  2437. function tstoreddef.is_specialization: boolean;
  2438. var
  2439. i : longint;
  2440. sym : tsym;
  2441. begin
  2442. result:=assigned(genericparas) and
  2443. (genericparas.count>0) and
  2444. (df_specialization in defoptions);
  2445. if result then
  2446. begin
  2447. { if at least one of the generic parameters is not owned by us (meaning it was
  2448. passed in from outside) then we have a specialization, otherwise we have a generic }
  2449. for i:=0 to genericparas.count-1 do
  2450. begin
  2451. sym:=tsym(genericparas[i]);
  2452. { sym must be either a type or const }
  2453. if not (sym.typ in [symconst.typesym,symconst.constsym]) then
  2454. internalerror(2014050904);
  2455. if (sym.owner.defowner<>self) or (sp_generic_unnamed_type in sym.symoptions) then
  2456. exit(true);
  2457. if (sym.typ=symconst.constsym) and (sp_generic_const in sym.symoptions) then
  2458. exit(true);
  2459. end;
  2460. result:=false;
  2461. end;
  2462. end;
  2463. procedure tstoreddef.register_def;
  2464. var
  2465. gst : tgetsymtable;
  2466. st : tsymtable;
  2467. begin
  2468. if registered then
  2469. exit;
  2470. { Register in current_module }
  2471. if assigned(current_module) then
  2472. begin
  2473. exclude(defoptions,df_not_registered_no_free);
  2474. for gst:=low(tgetsymtable) to high(tgetsymtable) do
  2475. begin
  2476. st:=getsymtable(gst);
  2477. if assigned(st) then
  2478. tstoredsymtable(st).register_children;
  2479. end;
  2480. if defid<defid_not_registered then
  2481. defid:=deflist_index
  2482. else
  2483. begin
  2484. current_module.deflist.Add(self);
  2485. defid:=current_module.deflist.Count-1;
  2486. registered_in_module:=current_module;
  2487. end;
  2488. maybe_put_in_symtable_stack;
  2489. end
  2490. else
  2491. DefId:=defid_registered_nost;
  2492. end;
  2493. procedure tstoreddef.maybe_put_in_symtable_stack;
  2494. var
  2495. insertstack: psymtablestackitem;
  2496. begin
  2497. if assigned(symtablestack) and
  2498. not assigned(self.owner) then
  2499. begin
  2500. insertstack:=symtablestack.stack;
  2501. { don't insert defs in exception symtables, as they are freed before
  2502. the module is compiled, so we can get crashes on high level targets
  2503. if they still need it while e.g. writing assembler code }
  2504. while assigned(insertstack) and
  2505. (insertstack^.symtable.symtabletype in [exceptsymtable,withsymtable]) do
  2506. insertstack:=insertstack^.next;
  2507. if not assigned(insertstack) then
  2508. internalerror(200602044);
  2509. if insertstack^.symtable.sealed then
  2510. internalerror(2015022301);
  2511. insertstack^.symtable.insertdef(self);
  2512. end;
  2513. end;
  2514. {****************************************************************************
  2515. Tstringdef
  2516. ****************************************************************************}
  2517. constructor tstringdef.createshort(l: byte; doregister: boolean);
  2518. begin
  2519. inherited create(stringdef,doregister);
  2520. stringtype:=st_shortstring;
  2521. encoding:=0;
  2522. len:=l;
  2523. end;
  2524. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  2525. begin
  2526. inherited ppuload(stringdef,ppufile);
  2527. stringtype:=st_shortstring;
  2528. encoding:=0;
  2529. len:=ppufile.getbyte;
  2530. ppuload_platform(ppufile);
  2531. end;
  2532. constructor tstringdef.createlong(l: asizeint; doregister: boolean);
  2533. begin
  2534. inherited create(stringdef,doregister);
  2535. stringtype:=st_longstring;
  2536. encoding:=0;
  2537. len:=l;
  2538. end;
  2539. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  2540. begin
  2541. inherited ppuload(stringdef,ppufile);
  2542. stringtype:=st_longstring;
  2543. encoding:=0;
  2544. len:=ppufile.getasizeint;
  2545. ppuload_platform(ppufile);
  2546. end;
  2547. constructor tstringdef.createansi(aencoding: tstringencoding; doregister: boolean);
  2548. begin
  2549. inherited create(stringdef,doregister);
  2550. stringtype:=st_ansistring;
  2551. encoding:=aencoding;
  2552. len:=-1;
  2553. end;
  2554. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  2555. begin
  2556. inherited ppuload(stringdef,ppufile);
  2557. stringtype:=st_ansistring;
  2558. len:=ppufile.getasizeint;
  2559. encoding:=ppufile.getword;
  2560. ppuload_platform(ppufile);
  2561. end;
  2562. constructor tstringdef.createwide(doregister: boolean);
  2563. begin
  2564. inherited create(stringdef,doregister);
  2565. stringtype:=st_widestring;
  2566. if target_info.endian=endian_little then
  2567. encoding:=CP_UTF16LE
  2568. else
  2569. encoding:=CP_UTF16BE;
  2570. len:=-1;
  2571. end;
  2572. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  2573. begin
  2574. inherited ppuload(stringdef,ppufile);
  2575. stringtype:=st_widestring;
  2576. if target_info.endian=endian_little then
  2577. encoding:=CP_UTF16LE
  2578. else
  2579. encoding:=CP_UTF16BE;
  2580. len:=ppufile.getasizeint;
  2581. ppuload_platform(ppufile);
  2582. end;
  2583. constructor tstringdef.createunicode(doregister: boolean);
  2584. begin
  2585. inherited create(stringdef,doregister);
  2586. stringtype:=st_unicodestring;
  2587. if target_info.endian=endian_little then
  2588. encoding:=CP_UTF16LE
  2589. else
  2590. encoding:=CP_UTF16BE;
  2591. len:=-1;
  2592. end;
  2593. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  2594. begin
  2595. inherited ppuload(stringdef,ppufile);
  2596. stringtype:=st_unicodestring;
  2597. len:=ppufile.getasizeint;
  2598. encoding:=ppufile.getword;
  2599. ppuload_platform(ppufile);
  2600. end;
  2601. function tstringdef.getcopy : tstoreddef;
  2602. begin
  2603. result:=cstringdef.create(typ,true);
  2604. result.typ:=stringdef;
  2605. tstringdef(result).stringtype:=stringtype;
  2606. tstringdef(result).encoding:=encoding;
  2607. tstringdef(result).len:=len;
  2608. end;
  2609. function tstringdef.stringtypname:string;
  2610. const
  2611. typname:array[tstringtype] of string[10]=(
  2612. 'shortstr','longstr','ansistr','widestr','unicodestr'
  2613. );
  2614. begin
  2615. stringtypname:=typname[stringtype];
  2616. end;
  2617. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  2618. begin
  2619. inherited ppuwrite(ppufile);
  2620. if stringtype=st_shortstring then
  2621. begin
  2622. {$ifdef extdebug}
  2623. if len > 255 then internalerror(12122002);
  2624. {$endif}
  2625. ppufile.putbyte(byte(len))
  2626. end
  2627. else
  2628. ppufile.putasizeint(len);
  2629. if stringtype in [st_ansistring,st_unicodestring] then
  2630. ppufile.putword(encoding);
  2631. case stringtype of
  2632. st_shortstring : writeentry(ppufile,ibshortstringdef);
  2633. st_longstring : writeentry(ppufile,iblongstringdef);
  2634. st_ansistring : writeentry(ppufile,ibansistringdef);
  2635. st_widestring : writeentry(ppufile,ibwidestringdef);
  2636. st_unicodestring : writeentry(ppufile,ibunicodestringdef);
  2637. end;
  2638. end;
  2639. function tstringdef.needs_inittable : boolean;
  2640. begin
  2641. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  2642. end;
  2643. function tstringdef.GetTypeName : string;
  2644. const
  2645. names : array[tstringtype] of string[15] = (
  2646. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  2647. begin
  2648. GetTypeName:=names[stringtype];
  2649. case stringtype of
  2650. st_ansistring,st_unicodestring:
  2651. GetTypeName:=GetTypeName+'('+tostr(encoding)+')';
  2652. st_shortstring:
  2653. GetTypeName:=GetTypeName+'['+tostr(len)+']';
  2654. else
  2655. ;
  2656. end;
  2657. end;
  2658. function tstringdef.getvardef : longint;
  2659. const
  2660. vardef : array[tstringtype] of longint = (
  2661. varUndefined,varUndefined,varString,varOleStr,varUString);
  2662. begin
  2663. result:=vardef[stringtype];
  2664. end;
  2665. function tstringdef.get_default_char_type: tdef;
  2666. begin
  2667. case stringtype of
  2668. st_shortstring,
  2669. st_longstring,
  2670. st_ansistring:
  2671. result:=cansichartype;
  2672. st_unicodestring,
  2673. st_widestring:
  2674. result:=cwidechartype;
  2675. end;
  2676. end;
  2677. function tstringdef.get_default_string_type: tdef;
  2678. begin
  2679. case stringtype of
  2680. st_shortstring:
  2681. result:=cshortstringtype;
  2682. { st_longstring is currently not supported but
  2683. when it is this case will need to be supplied }
  2684. st_longstring:
  2685. internalerror(2021040801);
  2686. st_ansistring:
  2687. result:=cansistringtype;
  2688. st_widestring:
  2689. result:=cwidestringtype;
  2690. st_unicodestring:
  2691. result:=cunicodestringtype;
  2692. end
  2693. end;
  2694. function tstringdef.alignment : shortint;
  2695. begin
  2696. case stringtype of
  2697. st_unicodestring,
  2698. st_widestring,
  2699. st_ansistring:
  2700. alignment:=voidpointertype.alignment;
  2701. st_longstring,
  2702. st_shortstring:
  2703. { char to string accesses byte 0 and 1 with one word access }
  2704. if (tf_requires_proper_alignment in target_info.flags) or
  2705. { macpas needs an alignment of 2 (MetroWerks compatible) }
  2706. (m_mac in current_settings.modeswitches) then
  2707. alignment:=size_2_align(2)
  2708. else
  2709. alignment:=size_2_align(1);
  2710. end;
  2711. end;
  2712. function tstringdef.getmangledparaname : TSymStr;
  2713. begin
  2714. getmangledparaname:='STRING';
  2715. end;
  2716. function tstringdef.is_publishable : tpublishproperty;
  2717. begin
  2718. is_publishable:=pp_publish;
  2719. end;
  2720. function tstringdef.size: asizeint;
  2721. begin
  2722. case stringtype of
  2723. st_shortstring:
  2724. Result:=len+1;
  2725. st_longstring,
  2726. st_ansistring,
  2727. st_widestring,
  2728. st_unicodestring:
  2729. Result:=voidpointertype.size;
  2730. end;
  2731. end;
  2732. {****************************************************************************
  2733. TENUMDEF
  2734. ****************************************************************************}
  2735. constructor tenumdef.create;
  2736. begin
  2737. inherited create(enumdef,true);
  2738. minval:=0;
  2739. maxval:=0;
  2740. calcsavesize(current_settings.packenum);
  2741. has_jumps:=false;
  2742. basedef:=nil;
  2743. basedefderef.reset;
  2744. symtable:=tenumsymtable.create(self);
  2745. end;
  2746. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  2747. begin
  2748. inherited create(enumdef,true);
  2749. minval:=_min;
  2750. maxval:=_max;
  2751. basedef:=_basedef;
  2752. calcsavesize(current_settings.packenum);
  2753. has_jumps:=false;
  2754. symtable:=basedef.symtable.getcopy;
  2755. include(defoptions, df_copied_def);
  2756. end;
  2757. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  2758. begin
  2759. inherited ppuload(enumdef,ppufile);
  2760. minval:=ppufile.getaint;
  2761. maxval:=ppufile.getaint;
  2762. savesize:=ppufile.getaint;
  2763. has_jumps:=false;
  2764. if df_copied_def in defoptions then
  2765. begin
  2766. symtable:=nil;
  2767. ppufile.getderef(basedefderef);
  2768. ppuload_platform(ppufile);
  2769. end
  2770. else
  2771. begin
  2772. ppuload_platform(ppufile);
  2773. // create with nil defowner first to prevent values changes on insert
  2774. symtable:=tenumsymtable.create(nil);
  2775. tenumsymtable(symtable).ppuload(ppufile);
  2776. symtable.defowner:=self;
  2777. end;
  2778. end;
  2779. destructor tenumdef.destroy;
  2780. begin
  2781. symtable.free;
  2782. symtable:=nil;
  2783. inherited destroy;
  2784. end;
  2785. function tenumdef.getcopy : tstoreddef;
  2786. begin
  2787. if assigned(basedef) then
  2788. result:=cenumdef.create_subrange(basedef,minval,maxval)
  2789. else
  2790. begin
  2791. result:=cenumdef.create;
  2792. tenumdef(result).minval:=minval;
  2793. tenumdef(result).maxval:=maxval;
  2794. tenumdef(result).symtable.free;
  2795. tenumdef(result).symtable:=symtable.getcopy;
  2796. tenumdef(result).basedef:=self;
  2797. end;
  2798. tenumdef(result).has_jumps:=has_jumps;
  2799. tenumdef(result).basedefderef:=basedefderef;
  2800. include(tenumdef(result).defoptions,df_copied_def);
  2801. end;
  2802. procedure tenumdef.calcsavesize(packenum: shortint);
  2803. begin
  2804. {$IFNDEF cpu64bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2805. if (packenum=8) or (int64(min)<low(longint)) or (int64(max)>high(cardinal)) or ((min<0) and (max>high(longint))) then
  2806. savesize:=8
  2807. {$IFNDEF cpu64bitaddr} {$pop} {$ENDIF}
  2808. else
  2809. {$IFDEF cpu16bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2810. if (packenum=4) or (min<low(smallint)) or (max>high(word)) or ((min<0) and (max>high(smallint))) then
  2811. savesize:=4
  2812. {$IFDEF cpu16bitaddr} {$pop} {$ENDIF}
  2813. else
  2814. if (packenum=2) or (min<low(shortint)) or (max>high(byte)) or ((min<0) and (max>high(shortint))) then
  2815. savesize:=2
  2816. else
  2817. savesize:=1;
  2818. end;
  2819. function tenumdef.packedbitsize: asizeint;
  2820. var
  2821. sizeval: tconstexprint;
  2822. power: longint;
  2823. begin
  2824. result := 0;
  2825. if (minval >= 0) and
  2826. (maxval <= 1) then
  2827. result := 1
  2828. else
  2829. begin
  2830. if (minval>=0) then
  2831. sizeval:=maxval
  2832. else
  2833. { don't count 0 twice, but take into account that range goes from -n-1..n }
  2834. sizeval:=(cutils.max(-minval,maxval+1)*2)-1;
  2835. { 256 must become 512 etc. }
  2836. nextpowerof2(sizeval+1,power);
  2837. result := power;
  2838. end;
  2839. end;
  2840. procedure tenumdef.setmax(_max:asizeint);
  2841. begin
  2842. maxval:=_max;
  2843. calcsavesize(current_settings.packenum);
  2844. end;
  2845. procedure tenumdef.setmin(_min:asizeint);
  2846. begin
  2847. minval:=_min;
  2848. calcsavesize(current_settings.packenum);
  2849. end;
  2850. function tenumdef.min:asizeint;
  2851. begin
  2852. min:=minval;
  2853. end;
  2854. function tenumdef.max:asizeint;
  2855. begin
  2856. max:=maxval;
  2857. end;
  2858. function tenumdef.getfirstsym: tsym;
  2859. var
  2860. i:integer;
  2861. begin
  2862. for i := 0 to symtable.SymList.Count - 1 do
  2863. begin
  2864. result:=tsym(symtable.SymList[i]);
  2865. if tenumsym(result).value=minval then
  2866. exit;
  2867. end;
  2868. result:=nil;
  2869. end;
  2870. function tenumdef.int2enumsym(l: asizeint): tsym;
  2871. var
  2872. i: longint;
  2873. sym: tsym;
  2874. bdef: tenumdef;
  2875. begin
  2876. result:=nil;
  2877. if (l<minval) or
  2878. (l>maxval) then
  2879. exit;
  2880. bdef:=getbasedef;
  2881. for i:=0 to bdef.symtable.symlist.count-1 do
  2882. begin
  2883. sym:=tsym(bdef.symtable.symlist[i]);
  2884. if (sym.typ=enumsym) and
  2885. (tenumsym(sym).value=l) then
  2886. begin
  2887. result:=sym;
  2888. exit;
  2889. end;
  2890. end;
  2891. end;
  2892. function tenumdef.getbasedef: tenumdef;
  2893. begin
  2894. if not assigned(basedef) then
  2895. result:=self
  2896. else
  2897. result:=basedef;
  2898. end;
  2899. procedure tenumdef.buildderef;
  2900. begin
  2901. inherited buildderef;
  2902. if df_copied_def in defoptions then
  2903. basedefderef.build(basedef)
  2904. else
  2905. tenumsymtable(symtable).buildderef;
  2906. end;
  2907. procedure tenumdef.deref;
  2908. begin
  2909. inherited deref;
  2910. if df_copied_def in defoptions then
  2911. begin
  2912. basedef:=tenumdef(basedefderef.resolve);
  2913. symtable:=basedef.symtable.getcopy;
  2914. end
  2915. else
  2916. tenumsymtable(symtable).deref(false);
  2917. end;
  2918. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  2919. begin
  2920. inherited ppuwrite(ppufile);
  2921. ppufile.putaint(min);
  2922. ppufile.putaint(max);
  2923. ppufile.putaint(savesize);
  2924. if df_copied_def in defoptions then
  2925. ppufile.putderef(basedefderef);
  2926. writeentry(ppufile,ibenumdef);
  2927. if not (df_copied_def in defoptions) then
  2928. tenumsymtable(symtable).ppuwrite(ppufile);
  2929. end;
  2930. function tenumdef.is_publishable : tpublishproperty;
  2931. begin
  2932. if not has_jumps then
  2933. is_publishable:=pp_publish
  2934. else
  2935. if m_delphi in current_settings.modeswitches then
  2936. is_publishable:=pp_ignore
  2937. else
  2938. is_publishable:=pp_error;
  2939. end;
  2940. function tenumdef.GetTypeName : string;
  2941. begin
  2942. GetTypeName:='<enumeration type>';
  2943. end;
  2944. {****************************************************************************
  2945. TRTTI_ATTRIBUTE_LIST
  2946. ****************************************************************************}
  2947. constructor trtti_attribute.ppuload(ppufile: tcompilerppufile);
  2948. begin
  2949. ppufile.getderef(typesymderef);
  2950. ppufile.getderef(typeconstrderef);
  2951. setlength(paras,ppufile.getlongint);
  2952. end;
  2953. procedure trtti_attribute.ppuwrite(ppufile: tcompilerppufile);
  2954. begin
  2955. ppufile.putderef(typesymderef);
  2956. ppufile.putderef(typeconstrderef);
  2957. ppufile.putlongint(length(paras));
  2958. end;
  2959. procedure trtti_attribute.ppuload_subentries(ppufile: tcompilerppufile);
  2960. var
  2961. i : sizeint;
  2962. begin
  2963. for i:=0 to high(paras) do
  2964. paras[i]:=ppuloadnodetree(ppufile);
  2965. end;
  2966. procedure trtti_attribute.ppuwrite_subentries(ppufile: tcompilerppufile);
  2967. var
  2968. i : sizeint;
  2969. begin
  2970. for i:=0 to high(paras) do
  2971. ppuwritenodetree(ppufile,paras[i]);
  2972. end;
  2973. destructor trtti_attribute.destroy;
  2974. var
  2975. n : tnode;
  2976. begin
  2977. constructorcall.free;
  2978. for n in paras do
  2979. n.free;
  2980. inherited destroy;
  2981. end;
  2982. procedure trtti_attribute.buildderef;
  2983. var
  2984. i : sizeint;
  2985. begin
  2986. typesymderef.build(typesym);
  2987. typeconstrderef.build(typeconstr);
  2988. for i:=0 to high(paras) do
  2989. paras[i].buildderefimpl;
  2990. end;
  2991. procedure trtti_attribute.deref;
  2992. var
  2993. i : sizeint;
  2994. begin
  2995. typesym:=tsym(typesymderef.resolve);
  2996. typeconstr:=tdef(typeconstrderef.resolve);
  2997. for i:=0 to high(paras) do
  2998. paras[i].derefimpl;
  2999. end;
  3000. class procedure trtti_attribute_list.bind(var dangling,owned:trtti_attribute_list);
  3001. begin
  3002. if assigned(owned) then
  3003. internalerror(2019071001);
  3004. if not assigned(dangling) then
  3005. exit;
  3006. if dangling.is_bound then
  3007. internalerror(2019071002);
  3008. current_module.used_rtti_attrs.concatlistcopy(dangling.rtti_attributes);
  3009. dangling.is_bound:=true;
  3010. owned:=dangling;
  3011. dangling:=nil;
  3012. end;
  3013. class procedure trtti_attribute_list.copyandbind(alist : trtti_attribute_list; var owned: trtti_attribute_list);
  3014. var
  3015. i,j : Integer;
  3016. attr,newattribute : trtti_attribute;
  3017. begin
  3018. if owned=Nil then
  3019. owned:=trtti_attribute_list.Create;
  3020. owned.is_bound:=True;
  3021. for i:=0 to aList.rtti_attributes.Count-1 do
  3022. begin
  3023. attr:=trtti_attribute(alist.rtti_attributes[i]);
  3024. newattribute:=trtti_attribute.Create;
  3025. newattribute.typesym:=attr.typesym;
  3026. newattribute.typeconstr:=attr.typeconstr;
  3027. newattribute.constructorcall:=attr.constructorcall.getcopy;
  3028. setlength(newattribute.paras,length(attr.paras));
  3029. for j:=0 to length(attr.paras)-1 do
  3030. newattribute.paras[j]:=attr.paras[j].getcopy;
  3031. owned.AddAttribute(newattribute);
  3032. end;
  3033. current_module.used_rtti_attrs.concatlistcopy(owned.rtti_attributes);
  3034. end;
  3035. procedure trtti_attribute_list.addattribute(atypesym:tsym;typeconstr:tdef;constructorcall:tnode;constref paras:array of tnode);
  3036. var
  3037. newattribute : trtti_attribute;
  3038. i : sizeint;
  3039. begin
  3040. if not assigned(rtti_attributes) then
  3041. rtti_attributes:=TFPObjectList.Create(true);
  3042. newattribute:=trtti_attribute.Create;
  3043. newattribute.typesym:=atypesym;
  3044. newattribute.typeconstr:=typeconstr;
  3045. newattribute.constructorcall:=constructorcall;
  3046. setlength(newattribute.paras,length(paras));
  3047. for i:=0 to high(paras) do
  3048. newattribute.paras[i]:=paras[i];
  3049. rtti_attributes.Add(newattribute);
  3050. end;
  3051. procedure trtti_attribute_list.addattribute(attr:trtti_attribute);
  3052. begin
  3053. if not assigned(rtti_attributes) then
  3054. rtti_attributes:=TFPObjectList.Create(true);
  3055. rtti_attributes.add(attr);
  3056. end;
  3057. destructor trtti_attribute_list.destroy;
  3058. begin
  3059. rtti_attributes.Free;
  3060. inherited destroy;
  3061. end;
  3062. function trtti_attribute_list.get_attribute_count:longint;
  3063. begin
  3064. if assigned(rtti_attributes) then
  3065. result:=rtti_attributes.Count
  3066. else
  3067. result:=0;
  3068. end;
  3069. procedure trtti_attribute_list.buildderef;
  3070. var
  3071. i : sizeint;
  3072. begin
  3073. if not assigned(rtti_attributes) then
  3074. exit;
  3075. for i:=0 to rtti_attributes.count-1 do
  3076. trtti_attribute(rtti_attributes[i]).buildderef;
  3077. end;
  3078. procedure trtti_attribute_list.deref;
  3079. var
  3080. i : sizeint;
  3081. begin
  3082. if not assigned(rtti_attributes) then
  3083. exit;
  3084. for i:=0 to rtti_attributes.count-1 do
  3085. trtti_attribute(rtti_attributes[i]).deref;
  3086. end;
  3087. class procedure trtti_attribute_list.ppuload_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3088. var
  3089. i : sizeint;
  3090. begin
  3091. if assigned(attrlist) then
  3092. begin
  3093. if not assigned(attrlist.rtti_attributes) then
  3094. internalerror(2019071101);
  3095. for i:=0 to attrlist.rtti_attributes.count-1 do
  3096. trtti_attribute(attrlist.rtti_attributes[i]).ppuload_subentries(ppufile);
  3097. end;
  3098. end;
  3099. class procedure trtti_attribute_list.ppuwrite_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3100. var
  3101. i : sizeint;
  3102. begin
  3103. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  3104. begin
  3105. for i:=0 to attrlist.rtti_attributes.count-1 do
  3106. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite_subentries(ppufile);
  3107. end;
  3108. end;
  3109. class function trtti_attribute_list.ppuload(ppufile:tcompilerppufile):trtti_attribute_list;
  3110. var
  3111. cnt,i : longint;
  3112. begin
  3113. cnt:=ppufile.getlongint;
  3114. if cnt>0 then
  3115. begin
  3116. result:=trtti_attribute_list.create;
  3117. for i:=0 to cnt-1 do
  3118. result.addattribute(trtti_attribute.ppuload(ppufile));
  3119. end
  3120. else
  3121. result:=nil;
  3122. end;
  3123. class procedure trtti_attribute_list.ppuwrite(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3124. var
  3125. i : longint;
  3126. begin
  3127. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  3128. begin
  3129. ppufile.putlongint(attrlist.rtti_attributes.count);
  3130. for i:=0 to attrlist.rtti_attributes.count-1 do
  3131. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite(ppufile);
  3132. end
  3133. else
  3134. ppufile.putlongint(0);
  3135. end;
  3136. {****************************************************************************
  3137. TORDDEF
  3138. ****************************************************************************}
  3139. constructor torddef.create(t : tordtype;v,b : TConstExprInt; doregister: boolean);
  3140. begin
  3141. inherited create(orddef,doregister);
  3142. low:=v;
  3143. high:=b;
  3144. ordtype:=t;
  3145. setsize;
  3146. end;
  3147. constructor torddef.ppuload(ppufile:tcompilerppufile);
  3148. begin
  3149. inherited ppuload(orddef,ppufile);
  3150. ordtype:=tordtype(ppufile.getbyte);
  3151. low:=ppufile.getexprint;
  3152. high:=ppufile.getexprint;
  3153. setsize;
  3154. ppuload_platform(ppufile);
  3155. end;
  3156. function torddef.getcopy : tstoreddef;
  3157. begin
  3158. result:=corddef.create(ordtype,low,high,true);
  3159. result.typ:=orddef;
  3160. torddef(result).low:=low;
  3161. torddef(result).high:=high;
  3162. torddef(result).ordtype:=ordtype;
  3163. torddef(result).savesize:=savesize;
  3164. end;
  3165. function torddef.alignment:shortint;
  3166. begin
  3167. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) and
  3168. (ordtype in [s64bit,u64bit]) then
  3169. result := 4
  3170. else
  3171. result := inherited alignment;
  3172. end;
  3173. procedure torddef.setsize;
  3174. const
  3175. sizetbl : array[tordtype] of longint = (
  3176. 0,
  3177. 1,2,4,8,16,
  3178. 1,2,4,8,16,
  3179. 1,1,2,4,8,
  3180. 1,2,4,8,
  3181. 1,2,8,system.high(longint)
  3182. );
  3183. begin
  3184. savesize:=sizetbl[ordtype];
  3185. if savesize=system.high(longint) then
  3186. savesize:=packedbitsize div 8;
  3187. end;
  3188. function torddef.packedbitsize: asizeint;
  3189. var
  3190. sizeval: tconstexprint;
  3191. power: longint;
  3192. begin
  3193. result := 0;
  3194. if ordtype = uvoid then
  3195. exit;
  3196. {$ifndef cpu64bitalu}
  3197. if (ordtype in [s64bit,u64bit]) then
  3198. {$else not cpu64bitalu}
  3199. if ((ordtype = u64bit) and
  3200. (high > system.high(int64))) or
  3201. ((ordtype = s64bit) and
  3202. ((low <= (system.low(int64) div 2)) or
  3203. ((low < 0) and
  3204. (high > (system.high(int64) div 2))))) then
  3205. {$endif cpu64bitalu}
  3206. result := 64
  3207. else if (
  3208. (low >= 0) and
  3209. (high <= 1)
  3210. ) or (
  3211. ordtype in [pasbool1,pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit]
  3212. ) then
  3213. result := 1
  3214. else
  3215. begin
  3216. if (low>=0) then
  3217. sizeval:=high
  3218. else
  3219. { don't count 0 twice, but take into account that range goes from -n-1..n }
  3220. sizeval:=(cutils.max(-low,high+1)*2)-1;
  3221. { 256 must become 512 etc. }
  3222. nextpowerof2(sizeval+1,power);
  3223. result := power;
  3224. end;
  3225. end;
  3226. function torddef.getvardef : longint;
  3227. const
  3228. basetype2vardef : array[tordtype] of longint = (
  3229. varUndefined,
  3230. varbyte,varword,varlongword,varqword,varUndefined,
  3231. varshortint,varsmallint,varinteger,varint64,varUndefined,
  3232. varboolean,varboolean,varboolean,varboolean,varboolean,
  3233. varboolean,varboolean,varUndefined,varUndefined,
  3234. varUndefined,varUndefined,varCurrency,varEmpty);
  3235. begin
  3236. result:=basetype2vardef[ordtype];
  3237. if result=varEmpty then
  3238. result:=basetype2vardef[range_to_basetype(low,high)];
  3239. end;
  3240. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  3241. begin
  3242. inherited ppuwrite(ppufile);
  3243. ppufile.putbyte(byte(ordtype));
  3244. ppufile.putexprint(low);
  3245. ppufile.putexprint(high);
  3246. writeentry(ppufile,iborddef);
  3247. end;
  3248. function torddef.is_publishable : tpublishproperty;
  3249. begin
  3250. if ordtype<>uvoid then
  3251. is_publishable:=pp_publish
  3252. else
  3253. is_publishable:=pp_error;
  3254. end;
  3255. function torddef.GetTypeName : string;
  3256. const
  3257. names : array[tordtype] of string[20] = (
  3258. 'untyped',
  3259. 'Byte','Word','DWord','QWord','UInt128',
  3260. 'ShortInt','SmallInt','LongInt','Int64','Int128',
  3261. 'Boolean','Boolean8','Boolean16','Boolean32','Boolean64',
  3262. 'ByteBool','WordBool','LongBool','QWordBool',
  3263. 'AnsiChar','WideChar','Currency','CustomRange');
  3264. begin
  3265. GetTypeName:=names[ordtype];
  3266. end;
  3267. {****************************************************************************
  3268. TFLOATDEF
  3269. ****************************************************************************}
  3270. constructor tfloatdef.create(t: tfloattype; doregister: boolean);
  3271. begin
  3272. inherited create(floatdef,doregister);
  3273. floattype:=t;
  3274. setsize;
  3275. end;
  3276. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  3277. begin
  3278. inherited ppuload(floatdef,ppufile);
  3279. floattype:=tfloattype(ppufile.getbyte);
  3280. setsize;
  3281. ppuload_platform(ppufile);
  3282. end;
  3283. function tfloatdef.getcopy : tstoreddef;
  3284. begin
  3285. result:=cfloatdef.create(floattype,true);
  3286. result.typ:=floatdef;
  3287. tfloatdef(result).savesize:=savesize;
  3288. end;
  3289. function tfloatdef.alignment:shortint;
  3290. begin
  3291. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) then
  3292. case floattype of
  3293. sc80real,
  3294. s80real: result:=16;
  3295. s64real,
  3296. s64currency,
  3297. s64comp : result:=4;
  3298. else
  3299. result := inherited alignment;
  3300. end
  3301. else
  3302. result := inherited alignment;
  3303. end;
  3304. function tfloatdef.structalignment: shortint;
  3305. begin
  3306. { aix is really annoying: the recommended scalar alignment for both
  3307. int64 and double is 64 bits, but in structs int64 has to be aligned
  3308. to 8 bytes and double to 4 bytes }
  3309. if (target_info.system in systems_aix) and
  3310. (floattype=s64real) then
  3311. result:=4
  3312. else
  3313. result:=alignment;
  3314. end;
  3315. procedure tfloatdef.setsize;
  3316. begin
  3317. case floattype of
  3318. s32real : savesize:=4;
  3319. s80real : savesize:=10;
  3320. sc80real:
  3321. if target_info.system in [system_i386_darwin,
  3322. system_i386_iphonesim,system_x86_64_darwin,
  3323. system_x86_64_iphonesim,
  3324. system_x86_64_linux,system_x86_64_freebsd,
  3325. system_x86_64_openbsd,system_x86_64_netbsd,
  3326. system_x86_64_solaris,system_x86_64_embedded,
  3327. system_x86_64_dragonfly,system_x86_64_haiku] then
  3328. savesize:=16
  3329. else
  3330. savesize:=12;
  3331. s64real,
  3332. s64currency,
  3333. s64comp : savesize:=8;
  3334. else
  3335. savesize:=0;
  3336. end;
  3337. end;
  3338. function tfloatdef.getvardef : longint;
  3339. const
  3340. floattype2vardef : array[tfloattype] of longint = (
  3341. varSingle,varDouble,varUndefined,varUndefined,
  3342. varUndefined,varCurrency,varUndefined);
  3343. begin
  3344. if (upper(typename)='TDATETIME') and
  3345. assigned(owner) and
  3346. assigned(owner.name) and
  3347. (owner.name^='SYSTEM') then
  3348. result:=varDate
  3349. else
  3350. result:=floattype2vardef[floattype];
  3351. end;
  3352. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  3353. begin
  3354. inherited ppuwrite(ppufile);
  3355. ppufile.putbyte(byte(floattype));
  3356. writeentry(ppufile,ibfloatdef);
  3357. end;
  3358. function tfloatdef.is_publishable : tpublishproperty;
  3359. begin
  3360. is_publishable:=pp_publish;
  3361. end;
  3362. function tfloatdef.GetTypeName : string;
  3363. const
  3364. names : array[tfloattype] of string[20] = (
  3365. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  3366. begin
  3367. GetTypeName:=names[floattype];
  3368. end;
  3369. {****************************************************************************
  3370. TFILEDEF
  3371. ****************************************************************************}
  3372. constructor tfiledef.createtext;
  3373. begin
  3374. inherited create(filedef,true);
  3375. filetyp:=ft_text;
  3376. typedfiledef:=nil;
  3377. typedfiledefderef.reset;
  3378. end;
  3379. constructor tfiledef.createuntyped;
  3380. begin
  3381. inherited create(filedef,true);
  3382. filetyp:=ft_untyped;
  3383. typedfiledef:=nil;
  3384. end;
  3385. constructor tfiledef.createtyped(def:tdef);
  3386. begin
  3387. inherited create(filedef,true);
  3388. filetyp:=ft_typed;
  3389. typedfiledef:=def;
  3390. end;
  3391. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  3392. begin
  3393. inherited ppuload(filedef,ppufile);
  3394. filetyp:=tfiletyp(ppufile.getbyte);
  3395. if filetyp=ft_typed then
  3396. ppufile.getderef(typedfiledefderef)
  3397. else
  3398. typedfiledef:=nil;
  3399. ppuload_platform(ppufile);
  3400. end;
  3401. function tfiledef.getcopy : tstoreddef;
  3402. begin
  3403. case filetyp of
  3404. ft_typed:
  3405. result:=cfiledef.createtyped(typedfiledef);
  3406. ft_untyped:
  3407. result:=cfiledef.createuntyped;
  3408. ft_text:
  3409. result:=cfiledef.createtext;
  3410. end;
  3411. end;
  3412. procedure tfiledef.buildderef;
  3413. begin
  3414. inherited buildderef;
  3415. if filetyp=ft_typed then
  3416. typedfiledefderef.build(typedfiledef);
  3417. end;
  3418. procedure tfiledef.deref;
  3419. begin
  3420. inherited deref;
  3421. if filetyp=ft_typed then
  3422. typedfiledef:=tdef(typedfiledefderef.resolve);
  3423. end;
  3424. function tfiledef.size:asizeint;
  3425. begin
  3426. if savesize=0 then
  3427. setsize;
  3428. size:=savesize;
  3429. end;
  3430. procedure tfiledef.setsize;
  3431. begin
  3432. case filetyp of
  3433. ft_text:
  3434. savesize:=search_system_type('TEXTREC').typedef.size;
  3435. ft_typed:
  3436. begin
  3437. savesize:=search_system_type('FILEREC').typedef.size;
  3438. { allocate put/get buffer in iso mode }
  3439. if m_isolike_io in current_settings.modeswitches then
  3440. inc(savesize,typedfiledef.size);
  3441. end;
  3442. ft_untyped:
  3443. savesize:=search_system_type('FILEREC').typedef.size;
  3444. end;
  3445. end;
  3446. function tfiledef.alignment: shortint;
  3447. begin
  3448. case filetyp of
  3449. ft_text:
  3450. result:=search_system_type('TEXTREC').typedef.alignment;
  3451. ft_typed,
  3452. ft_untyped:
  3453. result:=search_system_type('FILEREC').typedef.alignment;
  3454. end;
  3455. end;
  3456. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  3457. begin
  3458. inherited ppuwrite(ppufile);
  3459. ppufile.putbyte(byte(filetyp));
  3460. if filetyp=ft_typed then
  3461. ppufile.putderef(typedfiledefderef);
  3462. writeentry(ppufile,ibfiledef);
  3463. end;
  3464. function tfiledef.GetTypeName : string;
  3465. begin
  3466. case filetyp of
  3467. ft_untyped:
  3468. GetTypeName:='File';
  3469. ft_typed:
  3470. GetTypeName:='File Of '+typedfiledef.typename;
  3471. ft_text:
  3472. GetTypeName:='Text'
  3473. end;
  3474. end;
  3475. function tfiledef.getmangledparaname : TSymStr;
  3476. begin
  3477. case filetyp of
  3478. ft_untyped:
  3479. getmangledparaname:='FILE';
  3480. ft_typed:
  3481. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  3482. ft_text:
  3483. getmangledparaname:='TEXT'
  3484. end;
  3485. end;
  3486. {****************************************************************************
  3487. TVARIANTDEF
  3488. ****************************************************************************}
  3489. constructor tvariantdef.create(v : tvarianttype);
  3490. begin
  3491. inherited create(variantdef,true);
  3492. varianttype:=v;
  3493. setsize;
  3494. end;
  3495. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  3496. begin
  3497. inherited ppuload(variantdef,ppufile);
  3498. varianttype:=tvarianttype(ppufile.getbyte);
  3499. setsize;
  3500. ppuload_platform(ppufile);
  3501. end;
  3502. function tvariantdef.getcopy : tstoreddef;
  3503. begin
  3504. result:=cvariantdef.create(varianttype);
  3505. end;
  3506. function tvariantdef.alignment: shortint;
  3507. begin
  3508. result:=search_system_type('TVARDATA').typedef.alignment;
  3509. end;
  3510. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  3511. begin
  3512. inherited ppuwrite(ppufile);
  3513. ppufile.putbyte(byte(varianttype));
  3514. writeentry(ppufile,ibvariantdef);
  3515. end;
  3516. function tvariantdef.getvardef : longint;
  3517. begin
  3518. Result:=varVariant;
  3519. end;
  3520. procedure tvariantdef.setsize;
  3521. begin
  3522. {$ifdef cpu64bitaddr}
  3523. savesize:=24;
  3524. {$else cpu64bitaddr}
  3525. savesize:=16;
  3526. {$endif cpu64bitaddr}
  3527. end;
  3528. function tvariantdef.GetTypeName : string;
  3529. begin
  3530. case varianttype of
  3531. vt_normalvariant:
  3532. GetTypeName:='Variant';
  3533. vt_olevariant:
  3534. GetTypeName:='OleVariant';
  3535. end;
  3536. end;
  3537. function tvariantdef.needs_inittable : boolean;
  3538. begin
  3539. needs_inittable:=true;
  3540. end;
  3541. function tvariantdef.is_publishable : tpublishproperty;
  3542. begin
  3543. is_publishable:=pp_publish;
  3544. end;
  3545. {****************************************************************************
  3546. TABSTRACtpointerdef
  3547. ****************************************************************************}
  3548. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  3549. begin
  3550. inherited create(dt,true);
  3551. pointeddef:=def;
  3552. pointeddefderef.reset;
  3553. if df_generic in pointeddef.defoptions then
  3554. include(defoptions,df_generic);
  3555. if df_specialization in pointeddef.defoptions then
  3556. include(defoptions,df_specialization);
  3557. end;
  3558. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3559. begin
  3560. inherited ppuload(dt,ppufile);
  3561. ppufile.getderef(pointeddefderef);
  3562. end;
  3563. procedure tabstractpointerdef.buildderef;
  3564. begin
  3565. inherited buildderef;
  3566. pointeddefderef.build(pointeddef);
  3567. end;
  3568. procedure tabstractpointerdef.deref;
  3569. begin
  3570. inherited deref;
  3571. pointeddef:=tdef(pointeddefderef.resolve);
  3572. end;
  3573. function tabstractpointerdef.size: asizeint;
  3574. begin
  3575. Result:=voidpointertype.size;
  3576. end;
  3577. function tabstractpointerdef.alignment: shortint;
  3578. begin
  3579. alignment:=size_2_align(voidpointertype.size);
  3580. end;
  3581. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3582. begin
  3583. inherited ppuwrite(ppufile);
  3584. ppufile.putderef(pointeddefderef);
  3585. end;
  3586. {****************************************************************************
  3587. tpointerdef
  3588. ****************************************************************************}
  3589. constructor tpointerdef.create(def:tdef);
  3590. begin
  3591. inherited create(pointerdef,def);
  3592. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  3593. if (df_specialization in tstoreddef(def).defoptions)
  3594. {$ifndef genericdef_for_nested}
  3595. { currently, nested procdefs of generic routines get df_specialization,
  3596. but no genericdef }
  3597. and assigned(tstoreddef(def).genericdef)
  3598. {$endif}
  3599. then
  3600. genericdef:=cpointerdef.getreusable(tstoreddef(def).genericdef);
  3601. end;
  3602. class function tpointerdef.getreusable(def: tdef): tpointerdef;
  3603. var
  3604. res: PHashSetItem;
  3605. oldsymtablestack: tsymtablestack;
  3606. begin
  3607. if not assigned(current_module) then
  3608. internalerror(2011071101);
  3609. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  3610. if not assigned(res^.Data) then
  3611. begin
  3612. { since these pointerdefs can be reused anywhere in the current
  3613. unit, add them to the global/staticsymtable (or local symtable
  3614. if they're a local def, because otherwise they'll be saved
  3615. to the ppu referencing a local symtable entry that doesn't
  3616. exist in the ppu) }
  3617. oldsymtablestack:=symtablestack;
  3618. { do not simply push/pop current_module.localsymtable, because
  3619. that can have side-effects (e.g., it removes helpers) }
  3620. symtablestack:=nil;
  3621. result:=cpointerdef.create(def);
  3622. setup_reusable_def(def,result,res,oldsymtablestack);
  3623. { res^.Data may still be nil -> don't overwrite result }
  3624. exit;
  3625. end;
  3626. result:=tpointerdef(res^.Data);
  3627. end;
  3628. class function tpointerdef.getreusable_no_free(def: tdef): tpointerdef;
  3629. begin
  3630. result:=getreusable(def);
  3631. if not result.is_registered then
  3632. include(result.defoptions,df_not_registered_no_free);
  3633. end;
  3634. function tpointerdef.size: asizeint;
  3635. begin
  3636. result:=sizeof(pint);
  3637. end;
  3638. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  3639. begin
  3640. inherited ppuload(pointerdef,ppufile);
  3641. has_pointer_math:=(ppufile.getbyte<>0);
  3642. ppuload_platform(ppufile);
  3643. end;
  3644. function tpointerdef.getcopy : tstoreddef;
  3645. begin
  3646. { don't use direct pointeddef if it is a forwarddef because in other case
  3647. one of them will be destroyed on forward type resolve and the second will
  3648. point to garbage }
  3649. if pointeddef.typ=forwarddef then
  3650. result:=cpointerdef.create(tforwarddef(pointeddef).getcopy)
  3651. else
  3652. result:=cpointerdef.create(pointeddef);
  3653. tpointerdef(result).has_pointer_math:=has_pointer_math;
  3654. tpointerdef(result).savesize:=savesize;
  3655. end;
  3656. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3657. begin
  3658. inherited ppuwrite(ppufile);
  3659. ppufile.putbyte(byte(has_pointer_math));
  3660. writeentry(ppufile,ibpointerdef);
  3661. end;
  3662. function tpointerdef.GetTypeName : string;
  3663. begin
  3664. { parameter types and the resultdef of a procvardef can contain a
  3665. pointer to this procvardef itself, resulting in endless recursion ->
  3666. use the typesym's name instead if it exists (if it doesn't, such as
  3667. for anynonymous procedure types in macpas/iso mode, then there cannot
  3668. be any recursive references to it either) }
  3669. if (pointeddef.typ<>procvardef) or
  3670. not assigned(pointeddef.typesym) then
  3671. GetTypeName:='^'+pointeddef.typename
  3672. else
  3673. GetTypeName:='^'+pointeddef.typesym.realname;
  3674. end;
  3675. function tpointerdef.pointer_arithmetic_int_type:tdef;
  3676. begin
  3677. result:=ptrsinttype;
  3678. end;
  3679. function tpointerdef.pointer_arithmetic_uint_type:tdef;
  3680. begin
  3681. result:=ptruinttype;
  3682. end;
  3683. function tpointerdef.pointer_subtraction_result_type:tdef;
  3684. begin
  3685. result:=ptrsinttype;
  3686. end;
  3687. function tpointerdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  3688. begin
  3689. result:=true;
  3690. end;
  3691. function tpointerdef.converted_pointer_to_array_range_type:tdef;
  3692. begin
  3693. result:=ptrsinttype;
  3694. end;
  3695. {****************************************************************************
  3696. TCLASSREFDEF
  3697. ****************************************************************************}
  3698. constructor tclassrefdef.create(def:tdef);
  3699. begin
  3700. while (def.typ=objectdef) and tobjectdef(def).is_unique_objpasdef do
  3701. def:=tobjectdef(def).childof;
  3702. inherited create(classrefdef,def);
  3703. if df_specialization in tstoreddef(def).defoptions then
  3704. genericdef:=cclassrefdef.create(tstoreddef(def).genericdef);
  3705. end;
  3706. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  3707. begin
  3708. inherited ppuload(classrefdef,ppufile);
  3709. ppuload_platform(ppufile);
  3710. end;
  3711. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  3712. begin
  3713. inherited ppuwrite(ppufile);
  3714. writeentry(ppufile,ibclassrefdef);
  3715. end;
  3716. function tclassrefdef.getcopy:tstoreddef;
  3717. begin
  3718. if pointeddef.typ=forwarddef then
  3719. result:=cclassrefdef.create(tforwarddef(pointeddef).getcopy)
  3720. else
  3721. result:=cclassrefdef.create(pointeddef);
  3722. end;
  3723. function tclassrefdef.GetTypeName : string;
  3724. begin
  3725. GetTypeName:='Class Of '+pointeddef.typename;
  3726. end;
  3727. function tclassrefdef.is_publishable : tpublishproperty;
  3728. begin
  3729. is_publishable:=pp_publish;
  3730. end;
  3731. function tclassrefdef.rtti_mangledname(rt: trttitype): TSymStr;
  3732. begin
  3733. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  3734. result:=inherited rtti_mangledname(rt)
  3735. else
  3736. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  3737. end;
  3738. procedure tclassrefdef.register_created_object_type;
  3739. begin
  3740. tobjectdef(pointeddef).register_created_classref_type;
  3741. end;
  3742. {***************************************************************************
  3743. TSETDEF
  3744. ***************************************************************************}
  3745. constructor tsetdef.create(def: tdef; low, high: asizeint; doregister: boolean);
  3746. var
  3747. setallocbits: aint;
  3748. packedsavesize: aint;
  3749. actual_setalloc: ShortInt;
  3750. begin
  3751. inherited create(setdef,doregister);
  3752. elementdef:=def;
  3753. elementdefderef.reset;
  3754. setmax:=high;
  3755. setlow:=low;
  3756. actual_setalloc:=current_settings.setalloc;
  3757. {$if defined(cpu8bitalu) or defined(cpu16bitalu)}
  3758. if actual_setalloc=0 then
  3759. actual_setalloc:=1;
  3760. {$endif}
  3761. if (actual_setalloc=0) then
  3762. begin
  3763. setbase:=0;
  3764. if (high<32) then
  3765. savesize:=Sizeof(longint)
  3766. else if (high<256) then
  3767. savesize:=32
  3768. else
  3769. savesize:=(high+7) div 8
  3770. end
  3771. else
  3772. begin
  3773. setallocbits:=actual_setalloc*8;
  3774. setbase:=low and not(setallocbits-1);
  3775. packedsavesize:=actual_setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  3776. savesize:=packedsavesize;
  3777. {$if not defined(cpu8bitalu) and not defined(cpu16bitalu)}
  3778. if savesize=3 then
  3779. savesize:=4;
  3780. {$endif}
  3781. end;
  3782. end;
  3783. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  3784. begin
  3785. inherited ppuload(setdef,ppufile);
  3786. ppufile.getderef(elementdefderef);
  3787. savesize:=ppufile.getasizeint;
  3788. setbase:=ppufile.getasizeint;
  3789. setlow:=ppufile.getasizeint;
  3790. setmax:=ppufile.getasizeint;
  3791. ppuload_platform(ppufile);
  3792. end;
  3793. function tsetdef.getcopy : tstoreddef;
  3794. begin
  3795. result:=csetdef.create(elementdef,setbase,setmax,true);
  3796. { the copy might have been created with a different setalloc setting }
  3797. tsetdef(result).savesize:=savesize;
  3798. end;
  3799. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  3800. begin
  3801. inherited ppuwrite(ppufile);
  3802. ppufile.putderef(elementdefderef);
  3803. ppufile.putasizeint(savesize);
  3804. ppufile.putasizeint(setbase);
  3805. ppufile.putasizeint(setlow);
  3806. ppufile.putasizeint(setmax);
  3807. writeentry(ppufile,ibsetdef);
  3808. end;
  3809. procedure tsetdef.buildderef;
  3810. begin
  3811. inherited buildderef;
  3812. elementdefderef.build(elementdef);
  3813. end;
  3814. procedure tsetdef.deref;
  3815. begin
  3816. inherited deref;
  3817. elementdef:=tdef(elementdefderef.resolve);
  3818. end;
  3819. function tsetdef.is_publishable : tpublishproperty;
  3820. begin
  3821. if savesize in [1,2,4] then
  3822. is_publishable:=pp_publish
  3823. else
  3824. is_publishable:=pp_error;
  3825. end;
  3826. function tsetdef.alignment: shortint;
  3827. begin
  3828. Result:=inherited;
  3829. if result>sizeof(aint) then
  3830. result:=sizeof(aint);
  3831. end;
  3832. function tsetdef.GetTypeName : string;
  3833. begin
  3834. if assigned(elementdef) then
  3835. GetTypeName:='Set Of '+elementdef.typename
  3836. else
  3837. GetTypeName:='Empty Set';
  3838. end;
  3839. {***************************************************************************
  3840. TFORMALDEF
  3841. ***************************************************************************}
  3842. constructor tformaldef.create(Atyped:boolean);
  3843. begin
  3844. inherited create(formaldef,true);
  3845. typed:=Atyped;
  3846. savesize:=0;
  3847. end;
  3848. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  3849. begin
  3850. inherited ppuload(formaldef,ppufile);
  3851. typed:=boolean(ppufile.getbyte);
  3852. savesize:=0;
  3853. ppuload_platform(ppufile);
  3854. end;
  3855. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  3856. begin
  3857. inherited ppuwrite(ppufile);
  3858. ppufile.putbyte(byte(typed));
  3859. writeentry(ppufile,ibformaldef);
  3860. end;
  3861. function tformaldef.GetTypeName : string;
  3862. begin
  3863. if typed then
  3864. GetTypeName:='<Typed formal type>'
  3865. else
  3866. GetTypeName:='<Formal type>';
  3867. end;
  3868. {***************************************************************************
  3869. TARRAYDEF
  3870. ***************************************************************************}
  3871. constructor tarraydef.create(l, h: asizeint; def: tdef);
  3872. begin
  3873. inherited create(arraydef,true);
  3874. lowrange:=l;
  3875. highrange:=h;
  3876. rangedef:=def;
  3877. rangedefderef.reset;
  3878. _elementdef:=nil;
  3879. _elementdefderef.reset;
  3880. arrayoptions:=[];
  3881. symtable:=tarraysymtable.create(self);
  3882. end;
  3883. constructor tarraydef.create_vector(l ,h: asizeint; def: tdef);
  3884. begin
  3885. self.create(l,h,def);
  3886. include(arrayoptions,ado_IsVector);
  3887. end;
  3888. constructor tarraydef.create_openarray;
  3889. begin
  3890. self.create(0,-1,sizesinttype);
  3891. include(arrayoptions,ado_OpenArray);
  3892. end;
  3893. class function tarraydef.getreusable_intern(def: tdef; elems: asizeint; const options: tarraydefoptions): tarraydef;
  3894. var
  3895. res: PHashSetItem;
  3896. oldsymtablestack: tsymtablestack;
  3897. arrdesc: packed record
  3898. def: tdef;
  3899. elecount: asizeint;
  3900. options: tarraydefoptions
  3901. end;
  3902. begin
  3903. if not assigned(current_module) then
  3904. internalerror(2011081301);
  3905. arrdesc.def:=def;
  3906. arrdesc.elecount:=elems;
  3907. arrdesc.options:=options;
  3908. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  3909. if not assigned(res^.Data) then
  3910. begin
  3911. { since these pointerdefs can be reused anywhere in the current
  3912. unit, add them to the global/staticsymtable (or local symtable
  3913. if they're a local def, because otherwise they'll be saved
  3914. to the ppu referencing a local symtable entry that doesn't
  3915. exist in the ppu) }
  3916. oldsymtablestack:=symtablestack;
  3917. { do not simply push/pop current_module.localsymtable, because
  3918. that can have side-effects (e.g., it removes helpers) }
  3919. symtablestack:=nil;
  3920. result:=carraydef.create(0,elems-1,sizesinttype);
  3921. result.elementdef:=def;
  3922. result.arrayoptions:=options;
  3923. setup_reusable_def(def,result,res,oldsymtablestack);
  3924. { res^.Data may still be nil -> don't overwrite result }
  3925. exit;
  3926. end;
  3927. result:=tarraydef(res^.Data);
  3928. end;
  3929. class function tarraydef.getreusable(def: tdef; elems: asizeint): tarraydef;
  3930. begin
  3931. result:=getreusable_intern(def,elems,[]);
  3932. end;
  3933. class function tarraydef.getreusable_vector(def: tdef; elems: asizeint): tarraydef;
  3934. begin
  3935. result:=getreusable_intern(def,elems,[ado_IsVector]);
  3936. end;
  3937. class function tarraydef.getreusable_no_free(def: tdef; elems: asizeint): tarraydef;
  3938. begin
  3939. result:=getreusable(def,elems);
  3940. if not result.is_registered then
  3941. include(result.defoptions,df_not_registered_no_free);
  3942. end;
  3943. class function tarraydef.getreusable_no_free_vector(def: tdef; elems: asizeint): tarraydef;
  3944. begin
  3945. result:=getreusable_vector(def,elems);
  3946. if not result.is_registered then
  3947. include(result.defoptions,df_not_registered_no_free);
  3948. end;
  3949. destructor tarraydef.destroy;
  3950. begin
  3951. symtable.free;
  3952. symtable:=nil;
  3953. inherited;
  3954. end;
  3955. constructor tarraydef.create_from_pointer(def:tpointerdef);
  3956. begin
  3957. { divide by the element size and do -1 so the array will have a valid size,
  3958. further, the element size might be 0 e.g. for empty records, so use max(...,1)
  3959. to avoid a division by zero }
  3960. self.create(0,(high(asizeint) div max(def.pointeddef.size,1))-1,
  3961. def.converted_pointer_to_array_range_type);
  3962. arrayoptions:=[ado_IsConvertedPointer];
  3963. setelementdef(def.pointeddef);
  3964. end;
  3965. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  3966. begin
  3967. inherited ppuload(arraydef,ppufile);
  3968. { the addresses are calculated later }
  3969. ppufile.getderef(_elementdefderef);
  3970. ppufile.getderef(rangedefderef);
  3971. lowrange:=ppufile.getasizeint;
  3972. highrange:=ppufile.getasizeint;
  3973. ppufile.getset(tppuset2(arrayoptions));
  3974. ppuload_platform(ppufile);
  3975. symtable:=tarraysymtable.create(self);
  3976. tarraysymtable(symtable).ppuload(ppufile)
  3977. end;
  3978. function tarraydef.getcopy : tstoreddef;
  3979. begin
  3980. result:=carraydef.create(lowrange,highrange,rangedef);
  3981. tarraydef(result).arrayoptions:=arrayoptions;
  3982. tarraydef(result)._elementdef:=_elementdef;
  3983. end;
  3984. procedure tarraydef.buildderef;
  3985. begin
  3986. inherited buildderef;
  3987. tarraysymtable(symtable).buildderef;
  3988. _elementdefderef.build(_elementdef);
  3989. rangedefderef.build(rangedef);
  3990. end;
  3991. procedure tarraydef.deref;
  3992. begin
  3993. inherited deref;
  3994. tarraysymtable(symtable).deref(false);
  3995. _elementdef:=tdef(_elementdefderef.resolve);
  3996. rangedef:=tdef(rangedefderef.resolve);
  3997. end;
  3998. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  3999. begin
  4000. inherited ppuwrite(ppufile);
  4001. ppufile.putderef(_elementdefderef);
  4002. ppufile.putderef(rangedefderef);
  4003. ppufile.putasizeint(lowrange);
  4004. ppufile.putasizeint(highrange);
  4005. ppufile.putset(tppuset2(arrayoptions));
  4006. writeentry(ppufile,ibarraydef);
  4007. tarraysymtable(symtable).ppuwrite(ppufile);
  4008. end;
  4009. function tarraydef.elesize : asizeint;
  4010. begin
  4011. if (ado_IsBitPacked in arrayoptions) then
  4012. internalerror(2006080101);
  4013. if assigned(_elementdef) then
  4014. result:=_elementdef.size
  4015. else
  4016. result:=0;
  4017. end;
  4018. function tarraydef.elepackedbitsize : asizeint;
  4019. begin
  4020. if not(ado_IsBitPacked in arrayoptions) then
  4021. internalerror(2006080102);
  4022. if assigned(_elementdef) then
  4023. result:=_elementdef.packedbitsize
  4024. else
  4025. result:=0;
  4026. end;
  4027. function tarraydef.elecount : asizeuint;
  4028. var
  4029. qhigh,qlow : qword;
  4030. begin
  4031. if ado_IsDynamicArray in arrayoptions then
  4032. begin
  4033. result:=0;
  4034. exit;
  4035. end;
  4036. { check whether the range might be larger than high(asizeint). Has
  4037. to include 0..high(sizeint), since that's high(sizeint)+1 elements }
  4038. if (highrange>=0) and (lowrange<=0) then
  4039. begin
  4040. qhigh:=highrange;
  4041. if lowrange=low(asizeint) then
  4042. qlow:=high(asizeint) + 1
  4043. else
  4044. qlow:=qword(-lowrange);
  4045. { prevent overflow, return 0 to indicate overflow }
  4046. if qhigh+qlow>qword(high(asizeint)-1) then
  4047. result:=0
  4048. else
  4049. result:=qhigh+qlow+1;
  4050. end
  4051. else
  4052. result:=int64(highrange)-lowrange+1;
  4053. end;
  4054. function tarraydef.size : asizeint;
  4055. var
  4056. cachedelecount : asizeuint;
  4057. cachedelesize : asizeint;
  4058. begin
  4059. if ado_IsDynamicArray in arrayoptions then
  4060. begin
  4061. size:=voidpointertype.size;
  4062. exit;
  4063. end;
  4064. { Tarraydef.size may never be called for an open array! }
  4065. if ado_OpenArray in arrayoptions then
  4066. internalerror(99080501);
  4067. if not (ado_IsBitPacked in arrayoptions) then
  4068. cachedelesize:=elesize
  4069. else
  4070. cachedelesize := elepackedbitsize;
  4071. cachedelecount:=elecount;
  4072. if (cachedelesize = 0) then
  4073. begin
  4074. size := 0;
  4075. exit;
  4076. end;
  4077. if (cachedelecount = 0) then
  4078. begin
  4079. if ado_isconststring in arrayoptions then
  4080. size := 0
  4081. else
  4082. size := -1;
  4083. exit;
  4084. end;
  4085. { prevent overflow, return -1 to indicate overflow }
  4086. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  4087. if (cachedelecount > asizeuint(high(asizeint))) or
  4088. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  4089. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  4090. accessing the array, see ncgmem (PFV) }
  4091. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  4092. begin
  4093. result:=-1;
  4094. exit;
  4095. end;
  4096. result:=cachedelesize*asizeint(cachedelecount);
  4097. if (ado_IsBitPacked in arrayoptions) then
  4098. { can't just add 7 and divide by 8, because that may overflow }
  4099. result:=result div 8 + ord((result mod 8)<>0);
  4100. {$ifdef cpu16bitaddr}
  4101. if result>65535 then
  4102. begin
  4103. result:=-1;
  4104. exit;
  4105. end;
  4106. {$endif cpu16bitaddr}
  4107. end;
  4108. procedure tarraydef.setelementdef(def:tdef);
  4109. begin
  4110. _elementdef:=def;
  4111. if not(
  4112. (ado_IsDynamicArray in arrayoptions) or
  4113. (ado_IsConvertedPointer in arrayoptions) or
  4114. (ado_IsConstructor in arrayoptions) or
  4115. (ado_IsGeneric in arrayoptions) or
  4116. (highrange<lowrange)
  4117. ) and
  4118. (size=-1) then
  4119. Message(sym_e_segment_too_large);
  4120. end;
  4121. function tarraydef.alignment : shortint;
  4122. begin
  4123. if ado_IsVector in arrayoptions then
  4124. alignment:=size
  4125. { alignment of dyn. arrays doesn't depend on the element size }
  4126. else if ado_IsDynamicArray in arrayoptions then
  4127. alignment:=voidpointertype.alignment
  4128. { alignment is the target alignment for the used load size }
  4129. else if (ado_IsBitPacked in arrayoptions) and
  4130. (elementdef.typ in [enumdef,orddef]) then
  4131. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  4132. { alignment is the alignment of the elements }
  4133. else
  4134. alignment:=elementdef.alignment
  4135. end;
  4136. function tarraydef.needs_inittable : boolean;
  4137. begin
  4138. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  4139. end;
  4140. function tarraydef.needs_separate_initrtti : boolean;
  4141. begin
  4142. if ado_IsBitPacked in arrayoptions then
  4143. result:=false
  4144. else
  4145. result:=elementdef.needs_separate_initrtti;
  4146. end;
  4147. function tarraydef.GetTypeName : string;
  4148. begin
  4149. if (ado_IsConstString in arrayoptions) then
  4150. result:='Constant String'
  4151. else if (ado_isarrayofconst in arrayoptions) or
  4152. (ado_isConstructor in arrayoptions) then
  4153. begin
  4154. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  4155. GetTypeName:='Array Of Const'
  4156. else
  4157. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  4158. end
  4159. else if (ado_IsDynamicArray in arrayoptions) then
  4160. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  4161. else if (ado_OpenArray in arrayoptions) then
  4162. GetTypeName:='{Open} Array Of '+elementdef.typename
  4163. else
  4164. begin
  4165. result := '';
  4166. if (ado_IsBitPacked in arrayoptions) then
  4167. result:='BitPacked ';
  4168. if rangedef.typ=enumdef then
  4169. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  4170. else
  4171. result:=result+'Array['+tostr(lowrange)+'..'+
  4172. tostr(highrange)+'] Of '+elementdef.typename
  4173. end;
  4174. end;
  4175. function tarraydef.getmangledparaname : TSymStr;
  4176. begin
  4177. if ado_isarrayofconst in arrayoptions then
  4178. getmangledparaname:='array_of_const'
  4179. else
  4180. if ((highrange=-1) and (lowrange=0)) then
  4181. getmangledparaname:='array_of_'+elementdef.mangledparaname
  4182. else
  4183. internalerror(200204176);
  4184. end;
  4185. function tarraydef.is_publishable : tpublishproperty;
  4186. begin
  4187. if ado_IsDynamicArray in arrayoptions then
  4188. is_publishable:=pp_publish
  4189. else
  4190. is_publishable:=pp_error;
  4191. end;
  4192. function tarraydef.is_hwvector: boolean;
  4193. begin
  4194. result:=ado_IsVector in arrayoptions;
  4195. end;
  4196. {***************************************************************************
  4197. tabstractrecorddef
  4198. ***************************************************************************}
  4199. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp;doregister:boolean);
  4200. begin
  4201. inherited create(dt,doregister);
  4202. objname:=stringdup(upper(n));
  4203. objrealname:=stringdup(n);
  4204. objectoptions:=[];
  4205. if assigned(current_module.namespace) then
  4206. begin
  4207. import_lib:=stringdup(current_module.namespace^);
  4208. replace(import_lib^,'.','/');
  4209. end;
  4210. end;
  4211. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  4212. var
  4213. ro: trtti_option;
  4214. begin
  4215. inherited ppuload(dt,ppufile);
  4216. objrealname:=ppufile.getpshortstring;
  4217. objname:=stringdup(upper(objrealname^));
  4218. import_lib:=ppufile.getpshortstring;
  4219. { only used for external C++ classes and Java classes/records }
  4220. if (import_lib^='') then
  4221. stringdispose(import_lib);
  4222. ppufile.getset(tppuset4(objectoptions));
  4223. rtti.clause:=trtti_clause(ppufile.getbyte);
  4224. for ro in trtti_option do
  4225. ppufile.getset(tppuset1(rtti.options[ro]));
  4226. end;
  4227. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  4228. var
  4229. ro: trtti_option;
  4230. begin
  4231. inherited ppuwrite(ppufile);
  4232. ppufile.putstring(objrealname^);
  4233. if assigned(import_lib) then
  4234. ppufile.putstring(import_lib^)
  4235. else
  4236. ppufile.putstring('');
  4237. ppufile.putset(tppuset4(objectoptions));
  4238. ppufile.putbyte(byte(rtti.clause));
  4239. for ro in trtti_option do
  4240. ppufile.putset(tppuset1(rtti.options[ro]));
  4241. end;
  4242. destructor tabstractrecorddef.destroy;
  4243. begin
  4244. stringdispose(objname);
  4245. stringdispose(objrealname);
  4246. stringdispose(import_lib);
  4247. tcinitcode.free;
  4248. inherited destroy;
  4249. end;
  4250. procedure tabstractrecorddef.buildderefimpl;
  4251. begin
  4252. inherited buildderefimpl;
  4253. if not (df_copied_def in defoptions) then
  4254. tstoredsymtable(symtable).buildderefimpl;
  4255. end;
  4256. procedure tabstractrecorddef.derefimpl;
  4257. begin
  4258. inherited derefimpl;
  4259. if not (df_copied_def in defoptions) then
  4260. tstoredsymtable(symtable).derefimpl(false);
  4261. end;
  4262. procedure tabstractrecorddef.check_forwards;
  4263. begin
  4264. { the defs of a copied def are defined for the original type only }
  4265. if not(df_copied_def in defoptions) then
  4266. tstoredsymtable(symtable).check_forwards;
  4267. end;
  4268. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  4269. var
  4270. i: longint;
  4271. sym: tsym;
  4272. begin
  4273. for i:=0 to symtable.SymList.Count-1 do
  4274. begin
  4275. sym:=tsym(symtable.SymList[i]);
  4276. if sym.typ=procsym then
  4277. begin
  4278. result:=tprocsym(sym).find_procdef_bytype(pt);
  4279. if assigned(result) then
  4280. exit;
  4281. end;
  4282. end;
  4283. result:=nil;
  4284. end;
  4285. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  4286. begin
  4287. if t=gs_record then
  4288. GetSymtable:=symtable
  4289. else
  4290. GetSymtable:=nil;
  4291. end;
  4292. function tabstractrecorddef.is_packed:boolean;
  4293. begin
  4294. result:=tabstractrecordsymtable(symtable).is_packed;
  4295. end;
  4296. function tabstractrecorddef.RttiName: string;
  4297. function generate_full_paramname(maxlength:longint):string;
  4298. const
  4299. commacount : array[boolean] of longint = (0,1);
  4300. var
  4301. fullparas,
  4302. paramname : ansistring;
  4303. module : tmodule;
  4304. sym : tsym;
  4305. def : tdef;
  4306. i : longint;
  4307. begin
  4308. { we want at least enough space for an ellipsis }
  4309. if maxlength<3 then
  4310. internalerror(2014121203);
  4311. fullparas:='';
  4312. for i:=0 to genericparas.count-1 do
  4313. begin
  4314. sym:=tsym(genericparas[i]);
  4315. module:=find_module_from_symtable(sym.owner);
  4316. if not assigned(module) then
  4317. internalerror(2014121202);
  4318. if not (sym.typ in [constsym,symconst.typesym]) then
  4319. internalerror(2020042501);
  4320. if sym.typ=constsym then
  4321. def:=tconstsym(sym).constdef
  4322. else
  4323. def:=ttypesym(sym).typedef;
  4324. paramname:=module.realmodulename^;
  4325. if def.typ in [objectdef,recorddef] then
  4326. paramname:=paramname+'.'+tabstractrecorddef(def).rttiname
  4327. else
  4328. paramname:=paramname+'.'+def.typename;
  4329. if length(fullparas)+commacount[i>0]+length(paramname)>maxlength then
  4330. begin
  4331. if i>0 then
  4332. fullparas:=fullparas+',...'
  4333. else
  4334. fullparas:=fullparas+'...';
  4335. break;
  4336. end;
  4337. { could we fit an ellipsis after this parameter if it should be too long? }
  4338. if (maxlength-(length(fullparas)+commacount[i>0]+length(paramname))<4) and (i<genericparas.count-1) then
  4339. begin
  4340. { then omit already this parameter }
  4341. if i>0 then
  4342. fullparas:=fullparas+',...'
  4343. else
  4344. fullparas:=fullparas+'...';
  4345. break;
  4346. end;
  4347. if i>0 then
  4348. fullparas:=fullparas+',';
  4349. fullparas:=fullparas+paramname;
  4350. end;
  4351. result:=fullparas;
  4352. end;
  4353. var
  4354. nongeneric,
  4355. basename : string;
  4356. i,
  4357. remlength,
  4358. paramcount,
  4359. crcidx : longint;
  4360. begin
  4361. if rttistring='' then
  4362. begin
  4363. if is_specialization then
  4364. begin
  4365. rttistring:=OwnerHierarchyName;
  4366. { there should be two $ characters, one before the CRC and one before the count }
  4367. crcidx:=-1;
  4368. for i:=length(objrealname^) downto 1 do
  4369. if objrealname^[i]='$' then
  4370. begin
  4371. crcidx:=i;
  4372. break;
  4373. end;
  4374. if crcidx<0 then
  4375. internalerror(2014121201);
  4376. basename:=copy(objrealname^,1,crcidx-1);
  4377. split_generic_name(basename,nongeneric,paramcount);
  4378. rttistring:=rttistring+nongeneric+'<';
  4379. remlength:=255-length(rttistring)-1;
  4380. if remlength<4 then
  4381. rttistring:=rttistring+'>'
  4382. else
  4383. rttistring:=rttistring+generate_full_paramname(remlength)+'>';
  4384. end
  4385. else
  4386. if is_generic then
  4387. begin
  4388. rttistring:=OwnerHierarchyName;
  4389. split_generic_name(objrealname^,nongeneric,paramcount);
  4390. rttistring:=rttistring+nongeneric+'<';
  4391. { we don't want any ',' if there is only one parameter }
  4392. for i:=0 to paramcount-0 do
  4393. rttistring:=rttistring+',';
  4394. rttistring:=rttistring+'>';
  4395. end
  4396. else
  4397. rttistring:=OwnerHierarchyName+objrealname^;
  4398. end;
  4399. result:=rttistring;
  4400. end;
  4401. function tabstractrecorddef.search_enumerator_get: tprocdef;
  4402. var
  4403. sym : tsym;
  4404. i : integer;
  4405. pd : tprocdef;
  4406. hashedid : THashedIDString;
  4407. begin
  4408. result:=nil;
  4409. hashedid.id:='GETENUMERATOR';
  4410. sym:=tsym(symtable.FindWithHash(hashedid));
  4411. if assigned(sym) and (sym.typ=procsym) then
  4412. begin
  4413. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  4414. begin
  4415. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4416. if (pd.proctypeoption = potype_function) and
  4417. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  4418. (pd.visibility >= vis_public) then
  4419. begin
  4420. result:=pd;
  4421. exit;
  4422. end;
  4423. end;
  4424. end;
  4425. end;
  4426. function tabstractrecorddef.search_enumerator_move: tprocdef;
  4427. var
  4428. sym : tsym;
  4429. i : integer;
  4430. pd : tprocdef;
  4431. hashedid : THashedIDString;
  4432. begin
  4433. result:=nil;
  4434. // first search for po_enumerator_movenext method modifier
  4435. // then search for public function MoveNext: Boolean
  4436. for i:=0 to symtable.SymList.Count-1 do
  4437. begin
  4438. sym:=TSym(symtable.SymList[i]);
  4439. if (sym.typ=procsym) then
  4440. begin
  4441. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  4442. if assigned(pd) then
  4443. begin
  4444. result:=pd;
  4445. exit;
  4446. end;
  4447. end;
  4448. end;
  4449. hashedid.id:='MOVENEXT';
  4450. sym:=tsym(symtable.FindWithHash(hashedid));
  4451. if assigned(sym) and (sym.typ=procsym) then
  4452. begin
  4453. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  4454. begin
  4455. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4456. if (pd.proctypeoption = potype_function) and
  4457. is_boolean(pd.returndef) and
  4458. (pd.minparacount = 0) and
  4459. (pd.visibility >= vis_public) then
  4460. begin
  4461. result:=pd;
  4462. exit;
  4463. end;
  4464. end;
  4465. end;
  4466. end;
  4467. function tabstractrecorddef.search_enumerator_current: tsym;
  4468. var
  4469. sym: tsym;
  4470. i: integer;
  4471. hashedid : THashedIDString;
  4472. begin
  4473. result:=nil;
  4474. // first search for ppo_enumerator_current property modifier
  4475. // then search for public property Current
  4476. for i:=0 to symtable.SymList.Count-1 do
  4477. begin
  4478. sym:=TSym(symtable.SymList[i]);
  4479. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  4480. begin
  4481. result:=sym;
  4482. exit;
  4483. end;
  4484. end;
  4485. hashedid.id:='CURRENT';
  4486. sym:=tsym(symtable.FindWithHash(hashedid));
  4487. if assigned(sym) and (sym.typ=propertysym) and
  4488. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  4489. begin
  4490. result:=sym;
  4491. exit;
  4492. end;
  4493. end;
  4494. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  4495. var
  4496. st: tsymtable;
  4497. enclosingdef: tdef;
  4498. begin
  4499. if typ=objectdef then
  4500. result:=tobjectdef(self).objextname^
  4501. else if assigned(typesym) then
  4502. result:=typesym.realname
  4503. { have to generate anonymous nested type in current unit/class/record }
  4504. else
  4505. internalerror(2011032601);
  4506. { in case of specializations, add some extras to prevent name conflicts
  4507. with nested classes }
  4508. if df_specialization in defoptions then
  4509. result:='$'+result+'$specialization$';
  4510. st:=owner;
  4511. while assigned(st) and
  4512. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  4513. begin
  4514. { nested classes are named as "OuterClass$InnerClass" }
  4515. enclosingdef:=tdef(st.defowner);
  4516. if enclosingdef.typ=procdef then
  4517. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  4518. else if enclosingdef.typ=objectdef then
  4519. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  4520. else if assigned(enclosingdef.typesym) then
  4521. result:=enclosingdef.typesym.realname+'$'+result
  4522. else
  4523. internalerror(2011060305);
  4524. st:=enclosingdef.owner;
  4525. end;
  4526. if with_package_name and
  4527. assigned(import_lib) then
  4528. result:=import_lib^+'/'+result;
  4529. end;
  4530. function tabstractrecorddef.contains_float_field: boolean;
  4531. var
  4532. i : longint;
  4533. begin
  4534. result:=true;
  4535. for i:=0 to symtable.symlist.count-1 do
  4536. begin
  4537. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4538. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4539. continue;
  4540. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4541. begin
  4542. if tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  4543. exit;
  4544. { search recursively }
  4545. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4546. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_float_field) then
  4547. exit;
  4548. end;
  4549. end;
  4550. result:=false;
  4551. end;
  4552. function tabstractrecorddef.contains_cross_aword_field: boolean;
  4553. var
  4554. i : longint;
  4555. foffset, fsize: aword;
  4556. begin
  4557. result:=true;
  4558. for i:=0 to symtable.symlist.count-1 do
  4559. begin
  4560. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4561. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4562. continue;
  4563. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4564. begin
  4565. if is_packed then
  4566. begin
  4567. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset;
  4568. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.packedbitsize;
  4569. end
  4570. else
  4571. begin
  4572. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset*8;
  4573. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.size*8;
  4574. end;
  4575. if (fsize>0) and ((foffset div (sizeof(aword)*8)) <> ((foffset+fsize-1) div (sizeof(aword)*8))) then
  4576. exit;
  4577. { search recursively }
  4578. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4579. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_cross_aword_field) then
  4580. exit;
  4581. end;
  4582. end;
  4583. result:=false;
  4584. end;
  4585. procedure tabstractrecorddef.apply_rtti_directive(dir: trtti_directive);
  4586. begin
  4587. { records don't support the inherit clause but shouldn't
  4588. give an error either if used (for Delphi compatibility),
  4589. so we silently enforce the clause as explicit. }
  4590. rtti.clause:=rtc_explicit;
  4591. rtti.options:=dir.options;
  4592. end;
  4593. function tabstractrecorddef.is_visible_for_rtti(option: trtti_option; vis: tvisibility): boolean;
  4594. begin
  4595. case vis of
  4596. vis_private,
  4597. vis_strictprivate: result:=rv_private in rtti.options[option];
  4598. vis_protected,
  4599. vis_strictprotected: result:=rv_protected in rtti.options[option];
  4600. vis_public: result:=rv_public in rtti.options[option];
  4601. vis_published: result:=rv_published in rtti.options[option];
  4602. otherwise
  4603. result:=false;
  4604. end;
  4605. end;
  4606. function tabstractrecorddef.rtti_visibilities_for_option(option: trtti_option): tvisibilities;
  4607. begin
  4608. result:=[];
  4609. if rv_private in rtti.options[option] then
  4610. begin
  4611. include(result,vis_private);
  4612. include(result,vis_strictprivate);
  4613. end;
  4614. if rv_protected in rtti.options[option] then
  4615. begin
  4616. include(result,vis_protected);
  4617. include(result,vis_strictprotected);
  4618. end;
  4619. if rv_public in rtti.options[option] then
  4620. include(result,vis_public);
  4621. if rv_published in rtti.options[option] then
  4622. include(result,vis_published);
  4623. end;
  4624. function tabstractrecorddef.has_extended_rtti: boolean;
  4625. begin
  4626. result := (rtti.options[ro_fields]<>[]) or
  4627. (rtti.options[ro_methods]<>[]) or
  4628. (rtti.options[ro_properties]<>[]);
  4629. end;
  4630. {$ifdef DEBUG_NODE_XML}
  4631. procedure tabstractrecorddef.XMLPrintDefData(var T: Text; Sym: TSym);
  4632. procedure WriteSymOptions(SourceSym: TSym);
  4633. var
  4634. i: TSymOption;
  4635. first: Boolean;
  4636. begin
  4637. First := True;
  4638. for i := Low(TSymOption) to High(TSymOption) do
  4639. if i in SourceSym.symoptions then
  4640. begin
  4641. if First then
  4642. begin
  4643. Write(T, '" symoptions="', i);
  4644. First := False;
  4645. end
  4646. else
  4647. Write(T, ',', i)
  4648. end;
  4649. end;
  4650. var
  4651. List: TFPHashObjectList;
  4652. i: Integer;
  4653. begin
  4654. WriteLn(T, PrintNodeIndention, '<size>', size, '</size>');
  4655. if (alignment = structalignment) and (alignment = aggregatealignment) then
  4656. begin
  4657. { Straightforward and simple }
  4658. WriteLn(T, PrintNodeIndention, '<alignment>', alignment, '</alignment>');
  4659. end
  4660. else
  4661. begin
  4662. WriteLn(T, PrintNodeIndention, '<alignment>');
  4663. printnodeindent;
  4664. WriteLn(T, PrintNodeIndention, '<basic>', alignment, '</basic>');
  4665. if (structalignment <> alignment) then
  4666. WriteLn(T, PrintNodeIndention, '<struct>', structalignment, '</struct>');
  4667. if (aggregatealignment <> alignment) and (aggregatealignment <> structalignment) then
  4668. WriteLn(T, PrintNodeIndention, '<aggregate>', aggregatealignment, '</aggregate>');
  4669. printnodeunindent;
  4670. WriteLn(T, PrintNodeIndention, '</alignment>');
  4671. end;
  4672. { List the fields }
  4673. List := Symtable.SymList;
  4674. for i := 0 to List.Count - 1 do
  4675. case TSym(List[i]).typ of
  4676. { staticvarsym,localvarsym,paravarsym,fieldvarsym,
  4677. typesym,procsym,unitsym,}
  4678. constsym:
  4679. with TConstSym(List[i]) do
  4680. begin
  4681. Write(T, PrintNodeIndention, '<const name="', RealName, '" pos="', fileinfo.line, ',', fileinfo.column);
  4682. WriteSymOptions(TSym(List[i]));
  4683. WriteLn(T, '">');
  4684. PrintNodeIndent;
  4685. XMLPrintConstData(T);
  4686. PrintNodeUnindent;
  4687. WriteLn(T, PrintNodeIndention, '</const>');
  4688. end;
  4689. {
  4690. errorsym,syssym,labelsym,absolutevarsym,propertysym,
  4691. macrosym,namespacesym,undefinedsym,programparasym
  4692. }
  4693. fieldvarsym:
  4694. with TFieldVarSym(List[i]) do
  4695. begin
  4696. Write(T, PrintNodeIndention, '<field name="', RealName, '" pos="', fileinfo.line, ',', fileinfo.column);
  4697. WriteSymOptions(TSym(List[i]));
  4698. WriteLn(T, '">');
  4699. PrintNodeIndent;
  4700. XMLPrintFieldData(T);
  4701. PrintNodeUnindent;
  4702. WriteLn(T, PrintNodeIndention, '</field>');
  4703. end;
  4704. else
  4705. ;
  4706. end;
  4707. end;
  4708. {$endif DEBUG_NODE_XML}
  4709. {***************************************************************************
  4710. trecorddef
  4711. ***************************************************************************}
  4712. constructor trecorddef.create(const n:string; p:TSymtable);
  4713. begin
  4714. inherited create(n,recorddef,true);
  4715. symtable:=p;
  4716. { we can own the symtable only if nobody else owns a copy so far }
  4717. if symtable.refcount=1 then
  4718. symtable.defowner:=self;
  4719. isunion:=false;
  4720. cloneddefderef.reset;
  4721. end;
  4722. constructor trecorddef.create_internal(const n: string; packrecords, recordalignmin: shortint; where: tsymtable);
  4723. var
  4724. name : string;
  4725. pname : pshortstring;
  4726. oldsymtablestack: tsymtablestack;
  4727. ts: ttypesym;
  4728. begin
  4729. { construct name }
  4730. if n<>'' then
  4731. pname:=@n
  4732. else
  4733. begin
  4734. init_defid;
  4735. name:='$InternalRec'+unique_id_str;
  4736. pname:=@name;
  4737. end;
  4738. oldsymtablestack:=symtablestack;
  4739. { do not simply push/pop current_module.localsymtable, because
  4740. that can have side-effects (e.g., it removes helpers) }
  4741. symtablestack:=nil;
  4742. symtable:=trecordsymtable.create(pname^,packrecords,recordalignmin);
  4743. symtable.defowner:=self;
  4744. isunion:=false;
  4745. inherited create(pname^,recorddef,true);
  4746. where.insertdef(self);
  4747. { if we specified a name, then we'll probably want to look up the
  4748. type again by name too -> create typesym }
  4749. if n<>'' then
  4750. begin
  4751. ts:=ctypesym.create(n,self);
  4752. include(ts.symoptions,sp_internal);
  4753. { avoid hints about unused types (these may only be used for
  4754. typed constant data) }
  4755. ts.increfcount;
  4756. where.insertsym(ts);
  4757. end;
  4758. symtablestack:=oldsymtablestack;
  4759. { don't create RTTI for internal types, these are not exported }
  4760. defstates:=defstates+[ds_rtti_table_written,ds_init_table_written];
  4761. include(defoptions,df_internal);
  4762. end;
  4763. constructor trecorddef.create_global_internal(const n: string; packrecords, recordalignmin: shortint);
  4764. var
  4765. where : tsymtable;
  4766. begin
  4767. where:=current_module.localsymtable;
  4768. if not assigned(where) then
  4769. where:=current_module.globalsymtable;
  4770. create_internal(n,packrecords,recordalignmin,where);
  4771. end;
  4772. function trecorddef.add_field_by_def(const optionalname: TIDString; def: tdef): tsym;
  4773. var
  4774. sym: tfieldvarsym;
  4775. name: TIDString;
  4776. pname: ^TIDString;
  4777. begin
  4778. if optionalname='' then
  4779. begin
  4780. name:='$f'+tostr(trecordsymtable(symtable).symlist.count);
  4781. pname:=@name
  4782. end
  4783. else
  4784. pname:=@optionalname;
  4785. sym:=cfieldvarsym.create(pname^,vs_value,def,[]);
  4786. symtable.insertsym(sym);
  4787. trecordsymtable(symtable).addfield(sym,vis_hidden);
  4788. result:=sym;
  4789. end;
  4790. procedure trecorddef.add_fields_from_deflist(fieldtypes: tfplist);
  4791. var
  4792. i: longint;
  4793. begin
  4794. for i:=0 to fieldtypes.count-1 do
  4795. add_field_by_def('',tdef(fieldtypes[i]));
  4796. end;
  4797. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  4798. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  4799. var
  4800. i,j : longint;
  4801. begin
  4802. if ppufile.getbyte=1 then
  4803. begin
  4804. new(variantrecdesc);
  4805. ppufile.getderef(variantrecdesc^.variantselectorderef);
  4806. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  4807. for i:=0 to high(variantrecdesc^.branches) do
  4808. begin
  4809. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  4810. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4811. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  4812. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4813. end;
  4814. end
  4815. else
  4816. variantrecdesc:=nil;
  4817. end;
  4818. begin
  4819. inherited ppuload(recorddef,ppufile);
  4820. if df_copied_def in defoptions then
  4821. begin
  4822. ppufile.getderef(cloneddefderef);
  4823. ppuload_platform(ppufile);
  4824. end
  4825. else
  4826. begin
  4827. symtable:=trecordsymtable.create(objrealname^,0,0);
  4828. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  4829. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  4830. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  4831. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  4832. trecordsymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  4833. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  4834. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  4835. ppufile.getset(tppuset1(trecordsymtable(symtable).managementoperators));
  4836. { position of ppuload_platform call must correspond
  4837. to position of writeentry in ppuwrite method }
  4838. ppuload_platform(ppufile);
  4839. trecordsymtable(symtable).ppuload(ppufile);
  4840. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4841. but because iso mode supports no units, there is no need to store the variantrecdesc
  4842. in the ppu
  4843. }
  4844. // readvariantrecdesc(variantrecdesc);
  4845. { requires usefieldalignment to be set }
  4846. symtable.defowner:=self;
  4847. end;
  4848. isunion:=false;
  4849. end;
  4850. destructor trecorddef.destroy;
  4851. procedure free_variantrecdesc(var variantrecdesc : pvariantrecdesc);
  4852. var
  4853. i : longint;
  4854. begin
  4855. while assigned(variantrecdesc) do
  4856. begin
  4857. for i:=0 to high(variantrecdesc^.branches) do
  4858. begin
  4859. free_variantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4860. SetLength(variantrecdesc^.branches[i].values,0);
  4861. end;
  4862. SetLength(variantrecdesc^.branches,0);
  4863. dispose(variantrecdesc);
  4864. variantrecdesc:=nil;
  4865. end;
  4866. end;
  4867. begin
  4868. if assigned(variantrecdesc) then
  4869. free_variantrecdesc(variantrecdesc);
  4870. if assigned(symtable) then
  4871. begin
  4872. symtable.free;
  4873. symtable:=nil;
  4874. end;
  4875. inherited destroy;
  4876. end;
  4877. function trecorddef.getcopy : tstoreddef;
  4878. begin
  4879. result:=crecorddef.create(objrealname^,symtable.getcopy);
  4880. trecorddef(result).isunion:=isunion;
  4881. include(trecorddef(result).defoptions,df_copied_def);
  4882. if assigned(tcinitcode) then
  4883. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  4884. if assigned(import_lib) then
  4885. trecorddef(result).import_lib:=stringdup(import_lib^);
  4886. end;
  4887. function trecorddef.needs_inittable : boolean;
  4888. begin
  4889. { each record with managed field or with any management operator needs
  4890. init table }
  4891. needs_inittable:=(trecordsymtable(symtable).managementoperators<>[]) or
  4892. trecordsymtable(symtable).needs_init_final
  4893. end;
  4894. function trecorddef.needs_separate_initrtti : boolean;
  4895. begin
  4896. result:=true;
  4897. end;
  4898. function trecorddef.has_non_trivial_init_child(check_parent:boolean):boolean;
  4899. begin
  4900. result:=trecordsymtable(symtable).has_non_trivial_init;
  4901. end;
  4902. procedure trecorddef.buildderef;
  4903. begin
  4904. inherited buildderef;
  4905. if df_copied_def in defoptions then
  4906. cloneddefderef.build(symtable.defowner)
  4907. else
  4908. tstoredsymtable(symtable).buildderef;
  4909. end;
  4910. procedure trecorddef.deref;
  4911. begin
  4912. inherited deref;
  4913. { now dereference the definitions }
  4914. if df_copied_def in defoptions then
  4915. begin
  4916. cloneddef:=trecorddef(cloneddefderef.resolve);
  4917. symtable:=cloneddef.symtable.getcopy;
  4918. end
  4919. else
  4920. tstoredsymtable(symtable).deref(false);
  4921. { internal types, only load from the system unit }
  4922. if assigned(owner) and
  4923. assigned(owner.name) and
  4924. (owner.name^='SYSTEM') then
  4925. begin
  4926. { TGUID }
  4927. if not assigned(rec_tguid) and
  4928. (upper(typename)='TGUID') then
  4929. rec_tguid:=self
  4930. { JMP_BUF }
  4931. else if not assigned(rec_jmp_buf) and
  4932. (upper(typename)='JMP_BUF') then
  4933. rec_jmp_buf:=self
  4934. else if not assigned(rec_exceptaddr) and
  4935. (upper(typename)='TEXCEPTADDR') then
  4936. rec_exceptaddr:=self;
  4937. end;
  4938. end;
  4939. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  4940. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  4941. var
  4942. i,j : longint;
  4943. begin
  4944. if assigned(variantrecdesc) then
  4945. begin
  4946. ppufile.putbyte(1);
  4947. ppufile.putderef(variantrecdesc^.variantselectorderef);
  4948. ppufile.putasizeint(length(variantrecdesc^.branches));
  4949. for i:=0 to high(variantrecdesc^.branches) do
  4950. begin
  4951. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  4952. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4953. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  4954. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4955. end;
  4956. end
  4957. else
  4958. ppufile.putbyte(0);
  4959. end;
  4960. begin
  4961. inherited ppuwrite(ppufile);
  4962. if df_copied_def in defoptions then
  4963. ppufile.putderef(cloneddefderef)
  4964. else
  4965. begin
  4966. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  4967. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  4968. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  4969. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  4970. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignmin));
  4971. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  4972. ppufile.putword(trecordsymtable(symtable).paddingsize);
  4973. ppufile.putset(tppuset1(trecordsymtable(symtable).managementoperators));
  4974. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4975. but because iso mode supports no units, there is no need to store the variantrecdesc
  4976. in the ppu
  4977. }
  4978. // writevariantrecdesc(variantrecdesc);
  4979. end;
  4980. writeentry(ppufile,ibrecorddef);
  4981. if not(df_copied_def in defoptions) then
  4982. trecordsymtable(symtable).ppuwrite(ppufile);
  4983. end;
  4984. function trecorddef.size:asizeint;
  4985. begin
  4986. result:=trecordsymtable(symtable).datasize;
  4987. end;
  4988. function trecorddef.alignment:shortint;
  4989. begin
  4990. alignment:=trecordsymtable(symtable).recordalignment;
  4991. end;
  4992. function trecorddef.padalignment:shortint;
  4993. begin
  4994. padalignment := trecordsymtable(symtable).padalignment;
  4995. end;
  4996. function trecorddef.GetTypeName : string;
  4997. begin
  4998. GetTypeName:='<record type>'
  4999. end;
  5000. {$ifdef DEBUG_NODE_XML}
  5001. function TRecordDef.XMLPrintType: ansistring;
  5002. begin
  5003. Result := '&lt;record&gt;';
  5004. end;
  5005. {$endif DEBUG_NODE_XML}
  5006. {***************************************************************************
  5007. TABSTRACTPROCDEF
  5008. ***************************************************************************}
  5009. constructor tabstractprocdef.create(dt:tdeftyp;level:byte;doregister:boolean);
  5010. begin
  5011. inherited create(dt,doregister);
  5012. parast:=tparasymtable.create(self,level);
  5013. paras:=nil;
  5014. minparacount:=0;
  5015. maxparacount:=0;
  5016. proctypeoption:=potype_none;
  5017. proccalloption:=pocall_none;
  5018. procoptions:=[];
  5019. returndef:=voidtype;
  5020. returndefderef.reset;
  5021. savesize:=sizeof(pint);
  5022. callerargareasize:=0;
  5023. calleeargareasize:=0;
  5024. has_paraloc_info:=callnoside;
  5025. funcretloc[callerside].init;
  5026. funcretloc[calleeside].init;
  5027. check_mark_as_nested;
  5028. end;
  5029. destructor tabstractprocdef.destroy;
  5030. begin
  5031. if assigned(paras) then
  5032. begin
  5033. {$ifdef MEMDEBUG}
  5034. memprocpara.start;
  5035. {$endif MEMDEBUG}
  5036. paras.free;
  5037. paras:=nil;
  5038. {$ifdef MEMDEBUG}
  5039. memprocpara.stop;
  5040. {$endif MEMDEBUG}
  5041. end;
  5042. if assigned(parast) then
  5043. begin
  5044. {$ifdef MEMDEBUG}
  5045. memprocparast.start;
  5046. {$endif MEMDEBUG}
  5047. parast.free;
  5048. parast:=nil;
  5049. {$ifdef MEMDEBUG}
  5050. memprocparast.stop;
  5051. {$endif MEMDEBUG}
  5052. end;
  5053. funcretloc[callerside].done;
  5054. funcretloc[calleeside].done;
  5055. inherited destroy;
  5056. end;
  5057. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  5058. begin
  5059. if (tsym(p).typ<>paravarsym) then
  5060. exit;
  5061. inc(plongint(arg)^);
  5062. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  5063. begin
  5064. if not assigned(tparavarsym(p).defaultconstsym) then
  5065. inc(minparacount);
  5066. inc(maxparacount);
  5067. end;
  5068. end;
  5069. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  5070. begin
  5071. if (tsym(p).typ<>paravarsym) then
  5072. exit;
  5073. paras.add(p);
  5074. end;
  5075. procedure tabstractprocdef.calcparas;
  5076. var
  5077. paracount : longint;
  5078. begin
  5079. { This can already be assigned when
  5080. we need to reresolve this unit (PFV) }
  5081. if assigned(paras) then
  5082. paras.free;
  5083. paras:=tparalist.create(false);
  5084. paracount:=0;
  5085. minparacount:=0;
  5086. maxparacount:=0;
  5087. parast.SymList.ForEachCall(@count_para,@paracount);
  5088. paras.capacity:=paracount;
  5089. { Insert parameters in table }
  5090. parast.SymList.ForEachCall(@insert_para,nil);
  5091. { Order parameters }
  5092. paras.sortparas;
  5093. end;
  5094. function tabstractprocdef.mangledprocparanames(oldlen : longint) : string;
  5095. var
  5096. hash : qword;
  5097. hp : TParavarsym;
  5098. hs : TSymStr;
  5099. newlen,
  5100. i : integer;
  5101. begin
  5102. result:='';
  5103. hp:=nil;
  5104. { add parameter types }
  5105. for i:=0 to paras.count-1 do
  5106. begin
  5107. hp:=tparavarsym(paras[i]);
  5108. if not(vo_is_hidden_para in hp.varoptions) then
  5109. result:=result+'$'+hp.vardef.mangledparaname;
  5110. end;
  5111. { add resultdef, add $$ as separator to make it unique from a
  5112. parameter separator }
  5113. if not is_void(returndef) then
  5114. result:=result+'$$'+returndef.mangledparaname;
  5115. newlen:=length(result)+oldlen;
  5116. { Replace with hash if the parameter line is very long }
  5117. if (newlen-oldlen>12) and
  5118. ((newlen>100) or (newlen-oldlen>64)) then
  5119. begin
  5120. hash:=InitFnv64;
  5121. for i:=0 to paras.count-1 do
  5122. begin
  5123. hp:=tparavarsym(paras[i]);
  5124. if not(vo_is_hidden_para in hp.varoptions) then
  5125. begin
  5126. hs:=hp.vardef.mangledparaname;
  5127. hash:=UpdateFnv64(hash,hs[1],length(hs));
  5128. end;
  5129. end;
  5130. if not is_void(returndef) then
  5131. begin
  5132. { add a little prefix so that x(integer; integer) is different from x(integer):integer }
  5133. hs:='$$'+returndef.mangledparaname;
  5134. hash:=UpdateFnv64(hash,hs[1],length(hs));
  5135. end;
  5136. result:='$h'+Base64Mangle(hash);
  5137. end;
  5138. end;
  5139. procedure tabstractprocdef.buildderef;
  5140. begin
  5141. { released procdef? }
  5142. if not assigned(parast) then
  5143. exit;
  5144. inherited buildderef;
  5145. returndefderef.build(returndef);
  5146. if po_explicitparaloc in procoptions then
  5147. funcretloc[callerside].buildderef;
  5148. { parast }
  5149. tparasymtable(parast).buildderef;
  5150. end;
  5151. procedure tabstractprocdef.deref;
  5152. begin
  5153. inherited deref;
  5154. returndef:=tdef(returndefderef.resolve);
  5155. if po_explicitparaloc in procoptions then
  5156. begin
  5157. funcretloc[callerside].deref;
  5158. has_paraloc_info:=callerside;
  5159. end
  5160. else
  5161. begin
  5162. { deref is called after loading from a ppu, but also after another
  5163. unit has been reloaded/recompiled and all references must be
  5164. re-resolved. Since the funcretloc contains a reference to a tdef,
  5165. reset it so that we won't try to access the stale def }
  5166. funcretloc[callerside].init;
  5167. has_paraloc_info:=callnoside;
  5168. end;
  5169. { parast }
  5170. tparasymtable(parast).deref(false);
  5171. { recalculated parameters }
  5172. calcparas;
  5173. end;
  5174. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  5175. begin
  5176. inherited ppuload(dt,ppufile);
  5177. parast:=nil;
  5178. Paras:=nil;
  5179. minparacount:=0;
  5180. maxparacount:=0;
  5181. ppufile.getderef(returndefderef);
  5182. proctypeoption:=tproctypeoption(ppufile.getbyte);
  5183. proccalloption:=tproccalloption(ppufile.getbyte);
  5184. ppufile.getset(tppuset8(procoptions));
  5185. funcretloc[callerside].init;
  5186. if po_explicitparaloc in procoptions then
  5187. funcretloc[callerside].ppuload(ppufile);
  5188. savesize:=sizeof(pint);
  5189. if (po_explicitparaloc in procoptions) then
  5190. has_paraloc_info:=callerside;
  5191. end;
  5192. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  5193. var
  5194. oldintfcrc : boolean;
  5195. begin
  5196. { released procdef? }
  5197. if not assigned(parast) then
  5198. exit;
  5199. inherited ppuwrite(ppufile);
  5200. ppufile.putderef(returndefderef);
  5201. oldintfcrc:=ppufile.do_interface_crc;
  5202. ppufile.do_interface_crc:=false;
  5203. ppufile.putbyte(ord(proctypeoption));
  5204. ppufile.putbyte(ord(proccalloption));
  5205. ppufile.putset(tppuset8(procoptions));
  5206. ppufile.do_interface_crc:=oldintfcrc;
  5207. if (po_explicitparaloc in procoptions) then
  5208. funcretloc[callerside].ppuwrite(ppufile);
  5209. end;
  5210. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  5211. var
  5212. hs,s : ansistring;
  5213. hp : TParavarsym;
  5214. hpc : tconstsym;
  5215. first : boolean;
  5216. i,j : integer;
  5217. begin
  5218. s:='';
  5219. first:=true;
  5220. for i:=0 to paras.count-1 do
  5221. begin
  5222. hp:=tparavarsym(paras[i]);
  5223. if not(vo_is_hidden_para in hp.varoptions) or
  5224. (pno_showhidden in pno) then
  5225. begin
  5226. if first then
  5227. begin
  5228. s:=s+'(';
  5229. first:=false;
  5230. end
  5231. else
  5232. s:=s+';';
  5233. if vo_is_hidden_para in hp.varoptions then
  5234. s:=s+'<';
  5235. case hp.varspez of
  5236. vs_var :
  5237. s:=s+'var ';
  5238. vs_const :
  5239. s:=s+'const ';
  5240. vs_out :
  5241. s:=s+'out ';
  5242. vs_constref :
  5243. s:=s+'constref ';
  5244. else
  5245. ;
  5246. end;
  5247. if (pno_paranames in pno) then
  5248. s:=s+hp.realname+':';
  5249. if hp.univpara then
  5250. s:=s+'univ ';
  5251. if assigned(hp.vardef.typesym) then
  5252. begin
  5253. hs:=hp.vardef.typesym.realname;
  5254. if hs[1]<>'$' then
  5255. s:=s+hp.vardef.OwnerHierarchyName+hs
  5256. else
  5257. s:=s+hp.vardef.GetTypeName;
  5258. end
  5259. else
  5260. s:=s+hp.vardef.GetTypeName;
  5261. { default value }
  5262. if assigned(hp.defaultconstsym) then
  5263. begin
  5264. hpc:=tconstsym(hp.defaultconstsym);
  5265. hs:='';
  5266. case hpc.consttyp of
  5267. constwresourcestring,
  5268. constwstring:
  5269. begin
  5270. if hpc.value.valuews.len>0 then
  5271. begin
  5272. setlength(hs,hpc.value.valuews.len);
  5273. for j:=0 to hpc.value.valuews.len-1 do
  5274. begin
  5275. if (ord(hpc.value.valuews.data[j])<127) and
  5276. not(byte(hpc.value.valuews.data[j]) in [0,10,13]) then
  5277. hs[j+1]:=char(hpc.value.valuews.data[j])
  5278. else
  5279. hs[j+1]:='.';
  5280. end;
  5281. end;
  5282. end;
  5283. conststring,
  5284. constresourcestring :
  5285. begin
  5286. if hpc.value.len>0 then
  5287. begin
  5288. setLength(hs,hpc.value.len);
  5289. { don't write past the end of hs if the constant
  5290. is > 255 chars }
  5291. move(hpc.value.valueptr^,hs[1],length(hs));
  5292. { make sure that constant strings with newline chars
  5293. don't create a linebreak in the assembler code,
  5294. since comments are line-based. Also remove nulls
  5295. because the comments are written as a pchar. }
  5296. ReplaceCase(hs,#0,'.');
  5297. ReplaceCase(hs,#10,'.');
  5298. ReplaceCase(hs,#13,'.');
  5299. end;
  5300. end;
  5301. constreal :
  5302. str(pbestreal(hpc.value.valueptr)^,hs);
  5303. constpointer :
  5304. hs:=tostr(hpc.value.valueordptr);
  5305. constord :
  5306. begin
  5307. if is_boolean(hpc.constdef) then
  5308. begin
  5309. if hpc.value.valueord<>0 then
  5310. hs:='TRUE'
  5311. else
  5312. hs:='FALSE';
  5313. end
  5314. else
  5315. hs:=tostr(hpc.value.valueord);
  5316. end;
  5317. constnil :
  5318. hs:='nil';
  5319. constset :
  5320. hs:='<set>';
  5321. constguid:
  5322. hs:=guid2string(pguid(hpc.value.valueptr)^);
  5323. constnone:
  5324. internalerror(2019050704);
  5325. end;
  5326. if hs<>'' then
  5327. s:=s+'=`'+hs+'`';
  5328. end;
  5329. if vo_is_hidden_para in hp.varoptions then
  5330. s:=s+'>';
  5331. end;
  5332. end;
  5333. if not first then
  5334. s:=s+')';
  5335. if (po_varargs in procoptions) then
  5336. s:=s+';VarArgs';
  5337. typename_paras:=s;
  5338. end;
  5339. function tabstractprocdef.is_methodpointer:boolean;
  5340. begin
  5341. result:=false;
  5342. end;
  5343. function tabstractprocdef.is_addressonly:boolean;
  5344. begin
  5345. result:=true;
  5346. end;
  5347. function tabstractprocdef.no_self_node: boolean;
  5348. begin
  5349. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  5350. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  5351. end;
  5352. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  5353. var
  5354. j, nestinglevel: longint;
  5355. pvs, npvs: tparavarsym;
  5356. begin
  5357. nestinglevel:=parast.symtablelevel;
  5358. if newtyp=procdef then
  5359. begin
  5360. if (copytyp<>pc_bareproc) then
  5361. result:=cprocdef.create(nestinglevel,doregister)
  5362. else
  5363. result:=cprocdef.create(normal_function_level,doregister);
  5364. tprocdef(result).visibility:=vis_public;
  5365. end
  5366. else
  5367. begin
  5368. result:=cprocvardef.create(nestinglevel,true);
  5369. end;
  5370. tabstractprocdef(result).returndef:=returndef;
  5371. tabstractprocdef(result).returndefderef:=returndefderef;
  5372. pvs:=nil;
  5373. npvs:=nil;
  5374. if copytyp<>pc_normal_no_paras then
  5375. begin
  5376. for j:=0 to parast.symlist.count-1 do
  5377. begin
  5378. case tsym(parast.symlist[j]).typ of
  5379. paravarsym:
  5380. begin
  5381. pvs:=tparavarsym(parast.symlist[j]);
  5382. { in case of bare proc, don't copy self, vmt or framepointer
  5383. parameters }
  5384. if (copytyp in [pc_bareproc,pc_normal_no_hidden]) and
  5385. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result,vo_is_funcret,vo_is_high_para]*pvs.varoptions)<>[]) then
  5386. continue;
  5387. if paraprefix='' then
  5388. npvs:=cparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  5389. pvs.vardef,pvs.varoptions)
  5390. else if not(vo_is_high_para in pvs.varoptions) then
  5391. npvs:=cparavarsym.create(paraprefix+pvs.realname,pvs.paranr,pvs.varspez,
  5392. pvs.vardef,pvs.varoptions)
  5393. else
  5394. npvs:=cparavarsym.create('$high'+paraprefix+copy(pvs.name,5,length(pvs.name)),pvs.paranr,pvs.varspez,
  5395. pvs.vardef,pvs.varoptions);
  5396. npvs.defaultconstsym:=pvs.defaultconstsym;
  5397. tabstractprocdef(result).parast.insertsym(npvs);
  5398. end;
  5399. constsym:
  5400. begin
  5401. // ignore, reuse original constym. Should also be duplicated
  5402. // be safe though
  5403. end;
  5404. symconst.typesym:
  5405. begin
  5406. // reuse original, part of generic declaration
  5407. end
  5408. else
  5409. internalerror(201160604);
  5410. end;
  5411. end;
  5412. end;
  5413. tabstractprocdef(result).savesize:=savesize;
  5414. if (typ<>procvardef) and
  5415. (newtyp=procvardef) then
  5416. begin
  5417. { procvars can't be (class)constructures/destructors etc }
  5418. if proctypeoption=potype_constructor then
  5419. begin
  5420. tabstractprocdef(result).returndef:=tdef(owner.defowner);
  5421. if not(is_implicit_pointer_object_type(returndef) or
  5422. (returndef.typ<>objectdef)) then
  5423. tabstractprocdef(result).returndef:=cpointerdef.getreusable(tabstractprocdef(result).returndef);
  5424. tabstractprocdef(result).proctypeoption:=potype_function;
  5425. end
  5426. else if is_void(returndef) then
  5427. tabstractprocdef(result).proctypeoption:=potype_procedure
  5428. else
  5429. tabstractprocdef(result).proctypeoption:=potype_function;
  5430. end
  5431. else
  5432. tabstractprocdef(result).proctypeoption:=proctypeoption;
  5433. tabstractprocdef(result).proccalloption:=proccalloption;
  5434. tabstractprocdef(result).procoptions:=procoptions;
  5435. if (copytyp=pc_bareproc) then
  5436. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  5437. if newtyp=procvardef then
  5438. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  5439. if copytyp=pc_address_only then
  5440. include(tabstractprocdef(result).procoptions,po_addressonly);
  5441. tabstractprocdef(result).callerargareasize:=callerargareasize;
  5442. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  5443. tabstractprocdef(result).maxparacount:=maxparacount;
  5444. tabstractprocdef(result).minparacount:=minparacount;
  5445. if po_explicitparaloc in procoptions then
  5446. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  5447. { recalculate parameter info }
  5448. tabstractprocdef(result).has_paraloc_info:=callnoside;
  5449. {$ifdef m68k}
  5450. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  5451. {$endif}
  5452. if (typ=procdef) and
  5453. (newtyp=procvardef) and
  5454. (owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  5455. include(tprocvardef(result).procoptions,po_methodpointer);
  5456. end;
  5457. function tabstractprocdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  5458. begin
  5459. result:=is_addressonly;
  5460. end;
  5461. procedure tabstractprocdef.check_mark_as_nested;
  5462. begin
  5463. { nested procvars require that nested functions use the Delphi-style
  5464. nested procedure calling convention }
  5465. if (parast.symtablelevel>normal_function_level) and
  5466. (m_nested_procvars in current_settings.modeswitches) then
  5467. include(procoptions,po_delphi_nested_cc);
  5468. end;
  5469. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  5470. begin
  5471. if (side in [callerside,callbothsides]) and
  5472. not(has_paraloc_info in [callerside,callbothsides]) then
  5473. begin
  5474. if not is_c_variadic(self) then
  5475. callerargareasize:=paramanager.create_paraloc_info(self,callerside)
  5476. else
  5477. callerargareasize:=paramanager.create_varargs_paraloc_info(self,callerside,nil);
  5478. if has_paraloc_info in [calleeside,callbothsides] then
  5479. has_paraloc_info:=callbothsides
  5480. else
  5481. has_paraloc_info:=callerside;
  5482. end;
  5483. if (side in [calleeside,callbothsides]) and
  5484. not(has_paraloc_info in [calleeside,callbothsides]) then
  5485. begin
  5486. if not is_c_variadic(self) then
  5487. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside)
  5488. else
  5489. callerargareasize:=paramanager.create_varargs_paraloc_info(self,calleeside,nil);
  5490. if has_paraloc_info in [callerside,callbothsides] then
  5491. has_paraloc_info:=callbothsides
  5492. else
  5493. has_paraloc_info:=calleeside;
  5494. end;
  5495. end;
  5496. procedure tabstractprocdef.done_paraloc_info(side: tcallercallee);
  5497. var
  5498. i: longint;
  5499. begin
  5500. if (side in [callerside,callbothsides]) and
  5501. (has_paraloc_info in [callerside,callbothsides]) then
  5502. begin
  5503. funcretloc[callerside].done;
  5504. for i:=0 to paras.count-1 do
  5505. tparavarsym(paras[i]).paraloc[callerside].done;
  5506. if has_paraloc_info=callerside then
  5507. has_paraloc_info:=callnoside
  5508. else
  5509. has_paraloc_info:=calleeside;
  5510. end;
  5511. if (side in [calleeside,callbothsides]) and
  5512. (has_paraloc_info in [calleeside,callbothsides]) then
  5513. begin
  5514. funcretloc[calleeside].done;
  5515. for i:=0 to paras.count-1 do
  5516. tparavarsym(paras[i]).paraloc[calleeside].done;
  5517. if has_paraloc_info=calleeside then
  5518. has_paraloc_info:=callnoside
  5519. else
  5520. has_paraloc_info:=callerside;
  5521. end;
  5522. end;
  5523. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  5524. var
  5525. p: tparavarsym;
  5526. ploc: PCGParalocation;
  5527. i: longint;
  5528. begin
  5529. result:=false;
  5530. init_paraloc_info(side);
  5531. for i:=0 to parast.SymList.Count-1 do
  5532. if tsym(parast.SymList[i]).typ=paravarsym then
  5533. begin
  5534. p:=tparavarsym(parast.SymList[i]);
  5535. if not p.is_used then
  5536. continue;
  5537. { check if no parameter is located on the stack }
  5538. if (is_open_array(p.vardef) or
  5539. is_array_of_const(p.vardef)) and (p.varspez=vs_value) then
  5540. begin
  5541. result:=true;
  5542. exit;
  5543. end;
  5544. ploc:=p.paraloc[side].location;
  5545. while assigned(ploc) do
  5546. begin
  5547. if (ploc^.loc=LOC_REFERENCE) then
  5548. begin
  5549. result:=true;
  5550. exit
  5551. end;
  5552. ploc:=ploc^.next;
  5553. end;
  5554. end;
  5555. end;
  5556. function tabstractprocdef.is_pushleftright: boolean;
  5557. begin
  5558. result:=false;
  5559. end;
  5560. function tabstractprocdef.address_type: tdef;
  5561. begin
  5562. result:=voidcodepointertype;
  5563. end;
  5564. function tabstractprocdef.ofs_address_type:tdef;
  5565. begin
  5566. result:=address_type;
  5567. end;
  5568. procedure tabstractprocdef.declared_far;
  5569. begin
  5570. Message1(parser_w_proc_directive_ignored,'FAR');
  5571. end;
  5572. procedure tabstractprocdef.declared_near;
  5573. begin
  5574. Message1(parser_w_proc_directive_ignored,'NEAR');
  5575. end;
  5576. function tabstractprocdef.generate_safecall_wrapper: boolean;
  5577. begin
  5578. {$ifdef SUPPORT_SAFECALL}
  5579. result:=
  5580. (proccalloption=pocall_safecall) and
  5581. not(po_assembler in procoptions) and
  5582. (tf_safecall_exceptions in target_info.flags);
  5583. {$else SUPPORT_SAFECALL}
  5584. result:=false;
  5585. {$endif}
  5586. end;
  5587. function tabstractprocdef.is_generic_param(def:tdef): boolean;
  5588. begin
  5589. if def.typ=undefineddef then
  5590. result:=def.owner=self.parast
  5591. else if def.typ=objectdef then
  5592. result:=(def.owner=self.parast) and (tstoreddef(def).genconstraintdata<>nil)
  5593. else
  5594. result:=false;
  5595. end;
  5596. function tabstractprocdef.wpo_may_create_instance(optionalmethodpointer: tnode): boolean;
  5597. begin
  5598. result:=
  5599. (proctypeoption=potype_constructor) or
  5600. ((typ=procdef) and
  5601. ((not assigned(optionalmethodpointer) and
  5602. is_class(tdef(owner.defowner))) or
  5603. (assigned(optionalmethodpointer) and
  5604. ((optionalmethodpointer.resultdef.typ=classrefdef) or
  5605. (optionalmethodpointer.nodetype=typen)))) and
  5606. (tprocdef(self).procsym.Name='NEWINSTANCE'))
  5607. end;
  5608. {***************************************************************************
  5609. TPROCDEF
  5610. ***************************************************************************}
  5611. function tprocdef.getparentfpsym: tsym;
  5612. begin
  5613. if not assigned(_parentfpsym) then
  5614. begin
  5615. _parentfpsym:=tsym(parast.Find('parentfp'));
  5616. if not assigned(_parentfpsym) then
  5617. internalerror(200309281);
  5618. end;
  5619. result:=_parentfpsym;
  5620. end;
  5621. function tprocdef.Getis_implemented: boolean;
  5622. begin
  5623. result:=not assigned(implprocdefinfo) or implprocdefinfo^.is_implemented;
  5624. end;
  5625. procedure tprocdef.Setis_implemented(AValue: boolean);
  5626. begin
  5627. if not assigned(implprocdefinfo) then
  5628. internalerror(2020062101);
  5629. implprocdefinfo^.is_implemented:=AValue;
  5630. end;
  5631. function tprocdef.getwas_anonymous:boolean;
  5632. begin
  5633. result:=assigned(implprocdefinfo) and implprocdefinfo^.was_anonymous;
  5634. end;
  5635. procedure tprocdef.setwas_anonymous(avalue:boolean);
  5636. begin
  5637. if not assigned(implprocdefinfo) then
  5638. internalerror(2022020502);
  5639. implprocdefinfo^.was_anonymous:=avalue;
  5640. end;
  5641. function tprocdef.gethas_capturer:boolean;
  5642. begin
  5643. result:=assigned(implprocdefinfo) and implprocdefinfo^.has_capturer;
  5644. end;
  5645. procedure tprocdef.sethas_capturer(avalue:boolean);
  5646. begin
  5647. if not assigned(implprocdefinfo) then
  5648. internalerror(2022020503);
  5649. implprocdefinfo^.has_capturer:=avalue;
  5650. end;
  5651. function tprocdef.Getcapturedsyms:tfplist;
  5652. begin
  5653. if not assigned(implprocdefinfo) then
  5654. result:=nil
  5655. else
  5656. result:=implprocdefinfo^.capturedsyms;
  5657. end;
  5658. function tprocdef.store_localst: boolean;
  5659. begin
  5660. result:=has_inlininginfo or (df_generic in defoptions);
  5661. end;
  5662. function tprocdef.GetResultName: PShortString;
  5663. begin
  5664. if not assigned(implprocdefinfo) then
  5665. internalerror(2014010301);
  5666. result:=implprocdefinfo^.resultname;
  5667. end;
  5668. procedure tprocdef.SetResultName(AValue: PShortString);
  5669. begin
  5670. if not assigned(implprocdefinfo) then
  5671. internalerror(2014010302);
  5672. implprocdefinfo^.resultname:=AValue;
  5673. end;
  5674. function tprocdef.GetParentFPInitBlock: tnode;
  5675. begin
  5676. if not assigned(implprocdefinfo) then
  5677. internalerror(2014010303);
  5678. result:=implprocdefinfo^.parentfpinitblock;
  5679. end;
  5680. function tprocdef.GetParentFPStruct: tsym;
  5681. begin
  5682. if not assigned(implprocdefinfo) then
  5683. internalerror(2014010304);
  5684. result:=implprocdefinfo^.parentfpstruct;
  5685. end;
  5686. function tprocdef.GetParentFPStructPtrType: tdef;
  5687. begin
  5688. if not assigned(implprocdefinfo) then
  5689. internalerror(2014010305);
  5690. result:=implprocdefinfo^.parentfpstructptrtype;
  5691. end;
  5692. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  5693. begin
  5694. if not assigned(implprocdefinfo) then
  5695. internalerror(2014010306);
  5696. implprocdefinfo^.parentfpinitblock:=AValue;
  5697. end;
  5698. function tprocdef.Getprocendtai: tai;
  5699. begin
  5700. if not assigned(implprocdefinfo) then
  5701. internalerror(2014010307);
  5702. result:=implprocdefinfo^.procendtai;
  5703. end;
  5704. function tprocdef.Getprocstarttai: tai;
  5705. begin
  5706. if not assigned(implprocdefinfo) then
  5707. internalerror(2014010308);
  5708. result:=implprocdefinfo^.procstarttai;
  5709. end;
  5710. procedure tprocdef.Setprocendtai(AValue: tai);
  5711. begin
  5712. if not assigned(implprocdefinfo) then
  5713. internalerror(2014010309);
  5714. implprocdefinfo^.procendtai:=AValue;
  5715. end;
  5716. function tprocdef.Getskpara: pointer;
  5717. begin
  5718. if not assigned(implprocdefinfo) then
  5719. internalerror(2014010310);
  5720. result:=implprocdefinfo^.skpara;
  5721. end;
  5722. procedure tprocdef.Setskpara(AValue: pointer);
  5723. begin
  5724. if not assigned(implprocdefinfo) then
  5725. internalerror(2014010311);
  5726. implprocdefinfo^.skpara:=AValue;
  5727. end;
  5728. function tprocdef.Getpersonality: tprocdef;
  5729. begin
  5730. if not assigned(implprocdefinfo) then
  5731. internalerror(2016121704);
  5732. result:=implprocdefinfo^.personality;
  5733. end;
  5734. procedure tprocdef.Setpersonality(AValue: tprocdef);
  5735. begin
  5736. if not assigned(implprocdefinfo) then
  5737. internalerror(2016121705);
  5738. implprocdefinfo^.personality:=AValue;
  5739. end;
  5740. function tprocdef.Getforwarddef: boolean;
  5741. begin
  5742. if not assigned(implprocdefinfo) then
  5743. internalerror(2014010312);
  5744. result:=implprocdefinfo^.forwarddef;
  5745. end;
  5746. function tprocdef.Gethasforward: boolean;
  5747. begin
  5748. if not assigned(implprocdefinfo) then
  5749. internalerror(2014010313);
  5750. result:=implprocdefinfo^.hasforward;
  5751. end;
  5752. function tprocdef.Getinterfacedef: boolean;
  5753. begin
  5754. if not assigned(implprocdefinfo) then
  5755. internalerror(2014010314);
  5756. result:=implprocdefinfo^.interfacedef;
  5757. end;
  5758. procedure tprocdef.Setforwarddef(AValue: boolean);
  5759. begin
  5760. if not assigned(implprocdefinfo) then
  5761. internalerror(2014010315);
  5762. implprocdefinfo^.forwarddef:=AValue;
  5763. end;
  5764. procedure tprocdef.Sethasforward(AValue: boolean);
  5765. begin
  5766. if not assigned(implprocdefinfo) then
  5767. internalerror(2014010316);
  5768. implprocdefinfo^.hasforward:=AValue;
  5769. end;
  5770. function tprocdef.GetIsEmpty: boolean;
  5771. begin
  5772. result:=pio_empty in implprocoptions;
  5773. end;
  5774. procedure tprocdef.SetIsEmpty(AValue: boolean);
  5775. begin
  5776. if AValue then
  5777. include(implprocoptions,pio_empty)
  5778. else
  5779. exclude(implprocoptions,pio_empty);
  5780. end;
  5781. function tprocdef.GetHasInliningInfo: boolean;
  5782. begin
  5783. result:=pio_has_inlininginfo in implprocoptions;
  5784. end;
  5785. procedure tprocdef.SetHasInliningInfo(AValue: boolean);
  5786. begin
  5787. if AValue then
  5788. include(implprocoptions,pio_has_inlininginfo)
  5789. else
  5790. exclude(implprocoptions,pio_has_inlininginfo);
  5791. end;
  5792. procedure tprocdef.Setinterfacedef(AValue: boolean);
  5793. begin
  5794. if not assigned(implprocdefinfo) then
  5795. internalerror(2014010317);
  5796. implprocdefinfo^.interfacedef:=AValue;
  5797. end;
  5798. procedure tprocdef.Setprocstarttai(AValue: tai);
  5799. begin
  5800. if not assigned(implprocdefinfo) then
  5801. internalerror(2014010318);
  5802. implprocdefinfo^.procstarttai:=AValue;
  5803. end;
  5804. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  5805. begin
  5806. if not assigned(implprocdefinfo) then
  5807. internalerror(2014010319);
  5808. implprocdefinfo^.parentfpstruct:=AValue;
  5809. end;
  5810. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  5811. begin
  5812. if not assigned(implprocdefinfo) then
  5813. internalerror(2014010320);
  5814. implprocdefinfo^.parentfpstructptrtype:=AValue;
  5815. end;
  5816. constructor tprocdef.create(level:byte;doregister:boolean);
  5817. begin
  5818. inherited create(procdef,level,doregister);
  5819. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  5820. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  5821. {$ifdef symansistr}
  5822. _mangledname:='';
  5823. {$else symansistr}
  5824. _mangledname:=nil;
  5825. {$endif symansistr}
  5826. {$ifndef DISABLE_FAST_OVERLOAD_PATCH}
  5827. seenmarker := nil;
  5828. {$endif}
  5829. fileinfo:=current_filepos;
  5830. extnumber:=$ffff;
  5831. aliasnames:=TCmdStrList.create;
  5832. funcretsym:=nil;
  5833. funcretsymderef.reset;
  5834. procsymderef.reset;
  5835. forwarddef:=true;
  5836. interfacedef:=false;
  5837. hasforward:=false;
  5838. struct := nil;
  5839. structderef.reset;
  5840. import_dll:=nil;
  5841. import_name:=nil;
  5842. import_nr:=0;
  5843. inlininginfo:=nil;
  5844. deprecatedmsg:=nil;
  5845. genericdecltokenbuf:=nil;
  5846. if cs_opt_fastmath in current_settings.optimizerswitches then
  5847. include(implprocoptions, pio_fastmath);
  5848. end;
  5849. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  5850. var
  5851. i,aliasnamescount,sizeleft : longint;
  5852. level : byte;
  5853. buf : array[0..255] of byte;
  5854. begin
  5855. inherited ppuload(procdef,ppufile);
  5856. {$ifdef symansistr}
  5857. if po_has_mangledname in procoptions then
  5858. _mangledname:=ppufile.getansistring
  5859. else
  5860. _mangledname:='';
  5861. {$else symansistr}
  5862. if po_has_mangledname in procoptions then
  5863. _mangledname:=ppufile.getpshortstring
  5864. else
  5865. _mangledname:=nil;
  5866. {$endif symansistr}
  5867. extnumber:=ppufile.getword;
  5868. level:=ppufile.getbyte;
  5869. ppufile.getderef(structderef);
  5870. ppufile.getderef(procsymderef);
  5871. ppufile.getposinfo(fileinfo);
  5872. visibility:=tvisibility(ppufile.getbyte);
  5873. ppufile.getset(tppuset2(symoptions));
  5874. if sp_has_deprecated_msg in symoptions then
  5875. deprecatedmsg:=ppufile.getpshortstring
  5876. else
  5877. deprecatedmsg:=nil;
  5878. { import stuff }
  5879. if po_has_importdll in procoptions then
  5880. import_dll:=ppufile.getpshortstring
  5881. else
  5882. import_dll:=nil;
  5883. if po_has_importname in procoptions then
  5884. import_name:=ppufile.getpshortstring
  5885. else
  5886. import_name:=nil;
  5887. import_nr:=ppufile.getword;
  5888. if (po_msgint in procoptions) then
  5889. messageinf.i:=ppufile.getlongint;
  5890. if (po_msgstr in procoptions) then
  5891. messageinf.str:=ppufile.getpshortstring;
  5892. if (po_dispid in procoptions) then
  5893. dispid:=ppufile.getlongint;
  5894. { inline stuff }
  5895. ppufile.getset(tppuset1(implprocoptions));
  5896. if has_inlininginfo then
  5897. begin
  5898. ppufile.getderef(funcretsymderef);
  5899. new(inlininginfo);
  5900. ppufile.getset(tppuset4(inlininginfo^.flags));
  5901. end
  5902. else
  5903. begin
  5904. inlininginfo:=nil;
  5905. funcretsym:=nil;
  5906. end;
  5907. aliasnames:=TCmdStrList.create;
  5908. { count alias names }
  5909. aliasnamescount:=ppufile.getbyte;
  5910. for i:=1 to aliasnamescount do
  5911. aliasnames.insert(ppufile.getstring);
  5912. { load the token stream containing the declaration }
  5913. sizeleft:=ppufile.getlongint;
  5914. if sizeleft>0 then
  5915. begin
  5916. init_genericdecl;
  5917. while sizeleft>0 do
  5918. begin
  5919. if sizeleft>sizeof(buf) then
  5920. i:=sizeof(buf)
  5921. else
  5922. i:=sizeleft;
  5923. ppufile.getdata(buf,i);
  5924. genericdecltokenbuf.write(buf,i);
  5925. dec(sizeleft,i);
  5926. end;
  5927. end;
  5928. ppuload_platform(ppufile);
  5929. { load para symtable }
  5930. parast:=tparasymtable.create(self,level);
  5931. tparasymtable(parast).ppuload(ppufile);
  5932. { load local symtable }
  5933. if store_localst then
  5934. begin
  5935. localst:=tlocalsymtable.create(self,level);
  5936. tlocalsymtable(localst).ppuload(ppufile);
  5937. end
  5938. else
  5939. localst:=nil;
  5940. { inline stuff }
  5941. if has_inlininginfo then
  5942. inlininginfo^.code:=ppuloadnodetree(ppufile);
  5943. { default values for no persistent data }
  5944. if (cs_link_deffile in current_settings.globalswitches) and
  5945. (tf_need_export in target_info.flags) and
  5946. (po_exports in procoptions) then
  5947. deffile.AddExport(mangledname);
  5948. { Disable po_has_inlining until the derefimpl is done }
  5949. has_inlininginfo:=false;
  5950. end;
  5951. destructor tprocdef.destroy;
  5952. begin
  5953. aliasnames.free;
  5954. aliasnames:=nil;
  5955. if assigned(localst) and
  5956. (localst.symtabletype<>staticsymtable) then
  5957. begin
  5958. {$ifdef MEMDEBUG}
  5959. memproclocalst.start;
  5960. {$endif MEMDEBUG}
  5961. localst.free;
  5962. localst:=nil;
  5963. {$ifdef MEMDEBUG}
  5964. memproclocalst.start;
  5965. {$endif MEMDEBUG}
  5966. end;
  5967. if assigned(inlininginfo) then
  5968. begin
  5969. {$ifdef MEMDEBUG}
  5970. memprocnodetree.start;
  5971. {$endif MEMDEBUG}
  5972. tnode(inlininginfo^.code).free;
  5973. {$ifdef MEMDEBUG}
  5974. memprocnodetree.start;
  5975. {$endif MEMDEBUG}
  5976. dispose(inlininginfo);
  5977. inlininginfo:=nil;
  5978. end;
  5979. freeimplprocdefinfo;
  5980. genericdecltokenbuf.free;
  5981. genericdecltokenbuf:=nil;
  5982. stringdispose(import_dll);
  5983. stringdispose(import_name);
  5984. stringdispose(deprecatedmsg);
  5985. if (po_msgstr in procoptions) then
  5986. stringdispose(messageinf.str);
  5987. {$ifndef symansistr}
  5988. if assigned(_mangledname) then
  5989. begin
  5990. {$ifdef MEMDEBUG}
  5991. memmanglednames.start;
  5992. {$endif MEMDEBUG}
  5993. stringdispose(_mangledname);
  5994. {$ifdef MEMDEBUG}
  5995. memmanglednames.stop;
  5996. {$endif MEMDEBUG}
  5997. end;
  5998. {$endif symansistr}
  5999. inherited destroy;
  6000. end;
  6001. procedure tprocdef.freeimplprocdefinfo;
  6002. begin
  6003. if assigned(implprocdefinfo) then
  6004. begin
  6005. stringdispose(implprocdefinfo^.resultname);
  6006. TFPList.FreeAndNilDisposing(implprocdefinfo^.capturedsyms,typeinfo(tcapturedsyminfo));
  6007. freemem(implprocdefinfo);
  6008. implprocdefinfo:=nil;
  6009. end;
  6010. end;
  6011. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  6012. var
  6013. oldintfcrc : boolean;
  6014. aliasnamescount,i,sizeleft : longint;
  6015. item : TCmdStrListItem;
  6016. buf : array[0..255] of byte;
  6017. begin
  6018. { released procdef? }
  6019. if not assigned(parast) then
  6020. exit;
  6021. inherited ppuwrite(ppufile);
  6022. {$ifdef symansistr}
  6023. if po_has_mangledname in procoptions then
  6024. ppufile.putansistring(_mangledname);
  6025. {$else symansistr}
  6026. if po_has_mangledname in procoptions then
  6027. ppufile.putstring(_mangledname^);
  6028. {$endif symansistr}
  6029. ppufile.putword(extnumber);
  6030. ppufile.putbyte(parast.symtablelevel);
  6031. ppufile.putderef(structderef);
  6032. ppufile.putderef(procsymderef);
  6033. ppufile.putposinfo(fileinfo);
  6034. ppufile.putbyte(byte(visibility));
  6035. ppufile.putset(tppuset2(symoptions));
  6036. if sp_has_deprecated_msg in symoptions then
  6037. ppufile.putstring(deprecatedmsg^);
  6038. { import }
  6039. if po_has_importdll in procoptions then
  6040. ppufile.putstring(import_dll^);
  6041. if po_has_importname in procoptions then
  6042. ppufile.putstring(import_name^);
  6043. ppufile.putword(import_nr);
  6044. if (po_msgint in procoptions) then
  6045. ppufile.putlongint(messageinf.i);
  6046. if (po_msgstr in procoptions) then
  6047. ppufile.putstring(messageinf.str^);
  6048. if (po_dispid in procoptions) then
  6049. ppufile.putlongint(dispid);
  6050. { inline stuff }
  6051. oldintfcrc:=ppufile.do_crc;
  6052. ppufile.do_crc:=false;
  6053. ppufile.putset(tppuset1(implprocoptions));
  6054. if has_inlininginfo then
  6055. begin
  6056. ppufile.putderef(funcretsymderef);
  6057. ppufile.putset(tppuset4(inlininginfo^.flags));
  6058. end;
  6059. { count alias names }
  6060. aliasnamescount:=0;
  6061. item:=TCmdStrListItem(aliasnames.first);
  6062. while assigned(item) do
  6063. begin
  6064. inc(aliasnamescount);
  6065. item:=TCmdStrListItem(item.next);
  6066. end;
  6067. if aliasnamescount>255 then
  6068. internalerror(200711021);
  6069. ppufile.putbyte(aliasnamescount);
  6070. item:=TCmdStrListItem(aliasnames.first);
  6071. while assigned(item) do
  6072. begin
  6073. ppufile.putstring(item.str);
  6074. item:=TCmdStrListItem(item.next);
  6075. end;
  6076. ppufile.do_crc:=oldintfcrc;
  6077. { generic tokens for the declaration }
  6078. if assigned(genericdecltokenbuf) and (genericdecltokenbuf.size>0) then
  6079. begin
  6080. sizeleft:=genericdecltokenbuf.size;
  6081. genericdecltokenbuf.seek(0);
  6082. ppufile.putlongint(sizeleft);
  6083. while sizeleft>0 do
  6084. begin
  6085. if sizeleft>sizeof(buf) then
  6086. i:=sizeof(buf)
  6087. else
  6088. i:=sizeleft;
  6089. genericdecltokenbuf.read(buf,i);
  6090. ppufile.putdata(buf,i);
  6091. dec(sizeleft,i);
  6092. end;
  6093. end
  6094. else
  6095. ppufile.putlongint(0);
  6096. { write this entry }
  6097. writeentry(ppufile,ibprocdef);
  6098. { Save the para symtable, this is taken from the interface }
  6099. tparasymtable(parast).ppuwrite(ppufile);
  6100. { save localsymtable for inline procedures or when local
  6101. browser info is requested, this has no influence on the crc }
  6102. if store_localst and not ppufile.crc_only then
  6103. begin
  6104. oldintfcrc:=ppufile.do_crc;
  6105. ppufile.do_crc:=false;
  6106. tlocalsymtable(localst).ppuwrite(ppufile);
  6107. ppufile.do_crc:=oldintfcrc;
  6108. end;
  6109. { node tree for inlining }
  6110. oldintfcrc:=ppufile.do_crc;
  6111. ppufile.do_crc:=false;
  6112. if has_inlininginfo then
  6113. ppuwritenodetree(ppufile,inlininginfo^.code);
  6114. ppufile.do_crc:=oldintfcrc;
  6115. end;
  6116. function tprocdef.fullprocname(showhidden:boolean):string;
  6117. var
  6118. pno: tprocnameoptions;
  6119. begin
  6120. pno:=[];
  6121. if showhidden then
  6122. include(pno,pno_showhidden);
  6123. result:=customprocname(pno);
  6124. end;
  6125. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  6126. var
  6127. s, hs, rn : ansistring;
  6128. t : ttoken;
  6129. module : tmodule;
  6130. syssym : tsyssym;
  6131. begin
  6132. {$ifdef EXTDEBUG}
  6133. include(pno,pno_showhidden);
  6134. {$endif EXTDEBUG}
  6135. s:='';
  6136. rn:='';
  6137. if proctypeoption=potype_operator then
  6138. begin
  6139. for t:=NOTOKEN to last_overloaded do
  6140. if procsym.realname='$'+overloaded_names[t] then
  6141. begin
  6142. s:='operator ';
  6143. if (pno_ownername in pno) and
  6144. assigned(struct) then
  6145. s:=s+struct.RttiName+'.';
  6146. s:=s+arraytokeninfo[t].str;
  6147. if not (pno_noparams in pno) then
  6148. s:=s+typename_paras(pno);
  6149. break;
  6150. end;
  6151. end
  6152. else
  6153. begin
  6154. if (po_classmethod in procoptions) and
  6155. not(pno_noclassmarker in pno) then
  6156. s:='class ';
  6157. case proctypeoption of
  6158. potype_constructor,
  6159. potype_class_constructor:
  6160. s:=s+'constructor ';
  6161. potype_class_destructor,
  6162. potype_destructor:
  6163. s:=s+'destructor ';
  6164. else
  6165. if (pno_proctypeoption in pno) and not (po_anonymous in procoptions) then
  6166. begin
  6167. if assigned(returndef) and
  6168. not(is_void(returndef)) then
  6169. s:=s+'function '
  6170. else
  6171. s:=s+'procedure ';
  6172. end;
  6173. end;
  6174. if (pno_ownername in pno) and
  6175. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  6176. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  6177. if (po_compilerproc in procoptions) and (extnumber<>$ffff) then
  6178. begin
  6179. syssym:=tsyssym.find_by_number(extnumber);
  6180. if not assigned(syssym) then
  6181. internalerror(2016060305);
  6182. rn:=syssym.realname;
  6183. end
  6184. else if po_anonymous in procoptions then
  6185. begin
  6186. s:=s+'anonymous ';
  6187. if assigned(returndef) and
  6188. not(is_void(returndef)) then
  6189. s:=s+'function'
  6190. else
  6191. s:=s+'procedure';
  6192. end
  6193. else if pno_prettynames in pno then
  6194. rn:=procsym.prettyname
  6195. else
  6196. rn:=procsym.RealName;
  6197. if (pno_noleadingdollar in pno) and
  6198. (rn[1]='$') then
  6199. delete(rn,1,1);
  6200. s:=s+rn;
  6201. if not (pno_noparams in pno) then
  6202. s:=s+typename_paras(pno);
  6203. end;
  6204. if not(proctypeoption in [potype_constructor,potype_destructor,
  6205. potype_class_constructor,potype_class_destructor]) and
  6206. assigned(returndef) and
  6207. not(is_void(returndef)) then
  6208. begin
  6209. if assigned(returndef.typesym) then
  6210. begin
  6211. module:=find_module_from_symtable(returndef.typesym.owner);
  6212. if module <> current_module then
  6213. s:=s+':'+module.realmodulename^+'.'
  6214. else
  6215. s:=s+':';
  6216. if pno_prettynames in pno then
  6217. hs:=returndef.typesym.prettyname
  6218. else
  6219. hs:=returndef.typesym.realname;
  6220. if hs[1]<>'$' then
  6221. s:=s+returndef.OwnerHierarchyName+hs
  6222. else
  6223. s:=s+returndef.GetTypeName;
  6224. end
  6225. else
  6226. s:=s+':'+returndef.GetTypeName;
  6227. end;
  6228. if not (po_anonymous in procoptions) then
  6229. if assigned(owner) and (owner.symtabletype=localsymtable) then
  6230. s:=s+' is nested'
  6231. else if po_is_block in procoptions then
  6232. s:=s+' is block';
  6233. s:=s+';';
  6234. if po_far in procoptions then
  6235. s:=s+' far;';
  6236. { forced calling convention? }
  6237. if (po_hascallingconvention in procoptions) then
  6238. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  6239. if (po_staticmethod in procoptions) and
  6240. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  6241. s:=s+' Static;';
  6242. if pno_mangledname in pno then
  6243. s:=s+' -- mangled name: '+mangledname;
  6244. customprocname:=s;
  6245. end;
  6246. function tprocdef.is_methodpointer:boolean;
  6247. begin
  6248. { don't check assigned(_class), that's also the case for nested
  6249. procedures inside methods }
  6250. result:=(owner.symtabletype in [recordsymtable,ObjectSymtable]) and not no_self_node;
  6251. end;
  6252. function tprocdef.is_addressonly:boolean;
  6253. begin
  6254. result:=assigned(owner) and
  6255. not is_methodpointer and
  6256. (not(m_nested_procvars in current_settings.modeswitches) or
  6257. not is_nested_pd(self)) and
  6258. (
  6259. not (po_anonymous in procoptions) or
  6260. not assigned(capturedsyms) or
  6261. (capturedsyms.count=0)
  6262. );
  6263. end;
  6264. procedure tprocdef.make_external;
  6265. begin
  6266. include(procoptions,po_external);
  6267. forwarddef:=false;
  6268. end;
  6269. procedure tprocdef.init_genericdecl;
  6270. begin
  6271. if assigned(genericdecltokenbuf) then
  6272. internalerror(2015061901);
  6273. genericdecltokenbuf:=tdynamicarray.create(256);
  6274. end;
  6275. function tprocdef.get_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  6276. begin
  6277. result:=false;
  6278. if proctypeoption=potype_constructor then
  6279. begin
  6280. result:=true;
  6281. ressym:=tsym(parast.Find('self'));
  6282. resdef:=tabstractnormalvarsym(ressym).vardef;
  6283. { and TP-style constructors return a pointer to self }
  6284. if is_object(resdef) then
  6285. resdef:=cpointerdef.getreusable(resdef);
  6286. end
  6287. else if (proccalloption=pocall_safecall) and
  6288. (tf_safecall_exceptions in target_info.flags) then
  6289. begin
  6290. result:=true;
  6291. ressym:=tsym(localst.Find('safecallresult'));
  6292. resdef:=tabstractnormalvarsym(ressym).vardef;
  6293. end
  6294. else if not is_void(returndef) then
  6295. begin
  6296. result:=true;
  6297. ressym:=funcretsym;
  6298. resdef:=tabstractnormalvarsym(ressym).vardef;
  6299. end;
  6300. end;
  6301. function tprocdef.get_safecall_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  6302. begin
  6303. result:=false;
  6304. if (proctypeoption<>potype_constructor) and
  6305. (proccalloption=pocall_safecall) and
  6306. (tf_safecall_exceptions in target_info.flags) then
  6307. begin
  6308. result:=true;
  6309. ressym:=tsym(localst.Find('safecallresult'));
  6310. resdef:=tabstractnormalvarsym(ressym).vardef;
  6311. end
  6312. end;
  6313. procedure tprocdef.add_captured_sym(sym:tsym;def:tdef;const filepos:tfileposinfo);
  6314. var
  6315. i : longint;
  6316. capturedsym : pcapturedsyminfo;
  6317. begin
  6318. if not assigned(implprocdefinfo) then
  6319. internalerror(2021052601);
  6320. if not assigned(implprocdefinfo^.capturedsyms) then
  6321. implprocdefinfo^.capturedsyms:=tfplist.create;
  6322. for i:=0 to implprocdefinfo^.capturedsyms.count-1 do
  6323. begin
  6324. capturedsym:=pcapturedsyminfo(implprocdefinfo^.capturedsyms[i]);
  6325. if (capturedsym^.sym=sym) and (capturedsym^.def=def) then
  6326. exit;
  6327. end;
  6328. new(capturedsym);
  6329. capturedsym^.sym:=sym;
  6330. capturedsym^.def:=def;
  6331. capturedsym^.fileinfo:=filepos;
  6332. implprocdefinfo^.capturedsyms.add(capturedsym);
  6333. end;
  6334. function tprocdef.has_alias_name(const s: TSymStr): boolean;
  6335. var
  6336. item : TCmdStrListItem;
  6337. begin
  6338. result:=true;
  6339. if mangledname=s then
  6340. exit;
  6341. item:=TCmdStrListItem(aliasnames.first);
  6342. while assigned(item) do
  6343. begin
  6344. if item.str=s then
  6345. exit;
  6346. item:=TCmdStrListItem(item.next);
  6347. end;
  6348. result:=false;
  6349. end;
  6350. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  6351. begin
  6352. case t of
  6353. gs_local :
  6354. GetSymtable:=localst;
  6355. gs_para :
  6356. GetSymtable:=parast;
  6357. else
  6358. GetSymtable:=nil;
  6359. end;
  6360. end;
  6361. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  6362. var
  6363. j : longint;
  6364. begin
  6365. result:=inherited;
  6366. if newtyp=procvardef then
  6367. begin
  6368. { create new paralist }
  6369. tprocvardef(result).calcparas;
  6370. exit;
  6371. end;
  6372. { don't copy mangled name, can be different }
  6373. tprocdef(result).messageinf:=messageinf;
  6374. tprocdef(result).dispid:=dispid;
  6375. if po_msgstr in procoptions then
  6376. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  6377. tprocdef(result).symoptions:=symoptions;
  6378. if assigned(deprecatedmsg) then
  6379. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  6380. { will have to be associated with appropriate procsym }
  6381. tprocdef(result).procsym:=nil;
  6382. { don't create aliases for bare copies, nor copy the funcretsym as
  6383. the function result parameter will be inserted again if necessary
  6384. (e.g. if the calling convention is changed) }
  6385. if not(copytyp in [pc_bareproc,pc_normal_no_hidden]) then
  6386. begin
  6387. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  6388. if assigned(funcretsym) then
  6389. begin
  6390. if funcretsym.owner=parast then
  6391. begin
  6392. j:=parast.symlist.indexof(funcretsym);
  6393. if j<0 then
  6394. internalerror(2011040606);
  6395. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  6396. end
  6397. else if funcretsym.owner=localst then
  6398. begin
  6399. { nothing to do, will be inserted for the new procdef while
  6400. parsing its body (by pdecsub.insert_funcret_local) }
  6401. end
  6402. else
  6403. internalerror(2011040605);
  6404. end;
  6405. end;
  6406. { will have to be associated with a new struct }
  6407. tprocdef(result).struct:=nil;
  6408. if assigned(implprocdefinfo) then
  6409. begin
  6410. if assigned(resultname) then
  6411. tprocdef(result).resultname:=stringdup(resultname^);
  6412. tprocdef(result).synthetickind:=synthetickind;
  6413. end;
  6414. if assigned(import_dll) then
  6415. tprocdef(result).import_dll:=stringdup(import_dll^);
  6416. if assigned(import_name) then
  6417. tprocdef(result).import_name:=stringdup(import_name^);
  6418. tprocdef(result).import_nr:=import_nr;
  6419. tprocdef(result).extnumber:=$ffff;
  6420. tprocdef(result).visibility:=visibility;
  6421. { we need a separate implementation for the copied def }
  6422. tprocdef(result).forwarddef:=true;
  6423. tprocdef(result).interfacedef:=true;
  6424. { create new paralist }
  6425. tprocdef(result).calcparas;
  6426. end;
  6427. function tprocdef.getcopy: tstoreddef;
  6428. begin
  6429. result:=getcopyas(procdef,pc_normal,'',true);
  6430. end;
  6431. procedure tprocdef.buildderef;
  6432. begin
  6433. inherited buildderef;
  6434. structderef.build(struct);
  6435. { procsym that originaly defined this definition, should be in the
  6436. same symtable }
  6437. procsymderef.build(procsym);
  6438. end;
  6439. procedure tprocdef.buildderefimpl;
  6440. begin
  6441. inherited buildderefimpl;
  6442. { Localst is not available for main/unit init }
  6443. if store_localst and assigned(localst) then
  6444. begin
  6445. tlocalsymtable(localst).buildderef;
  6446. tlocalsymtable(localst).buildderefimpl;
  6447. end;
  6448. { inline tree }
  6449. if has_inlininginfo then
  6450. begin
  6451. funcretsymderef.build(funcretsym);
  6452. inlininginfo^.code.buildderefimpl;
  6453. end;
  6454. end;
  6455. procedure tprocdef.deref;
  6456. begin
  6457. inherited deref;
  6458. struct:=tabstractrecorddef(structderef.resolve);
  6459. { procsym that originaly defined this definition, should be in the
  6460. same symtable }
  6461. procsym:=tprocsym(procsymderef.resolve);
  6462. end;
  6463. procedure tprocdef.derefimpl;
  6464. begin
  6465. { Enable has_inlininginfo when the inlininginfo
  6466. structure is available. The has_inlininginfo was disabled
  6467. after the load, since the data was invalid }
  6468. if assigned(inlininginfo) then
  6469. has_inlininginfo:=true;
  6470. { Locals }
  6471. if store_localst and assigned(localst) then
  6472. begin
  6473. tlocalsymtable(localst).deref(false);
  6474. tlocalsymtable(localst).derefimpl(false);
  6475. end;
  6476. { Inline }
  6477. if has_inlininginfo then
  6478. begin
  6479. inlininginfo^.code.derefimpl;
  6480. { funcretsym, this is always located in the localst }
  6481. funcretsym:=tsym(funcretsymderef.resolve);
  6482. end
  6483. else
  6484. begin
  6485. { safety }
  6486. { Not safe! A unit may be reresolved after its interface has been
  6487. parsed but before its implementation has been parsed, and in that
  6488. case the funcretsym is still required!
  6489. funcretsym:=nil; }
  6490. end;
  6491. end;
  6492. function tprocdef.GetTypeName : string;
  6493. begin
  6494. GetTypeName := FullProcName(false);
  6495. end;
  6496. function tprocdef.mangledname : TSymStr;
  6497. begin
  6498. {$ifdef symansistr}
  6499. if _mangledname='' then
  6500. begin
  6501. result:=defaultmangledname;
  6502. _mangledname:=result;
  6503. end
  6504. else
  6505. result:=_mangledname;
  6506. {$else symansistr}
  6507. if not assigned(_mangledname) then
  6508. begin
  6509. result:=defaultmangledname;
  6510. _mangledname:=stringdup(mangledname);
  6511. end
  6512. else
  6513. result:=_mangledname^;
  6514. {$endif symansistr}
  6515. end;
  6516. function tprocdef.defaultmangledname: TSymStr;
  6517. var
  6518. n : TSymStr;
  6519. begin
  6520. n:=procsym.name;
  6521. { make sure that the mangled names of these overloadable methods types is
  6522. unique even if it's made lowercase (e.g. for section names) }
  6523. if proctypeoption in [potype_operator,potype_class_constructor,potype_class_destructor] then
  6524. n:='$'+n;
  6525. { we need to use the symtable where the procsym is inserted,
  6526. because that is visible to the world }
  6527. defaultmangledname:=make_mangledname('',procsym.owner,n);
  6528. defaultmangledname:=defaultmangledname+mangledprocparanames(Length(defaultmangledname))
  6529. end;
  6530. function tprocdef.cplusplusmangledname : TSymStr;
  6531. function getcppparaname(p : tdef) : TSymStr;
  6532. const
  6533. {$ifdef NAMEMANGLING_GCC2}
  6534. ordtype2str : array[tordtype] of string[2] = (
  6535. '',
  6536. 'Uc','Us','Ui','Us','',
  6537. 'Sc','s','i','x','',
  6538. 'b','b','b','b','b','b',
  6539. 'c','w','x');
  6540. {$else NAMEMANGLING_GCC2}
  6541. ordtype2str : array[tordtype] of string[1] = (
  6542. 'v',
  6543. 'h','t','j','y','',
  6544. 'a','s','i','x','',
  6545. 'b','b','b','b','b',
  6546. 'b','b','b','b',
  6547. 'c','w','x','C');
  6548. floattype2str : array[tfloattype] of string[1] = (
  6549. 'f','d','e','e',
  6550. 'd','d','g');
  6551. {$endif NAMEMANGLING_GCC2}
  6552. var
  6553. s : TSymStr;
  6554. begin
  6555. case p.typ of
  6556. orddef:
  6557. begin
  6558. s:=ordtype2str[torddef(p).ordtype];
  6559. if s='C' then
  6560. s:=ordtype2str[range_to_basetype(torddef(p).low,torddef(p).high)];
  6561. end;
  6562. pointerdef:
  6563. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  6564. {$ifndef NAMEMANGLING_GCC2}
  6565. floatdef:
  6566. s:=floattype2str[tfloatdef(p).floattype];
  6567. {$endif NAMEMANGLING_GCC2}
  6568. else
  6569. internalerror(2103001);
  6570. end;
  6571. getcppparaname:=s;
  6572. end;
  6573. var
  6574. s,s2 : TSymStr;
  6575. hp : TParavarsym;
  6576. i : integer;
  6577. begin
  6578. {$ifdef NAMEMANGLING_GCC2}
  6579. { outdated gcc 2.x name mangling scheme }
  6580. s := procsym.realname;
  6581. if procsym.owner.symtabletype=ObjectSymtable then
  6582. begin
  6583. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  6584. case proctypeoption of
  6585. potype_destructor:
  6586. s:='_$_'+tostr(length(s2))+s2;
  6587. potype_constructor:
  6588. s:='___'+tostr(length(s2))+s2;
  6589. else
  6590. s:='_'+s+'__'+tostr(length(s2))+s2;
  6591. end;
  6592. end
  6593. else s:=s+'__';
  6594. s:=s+'F';
  6595. { concat modifiers }
  6596. { !!!!! }
  6597. { now we handle the parameters }
  6598. if maxparacount>0 then
  6599. begin
  6600. for i:=0 to paras.count-1 do
  6601. begin
  6602. hp:=tparavarsym(paras[i]);
  6603. { no hidden parameters form part of a C++ mangled name:
  6604. a) self is not included
  6605. b) there are no "high" or other hidden parameters
  6606. }
  6607. if vo_is_hidden_para in hp.varoptions then
  6608. continue;
  6609. s2:=getcppparaname(hp.vardef);
  6610. if hp.varspez in [vs_var,vs_out] then
  6611. s2:='R'+s2;
  6612. s:=s+s2;
  6613. end;
  6614. end
  6615. else
  6616. s:=s+'v';
  6617. cplusplusmangledname:=s;
  6618. {$else NAMEMANGLING_GCC2}
  6619. { gcc 3.x and 4.x name mangling scheme }
  6620. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  6621. if procsym.owner.symtabletype=ObjectSymtable then
  6622. begin
  6623. s:='_ZN';
  6624. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  6625. s:=s+tostr(length(s2))+s2;
  6626. case proctypeoption of
  6627. potype_constructor:
  6628. s:=s+'C1';
  6629. potype_destructor:
  6630. s:=s+'D1';
  6631. else
  6632. s:=s+tostr(length(procsym.realname))+procsym.realname;
  6633. end;
  6634. s:=s+'E';
  6635. end
  6636. else
  6637. s:=procsym.realname;
  6638. { now we handle the parameters }
  6639. if maxparacount>0 then
  6640. begin
  6641. for i:=0 to paras.count-1 do
  6642. begin
  6643. hp:=tparavarsym(paras[i]);
  6644. { no hidden parameters form part of a C++ mangled name:
  6645. a) self is not included
  6646. b) there are no "high" or other hidden parameters
  6647. }
  6648. if vo_is_hidden_para in hp.varoptions then
  6649. continue;
  6650. s2:=getcppparaname(hp.vardef);
  6651. if hp.varspez in [vs_var,vs_out] then
  6652. s2:='R'+s2;
  6653. s:=s+s2;
  6654. end;
  6655. end
  6656. else
  6657. s:=s+'v';
  6658. cplusplusmangledname:=s;
  6659. {$endif NAMEMANGLING_GCC2}
  6660. end;
  6661. function tprocdef.objcmangledname : TSymStr;
  6662. var
  6663. manglednamelen: longint;
  6664. iscatmethod : boolean;
  6665. begin
  6666. if not (po_msgstr in procoptions) then
  6667. internalerror(2009030901);
  6668. { we may very well need longer strings to handle these... }
  6669. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  6670. length('+"[ ]"')+length(messageinf.str^);
  6671. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  6672. if (iscatmethod) then
  6673. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  6674. if manglednamelen>255 then
  6675. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  6676. if not(po_classmethod in procoptions) then
  6677. result:='"-['
  6678. else
  6679. result:='"+[';
  6680. { quotes are necessary because the +/- otherwise confuse the assembler
  6681. into expecting a number
  6682. }
  6683. if iscatmethod then
  6684. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  6685. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  6686. if iscatmethod then
  6687. result:=result+')';
  6688. result:=result+' '+messageinf.str^+']"';
  6689. end;
  6690. procedure tprocdef.setmangledname(const s : TSymStr);
  6691. begin
  6692. { This is not allowed anymore, the forward declaration
  6693. already needs to create the correct mangledname, no changes
  6694. afterwards are allowed (PFV) }
  6695. { Exception: interface definitions in mode macpas, since in that }
  6696. { case no reference to the old name can exist yet (JM) }
  6697. {$ifdef symansistr}
  6698. if _mangledname<>'' then
  6699. if ((m_mac in current_settings.modeswitches) and
  6700. (interfacedef)) then
  6701. _mangledname:=''
  6702. else
  6703. internalerror(200411171);
  6704. {$else symansistr}
  6705. if assigned(_mangledname) then
  6706. if ((m_mac in current_settings.modeswitches) and
  6707. (interfacedef)) then
  6708. stringdispose(_mangledname)
  6709. else
  6710. internalerror(200411171);
  6711. {$endif symansistr}
  6712. {$ifdef jvm}
  6713. { this routine can be called for compilerproces. can't set mangled
  6714. name since it must be calculated, but it uses import_name when set
  6715. -> set that one }
  6716. import_name:=stringdup(s);
  6717. include(procoptions,po_has_importname);
  6718. include(procoptions,po_has_mangledname);
  6719. {$else}
  6720. {$ifdef symansistr}
  6721. _mangledname:=s;
  6722. {$else symansistr}
  6723. _mangledname:=stringdup(s);
  6724. {$endif symansistr}
  6725. {$endif jvm}
  6726. include(procoptions,po_has_mangledname);
  6727. end;
  6728. function tprocdef.needsglobalasmsym: boolean;
  6729. begin
  6730. result:=
  6731. (cs_profile in current_settings.moduleswitches) or
  6732. { smart linking using a library requires to promote
  6733. all non-nested procedures to AB_GLOBAL
  6734. otherwise you get undefined symbol error at linking
  6735. for msdos target with -CX option for instance }
  6736. (create_smartlink_library and not is_nested_pd(self)) or
  6737. (po_global in procoptions);
  6738. end;
  6739. procedure tprocdef.setcompilerprocname;
  6740. begin
  6741. procsym.realname:='$'+lower(procsym.name);
  6742. end;
  6743. {***************************************************************************
  6744. TPROCVARDEF
  6745. ***************************************************************************}
  6746. constructor tprocvardef.create(level:byte;doregister:boolean);
  6747. begin
  6748. inherited create(procvardef,level,doregister);
  6749. end;
  6750. class function tprocvardef.getreusableprocaddr(def: tabstractprocdef; copytyp: tcacheableproccopytyp): tprocvardef;
  6751. var
  6752. res: PHashSetItem;
  6753. oldsymtablestack: tsymtablestack;
  6754. key: packed record
  6755. def: tabstractprocdef;
  6756. copytyp: tcacheableproccopytyp;
  6757. end;
  6758. begin
  6759. if not assigned(current_module) then
  6760. internalerror(2011081302);
  6761. key.def:=def;
  6762. key.copytyp:=copytyp;
  6763. res:=current_module.procaddrdefs.FindOrAdd(@key,sizeof(key));
  6764. if not assigned(res^.Data) then
  6765. begin
  6766. { since these pointerdefs can be reused anywhere in the current
  6767. unit, add them to the global/staticsymtable (or local symtable
  6768. if they're a local def, because otherwise they'll be saved
  6769. to the ppu referencing a local symtable entry that doesn't
  6770. exist in the ppu) }
  6771. oldsymtablestack:=symtablestack;
  6772. { do not simply push/pop current_module.localsymtable, because
  6773. that can have side-effects (e.g., it removes helpers) }
  6774. symtablestack:=nil;
  6775. result:=tprocvardef(def.getcopyas(procvardef,copytyp,'',true));
  6776. setup_reusable_def(def,result,res,oldsymtablestack);
  6777. { res^.Data may still be nil -> don't overwrite result }
  6778. exit;
  6779. end;
  6780. result:=tprocvardef(res^.Data);
  6781. end;
  6782. class function tprocvardef.getreusableprocaddr_no_free(def: tabstractprocdef): tprocvardef;
  6783. begin
  6784. result:=getreusableprocaddr(def,pc_address_only);
  6785. if not result.is_registered then
  6786. include(result.defoptions,df_not_registered_no_free);
  6787. end;
  6788. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  6789. begin
  6790. inherited ppuload(procvardef,ppufile);
  6791. { load para symtable }
  6792. parast:=tparasymtable.create(self,ppufile.getbyte);
  6793. ppuload_platform(ppufile);
  6794. tparasymtable(parast).ppuload(ppufile);
  6795. end;
  6796. function tprocvardef.getcopy : tstoreddef;
  6797. var
  6798. i : tcallercallee;
  6799. j : longint;
  6800. begin
  6801. result:=cprocvardef.create(parast.symtablelevel,true);
  6802. tprocvardef(result).returndef:=returndef;
  6803. tprocvardef(result).returndefderef:=returndefderef;
  6804. tprocvardef(result).parast:=parast.getcopy;
  6805. tprocvardef(result).savesize:=savesize;
  6806. { create paralist copy }
  6807. calcparas;
  6808. tprocvardef(result).paras:=tparalist.create(false);
  6809. tprocvardef(result).paras.count:=paras.count;
  6810. for j:=0 to paras.count-1 do
  6811. tprocvardef(result).paras[j]:=paras[j];
  6812. tprocvardef(result).proctypeoption:=proctypeoption;
  6813. tprocvardef(result).proccalloption:=proccalloption;
  6814. tprocvardef(result).procoptions:=procoptions;
  6815. tprocvardef(result).callerargareasize:=callerargareasize;
  6816. tprocvardef(result).calleeargareasize:=calleeargareasize;
  6817. tprocvardef(result).maxparacount:=maxparacount;
  6818. tprocvardef(result).minparacount:=minparacount;
  6819. for i:=low(funcretloc) to high(funcretloc) do
  6820. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  6821. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  6822. {$ifdef m68k}
  6823. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  6824. {$endif}
  6825. end;
  6826. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  6827. begin
  6828. inherited ppuwrite(ppufile);
  6829. { Save the para symtable level (necessary to distinguish nested
  6830. procvars) }
  6831. ppufile.putbyte(parast.symtablelevel);
  6832. { Write this entry }
  6833. writeentry(ppufile,ibprocvardef);
  6834. { Save the para symtable, this is taken from the interface }
  6835. tparasymtable(parast).ppuwrite(ppufile);
  6836. end;
  6837. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  6838. begin
  6839. case t of
  6840. gs_para :
  6841. GetSymtable:=parast;
  6842. else
  6843. GetSymtable:=nil;
  6844. end;
  6845. end;
  6846. function tprocvardef.size : asizeint;
  6847. begin
  6848. { we return false for is_addressonly for a block (because it's not a
  6849. simple pointer to a function), but they are handled as implicit
  6850. pointers to a datastructure that contains everything ->
  6851. voidpointertype.size instead of voidcodepointertype.size }
  6852. if po_is_block in procoptions then
  6853. size:=voidpointertype.size
  6854. else if not is_addressonly then
  6855. begin
  6856. if is_nested_pd(self) then
  6857. size:=voidcodepointertype.size+parentfpvoidpointertype.size
  6858. else
  6859. size:=voidcodepointertype.size+voidpointertype.size;
  6860. end
  6861. else
  6862. size:=voidcodepointertype.size;
  6863. end;
  6864. function tprocvardef.is_methodpointer:boolean;
  6865. begin
  6866. result:=(po_methodpointer in procoptions);
  6867. end;
  6868. function tprocvardef.is_addressonly:boolean;
  6869. begin
  6870. result:=((not(po_methodpointer in procoptions) or (po_staticmethod in procoptions)) and
  6871. not(po_is_block in procoptions) and
  6872. not is_nested_pd(self)) or
  6873. (po_addressonly in procoptions);
  6874. end;
  6875. function tprocvardef.getmangledparaname:TSymStr;
  6876. begin
  6877. if not(po_methodpointer in procoptions) then
  6878. if not is_nested_pd(self) then
  6879. result:='procvar'
  6880. else
  6881. { we need the manglednames here, because nestedprocvars can be anonymous, e.g.
  6882. having not a type name or not an unique one, see webtbs/tw27515.pp
  6883. Further, use $_ ... _$ delimiters to avoid ambiguous names, see webtbs/tw27515.pp }
  6884. result:='$_nestedprovar'+mangledprocparanames(0)+'_$'
  6885. else
  6886. result:='procvarofobj'
  6887. end;
  6888. function tprocvardef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  6889. begin
  6890. result:=inherited;
  6891. tabstractprocdef(result).calcparas;
  6892. end;
  6893. function tprocvardef.is_publishable : tpublishproperty;
  6894. begin
  6895. if po_methodpointer in procoptions then
  6896. is_publishable:=pp_publish
  6897. else
  6898. is_publishable:=pp_error;
  6899. end;
  6900. function tprocvardef.GetTypeName : string;
  6901. var
  6902. s: string;
  6903. pno : tprocnameoptions;
  6904. begin
  6905. {$ifdef EXTDEBUG}
  6906. pno:=[pno_showhidden];
  6907. {$else EXTDEBUG}
  6908. pno:=[];
  6909. {$endif EXTDEBUG}
  6910. s:='<';
  6911. if po_is_block in procoptions then
  6912. s := s+'reference to'
  6913. else if po_classmethod in procoptions then
  6914. s := s+'class method type of'
  6915. else
  6916. if po_addressonly in procoptions then
  6917. s := s+'address of'
  6918. else
  6919. s := s+'procedure variable type of';
  6920. if assigned(returndef) and
  6921. (returndef<>voidtype) then
  6922. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  6923. else
  6924. s:=s+' procedure'+typename_paras(pno);
  6925. if po_methodpointer in procoptions then
  6926. s := s+' of object';
  6927. if is_nested_pd(self) then
  6928. s := s+' is nested';
  6929. if po_far in procoptions then
  6930. s := s+';far';
  6931. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  6932. end;
  6933. {***************************************************************************
  6934. TOBJECTDEF
  6935. ***************************************************************************}
  6936. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef;doregister:boolean);
  6937. begin
  6938. inherited create(n,objectdef,doregister);
  6939. fcurrent_dispid:=0;
  6940. objecttype:=ot;
  6941. childof:=nil;
  6942. childofderef.reset;
  6943. vmt_fieldderef.reset;
  6944. hiddenclassdefref.reset;
  6945. extendeddefderef.reset;
  6946. cloneddefderef.reset;
  6947. if objecttype=odt_helper then
  6948. owner.includeoption(sto_has_helper);
  6949. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords,
  6950. current_settings.alignment.recordalignmin);
  6951. { create space for vmt !! }
  6952. vmtentries:=TFPList.Create;
  6953. set_parent(c);
  6954. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  6955. prepareguid;
  6956. { setup implemented interfaces }
  6957. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
  6958. ImplementedInterfaces:=TFPObjectList.Create(true)
  6959. else
  6960. ImplementedInterfaces:=nil;
  6961. writing_class_record_dbginfo:=false;
  6962. end;
  6963. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  6964. var
  6965. i,
  6966. implintfcount : longint;
  6967. d, getterd : tderef;
  6968. ImplIntf : TImplementedInterface;
  6969. vmtentry : pvmtentry;
  6970. begin
  6971. inherited ppuload(objectdef,ppufile);
  6972. objecttype:=tobjecttyp(ppufile.getbyte);
  6973. helpertype:=thelpertype(ppufile.getbyte);
  6974. objextname:=ppufile.getpshortstring;
  6975. { only used for external Objective-C classes/protocols }
  6976. if (objextname^='') then
  6977. stringdispose(objextname);
  6978. symtable:=tObjectSymtable.create(self,objrealname^,0,0);
  6979. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  6980. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  6981. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  6982. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  6983. tObjectSymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  6984. ppufile.getderef(vmt_fieldderef);
  6985. ppufile.getderef(childofderef);
  6986. { load guid }
  6987. iidstr:=nil;
  6988. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  6989. begin
  6990. new(iidguid);
  6991. ppufile.getguid(iidguid^);
  6992. iidstr:=ppufile.getpshortstring;
  6993. end;
  6994. abstractcnt:=ppufile.getlongint;
  6995. if objecttype=odt_helper then
  6996. ppufile.getderef(extendeddefderef);
  6997. vmtentries:=TFPList.Create;
  6998. vmtentries.count:=ppufile.getlongint;
  6999. for i:=0 to vmtentries.count-1 do
  7000. begin
  7001. ppufile.getderef(d);
  7002. new(vmtentry);
  7003. vmtentry^.procdef:=nil;
  7004. vmtentry^.procdefderef:=d;
  7005. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  7006. vmtentries[i]:=vmtentry;
  7007. end;
  7008. { load implemented interfaces }
  7009. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
  7010. begin
  7011. ImplementedInterfaces:=TFPObjectList.Create(true);
  7012. implintfcount:=ppufile.getlongint;
  7013. for i:=0 to implintfcount-1 do
  7014. begin
  7015. ppufile.getderef(d);
  7016. ppufile.getderef(getterd);
  7017. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  7018. ImplIntf.IOffset:=ppufile.getlongint;
  7019. byte(ImplIntf.IType):=ppufile.getbyte;
  7020. ImplementedInterfaces.Add(ImplIntf);
  7021. end;
  7022. end
  7023. else
  7024. ImplementedInterfaces:=nil;
  7025. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7026. ppufile.getderef(hiddenclassdefref);
  7027. if df_copied_def in defoptions then
  7028. begin
  7029. ppufile.getderef(cloneddefderef);
  7030. ppuload_platform(ppufile);
  7031. end
  7032. else
  7033. begin
  7034. ppuload_platform(ppufile);
  7035. tObjectSymtable(symtable).ppuload(ppufile);
  7036. end;
  7037. { handles the predefined class tobject }
  7038. { the last TOBJECT which is loaded gets }
  7039. { it ! }
  7040. { but do this only from a unit that's }
  7041. { marked as system unit to avoid some }
  7042. { equally named user's type to override }
  7043. { the internal types! }
  7044. if mf_system_unit in current_module.moduleflags then
  7045. begin
  7046. if (childof=nil) and
  7047. (objecttype in [odt_class,odt_javaclass]) and
  7048. (objname^='TOBJECT') then
  7049. class_tobject:=self;
  7050. if (childof=nil) and
  7051. (objecttype=odt_interfacecom) then
  7052. if (objname^='IUNKNOWN') then
  7053. interface_iunknown:=self
  7054. else
  7055. if (objname^='IDISPATCH') then
  7056. interface_idispatch:=self;
  7057. if (objecttype=odt_javaclass) and
  7058. not(oo_is_formal in objectoptions) then
  7059. begin
  7060. if (objname^='JLOBJECT') then
  7061. java_jlobject:=self
  7062. else if (objname^='JLTHROWABLE') then
  7063. java_jlthrowable:=self
  7064. else if (objname^='FPCBASERECORDTYPE') then
  7065. java_fpcbaserecordtype:=self
  7066. else if (objname^='JLSTRING') then
  7067. java_jlstring:=self
  7068. else if (objname^='ANSISTRINGCLASS') then
  7069. java_ansistring:=self
  7070. else if (objname^='SHORTSTRINGCLASS') then
  7071. java_shortstring:=self
  7072. else if (objname^='JLENUM') then
  7073. java_jlenum:=self
  7074. else if (objname^='JUENUMSET') then
  7075. java_juenumset:=self
  7076. else if (objname^='FPCBITSET') then
  7077. java_jubitset:=self
  7078. else if (objname^='FPCBASEPROCVARTYPE') then
  7079. java_procvarbase:=self;
  7080. end;
  7081. end;
  7082. if (childof=nil) and
  7083. (objecttype=odt_objcclass) and
  7084. (objname^='PROTOCOL') then
  7085. objc_protocoltype:=self;
  7086. writing_class_record_dbginfo:=false;
  7087. end;
  7088. destructor tobjectdef.destroy;
  7089. begin
  7090. if assigned(symtable) then
  7091. begin
  7092. symtable.free;
  7093. symtable:=nil;
  7094. end;
  7095. stringdispose(objextname);
  7096. stringdispose(iidstr);
  7097. if assigned(ImplementedInterfaces) then
  7098. begin
  7099. ImplementedInterfaces.free;
  7100. ImplementedInterfaces:=nil;
  7101. end;
  7102. if assigned(iidguid) then
  7103. begin
  7104. dispose(iidguid);
  7105. iidguid:=nil;
  7106. end;
  7107. TFPList.FreeAndNilDisposing(vmtentries,TypeInfo(tvmtentry));
  7108. if assigned(vmcallstaticinfo) then
  7109. begin
  7110. freemem(vmcallstaticinfo);
  7111. vmcallstaticinfo:=nil;
  7112. end;
  7113. inherited destroy;
  7114. end;
  7115. function tobjectdef.getcopy : tstoreddef;
  7116. var
  7117. i : longint;
  7118. begin
  7119. result:=cobjectdef.create(objecttype,objrealname^,childof,true);
  7120. { the constructor allocates a symtable which we release to avoid memory leaks }
  7121. tobjectdef(result).symtable.free;
  7122. tobjectdef(result).symtable:=symtable.getcopy;
  7123. if assigned(objextname) then
  7124. tobjectdef(result).objextname:=stringdup(objextname^);
  7125. if assigned(import_lib) then
  7126. tobjectdef(result).import_lib:=stringdup(import_lib^);
  7127. tobjectdef(result).objectoptions:=objectoptions;
  7128. include(tobjectdef(result).defoptions,df_copied_def);
  7129. tobjectdef(result).extendeddef:=extendeddef;
  7130. if assigned(tcinitcode) then
  7131. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  7132. tobjectdef(result).vmt_field:=vmt_field;
  7133. if assigned(iidguid) then
  7134. begin
  7135. new(tobjectdef(result).iidguid);
  7136. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  7137. end;
  7138. if assigned(iidstr) then
  7139. tobjectdef(result).iidstr:=stringdup(iidstr^);
  7140. tobjectdef(result).abstractcnt:=abstractcnt;
  7141. if assigned(ImplementedInterfaces) then
  7142. begin
  7143. tobjectdef(result).ImplementedInterfaces.capacity:=tobjectdef(result).ImplementedInterfaces.count+ImplementedInterfaces.count;
  7144. for i:=0 to ImplementedInterfaces.count-1 do
  7145. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  7146. end;
  7147. tobjectdef(result).copyvmtentries(self);
  7148. end;
  7149. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  7150. var
  7151. i : longint;
  7152. vmtentry : pvmtentry;
  7153. ImplIntf : TImplementedInterface;
  7154. old_do_indirect_crc: boolean;
  7155. begin
  7156. { if class1 in unit A changes, and class2 in unit B inherits from it
  7157. (so unit B uses unit A), then unit B with class2 will be recompiled.
  7158. However, if there is also a class3 in unit C that only depends on
  7159. unit B, then unit C will not be recompiled because nothing changed
  7160. to the interface of unit B. Nevertheless, unit C can indirectly
  7161. depend on unit A via derefs, and these must be updated -> the
  7162. indirect crc keeps track of such changes. }
  7163. old_do_indirect_crc:=ppufile.do_indirect_crc;
  7164. ppufile.do_indirect_crc:=true;
  7165. inherited ppuwrite(ppufile);
  7166. ppufile.putbyte(byte(objecttype));
  7167. ppufile.putbyte(byte(helpertype));
  7168. if assigned(objextname) then
  7169. ppufile.putstring(objextname^)
  7170. else
  7171. ppufile.putstring('');
  7172. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  7173. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  7174. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  7175. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  7176. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignmin));
  7177. ppufile.putderef(vmt_fieldderef);
  7178. ppufile.putderef(childofderef);
  7179. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  7180. begin
  7181. ppufile.putguid(iidguid^);
  7182. ppufile.putstring(iidstr^);
  7183. end;
  7184. ppufile.putlongint(abstractcnt);
  7185. if objecttype=odt_helper then
  7186. ppufile.putderef(extendeddefderef);
  7187. ppufile.putlongint(vmtentries.count);
  7188. for i:=0 to vmtentries.count-1 do
  7189. begin
  7190. vmtentry:=pvmtentry(vmtentries[i]);
  7191. ppufile.putderef(vmtentry^.procdefderef);
  7192. ppufile.putbyte(byte(vmtentry^.visibility));
  7193. end;
  7194. if assigned(ImplementedInterfaces) then
  7195. begin
  7196. ppufile.putlongint(ImplementedInterfaces.Count);
  7197. for i:=0 to ImplementedInterfaces.Count-1 do
  7198. begin
  7199. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  7200. ppufile.putderef(ImplIntf.intfdefderef);
  7201. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  7202. ppufile.putlongint(ImplIntf.Ioffset);
  7203. ppufile.putbyte(byte(ImplIntf.IType));
  7204. end;
  7205. end;
  7206. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7207. ppufile.putderef(hiddenclassdefref);
  7208. if df_copied_def in defoptions then
  7209. ppufile.putderef(cloneddefderef);
  7210. writeentry(ppufile,ibobjectdef);
  7211. if not(df_copied_def in defoptions) then
  7212. tObjectSymtable(symtable).ppuwrite(ppufile);
  7213. ppufile.do_indirect_crc:=old_do_indirect_crc;
  7214. end;
  7215. function tobjectdef.GetTypeName:string;
  7216. begin
  7217. { in this case we will go in endless recursion, because then }
  7218. { there is no tsym associated yet with the def. It can occur }
  7219. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  7220. { instead of the actual type name }
  7221. if not assigned(typesym) then
  7222. result:='<Currently Parsed Class>'
  7223. else
  7224. result:=typesymbolprettyname;
  7225. end;
  7226. procedure tobjectdef.buildderef;
  7227. var
  7228. i : longint;
  7229. vmtentry : pvmtentry;
  7230. begin
  7231. inherited buildderef;
  7232. vmt_fieldderef.build(vmt_field);
  7233. childofderef.build(childof);
  7234. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7235. hiddenclassdefref.build(hiddenclassdef);
  7236. if df_copied_def in defoptions then
  7237. cloneddefderef.build(symtable.defowner)
  7238. else
  7239. tstoredsymtable(symtable).buildderef;
  7240. if objecttype=odt_helper then
  7241. extendeddefderef.build(extendeddef);
  7242. for i:=0 to vmtentries.count-1 do
  7243. begin
  7244. vmtentry:=pvmtentry(vmtentries[i]);
  7245. vmtentry^.procdefderef.build(vmtentry^.procdef);
  7246. end;
  7247. if assigned(ImplementedInterfaces) then
  7248. begin
  7249. for i:=0 to ImplementedInterfaces.count-1 do
  7250. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  7251. end;
  7252. end;
  7253. procedure tobjectdef.deref;
  7254. var
  7255. i : longint;
  7256. vmtentry : pvmtentry;
  7257. begin
  7258. inherited deref;
  7259. vmt_field:=tsym(vmt_fieldderef.resolve);
  7260. childof:=tobjectdef(childofderef.resolve);
  7261. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7262. hiddenclassdef:=tobjectdef(hiddenclassdefref.resolve);
  7263. if df_copied_def in defoptions then
  7264. begin
  7265. cloneddef:=tobjectdef(cloneddefderef.resolve);
  7266. symtable:=cloneddef.symtable.getcopy;
  7267. end
  7268. else
  7269. tstoredsymtable(symtable).deref(false);
  7270. if objecttype=odt_helper then
  7271. extendeddef:=tdef(extendeddefderef.resolve);
  7272. for i:=0 to vmtentries.count-1 do
  7273. begin
  7274. vmtentry:=pvmtentry(vmtentries[i]);
  7275. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  7276. end;
  7277. if assigned(ImplementedInterfaces) then
  7278. begin
  7279. for i:=0 to ImplementedInterfaces.count-1 do
  7280. TImplementedInterface(ImplementedInterfaces[i]).deref;
  7281. end;
  7282. end;
  7283. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  7284. var
  7285. pd: tprocdef absolute def;
  7286. st: tsymtable;
  7287. psym: tsym;
  7288. nname: TIDString;
  7289. begin
  7290. if (tdef(def).typ<>procdef) then
  7291. exit;
  7292. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  7293. owner = symtable in which objcclassdef is defined
  7294. }
  7295. st:=pd.owner.defowner.owner;
  7296. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  7297. { check for an existing procsym with our special name }
  7298. psym:=tsym(st.find(nname));
  7299. if not assigned(psym) then
  7300. begin
  7301. psym:=cprocsym.create(nname);
  7302. { avoid warning about this symbol being unused }
  7303. psym.IncRefCount;
  7304. { don't check for duplicates:
  7305. a) we checked above
  7306. b) in case we are in the implementation section of a unit, this
  7307. will also check for this symbol in the interface section
  7308. (since you normally cannot have symbols with the same name
  7309. both interface and implementation), and it's possible to
  7310. have class helpers for the same class in the interface and
  7311. in the implementation, and they cannot be merged since only
  7312. the once in the interface must be saved to the ppu/visible
  7313. from other units }
  7314. st.insertsym(psym,false);
  7315. end
  7316. else if (psym.typ<>procsym) then
  7317. internalerror(2009111501);
  7318. { add ourselves to this special procsym }
  7319. tprocsym(psym).procdeflist.add(def);
  7320. end;
  7321. procedure tobjectdef.derefimpl;
  7322. begin
  7323. inherited derefimpl;
  7324. { the procdefs are not owned by the class helper procsyms, so they
  7325. are not stored/restored either -> re-add them here }
  7326. if (objecttype in [odt_objcclass,odt_objcprotocol]) or
  7327. (oo_is_classhelper in objectoptions) then
  7328. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  7329. end;
  7330. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  7331. var
  7332. i : longint;
  7333. vmtentry : pvmtentry;
  7334. begin
  7335. if vmtentries.count<>0 then
  7336. internalerror(2019081401);
  7337. vmtentries.count:=objdef.vmtentries.count;
  7338. for i:=0 to objdef.vmtentries.count-1 do
  7339. begin
  7340. new(vmtentry);
  7341. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  7342. vmtentries[i]:=vmtentry;
  7343. end;
  7344. end;
  7345. function tobjectdef.getparentdef:tdef;
  7346. begin
  7347. { TODO: Remove getparentdef hack}
  7348. { With 2 forward declared classes with the child class before the
  7349. parent class the child class is written earlier to the ppu. Leaving it
  7350. possible to have a reference to the parent class for property overriding,
  7351. but the parent class still has the childof not resolved yet (PFV) }
  7352. if childof=nil then
  7353. childof:=tobjectdef(childofderef.resolve);
  7354. result:=childof;
  7355. end;
  7356. procedure tobjectdef.prepareguid;
  7357. begin
  7358. { set up guid }
  7359. if not assigned(iidguid) then
  7360. begin
  7361. new(iidguid);
  7362. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  7363. end;
  7364. { setup iidstring }
  7365. if not assigned(iidstr) then
  7366. iidstr:=stringdup(''); { default is empty string }
  7367. end;
  7368. procedure tobjectdef.set_parent( c : tobjectdef);
  7369. begin
  7370. if assigned(childof) then
  7371. exit;
  7372. childof:=c;
  7373. if not assigned(c) then
  7374. exit;
  7375. { inherit options and status }
  7376. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  7377. { check if parent is a generic parameter }
  7378. if sp_generic_para in c.typesym.symoptions then
  7379. objectoptions:=objectoptions+[oo_inherits_not_specialized];
  7380. { initially has the same number of abstract methods as the parent }
  7381. abstractcnt:=c.abstractcnt;
  7382. { add the data of the anchestor class/object }
  7383. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  7384. begin
  7385. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  7386. { inherit recordalignment }
  7387. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  7388. { if both the parent and this record use C-alignment, also inherit
  7389. the current field alignment }
  7390. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  7391. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  7392. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  7393. { the padding is not inherited for Objective-C classes (maybe not
  7394. for cppclass either?) }
  7395. if objecttype=odt_objcclass then
  7396. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  7397. if (oo_has_vmt in objectoptions) and
  7398. (oo_has_vmt in c.objectoptions) then
  7399. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  7400. { if parent has a vmt field then the offset is the same for the child PM }
  7401. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  7402. begin
  7403. vmt_field:=c.vmt_field;
  7404. include(objectoptions,oo_has_vmt);
  7405. end;
  7406. end;
  7407. end;
  7408. procedure tobjectdef.insertvmt;
  7409. begin
  7410. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  7411. exit;
  7412. if (oo_has_vmt in objectoptions) then
  7413. internalerror(2020100816)
  7414. else
  7415. begin
  7416. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  7417. tObjectSymtable(symtable).fieldalignment);
  7418. if (tf_requires_proper_alignment in target_info.flags) then
  7419. begin
  7420. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  7421. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  7422. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  7423. end;
  7424. vmt_field:=cfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  7425. hidesym(vmt_field);
  7426. tObjectSymtable(symtable).insertsym(vmt_field);
  7427. tObjectSymtable(symtable).addfield(tfieldvarsym(vmt_field),vis_hidden);
  7428. include(objectoptions,oo_has_vmt);
  7429. end;
  7430. end;
  7431. function tobjectdef.vmt_offset: asizeint;
  7432. begin
  7433. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  7434. result:=0
  7435. else if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  7436. result:=tfieldvarsym(vmt_field).fieldoffset
  7437. else
  7438. result:=tfieldvarsym(vmt_field).fieldoffset div 8;
  7439. end;
  7440. procedure tobjectdef.check_forwards;
  7441. begin
  7442. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  7443. inherited;
  7444. if (oo_is_forward in objectoptions) then
  7445. begin
  7446. { ok, in future, the forward can be resolved }
  7447. Message1(sym_e_class_forward_not_resolved,objrealname^);
  7448. exclude(objectoptions,oo_is_forward);
  7449. end;
  7450. end;
  7451. function tobjectdef.find_destructor: tprocdef;
  7452. var
  7453. objdef: tobjectdef;
  7454. begin
  7455. objdef:=self;
  7456. while assigned(objdef) do
  7457. begin
  7458. result:=objdef.find_procdef_bytype(potype_destructor);
  7459. if assigned(result) then
  7460. exit;
  7461. objdef:=objdef.childof;
  7462. end;
  7463. result:=nil;
  7464. end;
  7465. function tobjectdef.implements_any_interfaces: boolean;
  7466. begin
  7467. result := (ImplementedInterfaces.Count > 0) or
  7468. (assigned(childof) and childof.implements_any_interfaces);
  7469. end;
  7470. function tobjectdef.register_implemented_interface(intfdef:tobjectdef;useguid:boolean):timplementedinterface;
  7471. begin
  7472. { allocate the GUID only if the class implements at least one interface }
  7473. if useguid then
  7474. prepareguid;
  7475. result:=timplementedinterface.create(intfdef);
  7476. ImplementedInterfaces.Add(result);
  7477. end;
  7478. function tobjectdef.size : asizeint;
  7479. begin
  7480. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  7481. result:=voidpointertype.size
  7482. else
  7483. result:=tObjectSymtable(symtable).datasize;
  7484. end;
  7485. function tobjectdef.alignment:shortint;
  7486. begin
  7487. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  7488. alignment:=voidpointertype.alignment
  7489. else
  7490. alignment:=tObjectSymtable(symtable).recordalignment;
  7491. end;
  7492. function tobjectdef.vmtmethodoffset(index:longint):longint;
  7493. begin
  7494. { for offset of methods for classes, see rtl/inc/objpash.inc }
  7495. case objecttype of
  7496. odt_class:
  7497. { the +2*sizeof(pint) is size and -size }
  7498. vmtmethodoffset:=index*voidcodepointertype.size+10*voidpointertype.size+2*sizeof(pint);
  7499. odt_helper,
  7500. odt_objcclass,
  7501. odt_objcprotocol:
  7502. vmtmethodoffset:=0;
  7503. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  7504. vmtmethodoffset:=index*voidcodepointertype.size;
  7505. odt_javaclass,
  7506. odt_interfacejava:
  7507. { invalid }
  7508. vmtmethodoffset:=-1;
  7509. else
  7510. { the +2*sizeof(pint) is size and -size }
  7511. {$ifdef WITHDMT}
  7512. vmtmethodoffset:=index*voidcodepointertype.size+2*voidpointertype.size+2*sizeof(pint);
  7513. {$else WITHDMT}
  7514. vmtmethodoffset:=index*voidcodepointertype.size+1*voidpointertype.size+2*sizeof(pint);
  7515. {$endif WITHDMT}
  7516. end;
  7517. end;
  7518. function tobjectdef.vmt_mangledname : TSymStr;
  7519. begin
  7520. if not(oo_has_vmt in objectoptions) then
  7521. Message1(parser_n_object_has_no_vmt,objrealname^);
  7522. if not is_unique_objpasdef then
  7523. vmt_mangledname:=make_mangledname('VMT',owner,objname^)
  7524. else
  7525. vmt_mangledname:=childof.vmt_mangledname;
  7526. end;
  7527. function tobjectdef.vmt_def: trecorddef;
  7528. var
  7529. where: tsymtable;
  7530. vmttypesym: tsymentry;
  7531. begin
  7532. if not is_unique_objpasdef then
  7533. begin
  7534. vmttypesym:=symtable.Find('vmtdef');
  7535. if not assigned(vmttypesym) or
  7536. (vmttypesym.typ<>symconst.typesym) or
  7537. (ttypesym(vmttypesym).typedef.typ<>recorddef) then
  7538. internalerror(2015052501);
  7539. result:=trecorddef(ttypesym(vmttypesym).typedef);
  7540. end
  7541. else
  7542. result:=childof.vmt_def;
  7543. end;
  7544. function tobjectdef.needs_inittable : boolean;
  7545. var
  7546. hp : tobjectdef;
  7547. begin
  7548. case objecttype of
  7549. odt_helper,
  7550. odt_class :
  7551. needs_inittable:=false;
  7552. odt_dispinterface,
  7553. odt_interfacecom:
  7554. needs_inittable:=true;
  7555. odt_interfacecorba:
  7556. begin
  7557. hp:=childof;
  7558. while assigned(hp) do
  7559. begin
  7560. if hp=interface_iunknown then
  7561. begin
  7562. needs_inittable:=true;
  7563. exit;
  7564. end;
  7565. hp:=hp.childof;
  7566. end;
  7567. needs_inittable:=false;
  7568. end;
  7569. odt_object:
  7570. needs_inittable:=
  7571. tObjectSymtable(symtable).needs_init_final or
  7572. (assigned(childof) and
  7573. childof.needs_inittable);
  7574. odt_cppclass,
  7575. odt_objcclass,
  7576. odt_objcprotocol,
  7577. odt_javaclass,
  7578. odt_interfacejava:
  7579. needs_inittable:=false;
  7580. else
  7581. internalerror(200108267);
  7582. end;
  7583. end;
  7584. function tobjectdef.needs_separate_initrtti : boolean;
  7585. begin
  7586. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  7587. end;
  7588. function tobjectdef.has_non_trivial_init_child(check_parent:boolean):boolean;
  7589. begin
  7590. if objecttype in [odt_class,odt_object] then
  7591. begin
  7592. result:=tobjectsymtable(symtable).has_non_trivial_init or
  7593. (check_parent and assigned(childof) and childof.has_non_trivial_init_child(true));
  7594. end
  7595. else
  7596. result:=false;
  7597. end;
  7598. function tobjectdef.rtti_mangledname(rt: trttitype): TSymStr;
  7599. begin
  7600. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  7601. begin
  7602. if not is_unique_objpasdef then
  7603. result:=inherited rtti_mangledname(rt)
  7604. else
  7605. result:=childof.rtti_mangledname(rt)
  7606. end
  7607. else
  7608. begin
  7609. { necessary in case of a dynamic array of nsobject, or
  7610. if an nsobject field appears in a record that needs
  7611. init/finalisation }
  7612. if rt=initrtti then
  7613. begin
  7614. result:=voidpointertype.rtti_mangledname(rt);
  7615. exit;
  7616. end;
  7617. if not(target_info.system in systems_objc_nfabi) then
  7618. begin
  7619. result:=target_asm.labelprefix;
  7620. case objecttype of
  7621. odt_objcclass:
  7622. begin
  7623. case rt of
  7624. objcclassrtti:
  7625. if not(oo_is_classhelper in objectoptions) then
  7626. result:=result+'_OBJC_CLASS_'
  7627. else
  7628. result:=result+'_OBJC_CATEGORY_';
  7629. objcmetartti:
  7630. if not(oo_is_classhelper in objectoptions) then
  7631. result:=result+'_OBJC_METACLASS_'
  7632. else
  7633. internalerror(2009111511);
  7634. else
  7635. internalerror(2009092302);
  7636. end;
  7637. end;
  7638. odt_objcprotocol:
  7639. result:=result+'_OBJC_PROTOCOL_';
  7640. else
  7641. ;
  7642. end;
  7643. end
  7644. else
  7645. begin
  7646. case objecttype of
  7647. odt_objcclass:
  7648. begin
  7649. if (oo_is_classhelper in objectoptions) and
  7650. (rt<>objcclassrtti) then
  7651. internalerror(2009111512);
  7652. case rt of
  7653. objcclassrtti:
  7654. if not(oo_is_classhelper in objectoptions) then
  7655. result:='_OBJC_CLASS_$_'
  7656. else
  7657. result:='_OBJC_$_CATEGORY_';
  7658. objcmetartti:
  7659. result:='_OBJC_METACLASS_$_';
  7660. objcclassrortti:
  7661. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  7662. objcmetarortti:
  7663. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  7664. else
  7665. internalerror(2009092303);
  7666. end;
  7667. end;
  7668. odt_objcprotocol:
  7669. begin
  7670. result:=lower(target_asm.labelprefix);
  7671. case rt of
  7672. objcclassrtti:
  7673. result:=result+'_OBJC_PROTOCOL_$_';
  7674. objcmetartti:
  7675. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  7676. else
  7677. internalerror(2009092501);
  7678. end;
  7679. end;
  7680. else
  7681. internalerror(2013113005);
  7682. end;
  7683. end;
  7684. result:=result+objextname^;
  7685. end;
  7686. end;
  7687. function tobjectdef.is_unique_objpasdef: boolean;
  7688. begin
  7689. result:=
  7690. (df_unique in defoptions) and
  7691. is_class_or_interface_or_dispinterface(self)
  7692. end;
  7693. function tobjectdef.members_need_inittable : boolean;
  7694. begin
  7695. members_need_inittable:=tObjectSymtable(symtable).needs_init_final or
  7696. has_non_trivial_init_child(true);
  7697. end;
  7698. function tobjectdef.is_publishable : tpublishproperty;
  7699. begin
  7700. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  7701. is_publishable:=pp_publish
  7702. else
  7703. is_publishable:=pp_error;
  7704. end;
  7705. function tobjectdef.get_next_dispid: longint;
  7706. begin
  7707. inc(fcurrent_dispid);
  7708. result:=fcurrent_dispid;
  7709. end;
  7710. function tobjectdef.search_enumerator_get: tprocdef;
  7711. begin
  7712. result:=inherited;
  7713. if not assigned(result) and assigned(childof) then
  7714. result:=childof.search_enumerator_get;
  7715. end;
  7716. function tobjectdef.search_enumerator_move: tprocdef;
  7717. begin
  7718. result:=inherited;
  7719. if not assigned(result) and assigned(childof) then
  7720. result:=childof.search_enumerator_move;
  7721. end;
  7722. function tobjectdef.search_enumerator_current: tsym;
  7723. begin
  7724. result:=inherited;
  7725. if not assigned(result) and assigned(childof) then
  7726. result:=childof.search_enumerator_current;
  7727. end;
  7728. procedure tobjectdef.register_created_classref_type;
  7729. begin
  7730. if not classref_created_in_current_module then
  7731. begin
  7732. classref_created_in_current_module:=true;
  7733. if not (owner.symtabletype in [localsymtable]) then
  7734. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  7735. end;
  7736. end;
  7737. procedure tobjectdef.register_created_object_type;
  7738. begin
  7739. if not created_in_current_module then
  7740. begin
  7741. created_in_current_module:=true;
  7742. if not (owner.symtabletype in [localsymtable]) then
  7743. current_module.wpoinfo.addcreatedobjtype(self);
  7744. end;
  7745. end;
  7746. procedure tobjectdef.register_maybe_created_object_type;
  7747. begin
  7748. { if we know it has been created for sure, no need
  7749. to also record that it maybe can be created in
  7750. this module
  7751. }
  7752. if not (created_in_current_module) and
  7753. not (maybe_created_in_current_module) then
  7754. begin
  7755. maybe_created_in_current_module:=true;
  7756. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  7757. end;
  7758. end;
  7759. procedure tobjectdef.register_vmt_call(index: longint);
  7760. begin
  7761. if (is_object(self) or is_class(self)) then
  7762. current_module.wpoinfo.addcalledvmtentry(self,index);
  7763. end;
  7764. procedure check_and_finish_msg(data: tobject; arg: pointer);
  7765. var
  7766. def: tdef absolute data;
  7767. pd: tprocdef absolute data;
  7768. i,
  7769. paracount: longint;
  7770. begin
  7771. if (def.typ=procdef) then
  7772. begin
  7773. { add all messages also under a dummy name to the symtable in
  7774. which the objcclass/protocol/category is declared, so they can
  7775. be called via id.<name>
  7776. }
  7777. create_class_helper_for_procdef(pd,nil);
  7778. { we have to wait until now to set the mangled name because it
  7779. depends on the (possibly external) class name, which is defined
  7780. at the very end. }
  7781. if not(po_msgstr in pd.procoptions) then
  7782. begin
  7783. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  7784. { recover to avoid internalerror later on }
  7785. include(pd.procoptions,po_msgstr);
  7786. pd.messageinf.str:=stringdup('MissingDeclaration');
  7787. end;
  7788. { Mangled name is already set in case this is a copy of
  7789. another type. }
  7790. if not(po_has_mangledname in pd.procoptions) then
  7791. begin
  7792. { check whether the number of formal parameters is correct,
  7793. and whether they have valid Objective-C types }
  7794. paracount:=0;
  7795. for i:=1 to length(pd.messageinf.str^) do
  7796. if pd.messageinf.str^[i]=':' then
  7797. inc(paracount);
  7798. for i:=0 to pd.paras.count-1 do
  7799. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  7800. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  7801. dec(paracount);
  7802. if (paracount<>0) then
  7803. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  7804. pd.setmangledname(pd.objcmangledname);
  7805. end
  7806. else
  7807. { all checks already done }
  7808. exit;
  7809. if not(oo_is_external in pd.struct.objectoptions) then
  7810. begin
  7811. if (po_varargs in pd.procoptions) then
  7812. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  7813. else
  7814. begin
  7815. { check for "array of const" parameters }
  7816. for i:=0 to pd.parast.symlist.count-1 do
  7817. begin
  7818. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  7819. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  7820. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  7821. end;
  7822. end;
  7823. end;
  7824. end;
  7825. end;
  7826. procedure mark_private_fields_used(data: tobject; arg: pointer);
  7827. var
  7828. sym: tsym absolute data;
  7829. begin
  7830. if (sym.typ=fieldvarsym) and
  7831. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  7832. sym.IncRefCount;
  7833. end;
  7834. procedure tobjectdef.finish_objc_data;
  7835. begin
  7836. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  7837. if (oo_is_external in objectoptions) then
  7838. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  7839. end;
  7840. procedure verify_objc_vardef(data: tobject; arg: pointer);
  7841. var
  7842. sym: tabstractvarsym absolute data;
  7843. res: pboolean absolute arg;
  7844. founderrordef: tdef;
  7845. begin
  7846. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  7847. exit;
  7848. if (sym.typ=paravarsym) and
  7849. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  7850. is_array_of_const(tparavarsym(sym).vardef)) then
  7851. exit;
  7852. if not objcchecktype(sym.vardef,founderrordef) then
  7853. begin
  7854. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7855. res^:=false;
  7856. end;
  7857. end;
  7858. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  7859. var
  7860. def: tdef absolute data;
  7861. res: pboolean absolute arg;
  7862. founderrordef: tdef;
  7863. begin
  7864. if (def.typ<>procdef) then
  7865. exit;
  7866. { check parameter types for validity }
  7867. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  7868. { check the result type for validity }
  7869. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  7870. begin
  7871. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7872. res^:=false;
  7873. end;
  7874. end;
  7875. function tobjectdef.check_objc_types: boolean;
  7876. begin
  7877. { done in separate step from finish_objc_data, because when
  7878. finish_objc_data is called, not all forwarddefs have been resolved
  7879. yet and we need to know all types here }
  7880. result:=true;
  7881. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  7882. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  7883. end;
  7884. procedure do_cpp_import_info(data: tobject; arg: pointer);
  7885. var
  7886. def: tdef absolute data;
  7887. pd: tprocdef absolute data;
  7888. begin
  7889. if (def.typ=procdef) then
  7890. begin
  7891. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  7892. if (oo_is_external in pd.struct.objectoptions) then
  7893. begin
  7894. { copied from psub.read_proc }
  7895. if assigned(tobjectdef(pd.struct).import_lib) then
  7896. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  7897. else
  7898. begin
  7899. { add import name to external list for DLL scanning }
  7900. if tf_has_dllscanner in target_info.flags then
  7901. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  7902. end;
  7903. end;
  7904. end;
  7905. end;
  7906. procedure tobjectdef.finish_cpp_data;
  7907. begin
  7908. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  7909. end;
  7910. procedure tobjectdef.apply_rtti_directive(dir: trtti_directive);
  7911. begin
  7912. rtti.clause:=dir.clause;
  7913. rtti.options:=dir.options;
  7914. if (dir.clause=rtc_inherit) and assigned(childof) and (childof.rtti.clause<>rtc_none) then
  7915. begin
  7916. rtti.options[ro_methods]:=rtti.options[ro_methods]+childof.rtti.options[ro_methods];
  7917. rtti.options[ro_fields]:=rtti.options[ro_fields]+childof.rtti.options[ro_fields];
  7918. rtti.options[ro_properties]:=rtti.options[ro_properties]+childof.rtti.options[ro_properties];
  7919. end;
  7920. end;
  7921. {$ifdef DEBUG_NODE_XML}
  7922. function TObjectDef.XMLPrintType: ansistring;
  7923. begin
  7924. if (oo_is_forward in objectoptions) then
  7925. Result := '&lt;class prototype&gt;'
  7926. else
  7927. Result := '&lt;class&gt;';
  7928. end;
  7929. procedure TObjectDef.XMLPrintDefInfo(var T: Text; Sym: TSym);
  7930. var
  7931. i: TObjectOption;
  7932. first: Boolean;
  7933. begin
  7934. inherited XMLPrintDefInfo(T, Sym);
  7935. First := True;
  7936. for i := Low(TObjectOption) to High(TObjectOption) do
  7937. if i in objectoptions then
  7938. begin
  7939. if First then
  7940. begin
  7941. Write(T, ' objectoptions="', i);
  7942. First := False;
  7943. end
  7944. else
  7945. Write(T, ',', i)
  7946. end;
  7947. if not first then
  7948. Write(T, '"');
  7949. end;
  7950. procedure TObjectDef.XMLPrintDefData(var T: Text; Sym: TSym);
  7951. begin
  7952. { There's nothing useful yet if the type is only forward-declared }
  7953. if not (oo_is_forward in objectoptions) then
  7954. begin
  7955. if Assigned(childof) then
  7956. WriteLn(T, printnodeindention, '<ancestor>', SanitiseXMLString(childof.typesym.RealName), '</ancestor>');
  7957. inherited XMLPrintDefData(T, Sym);
  7958. end;
  7959. end;
  7960. {$endif DEBUG_NODE_XML}
  7961. {****************************************************************************
  7962. TImplementedInterface
  7963. ****************************************************************************}
  7964. function TImplementedInterface.GetIOffset: longint;
  7965. begin
  7966. if (fIOffset=-1) and
  7967. (IType in [etFieldValue,etFieldValueClass]) then
  7968. result:=tfieldvarsym(ImplementsField).fieldoffset
  7969. else
  7970. result:=fIOffset;
  7971. end;
  7972. constructor TImplementedInterface.create(aintf: tobjectdef);
  7973. begin
  7974. inherited create;
  7975. intfdef:=aintf;
  7976. intfdefderef.reset;
  7977. IOffset:=-1;
  7978. IType:=etStandard;
  7979. NameMappings:=nil;
  7980. procdefs:=nil;
  7981. end;
  7982. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  7983. begin
  7984. inherited create;
  7985. intfdef:=nil;
  7986. intfdefderef:=intfd;
  7987. ImplementsGetterDeref:=getterd;
  7988. IOffset:=-1;
  7989. IType:=etStandard;
  7990. NameMappings:=nil;
  7991. procdefs:=nil;
  7992. end;
  7993. destructor TImplementedInterface.destroy;
  7994. var
  7995. i : longint;
  7996. mappedname : pshortstring;
  7997. begin
  7998. if assigned(NameMappings) then
  7999. begin
  8000. for i:=0 to NameMappings.Count-1 do
  8001. begin
  8002. mappedname:=pshortstring(NameMappings[i]);
  8003. stringdispose(mappedname);
  8004. end;
  8005. NameMappings.free;
  8006. NameMappings:=nil;
  8007. end;
  8008. if assigned(procdefs) then
  8009. begin
  8010. procdefs.free;
  8011. procdefs:=nil;
  8012. end;
  8013. inherited destroy;
  8014. end;
  8015. procedure TImplementedInterface.buildderef;
  8016. begin
  8017. intfdefderef.build(intfdef);
  8018. ImplementsGetterDeref.build(ImplementsGetter);
  8019. end;
  8020. procedure TImplementedInterface.deref;
  8021. begin
  8022. intfdef:=tobjectdef(intfdefderef.resolve);
  8023. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  8024. end;
  8025. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  8026. begin
  8027. if not assigned(NameMappings) then
  8028. NameMappings:=TFPHashList.Create;
  8029. NameMappings.Add(origname,stringdup(newname));
  8030. end;
  8031. function TImplementedInterface.GetMapping(const origname: string):string;
  8032. var
  8033. mappedname : pshortstring;
  8034. begin
  8035. result:='';
  8036. if not assigned(NameMappings) then
  8037. exit;
  8038. mappedname:=PShortstring(NameMappings.Find(origname));
  8039. if assigned(mappedname) then
  8040. result:=mappedname^;
  8041. end;
  8042. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  8043. begin
  8044. if not assigned(procdefs) then
  8045. procdefs:=TFPObjectList.Create(false);
  8046. { duplicate entries must be stored, because multiple }
  8047. { interfaces can declare methods with the same name }
  8048. { and all of these get their own VMT entry }
  8049. procdefs.Add(pd);
  8050. end;
  8051. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  8052. var
  8053. i : longint;
  8054. begin
  8055. result:=false;
  8056. { interfaces being implemented through delegation are not mergable (FK) }
  8057. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  8058. exit;
  8059. weight:=0;
  8060. { empty interface is mergeable }
  8061. if ProcDefs.Count=0 then
  8062. begin
  8063. result:=true;
  8064. exit;
  8065. end;
  8066. { The interface to merge must at least the number of
  8067. procedures of this interface }
  8068. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  8069. exit;
  8070. for i:=0 to ProcDefs.Count-1 do
  8071. begin
  8072. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  8073. exit;
  8074. end;
  8075. weight:=ProcDefs.Count;
  8076. result:=true;
  8077. end;
  8078. function TImplementedInterface.getcopy:TImplementedInterface;
  8079. var
  8080. i : longint;
  8081. begin
  8082. Result:=TImplementedInterface.Create(nil);
  8083. { 1) the procdefs list will be freed once for each copy
  8084. 2) since the procdefs list owns its elements, those will also be freed for each copy
  8085. Nope: procdefs are owned by their symtable, so no copy necessary
  8086. 3) idem for the name mappings
  8087. }
  8088. result.fIOffset:=fIOffset;
  8089. result.IntfDef:=IntfDef;
  8090. result.IntfDefDeref.reset;
  8091. result.IType:=IType;
  8092. result.VtblImplIntf:=VtblImplIntf;
  8093. if assigned(NameMappings) then
  8094. begin
  8095. result.NameMappings:=TFPHashList.create;
  8096. for i:=0 to NameMappings.Count-1 do
  8097. Result.NameMappings.Add(NameMappings.NameOfIndex(i),
  8098. stringdup(pshortstring(NameMappings.Items[i])^));
  8099. end;
  8100. if assigned(ProcDefs) then
  8101. begin
  8102. result.ProcDefs:=TFPObjectList.create(false);
  8103. { Note: this is probably wrong, because those procdefs are owned by
  8104. the old objectdef from which we copy, what would be the correct way
  8105. of doing this is to lookup the equivalent copy in the new owner
  8106. and reference this instead... But this is complicated so let's try
  8107. it this way until it blows up ok? }
  8108. for i:=0 to ProcDefs.Count-1 do
  8109. Result.ProcDefs.add(tprocdef(procdefs[i]).getcopy);
  8110. end;
  8111. result.ImplementsGetter:=ImplementsGetter;
  8112. result.ImplementsGetterDeref.reset;
  8113. result.ImplementsField:=ImplementsField;
  8114. end;
  8115. {****************************************************************************
  8116. TFORWARDDEF
  8117. ****************************************************************************}
  8118. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  8119. begin
  8120. inherited create(forwarddef,true);
  8121. tosymname:=stringdup(s);
  8122. forwardpos:=pos;
  8123. end;
  8124. function tforwarddef.GetTypeName:string;
  8125. begin
  8126. GetTypeName:='unresolved forward to '+tosymname^;
  8127. end;
  8128. destructor tforwarddef.destroy;
  8129. begin
  8130. stringdispose(tosymname);
  8131. inherited destroy;
  8132. end;
  8133. function tforwarddef.getcopy:tstoreddef;
  8134. begin
  8135. result:=cforwarddef.create(tosymname^, forwardpos);
  8136. end;
  8137. {****************************************************************************
  8138. TUNDEFINEDDEF
  8139. ****************************************************************************}
  8140. constructor tundefineddef.create(doregister:boolean);
  8141. begin
  8142. inherited create(undefineddef,doregister);
  8143. end;
  8144. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  8145. begin
  8146. inherited ppuload(undefineddef,ppufile);
  8147. ppuload_platform(ppufile);
  8148. end;
  8149. function tundefineddef.GetTypeName:string;
  8150. begin
  8151. GetTypeName:='<undefined type>';
  8152. end;
  8153. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  8154. begin
  8155. inherited ppuwrite(ppufile);
  8156. writeentry(ppufile,ibundefineddef);
  8157. end;
  8158. {****************************************************************************
  8159. TERRORDEF
  8160. ****************************************************************************}
  8161. constructor terrordef.create;
  8162. begin
  8163. inherited create(errordef,true);
  8164. { prevent consecutive faults }
  8165. savesize:=1;
  8166. end;
  8167. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  8168. begin
  8169. { Can't write errordefs to ppu }
  8170. internalerror(200411063);
  8171. end;
  8172. function terrordef.GetTypeName:string;
  8173. begin
  8174. GetTypeName:='<erroneous type>';
  8175. end;
  8176. function terrordef.getmangledparaname:TSymStr;
  8177. begin
  8178. getmangledparaname:='error';
  8179. end;
  8180. {****************************************************************************
  8181. Definition Helpers
  8182. ****************************************************************************}
  8183. function is_interfacecom(def: tdef): boolean;
  8184. begin
  8185. is_interfacecom:=
  8186. assigned(def) and
  8187. (def.typ=objectdef) and
  8188. (tobjectdef(def).objecttype=odt_interfacecom);
  8189. end;
  8190. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  8191. begin
  8192. is_interfacecom_or_dispinterface:=
  8193. assigned(def) and
  8194. (def.typ=objectdef) and
  8195. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  8196. end;
  8197. function is_any_interface_kind(def: tdef): boolean;
  8198. begin
  8199. result:=
  8200. assigned(def) and
  8201. (def.typ=objectdef) and
  8202. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  8203. is_objccategory(def));
  8204. end;
  8205. function is_interfacecorba(def: tdef): boolean;
  8206. begin
  8207. is_interfacecorba:=
  8208. assigned(def) and
  8209. (def.typ=objectdef) and
  8210. (tobjectdef(def).objecttype=odt_interfacecorba);
  8211. end;
  8212. function is_interface(def: tdef): boolean;
  8213. begin
  8214. is_interface:=
  8215. assigned(def) and
  8216. (def.typ=objectdef) and
  8217. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  8218. end;
  8219. function is_dispinterface(def: tdef): boolean;
  8220. begin
  8221. result:=
  8222. assigned(def) and
  8223. (def.typ=objectdef) and
  8224. (tobjectdef(def).objecttype=odt_dispinterface);
  8225. end;
  8226. function is_class(def: tdef): boolean;
  8227. begin
  8228. is_class:=
  8229. assigned(def) and
  8230. (def.typ=objectdef) and
  8231. (tobjectdef(def).objecttype=odt_class);
  8232. end;
  8233. function is_object(def: tdef): boolean;
  8234. begin
  8235. is_object:=
  8236. assigned(def) and
  8237. (def.typ=objectdef) and
  8238. (tobjectdef(def).objecttype=odt_object);
  8239. end;
  8240. function is_cppclass(def: tdef): boolean;
  8241. begin
  8242. is_cppclass:=
  8243. assigned(def) and
  8244. (def.typ=objectdef) and
  8245. (tobjectdef(def).objecttype=odt_cppclass);
  8246. end;
  8247. function is_objcclass(def: tdef): boolean;
  8248. begin
  8249. is_objcclass:=
  8250. assigned(def) and
  8251. (def.typ=objectdef) and
  8252. (tobjectdef(def).objecttype=odt_objcclass);
  8253. end;
  8254. function is_objectpascal_helper(def: tdef): boolean;
  8255. begin
  8256. result:=
  8257. assigned(def) and
  8258. (def.typ=objectdef) and
  8259. (tobjectdef(def).objecttype=odt_helper);
  8260. end;
  8261. function is_objcclassref(def: tdef): boolean;
  8262. begin
  8263. is_objcclassref:=
  8264. assigned(def) and
  8265. (def.typ=classrefdef) and
  8266. is_objcclass(tclassrefdef(def).pointeddef);
  8267. end;
  8268. function is_objcprotocol(def: tdef): boolean;
  8269. begin
  8270. result:=
  8271. assigned(def) and
  8272. (def.typ=objectdef) and
  8273. (tobjectdef(def).objecttype=odt_objcprotocol);
  8274. end;
  8275. function is_objccategory(def: tdef): boolean;
  8276. begin
  8277. result:=
  8278. assigned(def) and
  8279. (def.typ=objectdef) and
  8280. { if used as a forward type }
  8281. ((tobjectdef(def).objecttype=odt_objccategory) or
  8282. { if used as after it has been resolved }
  8283. ((tobjectdef(def).objecttype=odt_objcclass) and
  8284. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  8285. end;
  8286. function is_objc_class_or_protocol(def: tdef): boolean;
  8287. begin
  8288. result:=
  8289. assigned(def) and
  8290. (def.typ=objectdef) and
  8291. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  8292. end;
  8293. function is_objc_protocol_or_category(def: tdef): boolean;
  8294. begin
  8295. result:=
  8296. assigned(def) and
  8297. (def.typ=objectdef) and
  8298. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  8299. ((tobjectdef(def).objecttype = odt_objcclass) and
  8300. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  8301. end;
  8302. function is_classhelper(def: tdef): boolean;
  8303. begin
  8304. result:=
  8305. is_objectpascal_helper(def) or
  8306. is_objccategory(def);
  8307. end;
  8308. function is_class_or_interface(def: tdef): boolean;
  8309. begin
  8310. result:=
  8311. assigned(def) and
  8312. (def.typ=objectdef) and
  8313. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  8314. end;
  8315. function is_class_or_interface_or_objc(def: tdef): boolean;
  8316. begin
  8317. result:=
  8318. assigned(def) and
  8319. (def.typ=objectdef) and
  8320. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  8321. end;
  8322. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  8323. begin
  8324. result:=
  8325. assigned(def) and
  8326. (def.typ=objectdef) and
  8327. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  8328. end;
  8329. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  8330. begin
  8331. result:=
  8332. assigned(def) and
  8333. (def.typ=objectdef) and
  8334. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  8335. end;
  8336. function is_class_or_interface_or_object(def: tdef): boolean;
  8337. begin
  8338. result:=
  8339. assigned(def) and
  8340. (def.typ=objectdef) and
  8341. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  8342. end;
  8343. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  8344. begin
  8345. result:=
  8346. assigned(def) and
  8347. (def.typ=objectdef) and
  8348. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  8349. end;
  8350. function is_implicit_pointer_object_type(def: tdef): boolean;
  8351. begin
  8352. result:=
  8353. assigned(def) and
  8354. (((def.typ=objectdef) and
  8355. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  8356. ((target_info.system in systems_jvm) and
  8357. (def.typ=recorddef)));
  8358. end;
  8359. function is_implicit_array_pointer(def: tdef): boolean;
  8360. begin
  8361. result:=is_dynamic_array(def) or is_dynamicstring(def);
  8362. end;
  8363. function is_class_or_object(def: tdef): boolean;
  8364. begin
  8365. result:=
  8366. assigned(def) and
  8367. (def.typ=objectdef) and
  8368. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  8369. end;
  8370. function is_record(def: tdef): boolean;
  8371. begin
  8372. result:=
  8373. assigned(def) and
  8374. (def.typ=recorddef);
  8375. end;
  8376. function is_javaclass(def: tdef): boolean;
  8377. begin
  8378. result:=
  8379. assigned(def) and
  8380. (def.typ=objectdef) and
  8381. (tobjectdef(def).objecttype=odt_javaclass);
  8382. end;
  8383. function is_javaclassref(def: tdef): boolean;
  8384. begin
  8385. is_javaclassref:=
  8386. assigned(def) and
  8387. (def.typ=classrefdef) and
  8388. is_javaclass(tclassrefdef(def).pointeddef);
  8389. end;
  8390. function is_javainterface(def: tdef): boolean;
  8391. begin
  8392. result:=
  8393. assigned(def) and
  8394. (def.typ=objectdef) and
  8395. (tobjectdef(def).objecttype=odt_interfacejava);
  8396. end;
  8397. function is_java_class_or_interface(def: tdef): boolean;
  8398. begin
  8399. result:=
  8400. assigned(def) and
  8401. (def.typ=objectdef) and
  8402. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  8403. end;
  8404. procedure loadobjctypes;
  8405. begin
  8406. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  8407. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  8408. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  8409. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  8410. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  8411. end;
  8412. procedure maybeloadcocoatypes;
  8413. var
  8414. tsym: ttypesym;
  8415. cocoaunit: string[15];
  8416. begin
  8417. if assigned(objc_fastenumeration) then
  8418. exit;
  8419. if not(target_info.system in [system_arm_ios,system_i386_iphonesim,system_aarch64_ios,system_x86_64_iphonesim,system_aarch64_iphonesim]) then
  8420. cocoaunit:='COCOAALL'
  8421. else
  8422. cocoaunit:='IPHONEALL';
  8423. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  8424. if assigned(tsym) then
  8425. objc_fastenumeration:=tobjectdef(tsym.typedef)
  8426. else
  8427. objc_fastenumeration:=nil;
  8428. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  8429. if assigned(tsym) then
  8430. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  8431. else
  8432. objc_fastenumerationstate:=nil;
  8433. end;
  8434. function use_vectorfpu(def : tdef) : boolean;
  8435. begin
  8436. {$ifdef x86}
  8437. {$define use_vectorfpuimplemented}
  8438. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  8439. (is_double(def) and (current_settings.fputype in sse_doublescalar)) or
  8440. { Check vector types }
  8441. (
  8442. is_normal_array(def) and
  8443. (ado_IsVector in tarraydef(def).arrayoptions) and
  8444. (
  8445. (
  8446. is_single(tarraydef(def).elementdef) and
  8447. (
  8448. { SSE or AVX XMM register }
  8449. ((tarraydef(def).elecount = 4) and (current_settings.fputype in sse_singlescalar)) or
  8450. { AVX YMM register }
  8451. ((tarraydef(def).elecount = 8) and (current_settings.fputype in fpu_avx_instructionsets))
  8452. {$ifndef i8086}
  8453. or
  8454. { AVX512 ZMM register }
  8455. ((tarraydef(def).elecount = 16) and (current_settings.fputype in [fpu_avx512f]))
  8456. {$endif not i8086}
  8457. )
  8458. ) or
  8459. (
  8460. is_double(tarraydef(def).elementdef) and
  8461. (
  8462. { SSE or AVX XMM register }
  8463. ((tarraydef(def).elecount = 2) and (current_settings.fputype in sse_doublescalar)) or
  8464. { AVX YMM register }
  8465. ((tarraydef(def).elecount = 4) and (current_settings.fputype in fpu_avx_instructionsets))
  8466. {$ifndef i8086}
  8467. { AVX512 ZMM register }
  8468. or ((tarraydef(def).elecount = 8) and (current_settings.fputype in [fpu_avx512f]))
  8469. {$endif not i8086}
  8470. )
  8471. )
  8472. )
  8473. );
  8474. {$endif x86}
  8475. {$ifdef arm}
  8476. {$define use_vectorfpuimplemented}
  8477. use_vectorfpu:=FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[current_settings.fputype];
  8478. {$endif arm}
  8479. {$ifdef aarch64}
  8480. {$define use_vectorfpuimplemented}
  8481. use_vectorfpu:=true;
  8482. {$endif aarch64}
  8483. {$ifndef use_vectorfpuimplemented}
  8484. use_vectorfpu:=false;
  8485. {$endif}
  8486. end;
  8487. procedure reset_all_default_types;
  8488. { Those class pointers have to be set to nil manually }
  8489. { after memory they point to have been released. }
  8490. { Necessary strictly for Textmode IDE. }
  8491. begin
  8492. voidpointertype:=nil; { pointer for Void-pointeddef }
  8493. charpointertype:=nil; { pointer for Char-pointeddef }
  8494. widecharpointertype:=nil; { pointer for WideChar-pointeddef }
  8495. voidcodepointertype:=nil; { pointer to code; corresponds to System.CodePointer }
  8496. voidstackpointertype:=nil; { the pointer type used for accessing parameters and local vars on the stack }
  8497. parentfpvoidpointertype:=nil; { void pointer with the size of the hidden parentfp parameter, passed to nested functions }
  8498. {$ifdef x86}
  8499. voidnearpointertype:=nil;
  8500. voidnearcspointertype:=nil;
  8501. voidneardspointertype:=nil;
  8502. voidnearsspointertype:=nil;
  8503. voidnearespointertype:=nil;
  8504. voidnearfspointertype:=nil;
  8505. voidneargspointertype:=nil;
  8506. {$ifdef i8086}
  8507. voidfarpointertype:=nil;
  8508. voidhugepointertype:=nil;
  8509. charnearpointertype:=nil;
  8510. charfarpointertype:=nil;
  8511. charhugepointertype:=nil;
  8512. bytefarpointertype:=nil; { used for Mem[] }
  8513. wordfarpointertype:=nil; { used for MemW[] }
  8514. longintfarpointertype:=nil; { used for MemL[] }
  8515. {$endif i8086}
  8516. {$endif x86}
  8517. {$ifdef wasm}
  8518. wasmvoidexternreftype:=nil;
  8519. {$endif wasm}
  8520. cundefinedtype:=nil;
  8521. cformaltype:=nil; { unique formal definition }
  8522. ctypedformaltype:=nil; { unique typed formal definition }
  8523. voidtype:=nil; { Void (procedure) }
  8524. cansichartype:=nil; { Char }
  8525. cwidechartype:=nil; { WideChar }
  8526. cchartype:=nil; { either cansichartype or cwidechartype. Do not free }
  8527. pasbool1type:=nil; { boolean type }
  8528. pasbool8type:=nil;
  8529. pasbool16type:=nil;
  8530. pasbool32type:=nil;
  8531. pasbool64type:=nil;
  8532. bool8type:=nil;
  8533. bool16type:=nil;
  8534. bool32type:=nil;
  8535. bool64type:=nil;
  8536. {$ifdef llvm}
  8537. llvmbool1type:=nil; { LLVM i1 type }
  8538. {$endif llvm}
  8539. u8inttype:=nil; { 8-Bit unsigned integer }
  8540. s8inttype:=nil; { 8-Bit signed integer }
  8541. u16inttype:=nil; { 16-Bit unsigned integer }
  8542. s16inttype:=nil; { 16-Bit signed integer }
  8543. u24inttype:=nil; { 24-Bit unsigned integer }
  8544. s24inttype:=nil; { 24-Bit signed integer }
  8545. u32inttype:=nil; { 32-Bit unsigned integer }
  8546. s32inttype:=nil; { 32-Bit signed integer }
  8547. u40inttype:=nil; { 40-Bit unsigned integer }
  8548. s40inttype:=nil; { 40-Bit signed integer }
  8549. u48inttype:=nil; { 48-Bit unsigned integer }
  8550. s48inttype:=nil; { 48-Bit signed integer }
  8551. u56inttype:=nil; { 56-Bit unsigned integer }
  8552. s56inttype:=nil; { 56-Bit signed integer }
  8553. u64inttype:=nil; { 64-bit unsigned integer }
  8554. s64inttype:=nil; { 64-bit signed integer }
  8555. u128inttype:=nil; { 128-bit unsigned integer }
  8556. s128inttype:=nil; { 128-bit signed integer }
  8557. s32floattype:=nil; { 32 bit floating point number }
  8558. s64floattype:=nil; { 64 bit floating point number }
  8559. s80floattype:=nil; { 80 bit floating point number }
  8560. sc80floattype:=nil; { 80 bit floating point number but stored like in C }
  8561. s64currencytype:=nil; { pointer to a currency type }
  8562. cshortstringtype:=nil; { pointer to type of short string const }
  8563. clongstringtype:=nil; { pointer to type of long string const }
  8564. cansistringtype:=nil; { pointer to type of ansi string const }
  8565. cwidestringtype:=nil; { pointer to type of wide string const }
  8566. cunicodestringtype:=nil;
  8567. openshortstringtype:=nil;
  8568. openchararraytype:=nil;
  8569. cfiletype:=nil;
  8570. methodpointertype:=nil; { typecasting of methodpointers to extract self }
  8571. nestedprocpointertype:=nil; { typecasting of nestedprocpointers to extract parentfp }
  8572. hresultdef:=nil;
  8573. typekindtype:=nil; { def of TTypeKind for correct handling of GetTypeKind parameters }
  8574. { we use only one variant def for every variant class }
  8575. cvarianttype:=nil;
  8576. colevarianttype:=nil;
  8577. { default integer type, normally s32inttype on 32 bit systems and s64bittype on 64 bit systems }
  8578. sinttype:=nil;
  8579. uinttype:=nil;
  8580. { integer types corresponding to OS_SINT/OS_INT }
  8581. ossinttype:=nil;
  8582. osuinttype:=nil;
  8583. { integer types corresponding to the ALU size, sizeof(aint) and the ALUSInt/ALUUInt types in the system unit }
  8584. alusinttype:=nil;
  8585. aluuinttype:=nil;
  8586. { integer types corresponding to SizeInt and SizeUInt for the target platform }
  8587. sizeuinttype:=nil;
  8588. sizesinttype:=nil;
  8589. { unsigned and signed ord type with the same size as a pointer }
  8590. ptruinttype:=nil;
  8591. ptrsinttype:=nil;
  8592. { unsigned and signed ord type with the same size as a codepointer }
  8593. codeptruinttype:=nil;
  8594. codeptrsinttype:=nil;
  8595. { several types to simulate more or less C++ objects for GDB }
  8596. vmttype:=nil;
  8597. vmtarraytype:=nil;
  8598. { type of classrefs, used for stabs }
  8599. pvmttype:=nil;
  8600. { return type of the setjmp function }
  8601. exceptionreasontype:=nil;
  8602. class_tobject:=nil;
  8603. class_tcustomattribute:=nil;
  8604. interface_iunknown:=nil;
  8605. interface_idispatch:=nil;
  8606. rec_tguid:=nil;
  8607. rec_jmp_buf:=nil;
  8608. rec_exceptaddr:=nil;
  8609. objc_metaclasstype:=nil;
  8610. objc_superclasstype:=nil;
  8611. objc_idtype:=nil;
  8612. objc_seltype:=nil;
  8613. objc_objecttype:=nil;
  8614. objc_protocoltype:=nil;
  8615. objc_fastenumeration:=nil;
  8616. objc_fastenumerationstate:=nil;
  8617. {$ifdef llvm}
  8618. { llvm types }
  8619. { a unique def to identify any kind of metadata }
  8620. llvm_metadatatype:=nil;
  8621. {$endif llvm}
  8622. { Java base types }
  8623. java_jlobject:=nil;
  8624. java_jlthrowable:=nil;
  8625. java_fpcbaserecordtype:=nil;
  8626. java_jlstring:=nil;
  8627. java_jlenum:=nil;
  8628. java_juenumset:=nil;
  8629. java_jubitset:=nil;
  8630. java_ansistring:=nil;
  8631. java_shortstring:=nil;
  8632. java_procvarbase:=nil;
  8633. { x86 vector types }
  8634. x86_m64type:=nil;
  8635. x86_m128type:=nil;
  8636. x86_m128dtype:=nil;
  8637. x86_m128itype:=nil;
  8638. x86_m256type:=nil;
  8639. x86_m256dtype:=nil;
  8640. x86_m256itype:=nil;
  8641. end;
  8642. end.