symdef.pas 317 KB

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