symdef.pas 281 KB

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