symdef.pas 314 KB

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