symdef.pas 313 KB

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