symdef.pas 335 KB

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