symdef.pas 316 KB

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