symdef.pas 313 KB

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