symdef.pas 333 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804
  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[current_settings.fputype]) and (tfloatdef(self).floattype=s32real)
  2376. {$endif xtensa}
  2377. {$ifdef riscv}
  2378. and (((CPURV_HAS_F in cpu_capabilities[current_settings.cputype]) and (tfloatdef(self).floattype=s32real)) or
  2379. ((CPURV_HAS_D in cpu_capabilities[current_settings.cputype]) and (tfloatdef(self).floattype=s64real)) or
  2380. ((CPURV_HAS_Q in cpu_capabilities[current_settings.cputype]) and (tfloatdef(self).floattype=s128real)))
  2381. {$endif riscv}
  2382. {$ifdef arm}
  2383. and (((FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[current_settings.fputype]) and (tfloatdef(self).floattype=s32real)) or
  2384. (FPUARM_HAS_VFP_DOUBLE in fpu_capabilities[current_settings.fputype]))
  2385. {$endif arm}
  2386. ;
  2387. {$endif x86}
  2388. end;
  2389. function tstoreddef.is_const_intregable : boolean;
  2390. begin
  2391. case typ of
  2392. stringdef:
  2393. result:=tstringdef(self).stringtype in [st_ansistring,st_unicodestring,st_widestring];
  2394. arraydef:
  2395. result:=is_dynamic_array(self);
  2396. objectdef:
  2397. result:=is_interface(self);
  2398. else
  2399. result:=false;
  2400. end;
  2401. end;
  2402. procedure tstoreddef.initgeneric;
  2403. begin
  2404. if assigned(generictokenbuf) then
  2405. internalerror(200512131);
  2406. generictokenbuf:=tdynamicarray.create(256);
  2407. end;
  2408. function tstoreddef.is_generic: boolean;
  2409. var
  2410. sym: tsym;
  2411. i: longint;
  2412. begin
  2413. result:=assigned(genericparas) and
  2414. (genericparas.count>0) and
  2415. (df_generic in defoptions);
  2416. if result then
  2417. { if any of the type parameters does *not* belong to us (meaning it was passed
  2418. in from outside) then we aren't a generic, but a specialization }
  2419. for i:=0 to genericparas.count-1 do
  2420. begin
  2421. sym:=tsym(genericparas[i]);
  2422. { sym must be either a type or const }
  2423. if not (sym.typ in [symconst.typesym,symconst.constsym]) then
  2424. internalerror(2014050903);
  2425. if (sym.owner.defowner<>self) or (sp_generic_unnamed_type in sym.symoptions) then
  2426. exit(false);
  2427. if (sym.typ=symconst.constsym) and (sp_generic_const in sym.symoptions) then
  2428. exit(false);
  2429. end;
  2430. end;
  2431. function tstoreddef.is_generic_param_const(index:integer):boolean;
  2432. begin
  2433. result:=tsym(genericparas[index]).typ=constsym;
  2434. end;
  2435. function tstoreddef.get_generic_param_def(index:integer):tdef;
  2436. begin
  2437. if tsym(genericparas[index]).typ=constsym then
  2438. result:=tconstsym(genericparas[index]).constdef
  2439. else
  2440. result:=ttypesym(genericparas[index]).typedef;
  2441. end;
  2442. function tstoreddef.is_specialization: boolean;
  2443. var
  2444. i : longint;
  2445. sym : tsym;
  2446. begin
  2447. result:=assigned(genericparas) and
  2448. (genericparas.count>0) and
  2449. (df_specialization in defoptions);
  2450. if result then
  2451. begin
  2452. { if at least one of the generic parameters is not owned by us (meaning it was
  2453. passed in from outside) then we have a specialization, otherwise we have a generic }
  2454. for i:=0 to genericparas.count-1 do
  2455. begin
  2456. sym:=tsym(genericparas[i]);
  2457. { sym must be either a type or const }
  2458. if not (sym.typ in [symconst.typesym,symconst.constsym]) then
  2459. internalerror(2014050904);
  2460. if (sym.owner.defowner<>self) or (sp_generic_unnamed_type in sym.symoptions) then
  2461. exit(true);
  2462. if (sym.typ=symconst.constsym) and (sp_generic_const in sym.symoptions) then
  2463. exit(true);
  2464. end;
  2465. result:=false;
  2466. end;
  2467. end;
  2468. procedure tstoreddef.register_def;
  2469. var
  2470. gst : tgetsymtable;
  2471. st : tsymtable;
  2472. tmod : tmodule;
  2473. begin
  2474. if registered then
  2475. exit;
  2476. if assigned(owner) then
  2477. begin
  2478. tmod:=find_module_from_symtable(owner);
  2479. if assigned(tmod) and assigned(current_module) and (tmod<>current_module) then
  2480. begin
  2481. comment(v_error,'Definition '+fullownerhierarchyname(false)+' from module '+tmod.mainsource+' registered with current module '+current_module.mainsource);
  2482. end;
  2483. if not assigned(tmod) then
  2484. tmod:=current_module;
  2485. end
  2486. else
  2487. tmod:=current_module;
  2488. { Register in current_module }
  2489. if assigned(tmod) then
  2490. begin
  2491. exclude(defoptions,df_not_registered_no_free);
  2492. for gst:=low(tgetsymtable) to high(tgetsymtable) do
  2493. begin
  2494. st:=getsymtable(gst);
  2495. if assigned(st) then
  2496. tstoredsymtable(st).register_children;
  2497. end;
  2498. if defid<defid_not_registered then
  2499. defid:=deflist_index
  2500. else
  2501. begin
  2502. tmod.deflist.Add(self);
  2503. defid:=tmod.deflist.Count-1;
  2504. registered_in_module:=tmod;
  2505. end;
  2506. maybe_put_in_symtable_stack;
  2507. end
  2508. else
  2509. DefId:=defid_registered_nost;
  2510. end;
  2511. procedure tstoreddef.maybe_put_in_symtable_stack;
  2512. var
  2513. insertstack: psymtablestackitem;
  2514. begin
  2515. if assigned(symtablestack) and
  2516. not assigned(self.owner) then
  2517. begin
  2518. insertstack:=symtablestack.stack;
  2519. { don't insert defs in exception symtables, as they are freed before
  2520. the module is compiled, so we can get crashes on high level targets
  2521. if they still need it while e.g. writing assembler code }
  2522. while assigned(insertstack) and
  2523. (insertstack^.symtable.symtabletype in [exceptsymtable,withsymtable]) do
  2524. insertstack:=insertstack^.next;
  2525. if not assigned(insertstack) then
  2526. internalerror(200602044);
  2527. if insertstack^.symtable.sealed then
  2528. internalerror(2015022301);
  2529. insertstack^.symtable.insertdef(self);
  2530. end;
  2531. end;
  2532. {****************************************************************************
  2533. Tstringdef
  2534. ****************************************************************************}
  2535. constructor tstringdef.createshort(l: byte; doregister: boolean);
  2536. begin
  2537. inherited create(stringdef,doregister);
  2538. stringtype:=st_shortstring;
  2539. encoding:=0;
  2540. len:=l;
  2541. end;
  2542. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  2543. begin
  2544. inherited ppuload(stringdef,ppufile);
  2545. stringtype:=st_shortstring;
  2546. encoding:=0;
  2547. len:=ppufile.getbyte;
  2548. ppuload_platform(ppufile);
  2549. end;
  2550. constructor tstringdef.createlong(l: asizeint; doregister: boolean);
  2551. begin
  2552. inherited create(stringdef,doregister);
  2553. stringtype:=st_longstring;
  2554. encoding:=0;
  2555. len:=l;
  2556. end;
  2557. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  2558. begin
  2559. inherited ppuload(stringdef,ppufile);
  2560. stringtype:=st_longstring;
  2561. encoding:=0;
  2562. len:=ppufile.getasizeint;
  2563. ppuload_platform(ppufile);
  2564. end;
  2565. constructor tstringdef.createansi(aencoding: tstringencoding; doregister: boolean);
  2566. begin
  2567. inherited create(stringdef,doregister);
  2568. stringtype:=st_ansistring;
  2569. encoding:=aencoding;
  2570. len:=-1;
  2571. end;
  2572. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  2573. begin
  2574. inherited ppuload(stringdef,ppufile);
  2575. stringtype:=st_ansistring;
  2576. len:=ppufile.getasizeint;
  2577. encoding:=ppufile.getword;
  2578. ppuload_platform(ppufile);
  2579. end;
  2580. constructor tstringdef.createwide(doregister: boolean);
  2581. begin
  2582. inherited create(stringdef,doregister);
  2583. stringtype:=st_widestring;
  2584. if target_info.endian=endian_little then
  2585. encoding:=CP_UTF16LE
  2586. else
  2587. encoding:=CP_UTF16BE;
  2588. len:=-1;
  2589. end;
  2590. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  2591. begin
  2592. inherited ppuload(stringdef,ppufile);
  2593. stringtype:=st_widestring;
  2594. if target_info.endian=endian_little then
  2595. encoding:=CP_UTF16LE
  2596. else
  2597. encoding:=CP_UTF16BE;
  2598. len:=ppufile.getasizeint;
  2599. ppuload_platform(ppufile);
  2600. end;
  2601. constructor tstringdef.createunicode(doregister: boolean);
  2602. begin
  2603. inherited create(stringdef,doregister);
  2604. stringtype:=st_unicodestring;
  2605. if target_info.endian=endian_little then
  2606. encoding:=CP_UTF16LE
  2607. else
  2608. encoding:=CP_UTF16BE;
  2609. len:=-1;
  2610. end;
  2611. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  2612. begin
  2613. inherited ppuload(stringdef,ppufile);
  2614. stringtype:=st_unicodestring;
  2615. len:=ppufile.getasizeint;
  2616. encoding:=ppufile.getword;
  2617. ppuload_platform(ppufile);
  2618. end;
  2619. function tstringdef.getcopy : tstoreddef;
  2620. begin
  2621. result:=cstringdef.create(typ,true);
  2622. result.typ:=stringdef;
  2623. tstringdef(result).stringtype:=stringtype;
  2624. tstringdef(result).encoding:=encoding;
  2625. tstringdef(result).len:=len;
  2626. end;
  2627. function tstringdef.stringtypname:string;
  2628. const
  2629. typname:array[tstringtype] of string[10]=(
  2630. 'shortstr','longstr','ansistr','widestr','unicodestr'
  2631. );
  2632. begin
  2633. stringtypname:=typname[stringtype];
  2634. end;
  2635. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  2636. begin
  2637. inherited ppuwrite(ppufile);
  2638. if stringtype=st_shortstring then
  2639. begin
  2640. {$ifdef extdebug}
  2641. if len > 255 then internalerror(12122002);
  2642. {$endif}
  2643. ppufile.putbyte(byte(len))
  2644. end
  2645. else
  2646. ppufile.putasizeint(len);
  2647. if stringtype in [st_ansistring,st_unicodestring] then
  2648. ppufile.putword(encoding);
  2649. case stringtype of
  2650. st_shortstring : writeentry(ppufile,ibshortstringdef);
  2651. st_longstring : writeentry(ppufile,iblongstringdef);
  2652. st_ansistring : writeentry(ppufile,ibansistringdef);
  2653. st_widestring : writeentry(ppufile,ibwidestringdef);
  2654. st_unicodestring : writeentry(ppufile,ibunicodestringdef);
  2655. end;
  2656. end;
  2657. function tstringdef.needs_inittable : boolean;
  2658. begin
  2659. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  2660. end;
  2661. function tstringdef.GetTypeName : string;
  2662. const
  2663. names : array[tstringtype] of string[15] = (
  2664. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  2665. begin
  2666. GetTypeName:=names[stringtype];
  2667. case stringtype of
  2668. st_ansistring,st_unicodestring:
  2669. GetTypeName:=GetTypeName+'('+tostr(encoding)+')';
  2670. st_shortstring:
  2671. GetTypeName:=GetTypeName+'['+tostr(len)+']';
  2672. else
  2673. ;
  2674. end;
  2675. end;
  2676. function tstringdef.getvardef : longint;
  2677. const
  2678. vardef : array[tstringtype] of longint = (
  2679. varUndefined,varUndefined,varString,varOleStr,varUString);
  2680. begin
  2681. result:=vardef[stringtype];
  2682. end;
  2683. function tstringdef.get_default_char_type: tdef;
  2684. begin
  2685. case stringtype of
  2686. st_shortstring,
  2687. st_longstring,
  2688. st_ansistring:
  2689. result:=cansichartype;
  2690. st_unicodestring,
  2691. st_widestring:
  2692. result:=cwidechartype;
  2693. end;
  2694. end;
  2695. function tstringdef.get_default_string_type: tdef;
  2696. begin
  2697. case stringtype of
  2698. st_shortstring:
  2699. result:=cshortstringtype;
  2700. { st_longstring is currently not supported but
  2701. when it is this case will need to be supplied }
  2702. st_longstring:
  2703. internalerror(2021040801);
  2704. st_ansistring:
  2705. result:=cansistringtype;
  2706. st_widestring:
  2707. result:=cwidestringtype;
  2708. st_unicodestring:
  2709. result:=cunicodestringtype;
  2710. end
  2711. end;
  2712. function tstringdef.alignment : shortint;
  2713. begin
  2714. case stringtype of
  2715. st_unicodestring,
  2716. st_widestring,
  2717. st_ansistring:
  2718. alignment:=voidpointertype.alignment;
  2719. st_longstring,
  2720. st_shortstring:
  2721. { char to string accesses byte 0 and 1 with one word access }
  2722. if (tf_requires_proper_alignment in target_info.flags) or
  2723. { macpas needs an alignment of 2 (MetroWerks compatible) }
  2724. (m_mac in current_settings.modeswitches) then
  2725. alignment:=size_2_align(2)
  2726. else
  2727. alignment:=size_2_align(1);
  2728. end;
  2729. end;
  2730. function tstringdef.getmangledparaname : TSymStr;
  2731. begin
  2732. getmangledparaname:='STRING';
  2733. end;
  2734. function tstringdef.is_publishable : tpublishproperty;
  2735. begin
  2736. is_publishable:=pp_publish;
  2737. end;
  2738. function tstringdef.size: asizeint;
  2739. begin
  2740. case stringtype of
  2741. st_shortstring:
  2742. Result:=len+1;
  2743. st_longstring,
  2744. st_ansistring,
  2745. st_widestring,
  2746. st_unicodestring:
  2747. Result:=voidpointertype.size;
  2748. end;
  2749. end;
  2750. {****************************************************************************
  2751. TENUMDEF
  2752. ****************************************************************************}
  2753. constructor tenumdef.create;
  2754. begin
  2755. inherited create(enumdef,true);
  2756. minval:=0;
  2757. maxval:=0;
  2758. calcsavesize(current_settings.packenum);
  2759. has_jumps:=false;
  2760. basedef:=nil;
  2761. basedefderef.reset;
  2762. symtable:=tenumsymtable.create(self);
  2763. end;
  2764. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  2765. begin
  2766. inherited create(enumdef,true);
  2767. minval:=_min;
  2768. maxval:=_max;
  2769. basedef:=_basedef;
  2770. calcsavesize(current_settings.packenum);
  2771. has_jumps:=false;
  2772. symtable:=basedef.symtable.getcopy;
  2773. include(defoptions, df_copied_def);
  2774. end;
  2775. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  2776. begin
  2777. inherited ppuload(enumdef,ppufile);
  2778. minval:=ppufile.getaint;
  2779. maxval:=ppufile.getaint;
  2780. savesize:=ppufile.getaint;
  2781. has_jumps:=false;
  2782. if df_copied_def in defoptions then
  2783. begin
  2784. symtable:=nil;
  2785. ppufile.getderef(basedefderef);
  2786. ppuload_platform(ppufile);
  2787. end
  2788. else
  2789. begin
  2790. ppuload_platform(ppufile);
  2791. // create with nil defowner first to prevent values changes on insert
  2792. symtable:=tenumsymtable.create(nil);
  2793. tenumsymtable(symtable).ppuload(ppufile);
  2794. symtable.defowner:=self;
  2795. end;
  2796. end;
  2797. destructor tenumdef.destroy;
  2798. begin
  2799. symtable.free;
  2800. symtable:=nil;
  2801. inherited destroy;
  2802. end;
  2803. function tenumdef.getcopy : tstoreddef;
  2804. begin
  2805. if assigned(basedef) then
  2806. result:=cenumdef.create_subrange(basedef,minval,maxval)
  2807. else
  2808. begin
  2809. result:=cenumdef.create;
  2810. tenumdef(result).minval:=minval;
  2811. tenumdef(result).maxval:=maxval;
  2812. tenumdef(result).symtable.free;
  2813. tenumdef(result).symtable:=symtable.getcopy;
  2814. tenumdef(result).basedef:=self;
  2815. end;
  2816. tenumdef(result).has_jumps:=has_jumps;
  2817. tenumdef(result).basedefderef:=basedefderef;
  2818. include(tenumdef(result).defoptions,df_copied_def);
  2819. end;
  2820. procedure tenumdef.calcsavesize(packenum: shortint);
  2821. begin
  2822. {$IFNDEF cpu64bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2823. if (packenum=8) or (int64(min)<low(longint)) or (int64(max)>high(cardinal)) or ((min<0) and (max>high(longint))) then
  2824. savesize:=8
  2825. {$IFNDEF cpu64bitaddr} {$pop} {$ENDIF}
  2826. else
  2827. {$IFDEF cpu16bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2828. if (packenum=4) or (min<low(smallint)) or (max>high(word)) or ((min<0) and (max>high(smallint))) then
  2829. savesize:=4
  2830. {$IFDEF cpu16bitaddr} {$pop} {$ENDIF}
  2831. else
  2832. if (packenum=2) or (min<low(shortint)) or (max>high(byte)) or ((min<0) and (max>high(shortint))) then
  2833. savesize:=2
  2834. else
  2835. savesize:=1;
  2836. end;
  2837. function tenumdef.packedbitsize: asizeint;
  2838. var
  2839. sizeval: tconstexprint;
  2840. power: longint;
  2841. begin
  2842. result := 0;
  2843. if (minval >= 0) and
  2844. (maxval <= 1) then
  2845. result := 1
  2846. else
  2847. begin
  2848. if (minval>=0) then
  2849. sizeval:=maxval
  2850. else
  2851. { don't count 0 twice, but take into account that range goes from -n-1..n }
  2852. sizeval:=(cutils.max(-minval,maxval+1)*2)-1;
  2853. { 256 must become 512 etc. }
  2854. nextpowerof2(sizeval+1,power);
  2855. result := power;
  2856. end;
  2857. end;
  2858. procedure tenumdef.setmax(_max:asizeint);
  2859. begin
  2860. maxval:=_max;
  2861. calcsavesize(current_settings.packenum);
  2862. end;
  2863. procedure tenumdef.setmin(_min:asizeint);
  2864. begin
  2865. minval:=_min;
  2866. calcsavesize(current_settings.packenum);
  2867. end;
  2868. function tenumdef.min:asizeint;
  2869. begin
  2870. min:=minval;
  2871. end;
  2872. function tenumdef.max:asizeint;
  2873. begin
  2874. max:=maxval;
  2875. end;
  2876. function tenumdef.getfirstsym: tsym;
  2877. var
  2878. i:integer;
  2879. begin
  2880. for i := 0 to symtable.SymList.Count - 1 do
  2881. begin
  2882. result:=tsym(symtable.SymList[i]);
  2883. if tenumsym(result).value=minval then
  2884. exit;
  2885. end;
  2886. result:=nil;
  2887. end;
  2888. function tenumdef.int2enumsym(l: asizeint): tsym;
  2889. var
  2890. i: longint;
  2891. sym: tsym;
  2892. bdef: tenumdef;
  2893. begin
  2894. result:=nil;
  2895. if (l<minval) or
  2896. (l>maxval) then
  2897. exit;
  2898. bdef:=getbasedef;
  2899. for i:=0 to bdef.symtable.symlist.count-1 do
  2900. begin
  2901. sym:=tsym(bdef.symtable.symlist[i]);
  2902. if (sym.typ=enumsym) and
  2903. (tenumsym(sym).value=l) then
  2904. begin
  2905. result:=sym;
  2906. exit;
  2907. end;
  2908. end;
  2909. end;
  2910. function tenumdef.getbasedef: tenumdef;
  2911. begin
  2912. if not assigned(basedef) then
  2913. result:=self
  2914. else
  2915. result:=basedef;
  2916. end;
  2917. procedure tenumdef.buildderef;
  2918. begin
  2919. inherited buildderef;
  2920. if df_copied_def in defoptions then
  2921. basedefderef.build(basedef)
  2922. else
  2923. tenumsymtable(symtable).buildderef;
  2924. end;
  2925. procedure tenumdef.deref;
  2926. begin
  2927. inherited deref;
  2928. if df_copied_def in defoptions then
  2929. begin
  2930. basedef:=tenumdef(basedefderef.resolve);
  2931. symtable:=basedef.symtable.getcopy;
  2932. end
  2933. else
  2934. tenumsymtable(symtable).deref(false);
  2935. end;
  2936. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  2937. begin
  2938. inherited ppuwrite(ppufile);
  2939. ppufile.putaint(min);
  2940. ppufile.putaint(max);
  2941. ppufile.putaint(savesize);
  2942. if df_copied_def in defoptions then
  2943. ppufile.putderef(basedefderef);
  2944. writeentry(ppufile,ibenumdef);
  2945. if not (df_copied_def in defoptions) then
  2946. tenumsymtable(symtable).ppuwrite(ppufile);
  2947. end;
  2948. function tenumdef.is_publishable : tpublishproperty;
  2949. begin
  2950. if not has_jumps then
  2951. is_publishable:=pp_publish
  2952. else
  2953. if m_delphi in current_settings.modeswitches then
  2954. is_publishable:=pp_ignore
  2955. else
  2956. is_publishable:=pp_error;
  2957. end;
  2958. function tenumdef.GetTypeName : string;
  2959. begin
  2960. GetTypeName:='<enumeration type>';
  2961. end;
  2962. {****************************************************************************
  2963. TRTTI_ATTRIBUTE_LIST
  2964. ****************************************************************************}
  2965. constructor trtti_attribute.ppuload(ppufile: tcompilerppufile);
  2966. begin
  2967. ppufile.getderef(typesymderef);
  2968. ppufile.getderef(typeconstrderef);
  2969. setlength(paras,ppufile.getlongint);
  2970. end;
  2971. procedure trtti_attribute.ppuwrite(ppufile: tcompilerppufile);
  2972. begin
  2973. ppufile.putderef(typesymderef);
  2974. ppufile.putderef(typeconstrderef);
  2975. ppufile.putlongint(length(paras));
  2976. end;
  2977. procedure trtti_attribute.ppuload_subentries(ppufile: tcompilerppufile);
  2978. var
  2979. i : sizeint;
  2980. begin
  2981. for i:=0 to high(paras) do
  2982. paras[i]:=ppuloadnodetree(ppufile);
  2983. end;
  2984. procedure trtti_attribute.ppuwrite_subentries(ppufile: tcompilerppufile);
  2985. var
  2986. i : sizeint;
  2987. begin
  2988. for i:=0 to high(paras) do
  2989. ppuwritenodetree(ppufile,paras[i]);
  2990. end;
  2991. destructor trtti_attribute.destroy;
  2992. var
  2993. n : tnode;
  2994. begin
  2995. constructorcall.free;
  2996. for n in paras do
  2997. n.free;
  2998. inherited destroy;
  2999. end;
  3000. procedure trtti_attribute.buildderef;
  3001. var
  3002. i : sizeint;
  3003. begin
  3004. typesymderef.build(typesym);
  3005. typeconstrderef.build(typeconstr);
  3006. for i:=0 to high(paras) do
  3007. paras[i].buildderefimpl;
  3008. end;
  3009. procedure trtti_attribute.deref;
  3010. var
  3011. i : sizeint;
  3012. begin
  3013. typesym:=tsym(typesymderef.resolve);
  3014. typeconstr:=tdef(typeconstrderef.resolve);
  3015. for i:=0 to high(paras) do
  3016. paras[i].derefimpl;
  3017. end;
  3018. class procedure trtti_attribute_list.bind(var dangling,owned:trtti_attribute_list);
  3019. begin
  3020. if assigned(owned) then
  3021. internalerror(2019071001);
  3022. if not assigned(dangling) then
  3023. exit;
  3024. if dangling.is_bound then
  3025. internalerror(2019071002);
  3026. current_module.used_rtti_attrs.concatlistcopy(dangling.rtti_attributes);
  3027. dangling.is_bound:=true;
  3028. owned:=dangling;
  3029. dangling:=nil;
  3030. end;
  3031. class procedure trtti_attribute_list.copyandbind(alist : trtti_attribute_list; var owned: trtti_attribute_list);
  3032. var
  3033. i,j : Integer;
  3034. attr,newattribute : trtti_attribute;
  3035. begin
  3036. if owned=Nil then
  3037. owned:=trtti_attribute_list.Create;
  3038. owned.is_bound:=True;
  3039. for i:=0 to aList.rtti_attributes.Count-1 do
  3040. begin
  3041. attr:=trtti_attribute(alist.rtti_attributes[i]);
  3042. newattribute:=trtti_attribute.Create;
  3043. newattribute.typesym:=attr.typesym;
  3044. newattribute.typeconstr:=attr.typeconstr;
  3045. newattribute.constructorcall:=attr.constructorcall.getcopy;
  3046. setlength(newattribute.paras,length(attr.paras));
  3047. for j:=0 to length(attr.paras)-1 do
  3048. newattribute.paras[j]:=attr.paras[j].getcopy;
  3049. owned.AddAttribute(newattribute);
  3050. end;
  3051. current_module.used_rtti_attrs.concatlistcopy(owned.rtti_attributes);
  3052. end;
  3053. procedure trtti_attribute_list.addattribute(atypesym:tsym;typeconstr:tdef;constructorcall:tnode;constref paras:array of tnode);
  3054. var
  3055. newattribute : trtti_attribute;
  3056. i : sizeint;
  3057. begin
  3058. if not assigned(rtti_attributes) then
  3059. rtti_attributes:=TFPObjectList.Create(true);
  3060. newattribute:=trtti_attribute.Create;
  3061. newattribute.typesym:=atypesym;
  3062. newattribute.typeconstr:=typeconstr;
  3063. newattribute.constructorcall:=constructorcall;
  3064. setlength(newattribute.paras,length(paras));
  3065. for i:=0 to high(paras) do
  3066. newattribute.paras[i]:=paras[i];
  3067. rtti_attributes.Add(newattribute);
  3068. end;
  3069. procedure trtti_attribute_list.addattribute(attr:trtti_attribute);
  3070. begin
  3071. if not assigned(rtti_attributes) then
  3072. rtti_attributes:=TFPObjectList.Create(true);
  3073. rtti_attributes.add(attr);
  3074. end;
  3075. destructor trtti_attribute_list.destroy;
  3076. begin
  3077. rtti_attributes.Free;
  3078. inherited destroy;
  3079. end;
  3080. function trtti_attribute_list.get_attribute_count:longint;
  3081. begin
  3082. if assigned(rtti_attributes) then
  3083. result:=rtti_attributes.Count
  3084. else
  3085. result:=0;
  3086. end;
  3087. procedure trtti_attribute_list.buildderef;
  3088. var
  3089. i : sizeint;
  3090. begin
  3091. if not assigned(rtti_attributes) then
  3092. exit;
  3093. for i:=0 to rtti_attributes.count-1 do
  3094. trtti_attribute(rtti_attributes[i]).buildderef;
  3095. end;
  3096. procedure trtti_attribute_list.deref;
  3097. var
  3098. i : sizeint;
  3099. begin
  3100. if not assigned(rtti_attributes) then
  3101. exit;
  3102. for i:=0 to rtti_attributes.count-1 do
  3103. trtti_attribute(rtti_attributes[i]).deref;
  3104. end;
  3105. class procedure trtti_attribute_list.ppuload_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3106. var
  3107. i : sizeint;
  3108. begin
  3109. if assigned(attrlist) then
  3110. begin
  3111. if not assigned(attrlist.rtti_attributes) then
  3112. internalerror(2019071101);
  3113. for i:=0 to attrlist.rtti_attributes.count-1 do
  3114. trtti_attribute(attrlist.rtti_attributes[i]).ppuload_subentries(ppufile);
  3115. end;
  3116. end;
  3117. class procedure trtti_attribute_list.ppuwrite_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3118. var
  3119. i : sizeint;
  3120. begin
  3121. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  3122. begin
  3123. for i:=0 to attrlist.rtti_attributes.count-1 do
  3124. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite_subentries(ppufile);
  3125. end;
  3126. end;
  3127. class function trtti_attribute_list.ppuload(ppufile:tcompilerppufile):trtti_attribute_list;
  3128. var
  3129. cnt,i : longint;
  3130. begin
  3131. cnt:=ppufile.getlongint;
  3132. if cnt>0 then
  3133. begin
  3134. result:=trtti_attribute_list.create;
  3135. for i:=0 to cnt-1 do
  3136. result.addattribute(trtti_attribute.ppuload(ppufile));
  3137. end
  3138. else
  3139. result:=nil;
  3140. end;
  3141. class procedure trtti_attribute_list.ppuwrite(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3142. var
  3143. i : longint;
  3144. begin
  3145. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  3146. begin
  3147. ppufile.putlongint(attrlist.rtti_attributes.count);
  3148. for i:=0 to attrlist.rtti_attributes.count-1 do
  3149. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite(ppufile);
  3150. end
  3151. else
  3152. ppufile.putlongint(0);
  3153. end;
  3154. {****************************************************************************
  3155. TORDDEF
  3156. ****************************************************************************}
  3157. constructor torddef.create(t : tordtype;v,b : TConstExprInt; doregister: boolean);
  3158. begin
  3159. inherited create(orddef,doregister);
  3160. low:=v;
  3161. high:=b;
  3162. ordtype:=t;
  3163. setsize;
  3164. end;
  3165. constructor torddef.ppuload(ppufile:tcompilerppufile);
  3166. begin
  3167. inherited ppuload(orddef,ppufile);
  3168. ordtype:=tordtype(ppufile.getbyte);
  3169. low:=ppufile.getexprint;
  3170. high:=ppufile.getexprint;
  3171. setsize;
  3172. ppuload_platform(ppufile);
  3173. end;
  3174. function torddef.getcopy : tstoreddef;
  3175. begin
  3176. result:=corddef.create(ordtype,low,high,true);
  3177. result.typ:=orddef;
  3178. torddef(result).low:=low;
  3179. torddef(result).high:=high;
  3180. torddef(result).ordtype:=ordtype;
  3181. torddef(result).savesize:=savesize;
  3182. end;
  3183. function torddef.alignment:shortint;
  3184. begin
  3185. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) and
  3186. (ordtype in [s64bit,u64bit]) then
  3187. result := 4
  3188. else
  3189. result := inherited alignment;
  3190. end;
  3191. procedure torddef.setsize;
  3192. const
  3193. sizetbl : array[tordtype] of longint = (
  3194. 0,
  3195. 1,2,4,8,16,
  3196. 1,2,4,8,16,
  3197. 1,1,2,4,8,
  3198. 1,2,4,8,
  3199. 1,2,8,system.high(longint)
  3200. );
  3201. begin
  3202. savesize:=sizetbl[ordtype];
  3203. if savesize=system.high(longint) then
  3204. savesize:=packedbitsize div 8;
  3205. end;
  3206. function torddef.packedbitsize: asizeint;
  3207. var
  3208. sizeval: tconstexprint;
  3209. power: longint;
  3210. begin
  3211. result := 0;
  3212. if ordtype = uvoid then
  3213. exit;
  3214. {$ifndef cpu64bitalu}
  3215. if (ordtype in [s64bit,u64bit]) then
  3216. {$else not cpu64bitalu}
  3217. if ((ordtype = u64bit) and
  3218. (high > system.high(int64))) or
  3219. ((ordtype = s64bit) and
  3220. ((low <= (system.low(int64) div 2)) or
  3221. ((low < 0) and
  3222. (high > (system.high(int64) div 2))))) then
  3223. {$endif cpu64bitalu}
  3224. result := 64
  3225. else if (
  3226. (low >= 0) and
  3227. (high <= 1)
  3228. ) or (
  3229. ordtype in [pasbool1,pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit]
  3230. ) then
  3231. result := 1
  3232. else
  3233. begin
  3234. if (low>=0) then
  3235. sizeval:=high
  3236. else
  3237. { don't count 0 twice, but take into account that range goes from -n-1..n }
  3238. sizeval:=(cutils.max(-low,high+1)*2)-1;
  3239. { 256 must become 512 etc. }
  3240. nextpowerof2(sizeval+1,power);
  3241. result := power;
  3242. end;
  3243. end;
  3244. function torddef.getvardef : longint;
  3245. const
  3246. basetype2vardef : array[tordtype] of longint = (
  3247. varUndefined,
  3248. varbyte,varword,varlongword,varqword,varUndefined,
  3249. varshortint,varsmallint,varinteger,varint64,varUndefined,
  3250. varboolean,varboolean,varboolean,varboolean,varboolean,
  3251. varboolean,varboolean,varUndefined,varUndefined,
  3252. varUndefined,varUndefined,varCurrency,varEmpty);
  3253. begin
  3254. result:=basetype2vardef[ordtype];
  3255. if result=varEmpty then
  3256. result:=basetype2vardef[range_to_basetype(low,high)];
  3257. end;
  3258. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  3259. begin
  3260. inherited ppuwrite(ppufile);
  3261. ppufile.putbyte(byte(ordtype));
  3262. ppufile.putexprint(low);
  3263. ppufile.putexprint(high);
  3264. writeentry(ppufile,iborddef);
  3265. end;
  3266. function torddef.is_publishable : tpublishproperty;
  3267. begin
  3268. if ordtype<>uvoid then
  3269. is_publishable:=pp_publish
  3270. else
  3271. is_publishable:=pp_error;
  3272. end;
  3273. function torddef.GetTypeName : string;
  3274. const
  3275. names : array[tordtype] of string[20] = (
  3276. 'untyped',
  3277. 'Byte','Word','DWord','QWord','UInt128',
  3278. 'ShortInt','SmallInt','LongInt','Int64','Int128',
  3279. 'Boolean','Boolean8','Boolean16','Boolean32','Boolean64',
  3280. 'ByteBool','WordBool','LongBool','QWordBool',
  3281. 'AnsiChar','WideChar','Currency','CustomRange');
  3282. begin
  3283. GetTypeName:=names[ordtype];
  3284. end;
  3285. {****************************************************************************
  3286. TFLOATDEF
  3287. ****************************************************************************}
  3288. constructor tfloatdef.create(t: tfloattype; doregister: boolean);
  3289. begin
  3290. inherited create(floatdef,doregister);
  3291. floattype:=t;
  3292. setsize;
  3293. end;
  3294. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  3295. begin
  3296. inherited ppuload(floatdef,ppufile);
  3297. floattype:=tfloattype(ppufile.getbyte);
  3298. setsize;
  3299. ppuload_platform(ppufile);
  3300. end;
  3301. function tfloatdef.getcopy : tstoreddef;
  3302. begin
  3303. result:=cfloatdef.create(floattype,true);
  3304. result.typ:=floatdef;
  3305. tfloatdef(result).savesize:=savesize;
  3306. end;
  3307. function tfloatdef.alignment:shortint;
  3308. begin
  3309. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) then
  3310. case floattype of
  3311. sc80real,
  3312. s80real: result:=16;
  3313. s64real,
  3314. s64currency,
  3315. s64comp : result:=4;
  3316. else
  3317. result := inherited alignment;
  3318. end
  3319. else
  3320. result := inherited alignment;
  3321. end;
  3322. function tfloatdef.structalignment: shortint;
  3323. begin
  3324. { aix is really annoying: the recommended scalar alignment for both
  3325. int64 and double is 64 bits, but in structs int64 has to be aligned
  3326. to 8 bytes and double to 4 bytes }
  3327. if (target_info.system in systems_aix) and
  3328. (floattype=s64real) then
  3329. result:=4
  3330. else
  3331. result:=alignment;
  3332. end;
  3333. procedure tfloatdef.setsize;
  3334. begin
  3335. case floattype of
  3336. s32real : savesize:=4;
  3337. s80real : savesize:=10;
  3338. sc80real:
  3339. if target_info.system in [system_i386_darwin,
  3340. system_i386_iphonesim,system_x86_64_darwin,
  3341. system_x86_64_iphonesim,
  3342. system_x86_64_linux,system_x86_64_freebsd,
  3343. system_x86_64_openbsd,system_x86_64_netbsd,
  3344. system_x86_64_solaris,system_x86_64_embedded,
  3345. system_x86_64_dragonfly,system_x86_64_haiku] then
  3346. savesize:=16
  3347. else
  3348. savesize:=12;
  3349. s64real,
  3350. s64currency,
  3351. s64comp : savesize:=8;
  3352. else
  3353. savesize:=0;
  3354. end;
  3355. end;
  3356. function tfloatdef.getvardef : longint;
  3357. const
  3358. floattype2vardef : array[tfloattype] of longint = (
  3359. varSingle,varDouble,varUndefined,varUndefined,
  3360. varUndefined,varCurrency,varUndefined);
  3361. begin
  3362. if (upper(typename)='TDATETIME') and
  3363. assigned(owner) and
  3364. assigned(owner.name) and
  3365. (owner.name^='SYSTEM') then
  3366. result:=varDate
  3367. else
  3368. result:=floattype2vardef[floattype];
  3369. end;
  3370. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  3371. begin
  3372. inherited ppuwrite(ppufile);
  3373. ppufile.putbyte(byte(floattype));
  3374. writeentry(ppufile,ibfloatdef);
  3375. end;
  3376. function tfloatdef.is_publishable : tpublishproperty;
  3377. begin
  3378. is_publishable:=pp_publish;
  3379. end;
  3380. function tfloatdef.GetTypeName : string;
  3381. const
  3382. names : array[tfloattype] of string[20] = (
  3383. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  3384. begin
  3385. GetTypeName:=names[floattype];
  3386. end;
  3387. {****************************************************************************
  3388. TFILEDEF
  3389. ****************************************************************************}
  3390. constructor tfiledef.createtext;
  3391. begin
  3392. inherited create(filedef,true);
  3393. filetyp:=ft_text;
  3394. typedfiledef:=nil;
  3395. typedfiledefderef.reset;
  3396. end;
  3397. constructor tfiledef.createuntyped;
  3398. begin
  3399. inherited create(filedef,true);
  3400. filetyp:=ft_untyped;
  3401. typedfiledef:=nil;
  3402. end;
  3403. constructor tfiledef.createtyped(def:tdef);
  3404. begin
  3405. inherited create(filedef,true);
  3406. filetyp:=ft_typed;
  3407. typedfiledef:=def;
  3408. end;
  3409. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  3410. begin
  3411. inherited ppuload(filedef,ppufile);
  3412. filetyp:=tfiletyp(ppufile.getbyte);
  3413. if filetyp=ft_typed then
  3414. ppufile.getderef(typedfiledefderef)
  3415. else
  3416. typedfiledef:=nil;
  3417. ppuload_platform(ppufile);
  3418. end;
  3419. function tfiledef.getcopy : tstoreddef;
  3420. begin
  3421. case filetyp of
  3422. ft_typed:
  3423. result:=cfiledef.createtyped(typedfiledef);
  3424. ft_untyped:
  3425. result:=cfiledef.createuntyped;
  3426. ft_text:
  3427. result:=cfiledef.createtext;
  3428. end;
  3429. end;
  3430. procedure tfiledef.buildderef;
  3431. begin
  3432. inherited buildderef;
  3433. if filetyp=ft_typed then
  3434. typedfiledefderef.build(typedfiledef);
  3435. end;
  3436. procedure tfiledef.deref;
  3437. begin
  3438. inherited deref;
  3439. if filetyp=ft_typed then
  3440. typedfiledef:=tdef(typedfiledefderef.resolve);
  3441. end;
  3442. function tfiledef.size:asizeint;
  3443. begin
  3444. if savesize=0 then
  3445. setsize;
  3446. size:=savesize;
  3447. end;
  3448. procedure tfiledef.setsize;
  3449. begin
  3450. case filetyp of
  3451. ft_text:
  3452. savesize:=search_system_type('TEXTREC').typedef.size;
  3453. ft_typed:
  3454. begin
  3455. savesize:=search_system_type('FILEREC').typedef.size;
  3456. { allocate put/get buffer in iso mode }
  3457. if m_isolike_io in current_settings.modeswitches then
  3458. inc(savesize,typedfiledef.size);
  3459. end;
  3460. ft_untyped:
  3461. savesize:=search_system_type('FILEREC').typedef.size;
  3462. end;
  3463. end;
  3464. function tfiledef.alignment: shortint;
  3465. begin
  3466. case filetyp of
  3467. ft_text:
  3468. result:=search_system_type('TEXTREC').typedef.alignment;
  3469. ft_typed,
  3470. ft_untyped:
  3471. result:=search_system_type('FILEREC').typedef.alignment;
  3472. end;
  3473. end;
  3474. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  3475. begin
  3476. inherited ppuwrite(ppufile);
  3477. ppufile.putbyte(byte(filetyp));
  3478. if filetyp=ft_typed then
  3479. ppufile.putderef(typedfiledefderef);
  3480. writeentry(ppufile,ibfiledef);
  3481. end;
  3482. function tfiledef.GetTypeName : string;
  3483. begin
  3484. case filetyp of
  3485. ft_untyped:
  3486. GetTypeName:='File';
  3487. ft_typed:
  3488. GetTypeName:='File Of '+typedfiledef.typename;
  3489. ft_text:
  3490. GetTypeName:='Text'
  3491. end;
  3492. end;
  3493. function tfiledef.getmangledparaname : TSymStr;
  3494. begin
  3495. case filetyp of
  3496. ft_untyped:
  3497. getmangledparaname:='FILE';
  3498. ft_typed:
  3499. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  3500. ft_text:
  3501. getmangledparaname:='TEXT'
  3502. end;
  3503. end;
  3504. {****************************************************************************
  3505. TVARIANTDEF
  3506. ****************************************************************************}
  3507. constructor tvariantdef.create(v : tvarianttype);
  3508. begin
  3509. inherited create(variantdef,true);
  3510. varianttype:=v;
  3511. setsize;
  3512. end;
  3513. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  3514. begin
  3515. inherited ppuload(variantdef,ppufile);
  3516. varianttype:=tvarianttype(ppufile.getbyte);
  3517. setsize;
  3518. ppuload_platform(ppufile);
  3519. end;
  3520. function tvariantdef.getcopy : tstoreddef;
  3521. begin
  3522. result:=cvariantdef.create(varianttype);
  3523. end;
  3524. function tvariantdef.alignment: shortint;
  3525. begin
  3526. result:=search_system_type('TVARDATA').typedef.alignment;
  3527. end;
  3528. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  3529. begin
  3530. inherited ppuwrite(ppufile);
  3531. ppufile.putbyte(byte(varianttype));
  3532. writeentry(ppufile,ibvariantdef);
  3533. end;
  3534. function tvariantdef.getvardef : longint;
  3535. begin
  3536. Result:=varVariant;
  3537. end;
  3538. procedure tvariantdef.setsize;
  3539. begin
  3540. {$ifdef cpu64bitaddr}
  3541. savesize:=24;
  3542. {$else cpu64bitaddr}
  3543. savesize:=16;
  3544. {$endif cpu64bitaddr}
  3545. end;
  3546. function tvariantdef.GetTypeName : string;
  3547. begin
  3548. case varianttype of
  3549. vt_normalvariant:
  3550. GetTypeName:='Variant';
  3551. vt_olevariant:
  3552. GetTypeName:='OleVariant';
  3553. end;
  3554. end;
  3555. function tvariantdef.needs_inittable : boolean;
  3556. begin
  3557. needs_inittable:=true;
  3558. end;
  3559. function tvariantdef.is_publishable : tpublishproperty;
  3560. begin
  3561. is_publishable:=pp_publish;
  3562. end;
  3563. {****************************************************************************
  3564. TABSTRACtpointerdef
  3565. ****************************************************************************}
  3566. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  3567. begin
  3568. inherited create(dt,true);
  3569. pointeddef:=def;
  3570. pointeddefderef.reset;
  3571. if df_generic in pointeddef.defoptions then
  3572. include(defoptions,df_generic);
  3573. if df_specialization in pointeddef.defoptions then
  3574. include(defoptions,df_specialization);
  3575. end;
  3576. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3577. begin
  3578. inherited ppuload(dt,ppufile);
  3579. ppufile.getderef(pointeddefderef);
  3580. end;
  3581. procedure tabstractpointerdef.buildderef;
  3582. begin
  3583. inherited buildderef;
  3584. pointeddefderef.build(pointeddef);
  3585. end;
  3586. procedure tabstractpointerdef.deref;
  3587. begin
  3588. inherited deref;
  3589. pointeddef:=tdef(pointeddefderef.resolve);
  3590. end;
  3591. function tabstractpointerdef.size: asizeint;
  3592. begin
  3593. Result:=voidpointertype.size;
  3594. end;
  3595. function tabstractpointerdef.alignment: shortint;
  3596. begin
  3597. alignment:=size_2_align(voidpointertype.size);
  3598. end;
  3599. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3600. begin
  3601. inherited ppuwrite(ppufile);
  3602. ppufile.putderef(pointeddefderef);
  3603. end;
  3604. {****************************************************************************
  3605. tpointerdef
  3606. ****************************************************************************}
  3607. constructor tpointerdef.create(def:tdef);
  3608. begin
  3609. inherited create(pointerdef,def);
  3610. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  3611. if (df_specialization in tstoreddef(def).defoptions)
  3612. {$ifndef genericdef_for_nested}
  3613. { currently, nested procdefs of generic routines get df_specialization,
  3614. but no genericdef }
  3615. and assigned(tstoreddef(def).genericdef)
  3616. {$endif}
  3617. then
  3618. genericdef:=cpointerdef.getreusable(tstoreddef(def).genericdef);
  3619. end;
  3620. class function tpointerdef.getreusable(def: tdef): tpointerdef;
  3621. var
  3622. res: PHashSetItem;
  3623. oldsymtablestack: tsymtablestack;
  3624. begin
  3625. if not assigned(current_module) then
  3626. internalerror(2011071101);
  3627. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  3628. if not assigned(res^.Data) then
  3629. begin
  3630. { since these pointerdefs can be reused anywhere in the current
  3631. unit, add them to the global/staticsymtable (or local symtable
  3632. if they're a local def, because otherwise they'll be saved
  3633. to the ppu referencing a local symtable entry that doesn't
  3634. exist in the ppu) }
  3635. oldsymtablestack:=symtablestack;
  3636. { do not simply push/pop current_module.localsymtable, because
  3637. that can have side-effects (e.g., it removes helpers) }
  3638. symtablestack:=nil;
  3639. result:=cpointerdef.create(def);
  3640. setup_reusable_def(def,result,res,oldsymtablestack);
  3641. { res^.Data may still be nil -> don't overwrite result }
  3642. exit;
  3643. end;
  3644. result:=tpointerdef(res^.Data);
  3645. end;
  3646. class function tpointerdef.getreusable_no_free(def: tdef): tpointerdef;
  3647. begin
  3648. result:=getreusable(def);
  3649. if not result.is_registered then
  3650. include(result.defoptions,df_not_registered_no_free);
  3651. end;
  3652. function tpointerdef.size: asizeint;
  3653. begin
  3654. result:=sizeof(pint);
  3655. end;
  3656. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  3657. begin
  3658. inherited ppuload(pointerdef,ppufile);
  3659. has_pointer_math:=(ppufile.getbyte<>0);
  3660. ppuload_platform(ppufile);
  3661. end;
  3662. function tpointerdef.getcopy : tstoreddef;
  3663. begin
  3664. { don't use direct pointeddef if it is a forwarddef because in other case
  3665. one of them will be destroyed on forward type resolve and the second will
  3666. point to garbage }
  3667. if pointeddef.typ=forwarddef then
  3668. result:=cpointerdef.create(tforwarddef(pointeddef).getcopy)
  3669. else
  3670. result:=cpointerdef.create(pointeddef);
  3671. tpointerdef(result).has_pointer_math:=has_pointer_math;
  3672. tpointerdef(result).savesize:=savesize;
  3673. end;
  3674. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3675. begin
  3676. inherited ppuwrite(ppufile);
  3677. ppufile.putbyte(byte(has_pointer_math));
  3678. writeentry(ppufile,ibpointerdef);
  3679. end;
  3680. function tpointerdef.GetTypeName : string;
  3681. begin
  3682. { parameter types and the resultdef of a procvardef can contain a
  3683. pointer to this procvardef itself, resulting in endless recursion ->
  3684. use the typesym's name instead if it exists (if it doesn't, such as
  3685. for anynonymous procedure types in macpas/iso mode, then there cannot
  3686. be any recursive references to it either) }
  3687. if (pointeddef.typ<>procvardef) or
  3688. not assigned(pointeddef.typesym) then
  3689. GetTypeName:='^'+pointeddef.typename
  3690. else
  3691. GetTypeName:='^'+pointeddef.typesym.realname;
  3692. end;
  3693. function tpointerdef.pointer_arithmetic_int_type:tdef;
  3694. begin
  3695. result:=ptrsinttype;
  3696. end;
  3697. function tpointerdef.pointer_arithmetic_uint_type:tdef;
  3698. begin
  3699. result:=ptruinttype;
  3700. end;
  3701. function tpointerdef.pointer_subtraction_result_type:tdef;
  3702. begin
  3703. result:=ptrsinttype;
  3704. end;
  3705. function tpointerdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  3706. begin
  3707. result:=true;
  3708. end;
  3709. function tpointerdef.converted_pointer_to_array_range_type:tdef;
  3710. begin
  3711. result:=ptrsinttype;
  3712. end;
  3713. {****************************************************************************
  3714. TCLASSREFDEF
  3715. ****************************************************************************}
  3716. constructor tclassrefdef.create(def:tdef);
  3717. begin
  3718. while (def.typ=objectdef) and tobjectdef(def).is_unique_objpasdef do
  3719. def:=tobjectdef(def).childof;
  3720. inherited create(classrefdef,def);
  3721. if df_specialization in tstoreddef(def).defoptions then
  3722. genericdef:=cclassrefdef.create(tstoreddef(def).genericdef);
  3723. end;
  3724. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  3725. begin
  3726. inherited ppuload(classrefdef,ppufile);
  3727. ppuload_platform(ppufile);
  3728. end;
  3729. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  3730. begin
  3731. inherited ppuwrite(ppufile);
  3732. writeentry(ppufile,ibclassrefdef);
  3733. end;
  3734. function tclassrefdef.getcopy:tstoreddef;
  3735. begin
  3736. if pointeddef.typ=forwarddef then
  3737. result:=cclassrefdef.create(tforwarddef(pointeddef).getcopy)
  3738. else
  3739. result:=cclassrefdef.create(pointeddef);
  3740. end;
  3741. function tclassrefdef.GetTypeName : string;
  3742. begin
  3743. GetTypeName:='Class Of '+pointeddef.typename;
  3744. end;
  3745. function tclassrefdef.is_publishable : tpublishproperty;
  3746. begin
  3747. is_publishable:=pp_publish;
  3748. end;
  3749. function tclassrefdef.rtti_mangledname(rt: trttitype): TSymStr;
  3750. begin
  3751. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  3752. result:=inherited rtti_mangledname(rt)
  3753. else
  3754. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  3755. end;
  3756. procedure tclassrefdef.register_created_object_type;
  3757. begin
  3758. tobjectdef(pointeddef).register_created_classref_type;
  3759. end;
  3760. {***************************************************************************
  3761. TSETDEF
  3762. ***************************************************************************}
  3763. constructor tsetdef.create(def: tdef; low, high: asizeint; doregister: boolean);
  3764. var
  3765. setallocbits: aint;
  3766. packedsavesize: aint;
  3767. actual_setalloc: ShortInt;
  3768. begin
  3769. inherited create(setdef,doregister);
  3770. elementdef:=def;
  3771. elementdefderef.reset;
  3772. setmax:=high;
  3773. setlow:=low;
  3774. actual_setalloc:=current_settings.setalloc;
  3775. {$if defined(cpu8bitalu) or defined(cpu16bitalu)}
  3776. if actual_setalloc=0 then
  3777. actual_setalloc:=1;
  3778. {$endif}
  3779. if (actual_setalloc=0) then
  3780. begin
  3781. setbase:=0;
  3782. if (high<32) then
  3783. savesize:=Sizeof(longint)
  3784. else if (high<256) then
  3785. savesize:=32
  3786. else
  3787. savesize:=(high+7) div 8
  3788. end
  3789. else
  3790. begin
  3791. setallocbits:=actual_setalloc*8;
  3792. setbase:=low and not(setallocbits-1);
  3793. packedsavesize:=actual_setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  3794. savesize:=packedsavesize;
  3795. {$if not defined(cpu8bitalu) and not defined(cpu16bitalu)}
  3796. if savesize=3 then
  3797. savesize:=4;
  3798. {$endif}
  3799. end;
  3800. end;
  3801. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  3802. begin
  3803. inherited ppuload(setdef,ppufile);
  3804. ppufile.getderef(elementdefderef);
  3805. savesize:=ppufile.getasizeint;
  3806. setbase:=ppufile.getasizeint;
  3807. setlow:=ppufile.getasizeint;
  3808. setmax:=ppufile.getasizeint;
  3809. ppuload_platform(ppufile);
  3810. end;
  3811. function tsetdef.getcopy : tstoreddef;
  3812. begin
  3813. result:=csetdef.create(elementdef,setbase,setmax,true);
  3814. { the copy might have been created with a different setalloc setting }
  3815. tsetdef(result).savesize:=savesize;
  3816. end;
  3817. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  3818. begin
  3819. inherited ppuwrite(ppufile);
  3820. ppufile.putderef(elementdefderef);
  3821. ppufile.putasizeint(savesize);
  3822. ppufile.putasizeint(setbase);
  3823. ppufile.putasizeint(setlow);
  3824. ppufile.putasizeint(setmax);
  3825. writeentry(ppufile,ibsetdef);
  3826. end;
  3827. procedure tsetdef.buildderef;
  3828. begin
  3829. inherited buildderef;
  3830. elementdefderef.build(elementdef);
  3831. end;
  3832. procedure tsetdef.deref;
  3833. begin
  3834. inherited deref;
  3835. elementdef:=tdef(elementdefderef.resolve);
  3836. end;
  3837. function tsetdef.is_publishable : tpublishproperty;
  3838. begin
  3839. if savesize in [1,2,4] then
  3840. is_publishable:=pp_publish
  3841. else
  3842. is_publishable:=pp_error;
  3843. end;
  3844. function tsetdef.alignment: shortint;
  3845. begin
  3846. Result:=inherited;
  3847. if result>sizeof(aint) then
  3848. result:=sizeof(aint);
  3849. end;
  3850. function tsetdef.GetTypeName : string;
  3851. begin
  3852. if assigned(elementdef) then
  3853. GetTypeName:='Set Of '+elementdef.typename
  3854. else
  3855. GetTypeName:='Empty Set';
  3856. end;
  3857. {***************************************************************************
  3858. TFORMALDEF
  3859. ***************************************************************************}
  3860. constructor tformaldef.create(Atyped:boolean);
  3861. begin
  3862. inherited create(formaldef,true);
  3863. typed:=Atyped;
  3864. savesize:=0;
  3865. end;
  3866. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  3867. begin
  3868. inherited ppuload(formaldef,ppufile);
  3869. typed:=boolean(ppufile.getbyte);
  3870. savesize:=0;
  3871. ppuload_platform(ppufile);
  3872. end;
  3873. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  3874. begin
  3875. inherited ppuwrite(ppufile);
  3876. ppufile.putbyte(byte(typed));
  3877. writeentry(ppufile,ibformaldef);
  3878. end;
  3879. function tformaldef.GetTypeName : string;
  3880. begin
  3881. if typed then
  3882. GetTypeName:='<Typed formal type>'
  3883. else
  3884. GetTypeName:='<Formal type>';
  3885. end;
  3886. {***************************************************************************
  3887. TARRAYDEF
  3888. ***************************************************************************}
  3889. constructor tarraydef.create(l, h: asizeint; def: tdef);
  3890. begin
  3891. inherited create(arraydef,true);
  3892. lowrange:=l;
  3893. highrange:=h;
  3894. rangedef:=def;
  3895. rangedefderef.reset;
  3896. _elementdef:=nil;
  3897. _elementdefderef.reset;
  3898. arrayoptions:=[];
  3899. symtable:=tarraysymtable.create(self);
  3900. end;
  3901. constructor tarraydef.create_vector(l ,h: asizeint; def: tdef);
  3902. begin
  3903. self.create(l,h,def);
  3904. include(arrayoptions,ado_IsVector);
  3905. end;
  3906. constructor tarraydef.create_openarray;
  3907. begin
  3908. self.create(0,-1,sizesinttype);
  3909. include(arrayoptions,ado_OpenArray);
  3910. end;
  3911. class function tarraydef.getreusable_intern(def: tdef; elems: asizeint; const options: tarraydefoptions): tarraydef;
  3912. var
  3913. res: PHashSetItem;
  3914. oldsymtablestack: tsymtablestack;
  3915. arrdesc: packed record
  3916. def: tdef;
  3917. elecount: asizeint;
  3918. options: tarraydefoptions
  3919. end;
  3920. begin
  3921. if not assigned(current_module) then
  3922. internalerror(2011081301);
  3923. arrdesc.def:=def;
  3924. arrdesc.elecount:=elems;
  3925. arrdesc.options:=options;
  3926. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  3927. if not assigned(res^.Data) then
  3928. begin
  3929. { since these pointerdefs can be reused anywhere in the current
  3930. unit, add them to the global/staticsymtable (or local symtable
  3931. if they're a local def, because otherwise they'll be saved
  3932. to the ppu referencing a local symtable entry that doesn't
  3933. exist in the ppu) }
  3934. oldsymtablestack:=symtablestack;
  3935. { do not simply push/pop current_module.localsymtable, because
  3936. that can have side-effects (e.g., it removes helpers) }
  3937. symtablestack:=nil;
  3938. result:=carraydef.create(0,elems-1,sizesinttype);
  3939. result.elementdef:=def;
  3940. result.arrayoptions:=options;
  3941. setup_reusable_def(def,result,res,oldsymtablestack);
  3942. { res^.Data may still be nil -> don't overwrite result }
  3943. exit;
  3944. end;
  3945. result:=tarraydef(res^.Data);
  3946. end;
  3947. class function tarraydef.getreusable(def: tdef; elems: asizeint): tarraydef;
  3948. begin
  3949. result:=getreusable_intern(def,elems,[]);
  3950. end;
  3951. class function tarraydef.getreusable_vector(def: tdef; elems: asizeint): tarraydef;
  3952. begin
  3953. result:=getreusable_intern(def,elems,[ado_IsVector]);
  3954. end;
  3955. class function tarraydef.getreusable_no_free(def: tdef; elems: asizeint): tarraydef;
  3956. begin
  3957. result:=getreusable(def,elems);
  3958. if not result.is_registered then
  3959. include(result.defoptions,df_not_registered_no_free);
  3960. end;
  3961. class function tarraydef.getreusable_no_free_vector(def: tdef; elems: asizeint): tarraydef;
  3962. begin
  3963. result:=getreusable_vector(def,elems);
  3964. if not result.is_registered then
  3965. include(result.defoptions,df_not_registered_no_free);
  3966. end;
  3967. destructor tarraydef.destroy;
  3968. begin
  3969. symtable.free;
  3970. symtable:=nil;
  3971. inherited;
  3972. end;
  3973. constructor tarraydef.create_from_pointer(def:tpointerdef);
  3974. begin
  3975. { divide by the element size and do -1 so the array will have a valid size,
  3976. further, the element size might be 0 e.g. for empty records, so use max(...,1)
  3977. to avoid a division by zero }
  3978. self.create(0,(high(asizeint) div max(def.pointeddef.size,1))-1,
  3979. def.converted_pointer_to_array_range_type);
  3980. arrayoptions:=[ado_IsConvertedPointer];
  3981. setelementdef(def.pointeddef);
  3982. end;
  3983. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  3984. begin
  3985. inherited ppuload(arraydef,ppufile);
  3986. { the addresses are calculated later }
  3987. ppufile.getderef(_elementdefderef);
  3988. ppufile.getderef(rangedefderef);
  3989. lowrange:=ppufile.getasizeint;
  3990. highrange:=ppufile.getasizeint;
  3991. ppufile.getset(tppuset2(arrayoptions));
  3992. ppuload_platform(ppufile);
  3993. symtable:=tarraysymtable.create(self);
  3994. tarraysymtable(symtable).ppuload(ppufile)
  3995. end;
  3996. function tarraydef.getcopy : tstoreddef;
  3997. begin
  3998. result:=carraydef.create(lowrange,highrange,rangedef);
  3999. tarraydef(result).arrayoptions:=arrayoptions;
  4000. tarraydef(result)._elementdef:=_elementdef;
  4001. end;
  4002. procedure tarraydef.buildderef;
  4003. begin
  4004. inherited buildderef;
  4005. tarraysymtable(symtable).buildderef;
  4006. _elementdefderef.build(_elementdef);
  4007. rangedefderef.build(rangedef);
  4008. end;
  4009. procedure tarraydef.deref;
  4010. begin
  4011. inherited deref;
  4012. tarraysymtable(symtable).deref(false);
  4013. _elementdef:=tdef(_elementdefderef.resolve);
  4014. rangedef:=tdef(rangedefderef.resolve);
  4015. end;
  4016. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  4017. begin
  4018. inherited ppuwrite(ppufile);
  4019. ppufile.putderef(_elementdefderef);
  4020. ppufile.putderef(rangedefderef);
  4021. ppufile.putasizeint(lowrange);
  4022. ppufile.putasizeint(highrange);
  4023. ppufile.putset(tppuset2(arrayoptions));
  4024. writeentry(ppufile,ibarraydef);
  4025. tarraysymtable(symtable).ppuwrite(ppufile);
  4026. end;
  4027. function tarraydef.elesize : asizeint;
  4028. begin
  4029. if (ado_IsBitPacked in arrayoptions) then
  4030. internalerror(2006080101);
  4031. if assigned(_elementdef) then
  4032. result:=_elementdef.size
  4033. else
  4034. result:=0;
  4035. end;
  4036. function tarraydef.elepackedbitsize : asizeint;
  4037. begin
  4038. if not(ado_IsBitPacked in arrayoptions) then
  4039. internalerror(2006080102);
  4040. if assigned(_elementdef) then
  4041. result:=_elementdef.packedbitsize
  4042. else
  4043. result:=0;
  4044. end;
  4045. function tarraydef.elecount : asizeuint;
  4046. var
  4047. qhigh,qlow : qword;
  4048. begin
  4049. if ado_IsDynamicArray in arrayoptions then
  4050. begin
  4051. result:=0;
  4052. exit;
  4053. end;
  4054. { check whether the range might be larger than high(asizeint). Has
  4055. to include 0..high(sizeint), since that's high(sizeint)+1 elements }
  4056. if (highrange>=0) and (lowrange<=0) then
  4057. begin
  4058. qhigh:=highrange;
  4059. if lowrange=low(asizeint) then
  4060. qlow:=high(asizeint) + 1
  4061. else
  4062. qlow:=qword(-lowrange);
  4063. { prevent overflow, return 0 to indicate overflow }
  4064. if qhigh+qlow>qword(high(asizeint)-1) then
  4065. result:=0
  4066. else
  4067. result:=qhigh+qlow+1;
  4068. end
  4069. else
  4070. result:=int64(highrange)-lowrange+1;
  4071. end;
  4072. function tarraydef.size : asizeint;
  4073. var
  4074. cachedelecount : asizeuint;
  4075. cachedelesize : asizeint;
  4076. begin
  4077. if ado_IsDynamicArray in arrayoptions then
  4078. begin
  4079. size:=voidpointertype.size;
  4080. exit;
  4081. end;
  4082. { Tarraydef.size may never be called for an open array! }
  4083. if ado_OpenArray in arrayoptions then
  4084. internalerror(99080501);
  4085. if not (ado_IsBitPacked in arrayoptions) then
  4086. cachedelesize:=elesize
  4087. else
  4088. cachedelesize := elepackedbitsize;
  4089. cachedelecount:=elecount;
  4090. if (cachedelesize = 0) then
  4091. begin
  4092. size := 0;
  4093. exit;
  4094. end;
  4095. if (cachedelecount = 0) then
  4096. begin
  4097. if ado_isconststring in arrayoptions then
  4098. size := 0
  4099. else
  4100. size := -1;
  4101. exit;
  4102. end;
  4103. { prevent overflow, return -1 to indicate overflow }
  4104. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  4105. if (cachedelecount > asizeuint(high(asizeint))) or
  4106. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  4107. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  4108. accessing the array, see ncgmem (PFV) }
  4109. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  4110. begin
  4111. result:=-1;
  4112. exit;
  4113. end;
  4114. result:=cachedelesize*asizeint(cachedelecount);
  4115. if (ado_IsBitPacked in arrayoptions) then
  4116. { can't just add 7 and divide by 8, because that may overflow }
  4117. result:=result div 8 + ord((result mod 8)<>0);
  4118. {$ifdef cpu16bitaddr}
  4119. if result>65535 then
  4120. begin
  4121. result:=-1;
  4122. exit;
  4123. end;
  4124. {$endif cpu16bitaddr}
  4125. end;
  4126. procedure tarraydef.setelementdef(def:tdef);
  4127. begin
  4128. _elementdef:=def;
  4129. if not(
  4130. (ado_IsDynamicArray in arrayoptions) or
  4131. (ado_IsConvertedPointer in arrayoptions) or
  4132. (ado_IsConstructor in arrayoptions) or
  4133. (ado_IsGeneric in arrayoptions) or
  4134. (highrange<lowrange)
  4135. ) and
  4136. (size=-1) then
  4137. Message(sym_e_segment_too_large);
  4138. end;
  4139. function tarraydef.alignment : shortint;
  4140. begin
  4141. if ado_IsVector in arrayoptions then
  4142. alignment:=size
  4143. { alignment of dyn. arrays doesn't depend on the element size }
  4144. else if ado_IsDynamicArray in arrayoptions then
  4145. alignment:=voidpointertype.alignment
  4146. { alignment is the target alignment for the used load size }
  4147. else if (ado_IsBitPacked in arrayoptions) and
  4148. (elementdef.typ in [enumdef,orddef]) then
  4149. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  4150. { alignment is the alignment of the elements }
  4151. else
  4152. alignment:=elementdef.alignment
  4153. end;
  4154. function tarraydef.needs_inittable : boolean;
  4155. begin
  4156. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  4157. end;
  4158. function tarraydef.needs_separate_initrtti : boolean;
  4159. begin
  4160. if ado_IsBitPacked in arrayoptions then
  4161. result:=false
  4162. else
  4163. result:=elementdef.needs_separate_initrtti;
  4164. end;
  4165. function tarraydef.GetTypeName : string;
  4166. begin
  4167. if (ado_IsConstString in arrayoptions) then
  4168. result:='Constant String'
  4169. else if (ado_isarrayofconst in arrayoptions) or
  4170. (ado_isConstructor in arrayoptions) then
  4171. begin
  4172. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  4173. GetTypeName:='Array Of Const'
  4174. else
  4175. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  4176. end
  4177. else if (ado_IsDynamicArray in arrayoptions) then
  4178. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  4179. else if (ado_OpenArray in arrayoptions) then
  4180. GetTypeName:='{Open} Array Of '+elementdef.typename
  4181. else
  4182. begin
  4183. result := '';
  4184. if (ado_IsBitPacked in arrayoptions) then
  4185. result:='BitPacked ';
  4186. if rangedef.typ=enumdef then
  4187. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  4188. else
  4189. result:=result+'Array['+tostr(lowrange)+'..'+
  4190. tostr(highrange)+'] Of '+elementdef.typename
  4191. end;
  4192. end;
  4193. function tarraydef.getmangledparaname : TSymStr;
  4194. begin
  4195. if ado_isarrayofconst in arrayoptions then
  4196. getmangledparaname:='array_of_const'
  4197. else
  4198. if ((highrange=-1) and (lowrange=0)) then
  4199. getmangledparaname:='array_of_'+elementdef.mangledparaname
  4200. else
  4201. internalerror(200204176);
  4202. end;
  4203. function tarraydef.is_publishable : tpublishproperty;
  4204. begin
  4205. if ado_IsDynamicArray in arrayoptions then
  4206. is_publishable:=pp_publish
  4207. else
  4208. is_publishable:=pp_error;
  4209. end;
  4210. function tarraydef.is_hwvector: boolean;
  4211. begin
  4212. result:=ado_IsVector in arrayoptions;
  4213. end;
  4214. {***************************************************************************
  4215. tabstractrecorddef
  4216. ***************************************************************************}
  4217. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp;doregister:boolean);
  4218. begin
  4219. inherited create(dt,doregister);
  4220. objname:=stringdup(upper(n));
  4221. objrealname:=stringdup(n);
  4222. objectoptions:=[];
  4223. if assigned(current_module.namespace) then
  4224. begin
  4225. import_lib:=stringdup(current_module.namespace^);
  4226. replace(import_lib^,'.','/');
  4227. end;
  4228. end;
  4229. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  4230. var
  4231. ro: trtti_option;
  4232. begin
  4233. inherited ppuload(dt,ppufile);
  4234. objrealname:=ppufile.getpshortstring;
  4235. objname:=stringdup(upper(objrealname^));
  4236. import_lib:=ppufile.getpshortstring;
  4237. { only used for external C++ classes and Java classes/records }
  4238. if (import_lib^='') then
  4239. stringdispose(import_lib);
  4240. ppufile.getset(tppuset4(objectoptions));
  4241. rtti.clause:=trtti_clause(ppufile.getbyte);
  4242. for ro in trtti_option do
  4243. ppufile.getset(tppuset1(rtti.options[ro]));
  4244. end;
  4245. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  4246. var
  4247. ro: trtti_option;
  4248. begin
  4249. inherited ppuwrite(ppufile);
  4250. ppufile.putstring(objrealname^);
  4251. if assigned(import_lib) then
  4252. ppufile.putstring(import_lib^)
  4253. else
  4254. ppufile.putstring('');
  4255. ppufile.putset(tppuset4(objectoptions));
  4256. ppufile.putbyte(byte(rtti.clause));
  4257. for ro in trtti_option do
  4258. ppufile.putset(tppuset1(rtti.options[ro]));
  4259. end;
  4260. destructor tabstractrecorddef.destroy;
  4261. begin
  4262. stringdispose(objname);
  4263. stringdispose(objrealname);
  4264. stringdispose(import_lib);
  4265. tcinitcode.free;
  4266. inherited destroy;
  4267. end;
  4268. procedure tabstractrecorddef.buildderefimpl;
  4269. begin
  4270. inherited buildderefimpl;
  4271. if not (df_copied_def in defoptions) then
  4272. tstoredsymtable(symtable).buildderefimpl;
  4273. end;
  4274. procedure tabstractrecorddef.derefimpl;
  4275. begin
  4276. inherited derefimpl;
  4277. if not (df_copied_def in defoptions) then
  4278. tstoredsymtable(symtable).derefimpl(false);
  4279. end;
  4280. procedure tabstractrecorddef.check_forwards;
  4281. begin
  4282. { the defs of a copied def are defined for the original type only }
  4283. if not(df_copied_def in defoptions) then
  4284. tstoredsymtable(symtable).check_forwards;
  4285. end;
  4286. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  4287. var
  4288. i: longint;
  4289. sym: tsym;
  4290. begin
  4291. for i:=0 to symtable.SymList.Count-1 do
  4292. begin
  4293. sym:=tsym(symtable.SymList[i]);
  4294. if sym.typ=procsym then
  4295. begin
  4296. result:=tprocsym(sym).find_procdef_bytype(pt);
  4297. if assigned(result) then
  4298. exit;
  4299. end;
  4300. end;
  4301. result:=nil;
  4302. end;
  4303. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  4304. begin
  4305. if t=gs_record then
  4306. GetSymtable:=symtable
  4307. else
  4308. GetSymtable:=nil;
  4309. end;
  4310. function tabstractrecorddef.is_packed:boolean;
  4311. begin
  4312. result:=tabstractrecordsymtable(symtable).is_packed;
  4313. end;
  4314. function tabstractrecorddef.RttiName: string;
  4315. function generate_full_paramname(maxlength:longint):string;
  4316. const
  4317. commacount : array[boolean] of longint = (0,1);
  4318. var
  4319. fullparas,
  4320. paramname : ansistring;
  4321. module : tmodule;
  4322. sym : tsym;
  4323. def : tdef;
  4324. i : longint;
  4325. begin
  4326. { we want at least enough space for an ellipsis }
  4327. if maxlength<3 then
  4328. internalerror(2014121203);
  4329. fullparas:='';
  4330. for i:=0 to genericparas.count-1 do
  4331. begin
  4332. sym:=tsym(genericparas[i]);
  4333. module:=find_module_from_symtable(sym.owner);
  4334. if not assigned(module) then
  4335. internalerror(2014121202);
  4336. if not (sym.typ in [constsym,symconst.typesym]) then
  4337. internalerror(2020042501);
  4338. if sym.typ=constsym then
  4339. def:=tconstsym(sym).constdef
  4340. else
  4341. def:=ttypesym(sym).typedef;
  4342. paramname:=module.realmodulename^;
  4343. if def.typ in [objectdef,recorddef] then
  4344. paramname:=paramname+'.'+tabstractrecorddef(def).rttiname
  4345. else
  4346. paramname:=paramname+'.'+def.typename;
  4347. if length(fullparas)+commacount[i>0]+length(paramname)>maxlength then
  4348. begin
  4349. if i>0 then
  4350. fullparas:=fullparas+',...'
  4351. else
  4352. fullparas:=fullparas+'...';
  4353. break;
  4354. end;
  4355. { could we fit an ellipsis after this parameter if it should be too long? }
  4356. if (maxlength-(length(fullparas)+commacount[i>0]+length(paramname))<4) and (i<genericparas.count-1) then
  4357. begin
  4358. { then omit already this parameter }
  4359. if i>0 then
  4360. fullparas:=fullparas+',...'
  4361. else
  4362. fullparas:=fullparas+'...';
  4363. break;
  4364. end;
  4365. if i>0 then
  4366. fullparas:=fullparas+',';
  4367. fullparas:=fullparas+paramname;
  4368. end;
  4369. result:=fullparas;
  4370. end;
  4371. var
  4372. nongeneric,
  4373. basename : string;
  4374. i,
  4375. remlength,
  4376. paramcount,
  4377. crcidx : longint;
  4378. begin
  4379. if rttistring='' then
  4380. begin
  4381. if is_specialization then
  4382. begin
  4383. rttistring:=OwnerHierarchyName;
  4384. { there should be two $ characters, one before the CRC and one before the count }
  4385. crcidx:=-1;
  4386. for i:=length(objrealname^) downto 1 do
  4387. if objrealname^[i]='$' then
  4388. begin
  4389. crcidx:=i;
  4390. break;
  4391. end;
  4392. if crcidx<0 then
  4393. internalerror(2014121201);
  4394. basename:=copy(objrealname^,1,crcidx-1);
  4395. split_generic_name(basename,nongeneric,paramcount);
  4396. rttistring:=rttistring+nongeneric+'<';
  4397. remlength:=255-length(rttistring)-1;
  4398. if remlength<4 then
  4399. rttistring:=rttistring+'>'
  4400. else
  4401. rttistring:=rttistring+generate_full_paramname(remlength)+'>';
  4402. end
  4403. else
  4404. if is_generic then
  4405. begin
  4406. rttistring:=OwnerHierarchyName;
  4407. split_generic_name(objrealname^,nongeneric,paramcount);
  4408. rttistring:=rttistring+nongeneric+'<';
  4409. { we don't want any ',' if there is only one parameter }
  4410. for i:=0 to paramcount-1 do
  4411. rttistring:=rttistring+',';
  4412. rttistring:=rttistring+'>';
  4413. end
  4414. else
  4415. rttistring:=OwnerHierarchyName+objrealname^;
  4416. end;
  4417. result:=rttistring;
  4418. end;
  4419. function tabstractrecorddef.search_enumerator_get: tprocdef;
  4420. var
  4421. sym : tsym;
  4422. i : integer;
  4423. pd : tprocdef;
  4424. hashedid : THashedIDString;
  4425. begin
  4426. result:=nil;
  4427. hashedid.id:='GETENUMERATOR';
  4428. sym:=tsym(symtable.FindWithHash(hashedid));
  4429. if assigned(sym) and (sym.typ=procsym) then
  4430. begin
  4431. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  4432. begin
  4433. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4434. if (pd.proctypeoption = potype_function) and
  4435. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  4436. (pd.visibility >= vis_public) then
  4437. begin
  4438. result:=pd;
  4439. exit;
  4440. end;
  4441. end;
  4442. end;
  4443. end;
  4444. function tabstractrecorddef.search_enumerator_move: tprocdef;
  4445. var
  4446. sym : tsym;
  4447. i : integer;
  4448. pd : tprocdef;
  4449. hashedid : THashedIDString;
  4450. begin
  4451. result:=nil;
  4452. // first search for po_enumerator_movenext method modifier
  4453. // then search for public function MoveNext: Boolean
  4454. for i:=0 to symtable.SymList.Count-1 do
  4455. begin
  4456. sym:=TSym(symtable.SymList[i]);
  4457. if (sym.typ=procsym) then
  4458. begin
  4459. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  4460. if assigned(pd) then
  4461. begin
  4462. result:=pd;
  4463. exit;
  4464. end;
  4465. end;
  4466. end;
  4467. hashedid.id:='MOVENEXT';
  4468. sym:=tsym(symtable.FindWithHash(hashedid));
  4469. if assigned(sym) and (sym.typ=procsym) then
  4470. begin
  4471. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  4472. begin
  4473. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4474. if (pd.proctypeoption = potype_function) and
  4475. is_boolean(pd.returndef) and
  4476. (pd.minparacount = 0) and
  4477. (pd.visibility >= vis_public) then
  4478. begin
  4479. result:=pd;
  4480. exit;
  4481. end;
  4482. end;
  4483. end;
  4484. end;
  4485. function tabstractrecorddef.search_enumerator_current: tsym;
  4486. var
  4487. sym: tsym;
  4488. i: integer;
  4489. hashedid : THashedIDString;
  4490. begin
  4491. result:=nil;
  4492. // first search for ppo_enumerator_current property modifier
  4493. // then search for public property Current
  4494. for i:=0 to symtable.SymList.Count-1 do
  4495. begin
  4496. sym:=TSym(symtable.SymList[i]);
  4497. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  4498. begin
  4499. result:=sym;
  4500. exit;
  4501. end;
  4502. end;
  4503. hashedid.id:='CURRENT';
  4504. sym:=tsym(symtable.FindWithHash(hashedid));
  4505. if assigned(sym) and (sym.typ=propertysym) and
  4506. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  4507. begin
  4508. result:=sym;
  4509. exit;
  4510. end;
  4511. end;
  4512. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  4513. var
  4514. st: tsymtable;
  4515. enclosingdef: tdef;
  4516. begin
  4517. if typ=objectdef then
  4518. result:=tobjectdef(self).objextname^
  4519. else if assigned(typesym) then
  4520. result:=typesym.realname
  4521. { have to generate anonymous nested type in current unit/class/record }
  4522. else
  4523. internalerror(2011032601);
  4524. { in case of specializations, add some extras to prevent name conflicts
  4525. with nested classes }
  4526. if df_specialization in defoptions then
  4527. result:='$'+result+'$specialization$';
  4528. st:=owner;
  4529. while assigned(st) and
  4530. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  4531. begin
  4532. { nested classes are named as "OuterClass$InnerClass" }
  4533. enclosingdef:=tdef(st.defowner);
  4534. if enclosingdef.typ=procdef then
  4535. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  4536. else if enclosingdef.typ=objectdef then
  4537. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  4538. else if assigned(enclosingdef.typesym) then
  4539. result:=enclosingdef.typesym.realname+'$'+result
  4540. else
  4541. internalerror(2011060305);
  4542. st:=enclosingdef.owner;
  4543. end;
  4544. if with_package_name and
  4545. assigned(import_lib) then
  4546. result:=import_lib^+'/'+result;
  4547. end;
  4548. function tabstractrecorddef.contains_float_field: boolean;
  4549. var
  4550. i : longint;
  4551. begin
  4552. result:=true;
  4553. for i:=0 to symtable.symlist.count-1 do
  4554. begin
  4555. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4556. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4557. continue;
  4558. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4559. begin
  4560. if tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  4561. exit;
  4562. { search recursively }
  4563. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4564. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_float_field) then
  4565. exit;
  4566. end;
  4567. end;
  4568. result:=false;
  4569. end;
  4570. function tabstractrecorddef.contains_cross_aword_field: boolean;
  4571. var
  4572. i : longint;
  4573. foffset, fsize: aword;
  4574. begin
  4575. result:=true;
  4576. for i:=0 to symtable.symlist.count-1 do
  4577. begin
  4578. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4579. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4580. continue;
  4581. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4582. begin
  4583. if is_packed then
  4584. begin
  4585. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset;
  4586. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.packedbitsize;
  4587. end
  4588. else
  4589. begin
  4590. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset*8;
  4591. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.size*8;
  4592. end;
  4593. if (fsize>0) and ((foffset div (sizeof(aword)*8)) <> ((foffset+fsize-1) div (sizeof(aword)*8))) then
  4594. exit;
  4595. { search recursively }
  4596. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4597. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_cross_aword_field) then
  4598. exit;
  4599. end;
  4600. end;
  4601. result:=false;
  4602. end;
  4603. procedure tabstractrecorddef.apply_rtti_directive(dir: trtti_directive);
  4604. begin
  4605. { records don't support the inherit clause but shouldn't
  4606. give an error either if used (for Delphi compatibility),
  4607. so we silently enforce the clause as explicit. }
  4608. rtti.clause:=rtc_explicit;
  4609. rtti.options:=dir.options;
  4610. end;
  4611. function tabstractrecorddef.is_visible_for_rtti(option: trtti_option; vis: tvisibility): boolean;
  4612. begin
  4613. case vis of
  4614. vis_private,
  4615. vis_strictprivate: result:=rv_private in rtti.options[option];
  4616. vis_protected,
  4617. vis_strictprotected: result:=rv_protected in rtti.options[option];
  4618. vis_public: result:=rv_public in rtti.options[option];
  4619. vis_published: result:=rv_published in rtti.options[option];
  4620. otherwise
  4621. result:=false;
  4622. end;
  4623. end;
  4624. function tabstractrecorddef.rtti_visibilities_for_option(option: trtti_option): tvisibilities;
  4625. begin
  4626. result:=[];
  4627. if rv_private in rtti.options[option] then
  4628. begin
  4629. include(result,vis_private);
  4630. include(result,vis_strictprivate);
  4631. end;
  4632. if rv_protected in rtti.options[option] then
  4633. begin
  4634. include(result,vis_protected);
  4635. include(result,vis_strictprotected);
  4636. end;
  4637. if rv_public in rtti.options[option] then
  4638. include(result,vis_public);
  4639. if rv_published in rtti.options[option] then
  4640. include(result,vis_published);
  4641. end;
  4642. function tabstractrecorddef.has_extended_rtti: boolean;
  4643. begin
  4644. result := (rtti.options[ro_fields]<>[]) or
  4645. (rtti.options[ro_methods]<>[]) or
  4646. (rtti.options[ro_properties]<>[]);
  4647. end;
  4648. {$ifdef DEBUG_NODE_XML}
  4649. procedure tabstractrecorddef.XMLPrintDefData(var T: Text; Sym: TSym);
  4650. procedure WriteSymOptions(SourceSym: TSym);
  4651. var
  4652. i: TSymOption;
  4653. first: Boolean;
  4654. begin
  4655. First := True;
  4656. for i := Low(TSymOption) to High(TSymOption) do
  4657. if i in SourceSym.symoptions then
  4658. begin
  4659. if First then
  4660. begin
  4661. Write(T, '" symoptions="', i);
  4662. First := False;
  4663. end
  4664. else
  4665. Write(T, ',', i)
  4666. end;
  4667. end;
  4668. var
  4669. List: TFPHashObjectList;
  4670. i: Integer;
  4671. begin
  4672. WriteLn(T, PrintNodeIndention, '<size>', size, '</size>');
  4673. if (alignment = structalignment) and (alignment = aggregatealignment) then
  4674. begin
  4675. { Straightforward and simple }
  4676. WriteLn(T, PrintNodeIndention, '<alignment>', alignment, '</alignment>');
  4677. end
  4678. else
  4679. begin
  4680. WriteLn(T, PrintNodeIndention, '<alignment>');
  4681. printnodeindent;
  4682. WriteLn(T, PrintNodeIndention, '<basic>', alignment, '</basic>');
  4683. if (structalignment <> alignment) then
  4684. WriteLn(T, PrintNodeIndention, '<struct>', structalignment, '</struct>');
  4685. if (aggregatealignment <> alignment) and (aggregatealignment <> structalignment) then
  4686. WriteLn(T, PrintNodeIndention, '<aggregate>', aggregatealignment, '</aggregate>');
  4687. printnodeunindent;
  4688. WriteLn(T, PrintNodeIndention, '</alignment>');
  4689. end;
  4690. { List the fields }
  4691. List := Symtable.SymList;
  4692. for i := 0 to List.Count - 1 do
  4693. case TSym(List[i]).typ of
  4694. { staticvarsym,localvarsym,paravarsym,fieldvarsym,
  4695. typesym,procsym,unitsym,}
  4696. constsym:
  4697. with TConstSym(List[i]) do
  4698. begin
  4699. Write(T, PrintNodeIndention, '<const name="', RealName, '" pos="', fileinfo.line, ',', fileinfo.column);
  4700. WriteSymOptions(TSym(List[i]));
  4701. WriteLn(T, '">');
  4702. PrintNodeIndent;
  4703. XMLPrintConstData(T);
  4704. PrintNodeUnindent;
  4705. WriteLn(T, PrintNodeIndention, '</const>');
  4706. end;
  4707. {
  4708. errorsym,syssym,labelsym,absolutevarsym,propertysym,
  4709. macrosym,namespacesym,undefinedsym,programparasym
  4710. }
  4711. fieldvarsym:
  4712. with TFieldVarSym(List[i]) do
  4713. begin
  4714. Write(T, PrintNodeIndention, '<field name="', RealName, '" pos="', fileinfo.line, ',', fileinfo.column);
  4715. WriteSymOptions(TSym(List[i]));
  4716. WriteLn(T, '">');
  4717. PrintNodeIndent;
  4718. XMLPrintFieldData(T);
  4719. PrintNodeUnindent;
  4720. WriteLn(T, PrintNodeIndention, '</field>');
  4721. end;
  4722. else
  4723. ;
  4724. end;
  4725. end;
  4726. {$endif DEBUG_NODE_XML}
  4727. {***************************************************************************
  4728. trecorddef
  4729. ***************************************************************************}
  4730. constructor trecorddef.create(const n:string; p:TSymtable);
  4731. begin
  4732. inherited create(n,recorddef,true);
  4733. symtable:=p;
  4734. { we can own the symtable only if nobody else owns a copy so far }
  4735. if symtable.refcount=1 then
  4736. symtable.defowner:=self;
  4737. isunion:=false;
  4738. cloneddefderef.reset;
  4739. end;
  4740. constructor trecorddef.create_internal(const n: string; packrecords, recordalignmin: shortint; where: tsymtable);
  4741. var
  4742. name : string;
  4743. pname : pshortstring;
  4744. oldsymtablestack: tsymtablestack;
  4745. ts: ttypesym;
  4746. begin
  4747. { construct name }
  4748. if n<>'' then
  4749. pname:=@n
  4750. else
  4751. begin
  4752. init_defid;
  4753. name:='$InternalRec'+unique_id_str;
  4754. pname:=@name;
  4755. end;
  4756. oldsymtablestack:=symtablestack;
  4757. { do not simply push/pop current_module.localsymtable, because
  4758. that can have side-effects (e.g., it removes helpers) }
  4759. symtablestack:=nil;
  4760. symtable:=trecordsymtable.create(pname^,packrecords,recordalignmin);
  4761. symtable.defowner:=self;
  4762. isunion:=false;
  4763. inherited create(pname^,recorddef,true);
  4764. where.insertdef(self);
  4765. { if we specified a name, then we'll probably want to look up the
  4766. type again by name too -> create typesym }
  4767. if n<>'' then
  4768. begin
  4769. ts:=ctypesym.create(n,self);
  4770. include(ts.symoptions,sp_internal);
  4771. { avoid hints about unused types (these may only be used for
  4772. typed constant data) }
  4773. ts.increfcount;
  4774. where.insertsym(ts);
  4775. end;
  4776. symtablestack:=oldsymtablestack;
  4777. { don't create RTTI for internal types, these are not exported }
  4778. defstates:=defstates+[ds_rtti_table_written,ds_init_table_written];
  4779. include(defoptions,df_internal);
  4780. end;
  4781. constructor trecorddef.create_global_internal(const n: string; packrecords, recordalignmin: shortint);
  4782. var
  4783. where : tsymtable;
  4784. begin
  4785. where:=current_module.localsymtable;
  4786. if not assigned(where) then
  4787. where:=current_module.globalsymtable;
  4788. create_internal(n,packrecords,recordalignmin,where);
  4789. end;
  4790. function trecorddef.add_field_by_def(const optionalname: TIDString; def: tdef): tsym;
  4791. var
  4792. sym: tfieldvarsym;
  4793. name: TIDString;
  4794. pname: ^TIDString;
  4795. begin
  4796. if optionalname='' then
  4797. begin
  4798. name:='$f'+tostr(trecordsymtable(symtable).symlist.count);
  4799. pname:=@name
  4800. end
  4801. else
  4802. pname:=@optionalname;
  4803. sym:=cfieldvarsym.create(pname^,vs_value,def,[]);
  4804. symtable.insertsym(sym);
  4805. trecordsymtable(symtable).addfield(sym,vis_hidden);
  4806. result:=sym;
  4807. end;
  4808. procedure trecorddef.add_fields_from_deflist(fieldtypes: tfplist);
  4809. var
  4810. i: longint;
  4811. begin
  4812. for i:=0 to fieldtypes.count-1 do
  4813. add_field_by_def('',tdef(fieldtypes[i]));
  4814. end;
  4815. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  4816. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  4817. var
  4818. i,j : longint;
  4819. begin
  4820. if ppufile.getbyte=1 then
  4821. begin
  4822. new(variantrecdesc);
  4823. ppufile.getderef(variantrecdesc^.variantselectorderef);
  4824. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  4825. for i:=0 to high(variantrecdesc^.branches) do
  4826. begin
  4827. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  4828. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4829. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  4830. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4831. end;
  4832. end
  4833. else
  4834. variantrecdesc:=nil;
  4835. end;
  4836. begin
  4837. inherited ppuload(recorddef,ppufile);
  4838. if df_copied_def in defoptions then
  4839. begin
  4840. ppufile.getderef(cloneddefderef);
  4841. ppuload_platform(ppufile);
  4842. end
  4843. else
  4844. begin
  4845. symtable:=trecordsymtable.create(objrealname^,0,0);
  4846. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  4847. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  4848. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  4849. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  4850. trecordsymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  4851. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  4852. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  4853. ppufile.getset(tppuset1(trecordsymtable(symtable).managementoperators));
  4854. { position of ppuload_platform call must correspond
  4855. to position of writeentry in ppuwrite method }
  4856. ppuload_platform(ppufile);
  4857. trecordsymtable(symtable).ppuload(ppufile);
  4858. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4859. but because iso mode supports no units, there is no need to store the variantrecdesc
  4860. in the ppu
  4861. }
  4862. // readvariantrecdesc(variantrecdesc);
  4863. { requires usefieldalignment to be set }
  4864. symtable.defowner:=self;
  4865. end;
  4866. isunion:=false;
  4867. end;
  4868. destructor trecorddef.destroy;
  4869. procedure free_variantrecdesc(var variantrecdesc : pvariantrecdesc);
  4870. var
  4871. i : longint;
  4872. begin
  4873. while assigned(variantrecdesc) do
  4874. begin
  4875. for i:=0 to high(variantrecdesc^.branches) do
  4876. begin
  4877. free_variantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4878. SetLength(variantrecdesc^.branches[i].values,0);
  4879. end;
  4880. SetLength(variantrecdesc^.branches,0);
  4881. dispose(variantrecdesc);
  4882. variantrecdesc:=nil;
  4883. end;
  4884. end;
  4885. begin
  4886. if assigned(variantrecdesc) then
  4887. free_variantrecdesc(variantrecdesc);
  4888. if assigned(symtable) then
  4889. begin
  4890. symtable.free;
  4891. symtable:=nil;
  4892. end;
  4893. inherited destroy;
  4894. end;
  4895. function trecorddef.getcopy : tstoreddef;
  4896. begin
  4897. result:=crecorddef.create(objrealname^,symtable.getcopy);
  4898. trecorddef(result).isunion:=isunion;
  4899. include(trecorddef(result).defoptions,df_copied_def);
  4900. if assigned(tcinitcode) then
  4901. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  4902. if assigned(import_lib) then
  4903. trecorddef(result).import_lib:=stringdup(import_lib^);
  4904. end;
  4905. function trecorddef.needs_inittable : boolean;
  4906. begin
  4907. { each record with managed field or with any management operator needs
  4908. init table }
  4909. needs_inittable:=(trecordsymtable(symtable).managementoperators<>[]) or
  4910. trecordsymtable(symtable).needs_init_final
  4911. end;
  4912. function trecorddef.needs_separate_initrtti : boolean;
  4913. begin
  4914. result:=true;
  4915. end;
  4916. function trecorddef.has_non_trivial_init_child(check_parent:boolean):boolean;
  4917. begin
  4918. result:=trecordsymtable(symtable).has_non_trivial_init;
  4919. end;
  4920. procedure trecorddef.buildderef;
  4921. begin
  4922. inherited buildderef;
  4923. if df_copied_def in defoptions then
  4924. cloneddefderef.build(symtable.defowner)
  4925. else
  4926. tstoredsymtable(symtable).buildderef;
  4927. end;
  4928. procedure trecorddef.deref;
  4929. begin
  4930. inherited deref;
  4931. { now dereference the definitions }
  4932. if df_copied_def in defoptions then
  4933. begin
  4934. cloneddef:=trecorddef(cloneddefderef.resolve);
  4935. symtable:=cloneddef.symtable.getcopy;
  4936. end
  4937. else
  4938. tstoredsymtable(symtable).deref(false);
  4939. { internal types, only load from the system unit }
  4940. if assigned(owner) and
  4941. assigned(owner.name) and
  4942. (owner.name^='SYSTEM') then
  4943. begin
  4944. { TGUID }
  4945. if not assigned(rec_tguid) and
  4946. (upper(typename)='TGUID') then
  4947. rec_tguid:=self
  4948. { JMP_BUF }
  4949. else if not assigned(rec_jmp_buf) and
  4950. (upper(typename)='JMP_BUF') then
  4951. rec_jmp_buf:=self
  4952. else if not assigned(rec_exceptaddr) and
  4953. (upper(typename)='TEXCEPTADDR') then
  4954. rec_exceptaddr:=self;
  4955. end;
  4956. end;
  4957. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  4958. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  4959. var
  4960. i,j : longint;
  4961. begin
  4962. if assigned(variantrecdesc) then
  4963. begin
  4964. ppufile.putbyte(1);
  4965. ppufile.putderef(variantrecdesc^.variantselectorderef);
  4966. ppufile.putasizeint(length(variantrecdesc^.branches));
  4967. for i:=0 to high(variantrecdesc^.branches) do
  4968. begin
  4969. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  4970. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4971. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  4972. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4973. end;
  4974. end
  4975. else
  4976. ppufile.putbyte(0);
  4977. end;
  4978. begin
  4979. inherited ppuwrite(ppufile);
  4980. if df_copied_def in defoptions then
  4981. ppufile.putderef(cloneddefderef)
  4982. else
  4983. begin
  4984. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  4985. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  4986. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  4987. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  4988. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignmin));
  4989. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  4990. ppufile.putword(trecordsymtable(symtable).paddingsize);
  4991. ppufile.putset(tppuset1(trecordsymtable(symtable).managementoperators));
  4992. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4993. but because iso mode supports no units, there is no need to store the variantrecdesc
  4994. in the ppu
  4995. }
  4996. // writevariantrecdesc(variantrecdesc);
  4997. end;
  4998. writeentry(ppufile,ibrecorddef);
  4999. if not(df_copied_def in defoptions) then
  5000. trecordsymtable(symtable).ppuwrite(ppufile);
  5001. end;
  5002. function trecorddef.size:asizeint;
  5003. begin
  5004. result:=trecordsymtable(symtable).datasize;
  5005. end;
  5006. function trecorddef.alignment:shortint;
  5007. begin
  5008. alignment:=trecordsymtable(symtable).recordalignment;
  5009. end;
  5010. function trecorddef.padalignment:shortint;
  5011. begin
  5012. padalignment := trecordsymtable(symtable).padalignment;
  5013. end;
  5014. function trecorddef.GetTypeName : string;
  5015. begin
  5016. GetTypeName:='<record type>'
  5017. end;
  5018. {$ifdef DEBUG_NODE_XML}
  5019. function TRecordDef.XMLPrintType: ansistring;
  5020. begin
  5021. Result := '&lt;record&gt;';
  5022. end;
  5023. {$endif DEBUG_NODE_XML}
  5024. {***************************************************************************
  5025. TABSTRACTPROCDEF
  5026. ***************************************************************************}
  5027. constructor tabstractprocdef.create(dt:tdeftyp;level:byte;doregister:boolean);
  5028. begin
  5029. inherited create(dt,doregister);
  5030. parast:=tparasymtable.create(self,level);
  5031. paras:=nil;
  5032. minparacount:=0;
  5033. maxparacount:=0;
  5034. proctypeoption:=potype_none;
  5035. proccalloption:=pocall_none;
  5036. procoptions:=[];
  5037. returndef:=voidtype;
  5038. returndefderef.reset;
  5039. savesize:=sizeof(pint);
  5040. callerargareasize:=0;
  5041. calleeargareasize:=0;
  5042. has_paraloc_info:=callnoside;
  5043. funcretloc[callerside].init;
  5044. funcretloc[calleeside].init;
  5045. check_mark_as_nested;
  5046. end;
  5047. destructor tabstractprocdef.destroy;
  5048. begin
  5049. if assigned(paras) then
  5050. begin
  5051. {$ifdef MEMDEBUG}
  5052. memprocpara.start;
  5053. {$endif MEMDEBUG}
  5054. paras.free;
  5055. paras:=nil;
  5056. {$ifdef MEMDEBUG}
  5057. memprocpara.stop;
  5058. {$endif MEMDEBUG}
  5059. end;
  5060. if assigned(parast) then
  5061. begin
  5062. {$ifdef MEMDEBUG}
  5063. memprocparast.start;
  5064. {$endif MEMDEBUG}
  5065. parast.free;
  5066. parast:=nil;
  5067. {$ifdef MEMDEBUG}
  5068. memprocparast.stop;
  5069. {$endif MEMDEBUG}
  5070. end;
  5071. funcretloc[callerside].done;
  5072. funcretloc[calleeside].done;
  5073. inherited destroy;
  5074. end;
  5075. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  5076. begin
  5077. if (tsym(p).typ<>paravarsym) then
  5078. exit;
  5079. inc(plongint(arg)^);
  5080. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  5081. begin
  5082. if not assigned(tparavarsym(p).defaultconstsym) then
  5083. inc(minparacount);
  5084. inc(maxparacount);
  5085. end;
  5086. end;
  5087. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  5088. begin
  5089. if (tsym(p).typ<>paravarsym) then
  5090. exit;
  5091. paras.add(p);
  5092. end;
  5093. procedure tabstractprocdef.calcparas;
  5094. var
  5095. paracount : longint;
  5096. begin
  5097. { This can already be assigned when
  5098. we need to reresolve this unit (PFV) }
  5099. if assigned(paras) then
  5100. paras.free;
  5101. paras:=tparalist.create(false);
  5102. paracount:=0;
  5103. minparacount:=0;
  5104. maxparacount:=0;
  5105. parast.SymList.ForEachCall(@count_para,@paracount);
  5106. paras.capacity:=paracount;
  5107. { Insert parameters in table }
  5108. parast.SymList.ForEachCall(@insert_para,nil);
  5109. { Order parameters }
  5110. paras.sortparas;
  5111. end;
  5112. function tabstractprocdef.mangledprocparanames(oldlen : longint) : string;
  5113. var
  5114. hash : qword;
  5115. hp : TParavarsym;
  5116. hs : TSymStr;
  5117. newlen,
  5118. i : integer;
  5119. begin
  5120. result:='';
  5121. hp:=nil;
  5122. { add parameter types }
  5123. for i:=0 to paras.count-1 do
  5124. begin
  5125. hp:=tparavarsym(paras[i]);
  5126. if not(vo_is_hidden_para in hp.varoptions) then
  5127. result:=result+'$'+hp.vardef.mangledparaname;
  5128. end;
  5129. { add resultdef, add $$ as separator to make it unique from a
  5130. parameter separator }
  5131. if not is_void(returndef) then
  5132. result:=result+'$$'+returndef.mangledparaname;
  5133. newlen:=length(result)+oldlen;
  5134. { Replace with hash if the parameter line is very long }
  5135. if (newlen-oldlen>12) and
  5136. ((newlen>100) or (newlen-oldlen>64)) then
  5137. begin
  5138. hash:=InitFnv64;
  5139. for i:=0 to paras.count-1 do
  5140. begin
  5141. hp:=tparavarsym(paras[i]);
  5142. if not(vo_is_hidden_para in hp.varoptions) then
  5143. begin
  5144. hs:=hp.vardef.mangledparaname;
  5145. hash:=UpdateFnv64(hash,hs[1],length(hs));
  5146. end;
  5147. end;
  5148. if not is_void(returndef) then
  5149. begin
  5150. { add a little prefix so that x(integer; integer) is different from x(integer):integer }
  5151. hs:='$$'+returndef.mangledparaname;
  5152. hash:=UpdateFnv64(hash,hs[1],length(hs));
  5153. end;
  5154. result:='$h'+Base64Mangle(hash);
  5155. end;
  5156. end;
  5157. procedure tabstractprocdef.buildderef;
  5158. begin
  5159. { released procdef? }
  5160. if not assigned(parast) then
  5161. exit;
  5162. inherited buildderef;
  5163. returndefderef.build(returndef);
  5164. if po_explicitparaloc in procoptions then
  5165. funcretloc[callerside].buildderef;
  5166. { parast }
  5167. tparasymtable(parast).buildderef;
  5168. end;
  5169. procedure tabstractprocdef.deref;
  5170. begin
  5171. inherited deref;
  5172. returndef:=tdef(returndefderef.resolve);
  5173. if po_explicitparaloc in procoptions then
  5174. begin
  5175. funcretloc[callerside].deref;
  5176. has_paraloc_info:=callerside;
  5177. end
  5178. else
  5179. begin
  5180. { deref is called after loading from a ppu, but also after another
  5181. unit has been reloaded/recompiled and all references must be
  5182. re-resolved. Since the funcretloc contains a reference to a tdef,
  5183. reset it so that we won't try to access the stale def }
  5184. funcretloc[callerside].init;
  5185. has_paraloc_info:=callnoside;
  5186. end;
  5187. { parast }
  5188. tparasymtable(parast).deref(false);
  5189. { recalculated parameters }
  5190. calcparas;
  5191. end;
  5192. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  5193. begin
  5194. inherited ppuload(dt,ppufile);
  5195. parast:=nil;
  5196. Paras:=nil;
  5197. minparacount:=0;
  5198. maxparacount:=0;
  5199. ppufile.getderef(returndefderef);
  5200. proctypeoption:=tproctypeoption(ppufile.getbyte);
  5201. proccalloption:=tproccalloption(ppufile.getbyte);
  5202. ppufile.getset(tppuset8(procoptions));
  5203. funcretloc[callerside].init;
  5204. if po_explicitparaloc in procoptions then
  5205. funcretloc[callerside].ppuload(ppufile);
  5206. savesize:=sizeof(pint);
  5207. if (po_explicitparaloc in procoptions) then
  5208. has_paraloc_info:=callerside;
  5209. end;
  5210. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  5211. var
  5212. oldintfcrc : boolean;
  5213. begin
  5214. { released procdef? }
  5215. if not assigned(parast) then
  5216. exit;
  5217. inherited ppuwrite(ppufile);
  5218. ppufile.putderef(returndefderef);
  5219. oldintfcrc:=ppufile.do_interface_crc;
  5220. ppufile.do_interface_crc:=false;
  5221. ppufile.putbyte(ord(proctypeoption));
  5222. ppufile.putbyte(ord(proccalloption));
  5223. ppufile.putset(tppuset8(procoptions));
  5224. ppufile.do_interface_crc:=oldintfcrc;
  5225. if (po_explicitparaloc in procoptions) then
  5226. funcretloc[callerside].ppuwrite(ppufile);
  5227. end;
  5228. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  5229. var
  5230. hs,s : ansistring;
  5231. hp : TParavarsym;
  5232. hpc : tconstsym;
  5233. first : boolean;
  5234. i,j : integer;
  5235. begin
  5236. s:='';
  5237. first:=true;
  5238. for i:=0 to paras.count-1 do
  5239. begin
  5240. hp:=tparavarsym(paras[i]);
  5241. if not(vo_is_hidden_para in hp.varoptions) or
  5242. (pno_showhidden in pno) then
  5243. begin
  5244. if first then
  5245. begin
  5246. s:=s+'(';
  5247. first:=false;
  5248. end
  5249. else
  5250. s:=s+';';
  5251. if vo_is_hidden_para in hp.varoptions then
  5252. s:=s+'<';
  5253. case hp.varspez of
  5254. vs_var :
  5255. s:=s+'var ';
  5256. vs_const :
  5257. s:=s+'const ';
  5258. vs_out :
  5259. s:=s+'out ';
  5260. vs_constref :
  5261. s:=s+'constref ';
  5262. else
  5263. ;
  5264. end;
  5265. if (pno_paranames in pno) then
  5266. s:=s+hp.realname+':';
  5267. if hp.univpara then
  5268. s:=s+'univ ';
  5269. if assigned(hp.vardef.typesym) then
  5270. begin
  5271. hs:=hp.vardef.typesym.realname;
  5272. if hs[1]<>'$' then
  5273. s:=s+hp.vardef.OwnerHierarchyName+hs
  5274. else
  5275. s:=s+hp.vardef.GetTypeName;
  5276. end
  5277. else
  5278. s:=s+hp.vardef.GetTypeName;
  5279. { default value }
  5280. if assigned(hp.defaultconstsym) then
  5281. begin
  5282. hpc:=tconstsym(hp.defaultconstsym);
  5283. hs:='';
  5284. case hpc.consttyp of
  5285. constwresourcestring,
  5286. constwstring:
  5287. begin
  5288. if hpc.value.valuews.len>0 then
  5289. begin
  5290. setlength(hs,hpc.value.valuews.len);
  5291. for j:=0 to hpc.value.valuews.len-1 do
  5292. begin
  5293. if (ord(hpc.value.valuews.data[j])<127) and
  5294. not(byte(hpc.value.valuews.data[j]) in [0,10,13]) then
  5295. hs[j+1]:=char(hpc.value.valuews.data[j])
  5296. else
  5297. hs[j+1]:='.';
  5298. end;
  5299. end;
  5300. end;
  5301. conststring,
  5302. constresourcestring :
  5303. begin
  5304. if hpc.value.len>0 then
  5305. begin
  5306. setLength(hs,hpc.value.len);
  5307. { don't write past the end of hs if the constant
  5308. is > 255 chars }
  5309. move(hpc.value.valueptr^,hs[1],length(hs));
  5310. { make sure that constant strings with newline chars
  5311. don't create a linebreak in the assembler code,
  5312. since comments are line-based. Also remove nulls
  5313. because the comments are written as a pchar. }
  5314. ReplaceCase(hs,#0,'.');
  5315. ReplaceCase(hs,#10,'.');
  5316. ReplaceCase(hs,#13,'.');
  5317. end;
  5318. end;
  5319. constreal :
  5320. str(pbestreal(hpc.value.valueptr)^,hs);
  5321. constpointer :
  5322. hs:=tostr(hpc.value.valueordptr);
  5323. constord :
  5324. begin
  5325. if is_boolean(hpc.constdef) then
  5326. begin
  5327. if hpc.value.valueord<>0 then
  5328. hs:='TRUE'
  5329. else
  5330. hs:='FALSE';
  5331. end
  5332. else
  5333. hs:=tostr(hpc.value.valueord);
  5334. end;
  5335. constnil :
  5336. hs:='nil';
  5337. constset :
  5338. hs:='<set>';
  5339. constguid:
  5340. hs:=guid2string(pguid(hpc.value.valueptr)^);
  5341. constnone:
  5342. internalerror(2019050704);
  5343. end;
  5344. if hs<>'' then
  5345. s:=s+'=`'+hs+'`';
  5346. end;
  5347. if vo_is_hidden_para in hp.varoptions then
  5348. s:=s+'>';
  5349. end;
  5350. end;
  5351. if not first then
  5352. s:=s+')';
  5353. if (po_varargs in procoptions) then
  5354. s:=s+';VarArgs';
  5355. typename_paras:=s;
  5356. end;
  5357. function tabstractprocdef.is_methodpointer:boolean;
  5358. begin
  5359. result:=false;
  5360. end;
  5361. function tabstractprocdef.is_addressonly:boolean;
  5362. begin
  5363. result:=true;
  5364. end;
  5365. function tabstractprocdef.no_self_node: boolean;
  5366. begin
  5367. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  5368. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  5369. end;
  5370. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  5371. var
  5372. j, nestinglevel: longint;
  5373. pvs, npvs: tparavarsym;
  5374. begin
  5375. nestinglevel:=parast.symtablelevel;
  5376. if newtyp=procdef then
  5377. begin
  5378. if (copytyp<>pc_bareproc) then
  5379. result:=cprocdef.create(nestinglevel,doregister)
  5380. else
  5381. result:=cprocdef.create(normal_function_level,doregister);
  5382. tprocdef(result).visibility:=vis_public;
  5383. end
  5384. else
  5385. begin
  5386. result:=cprocvardef.create(nestinglevel,true);
  5387. end;
  5388. tabstractprocdef(result).returndef:=returndef;
  5389. tabstractprocdef(result).returndefderef:=returndefderef;
  5390. pvs:=nil;
  5391. npvs:=nil;
  5392. if copytyp<>pc_normal_no_paras then
  5393. begin
  5394. for j:=0 to parast.symlist.count-1 do
  5395. begin
  5396. case tsym(parast.symlist[j]).typ of
  5397. paravarsym:
  5398. begin
  5399. pvs:=tparavarsym(parast.symlist[j]);
  5400. { in case of bare proc, don't copy self, vmt or framepointer
  5401. parameters }
  5402. if (copytyp in [pc_bareproc,pc_normal_no_hidden]) and
  5403. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result,vo_is_funcret,vo_is_high_para]*pvs.varoptions)<>[]) then
  5404. continue;
  5405. if paraprefix='' then
  5406. npvs:=cparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  5407. pvs.vardef,pvs.varoptions)
  5408. else if not(vo_is_high_para in pvs.varoptions) then
  5409. npvs:=cparavarsym.create(paraprefix+pvs.realname,pvs.paranr,pvs.varspez,
  5410. pvs.vardef,pvs.varoptions)
  5411. else
  5412. npvs:=cparavarsym.create('$high'+paraprefix+copy(pvs.name,5,length(pvs.name)),pvs.paranr,pvs.varspez,
  5413. pvs.vardef,pvs.varoptions);
  5414. npvs.defaultconstsym:=pvs.defaultconstsym;
  5415. tabstractprocdef(result).parast.insertsym(npvs);
  5416. end;
  5417. constsym:
  5418. begin
  5419. // ignore, reuse original constym. Should also be duplicated
  5420. // be safe though
  5421. end;
  5422. symconst.typesym:
  5423. begin
  5424. // reuse original, part of generic declaration
  5425. end
  5426. else
  5427. internalerror(201160604);
  5428. end;
  5429. end;
  5430. end;
  5431. tabstractprocdef(result).savesize:=savesize;
  5432. if (typ<>procvardef) and
  5433. (newtyp=procvardef) then
  5434. begin
  5435. { procvars can't be (class)constructures/destructors etc }
  5436. if proctypeoption=potype_constructor then
  5437. begin
  5438. tabstractprocdef(result).returndef:=tdef(owner.defowner);
  5439. if not(is_implicit_pointer_object_type(returndef) or
  5440. (returndef.typ<>objectdef)) then
  5441. tabstractprocdef(result).returndef:=cpointerdef.getreusable(tabstractprocdef(result).returndef);
  5442. tabstractprocdef(result).proctypeoption:=potype_function;
  5443. end
  5444. else if is_void(returndef) then
  5445. tabstractprocdef(result).proctypeoption:=potype_procedure
  5446. else
  5447. tabstractprocdef(result).proctypeoption:=potype_function;
  5448. end
  5449. else
  5450. tabstractprocdef(result).proctypeoption:=proctypeoption;
  5451. tabstractprocdef(result).proccalloption:=proccalloption;
  5452. tabstractprocdef(result).procoptions:=procoptions;
  5453. if (copytyp=pc_bareproc) then
  5454. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  5455. if newtyp=procvardef then
  5456. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  5457. if copytyp=pc_address_only then
  5458. include(tabstractprocdef(result).procoptions,po_addressonly);
  5459. tabstractprocdef(result).callerargareasize:=callerargareasize;
  5460. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  5461. tabstractprocdef(result).maxparacount:=maxparacount;
  5462. tabstractprocdef(result).minparacount:=minparacount;
  5463. if po_explicitparaloc in procoptions then
  5464. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  5465. { recalculate parameter info }
  5466. tabstractprocdef(result).has_paraloc_info:=callnoside;
  5467. {$ifdef m68k}
  5468. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  5469. {$endif}
  5470. if (typ=procdef) and
  5471. (newtyp=procvardef) and
  5472. (owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  5473. include(tprocvardef(result).procoptions,po_methodpointer);
  5474. end;
  5475. function tabstractprocdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  5476. begin
  5477. result:=is_addressonly;
  5478. end;
  5479. procedure tabstractprocdef.check_mark_as_nested;
  5480. begin
  5481. { nested procvars require that nested functions use the Delphi-style
  5482. nested procedure calling convention }
  5483. if (parast.symtablelevel>normal_function_level) and
  5484. (m_nested_procvars in current_settings.modeswitches) then
  5485. include(procoptions,po_delphi_nested_cc);
  5486. end;
  5487. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  5488. begin
  5489. if (side in [callerside,callbothsides]) and
  5490. not(has_paraloc_info in [callerside,callbothsides]) then
  5491. begin
  5492. if not is_c_variadic(self) then
  5493. callerargareasize:=paramanager.create_paraloc_info(self,callerside)
  5494. else
  5495. callerargareasize:=paramanager.create_varargs_paraloc_info(self,callerside,nil);
  5496. if has_paraloc_info in [calleeside,callbothsides] then
  5497. has_paraloc_info:=callbothsides
  5498. else
  5499. has_paraloc_info:=callerside;
  5500. end;
  5501. if (side in [calleeside,callbothsides]) and
  5502. not(has_paraloc_info in [calleeside,callbothsides]) then
  5503. begin
  5504. if not is_c_variadic(self) then
  5505. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside)
  5506. else
  5507. callerargareasize:=paramanager.create_varargs_paraloc_info(self,calleeside,nil);
  5508. if has_paraloc_info in [callerside,callbothsides] then
  5509. has_paraloc_info:=callbothsides
  5510. else
  5511. has_paraloc_info:=calleeside;
  5512. end;
  5513. end;
  5514. procedure tabstractprocdef.done_paraloc_info(side: tcallercallee);
  5515. var
  5516. i: longint;
  5517. begin
  5518. if (side in [callerside,callbothsides]) and
  5519. (has_paraloc_info in [callerside,callbothsides]) then
  5520. begin
  5521. funcretloc[callerside].done;
  5522. for i:=0 to paras.count-1 do
  5523. tparavarsym(paras[i]).paraloc[callerside].done;
  5524. if has_paraloc_info=callerside then
  5525. has_paraloc_info:=callnoside
  5526. else
  5527. has_paraloc_info:=calleeside;
  5528. end;
  5529. if (side in [calleeside,callbothsides]) and
  5530. (has_paraloc_info in [calleeside,callbothsides]) then
  5531. begin
  5532. funcretloc[calleeside].done;
  5533. for i:=0 to paras.count-1 do
  5534. tparavarsym(paras[i]).paraloc[calleeside].done;
  5535. if has_paraloc_info=calleeside then
  5536. has_paraloc_info:=callnoside
  5537. else
  5538. has_paraloc_info:=callerside;
  5539. end;
  5540. end;
  5541. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  5542. var
  5543. p: tparavarsym;
  5544. ploc: PCGParalocation;
  5545. i: longint;
  5546. begin
  5547. result:=false;
  5548. init_paraloc_info(side);
  5549. for i:=0 to parast.SymList.Count-1 do
  5550. if tsym(parast.SymList[i]).typ=paravarsym then
  5551. begin
  5552. p:=tparavarsym(parast.SymList[i]);
  5553. if not p.is_used then
  5554. continue;
  5555. { check if no parameter is located on the stack }
  5556. if (is_open_array(p.vardef) or
  5557. is_array_of_const(p.vardef)) and (p.varspez=vs_value) then
  5558. begin
  5559. result:=true;
  5560. exit;
  5561. end;
  5562. ploc:=p.paraloc[side].location;
  5563. while assigned(ploc) do
  5564. begin
  5565. if (ploc^.loc=LOC_REFERENCE) then
  5566. begin
  5567. result:=true;
  5568. exit
  5569. end;
  5570. ploc:=ploc^.next;
  5571. end;
  5572. end;
  5573. end;
  5574. function tabstractprocdef.is_pushleftright: boolean;
  5575. begin
  5576. result:=false;
  5577. end;
  5578. function tabstractprocdef.address_type: tdef;
  5579. begin
  5580. result:=voidcodepointertype;
  5581. end;
  5582. function tabstractprocdef.ofs_address_type:tdef;
  5583. begin
  5584. result:=address_type;
  5585. end;
  5586. procedure tabstractprocdef.declared_far;
  5587. begin
  5588. Message1(parser_w_proc_directive_ignored,'FAR');
  5589. end;
  5590. procedure tabstractprocdef.declared_near;
  5591. begin
  5592. Message1(parser_w_proc_directive_ignored,'NEAR');
  5593. end;
  5594. function tabstractprocdef.generate_safecall_wrapper: boolean;
  5595. begin
  5596. {$ifdef SUPPORT_SAFECALL}
  5597. result:=
  5598. (proccalloption=pocall_safecall) and
  5599. not(po_assembler in procoptions) and
  5600. (tf_safecall_exceptions in target_info.flags);
  5601. {$else SUPPORT_SAFECALL}
  5602. result:=false;
  5603. {$endif}
  5604. end;
  5605. function tabstractprocdef.is_generic_param(def:tdef): boolean;
  5606. begin
  5607. if def.typ=undefineddef then
  5608. result:=def.owner=self.parast
  5609. else if def.typ=objectdef then
  5610. result:=(def.owner=self.parast) and (tstoreddef(def).genconstraintdata<>nil)
  5611. else
  5612. result:=false;
  5613. end;
  5614. function tabstractprocdef.wpo_may_create_instance(optionalmethodpointer: tnode): boolean;
  5615. begin
  5616. result:=
  5617. (proctypeoption=potype_constructor) or
  5618. ((typ=procdef) and
  5619. ((not assigned(optionalmethodpointer) and
  5620. is_class(tdef(owner.defowner))) or
  5621. (assigned(optionalmethodpointer) and
  5622. ((optionalmethodpointer.resultdef.typ=classrefdef) or
  5623. (optionalmethodpointer.nodetype=typen)))) and
  5624. (tprocdef(self).procsym.Name='NEWINSTANCE'))
  5625. end;
  5626. {***************************************************************************
  5627. TPROCDEF
  5628. ***************************************************************************}
  5629. function tprocdef.getparentfpsym: tsym;
  5630. begin
  5631. if not assigned(_parentfpsym) then
  5632. begin
  5633. _parentfpsym:=tsym(parast.Find('parentfp'));
  5634. if not assigned(_parentfpsym) then
  5635. internalerror(200309281);
  5636. end;
  5637. result:=_parentfpsym;
  5638. end;
  5639. function tprocdef.Getis_implemented: boolean;
  5640. begin
  5641. result:=not assigned(implprocdefinfo) or implprocdefinfo^.is_implemented;
  5642. end;
  5643. procedure tprocdef.Setis_implemented(AValue: boolean);
  5644. begin
  5645. if not assigned(implprocdefinfo) then
  5646. internalerror(2020062101);
  5647. implprocdefinfo^.is_implemented:=AValue;
  5648. end;
  5649. function tprocdef.getwas_anonymous:boolean;
  5650. begin
  5651. result:=assigned(implprocdefinfo) and implprocdefinfo^.was_anonymous;
  5652. end;
  5653. procedure tprocdef.setwas_anonymous(avalue:boolean);
  5654. begin
  5655. if not assigned(implprocdefinfo) then
  5656. internalerror(2022020502);
  5657. implprocdefinfo^.was_anonymous:=avalue;
  5658. end;
  5659. function tprocdef.gethas_capturer:boolean;
  5660. begin
  5661. result:=assigned(implprocdefinfo) and implprocdefinfo^.has_capturer;
  5662. end;
  5663. procedure tprocdef.sethas_capturer(avalue:boolean);
  5664. begin
  5665. if not assigned(implprocdefinfo) then
  5666. internalerror(2022020503);
  5667. implprocdefinfo^.has_capturer:=avalue;
  5668. end;
  5669. function tprocdef.Getcapturedsyms:tfplist;
  5670. begin
  5671. if not assigned(implprocdefinfo) then
  5672. result:=nil
  5673. else
  5674. result:=implprocdefinfo^.capturedsyms;
  5675. end;
  5676. function tprocdef.store_localst: boolean;
  5677. begin
  5678. result:=has_inlininginfo or (df_generic in defoptions);
  5679. end;
  5680. function tprocdef.GetResultName: PShortString;
  5681. begin
  5682. if not assigned(implprocdefinfo) then
  5683. internalerror(2014010301);
  5684. result:=implprocdefinfo^.resultname;
  5685. end;
  5686. procedure tprocdef.SetResultName(AValue: PShortString);
  5687. begin
  5688. if not assigned(implprocdefinfo) then
  5689. internalerror(2014010302);
  5690. implprocdefinfo^.resultname:=AValue;
  5691. end;
  5692. function tprocdef.GetParentFPInitBlock: tnode;
  5693. begin
  5694. if not assigned(implprocdefinfo) then
  5695. internalerror(2014010303);
  5696. result:=implprocdefinfo^.parentfpinitblock;
  5697. end;
  5698. function tprocdef.GetParentFPStruct: tsym;
  5699. begin
  5700. if not assigned(implprocdefinfo) then
  5701. internalerror(2014010304);
  5702. result:=implprocdefinfo^.parentfpstruct;
  5703. end;
  5704. function tprocdef.GetParentFPStructPtrType: tdef;
  5705. begin
  5706. if not assigned(implprocdefinfo) then
  5707. internalerror(2014010305);
  5708. result:=implprocdefinfo^.parentfpstructptrtype;
  5709. end;
  5710. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  5711. begin
  5712. if not assigned(implprocdefinfo) then
  5713. internalerror(2014010306);
  5714. implprocdefinfo^.parentfpinitblock:=AValue;
  5715. end;
  5716. function tprocdef.Getprocendtai: tai;
  5717. begin
  5718. if not assigned(implprocdefinfo) then
  5719. internalerror(2014010307);
  5720. result:=implprocdefinfo^.procendtai;
  5721. end;
  5722. function tprocdef.Getprocstarttai: tai;
  5723. begin
  5724. if not assigned(implprocdefinfo) then
  5725. internalerror(2014010308);
  5726. result:=implprocdefinfo^.procstarttai;
  5727. end;
  5728. procedure tprocdef.Setprocendtai(AValue: tai);
  5729. begin
  5730. if not assigned(implprocdefinfo) then
  5731. internalerror(2014010309);
  5732. implprocdefinfo^.procendtai:=AValue;
  5733. end;
  5734. function tprocdef.Getskpara: pointer;
  5735. begin
  5736. if not assigned(implprocdefinfo) then
  5737. internalerror(2014010310);
  5738. result:=implprocdefinfo^.skpara;
  5739. end;
  5740. procedure tprocdef.Setskpara(AValue: pointer);
  5741. begin
  5742. if not assigned(implprocdefinfo) then
  5743. internalerror(2014010311);
  5744. implprocdefinfo^.skpara:=AValue;
  5745. end;
  5746. function tprocdef.Getpersonality: tprocdef;
  5747. begin
  5748. if not assigned(implprocdefinfo) then
  5749. internalerror(2016121704);
  5750. result:=implprocdefinfo^.personality;
  5751. end;
  5752. procedure tprocdef.Setpersonality(AValue: tprocdef);
  5753. begin
  5754. if not assigned(implprocdefinfo) then
  5755. internalerror(2016121705);
  5756. implprocdefinfo^.personality:=AValue;
  5757. end;
  5758. function tprocdef.Getforwarddef: boolean;
  5759. begin
  5760. if not assigned(implprocdefinfo) then
  5761. internalerror(2014010312);
  5762. result:=implprocdefinfo^.forwarddef;
  5763. end;
  5764. function tprocdef.Gethasforward: boolean;
  5765. begin
  5766. if not assigned(implprocdefinfo) then
  5767. internalerror(2014010313);
  5768. result:=implprocdefinfo^.hasforward;
  5769. end;
  5770. function tprocdef.Getinterfacedef: boolean;
  5771. begin
  5772. if not assigned(implprocdefinfo) then
  5773. internalerror(2014010314);
  5774. result:=implprocdefinfo^.interfacedef;
  5775. end;
  5776. procedure tprocdef.Setforwarddef(AValue: boolean);
  5777. begin
  5778. if not assigned(implprocdefinfo) then
  5779. internalerror(2014010315);
  5780. implprocdefinfo^.forwarddef:=AValue;
  5781. end;
  5782. procedure tprocdef.Sethasforward(AValue: boolean);
  5783. begin
  5784. if not assigned(implprocdefinfo) then
  5785. internalerror(2014010316);
  5786. implprocdefinfo^.hasforward:=AValue;
  5787. end;
  5788. function tprocdef.GetIsEmpty: boolean;
  5789. begin
  5790. result:=pio_empty in implprocoptions;
  5791. end;
  5792. procedure tprocdef.SetIsEmpty(AValue: boolean);
  5793. begin
  5794. if AValue then
  5795. include(implprocoptions,pio_empty)
  5796. else
  5797. exclude(implprocoptions,pio_empty);
  5798. end;
  5799. function tprocdef.GetHasInliningInfo: boolean;
  5800. begin
  5801. result:=pio_has_inlininginfo in implprocoptions;
  5802. end;
  5803. procedure tprocdef.SetHasInliningInfo(AValue: boolean);
  5804. begin
  5805. if AValue then
  5806. include(implprocoptions,pio_has_inlininginfo)
  5807. else
  5808. exclude(implprocoptions,pio_has_inlininginfo);
  5809. end;
  5810. procedure tprocdef.Setinterfacedef(AValue: boolean);
  5811. begin
  5812. if not assigned(implprocdefinfo) then
  5813. internalerror(2014010317);
  5814. implprocdefinfo^.interfacedef:=AValue;
  5815. end;
  5816. procedure tprocdef.Setprocstarttai(AValue: tai);
  5817. begin
  5818. if not assigned(implprocdefinfo) then
  5819. internalerror(2014010318);
  5820. implprocdefinfo^.procstarttai:=AValue;
  5821. end;
  5822. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  5823. begin
  5824. if not assigned(implprocdefinfo) then
  5825. internalerror(2014010319);
  5826. implprocdefinfo^.parentfpstruct:=AValue;
  5827. end;
  5828. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  5829. begin
  5830. if not assigned(implprocdefinfo) then
  5831. internalerror(2014010320);
  5832. implprocdefinfo^.parentfpstructptrtype:=AValue;
  5833. end;
  5834. constructor tprocdef.create(level:byte;doregister:boolean);
  5835. begin
  5836. inherited create(procdef,level,doregister);
  5837. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  5838. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  5839. {$ifdef symansistr}
  5840. _mangledname:='';
  5841. {$else symansistr}
  5842. _mangledname:=nil;
  5843. {$endif symansistr}
  5844. {$ifndef DISABLE_FAST_OVERLOAD_PATCH}
  5845. seenmarker := nil;
  5846. {$endif}
  5847. fileinfo:=current_filepos;
  5848. extnumber:=$ffff;
  5849. aliasnames:=TCmdStrList.create;
  5850. funcretsym:=nil;
  5851. funcretsymderef.reset;
  5852. procsymderef.reset;
  5853. forwarddef:=true;
  5854. interfacedef:=false;
  5855. hasforward:=false;
  5856. struct := nil;
  5857. structderef.reset;
  5858. import_dll:=nil;
  5859. import_name:=nil;
  5860. import_nr:=0;
  5861. inlininginfo:=nil;
  5862. deprecatedmsg:=nil;
  5863. genericdecltokenbuf:=nil;
  5864. if cs_opt_fastmath in current_settings.optimizerswitches then
  5865. include(implprocoptions, pio_fastmath);
  5866. end;
  5867. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  5868. var
  5869. i,aliasnamescount,sizeleft : longint;
  5870. level : byte;
  5871. buf : array[0..255] of byte;
  5872. begin
  5873. inherited ppuload(procdef,ppufile);
  5874. {$ifdef symansistr}
  5875. if po_has_mangledname in procoptions then
  5876. _mangledname:=ppufile.getansistring
  5877. else
  5878. _mangledname:='';
  5879. {$else symansistr}
  5880. if po_has_mangledname in procoptions then
  5881. _mangledname:=ppufile.getpshortstring
  5882. else
  5883. _mangledname:=nil;
  5884. {$endif symansistr}
  5885. extnumber:=ppufile.getword;
  5886. level:=ppufile.getbyte;
  5887. ppufile.getderef(structderef);
  5888. ppufile.getderef(procsymderef);
  5889. ppufile.getposinfo(fileinfo);
  5890. visibility:=tvisibility(ppufile.getbyte);
  5891. ppufile.getset(tppuset2(symoptions));
  5892. if sp_has_deprecated_msg in symoptions then
  5893. deprecatedmsg:=ppufile.getpshortstring
  5894. else
  5895. deprecatedmsg:=nil;
  5896. { import stuff }
  5897. if po_has_importdll in procoptions then
  5898. import_dll:=ppufile.getpshortstring
  5899. else
  5900. import_dll:=nil;
  5901. if po_has_importname in procoptions then
  5902. import_name:=ppufile.getpshortstring
  5903. else
  5904. import_name:=nil;
  5905. import_nr:=ppufile.getword;
  5906. if (po_msgint in procoptions) then
  5907. messageinf.i:=ppufile.getlongint;
  5908. if (po_msgstr in procoptions) then
  5909. messageinf.str:=ppufile.getpshortstring;
  5910. if (po_dispid in procoptions) then
  5911. dispid:=ppufile.getlongint;
  5912. { inline stuff }
  5913. ppufile.getset(tppuset1(implprocoptions));
  5914. if has_inlininginfo then
  5915. begin
  5916. ppufile.getderef(funcretsymderef);
  5917. new(inlininginfo);
  5918. ppufile.getset(tppuset4(inlininginfo^.flags));
  5919. end
  5920. else
  5921. begin
  5922. inlininginfo:=nil;
  5923. funcretsym:=nil;
  5924. end;
  5925. aliasnames:=TCmdStrList.create;
  5926. { count alias names }
  5927. aliasnamescount:=ppufile.getbyte;
  5928. for i:=1 to aliasnamescount do
  5929. aliasnames.insert(ppufile.getstring);
  5930. { load the token stream containing the declaration }
  5931. sizeleft:=ppufile.getlongint;
  5932. if sizeleft>0 then
  5933. begin
  5934. init_genericdecl;
  5935. while sizeleft>0 do
  5936. begin
  5937. if sizeleft>sizeof(buf) then
  5938. i:=sizeof(buf)
  5939. else
  5940. i:=sizeleft;
  5941. ppufile.getdata(buf,i);
  5942. genericdecltokenbuf.write(buf,i);
  5943. dec(sizeleft,i);
  5944. end;
  5945. end;
  5946. ppuload_platform(ppufile);
  5947. { load para symtable }
  5948. parast:=tparasymtable.create(self,level);
  5949. tparasymtable(parast).ppuload(ppufile);
  5950. { load local symtable }
  5951. if store_localst then
  5952. begin
  5953. localst:=tlocalsymtable.create(self,level);
  5954. tlocalsymtable(localst).ppuload(ppufile);
  5955. end
  5956. else
  5957. localst:=nil;
  5958. { inline stuff }
  5959. if has_inlininginfo then
  5960. inlininginfo^.code:=ppuloadnodetree(ppufile);
  5961. { default values for no persistent data }
  5962. if (cs_link_deffile in current_settings.globalswitches) and
  5963. (tf_need_export in target_info.flags) and
  5964. (po_exports in procoptions) then
  5965. deffile.AddExport(mangledname);
  5966. { Disable po_has_inlining until the derefimpl is done }
  5967. has_inlininginfo:=false;
  5968. end;
  5969. destructor tprocdef.destroy;
  5970. begin
  5971. aliasnames.free;
  5972. aliasnames:=nil;
  5973. if assigned(localst) and
  5974. (localst.symtabletype<>staticsymtable) then
  5975. begin
  5976. {$ifdef MEMDEBUG}
  5977. memproclocalst.start;
  5978. {$endif MEMDEBUG}
  5979. localst.free;
  5980. localst:=nil;
  5981. {$ifdef MEMDEBUG}
  5982. memproclocalst.start;
  5983. {$endif MEMDEBUG}
  5984. end;
  5985. if assigned(inlininginfo) then
  5986. begin
  5987. {$ifdef MEMDEBUG}
  5988. memprocnodetree.start;
  5989. {$endif MEMDEBUG}
  5990. tnode(inlininginfo^.code).free;
  5991. {$ifdef MEMDEBUG}
  5992. memprocnodetree.start;
  5993. {$endif MEMDEBUG}
  5994. dispose(inlininginfo);
  5995. inlininginfo:=nil;
  5996. end;
  5997. freeimplprocdefinfo;
  5998. genericdecltokenbuf.free;
  5999. genericdecltokenbuf:=nil;
  6000. stringdispose(import_dll);
  6001. stringdispose(import_name);
  6002. stringdispose(deprecatedmsg);
  6003. if (po_msgstr in procoptions) then
  6004. stringdispose(messageinf.str);
  6005. {$ifndef symansistr}
  6006. if assigned(_mangledname) then
  6007. begin
  6008. {$ifdef MEMDEBUG}
  6009. memmanglednames.start;
  6010. {$endif MEMDEBUG}
  6011. stringdispose(_mangledname);
  6012. {$ifdef MEMDEBUG}
  6013. memmanglednames.stop;
  6014. {$endif MEMDEBUG}
  6015. end;
  6016. {$endif symansistr}
  6017. inherited destroy;
  6018. end;
  6019. procedure tprocdef.freeimplprocdefinfo;
  6020. begin
  6021. if assigned(implprocdefinfo) then
  6022. begin
  6023. stringdispose(implprocdefinfo^.resultname);
  6024. TFPList.FreeAndNilDisposing(implprocdefinfo^.capturedsyms,typeinfo(tcapturedsyminfo));
  6025. freemem(implprocdefinfo);
  6026. implprocdefinfo:=nil;
  6027. end;
  6028. end;
  6029. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  6030. var
  6031. oldintfcrc : boolean;
  6032. aliasnamescount,i,sizeleft : longint;
  6033. item : TCmdStrListItem;
  6034. buf : array[0..255] of byte;
  6035. begin
  6036. { released procdef? }
  6037. if not assigned(parast) then
  6038. exit;
  6039. inherited ppuwrite(ppufile);
  6040. {$ifdef symansistr}
  6041. if po_has_mangledname in procoptions then
  6042. ppufile.putansistring(_mangledname);
  6043. {$else symansistr}
  6044. if po_has_mangledname in procoptions then
  6045. ppufile.putstring(_mangledname^);
  6046. {$endif symansistr}
  6047. ppufile.putword(extnumber);
  6048. ppufile.putbyte(parast.symtablelevel);
  6049. ppufile.putderef(structderef);
  6050. ppufile.putderef(procsymderef);
  6051. ppufile.putposinfo(fileinfo);
  6052. ppufile.putbyte(byte(visibility));
  6053. ppufile.putset(tppuset2(symoptions));
  6054. if sp_has_deprecated_msg in symoptions then
  6055. ppufile.putstring(deprecatedmsg^);
  6056. { import }
  6057. if po_has_importdll in procoptions then
  6058. ppufile.putstring(import_dll^);
  6059. if po_has_importname in procoptions then
  6060. ppufile.putstring(import_name^);
  6061. ppufile.putword(import_nr);
  6062. if (po_msgint in procoptions) then
  6063. ppufile.putlongint(messageinf.i);
  6064. if (po_msgstr in procoptions) then
  6065. ppufile.putstring(messageinf.str^);
  6066. if (po_dispid in procoptions) then
  6067. ppufile.putlongint(dispid);
  6068. { inline stuff }
  6069. oldintfcrc:=ppufile.do_crc;
  6070. ppufile.do_crc:=false;
  6071. ppufile.putset(tppuset1(implprocoptions));
  6072. if has_inlininginfo then
  6073. begin
  6074. ppufile.putderef(funcretsymderef);
  6075. ppufile.putset(tppuset4(inlininginfo^.flags));
  6076. end;
  6077. { count alias names }
  6078. aliasnamescount:=0;
  6079. item:=TCmdStrListItem(aliasnames.first);
  6080. while assigned(item) do
  6081. begin
  6082. inc(aliasnamescount);
  6083. item:=TCmdStrListItem(item.next);
  6084. end;
  6085. if aliasnamescount>255 then
  6086. internalerror(200711021);
  6087. ppufile.putbyte(aliasnamescount);
  6088. item:=TCmdStrListItem(aliasnames.first);
  6089. while assigned(item) do
  6090. begin
  6091. ppufile.putstring(item.str);
  6092. item:=TCmdStrListItem(item.next);
  6093. end;
  6094. ppufile.do_crc:=oldintfcrc;
  6095. { generic tokens for the declaration }
  6096. if assigned(genericdecltokenbuf) and (genericdecltokenbuf.size>0) then
  6097. begin
  6098. sizeleft:=genericdecltokenbuf.size;
  6099. genericdecltokenbuf.seek(0);
  6100. ppufile.putlongint(sizeleft);
  6101. while sizeleft>0 do
  6102. begin
  6103. if sizeleft>sizeof(buf) then
  6104. i:=sizeof(buf)
  6105. else
  6106. i:=sizeleft;
  6107. genericdecltokenbuf.read(buf,i);
  6108. ppufile.putdata(buf,i);
  6109. dec(sizeleft,i);
  6110. end;
  6111. end
  6112. else
  6113. ppufile.putlongint(0);
  6114. { write this entry }
  6115. writeentry(ppufile,ibprocdef);
  6116. { Save the para symtable, this is taken from the interface }
  6117. tparasymtable(parast).ppuwrite(ppufile);
  6118. { save localsymtable for inline procedures or when local
  6119. browser info is requested, this has no influence on the crc }
  6120. if store_localst and not ppufile.crc_only then
  6121. begin
  6122. oldintfcrc:=ppufile.do_crc;
  6123. ppufile.do_crc:=false;
  6124. tlocalsymtable(localst).ppuwrite(ppufile);
  6125. ppufile.do_crc:=oldintfcrc;
  6126. end;
  6127. { node tree for inlining }
  6128. oldintfcrc:=ppufile.do_crc;
  6129. ppufile.do_crc:=false;
  6130. if has_inlininginfo then
  6131. ppuwritenodetree(ppufile,inlininginfo^.code);
  6132. ppufile.do_crc:=oldintfcrc;
  6133. end;
  6134. function tprocdef.fullprocname(showhidden:boolean):string;
  6135. var
  6136. pno: tprocnameoptions;
  6137. begin
  6138. pno:=[];
  6139. if showhidden then
  6140. include(pno,pno_showhidden);
  6141. result:=customprocname(pno);
  6142. end;
  6143. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  6144. var
  6145. s, hs, rn : ansistring;
  6146. t : ttoken;
  6147. module : tmodule;
  6148. syssym : tsyssym;
  6149. begin
  6150. {$ifdef EXTDEBUG}
  6151. include(pno,pno_showhidden);
  6152. {$endif EXTDEBUG}
  6153. s:='';
  6154. rn:='';
  6155. if proctypeoption=potype_operator then
  6156. begin
  6157. for t:=NOTOKEN to last_overloaded do
  6158. if procsym.realname='$'+overloaded_names[t] then
  6159. begin
  6160. s:='operator ';
  6161. if (pno_ownername in pno) and
  6162. assigned(struct) then
  6163. s:=s+struct.RttiName+'.';
  6164. s:=s+arraytokeninfo[t].str;
  6165. if not (pno_noparams in pno) then
  6166. s:=s+typename_paras(pno);
  6167. break;
  6168. end;
  6169. end
  6170. else
  6171. begin
  6172. if (po_classmethod in procoptions) and
  6173. not(pno_noclassmarker in pno) then
  6174. s:='class ';
  6175. case proctypeoption of
  6176. potype_constructor,
  6177. potype_class_constructor:
  6178. s:=s+'constructor ';
  6179. potype_class_destructor,
  6180. potype_destructor:
  6181. s:=s+'destructor ';
  6182. else
  6183. if (pno_proctypeoption in pno) and not (po_anonymous in procoptions) then
  6184. begin
  6185. if assigned(returndef) and
  6186. not(is_void(returndef)) then
  6187. s:=s+'function '
  6188. else
  6189. s:=s+'procedure ';
  6190. end;
  6191. end;
  6192. if (pno_ownername in pno) and
  6193. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  6194. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  6195. if (po_compilerproc in procoptions) and (extnumber<>$ffff) then
  6196. begin
  6197. syssym:=tsyssym.find_by_number(extnumber);
  6198. if not assigned(syssym) then
  6199. internalerror(2016060305);
  6200. rn:=syssym.realname;
  6201. end
  6202. else if po_anonymous in procoptions then
  6203. begin
  6204. s:=s+'anonymous ';
  6205. if assigned(returndef) and
  6206. not(is_void(returndef)) then
  6207. s:=s+'function'
  6208. else
  6209. s:=s+'procedure';
  6210. end
  6211. else if pno_prettynames in pno then
  6212. rn:=procsym.prettyname
  6213. else
  6214. rn:=procsym.RealName;
  6215. if (pno_noleadingdollar in pno) and
  6216. (rn[1]='$') then
  6217. delete(rn,1,1);
  6218. s:=s+rn;
  6219. if not (pno_noparams in pno) then
  6220. s:=s+typename_paras(pno);
  6221. end;
  6222. if not(proctypeoption in [potype_constructor,potype_destructor,
  6223. potype_class_constructor,potype_class_destructor]) and
  6224. assigned(returndef) and
  6225. not(is_void(returndef)) then
  6226. begin
  6227. if assigned(returndef.typesym) then
  6228. begin
  6229. module:=find_module_from_symtable(returndef.typesym.owner);
  6230. if module <> current_module then
  6231. s:=s+':'+module.realmodulename^+'.'
  6232. else
  6233. s:=s+':';
  6234. if pno_prettynames in pno then
  6235. hs:=returndef.typesym.prettyname
  6236. else
  6237. hs:=returndef.typesym.realname;
  6238. if hs[1]<>'$' then
  6239. s:=s+returndef.OwnerHierarchyName+hs
  6240. else
  6241. s:=s+returndef.GetTypeName;
  6242. end
  6243. else
  6244. s:=s+':'+returndef.GetTypeName;
  6245. end;
  6246. if not (po_anonymous in procoptions) then
  6247. if assigned(owner) and (owner.symtabletype=localsymtable) then
  6248. s:=s+' is nested'
  6249. else if po_is_block in procoptions then
  6250. s:=s+' is block';
  6251. s:=s+';';
  6252. if po_far in procoptions then
  6253. s:=s+' far;';
  6254. { forced calling convention? }
  6255. if (po_hascallingconvention in procoptions) then
  6256. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  6257. if (po_staticmethod in procoptions) and
  6258. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  6259. s:=s+' Static;';
  6260. if pno_mangledname in pno then
  6261. s:=s+' -- mangled name: '+mangledname;
  6262. customprocname:=s;
  6263. end;
  6264. function tprocdef.is_methodpointer:boolean;
  6265. begin
  6266. { don't check assigned(_class), that's also the case for nested
  6267. procedures inside methods }
  6268. result:=(owner.symtabletype in [recordsymtable,ObjectSymtable]) and not no_self_node;
  6269. end;
  6270. function tprocdef.is_addressonly:boolean;
  6271. begin
  6272. result:=assigned(owner) and
  6273. not is_methodpointer and
  6274. (not(m_nested_procvars in current_settings.modeswitches) or
  6275. not is_nested_pd(self)) and
  6276. (
  6277. not (po_anonymous in procoptions) or
  6278. not assigned(capturedsyms) or
  6279. (capturedsyms.count=0)
  6280. );
  6281. end;
  6282. procedure tprocdef.make_external;
  6283. begin
  6284. include(procoptions,po_external);
  6285. forwarddef:=false;
  6286. end;
  6287. procedure tprocdef.init_genericdecl;
  6288. begin
  6289. if assigned(genericdecltokenbuf) then
  6290. internalerror(2015061901);
  6291. genericdecltokenbuf:=tdynamicarray.create(256);
  6292. end;
  6293. function tprocdef.get_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  6294. begin
  6295. result:=false;
  6296. if proctypeoption=potype_constructor then
  6297. begin
  6298. result:=true;
  6299. ressym:=tsym(parast.Find('self'));
  6300. resdef:=tabstractnormalvarsym(ressym).vardef;
  6301. { and TP-style constructors return a pointer to self }
  6302. if is_object(resdef) then
  6303. resdef:=cpointerdef.getreusable(resdef);
  6304. end
  6305. else if (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. else if not is_void(returndef) then
  6313. begin
  6314. result:=true;
  6315. ressym:=funcretsym;
  6316. resdef:=tabstractnormalvarsym(ressym).vardef;
  6317. end;
  6318. end;
  6319. function tprocdef.get_safecall_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  6320. begin
  6321. result:=false;
  6322. if (proctypeoption<>potype_constructor) and
  6323. (proccalloption=pocall_safecall) and
  6324. (tf_safecall_exceptions in target_info.flags) then
  6325. begin
  6326. result:=true;
  6327. ressym:=tsym(localst.Find('safecallresult'));
  6328. resdef:=tabstractnormalvarsym(ressym).vardef;
  6329. end
  6330. end;
  6331. procedure tprocdef.add_captured_sym(sym:tsym;def:tdef;const filepos:tfileposinfo);
  6332. var
  6333. i : longint;
  6334. capturedsym : pcapturedsyminfo;
  6335. begin
  6336. if not assigned(implprocdefinfo) then
  6337. internalerror(2021052601);
  6338. if not assigned(implprocdefinfo^.capturedsyms) then
  6339. implprocdefinfo^.capturedsyms:=tfplist.create;
  6340. for i:=0 to implprocdefinfo^.capturedsyms.count-1 do
  6341. begin
  6342. capturedsym:=pcapturedsyminfo(implprocdefinfo^.capturedsyms[i]);
  6343. if (capturedsym^.sym=sym) and (capturedsym^.def=def) then
  6344. exit;
  6345. end;
  6346. new(capturedsym);
  6347. capturedsym^.sym:=sym;
  6348. capturedsym^.def:=def;
  6349. capturedsym^.fileinfo:=filepos;
  6350. implprocdefinfo^.capturedsyms.add(capturedsym);
  6351. end;
  6352. function tprocdef.has_alias_name(const s: TSymStr): boolean;
  6353. var
  6354. item : TCmdStrListItem;
  6355. begin
  6356. result:=true;
  6357. if mangledname=s then
  6358. exit;
  6359. item:=TCmdStrListItem(aliasnames.first);
  6360. while assigned(item) do
  6361. begin
  6362. if item.str=s then
  6363. exit;
  6364. item:=TCmdStrListItem(item.next);
  6365. end;
  6366. result:=false;
  6367. end;
  6368. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  6369. begin
  6370. case t of
  6371. gs_local :
  6372. GetSymtable:=localst;
  6373. gs_para :
  6374. GetSymtable:=parast;
  6375. else
  6376. GetSymtable:=nil;
  6377. end;
  6378. end;
  6379. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  6380. var
  6381. j : longint;
  6382. begin
  6383. result:=inherited;
  6384. if newtyp=procvardef then
  6385. begin
  6386. { create new paralist }
  6387. tprocvardef(result).calcparas;
  6388. exit;
  6389. end;
  6390. { don't copy mangled name, can be different }
  6391. tprocdef(result).messageinf:=messageinf;
  6392. tprocdef(result).dispid:=dispid;
  6393. if po_msgstr in procoptions then
  6394. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  6395. tprocdef(result).symoptions:=symoptions;
  6396. if assigned(deprecatedmsg) then
  6397. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  6398. { will have to be associated with appropriate procsym }
  6399. tprocdef(result).procsym:=nil;
  6400. { don't create aliases for bare copies, nor copy the funcretsym as
  6401. the function result parameter will be inserted again if necessary
  6402. (e.g. if the calling convention is changed) }
  6403. if not(copytyp in [pc_bareproc,pc_normal_no_hidden]) then
  6404. begin
  6405. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  6406. if assigned(funcretsym) then
  6407. begin
  6408. if funcretsym.owner=parast then
  6409. begin
  6410. j:=parast.symlist.indexof(funcretsym);
  6411. if j<0 then
  6412. internalerror(2011040606);
  6413. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  6414. end
  6415. else if funcretsym.owner=localst then
  6416. begin
  6417. { nothing to do, will be inserted for the new procdef while
  6418. parsing its body (by pdecsub.insert_funcret_local) }
  6419. end
  6420. else
  6421. internalerror(2011040605);
  6422. end;
  6423. end;
  6424. { will have to be associated with a new struct }
  6425. tprocdef(result).struct:=nil;
  6426. if assigned(implprocdefinfo) then
  6427. begin
  6428. if assigned(resultname) then
  6429. tprocdef(result).resultname:=stringdup(resultname^);
  6430. tprocdef(result).synthetickind:=synthetickind;
  6431. end;
  6432. if assigned(import_dll) then
  6433. tprocdef(result).import_dll:=stringdup(import_dll^);
  6434. if assigned(import_name) then
  6435. tprocdef(result).import_name:=stringdup(import_name^);
  6436. tprocdef(result).import_nr:=import_nr;
  6437. tprocdef(result).extnumber:=$ffff;
  6438. tprocdef(result).visibility:=visibility;
  6439. { we need a separate implementation for the copied def }
  6440. tprocdef(result).forwarddef:=true;
  6441. tprocdef(result).interfacedef:=true;
  6442. { create new paralist }
  6443. tprocdef(result).calcparas;
  6444. end;
  6445. function tprocdef.getcopy: tstoreddef;
  6446. begin
  6447. result:=getcopyas(procdef,pc_normal,'',true);
  6448. end;
  6449. procedure tprocdef.buildderef;
  6450. begin
  6451. inherited buildderef;
  6452. structderef.build(struct);
  6453. { procsym that originaly defined this definition, should be in the
  6454. same symtable }
  6455. procsymderef.build(procsym);
  6456. end;
  6457. procedure tprocdef.buildderefimpl;
  6458. begin
  6459. inherited buildderefimpl;
  6460. { Localst is not available for main/unit init }
  6461. if store_localst and assigned(localst) then
  6462. begin
  6463. tlocalsymtable(localst).buildderef;
  6464. tlocalsymtable(localst).buildderefimpl;
  6465. end;
  6466. { inline tree }
  6467. if has_inlininginfo then
  6468. begin
  6469. funcretsymderef.build(funcretsym);
  6470. inlininginfo^.code.buildderefimpl;
  6471. end;
  6472. end;
  6473. procedure tprocdef.deref;
  6474. begin
  6475. inherited deref;
  6476. struct:=tabstractrecorddef(structderef.resolve);
  6477. { procsym that originaly defined this definition, should be in the
  6478. same symtable }
  6479. procsym:=tprocsym(procsymderef.resolve);
  6480. end;
  6481. procedure tprocdef.derefimpl;
  6482. begin
  6483. { Enable has_inlininginfo when the inlininginfo
  6484. structure is available. The has_inlininginfo was disabled
  6485. after the load, since the data was invalid }
  6486. if assigned(inlininginfo) then
  6487. has_inlininginfo:=true;
  6488. { Locals }
  6489. if store_localst and assigned(localst) then
  6490. begin
  6491. tlocalsymtable(localst).deref(false);
  6492. tlocalsymtable(localst).derefimpl(false);
  6493. end;
  6494. { Inline }
  6495. if has_inlininginfo then
  6496. begin
  6497. inlininginfo^.code.derefimpl;
  6498. { funcretsym, this is always located in the localst }
  6499. funcretsym:=tsym(funcretsymderef.resolve);
  6500. end
  6501. else
  6502. begin
  6503. { safety }
  6504. { Not safe! A unit may be reresolved after its interface has been
  6505. parsed but before its implementation has been parsed, and in that
  6506. case the funcretsym is still required!
  6507. funcretsym:=nil; }
  6508. end;
  6509. end;
  6510. function tprocdef.GetTypeName : string;
  6511. begin
  6512. GetTypeName := FullProcName(false);
  6513. end;
  6514. function tprocdef.mangledname : TSymStr;
  6515. begin
  6516. {$ifdef symansistr}
  6517. if _mangledname='' then
  6518. begin
  6519. result:=defaultmangledname;
  6520. _mangledname:=result;
  6521. end
  6522. else
  6523. result:=_mangledname;
  6524. {$else symansistr}
  6525. if not assigned(_mangledname) then
  6526. begin
  6527. result:=defaultmangledname;
  6528. _mangledname:=stringdup(mangledname);
  6529. end
  6530. else
  6531. result:=_mangledname^;
  6532. {$endif symansistr}
  6533. end;
  6534. function tprocdef.defaultmangledname: TSymStr;
  6535. var
  6536. n : TSymStr;
  6537. begin
  6538. n:=procsym.name;
  6539. { make sure that the mangled names of these overloadable methods types is
  6540. unique even if it's made lowercase (e.g. for section names) }
  6541. if proctypeoption in [potype_operator,potype_class_constructor,potype_class_destructor] then
  6542. n:='$'+n;
  6543. { we need to use the symtable where the procsym is inserted,
  6544. because that is visible to the world }
  6545. defaultmangledname:=make_mangledname('',procsym.owner,n);
  6546. defaultmangledname:=defaultmangledname+mangledprocparanames(Length(defaultmangledname))
  6547. end;
  6548. function tprocdef.cplusplusmangledname : TSymStr;
  6549. function getcppparaname(p : tdef) : TSymStr;
  6550. const
  6551. {$ifdef NAMEMANGLING_GCC2}
  6552. ordtype2str : array[tordtype] of string[2] = (
  6553. '',
  6554. 'Uc','Us','Ui','Us','',
  6555. 'Sc','s','i','x','',
  6556. 'b','b','b','b','b','b',
  6557. 'c','w','x');
  6558. {$else NAMEMANGLING_GCC2}
  6559. ordtype2str : array[tordtype] of string[1] = (
  6560. 'v',
  6561. 'h','t','j','y','',
  6562. 'a','s','i','x','',
  6563. 'b','b','b','b','b',
  6564. 'b','b','b','b',
  6565. 'c','w','x','C');
  6566. floattype2str : array[tfloattype] of string[1] = (
  6567. 'f','d','e','e',
  6568. 'd','d','g');
  6569. {$endif NAMEMANGLING_GCC2}
  6570. var
  6571. s : TSymStr;
  6572. begin
  6573. case p.typ of
  6574. orddef:
  6575. begin
  6576. s:=ordtype2str[torddef(p).ordtype];
  6577. if s='C' then
  6578. s:=ordtype2str[range_to_basetype(torddef(p).low,torddef(p).high)];
  6579. end;
  6580. pointerdef:
  6581. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  6582. {$ifndef NAMEMANGLING_GCC2}
  6583. floatdef:
  6584. s:=floattype2str[tfloatdef(p).floattype];
  6585. {$endif NAMEMANGLING_GCC2}
  6586. else
  6587. internalerror(2103001);
  6588. end;
  6589. getcppparaname:=s;
  6590. end;
  6591. var
  6592. s,s2 : TSymStr;
  6593. hp : TParavarsym;
  6594. i : integer;
  6595. begin
  6596. {$ifdef NAMEMANGLING_GCC2}
  6597. { outdated gcc 2.x name mangling scheme }
  6598. s := procsym.realname;
  6599. if procsym.owner.symtabletype=ObjectSymtable then
  6600. begin
  6601. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  6602. case proctypeoption of
  6603. potype_destructor:
  6604. s:='_$_'+tostr(length(s2))+s2;
  6605. potype_constructor:
  6606. s:='___'+tostr(length(s2))+s2;
  6607. else
  6608. s:='_'+s+'__'+tostr(length(s2))+s2;
  6609. end;
  6610. end
  6611. else s:=s+'__';
  6612. s:=s+'F';
  6613. { concat modifiers }
  6614. { !!!!! }
  6615. { now we handle the parameters }
  6616. if maxparacount>0 then
  6617. begin
  6618. for i:=0 to paras.count-1 do
  6619. begin
  6620. hp:=tparavarsym(paras[i]);
  6621. { no hidden parameters form part of a C++ mangled name:
  6622. a) self is not included
  6623. b) there are no "high" or other hidden parameters
  6624. }
  6625. if vo_is_hidden_para in hp.varoptions then
  6626. continue;
  6627. s2:=getcppparaname(hp.vardef);
  6628. if hp.varspez in [vs_var,vs_out] then
  6629. s2:='R'+s2;
  6630. s:=s+s2;
  6631. end;
  6632. end
  6633. else
  6634. s:=s+'v';
  6635. cplusplusmangledname:=s;
  6636. {$else NAMEMANGLING_GCC2}
  6637. { gcc 3.x and 4.x name mangling scheme }
  6638. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  6639. if procsym.owner.symtabletype=ObjectSymtable then
  6640. begin
  6641. s:='_ZN';
  6642. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  6643. s:=s+tostr(length(s2))+s2;
  6644. case proctypeoption of
  6645. potype_constructor:
  6646. s:=s+'C1';
  6647. potype_destructor:
  6648. s:=s+'D1';
  6649. else
  6650. s:=s+tostr(length(procsym.realname))+procsym.realname;
  6651. end;
  6652. s:=s+'E';
  6653. end
  6654. else
  6655. s:=procsym.realname;
  6656. { now we handle the parameters }
  6657. if maxparacount>0 then
  6658. begin
  6659. for i:=0 to paras.count-1 do
  6660. begin
  6661. hp:=tparavarsym(paras[i]);
  6662. { no hidden parameters form part of a C++ mangled name:
  6663. a) self is not included
  6664. b) there are no "high" or other hidden parameters
  6665. }
  6666. if vo_is_hidden_para in hp.varoptions then
  6667. continue;
  6668. s2:=getcppparaname(hp.vardef);
  6669. if hp.varspez in [vs_var,vs_out] then
  6670. s2:='R'+s2;
  6671. s:=s+s2;
  6672. end;
  6673. end
  6674. else
  6675. s:=s+'v';
  6676. cplusplusmangledname:=s;
  6677. {$endif NAMEMANGLING_GCC2}
  6678. end;
  6679. function tprocdef.objcmangledname : TSymStr;
  6680. var
  6681. manglednamelen: longint;
  6682. iscatmethod : boolean;
  6683. begin
  6684. if not (po_msgstr in procoptions) then
  6685. internalerror(2009030901);
  6686. { we may very well need longer strings to handle these... }
  6687. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  6688. length('+"[ ]"')+length(messageinf.str^);
  6689. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  6690. if (iscatmethod) then
  6691. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  6692. if manglednamelen>255 then
  6693. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  6694. if not(po_classmethod in procoptions) then
  6695. result:='"-['
  6696. else
  6697. result:='"+[';
  6698. { quotes are necessary because the +/- otherwise confuse the assembler
  6699. into expecting a number
  6700. }
  6701. if iscatmethod then
  6702. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  6703. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  6704. if iscatmethod then
  6705. result:=result+')';
  6706. result:=result+' '+messageinf.str^+']"';
  6707. end;
  6708. procedure tprocdef.setmangledname(const s : TSymStr);
  6709. begin
  6710. { This is not allowed anymore, the forward declaration
  6711. already needs to create the correct mangledname, no changes
  6712. afterwards are allowed (PFV) }
  6713. { Exception: interface definitions in mode macpas, since in that }
  6714. { case no reference to the old name can exist yet (JM) }
  6715. {$ifdef symansistr}
  6716. if _mangledname<>'' then
  6717. if ((m_mac in current_settings.modeswitches) and
  6718. (interfacedef)) then
  6719. _mangledname:=''
  6720. else
  6721. internalerror(200411171);
  6722. {$else symansistr}
  6723. if assigned(_mangledname) then
  6724. if ((m_mac in current_settings.modeswitches) and
  6725. (interfacedef)) then
  6726. stringdispose(_mangledname)
  6727. else
  6728. internalerror(200411171);
  6729. {$endif symansistr}
  6730. {$ifdef jvm}
  6731. { this routine can be called for compilerproces. can't set mangled
  6732. name since it must be calculated, but it uses import_name when set
  6733. -> set that one }
  6734. import_name:=stringdup(s);
  6735. include(procoptions,po_has_importname);
  6736. include(procoptions,po_has_mangledname);
  6737. {$else}
  6738. {$ifdef symansistr}
  6739. _mangledname:=s;
  6740. {$else symansistr}
  6741. _mangledname:=stringdup(s);
  6742. {$endif symansistr}
  6743. {$endif jvm}
  6744. include(procoptions,po_has_mangledname);
  6745. end;
  6746. function tprocdef.needsglobalasmsym: boolean;
  6747. begin
  6748. result:=
  6749. (cs_profile in current_settings.moduleswitches) or
  6750. { smart linking using a library requires to promote
  6751. all non-nested procedures to AB_GLOBAL
  6752. otherwise you get undefined symbol error at linking
  6753. for msdos target with -CX option for instance }
  6754. (create_smartlink_library and not is_nested_pd(self)) or
  6755. (po_global in procoptions);
  6756. end;
  6757. procedure tprocdef.setcompilerprocname;
  6758. begin
  6759. procsym.realname:='$'+lower(procsym.name);
  6760. end;
  6761. {***************************************************************************
  6762. TPROCVARDEF
  6763. ***************************************************************************}
  6764. constructor tprocvardef.create(level:byte;doregister:boolean);
  6765. begin
  6766. inherited create(procvardef,level,doregister);
  6767. end;
  6768. class function tprocvardef.getreusableprocaddr(def: tabstractprocdef; copytyp: tcacheableproccopytyp): tprocvardef;
  6769. var
  6770. res: PHashSetItem;
  6771. oldsymtablestack: tsymtablestack;
  6772. key: packed record
  6773. def: tabstractprocdef;
  6774. copytyp: tcacheableproccopytyp;
  6775. end;
  6776. begin
  6777. if not assigned(current_module) then
  6778. internalerror(2011081302);
  6779. key.def:=def;
  6780. key.copytyp:=copytyp;
  6781. res:=current_module.procaddrdefs.FindOrAdd(@key,sizeof(key));
  6782. if not assigned(res^.Data) then
  6783. begin
  6784. { since these pointerdefs can be reused anywhere in the current
  6785. unit, add them to the global/staticsymtable (or local symtable
  6786. if they're a local def, because otherwise they'll be saved
  6787. to the ppu referencing a local symtable entry that doesn't
  6788. exist in the ppu) }
  6789. oldsymtablestack:=symtablestack;
  6790. { do not simply push/pop current_module.localsymtable, because
  6791. that can have side-effects (e.g., it removes helpers) }
  6792. symtablestack:=nil;
  6793. result:=tprocvardef(def.getcopyas(procvardef,copytyp,'',true));
  6794. setup_reusable_def(def,result,res,oldsymtablestack);
  6795. { res^.Data may still be nil -> don't overwrite result }
  6796. exit;
  6797. end;
  6798. result:=tprocvardef(res^.Data);
  6799. end;
  6800. class function tprocvardef.getreusableprocaddr_no_free(def: tabstractprocdef): tprocvardef;
  6801. begin
  6802. result:=getreusableprocaddr(def,pc_address_only);
  6803. if not result.is_registered then
  6804. include(result.defoptions,df_not_registered_no_free);
  6805. end;
  6806. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  6807. begin
  6808. inherited ppuload(procvardef,ppufile);
  6809. { load para symtable }
  6810. parast:=tparasymtable.create(self,ppufile.getbyte);
  6811. ppuload_platform(ppufile);
  6812. tparasymtable(parast).ppuload(ppufile);
  6813. end;
  6814. function tprocvardef.getcopy : tstoreddef;
  6815. var
  6816. i : tcallercallee;
  6817. j : longint;
  6818. begin
  6819. result:=cprocvardef.create(parast.symtablelevel,true);
  6820. tprocvardef(result).returndef:=returndef;
  6821. tprocvardef(result).returndefderef:=returndefderef;
  6822. tprocvardef(result).parast:=parast.getcopy;
  6823. tprocvardef(result).savesize:=savesize;
  6824. { create paralist copy }
  6825. calcparas;
  6826. tprocvardef(result).paras:=tparalist.create(false);
  6827. tprocvardef(result).paras.count:=paras.count;
  6828. for j:=0 to paras.count-1 do
  6829. tprocvardef(result).paras[j]:=paras[j];
  6830. tprocvardef(result).proctypeoption:=proctypeoption;
  6831. tprocvardef(result).proccalloption:=proccalloption;
  6832. tprocvardef(result).procoptions:=procoptions;
  6833. tprocvardef(result).callerargareasize:=callerargareasize;
  6834. tprocvardef(result).calleeargareasize:=calleeargareasize;
  6835. tprocvardef(result).maxparacount:=maxparacount;
  6836. tprocvardef(result).minparacount:=minparacount;
  6837. for i:=low(funcretloc) to high(funcretloc) do
  6838. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  6839. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  6840. {$ifdef m68k}
  6841. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  6842. {$endif}
  6843. end;
  6844. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  6845. begin
  6846. inherited ppuwrite(ppufile);
  6847. { Save the para symtable level (necessary to distinguish nested
  6848. procvars) }
  6849. ppufile.putbyte(parast.symtablelevel);
  6850. { Write this entry }
  6851. writeentry(ppufile,ibprocvardef);
  6852. { Save the para symtable, this is taken from the interface }
  6853. tparasymtable(parast).ppuwrite(ppufile);
  6854. end;
  6855. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  6856. begin
  6857. case t of
  6858. gs_para :
  6859. GetSymtable:=parast;
  6860. else
  6861. GetSymtable:=nil;
  6862. end;
  6863. end;
  6864. function tprocvardef.size : asizeint;
  6865. begin
  6866. { we return false for is_addressonly for a block (because it's not a
  6867. simple pointer to a function), but they are handled as implicit
  6868. pointers to a datastructure that contains everything ->
  6869. voidpointertype.size instead of voidcodepointertype.size }
  6870. if po_is_block in procoptions then
  6871. size:=voidpointertype.size
  6872. else if not is_addressonly then
  6873. begin
  6874. if is_nested_pd(self) then
  6875. size:=voidcodepointertype.size+parentfpvoidpointertype.size
  6876. else
  6877. size:=voidcodepointertype.size+voidpointertype.size;
  6878. end
  6879. else
  6880. size:=voidcodepointertype.size;
  6881. end;
  6882. function tprocvardef.is_methodpointer:boolean;
  6883. begin
  6884. result:=(po_methodpointer in procoptions);
  6885. end;
  6886. function tprocvardef.is_addressonly:boolean;
  6887. begin
  6888. result:=((not(po_methodpointer in procoptions) or (po_staticmethod in procoptions)) and
  6889. not(po_is_block in procoptions) and
  6890. not is_nested_pd(self)) or
  6891. (po_addressonly in procoptions);
  6892. end;
  6893. function tprocvardef.getmangledparaname:TSymStr;
  6894. begin
  6895. if not(po_methodpointer in procoptions) then
  6896. if not is_nested_pd(self) then
  6897. result:='procvar'
  6898. else
  6899. { we need the manglednames here, because nestedprocvars can be anonymous, e.g.
  6900. having not a type name or not an unique one, see webtbs/tw27515.pp
  6901. Further, use $_ ... _$ delimiters to avoid ambiguous names, see webtbs/tw27515.pp }
  6902. result:='$_nestedprovar'+mangledprocparanames(0)+'_$'
  6903. else
  6904. result:='procvarofobj'
  6905. end;
  6906. function tprocvardef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  6907. begin
  6908. result:=inherited;
  6909. tabstractprocdef(result).calcparas;
  6910. end;
  6911. function tprocvardef.is_publishable : tpublishproperty;
  6912. begin
  6913. if po_methodpointer in procoptions then
  6914. is_publishable:=pp_publish
  6915. else
  6916. is_publishable:=pp_error;
  6917. end;
  6918. function tprocvardef.GetTypeName : string;
  6919. var
  6920. s: string;
  6921. pno : tprocnameoptions;
  6922. begin
  6923. {$ifdef EXTDEBUG}
  6924. pno:=[pno_showhidden];
  6925. {$else EXTDEBUG}
  6926. pno:=[];
  6927. {$endif EXTDEBUG}
  6928. s:='<';
  6929. if po_is_block in procoptions then
  6930. s := s+'reference to'
  6931. else if po_classmethod in procoptions then
  6932. s := s+'class method type of'
  6933. else
  6934. if po_addressonly in procoptions then
  6935. s := s+'address of'
  6936. else
  6937. s := s+'procedure variable type of';
  6938. if assigned(returndef) and
  6939. (returndef<>voidtype) then
  6940. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  6941. else
  6942. s:=s+' procedure'+typename_paras(pno);
  6943. if po_methodpointer in procoptions then
  6944. s := s+' of object';
  6945. if is_nested_pd(self) then
  6946. s := s+' is nested';
  6947. if po_far in procoptions then
  6948. s := s+';far';
  6949. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  6950. end;
  6951. {***************************************************************************
  6952. TOBJECTDEF
  6953. ***************************************************************************}
  6954. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef;doregister:boolean);
  6955. begin
  6956. inherited create(n,objectdef,doregister);
  6957. fcurrent_dispid:=0;
  6958. objecttype:=ot;
  6959. childof:=nil;
  6960. childofderef.reset;
  6961. vmt_fieldderef.reset;
  6962. hiddenclassdefref.reset;
  6963. extendeddefderef.reset;
  6964. cloneddefderef.reset;
  6965. if objecttype=odt_helper then
  6966. owner.includeoption(sto_has_helper);
  6967. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords,
  6968. current_settings.alignment.recordalignmin);
  6969. { create space for vmt !! }
  6970. vmtentries:=TFPList.Create;
  6971. set_parent(c);
  6972. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  6973. prepareguid;
  6974. { setup implemented interfaces }
  6975. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
  6976. ImplementedInterfaces:=TFPObjectList.Create(true)
  6977. else
  6978. ImplementedInterfaces:=nil;
  6979. writing_class_record_dbginfo:=false;
  6980. end;
  6981. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  6982. var
  6983. i,
  6984. implintfcount : longint;
  6985. d, getterd : tderef;
  6986. ImplIntf : TImplementedInterface;
  6987. vmtentry : pvmtentry;
  6988. begin
  6989. inherited ppuload(objectdef,ppufile);
  6990. objecttype:=tobjecttyp(ppufile.getbyte);
  6991. helpertype:=thelpertype(ppufile.getbyte);
  6992. objextname:=ppufile.getpshortstring;
  6993. { only used for external Objective-C classes/protocols }
  6994. if (objextname^='') then
  6995. stringdispose(objextname);
  6996. symtable:=tObjectSymtable.create(self,objrealname^,0,0);
  6997. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  6998. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  6999. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  7000. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  7001. tObjectSymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  7002. ppufile.getderef(vmt_fieldderef);
  7003. ppufile.getderef(childofderef);
  7004. { load guid }
  7005. iidstr:=nil;
  7006. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  7007. begin
  7008. new(iidguid);
  7009. ppufile.getguid(iidguid^);
  7010. iidstr:=ppufile.getpshortstring;
  7011. end;
  7012. abstractcnt:=ppufile.getlongint;
  7013. if objecttype=odt_helper then
  7014. ppufile.getderef(extendeddefderef);
  7015. vmtentries:=TFPList.Create;
  7016. vmtentries.count:=ppufile.getlongint;
  7017. for i:=0 to vmtentries.count-1 do
  7018. begin
  7019. ppufile.getderef(d);
  7020. new(vmtentry);
  7021. vmtentry^.procdef:=nil;
  7022. vmtentry^.procdefderef:=d;
  7023. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  7024. vmtentries[i]:=vmtentry;
  7025. end;
  7026. { load implemented interfaces }
  7027. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
  7028. begin
  7029. ImplementedInterfaces:=TFPObjectList.Create(true);
  7030. implintfcount:=ppufile.getlongint;
  7031. for i:=0 to implintfcount-1 do
  7032. begin
  7033. ppufile.getderef(d);
  7034. ppufile.getderef(getterd);
  7035. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  7036. ImplIntf.IOffset:=ppufile.getlongint;
  7037. byte(ImplIntf.IType):=ppufile.getbyte;
  7038. ImplementedInterfaces.Add(ImplIntf);
  7039. end;
  7040. end
  7041. else
  7042. ImplementedInterfaces:=nil;
  7043. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7044. ppufile.getderef(hiddenclassdefref);
  7045. if df_copied_def in defoptions then
  7046. begin
  7047. ppufile.getderef(cloneddefderef);
  7048. ppuload_platform(ppufile);
  7049. end
  7050. else
  7051. begin
  7052. ppuload_platform(ppufile);
  7053. tObjectSymtable(symtable).ppuload(ppufile);
  7054. end;
  7055. { handles the predefined class tobject }
  7056. { the last TOBJECT which is loaded gets }
  7057. { it ! }
  7058. { but do this only from a unit that's }
  7059. { marked as system unit to avoid some }
  7060. { equally named user's type to override }
  7061. { the internal types! }
  7062. if mf_system_unit in current_module.moduleflags then
  7063. begin
  7064. if (childof=nil) and
  7065. (objecttype in [odt_class,odt_javaclass]) and
  7066. (objname^='TOBJECT') then
  7067. class_tobject:=self;
  7068. if (childof=nil) and
  7069. (objecttype=odt_interfacecom) then
  7070. if (objname^='IUNKNOWN') then
  7071. interface_iunknown:=self
  7072. else
  7073. if (objname^='IDISPATCH') then
  7074. interface_idispatch:=self;
  7075. if (objecttype=odt_javaclass) and
  7076. not(oo_is_formal in objectoptions) then
  7077. begin
  7078. if (objname^='JLOBJECT') then
  7079. java_jlobject:=self
  7080. else if (objname^='JLTHROWABLE') then
  7081. java_jlthrowable:=self
  7082. else if (objname^='FPCBASERECORDTYPE') then
  7083. java_fpcbaserecordtype:=self
  7084. else if (objname^='JLSTRING') then
  7085. java_jlstring:=self
  7086. else if (objname^='ANSISTRINGCLASS') then
  7087. java_ansistring:=self
  7088. else if (objname^='SHORTSTRINGCLASS') then
  7089. java_shortstring:=self
  7090. else if (objname^='JLENUM') then
  7091. java_jlenum:=self
  7092. else if (objname^='JUENUMSET') then
  7093. java_juenumset:=self
  7094. else if (objname^='FPCBITSET') then
  7095. java_jubitset:=self
  7096. else if (objname^='FPCBASEPROCVARTYPE') then
  7097. java_procvarbase:=self;
  7098. end;
  7099. end;
  7100. if (childof=nil) and
  7101. (objecttype=odt_objcclass) and
  7102. (objname^='PROTOCOL') then
  7103. objc_protocoltype:=self;
  7104. writing_class_record_dbginfo:=false;
  7105. end;
  7106. destructor tobjectdef.destroy;
  7107. begin
  7108. if assigned(symtable) then
  7109. begin
  7110. symtable.free;
  7111. symtable:=nil;
  7112. end;
  7113. stringdispose(objextname);
  7114. stringdispose(iidstr);
  7115. if assigned(ImplementedInterfaces) then
  7116. begin
  7117. ImplementedInterfaces.free;
  7118. ImplementedInterfaces:=nil;
  7119. end;
  7120. if assigned(iidguid) then
  7121. begin
  7122. dispose(iidguid);
  7123. iidguid:=nil;
  7124. end;
  7125. TFPList.FreeAndNilDisposing(vmtentries,TypeInfo(tvmtentry));
  7126. if assigned(vmcallstaticinfo) then
  7127. begin
  7128. freemem(vmcallstaticinfo);
  7129. vmcallstaticinfo:=nil;
  7130. end;
  7131. inherited destroy;
  7132. end;
  7133. function tobjectdef.getcopy : tstoreddef;
  7134. var
  7135. i : longint;
  7136. begin
  7137. result:=cobjectdef.create(objecttype,objrealname^,childof,true);
  7138. { the constructor allocates a symtable which we release to avoid memory leaks }
  7139. tobjectdef(result).symtable.free;
  7140. tobjectdef(result).symtable:=symtable.getcopy;
  7141. if assigned(objextname) then
  7142. tobjectdef(result).objextname:=stringdup(objextname^);
  7143. if assigned(import_lib) then
  7144. tobjectdef(result).import_lib:=stringdup(import_lib^);
  7145. tobjectdef(result).objectoptions:=objectoptions;
  7146. include(tobjectdef(result).defoptions,df_copied_def);
  7147. tobjectdef(result).extendeddef:=extendeddef;
  7148. if assigned(tcinitcode) then
  7149. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  7150. tobjectdef(result).vmt_field:=vmt_field;
  7151. if assigned(iidguid) then
  7152. begin
  7153. new(tobjectdef(result).iidguid);
  7154. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  7155. end;
  7156. if assigned(iidstr) then
  7157. tobjectdef(result).iidstr:=stringdup(iidstr^);
  7158. tobjectdef(result).abstractcnt:=abstractcnt;
  7159. if assigned(ImplementedInterfaces) then
  7160. begin
  7161. tobjectdef(result).ImplementedInterfaces.capacity:=tobjectdef(result).ImplementedInterfaces.count+ImplementedInterfaces.count;
  7162. for i:=0 to ImplementedInterfaces.count-1 do
  7163. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  7164. end;
  7165. tobjectdef(result).copyvmtentries(self);
  7166. end;
  7167. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  7168. var
  7169. i : longint;
  7170. vmtentry : pvmtentry;
  7171. ImplIntf : TImplementedInterface;
  7172. old_do_indirect_crc: boolean;
  7173. begin
  7174. { if class1 in unit A changes, and class2 in unit B inherits from it
  7175. (so unit B uses unit A), then unit B with class2 will be recompiled.
  7176. However, if there is also a class3 in unit C that only depends on
  7177. unit B, then unit C will not be recompiled because nothing changed
  7178. to the interface of unit B. Nevertheless, unit C can indirectly
  7179. depend on unit A via derefs, and these must be updated -> the
  7180. indirect crc keeps track of such changes. }
  7181. old_do_indirect_crc:=ppufile.do_indirect_crc;
  7182. ppufile.do_indirect_crc:=true;
  7183. inherited ppuwrite(ppufile);
  7184. ppufile.putbyte(byte(objecttype));
  7185. ppufile.putbyte(byte(helpertype));
  7186. if assigned(objextname) then
  7187. ppufile.putstring(objextname^)
  7188. else
  7189. ppufile.putstring('');
  7190. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  7191. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  7192. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  7193. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  7194. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignmin));
  7195. ppufile.putderef(vmt_fieldderef);
  7196. ppufile.putderef(childofderef);
  7197. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  7198. begin
  7199. ppufile.putguid(iidguid^);
  7200. ppufile.putstring(iidstr^);
  7201. end;
  7202. ppufile.putlongint(abstractcnt);
  7203. if objecttype=odt_helper then
  7204. ppufile.putderef(extendeddefderef);
  7205. ppufile.putlongint(vmtentries.count);
  7206. for i:=0 to vmtentries.count-1 do
  7207. begin
  7208. vmtentry:=pvmtentry(vmtentries[i]);
  7209. ppufile.putderef(vmtentry^.procdefderef);
  7210. ppufile.putbyte(byte(vmtentry^.visibility));
  7211. end;
  7212. if assigned(ImplementedInterfaces) then
  7213. begin
  7214. ppufile.putlongint(ImplementedInterfaces.Count);
  7215. for i:=0 to ImplementedInterfaces.Count-1 do
  7216. begin
  7217. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  7218. ppufile.putderef(ImplIntf.intfdefderef);
  7219. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  7220. ppufile.putlongint(ImplIntf.Ioffset);
  7221. ppufile.putbyte(byte(ImplIntf.IType));
  7222. end;
  7223. end;
  7224. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7225. ppufile.putderef(hiddenclassdefref);
  7226. if df_copied_def in defoptions then
  7227. ppufile.putderef(cloneddefderef);
  7228. writeentry(ppufile,ibobjectdef);
  7229. if not(df_copied_def in defoptions) then
  7230. tObjectSymtable(symtable).ppuwrite(ppufile);
  7231. ppufile.do_indirect_crc:=old_do_indirect_crc;
  7232. end;
  7233. function tobjectdef.GetTypeName:string;
  7234. begin
  7235. { in this case we will go in endless recursion, because then }
  7236. { there is no tsym associated yet with the def. It can occur }
  7237. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  7238. { instead of the actual type name }
  7239. if not assigned(typesym) then
  7240. result:='<Currently Parsed Class>'
  7241. else
  7242. result:=typesymbolprettyname;
  7243. end;
  7244. procedure tobjectdef.buildderef;
  7245. var
  7246. i : longint;
  7247. vmtentry : pvmtentry;
  7248. begin
  7249. inherited buildderef;
  7250. vmt_fieldderef.build(vmt_field);
  7251. childofderef.build(childof);
  7252. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7253. hiddenclassdefref.build(hiddenclassdef);
  7254. if df_copied_def in defoptions then
  7255. cloneddefderef.build(symtable.defowner)
  7256. else
  7257. tstoredsymtable(symtable).buildderef;
  7258. if objecttype=odt_helper then
  7259. extendeddefderef.build(extendeddef);
  7260. for i:=0 to vmtentries.count-1 do
  7261. begin
  7262. vmtentry:=pvmtentry(vmtentries[i]);
  7263. vmtentry^.procdefderef.build(vmtentry^.procdef);
  7264. end;
  7265. if assigned(ImplementedInterfaces) then
  7266. begin
  7267. for i:=0 to ImplementedInterfaces.count-1 do
  7268. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  7269. end;
  7270. end;
  7271. procedure tobjectdef.deref;
  7272. var
  7273. i : longint;
  7274. vmtentry : pvmtentry;
  7275. begin
  7276. inherited deref;
  7277. vmt_field:=tsym(vmt_fieldderef.resolve);
  7278. childof:=tobjectdef(childofderef.resolve);
  7279. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7280. hiddenclassdef:=tobjectdef(hiddenclassdefref.resolve);
  7281. if df_copied_def in defoptions then
  7282. begin
  7283. cloneddef:=tobjectdef(cloneddefderef.resolve);
  7284. symtable:=cloneddef.symtable.getcopy;
  7285. end
  7286. else
  7287. tstoredsymtable(symtable).deref(false);
  7288. if objecttype=odt_helper then
  7289. extendeddef:=tdef(extendeddefderef.resolve);
  7290. for i:=0 to vmtentries.count-1 do
  7291. begin
  7292. vmtentry:=pvmtentry(vmtentries[i]);
  7293. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  7294. end;
  7295. if assigned(ImplementedInterfaces) then
  7296. begin
  7297. for i:=0 to ImplementedInterfaces.count-1 do
  7298. TImplementedInterface(ImplementedInterfaces[i]).deref;
  7299. end;
  7300. end;
  7301. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  7302. var
  7303. pd: tprocdef absolute def;
  7304. st: tsymtable;
  7305. psym: tsym;
  7306. nname: TIDString;
  7307. begin
  7308. if (tdef(def).typ<>procdef) then
  7309. exit;
  7310. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  7311. owner = symtable in which objcclassdef is defined
  7312. }
  7313. st:=pd.owner.defowner.owner;
  7314. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  7315. { check for an existing procsym with our special name }
  7316. psym:=tsym(st.find(nname));
  7317. if not assigned(psym) then
  7318. begin
  7319. psym:=cprocsym.create(nname);
  7320. { avoid warning about this symbol being unused }
  7321. psym.IncRefCount;
  7322. { don't check for duplicates:
  7323. a) we checked above
  7324. b) in case we are in the implementation section of a unit, this
  7325. will also check for this symbol in the interface section
  7326. (since you normally cannot have symbols with the same name
  7327. both interface and implementation), and it's possible to
  7328. have class helpers for the same class in the interface and
  7329. in the implementation, and they cannot be merged since only
  7330. the once in the interface must be saved to the ppu/visible
  7331. from other units }
  7332. st.insertsym(psym,false);
  7333. end
  7334. else if (psym.typ<>procsym) then
  7335. internalerror(2009111501);
  7336. { add ourselves to this special procsym }
  7337. tprocsym(psym).procdeflist.add(def);
  7338. end;
  7339. procedure tobjectdef.derefimpl;
  7340. begin
  7341. inherited derefimpl;
  7342. { the procdefs are not owned by the class helper procsyms, so they
  7343. are not stored/restored either -> re-add them here }
  7344. if (objecttype in [odt_objcclass,odt_objcprotocol]) or
  7345. (oo_is_classhelper in objectoptions) then
  7346. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  7347. end;
  7348. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  7349. var
  7350. i : longint;
  7351. vmtentry : pvmtentry;
  7352. begin
  7353. if vmtentries.count<>0 then
  7354. internalerror(2019081401);
  7355. vmtentries.count:=objdef.vmtentries.count;
  7356. for i:=0 to objdef.vmtentries.count-1 do
  7357. begin
  7358. new(vmtentry);
  7359. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  7360. vmtentries[i]:=vmtentry;
  7361. end;
  7362. end;
  7363. function tobjectdef.getparentdef:tdef;
  7364. begin
  7365. { TODO: Remove getparentdef hack}
  7366. { With 2 forward declared classes with the child class before the
  7367. parent class the child class is written earlier to the ppu. Leaving it
  7368. possible to have a reference to the parent class for property overriding,
  7369. but the parent class still has the childof not resolved yet (PFV) }
  7370. if childof=nil then
  7371. childof:=tobjectdef(childofderef.resolve);
  7372. result:=childof;
  7373. end;
  7374. procedure tobjectdef.prepareguid;
  7375. begin
  7376. { set up guid }
  7377. if not assigned(iidguid) then
  7378. begin
  7379. new(iidguid);
  7380. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  7381. end;
  7382. { setup iidstring }
  7383. if not assigned(iidstr) then
  7384. iidstr:=stringdup(''); { default is empty string }
  7385. end;
  7386. procedure tobjectdef.set_parent( c : tobjectdef);
  7387. begin
  7388. if assigned(childof) then
  7389. exit;
  7390. childof:=c;
  7391. if not assigned(c) then
  7392. exit;
  7393. { inherit options and status }
  7394. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  7395. { check if parent is a generic parameter }
  7396. if sp_generic_para in c.typesym.symoptions then
  7397. objectoptions:=objectoptions+[oo_inherits_not_specialized];
  7398. { initially has the same number of abstract methods as the parent }
  7399. abstractcnt:=c.abstractcnt;
  7400. { add the data of the anchestor class/object }
  7401. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  7402. begin
  7403. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  7404. { inherit recordalignment }
  7405. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  7406. { if both the parent and this record use C-alignment, also inherit
  7407. the current field alignment }
  7408. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  7409. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  7410. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  7411. { the padding is not inherited for Objective-C classes (maybe not
  7412. for cppclass either?) }
  7413. if objecttype=odt_objcclass then
  7414. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  7415. if (oo_has_vmt in objectoptions) and
  7416. (oo_has_vmt in c.objectoptions) then
  7417. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  7418. { if parent has a vmt field then the offset is the same for the child PM }
  7419. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  7420. begin
  7421. vmt_field:=c.vmt_field;
  7422. include(objectoptions,oo_has_vmt);
  7423. end;
  7424. end;
  7425. end;
  7426. procedure tobjectdef.insertvmt;
  7427. begin
  7428. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  7429. exit;
  7430. if (oo_has_vmt in objectoptions) then
  7431. internalerror(2020100816)
  7432. else
  7433. begin
  7434. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  7435. tObjectSymtable(symtable).fieldalignment);
  7436. if (tf_requires_proper_alignment in target_info.flags) then
  7437. begin
  7438. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  7439. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  7440. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  7441. end;
  7442. vmt_field:=cfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  7443. hidesym(vmt_field);
  7444. tObjectSymtable(symtable).insertsym(vmt_field);
  7445. tObjectSymtable(symtable).addfield(tfieldvarsym(vmt_field),vis_hidden);
  7446. include(objectoptions,oo_has_vmt);
  7447. end;
  7448. end;
  7449. function tobjectdef.vmt_offset: asizeint;
  7450. begin
  7451. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  7452. result:=0
  7453. else if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  7454. result:=tfieldvarsym(vmt_field).fieldoffset
  7455. else
  7456. result:=tfieldvarsym(vmt_field).fieldoffset div 8;
  7457. end;
  7458. procedure tobjectdef.check_forwards;
  7459. begin
  7460. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  7461. inherited;
  7462. if (oo_is_forward in objectoptions) then
  7463. begin
  7464. { ok, in future, the forward can be resolved }
  7465. Message1(sym_e_class_forward_not_resolved,objrealname^);
  7466. exclude(objectoptions,oo_is_forward);
  7467. end;
  7468. end;
  7469. function tobjectdef.find_destructor: tprocdef;
  7470. var
  7471. objdef: tobjectdef;
  7472. begin
  7473. objdef:=self;
  7474. while assigned(objdef) do
  7475. begin
  7476. result:=objdef.find_procdef_bytype(potype_destructor);
  7477. if assigned(result) then
  7478. exit;
  7479. objdef:=objdef.childof;
  7480. end;
  7481. result:=nil;
  7482. end;
  7483. function tobjectdef.implements_any_interfaces: boolean;
  7484. begin
  7485. result := (ImplementedInterfaces.Count > 0) or
  7486. (assigned(childof) and childof.implements_any_interfaces);
  7487. end;
  7488. function tobjectdef.register_implemented_interface(intfdef:tobjectdef;useguid:boolean):timplementedinterface;
  7489. begin
  7490. { allocate the GUID only if the class implements at least one interface }
  7491. if useguid then
  7492. prepareguid;
  7493. result:=timplementedinterface.create(intfdef);
  7494. ImplementedInterfaces.Add(result);
  7495. end;
  7496. function tobjectdef.size : asizeint;
  7497. begin
  7498. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  7499. result:=voidpointertype.size
  7500. else
  7501. result:=tObjectSymtable(symtable).datasize;
  7502. end;
  7503. function tobjectdef.alignment:shortint;
  7504. begin
  7505. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  7506. alignment:=voidpointertype.alignment
  7507. else
  7508. alignment:=tObjectSymtable(symtable).recordalignment;
  7509. end;
  7510. function tobjectdef.vmtmethodoffset(index:longint):longint;
  7511. begin
  7512. { for offset of methods for classes, see rtl/inc/objpash.inc }
  7513. case objecttype of
  7514. odt_class:
  7515. { the +2*sizeof(pint) is size and -size }
  7516. vmtmethodoffset:=index*voidcodepointertype.size+10*voidpointertype.size+2*sizeof(pint);
  7517. odt_helper,
  7518. odt_objcclass,
  7519. odt_objcprotocol:
  7520. vmtmethodoffset:=0;
  7521. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  7522. vmtmethodoffset:=index*voidcodepointertype.size;
  7523. odt_javaclass,
  7524. odt_interfacejava:
  7525. { invalid }
  7526. vmtmethodoffset:=-1;
  7527. else
  7528. { the +2*sizeof(pint) is size and -size }
  7529. {$ifdef WITHDMT}
  7530. vmtmethodoffset:=index*voidcodepointertype.size+2*voidpointertype.size+2*sizeof(pint);
  7531. {$else WITHDMT}
  7532. vmtmethodoffset:=index*voidcodepointertype.size+1*voidpointertype.size+2*sizeof(pint);
  7533. {$endif WITHDMT}
  7534. end;
  7535. end;
  7536. function tobjectdef.vmt_mangledname : TSymStr;
  7537. begin
  7538. if not(oo_has_vmt in objectoptions) then
  7539. Message1(parser_n_object_has_no_vmt,objrealname^);
  7540. if not is_unique_objpasdef then
  7541. vmt_mangledname:=make_mangledname('VMT',owner,objname^)
  7542. else
  7543. vmt_mangledname:=childof.vmt_mangledname;
  7544. end;
  7545. function tobjectdef.vmt_def: trecorddef;
  7546. var
  7547. where: tsymtable;
  7548. vmttypesym: tsymentry;
  7549. begin
  7550. if not is_unique_objpasdef then
  7551. begin
  7552. vmttypesym:=symtable.Find('vmtdef');
  7553. if not assigned(vmttypesym) or
  7554. (vmttypesym.typ<>symconst.typesym) or
  7555. (ttypesym(vmttypesym).typedef.typ<>recorddef) then
  7556. internalerror(2015052501);
  7557. result:=trecorddef(ttypesym(vmttypesym).typedef);
  7558. end
  7559. else
  7560. result:=childof.vmt_def;
  7561. end;
  7562. function tobjectdef.needs_inittable : boolean;
  7563. var
  7564. hp : tobjectdef;
  7565. begin
  7566. case objecttype of
  7567. odt_helper,
  7568. odt_class :
  7569. needs_inittable:=false;
  7570. odt_dispinterface,
  7571. odt_interfacecom:
  7572. needs_inittable:=true;
  7573. odt_interfacecorba:
  7574. begin
  7575. hp:=childof;
  7576. while assigned(hp) do
  7577. begin
  7578. if hp=interface_iunknown then
  7579. begin
  7580. needs_inittable:=true;
  7581. exit;
  7582. end;
  7583. hp:=hp.childof;
  7584. end;
  7585. needs_inittable:=false;
  7586. end;
  7587. odt_object:
  7588. needs_inittable:=
  7589. tObjectSymtable(symtable).needs_init_final or
  7590. (assigned(childof) and
  7591. childof.needs_inittable);
  7592. odt_cppclass,
  7593. odt_objcclass,
  7594. odt_objcprotocol,
  7595. odt_javaclass,
  7596. odt_interfacejava:
  7597. needs_inittable:=false;
  7598. else
  7599. internalerror(200108267);
  7600. end;
  7601. end;
  7602. function tobjectdef.needs_separate_initrtti : boolean;
  7603. begin
  7604. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  7605. end;
  7606. function tobjectdef.has_non_trivial_init_child(check_parent:boolean):boolean;
  7607. begin
  7608. if objecttype in [odt_class,odt_object] then
  7609. begin
  7610. result:=tobjectsymtable(symtable).has_non_trivial_init or
  7611. (check_parent and assigned(childof) and childof.has_non_trivial_init_child(true));
  7612. end
  7613. else
  7614. result:=false;
  7615. end;
  7616. function tobjectdef.rtti_mangledname(rt: trttitype): TSymStr;
  7617. begin
  7618. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  7619. begin
  7620. if not is_unique_objpasdef then
  7621. result:=inherited rtti_mangledname(rt)
  7622. else
  7623. result:=childof.rtti_mangledname(rt)
  7624. end
  7625. else
  7626. begin
  7627. { necessary in case of a dynamic array of nsobject, or
  7628. if an nsobject field appears in a record that needs
  7629. init/finalisation }
  7630. if rt=initrtti then
  7631. begin
  7632. result:=voidpointertype.rtti_mangledname(rt);
  7633. exit;
  7634. end;
  7635. if not(target_info.system in systems_objc_nfabi) then
  7636. begin
  7637. result:=target_asm.labelprefix;
  7638. case objecttype of
  7639. odt_objcclass:
  7640. begin
  7641. case rt of
  7642. objcclassrtti:
  7643. if not(oo_is_classhelper in objectoptions) then
  7644. result:=result+'_OBJC_CLASS_'
  7645. else
  7646. result:=result+'_OBJC_CATEGORY_';
  7647. objcmetartti:
  7648. if not(oo_is_classhelper in objectoptions) then
  7649. result:=result+'_OBJC_METACLASS_'
  7650. else
  7651. internalerror(2009111511);
  7652. else
  7653. internalerror(2009092302);
  7654. end;
  7655. end;
  7656. odt_objcprotocol:
  7657. result:=result+'_OBJC_PROTOCOL_';
  7658. else
  7659. ;
  7660. end;
  7661. end
  7662. else
  7663. begin
  7664. case objecttype of
  7665. odt_objcclass:
  7666. begin
  7667. if (oo_is_classhelper in objectoptions) and
  7668. (rt<>objcclassrtti) then
  7669. internalerror(2009111512);
  7670. case rt of
  7671. objcclassrtti:
  7672. if not(oo_is_classhelper in objectoptions) then
  7673. result:='_OBJC_CLASS_$_'
  7674. else
  7675. result:='_OBJC_$_CATEGORY_';
  7676. objcmetartti:
  7677. result:='_OBJC_METACLASS_$_';
  7678. objcclassrortti:
  7679. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  7680. objcmetarortti:
  7681. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  7682. else
  7683. internalerror(2009092303);
  7684. end;
  7685. end;
  7686. odt_objcprotocol:
  7687. begin
  7688. result:=lower(target_asm.labelprefix);
  7689. case rt of
  7690. objcclassrtti:
  7691. result:=result+'_OBJC_PROTOCOL_$_';
  7692. objcmetartti:
  7693. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  7694. else
  7695. internalerror(2009092501);
  7696. end;
  7697. end;
  7698. else
  7699. internalerror(2013113005);
  7700. end;
  7701. end;
  7702. result:=result+objextname^;
  7703. end;
  7704. end;
  7705. function tobjectdef.is_unique_objpasdef: boolean;
  7706. begin
  7707. result:=
  7708. (df_unique in defoptions) and
  7709. is_class_or_interface_or_dispinterface(self)
  7710. end;
  7711. function tobjectdef.members_need_inittable : boolean;
  7712. begin
  7713. members_need_inittable:=tObjectSymtable(symtable).needs_init_final or
  7714. has_non_trivial_init_child(true);
  7715. end;
  7716. function tobjectdef.is_publishable : tpublishproperty;
  7717. begin
  7718. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  7719. is_publishable:=pp_publish
  7720. else
  7721. is_publishable:=pp_error;
  7722. end;
  7723. function tobjectdef.get_next_dispid: longint;
  7724. begin
  7725. inc(fcurrent_dispid);
  7726. result:=fcurrent_dispid;
  7727. end;
  7728. function tobjectdef.search_enumerator_get: tprocdef;
  7729. begin
  7730. result:=inherited;
  7731. if not assigned(result) and assigned(childof) then
  7732. result:=childof.search_enumerator_get;
  7733. end;
  7734. function tobjectdef.search_enumerator_move: tprocdef;
  7735. begin
  7736. result:=inherited;
  7737. if not assigned(result) and assigned(childof) then
  7738. result:=childof.search_enumerator_move;
  7739. end;
  7740. function tobjectdef.search_enumerator_current: tsym;
  7741. begin
  7742. result:=inherited;
  7743. if not assigned(result) and assigned(childof) then
  7744. result:=childof.search_enumerator_current;
  7745. end;
  7746. procedure tobjectdef.register_created_classref_type;
  7747. begin
  7748. if not classref_created_in_current_module then
  7749. begin
  7750. classref_created_in_current_module:=true;
  7751. if not (owner.symtabletype in [localsymtable]) then
  7752. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  7753. end;
  7754. end;
  7755. procedure tobjectdef.register_created_object_type;
  7756. begin
  7757. if not created_in_current_module then
  7758. begin
  7759. created_in_current_module:=true;
  7760. if not (owner.symtabletype in [localsymtable]) then
  7761. current_module.wpoinfo.addcreatedobjtype(self);
  7762. end;
  7763. end;
  7764. procedure tobjectdef.register_maybe_created_object_type;
  7765. begin
  7766. { if we know it has been created for sure, no need
  7767. to also record that it maybe can be created in
  7768. this module
  7769. }
  7770. if not (created_in_current_module) and
  7771. not (maybe_created_in_current_module) then
  7772. begin
  7773. maybe_created_in_current_module:=true;
  7774. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  7775. end;
  7776. end;
  7777. procedure tobjectdef.register_vmt_call(index: longint);
  7778. begin
  7779. if (is_object(self) or is_class(self)) then
  7780. current_module.wpoinfo.addcalledvmtentry(self,index);
  7781. end;
  7782. procedure check_and_finish_msg(data: tobject; arg: pointer);
  7783. var
  7784. def: tdef absolute data;
  7785. pd: tprocdef absolute data;
  7786. i,
  7787. paracount: longint;
  7788. begin
  7789. if (def.typ=procdef) then
  7790. begin
  7791. { add all messages also under a dummy name to the symtable in
  7792. which the objcclass/protocol/category is declared, so they can
  7793. be called via id.<name>
  7794. }
  7795. create_class_helper_for_procdef(pd,nil);
  7796. { we have to wait until now to set the mangled name because it
  7797. depends on the (possibly external) class name, which is defined
  7798. at the very end. }
  7799. if not(po_msgstr in pd.procoptions) then
  7800. begin
  7801. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  7802. { recover to avoid internalerror later on }
  7803. include(pd.procoptions,po_msgstr);
  7804. pd.messageinf.str:=stringdup('MissingDeclaration');
  7805. end;
  7806. { Mangled name is already set in case this is a copy of
  7807. another type. }
  7808. if not(po_has_mangledname in pd.procoptions) then
  7809. begin
  7810. { check whether the number of formal parameters is correct,
  7811. and whether they have valid Objective-C types }
  7812. paracount:=0;
  7813. for i:=1 to length(pd.messageinf.str^) do
  7814. if pd.messageinf.str^[i]=':' then
  7815. inc(paracount);
  7816. for i:=0 to pd.paras.count-1 do
  7817. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  7818. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  7819. dec(paracount);
  7820. if (paracount<>0) then
  7821. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  7822. pd.setmangledname(pd.objcmangledname);
  7823. end
  7824. else
  7825. { all checks already done }
  7826. exit;
  7827. if not(oo_is_external in pd.struct.objectoptions) then
  7828. begin
  7829. if (po_varargs in pd.procoptions) then
  7830. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  7831. else
  7832. begin
  7833. { check for "array of const" parameters }
  7834. for i:=0 to pd.parast.symlist.count-1 do
  7835. begin
  7836. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  7837. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  7838. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  7839. end;
  7840. end;
  7841. end;
  7842. end;
  7843. end;
  7844. procedure mark_private_fields_used(data: tobject; arg: pointer);
  7845. var
  7846. sym: tsym absolute data;
  7847. begin
  7848. if (sym.typ=fieldvarsym) and
  7849. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  7850. sym.IncRefCount;
  7851. end;
  7852. procedure tobjectdef.finish_objc_data;
  7853. begin
  7854. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  7855. if (oo_is_external in objectoptions) then
  7856. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  7857. end;
  7858. procedure verify_objc_vardef(data: tobject; arg: pointer);
  7859. var
  7860. sym: tabstractvarsym absolute data;
  7861. res: pboolean absolute arg;
  7862. founderrordef: tdef;
  7863. begin
  7864. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  7865. exit;
  7866. if (sym.typ=paravarsym) and
  7867. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  7868. is_array_of_const(tparavarsym(sym).vardef)) then
  7869. exit;
  7870. if not objcchecktype(sym.vardef,founderrordef) then
  7871. begin
  7872. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7873. res^:=false;
  7874. end;
  7875. end;
  7876. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  7877. var
  7878. def: tdef absolute data;
  7879. res: pboolean absolute arg;
  7880. founderrordef: tdef;
  7881. begin
  7882. if (def.typ<>procdef) then
  7883. exit;
  7884. { check parameter types for validity }
  7885. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  7886. { check the result type for validity }
  7887. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  7888. begin
  7889. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7890. res^:=false;
  7891. end;
  7892. end;
  7893. function tobjectdef.check_objc_types: boolean;
  7894. begin
  7895. { done in separate step from finish_objc_data, because when
  7896. finish_objc_data is called, not all forwarddefs have been resolved
  7897. yet and we need to know all types here }
  7898. result:=true;
  7899. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  7900. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  7901. end;
  7902. procedure do_cpp_import_info(data: tobject; arg: pointer);
  7903. var
  7904. def: tdef absolute data;
  7905. pd: tprocdef absolute data;
  7906. begin
  7907. if (def.typ=procdef) then
  7908. begin
  7909. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  7910. if (oo_is_external in pd.struct.objectoptions) then
  7911. begin
  7912. { copied from psub.read_proc }
  7913. if assigned(tobjectdef(pd.struct).import_lib) then
  7914. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  7915. else
  7916. begin
  7917. { add import name to external list for DLL scanning }
  7918. if tf_has_dllscanner in target_info.flags then
  7919. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  7920. end;
  7921. end;
  7922. end;
  7923. end;
  7924. procedure tobjectdef.finish_cpp_data;
  7925. begin
  7926. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  7927. end;
  7928. procedure tobjectdef.apply_rtti_directive(dir: trtti_directive);
  7929. begin
  7930. rtti.clause:=dir.clause;
  7931. rtti.options:=dir.options;
  7932. if (dir.clause=rtc_inherit) and assigned(childof) and (childof.rtti.clause<>rtc_none) then
  7933. begin
  7934. rtti.options[ro_methods]:=rtti.options[ro_methods]+childof.rtti.options[ro_methods];
  7935. rtti.options[ro_fields]:=rtti.options[ro_fields]+childof.rtti.options[ro_fields];
  7936. rtti.options[ro_properties]:=rtti.options[ro_properties]+childof.rtti.options[ro_properties];
  7937. end;
  7938. end;
  7939. {$ifdef DEBUG_NODE_XML}
  7940. function TObjectDef.XMLPrintType: ansistring;
  7941. begin
  7942. if (oo_is_forward in objectoptions) then
  7943. Result := '&lt;class prototype&gt;'
  7944. else
  7945. Result := '&lt;class&gt;';
  7946. end;
  7947. procedure TObjectDef.XMLPrintDefInfo(var T: Text; Sym: TSym);
  7948. var
  7949. i: TObjectOption;
  7950. first: Boolean;
  7951. begin
  7952. inherited XMLPrintDefInfo(T, Sym);
  7953. First := True;
  7954. for i := Low(TObjectOption) to High(TObjectOption) do
  7955. if i in objectoptions then
  7956. begin
  7957. if First then
  7958. begin
  7959. Write(T, ' objectoptions="', i);
  7960. First := False;
  7961. end
  7962. else
  7963. Write(T, ',', i)
  7964. end;
  7965. if not first then
  7966. Write(T, '"');
  7967. end;
  7968. procedure TObjectDef.XMLPrintDefData(var T: Text; Sym: TSym);
  7969. begin
  7970. { There's nothing useful yet if the type is only forward-declared }
  7971. if not (oo_is_forward in objectoptions) then
  7972. begin
  7973. if Assigned(childof) then
  7974. WriteLn(T, printnodeindention, '<ancestor>', SanitiseXMLString(childof.typesym.RealName), '</ancestor>');
  7975. inherited XMLPrintDefData(T, Sym);
  7976. end;
  7977. end;
  7978. {$endif DEBUG_NODE_XML}
  7979. {****************************************************************************
  7980. TImplementedInterface
  7981. ****************************************************************************}
  7982. function TImplementedInterface.GetIOffset: longint;
  7983. begin
  7984. if (fIOffset=-1) and
  7985. (IType in [etFieldValue,etFieldValueClass]) then
  7986. result:=tfieldvarsym(ImplementsField).fieldoffset
  7987. else
  7988. result:=fIOffset;
  7989. end;
  7990. constructor TImplementedInterface.create(aintf: tobjectdef);
  7991. begin
  7992. inherited create;
  7993. intfdef:=aintf;
  7994. intfdefderef.reset;
  7995. IOffset:=-1;
  7996. IType:=etStandard;
  7997. NameMappings:=nil;
  7998. procdefs:=nil;
  7999. end;
  8000. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  8001. begin
  8002. inherited create;
  8003. intfdef:=nil;
  8004. intfdefderef:=intfd;
  8005. ImplementsGetterDeref:=getterd;
  8006. IOffset:=-1;
  8007. IType:=etStandard;
  8008. NameMappings:=nil;
  8009. procdefs:=nil;
  8010. end;
  8011. destructor TImplementedInterface.destroy;
  8012. var
  8013. i : longint;
  8014. mappedname : pshortstring;
  8015. begin
  8016. if assigned(NameMappings) then
  8017. begin
  8018. for i:=0 to NameMappings.Count-1 do
  8019. begin
  8020. mappedname:=pshortstring(NameMappings[i]);
  8021. stringdispose(mappedname);
  8022. end;
  8023. NameMappings.free;
  8024. NameMappings:=nil;
  8025. end;
  8026. if assigned(procdefs) then
  8027. begin
  8028. procdefs.free;
  8029. procdefs:=nil;
  8030. end;
  8031. inherited destroy;
  8032. end;
  8033. procedure TImplementedInterface.buildderef;
  8034. begin
  8035. intfdefderef.build(intfdef);
  8036. ImplementsGetterDeref.build(ImplementsGetter);
  8037. end;
  8038. procedure TImplementedInterface.deref;
  8039. begin
  8040. intfdef:=tobjectdef(intfdefderef.resolve);
  8041. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  8042. end;
  8043. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  8044. begin
  8045. if not assigned(NameMappings) then
  8046. NameMappings:=TFPHashList.Create;
  8047. NameMappings.Add(origname,stringdup(newname));
  8048. end;
  8049. function TImplementedInterface.GetMapping(const origname: string):string;
  8050. var
  8051. mappedname : pshortstring;
  8052. begin
  8053. result:='';
  8054. if not assigned(NameMappings) then
  8055. exit;
  8056. mappedname:=PShortstring(NameMappings.Find(origname));
  8057. if assigned(mappedname) then
  8058. result:=mappedname^;
  8059. end;
  8060. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  8061. begin
  8062. if not assigned(procdefs) then
  8063. procdefs:=TFPObjectList.Create(false);
  8064. { duplicate entries must be stored, because multiple }
  8065. { interfaces can declare methods with the same name }
  8066. { and all of these get their own VMT entry }
  8067. procdefs.Add(pd);
  8068. end;
  8069. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  8070. var
  8071. i : longint;
  8072. begin
  8073. result:=false;
  8074. { interfaces being implemented through delegation are not mergable (FK) }
  8075. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  8076. exit;
  8077. weight:=0;
  8078. { empty interface is mergeable }
  8079. if ProcDefs.Count=0 then
  8080. begin
  8081. result:=true;
  8082. exit;
  8083. end;
  8084. { The interface to merge must at least the number of
  8085. procedures of this interface }
  8086. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  8087. exit;
  8088. for i:=0 to ProcDefs.Count-1 do
  8089. begin
  8090. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  8091. exit;
  8092. end;
  8093. weight:=ProcDefs.Count;
  8094. result:=true;
  8095. end;
  8096. function TImplementedInterface.getcopy:TImplementedInterface;
  8097. var
  8098. i : longint;
  8099. begin
  8100. Result:=TImplementedInterface.Create(nil);
  8101. { 1) the procdefs list will be freed once for each copy
  8102. 2) since the procdefs list owns its elements, those will also be freed for each copy
  8103. Nope: procdefs are owned by their symtable, so no copy necessary
  8104. 3) idem for the name mappings
  8105. }
  8106. result.fIOffset:=fIOffset;
  8107. result.IntfDef:=IntfDef;
  8108. result.IntfDefDeref.reset;
  8109. result.IType:=IType;
  8110. result.VtblImplIntf:=VtblImplIntf;
  8111. if assigned(NameMappings) then
  8112. begin
  8113. result.NameMappings:=TFPHashList.create;
  8114. for i:=0 to NameMappings.Count-1 do
  8115. Result.NameMappings.Add(NameMappings.NameOfIndex(i),
  8116. stringdup(pshortstring(NameMappings.Items[i])^));
  8117. end;
  8118. if assigned(ProcDefs) then
  8119. begin
  8120. result.ProcDefs:=TFPObjectList.create(false);
  8121. { Note: this is probably wrong, because those procdefs are owned by
  8122. the old objectdef from which we copy, what would be the correct way
  8123. of doing this is to lookup the equivalent copy in the new owner
  8124. and reference this instead... But this is complicated so let's try
  8125. it this way until it blows up ok? }
  8126. for i:=0 to ProcDefs.Count-1 do
  8127. Result.ProcDefs.add(tprocdef(procdefs[i]).getcopy);
  8128. end;
  8129. result.ImplementsGetter:=ImplementsGetter;
  8130. result.ImplementsGetterDeref.reset;
  8131. result.ImplementsField:=ImplementsField;
  8132. end;
  8133. {****************************************************************************
  8134. TFORWARDDEF
  8135. ****************************************************************************}
  8136. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  8137. begin
  8138. inherited create(forwarddef,true);
  8139. tosymname:=stringdup(s);
  8140. forwardpos:=pos;
  8141. end;
  8142. function tforwarddef.GetTypeName:string;
  8143. begin
  8144. GetTypeName:='unresolved forward to '+tosymname^;
  8145. end;
  8146. destructor tforwarddef.destroy;
  8147. begin
  8148. stringdispose(tosymname);
  8149. inherited destroy;
  8150. end;
  8151. function tforwarddef.getcopy:tstoreddef;
  8152. begin
  8153. result:=cforwarddef.create(tosymname^, forwardpos);
  8154. end;
  8155. {****************************************************************************
  8156. TUNDEFINEDDEF
  8157. ****************************************************************************}
  8158. constructor tundefineddef.create(doregister:boolean);
  8159. begin
  8160. inherited create(undefineddef,doregister);
  8161. end;
  8162. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  8163. begin
  8164. inherited ppuload(undefineddef,ppufile);
  8165. ppuload_platform(ppufile);
  8166. end;
  8167. function tundefineddef.GetTypeName:string;
  8168. begin
  8169. GetTypeName:='<undefined type>';
  8170. end;
  8171. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  8172. begin
  8173. inherited ppuwrite(ppufile);
  8174. writeentry(ppufile,ibundefineddef);
  8175. end;
  8176. {****************************************************************************
  8177. TERRORDEF
  8178. ****************************************************************************}
  8179. constructor terrordef.create;
  8180. begin
  8181. inherited create(errordef,true);
  8182. { prevent consecutive faults }
  8183. savesize:=1;
  8184. end;
  8185. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  8186. begin
  8187. { Can't write errordefs to ppu }
  8188. internalerror(200411063);
  8189. end;
  8190. function terrordef.GetTypeName:string;
  8191. begin
  8192. GetTypeName:='<erroneous type>';
  8193. end;
  8194. function terrordef.getmangledparaname:TSymStr;
  8195. begin
  8196. getmangledparaname:='error';
  8197. end;
  8198. {****************************************************************************
  8199. Definition Helpers
  8200. ****************************************************************************}
  8201. function is_interfacecom(def: tdef): boolean;
  8202. begin
  8203. is_interfacecom:=
  8204. assigned(def) and
  8205. (def.typ=objectdef) and
  8206. (tobjectdef(def).objecttype=odt_interfacecom);
  8207. end;
  8208. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  8209. begin
  8210. is_interfacecom_or_dispinterface:=
  8211. assigned(def) and
  8212. (def.typ=objectdef) and
  8213. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  8214. end;
  8215. function is_any_interface_kind(def: tdef): boolean;
  8216. begin
  8217. result:=
  8218. assigned(def) and
  8219. (def.typ=objectdef) and
  8220. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  8221. is_objccategory(def));
  8222. end;
  8223. function is_interfacecorba(def: tdef): boolean;
  8224. begin
  8225. is_interfacecorba:=
  8226. assigned(def) and
  8227. (def.typ=objectdef) and
  8228. (tobjectdef(def).objecttype=odt_interfacecorba);
  8229. end;
  8230. function is_interface(def: tdef): boolean;
  8231. begin
  8232. is_interface:=
  8233. assigned(def) and
  8234. (def.typ=objectdef) and
  8235. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  8236. end;
  8237. function is_dispinterface(def: tdef): boolean;
  8238. begin
  8239. result:=
  8240. assigned(def) and
  8241. (def.typ=objectdef) and
  8242. (tobjectdef(def).objecttype=odt_dispinterface);
  8243. end;
  8244. function is_class(def: tdef): boolean;
  8245. begin
  8246. is_class:=
  8247. assigned(def) and
  8248. (def.typ=objectdef) and
  8249. (tobjectdef(def).objecttype=odt_class);
  8250. end;
  8251. function is_object(def: tdef): boolean;
  8252. begin
  8253. is_object:=
  8254. assigned(def) and
  8255. (def.typ=objectdef) and
  8256. (tobjectdef(def).objecttype=odt_object);
  8257. end;
  8258. function is_cppclass(def: tdef): boolean;
  8259. begin
  8260. is_cppclass:=
  8261. assigned(def) and
  8262. (def.typ=objectdef) and
  8263. (tobjectdef(def).objecttype=odt_cppclass);
  8264. end;
  8265. function is_objcclass(def: tdef): boolean;
  8266. begin
  8267. is_objcclass:=
  8268. assigned(def) and
  8269. (def.typ=objectdef) and
  8270. (tobjectdef(def).objecttype=odt_objcclass);
  8271. end;
  8272. function is_objectpascal_helper(def: tdef): boolean;
  8273. begin
  8274. result:=
  8275. assigned(def) and
  8276. (def.typ=objectdef) and
  8277. (tobjectdef(def).objecttype=odt_helper);
  8278. end;
  8279. function is_objcclassref(def: tdef): boolean;
  8280. begin
  8281. is_objcclassref:=
  8282. assigned(def) and
  8283. (def.typ=classrefdef) and
  8284. is_objcclass(tclassrefdef(def).pointeddef);
  8285. end;
  8286. function is_objcprotocol(def: tdef): boolean;
  8287. begin
  8288. result:=
  8289. assigned(def) and
  8290. (def.typ=objectdef) and
  8291. (tobjectdef(def).objecttype=odt_objcprotocol);
  8292. end;
  8293. function is_objccategory(def: tdef): boolean;
  8294. begin
  8295. result:=
  8296. assigned(def) and
  8297. (def.typ=objectdef) and
  8298. { if used as a forward type }
  8299. ((tobjectdef(def).objecttype=odt_objccategory) or
  8300. { if used as after it has been resolved }
  8301. ((tobjectdef(def).objecttype=odt_objcclass) and
  8302. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  8303. end;
  8304. function is_objc_class_or_protocol(def: tdef): boolean;
  8305. begin
  8306. result:=
  8307. assigned(def) and
  8308. (def.typ=objectdef) and
  8309. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  8310. end;
  8311. function is_objc_protocol_or_category(def: tdef): boolean;
  8312. begin
  8313. result:=
  8314. assigned(def) and
  8315. (def.typ=objectdef) and
  8316. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  8317. ((tobjectdef(def).objecttype = odt_objcclass) and
  8318. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  8319. end;
  8320. function is_classhelper(def: tdef): boolean;
  8321. begin
  8322. result:=
  8323. is_objectpascal_helper(def) or
  8324. is_objccategory(def);
  8325. end;
  8326. function is_class_or_interface(def: tdef): boolean;
  8327. begin
  8328. result:=
  8329. assigned(def) and
  8330. (def.typ=objectdef) and
  8331. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  8332. end;
  8333. function is_class_or_interface_or_objc(def: tdef): boolean;
  8334. begin
  8335. result:=
  8336. assigned(def) and
  8337. (def.typ=objectdef) and
  8338. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  8339. end;
  8340. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  8341. begin
  8342. result:=
  8343. assigned(def) and
  8344. (def.typ=objectdef) and
  8345. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  8346. end;
  8347. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  8348. begin
  8349. result:=
  8350. assigned(def) and
  8351. (def.typ=objectdef) and
  8352. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  8353. end;
  8354. function is_class_or_interface_or_object(def: tdef): boolean;
  8355. begin
  8356. result:=
  8357. assigned(def) and
  8358. (def.typ=objectdef) and
  8359. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  8360. end;
  8361. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  8362. begin
  8363. result:=
  8364. assigned(def) and
  8365. (def.typ=objectdef) and
  8366. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  8367. end;
  8368. function is_implicit_pointer_object_type(def: tdef): boolean;
  8369. begin
  8370. result:=
  8371. assigned(def) and
  8372. (((def.typ=objectdef) and
  8373. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  8374. ((target_info.system in systems_jvm) and
  8375. (def.typ=recorddef)));
  8376. end;
  8377. function is_implicit_array_pointer(def: tdef): boolean;
  8378. begin
  8379. result:=is_dynamic_array(def) or is_dynamicstring(def);
  8380. end;
  8381. function is_class_or_object(def: tdef): boolean;
  8382. begin
  8383. result:=
  8384. assigned(def) and
  8385. (def.typ=objectdef) and
  8386. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  8387. end;
  8388. function is_record(def: tdef): boolean;
  8389. begin
  8390. result:=
  8391. assigned(def) and
  8392. (def.typ=recorddef);
  8393. end;
  8394. function is_javaclass(def: tdef): boolean;
  8395. begin
  8396. result:=
  8397. assigned(def) and
  8398. (def.typ=objectdef) and
  8399. (tobjectdef(def).objecttype=odt_javaclass);
  8400. end;
  8401. function is_javaclassref(def: tdef): boolean;
  8402. begin
  8403. is_javaclassref:=
  8404. assigned(def) and
  8405. (def.typ=classrefdef) and
  8406. is_javaclass(tclassrefdef(def).pointeddef);
  8407. end;
  8408. function is_javainterface(def: tdef): boolean;
  8409. begin
  8410. result:=
  8411. assigned(def) and
  8412. (def.typ=objectdef) and
  8413. (tobjectdef(def).objecttype=odt_interfacejava);
  8414. end;
  8415. function is_java_class_or_interface(def: tdef): boolean;
  8416. begin
  8417. result:=
  8418. assigned(def) and
  8419. (def.typ=objectdef) and
  8420. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  8421. end;
  8422. procedure loadobjctypes;
  8423. begin
  8424. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  8425. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  8426. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  8427. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  8428. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  8429. end;
  8430. procedure maybeloadcocoatypes;
  8431. var
  8432. tsym: ttypesym;
  8433. cocoaunit: string[15];
  8434. begin
  8435. if assigned(objc_fastenumeration) then
  8436. exit;
  8437. if not(target_info.system in [system_arm_ios,system_i386_iphonesim,system_aarch64_ios,system_x86_64_iphonesim,system_aarch64_iphonesim]) then
  8438. cocoaunit:='COCOAALL'
  8439. else
  8440. cocoaunit:='IPHONEALL';
  8441. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  8442. if assigned(tsym) then
  8443. objc_fastenumeration:=tobjectdef(tsym.typedef)
  8444. else
  8445. objc_fastenumeration:=nil;
  8446. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  8447. if assigned(tsym) then
  8448. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  8449. else
  8450. objc_fastenumerationstate:=nil;
  8451. end;
  8452. function use_vectorfpu(def : tdef) : boolean;
  8453. begin
  8454. {$ifdef x86}
  8455. {$define use_vectorfpuimplemented}
  8456. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  8457. (is_double(def) and (current_settings.fputype in sse_doublescalar)) or
  8458. { Check vector types }
  8459. (
  8460. is_normal_array(def) and
  8461. (ado_IsVector in tarraydef(def).arrayoptions) and
  8462. (
  8463. (
  8464. is_single(tarraydef(def).elementdef) and
  8465. (
  8466. { SSE or AVX XMM register }
  8467. ((tarraydef(def).elecount = 4) and (current_settings.fputype in sse_singlescalar)) or
  8468. { AVX YMM register }
  8469. ((tarraydef(def).elecount = 8) and (current_settings.fputype in fpu_avx_instructionsets))
  8470. {$ifndef i8086}
  8471. or
  8472. { AVX512 ZMM register }
  8473. ((tarraydef(def).elecount = 16) and (current_settings.fputype in [fpu_avx512f]))
  8474. {$endif not i8086}
  8475. )
  8476. ) or
  8477. (
  8478. is_double(tarraydef(def).elementdef) and
  8479. (
  8480. { SSE or AVX XMM register }
  8481. ((tarraydef(def).elecount = 2) and (current_settings.fputype in sse_doublescalar)) or
  8482. { AVX YMM register }
  8483. ((tarraydef(def).elecount = 4) and (current_settings.fputype in fpu_avx_instructionsets))
  8484. {$ifndef i8086}
  8485. { AVX512 ZMM register }
  8486. or ((tarraydef(def).elecount = 8) and (current_settings.fputype in [fpu_avx512f]))
  8487. {$endif not i8086}
  8488. )
  8489. )
  8490. )
  8491. );
  8492. {$endif x86}
  8493. {$ifdef arm}
  8494. {$define use_vectorfpuimplemented}
  8495. use_vectorfpu:=FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[current_settings.fputype];
  8496. {$endif arm}
  8497. {$ifdef aarch64}
  8498. {$define use_vectorfpuimplemented}
  8499. use_vectorfpu:=true;
  8500. {$endif aarch64}
  8501. {$ifndef use_vectorfpuimplemented}
  8502. use_vectorfpu:=false;
  8503. {$endif}
  8504. end;
  8505. procedure reset_all_default_types;
  8506. { Those class pointers have to be set to nil manually }
  8507. { after memory they point to have been released. }
  8508. { Necessary strictly for Textmode IDE. }
  8509. begin
  8510. voidpointertype:=nil; { pointer for Void-pointeddef }
  8511. charpointertype:=nil; { pointer for Char-pointeddef }
  8512. widecharpointertype:=nil; { pointer for WideChar-pointeddef }
  8513. voidcodepointertype:=nil; { pointer to code; corresponds to System.CodePointer }
  8514. voidstackpointertype:=nil; { the pointer type used for accessing parameters and local vars on the stack }
  8515. parentfpvoidpointertype:=nil; { void pointer with the size of the hidden parentfp parameter, passed to nested functions }
  8516. {$ifdef x86}
  8517. voidnearpointertype:=nil;
  8518. voidnearcspointertype:=nil;
  8519. voidneardspointertype:=nil;
  8520. voidnearsspointertype:=nil;
  8521. voidnearespointertype:=nil;
  8522. voidnearfspointertype:=nil;
  8523. voidneargspointertype:=nil;
  8524. {$ifdef i8086}
  8525. voidfarpointertype:=nil;
  8526. voidhugepointertype:=nil;
  8527. charnearpointertype:=nil;
  8528. charfarpointertype:=nil;
  8529. charhugepointertype:=nil;
  8530. bytefarpointertype:=nil; { used for Mem[] }
  8531. wordfarpointertype:=nil; { used for MemW[] }
  8532. longintfarpointertype:=nil; { used for MemL[] }
  8533. {$endif i8086}
  8534. {$endif x86}
  8535. {$ifdef wasm}
  8536. wasmvoidexternreftype:=nil;
  8537. {$endif wasm}
  8538. cundefinedtype:=nil;
  8539. cformaltype:=nil; { unique formal definition }
  8540. ctypedformaltype:=nil; { unique typed formal definition }
  8541. voidtype:=nil; { Void (procedure) }
  8542. cansichartype:=nil; { Char }
  8543. cwidechartype:=nil; { WideChar }
  8544. cchartype:=nil; { either cansichartype or cwidechartype. Do not free }
  8545. pasbool1type:=nil; { boolean type }
  8546. pasbool8type:=nil;
  8547. pasbool16type:=nil;
  8548. pasbool32type:=nil;
  8549. pasbool64type:=nil;
  8550. bool8type:=nil;
  8551. bool16type:=nil;
  8552. bool32type:=nil;
  8553. bool64type:=nil;
  8554. {$ifdef llvm}
  8555. llvmbool1type:=nil; { LLVM i1 type }
  8556. {$endif llvm}
  8557. u8inttype:=nil; { 8-Bit unsigned integer }
  8558. s8inttype:=nil; { 8-Bit signed integer }
  8559. u16inttype:=nil; { 16-Bit unsigned integer }
  8560. s16inttype:=nil; { 16-Bit signed integer }
  8561. u24inttype:=nil; { 24-Bit unsigned integer }
  8562. s24inttype:=nil; { 24-Bit signed integer }
  8563. u32inttype:=nil; { 32-Bit unsigned integer }
  8564. s32inttype:=nil; { 32-Bit signed integer }
  8565. u40inttype:=nil; { 40-Bit unsigned integer }
  8566. s40inttype:=nil; { 40-Bit signed integer }
  8567. u48inttype:=nil; { 48-Bit unsigned integer }
  8568. s48inttype:=nil; { 48-Bit signed integer }
  8569. u56inttype:=nil; { 56-Bit unsigned integer }
  8570. s56inttype:=nil; { 56-Bit signed integer }
  8571. u64inttype:=nil; { 64-bit unsigned integer }
  8572. s64inttype:=nil; { 64-bit signed integer }
  8573. u128inttype:=nil; { 128-bit unsigned integer }
  8574. s128inttype:=nil; { 128-bit signed integer }
  8575. s32floattype:=nil; { 32 bit floating point number }
  8576. s64floattype:=nil; { 64 bit floating point number }
  8577. s80floattype:=nil; { 80 bit floating point number }
  8578. sc80floattype:=nil; { 80 bit floating point number but stored like in C }
  8579. s64currencytype:=nil; { pointer to a currency type }
  8580. cshortstringtype:=nil; { pointer to type of short string const }
  8581. clongstringtype:=nil; { pointer to type of long string const }
  8582. cansistringtype:=nil; { pointer to type of ansi string const }
  8583. cwidestringtype:=nil; { pointer to type of wide string const }
  8584. cunicodestringtype:=nil;
  8585. openshortstringtype:=nil;
  8586. openchararraytype:=nil;
  8587. cfiletype:=nil;
  8588. methodpointertype:=nil; { typecasting of methodpointers to extract self }
  8589. nestedprocpointertype:=nil; { typecasting of nestedprocpointers to extract parentfp }
  8590. hresultdef:=nil;
  8591. typekindtype:=nil; { def of TTypeKind for correct handling of GetTypeKind parameters }
  8592. { we use only one variant def for every variant class }
  8593. cvarianttype:=nil;
  8594. colevarianttype:=nil;
  8595. { default integer type, normally s32inttype on 32 bit systems and s64bittype on 64 bit systems }
  8596. sinttype:=nil;
  8597. uinttype:=nil;
  8598. { integer types corresponding to OS_SINT/OS_INT }
  8599. ossinttype:=nil;
  8600. osuinttype:=nil;
  8601. { integer types corresponding to the ALU size, sizeof(aint) and the ALUSInt/ALUUInt types in the system unit }
  8602. alusinttype:=nil;
  8603. aluuinttype:=nil;
  8604. { integer types corresponding to SizeInt and SizeUInt for the target platform }
  8605. sizeuinttype:=nil;
  8606. sizesinttype:=nil;
  8607. { unsigned and signed ord type with the same size as a pointer }
  8608. ptruinttype:=nil;
  8609. ptrsinttype:=nil;
  8610. { unsigned and signed ord type with the same size as a codepointer }
  8611. codeptruinttype:=nil;
  8612. codeptrsinttype:=nil;
  8613. { several types to simulate more or less C++ objects for GDB }
  8614. vmttype:=nil;
  8615. vmtarraytype:=nil;
  8616. { type of classrefs, used for stabs }
  8617. pvmttype:=nil;
  8618. { return type of the setjmp function }
  8619. exceptionreasontype:=nil;
  8620. class_tobject:=nil;
  8621. class_tcustomattribute:=nil;
  8622. interface_iunknown:=nil;
  8623. interface_idispatch:=nil;
  8624. rec_tguid:=nil;
  8625. rec_jmp_buf:=nil;
  8626. rec_exceptaddr:=nil;
  8627. objc_metaclasstype:=nil;
  8628. objc_superclasstype:=nil;
  8629. objc_idtype:=nil;
  8630. objc_seltype:=nil;
  8631. objc_objecttype:=nil;
  8632. objc_protocoltype:=nil;
  8633. objc_fastenumeration:=nil;
  8634. objc_fastenumerationstate:=nil;
  8635. {$ifdef llvm}
  8636. { llvm types }
  8637. { a unique def to identify any kind of metadata }
  8638. llvm_metadatatype:=nil;
  8639. {$endif llvm}
  8640. { Java base types }
  8641. java_jlobject:=nil;
  8642. java_jlthrowable:=nil;
  8643. java_fpcbaserecordtype:=nil;
  8644. java_jlstring:=nil;
  8645. java_jlenum:=nil;
  8646. java_juenumset:=nil;
  8647. java_jubitset:=nil;
  8648. java_ansistring:=nil;
  8649. java_shortstring:=nil;
  8650. java_procvarbase:=nil;
  8651. { x86 vector types }
  8652. x86_m64type:=nil;
  8653. x86_m128type:=nil;
  8654. x86_m128dtype:=nil;
  8655. x86_m128itype:=nil;
  8656. x86_m256type:=nil;
  8657. x86_m256dtype:=nil;
  8658. x86_m256itype:=nil;
  8659. end;
  8660. end.