symdef.pas 317 KB

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