symdef.pas 297 KB

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