symdef.pas 313 KB

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