symdef.pas 193 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symdef;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,globals,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,
  28. { ppu }
  29. ppu,
  30. { node }
  31. node,
  32. { aasm }
  33. aasmbase,aasmtai,
  34. cpubase,cpuinfo,
  35. cgbase,parabase
  36. ;
  37. type
  38. {************************************************
  39. TDef
  40. ************************************************}
  41. tstoreddef = class(tdef)
  42. protected
  43. typesymderef : tderef;
  44. public
  45. { persistent (available across units) rtti and init tables }
  46. rttitablesym,
  47. inittablesym : tsym; {trttisym}
  48. rttitablesymderef,
  49. inittablesymderef : tderef;
  50. { local (per module) rtti and init tables }
  51. localrttilab : array[trttitype] of tasmlabel;
  52. { linked list of global definitions }
  53. {$ifdef EXTDEBUG}
  54. fileinfo : tfileposinfo;
  55. {$endif}
  56. {$ifdef GDB}
  57. globalnb : word;
  58. stab_state : tdefstabstatus;
  59. {$endif GDB}
  60. constructor create;
  61. constructor ppuloaddef(ppufile:tcompilerppufile);
  62. procedure reset;
  63. function getcopy : tstoreddef;virtual;
  64. procedure ppuwritedef(ppufile:tcompilerppufile);
  65. procedure ppuwrite(ppufile:tcompilerppufile);virtual;abstract;
  66. procedure buildderef;override;
  67. procedure buildderefimpl;override;
  68. procedure deref;override;
  69. procedure derefimpl;override;
  70. function size:aint;override;
  71. function alignment:longint;override;
  72. function is_publishable : boolean;override;
  73. function needs_inittable : boolean;override;
  74. { debug }
  75. {$ifdef GDB}
  76. function get_var_value(const s:string):string;
  77. function stabstr_evaluate(const s:string;const vars:array of string):Pchar;
  78. function stabstring : pchar;virtual;
  79. procedure concatstabto(asmlist : taasmoutput);virtual;
  80. function numberstring:string;virtual;
  81. procedure set_globalnb;virtual;
  82. function allstabstring : pchar;virtual;
  83. {$endif GDB}
  84. { rtti generation }
  85. procedure write_rtti_name;
  86. procedure write_rtti_data(rt:trttitype);virtual;
  87. procedure write_child_rtti_data(rt:trttitype);virtual;
  88. function get_rtti_label(rt:trttitype):tasmsymbol;
  89. { regvars }
  90. function is_intregable : boolean;
  91. function is_fpuregable : boolean;
  92. private
  93. savesize : aint;
  94. end;
  95. tparaitem = class(TLinkedListItem)
  96. paratype : ttype; { required for procvar }
  97. parasym : tsym;
  98. parasymderef : tderef;
  99. defaultvalue : tsym; { tconstsym }
  100. defaultvaluederef : tderef;
  101. paratyp : tvarspez; { required for procvar }
  102. paraloc : array[tcallercallee] of TCGPara;
  103. is_hidden : boolean; { is this a hidden (implicit) parameter }
  104. {$ifdef EXTDEBUG}
  105. eqval : tequaltype;
  106. {$endif EXTDEBUG}
  107. constructor create;
  108. destructor destroy;override;
  109. end;
  110. tfiletyp = (ft_text,ft_typed,ft_untyped);
  111. tfiledef = class(tstoreddef)
  112. filetyp : tfiletyp;
  113. typedfiletype : ttype;
  114. constructor createtext;
  115. constructor createuntyped;
  116. constructor createtyped(const tt : ttype);
  117. constructor ppuload(ppufile:tcompilerppufile);
  118. procedure ppuwrite(ppufile:tcompilerppufile);override;
  119. procedure buildderef;override;
  120. procedure deref;override;
  121. function gettypename:string;override;
  122. function getmangledparaname:string;override;
  123. procedure setsize;
  124. { debug }
  125. {$ifdef GDB}
  126. function stabstring : pchar;override;
  127. procedure concatstabto(asmlist : taasmoutput);override;
  128. {$endif GDB}
  129. end;
  130. tvariantdef = class(tstoreddef)
  131. varianttype : tvarianttype;
  132. constructor create(v : tvarianttype);
  133. constructor ppuload(ppufile:tcompilerppufile);
  134. function gettypename:string;override;
  135. procedure ppuwrite(ppufile:tcompilerppufile);override;
  136. procedure setsize;
  137. function needs_inittable : boolean;override;
  138. procedure write_rtti_data(rt:trttitype);override;
  139. {$ifdef GDB}
  140. function numberstring:string;override;
  141. function stabstring : pchar;override;
  142. procedure concatstabto(asmlist : taasmoutput);override;
  143. {$endif GDB}
  144. end;
  145. tformaldef = class(tstoreddef)
  146. constructor create;
  147. constructor ppuload(ppufile:tcompilerppufile);
  148. procedure ppuwrite(ppufile:tcompilerppufile);override;
  149. function gettypename:string;override;
  150. {$ifdef GDB}
  151. function numberstring:string;override;
  152. function stabstring : pchar;override;
  153. procedure concatstabto(asmlist : taasmoutput);override;
  154. {$endif GDB}
  155. end;
  156. tforwarddef = class(tstoreddef)
  157. tosymname : pstring;
  158. forwardpos : tfileposinfo;
  159. constructor create(const s:string;const pos : tfileposinfo);
  160. destructor destroy;override;
  161. function gettypename:string;override;
  162. end;
  163. terrordef = class(tstoreddef)
  164. constructor create;
  165. function gettypename:string;override;
  166. function getmangledparaname : string;override;
  167. { debug }
  168. {$ifdef GDB}
  169. function stabstring : pchar;override;
  170. procedure concatstabto(asmlist : taasmoutput);override;
  171. {$endif GDB}
  172. end;
  173. { tpointerdef and tclassrefdef should get a common
  174. base class, but I derived tclassrefdef from tpointerdef
  175. to avoid problems with bugs (FK)
  176. }
  177. tpointerdef = class(tstoreddef)
  178. pointertype : ttype;
  179. is_far : boolean;
  180. constructor create(const tt : ttype);
  181. constructor createfar(const tt : ttype);
  182. function getcopy : tstoreddef;override;
  183. constructor ppuload(ppufile:tcompilerppufile);
  184. procedure ppuwrite(ppufile:tcompilerppufile);override;
  185. procedure buildderef;override;
  186. procedure deref;override;
  187. function gettypename:string;override;
  188. { debug }
  189. {$ifdef GDB}
  190. function stabstring : pchar;override;
  191. procedure concatstabto(asmlist : taasmoutput);override;
  192. {$endif GDB}
  193. end;
  194. Trecord_stabgen_state=record
  195. stabstring:Pchar;
  196. stabsize,staballoc,recoffset:integer;
  197. end;
  198. tabstractrecorddef= class(tstoreddef)
  199. private
  200. Count : integer;
  201. FRTTIType : trttitype;
  202. {$ifdef GDB}
  203. procedure field_addname(p:Tnamedindexitem;arg:pointer);
  204. procedure field_concatstabto(p:Tnamedindexitem;arg:pointer);
  205. {$endif}
  206. procedure count_field_rtti(sym : tnamedindexitem;arg:pointer);
  207. procedure write_field_rtti(sym : tnamedindexitem;arg:pointer);
  208. procedure generate_field_rtti(sym : tnamedindexitem;arg:pointer);
  209. public
  210. symtable : tsymtable;
  211. function getsymtable(t:tgetsymtable):tsymtable;override;
  212. end;
  213. trecorddef = class(tabstractrecorddef)
  214. public
  215. isunion : boolean;
  216. constructor create(p : tsymtable);
  217. constructor ppuload(ppufile:tcompilerppufile);
  218. destructor destroy;override;
  219. procedure ppuwrite(ppufile:tcompilerppufile);override;
  220. procedure buildderef;override;
  221. procedure deref;override;
  222. function size:aint;override;
  223. function alignment : longint;override;
  224. function padalignment: longint;
  225. function gettypename:string;override;
  226. { debug }
  227. {$ifdef GDB}
  228. function stabstring : pchar;override;
  229. procedure concatstabto(asmlist:taasmoutput);override;
  230. {$endif GDB}
  231. function needs_inittable : boolean;override;
  232. { rtti }
  233. procedure write_child_rtti_data(rt:trttitype);override;
  234. procedure write_rtti_data(rt:trttitype);override;
  235. end;
  236. tprocdef = class;
  237. timplementedinterfaces = class;
  238. tobjectdef = class(tabstractrecorddef)
  239. private
  240. {$ifdef GDB}
  241. procedure proc_addname(p :tnamedindexitem;arg:pointer);
  242. procedure proc_concatstabto(p :tnamedindexitem;arg:pointer);
  243. {$endif GDB}
  244. procedure count_published_properties(sym:tnamedindexitem;arg:pointer);
  245. procedure write_property_info(sym : tnamedindexitem;arg:pointer);
  246. procedure generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  247. procedure count_published_fields(sym:tnamedindexitem;arg:pointer);
  248. procedure writefields(sym:tnamedindexitem;arg:pointer);
  249. public
  250. childof : tobjectdef;
  251. childofderef : tderef;
  252. objname,
  253. objrealname : pstring;
  254. objectoptions : tobjectoptions;
  255. { to be able to have a variable vmt position }
  256. { and no vmt field for objects without virtuals }
  257. vmt_offset : longint;
  258. {$ifdef GDB}
  259. writing_class_record_stab : boolean;
  260. {$endif GDB}
  261. objecttype : tobjectdeftype;
  262. iidguid: pguid;
  263. iidstr: pstring;
  264. lastvtableindex: longint;
  265. { store implemented interfaces defs and name mappings }
  266. implementedinterfaces: timplementedinterfaces;
  267. constructor create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  268. constructor ppuload(ppufile:tcompilerppufile);
  269. destructor destroy;override;
  270. procedure ppuwrite(ppufile:tcompilerppufile);override;
  271. function gettypename:string;override;
  272. procedure buildderef;override;
  273. procedure deref;override;
  274. function getparentdef:tdef;override;
  275. function size : aint;override;
  276. function alignment:longint;override;
  277. function vmtmethodoffset(index:longint):longint;
  278. function members_need_inittable : boolean;
  279. { this should be called when this class implements an interface }
  280. procedure prepareguid;
  281. function is_publishable : boolean;override;
  282. function needs_inittable : boolean;override;
  283. function vmt_mangledname : string;
  284. function rtti_name : string;
  285. procedure check_forwards;
  286. function is_related(d : tobjectdef) : boolean;
  287. function next_free_name_index : longint;
  288. procedure insertvmt;
  289. procedure set_parent(c : tobjectdef);
  290. function searchdestructor : tprocdef;
  291. { debug }
  292. {$ifdef GDB}
  293. function stabstring : pchar;override;
  294. procedure set_globalnb;override;
  295. function classnumberstring : string;
  296. procedure concatstabto(asmlist : taasmoutput);override;
  297. function allstabstring : pchar;override;
  298. {$endif GDB}
  299. { rtti }
  300. procedure write_child_rtti_data(rt:trttitype);override;
  301. procedure write_rtti_data(rt:trttitype);override;
  302. function generate_field_table : tasmlabel;
  303. end;
  304. timplementedinterfaces = class
  305. constructor create;
  306. destructor destroy; override;
  307. function count: longint;
  308. function interfaces(intfindex: longint): tobjectdef;
  309. function interfacesderef(intfindex: longint): tderef;
  310. function ioffsets(intfindex: longint): plongint;
  311. function searchintf(def: tdef): longint;
  312. procedure addintf(def: tdef);
  313. procedure buildderef;
  314. procedure deref;
  315. { add interface reference loaded from ppu }
  316. procedure addintf_deref(const d:tderef);
  317. procedure clearmappings;
  318. procedure addmappings(intfindex: longint; const name, newname: string);
  319. function getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  320. procedure clearimplprocs;
  321. procedure addimplproc(intfindex: longint; procdef: tprocdef);
  322. function implproccount(intfindex: longint): longint;
  323. function implprocs(intfindex: longint; procindex: longint): tprocdef;
  324. function isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  325. private
  326. finterfaces: tindexarray;
  327. procedure checkindex(intfindex: longint);
  328. end;
  329. tclassrefdef = class(tpointerdef)
  330. constructor create(const t:ttype);
  331. constructor ppuload(ppufile:tcompilerppufile);
  332. procedure ppuwrite(ppufile:tcompilerppufile);override;
  333. function gettypename:string;override;
  334. { debug }
  335. {$ifdef GDB}
  336. function stabstring : pchar;override;
  337. {$endif GDB}
  338. end;
  339. tarraydef = class(tstoreddef)
  340. lowrange,
  341. highrange : aint;
  342. rangetype : ttype;
  343. IsConvertedPointer,
  344. IsDynamicArray,
  345. IsVariant,
  346. IsConstructor,
  347. IsArrayOfConst : boolean;
  348. protected
  349. _elementtype : ttype;
  350. public
  351. function elesize : aint;
  352. function elecount : aint;
  353. constructor create_from_pointer(const elemt : ttype);
  354. constructor create(l,h : aint;const t : ttype);
  355. constructor ppuload(ppufile:tcompilerppufile);
  356. procedure ppuwrite(ppufile:tcompilerppufile);override;
  357. function gettypename:string;override;
  358. function getmangledparaname : string;override;
  359. procedure setelementtype(t: ttype);
  360. {$ifdef GDB}
  361. function stabstring : pchar;override;
  362. procedure concatstabto(asmlist : taasmoutput);override;
  363. {$endif GDB}
  364. procedure buildderef;override;
  365. procedure deref;override;
  366. function size : aint;override;
  367. function alignment : longint;override;
  368. { returns the label of the range check string }
  369. function needs_inittable : boolean;override;
  370. procedure write_child_rtti_data(rt:trttitype);override;
  371. procedure write_rtti_data(rt:trttitype);override;
  372. property elementtype : ttype Read _ElementType;
  373. end;
  374. torddef = class(tstoreddef)
  375. low,high : TConstExprInt;
  376. typ : tbasetype;
  377. constructor create(t : tbasetype;v,b : TConstExprInt);
  378. constructor ppuload(ppufile:tcompilerppufile);
  379. function getcopy : tstoreddef;override;
  380. procedure ppuwrite(ppufile:tcompilerppufile);override;
  381. function is_publishable : boolean;override;
  382. function gettypename:string;override;
  383. procedure setsize;
  384. { debug }
  385. {$ifdef GDB}
  386. function stabstring : pchar;override;
  387. {$endif GDB}
  388. { rtti }
  389. procedure write_rtti_data(rt:trttitype);override;
  390. end;
  391. tfloatdef = class(tstoreddef)
  392. typ : tfloattype;
  393. constructor create(t : tfloattype);
  394. constructor ppuload(ppufile:tcompilerppufile);
  395. function getcopy : tstoreddef;override;
  396. procedure ppuwrite(ppufile:tcompilerppufile);override;
  397. function gettypename:string;override;
  398. function is_publishable : boolean;override;
  399. procedure setsize;
  400. { debug }
  401. {$ifdef GDB}
  402. function stabstring : pchar;override;
  403. procedure concatstabto(asmlist:taasmoutput);override;
  404. {$endif GDB}
  405. { rtti }
  406. procedure write_rtti_data(rt:trttitype);override;
  407. end;
  408. tabstractprocdef = class(tstoreddef)
  409. { saves a definition to the return type }
  410. rettype : ttype;
  411. parast : tsymtable;
  412. para : tlinkedlist;
  413. proctypeoption : tproctypeoption;
  414. proccalloption : tproccalloption;
  415. procoptions : tprocoptions;
  416. requiredargarea : aint;
  417. maxparacount,
  418. minparacount : byte;
  419. {$ifdef i386}
  420. fpu_used : byte; { how many stack fpu must be empty }
  421. {$endif i386}
  422. funcret_paraloc : array[tcallercallee] of TCGPara;
  423. has_paraloc_info : boolean; { paraloc info is available }
  424. constructor create(level:byte);
  425. constructor ppuload(ppufile:tcompilerppufile);
  426. destructor destroy;override;
  427. procedure ppuwrite(ppufile:tcompilerppufile);override;
  428. procedure buildderef;override;
  429. procedure deref;override;
  430. procedure releasemem;
  431. function concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  432. function insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  433. procedure removepara(currpara:tparaitem);
  434. function typename_paras(showhidden:boolean): string;
  435. procedure test_if_fpu_result;
  436. function is_methodpointer:boolean;virtual;
  437. function is_addressonly:boolean;virtual;
  438. { debug }
  439. {$ifdef GDB}
  440. function stabstring : pchar;override;
  441. {$endif GDB}
  442. end;
  443. tprocvardef = class(tabstractprocdef)
  444. constructor create(level:byte);
  445. constructor ppuload(ppufile:tcompilerppufile);
  446. procedure ppuwrite(ppufile:tcompilerppufile);override;
  447. procedure buildderef;override;
  448. procedure deref;override;
  449. function getsymtable(t:tgetsymtable):tsymtable;override;
  450. function size : aint;override;
  451. function gettypename:string;override;
  452. function is_publishable : boolean;override;
  453. function is_methodpointer:boolean;override;
  454. function is_addressonly:boolean;override;
  455. { debug }
  456. {$ifdef GDB}
  457. function stabstring : pchar;override;
  458. procedure concatstabto(asmlist:taasmoutput);override;
  459. {$endif GDB}
  460. { rtti }
  461. procedure write_rtti_data(rt:trttitype);override;
  462. end;
  463. tmessageinf = record
  464. case integer of
  465. 0 : (str : pchar);
  466. 1 : (i : longint);
  467. end;
  468. tinlininginfo = record
  469. { node tree }
  470. code : tnode;
  471. flags : tprocinfoflags;
  472. inlinenode : boolean;
  473. end;
  474. pinlininginfo = ^tinlininginfo;
  475. {$ifdef oldregvars}
  476. { register variables }
  477. pregvarinfo = ^tregvarinfo;
  478. tregvarinfo = record
  479. regvars : array[1..maxvarregs] of tsym;
  480. regvars_para : array[1..maxvarregs] of boolean;
  481. regvars_refs : array[1..maxvarregs] of longint;
  482. fpuregvars : array[1..maxfpuvarregs] of tsym;
  483. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  484. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  485. end;
  486. {$endif oldregvars}
  487. tprocdef = class(tabstractprocdef)
  488. private
  489. _mangledname : pstring;
  490. {$ifdef GDB}
  491. isstabwritten : boolean;
  492. {$endif GDB}
  493. public
  494. extnumber : word;
  495. overloadnumber : word;
  496. messageinf : tmessageinf;
  497. {$ifndef EXTDEBUG}
  498. { where is this function defined and what were the symbol
  499. flags, needed here because there
  500. is only one symbol for all overloaded functions
  501. EXTDEBUG has fileinfo in tdef (PFV) }
  502. fileinfo : tfileposinfo;
  503. {$endif}
  504. symoptions : tsymoptions;
  505. { symbol owning this definition }
  506. procsym : tsym;
  507. procsymderef : tderef;
  508. { alias names }
  509. aliasnames : tstringlist;
  510. { symtables }
  511. localst : tsymtable;
  512. funcretsym : tsym;
  513. funcretsymderef : tderef;
  514. { browser info }
  515. lastref,
  516. defref,
  517. lastwritten : tref;
  518. refcount : longint;
  519. _class : tobjectdef;
  520. _classderef : tderef;
  521. {$ifdef powerpc}
  522. { library symbol for AmigaOS/MorphOS }
  523. libsym : tsym;
  524. libsymderef : tderef;
  525. {$endif powerpc}
  526. { name of the result variable to insert in the localsymtable }
  527. resultname : stringid;
  528. { true, if the procedure is only declared
  529. (forward procedure) }
  530. forwarddef,
  531. { true if the procedure is declared in the interface }
  532. interfacedef : boolean;
  533. { true if the procedure has a forward declaration }
  534. hasforward : boolean;
  535. { check the problems of manglednames }
  536. has_mangledname : boolean;
  537. { info for inlining the subroutine, if this pointer is nil,
  538. the procedure can't be inlined }
  539. inlininginfo : pinlininginfo;
  540. {$ifdef oldregvars}
  541. regvarinfo: pregvarinfo;
  542. {$endif oldregvars}
  543. constructor create(level:byte);
  544. constructor ppuload(ppufile:tcompilerppufile);
  545. destructor destroy;override;
  546. procedure ppuwrite(ppufile:tcompilerppufile);override;
  547. procedure buildderef;override;
  548. procedure buildderefimpl;override;
  549. procedure deref;override;
  550. procedure derefimpl;override;
  551. function getsymtable(t:tgetsymtable):tsymtable;override;
  552. function gettypename : string;override;
  553. function mangledname : string;
  554. procedure setmangledname(const s : string);
  555. procedure load_references(ppufile:tcompilerppufile;locals:boolean);
  556. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  557. { inserts the local symbol table, if this is not
  558. no local symbol table is built. Should be called only
  559. when we are sure that a local symbol table will be required.
  560. }
  561. procedure insert_localst;
  562. function fullprocname(showhidden:boolean):string;
  563. function cplusplusmangledname : string;
  564. function is_methodpointer:boolean;override;
  565. function is_addressonly:boolean;override;
  566. function is_visible_for_object(currobjdef:tobjectdef):boolean;
  567. { debug }
  568. {$ifdef GDB}
  569. function numberstring:string;override;
  570. function stabstring : pchar;override;
  571. procedure concatstabto(asmlist : taasmoutput);override;
  572. {$endif GDB}
  573. end;
  574. { single linked list of overloaded procs }
  575. pprocdeflist = ^tprocdeflist;
  576. tprocdeflist = record
  577. def : tprocdef;
  578. defderef : tderef;
  579. own : boolean;
  580. next : pprocdeflist;
  581. end;
  582. tstringdef = class(tstoreddef)
  583. string_typ : tstringtype;
  584. len : aint;
  585. constructor createshort(l : byte);
  586. constructor loadshort(ppufile:tcompilerppufile);
  587. constructor createlong(l : aint);
  588. constructor loadlong(ppufile:tcompilerppufile);
  589. {$ifdef ansistring_bits}
  590. constructor createansi(l:aint;bits:Tstringbits);
  591. constructor loadansi(ppufile:tcompilerppufile;bits:Tstringbits);
  592. {$else}
  593. constructor createansi(l : aint);
  594. constructor loadansi(ppufile:tcompilerppufile);
  595. {$endif}
  596. constructor createwide(l : aint);
  597. constructor loadwide(ppufile:tcompilerppufile);
  598. function getcopy : tstoreddef;override;
  599. function stringtypname:string;
  600. procedure ppuwrite(ppufile:tcompilerppufile);override;
  601. function gettypename:string;override;
  602. function getmangledparaname:string;override;
  603. function is_publishable : boolean;override;
  604. { debug }
  605. {$ifdef GDB}
  606. function stabstring : pchar;override;
  607. procedure concatstabto(asmlist : taasmoutput);override;
  608. {$endif GDB}
  609. { init/final }
  610. function needs_inittable : boolean;override;
  611. { rtti }
  612. procedure write_rtti_data(rt:trttitype);override;
  613. end;
  614. tenumdef = class(tstoreddef)
  615. minval,
  616. maxval : aint;
  617. has_jumps : boolean;
  618. firstenum : tsym; {tenumsym}
  619. basedef : tenumdef;
  620. basedefderef : tderef;
  621. constructor create;
  622. constructor create_subrange(_basedef:tenumdef;_min,_max:aint);
  623. constructor ppuload(ppufile:tcompilerppufile);
  624. destructor destroy;override;
  625. procedure ppuwrite(ppufile:tcompilerppufile);override;
  626. procedure buildderef;override;
  627. procedure deref;override;
  628. function gettypename:string;override;
  629. function is_publishable : boolean;override;
  630. procedure calcsavesize;
  631. procedure setmax(_max:aint);
  632. procedure setmin(_min:aint);
  633. function min:aint;
  634. function max:aint;
  635. { debug }
  636. {$ifdef GDB}
  637. function stabstring : pchar;override;
  638. {$endif GDB}
  639. { rtti }
  640. procedure write_rtti_data(rt:trttitype);override;
  641. procedure write_child_rtti_data(rt:trttitype);override;
  642. private
  643. procedure correct_owner_symtable;
  644. end;
  645. tsetdef = class(tstoreddef)
  646. elementtype : ttype;
  647. settype : tsettype;
  648. constructor create(const t:ttype;high : longint);
  649. constructor ppuload(ppufile:tcompilerppufile);
  650. destructor destroy;override;
  651. procedure ppuwrite(ppufile:tcompilerppufile);override;
  652. procedure buildderef;override;
  653. procedure deref;override;
  654. function gettypename:string;override;
  655. function is_publishable : boolean;override;
  656. { debug }
  657. {$ifdef GDB}
  658. function stabstring : pchar;override;
  659. procedure concatstabto(asmlist : taasmoutput);override;
  660. {$endif GDB}
  661. { rtti }
  662. procedure write_rtti_data(rt:trttitype);override;
  663. procedure write_child_rtti_data(rt:trttitype);override;
  664. end;
  665. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  666. var
  667. aktobjectdef : tobjectdef; { used for private functions check !! }
  668. {$ifdef GDB}
  669. writing_def_stabs : boolean;
  670. { for STAB debugging }
  671. globaltypecount : word;
  672. pglobaltypecount : pword;
  673. {$endif GDB}
  674. { default types }
  675. generrortype, { error in definition }
  676. voidpointertype, { pointer for Void-Pointerdef }
  677. charpointertype, { pointer for Char-Pointerdef }
  678. voidfarpointertype,
  679. cformaltype, { unique formal definition }
  680. voidtype, { Void (procedure) }
  681. cchartype, { Char }
  682. cwidechartype, { WideChar }
  683. booltype, { boolean type }
  684. u8inttype, { 8-Bit unsigned integer }
  685. s8inttype, { 8-Bit signed integer }
  686. u16inttype, { 16-Bit unsigned integer }
  687. s16inttype, { 16-Bit signed integer }
  688. u32inttype, { 32-Bit unsigned integer }
  689. s32inttype, { 32-Bit signed integer }
  690. u64inttype, { 64-bit unsigned integer }
  691. s64inttype, { 64-bit signed integer }
  692. s32floattype, { pointer for realconstn }
  693. s64floattype, { pointer for realconstn }
  694. s80floattype, { pointer to type of temp. floats }
  695. s64currencytype, { pointer to a currency type }
  696. cshortstringtype, { pointer to type of short string const }
  697. clongstringtype, { pointer to type of long string const }
  698. {$ifdef ansistring_bits}
  699. cansistringtype16, { pointer to type of ansi string const }
  700. cansistringtype32, { pointer to type of ansi string const }
  701. cansistringtype64, { pointer to type of ansi string const }
  702. {$else}
  703. cansistringtype, { pointer to type of ansi string const }
  704. {$endif}
  705. cwidestringtype, { pointer to type of wide string const }
  706. openshortstringtype, { pointer to type of an open shortstring,
  707. needed for readln() }
  708. openchararraytype, { pointer to type of an open array of char,
  709. needed for readln() }
  710. cfiletype, { get the same definition for all file }
  711. { used for stabs }
  712. methodpointertype, { typecasting of methodpointers to extract self }
  713. { we use only one variant def for every variant class }
  714. cvarianttype,
  715. colevarianttype,
  716. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  717. sinttype,
  718. uinttype,
  719. { unsigned ord type with the same size as a pointer }
  720. ptrinttype,
  721. { several types to simulate more or less C++ objects for GDB }
  722. vmttype,
  723. vmtarraytype,
  724. pvmttype : ttype; { type of classrefs, used for stabs }
  725. { pointer to the anchestor of all classes }
  726. class_tobject : tobjectdef;
  727. { pointer to the ancestor of all COM interfaces }
  728. interface_iunknown : tobjectdef;
  729. { pointer to the TGUID type
  730. of all interfaces }
  731. rec_tguid : trecorddef;
  732. const
  733. {$ifdef i386}
  734. pbestrealtype : ^ttype = @s80floattype;
  735. {$endif}
  736. {$ifdef x86_64}
  737. pbestrealtype : ^ttype = @s80floattype;
  738. {$endif}
  739. {$ifdef m68k}
  740. pbestrealtype : ^ttype = @s64floattype;
  741. {$endif}
  742. {$ifdef alpha}
  743. pbestrealtype : ^ttype = @s64floattype;
  744. {$endif}
  745. {$ifdef powerpc}
  746. pbestrealtype : ^ttype = @s64floattype;
  747. {$endif}
  748. {$ifdef ia64}
  749. pbestrealtype : ^ttype = @s64floattype;
  750. {$endif}
  751. {$ifdef SPARC}
  752. pbestrealtype : ^ttype = @s64floattype;
  753. {$endif SPARC}
  754. {$ifdef vis}
  755. pbestrealtype : ^ttype = @s64floattype;
  756. {$endif vis}
  757. {$ifdef ARM}
  758. pbestrealtype : ^ttype = @s64floattype;
  759. {$endif ARM}
  760. function reverseparaitems(p: tparaitem): tparaitem;
  761. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  762. { should be in the types unit, but the types unit uses the node stuff :( }
  763. function is_interfacecom(def: tdef): boolean;
  764. function is_interfacecorba(def: tdef): boolean;
  765. function is_interface(def: tdef): boolean;
  766. function is_object(def: tdef): boolean;
  767. function is_class(def: tdef): boolean;
  768. function is_cppclass(def: tdef): boolean;
  769. function is_class_or_interface(def: tdef): boolean;
  770. implementation
  771. uses
  772. strings,
  773. { global }
  774. verbose,
  775. { target }
  776. systems,aasmcpu,paramgr,
  777. { symtable }
  778. symsym,symtable,symutil,defutil,
  779. { module }
  780. {$ifdef GDB}
  781. gdb,
  782. {$endif GDB}
  783. fmodule,
  784. { other }
  785. gendef
  786. ;
  787. {****************************************************************************
  788. Helpers
  789. ****************************************************************************}
  790. function reverseparaitems(p: tparaitem): tparaitem;
  791. var
  792. hp1, hp2: tparaitem;
  793. begin
  794. hp1:=nil;
  795. while assigned(p) do
  796. begin
  797. { pull out }
  798. hp2:=p;
  799. p:=tparaitem(p.next);
  800. { pull in }
  801. hp2.next:=hp1;
  802. hp1:=hp2;
  803. end;
  804. reverseparaitems:=hp1;
  805. end;
  806. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  807. var
  808. s,
  809. prefix : string;
  810. begin
  811. prefix:='';
  812. if not assigned(st) then
  813. internalerror(200204212);
  814. { sub procedures }
  815. while (st.symtabletype=localsymtable) do
  816. begin
  817. if st.defowner.deftype<>procdef then
  818. internalerror(200204173);
  819. s:=tprocdef(st.defowner).procsym.name;
  820. if tprocdef(st.defowner).overloadnumber>0 then
  821. s:=s+'$'+tostr(tprocdef(st.defowner).overloadnumber);
  822. prefix:=s+'$'+prefix;
  823. st:=st.defowner.owner;
  824. end;
  825. { object/classes symtable }
  826. if (st.symtabletype=objectsymtable) then
  827. begin
  828. if st.defowner.deftype<>objectdef then
  829. internalerror(200204174);
  830. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  831. st:=st.defowner.owner;
  832. end;
  833. { symtable must now be static or global }
  834. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  835. internalerror(200204175);
  836. result:='';
  837. if typeprefix<>'' then
  838. result:=result+typeprefix+'_';
  839. { Add P$ for program, which can have the same name as
  840. a unit }
  841. if (tsymtable(main_module.localsymtable)=st) and
  842. (not main_module.is_unit) then
  843. result:=result+'P$'+st.name^
  844. else
  845. result:=result+st.name^;
  846. if prefix<>'' then
  847. result:=result+'_'+prefix;
  848. if suffix<>'' then
  849. result:=result+'_'+suffix;
  850. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  851. if (target_info.system = system_powerpc_darwin) and
  852. (result[1] = 'L') then
  853. result := '_' + result;
  854. end;
  855. {****************************************************************************
  856. TParaItem
  857. ****************************************************************************}
  858. constructor tparaitem.create;
  859. begin
  860. inherited create;
  861. paraloc[calleeside].init;
  862. paraloc[callerside].init;
  863. end;
  864. destructor tparaitem.destroy;
  865. begin
  866. paraloc[calleeside].done;
  867. paraloc[callerside].done;
  868. inherited destroy;
  869. end;
  870. {****************************************************************************
  871. TDEF (base class for definitions)
  872. ****************************************************************************}
  873. constructor tstoreddef.create;
  874. begin
  875. inherited create;
  876. savesize := 0;
  877. {$ifdef EXTDEBUG}
  878. fileinfo := aktfilepos;
  879. {$endif}
  880. if registerdef then
  881. symtablestack.registerdef(self);
  882. {$ifdef GDB}
  883. stab_state:=stab_state_unused;
  884. globalnb := 0;
  885. {$endif GDB}
  886. fillchar(localrttilab,sizeof(localrttilab),0);
  887. end;
  888. constructor tstoreddef.ppuloaddef(ppufile:tcompilerppufile);
  889. begin
  890. inherited create;
  891. {$ifdef EXTDEBUG}
  892. fillchar(fileinfo,sizeof(fileinfo),0);
  893. {$endif}
  894. {$ifdef GDB}
  895. stab_state:=stab_state_unused;
  896. globalnb := 0;
  897. {$endif GDB}
  898. fillchar(localrttilab,sizeof(localrttilab),0);
  899. { load }
  900. indexnr:=ppufile.getword;
  901. ppufile.getderef(typesymderef);
  902. ppufile.getsmallset(defoptions);
  903. if df_has_rttitable in defoptions then
  904. ppufile.getderef(rttitablesymderef);
  905. if df_has_inittable in defoptions then
  906. ppufile.getderef(inittablesymderef);
  907. end;
  908. procedure Tstoreddef.reset;
  909. begin
  910. {$ifdef GDB}
  911. stab_state:=stab_state_unused;
  912. {$endif GDB}
  913. if assigned(rttitablesym) then
  914. trttisym(rttitablesym).lab := nil;
  915. if assigned(inittablesym) then
  916. trttisym(inittablesym).lab := nil;
  917. localrttilab[initrtti]:=nil;
  918. localrttilab[fullrtti]:=nil;
  919. end;
  920. function tstoreddef.getcopy : tstoreddef;
  921. begin
  922. Message(sym_e_cant_create_unique_type);
  923. getcopy:=terrordef.create;
  924. end;
  925. procedure tstoreddef.ppuwritedef(ppufile:tcompilerppufile);
  926. begin
  927. ppufile.putword(indexnr);
  928. ppufile.putderef(typesymderef);
  929. ppufile.putsmallset(defoptions);
  930. if df_has_rttitable in defoptions then
  931. ppufile.putderef(rttitablesymderef);
  932. if df_has_inittable in defoptions then
  933. ppufile.putderef(inittablesymderef);
  934. {$ifdef GDB}
  935. if globalnb=0 then
  936. begin
  937. if (cs_gdb_dbx in aktglobalswitches) and
  938. assigned(owner) then
  939. globalnb := owner.getnewtypecount
  940. else
  941. set_globalnb;
  942. end;
  943. {$endif GDB}
  944. end;
  945. procedure tstoreddef.buildderef;
  946. begin
  947. typesymderef.build(typesym);
  948. rttitablesymderef.build(rttitablesym);
  949. inittablesymderef.build(inittablesym);
  950. end;
  951. procedure tstoreddef.buildderefimpl;
  952. begin
  953. end;
  954. procedure tstoreddef.deref;
  955. begin
  956. typesym:=ttypesym(typesymderef.resolve);
  957. if df_has_rttitable in defoptions then
  958. rttitablesym:=trttisym(rttitablesymderef.resolve);
  959. if df_has_inittable in defoptions then
  960. inittablesym:=trttisym(inittablesymderef.resolve);
  961. end;
  962. procedure tstoreddef.derefimpl;
  963. begin
  964. end;
  965. function tstoreddef.size : aint;
  966. begin
  967. size:=savesize;
  968. end;
  969. function tstoreddef.alignment : longint;
  970. begin
  971. { natural alignment by default }
  972. alignment:=size_2_align(savesize);
  973. end;
  974. {$ifdef GDB}
  975. procedure tstoreddef.set_globalnb;
  976. begin
  977. globalnb:=PGlobalTypeCount^;
  978. inc(PglobalTypeCount^);
  979. end;
  980. function Tstoreddef.get_var_value(const s:string):string;
  981. begin
  982. if s='numberstring' then
  983. get_var_value:=numberstring
  984. else if s='sym_name' then
  985. if assigned(typesym) then
  986. get_var_value:=Ttypesym(typesym).name
  987. else
  988. get_var_value:=' '
  989. else if s='N_LSYM' then
  990. get_var_value:=tostr(N_LSYM)
  991. else if s='savesize' then
  992. get_var_value:=tostr(savesize);
  993. end;
  994. function Tstoreddef.stabstr_evaluate(const s:string;const vars:array of string):Pchar;
  995. begin
  996. stabstr_evaluate:=string_evaluate(s,@get_var_value,vars);
  997. end;
  998. function tstoreddef.stabstring : pchar;
  999. begin
  1000. stabstring:=stabstr_evaluate('t${numberstring};',[]);
  1001. end;
  1002. function tstoreddef.numberstring : string;
  1003. begin
  1004. { Stab must already be written, or we must be busy writing it }
  1005. if writing_def_stabs and
  1006. not(stab_state in [stab_state_writing,stab_state_written]) then
  1007. internalerror(200403091);
  1008. { Keep track of used stabs, this info is only usefull for stabs
  1009. referenced by the symbols. Definitions will always include all
  1010. required stabs }
  1011. if stab_state=stab_state_unused then
  1012. stab_state:=stab_state_used;
  1013. { Need a new number? }
  1014. if globalnb=0 then
  1015. begin
  1016. if (cs_gdb_dbx in aktglobalswitches) and
  1017. assigned(owner) then
  1018. globalnb := owner.getnewtypecount
  1019. else
  1020. set_globalnb;
  1021. end;
  1022. if (cs_gdb_dbx in aktglobalswitches) and
  1023. assigned(typesym) and
  1024. (ttypesym(typesym).owner.unitid<>0) then
  1025. result:='('+tostr(ttypesym(typesym).owner.unitid)+','+tostr(tstoreddef(ttypesym(typesym).restype.def).globalnb)+')'
  1026. else
  1027. result:=tostr(globalnb);
  1028. end;
  1029. function tstoreddef.allstabstring : pchar;
  1030. var
  1031. stabchar : string[2];
  1032. ss,st,su : pchar;
  1033. begin
  1034. ss := stabstring;
  1035. stabchar := 't';
  1036. if deftype in tagtypes then
  1037. stabchar := 'Tt';
  1038. { Here we maybe generate a type, so we have to use numberstring }
  1039. st:=stabstr_evaluate('"${sym_name}:$1$2=',[stabchar,numberstring]);
  1040. reallocmem(st,strlen(ss)+512);
  1041. { line info is set to 0 for all defs, because the def can be in an other
  1042. unit and then the linenumber is invalid in the current sourcefile }
  1043. su:=stabstr_evaluate('",${N_LSYM},0,0,0',[]);
  1044. strcopy(strecopy(strend(st),ss),su);
  1045. reallocmem(st,strlen(st)+1);
  1046. allstabstring:=st;
  1047. strdispose(ss);
  1048. strdispose(su);
  1049. end;
  1050. procedure tstoreddef.concatstabto(asmlist : taasmoutput);
  1051. var
  1052. stab_str : pchar;
  1053. begin
  1054. if (stab_state in [stab_state_writing,stab_state_written]) then
  1055. exit;
  1056. If cs_gdb_dbx in aktglobalswitches then
  1057. begin
  1058. { otherwise you get two of each def }
  1059. If assigned(typesym) then
  1060. begin
  1061. if (ttypesym(typesym).owner = nil) or
  1062. ((ttypesym(typesym).owner.symtabletype = globalsymtable) and
  1063. tglobalsymtable(ttypesym(typesym).owner).dbx_count_ok) then
  1064. begin
  1065. {with DBX we get the definition from the other objects }
  1066. stab_state := stab_state_written;
  1067. exit;
  1068. end;
  1069. end;
  1070. end;
  1071. { to avoid infinite loops }
  1072. stab_state := stab_state_writing;
  1073. stab_str := allstabstring;
  1074. asmList.concat(Tai_stabs.Create(stab_str));
  1075. stab_state := stab_state_written;
  1076. end;
  1077. {$endif GDB}
  1078. procedure tstoreddef.write_rtti_name;
  1079. var
  1080. str : string;
  1081. begin
  1082. { name }
  1083. if assigned(typesym) then
  1084. begin
  1085. str:=ttypesym(typesym).realname;
  1086. rttiList.concat(Tai_string.Create(chr(length(str))+str));
  1087. end
  1088. else
  1089. rttiList.concat(Tai_string.Create(#0))
  1090. end;
  1091. procedure tstoreddef.write_rtti_data(rt:trttitype);
  1092. begin
  1093. rttilist.concat(tai_const.create_8bit(tkUnknown));
  1094. write_rtti_name;
  1095. end;
  1096. procedure tstoreddef.write_child_rtti_data(rt:trttitype);
  1097. begin
  1098. end;
  1099. function tstoreddef.get_rtti_label(rt:trttitype) : tasmsymbol;
  1100. begin
  1101. { try to reuse persistent rtti data }
  1102. if (rt=fullrtti) and (df_has_rttitable in defoptions) then
  1103. get_rtti_label:=trttisym(rttitablesym).get_label
  1104. else
  1105. if (rt=initrtti) and (df_has_inittable in defoptions) then
  1106. get_rtti_label:=trttisym(inittablesym).get_label
  1107. else
  1108. begin
  1109. if not assigned(localrttilab[rt]) then
  1110. begin
  1111. objectlibrary.getdatalabel(localrttilab[rt]);
  1112. write_child_rtti_data(rt);
  1113. maybe_new_object_file(rttiList);
  1114. new_section(rttiList,sec_rodata,localrttilab[rt].name,const_align(sizeof(aint)));
  1115. rttiList.concat(Tai_symbol.Create_global(localrttilab[rt],0));
  1116. write_rtti_data(rt);
  1117. rttiList.concat(Tai_symbol_end.Create(localrttilab[rt]));
  1118. end;
  1119. get_rtti_label:=localrttilab[rt];
  1120. end;
  1121. end;
  1122. { returns true, if the definition can be published }
  1123. function tstoreddef.is_publishable : boolean;
  1124. begin
  1125. is_publishable:=false;
  1126. end;
  1127. { needs an init table }
  1128. function tstoreddef.needs_inittable : boolean;
  1129. begin
  1130. needs_inittable:=false;
  1131. end;
  1132. function tstoreddef.is_intregable : boolean;
  1133. begin
  1134. is_intregable:=false;
  1135. case deftype of
  1136. pointerdef,
  1137. enumdef:
  1138. is_intregable:=true;
  1139. procvardef :
  1140. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  1141. orddef :
  1142. case torddef(self).typ of
  1143. bool8bit,bool16bit,bool32bit,
  1144. u8bit,u16bit,u32bit,
  1145. s8bit,s16bit,s32bit,
  1146. uchar, uwidechar:
  1147. is_intregable:=true;
  1148. end;
  1149. objectdef:
  1150. is_intregable:=is_class(self) or is_interface(self);
  1151. setdef:
  1152. is_intregable:=(tsetdef(self).settype=smallset);
  1153. end;
  1154. end;
  1155. function tstoreddef.is_fpuregable : boolean;
  1156. begin
  1157. {$ifdef x86}
  1158. result:=false;
  1159. {$else x86}
  1160. result:=(deftype=floatdef);
  1161. {$endif x86}
  1162. end;
  1163. {****************************************************************************
  1164. Tstringdef
  1165. ****************************************************************************}
  1166. constructor tstringdef.createshort(l : byte);
  1167. begin
  1168. inherited create;
  1169. string_typ:=st_shortstring;
  1170. deftype:=stringdef;
  1171. len:=l;
  1172. savesize:=len+1;
  1173. end;
  1174. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1175. begin
  1176. inherited ppuloaddef(ppufile);
  1177. string_typ:=st_shortstring;
  1178. deftype:=stringdef;
  1179. len:=ppufile.getbyte;
  1180. savesize:=len+1;
  1181. end;
  1182. constructor tstringdef.createlong(l : aint);
  1183. begin
  1184. inherited create;
  1185. string_typ:=st_longstring;
  1186. deftype:=stringdef;
  1187. len:=l;
  1188. savesize:=sizeof(aint);
  1189. end;
  1190. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1191. begin
  1192. inherited ppuloaddef(ppufile);
  1193. deftype:=stringdef;
  1194. string_typ:=st_longstring;
  1195. len:=ppufile.getaint;
  1196. savesize:=sizeof(aint);
  1197. end;
  1198. {$ifdef ansistring_bits}
  1199. constructor tstringdef.createansi(l:aint;bits:Tstringbits);
  1200. begin
  1201. inherited create;
  1202. case bits of
  1203. sb_16:
  1204. string_typ:=st_ansistring16;
  1205. sb_32:
  1206. string_typ:=st_ansistring32;
  1207. sb_64:
  1208. string_typ:=st_ansistring64;
  1209. end;
  1210. deftype:=stringdef;
  1211. len:=l;
  1212. savesize:=POINTER_SIZE;
  1213. end;
  1214. constructor tstringdef.loadansi(ppufile:tcompilerppufile;bits:Tstringbits);
  1215. begin
  1216. inherited ppuloaddef(ppufile);
  1217. deftype:=stringdef;
  1218. case bits of
  1219. sb_16:
  1220. string_typ:=st_ansistring16;
  1221. sb_32:
  1222. string_typ:=st_ansistring32;
  1223. sb_64:
  1224. string_typ:=st_ansistring64;
  1225. end;
  1226. len:=ppufile.getaint;
  1227. savesize:=POINTER_SIZE;
  1228. end;
  1229. {$else}
  1230. constructor tstringdef.createansi(l:aint);
  1231. begin
  1232. inherited create;
  1233. string_typ:=st_ansistring;
  1234. deftype:=stringdef;
  1235. len:=l;
  1236. savesize:=sizeof(aint);
  1237. end;
  1238. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1239. begin
  1240. inherited ppuloaddef(ppufile);
  1241. deftype:=stringdef;
  1242. string_typ:=st_ansistring;
  1243. len:=ppufile.getaint;
  1244. savesize:=sizeof(aint);
  1245. end;
  1246. {$endif}
  1247. constructor tstringdef.createwide(l : aint);
  1248. begin
  1249. inherited create;
  1250. string_typ:=st_widestring;
  1251. deftype:=stringdef;
  1252. len:=l;
  1253. savesize:=sizeof(aint);
  1254. end;
  1255. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1256. begin
  1257. inherited ppuloaddef(ppufile);
  1258. deftype:=stringdef;
  1259. string_typ:=st_widestring;
  1260. len:=ppufile.getaint;
  1261. savesize:=sizeof(aint);
  1262. end;
  1263. function tstringdef.getcopy : tstoreddef;
  1264. begin
  1265. result:=tstringdef.create;
  1266. result.deftype:=stringdef;
  1267. tstringdef(result).string_typ:=string_typ;
  1268. tstringdef(result).len:=len;
  1269. tstringdef(result).savesize:=savesize;
  1270. end;
  1271. function tstringdef.stringtypname:string;
  1272. {$ifdef ansistring_bits}
  1273. const
  1274. typname:array[tstringtype] of string[9]=('',
  1275. 'shortstr','longstr','ansistr16','ansistr32','ansistr64','widestr'
  1276. );
  1277. {$else}
  1278. const
  1279. typname:array[tstringtype] of string[8]=('',
  1280. 'shortstr','longstr','ansistr','widestr'
  1281. );
  1282. {$endif}
  1283. begin
  1284. stringtypname:=typname[string_typ];
  1285. end;
  1286. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1287. begin
  1288. inherited ppuwritedef(ppufile);
  1289. if string_typ=st_shortstring then
  1290. begin
  1291. {$ifdef extdebug}
  1292. if len > 255 then internalerror(12122002);
  1293. {$endif}
  1294. ppufile.putbyte(byte(len))
  1295. end
  1296. else
  1297. ppufile.putaint(len);
  1298. case string_typ of
  1299. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1300. st_longstring : ppufile.writeentry(iblongstringdef);
  1301. {$ifdef ansistring_bits}
  1302. st_ansistring16 : ppufile.writeentry(ibansistring16def);
  1303. st_ansistring32 : ppufile.writeentry(ibansistring32def);
  1304. st_ansistring64 : ppufile.writeentry(ibansistring64def);
  1305. {$else}
  1306. st_ansistring : ppufile.writeentry(ibansistringdef);
  1307. {$endif}
  1308. st_widestring : ppufile.writeentry(ibwidestringdef);
  1309. end;
  1310. end;
  1311. {$ifdef GDB}
  1312. function tstringdef.stabstring : pchar;
  1313. var
  1314. bytest,charst,longst : string;
  1315. slen : aint;
  1316. begin
  1317. case string_typ of
  1318. st_shortstring:
  1319. begin
  1320. charst:=tstoreddef(cchartype.def).numberstring;
  1321. { this is what I found in stabs.texinfo but
  1322. gdb 4.12 for go32 doesn't understand that !! }
  1323. {$IfDef GDBknowsstrings}
  1324. stabstring:=stabstr_evaluate('n$1;$2',[charst,tostr(len)]);
  1325. {$else}
  1326. { fix length of openshortstring }
  1327. slen:=len;
  1328. if slen=0 then
  1329. slen:=255;
  1330. bytest:=tstoreddef(u8inttype.def).numberstring;
  1331. stabstring:=stabstr_evaluate('s$1length:$2,0,8;st:ar$2;1;$3;$4,8,$5;;',
  1332. [tostr(slen+1),bytest,tostr(slen),charst,tostr(slen*8)]);
  1333. {$EndIf}
  1334. end;
  1335. st_longstring:
  1336. begin
  1337. charst:=tstoreddef(cchartype.def).numberstring;
  1338. { this is what I found in stabs.texinfo but
  1339. gdb 4.12 for go32 doesn't understand that !! }
  1340. {$IfDef GDBknowsstrings}
  1341. stabstring:=stabstr_evaluate('n$1;$2',[charst,tostr(len)]);
  1342. {$else}
  1343. bytest:=tstoreddef(u8inttype.def).numberstring;
  1344. longst:=tstoreddef(u32inttype.def).numberstring;
  1345. stabstring:=stabstr_evaluate('s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  1346. [tostr(len+5),longst,tostr(len),charst,tostr(len*8),bytest]);
  1347. {$EndIf}
  1348. end;
  1349. {$ifdef ansistring_bits}
  1350. st_ansistring16,st_ansistring32,st_ansistring64:
  1351. {$else}
  1352. st_ansistring:
  1353. {$endif}
  1354. begin
  1355. { an ansi string looks like a pchar easy !! }
  1356. charst:=tstoreddef(cchartype.def).numberstring;
  1357. stabstring:=strpnew('*'+charst);
  1358. end;
  1359. st_widestring:
  1360. begin
  1361. { an ansi string looks like a pwidechar easy !! }
  1362. charst:=tstoreddef(cwidechartype.def).numberstring;
  1363. stabstring:=strpnew('*'+charst);
  1364. end;
  1365. end;
  1366. end;
  1367. procedure tstringdef.concatstabto(asmlist:taasmoutput);
  1368. begin
  1369. if (stab_state in [stab_state_writing,stab_state_written]) then
  1370. exit;
  1371. case string_typ of
  1372. st_shortstring:
  1373. begin
  1374. tstoreddef(cchartype.def).concatstabto(asmlist);
  1375. {$IfNDef GDBknowsstrings}
  1376. tstoreddef(u8inttype.def).concatstabto(asmlist);
  1377. {$EndIf}
  1378. end;
  1379. st_longstring:
  1380. begin
  1381. tstoreddef(cchartype.def).concatstabto(asmlist);
  1382. {$IfNDef GDBknowsstrings}
  1383. tstoreddef(u8inttype.def).concatstabto(asmlist);
  1384. tstoreddef(u32inttype.def).concatstabto(asmlist);
  1385. {$EndIf}
  1386. end;
  1387. {$ifdef ansistring_bits}
  1388. st_ansistring16,st_ansistring32,st_ansistring64:
  1389. {$else}
  1390. st_ansistring:
  1391. {$endif}
  1392. tstoreddef(cchartype.def).concatstabto(asmlist);
  1393. st_widestring:
  1394. tstoreddef(cwidechartype.def).concatstabto(asmlist);
  1395. end;
  1396. inherited concatstabto(asmlist);
  1397. end;
  1398. {$endif GDB}
  1399. function tstringdef.needs_inittable : boolean;
  1400. begin
  1401. {$ifdef ansistring_bits}
  1402. needs_inittable:=string_typ in [st_ansistring16,st_ansistring32,st_ansistring64,st_widestring];
  1403. {$else}
  1404. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  1405. {$endif}
  1406. end;
  1407. function tstringdef.gettypename : string;
  1408. {$ifdef ansistring_bits}
  1409. const
  1410. names : array[tstringtype] of string[20] = ('',
  1411. 'shortstring','longstring','ansistring16','ansistring32','ansistring64','widestring');
  1412. {$else}
  1413. const
  1414. names : array[tstringtype] of string[20] = ('',
  1415. 'ShortString','LongString','AnsiString','WideString');
  1416. {$endif}
  1417. begin
  1418. gettypename:=names[string_typ];
  1419. end;
  1420. procedure tstringdef.write_rtti_data(rt:trttitype);
  1421. begin
  1422. case string_typ of
  1423. {$ifdef ansistring_bits}
  1424. st_ansistring16:
  1425. begin
  1426. rttiList.concat(Tai_const.Create_8bit(tkA16String));
  1427. write_rtti_name;
  1428. end;
  1429. st_ansistring32:
  1430. begin
  1431. rttiList.concat(Tai_const.Create_8bit(tkA32String));
  1432. write_rtti_name;
  1433. end;
  1434. st_ansistring64:
  1435. begin
  1436. rttiList.concat(Tai_const.Create_8bit(tkA64String));
  1437. write_rtti_name;
  1438. end;
  1439. {$else}
  1440. st_ansistring:
  1441. begin
  1442. rttiList.concat(Tai_const.Create_8bit(tkAString));
  1443. write_rtti_name;
  1444. end;
  1445. {$endif}
  1446. st_widestring:
  1447. begin
  1448. rttiList.concat(Tai_const.Create_8bit(tkWString));
  1449. write_rtti_name;
  1450. end;
  1451. st_longstring:
  1452. begin
  1453. rttiList.concat(Tai_const.Create_8bit(tkLString));
  1454. write_rtti_name;
  1455. end;
  1456. st_shortstring:
  1457. begin
  1458. rttiList.concat(Tai_const.Create_8bit(tkSString));
  1459. write_rtti_name;
  1460. rttiList.concat(Tai_const.Create_8bit(len));
  1461. end;
  1462. end;
  1463. end;
  1464. function tstringdef.getmangledparaname : string;
  1465. begin
  1466. getmangledparaname:='STRING';
  1467. end;
  1468. function tstringdef.is_publishable : boolean;
  1469. begin
  1470. is_publishable:=true;
  1471. end;
  1472. {****************************************************************************
  1473. TENUMDEF
  1474. ****************************************************************************}
  1475. constructor tenumdef.create;
  1476. begin
  1477. inherited create;
  1478. deftype:=enumdef;
  1479. minval:=0;
  1480. maxval:=0;
  1481. calcsavesize;
  1482. has_jumps:=false;
  1483. basedef:=nil;
  1484. firstenum:=nil;
  1485. correct_owner_symtable;
  1486. end;
  1487. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:aint);
  1488. begin
  1489. inherited create;
  1490. deftype:=enumdef;
  1491. minval:=_min;
  1492. maxval:=_max;
  1493. basedef:=_basedef;
  1494. calcsavesize;
  1495. has_jumps:=false;
  1496. firstenum:=basedef.firstenum;
  1497. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1498. firstenum:=tenumsym(firstenum).nextenum;
  1499. correct_owner_symtable;
  1500. end;
  1501. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1502. begin
  1503. inherited ppuloaddef(ppufile);
  1504. deftype:=enumdef;
  1505. ppufile.getderef(basedefderef);
  1506. minval:=ppufile.getaint;
  1507. maxval:=ppufile.getaint;
  1508. savesize:=ppufile.getaint;
  1509. has_jumps:=false;
  1510. firstenum:=Nil;
  1511. end;
  1512. procedure tenumdef.calcsavesize;
  1513. begin
  1514. if (aktpackenum=8) or (min<low(longint)) or (max>high(cardinal)) then
  1515. savesize:=8
  1516. else
  1517. if (aktpackenum=4) or (min<low(smallint)) or (max>high(word)) then
  1518. savesize:=4
  1519. else
  1520. if (aktpackenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1521. savesize:=2
  1522. else
  1523. savesize:=1;
  1524. end;
  1525. procedure tenumdef.setmax(_max:aint);
  1526. begin
  1527. maxval:=_max;
  1528. calcsavesize;
  1529. end;
  1530. procedure tenumdef.setmin(_min:aint);
  1531. begin
  1532. minval:=_min;
  1533. calcsavesize;
  1534. end;
  1535. function tenumdef.min:aint;
  1536. begin
  1537. min:=minval;
  1538. end;
  1539. function tenumdef.max:aint;
  1540. begin
  1541. max:=maxval;
  1542. end;
  1543. procedure tenumdef.buildderef;
  1544. begin
  1545. inherited buildderef;
  1546. basedefderef.build(basedef);
  1547. end;
  1548. procedure tenumdef.deref;
  1549. begin
  1550. inherited deref;
  1551. basedef:=tenumdef(basedefderef.resolve);
  1552. { restart ordering }
  1553. firstenum:=nil;
  1554. end;
  1555. destructor tenumdef.destroy;
  1556. begin
  1557. inherited destroy;
  1558. end;
  1559. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1560. begin
  1561. inherited ppuwritedef(ppufile);
  1562. ppufile.putderef(basedefderef);
  1563. ppufile.putaint(min);
  1564. ppufile.putaint(max);
  1565. ppufile.putaint(savesize);
  1566. ppufile.writeentry(ibenumdef);
  1567. end;
  1568. { used for enumdef because the symbols are
  1569. inserted in the owner symtable }
  1570. procedure tenumdef.correct_owner_symtable;
  1571. var
  1572. st : tsymtable;
  1573. begin
  1574. if assigned(owner) and
  1575. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  1576. begin
  1577. owner.defindex.deleteindex(self);
  1578. st:=owner;
  1579. while (st.symtabletype in [recordsymtable,objectsymtable]) do
  1580. st:=st.next;
  1581. st.registerdef(self);
  1582. end;
  1583. end;
  1584. {$ifdef GDB}
  1585. function tenumdef.stabstring : pchar;
  1586. var st:Pchar;
  1587. p:Tenumsym;
  1588. s:string;
  1589. memsize,stl:cardinal;
  1590. begin
  1591. memsize:=memsizeinc;
  1592. getmem(st,memsize);
  1593. { we can specify the size with @s<size>; prefix PM }
  1594. if savesize <> std_param_align then
  1595. strpcopy(st,'@s'+tostr(savesize*8)+';e')
  1596. else
  1597. strpcopy(st,'e');
  1598. p := tenumsym(firstenum);
  1599. stl:=strlen(st);
  1600. while assigned(p) do
  1601. begin
  1602. s :=p.name+':'+tostr(p.value)+',';
  1603. { place for the ending ';' also }
  1604. if (stl+length(s)+1>=memsize) then
  1605. begin
  1606. inc(memsize,memsizeinc);
  1607. reallocmem(st,memsize);
  1608. end;
  1609. strpcopy(st+stl,s);
  1610. inc(stl,length(s));
  1611. p:=p.nextenum;
  1612. end;
  1613. st[stl]:=';';
  1614. st[stl+1]:=#0;
  1615. reallocmem(st,stl+2);
  1616. stabstring:=st;
  1617. end;
  1618. {$endif GDB}
  1619. procedure tenumdef.write_child_rtti_data(rt:trttitype);
  1620. begin
  1621. if assigned(basedef) then
  1622. basedef.get_rtti_label(rt);
  1623. end;
  1624. procedure tenumdef.write_rtti_data(rt:trttitype);
  1625. var
  1626. hp : tenumsym;
  1627. begin
  1628. rttiList.concat(Tai_const.Create_8bit(tkEnumeration));
  1629. write_rtti_name;
  1630. case longint(savesize) of
  1631. 1:
  1632. rttiList.concat(Tai_const.Create_8bit(otUByte));
  1633. 2:
  1634. rttiList.concat(Tai_const.Create_8bit(otUWord));
  1635. 4:
  1636. rttiList.concat(Tai_const.Create_8bit(otULong));
  1637. end;
  1638. rttiList.concat(Tai_const.Create_32bit(min));
  1639. rttiList.concat(Tai_const.Create_32bit(max));
  1640. if assigned(basedef) then
  1641. rttiList.concat(Tai_const.Create_sym(basedef.get_rtti_label(rt)))
  1642. else
  1643. rttiList.concat(Tai_const.create_sym(nil));
  1644. hp:=tenumsym(firstenum);
  1645. while assigned(hp) do
  1646. begin
  1647. rttiList.concat(Tai_const.Create_8bit(length(hp.realname)));
  1648. rttiList.concat(Tai_string.Create(hp.realname));
  1649. hp:=hp.nextenum;
  1650. end;
  1651. rttiList.concat(Tai_const.Create_8bit(0));
  1652. end;
  1653. function tenumdef.is_publishable : boolean;
  1654. begin
  1655. is_publishable:=true;
  1656. end;
  1657. function tenumdef.gettypename : string;
  1658. begin
  1659. gettypename:='<enumeration type>';
  1660. end;
  1661. {****************************************************************************
  1662. TORDDEF
  1663. ****************************************************************************}
  1664. constructor torddef.create(t : tbasetype;v,b : TConstExprInt);
  1665. begin
  1666. inherited create;
  1667. deftype:=orddef;
  1668. low:=v;
  1669. high:=b;
  1670. typ:=t;
  1671. setsize;
  1672. end;
  1673. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1674. begin
  1675. inherited ppuloaddef(ppufile);
  1676. deftype:=orddef;
  1677. typ:=tbasetype(ppufile.getbyte);
  1678. if sizeof(TConstExprInt)=8 then
  1679. begin
  1680. low:=ppufile.getint64;
  1681. high:=ppufile.getint64;
  1682. end
  1683. else
  1684. begin
  1685. low:=ppufile.getlongint;
  1686. high:=ppufile.getlongint;
  1687. end;
  1688. setsize;
  1689. end;
  1690. function torddef.getcopy : tstoreddef;
  1691. begin
  1692. result:=torddef.create(typ,low,high);
  1693. result.deftype:=orddef;
  1694. torddef(result).low:=low;
  1695. torddef(result).high:=high;
  1696. torddef(result).typ:=typ;
  1697. torddef(result).savesize:=savesize;
  1698. end;
  1699. procedure torddef.setsize;
  1700. const
  1701. sizetbl : array[tbasetype] of longint = (
  1702. 0,
  1703. 1,2,4,8,
  1704. 1,2,4,8,
  1705. 1,2,4,
  1706. 1,2,8
  1707. );
  1708. begin
  1709. savesize:=sizetbl[typ];
  1710. end;
  1711. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1712. begin
  1713. inherited ppuwritedef(ppufile);
  1714. ppufile.putbyte(byte(typ));
  1715. if sizeof(TConstExprInt)=8 then
  1716. begin
  1717. ppufile.putint64(low);
  1718. ppufile.putint64(high);
  1719. end
  1720. else
  1721. begin
  1722. ppufile.putlongint(low);
  1723. ppufile.putlongint(high);
  1724. end;
  1725. ppufile.writeentry(iborddef);
  1726. end;
  1727. {$ifdef GDB}
  1728. function torddef.stabstring : pchar;
  1729. begin
  1730. if cs_gdb_valgrind in aktglobalswitches then
  1731. begin
  1732. case typ of
  1733. uvoid :
  1734. stabstring := strpnew(numberstring);
  1735. bool8bit,
  1736. bool16bit,
  1737. bool32bit :
  1738. stabstring := stabstr_evaluate('r${numberstring};0;255;',[]);
  1739. u32bit,
  1740. s64bit,
  1741. u64bit :
  1742. stabstring:=stabstr_evaluate('r${numberstring};0;-1;',[]);
  1743. else
  1744. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1745. end;
  1746. end
  1747. else
  1748. begin
  1749. case typ of
  1750. uvoid :
  1751. stabstring := strpnew(numberstring);
  1752. uchar :
  1753. stabstring := strpnew('-20;');
  1754. uwidechar :
  1755. stabstring := strpnew('-30;');
  1756. bool8bit :
  1757. stabstring := strpnew('-21;');
  1758. bool16bit :
  1759. stabstring := strpnew('-22;');
  1760. bool32bit :
  1761. stabstring := strpnew('-23;');
  1762. u64bit :
  1763. stabstring := strpnew('-32;');
  1764. s64bit :
  1765. stabstring := strpnew('-31;');
  1766. {u32bit : stabstring := tstoreddef(s32inttype.def).numberstring+';0;-1;'); }
  1767. else
  1768. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1769. end;
  1770. end;
  1771. end;
  1772. {$endif GDB}
  1773. procedure torddef.write_rtti_data(rt:trttitype);
  1774. procedure dointeger;
  1775. const
  1776. trans : array[tbasetype] of byte =
  1777. (otUByte{otNone},
  1778. otUByte,otUWord,otULong,otUByte{otNone},
  1779. otSByte,otSWord,otSLong,otUByte{otNone},
  1780. otUByte,otUWord,otULong,
  1781. otUByte,otUWord,otUByte);
  1782. begin
  1783. write_rtti_name;
  1784. rttiList.concat(Tai_const.Create_8bit(byte(trans[typ])));
  1785. rttiList.concat(Tai_const.Create_32bit(longint(low)));
  1786. rttiList.concat(Tai_const.Create_32bit(longint(high)));
  1787. end;
  1788. begin
  1789. case typ of
  1790. s64bit :
  1791. begin
  1792. rttiList.concat(Tai_const.Create_8bit(tkInt64));
  1793. write_rtti_name;
  1794. { low }
  1795. rttiList.concat(Tai_const.Create_64bit(int64($80000000) shl 32));
  1796. { high }
  1797. rttiList.concat(Tai_const.Create_64bit((int64($7fffffff) shl 32) or int64($ffffffff)));
  1798. end;
  1799. u64bit :
  1800. begin
  1801. rttiList.concat(Tai_const.Create_8bit(tkQWord));
  1802. write_rtti_name;
  1803. { low }
  1804. rttiList.concat(Tai_const.Create_64bit(0));
  1805. { high }
  1806. rttiList.concat(Tai_const.Create_64bit(int64((int64($ffffffff) shl 32) or int64($ffffffff))));
  1807. end;
  1808. bool8bit:
  1809. begin
  1810. rttiList.concat(Tai_const.Create_8bit(tkBool));
  1811. dointeger;
  1812. end;
  1813. uchar:
  1814. begin
  1815. rttiList.concat(Tai_const.Create_8bit(tkChar));
  1816. dointeger;
  1817. end;
  1818. uwidechar:
  1819. begin
  1820. rttiList.concat(Tai_const.Create_8bit(tkWChar));
  1821. dointeger;
  1822. end;
  1823. else
  1824. begin
  1825. rttiList.concat(Tai_const.Create_8bit(tkInteger));
  1826. dointeger;
  1827. end;
  1828. end;
  1829. end;
  1830. function torddef.is_publishable : boolean;
  1831. begin
  1832. is_publishable:=(typ<>uvoid);
  1833. end;
  1834. function torddef.gettypename : string;
  1835. const
  1836. names : array[tbasetype] of string[20] = (
  1837. 'untyped',
  1838. 'Byte','Word','DWord','QWord',
  1839. 'ShortInt','SmallInt','LongInt','Int64',
  1840. 'Boolean','WordBool','LongBool',
  1841. 'Char','WideChar','Currency');
  1842. begin
  1843. gettypename:=names[typ];
  1844. end;
  1845. {****************************************************************************
  1846. TFLOATDEF
  1847. ****************************************************************************}
  1848. constructor tfloatdef.create(t : tfloattype);
  1849. begin
  1850. inherited create;
  1851. deftype:=floatdef;
  1852. typ:=t;
  1853. setsize;
  1854. end;
  1855. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1856. begin
  1857. inherited ppuloaddef(ppufile);
  1858. deftype:=floatdef;
  1859. typ:=tfloattype(ppufile.getbyte);
  1860. setsize;
  1861. end;
  1862. function tfloatdef.getcopy : tstoreddef;
  1863. begin
  1864. result:=tfloatdef.create(typ);
  1865. result.deftype:=floatdef;
  1866. tfloatdef(result).savesize:=savesize;
  1867. end;
  1868. procedure tfloatdef.setsize;
  1869. begin
  1870. case typ of
  1871. s32real : savesize:=4;
  1872. s80real : savesize:=10;
  1873. s64real,
  1874. s64currency,
  1875. s64comp : savesize:=8;
  1876. else
  1877. savesize:=0;
  1878. end;
  1879. end;
  1880. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1881. begin
  1882. inherited ppuwritedef(ppufile);
  1883. ppufile.putbyte(byte(typ));
  1884. ppufile.writeentry(ibfloatdef);
  1885. end;
  1886. {$ifdef GDB}
  1887. function Tfloatdef.stabstring:Pchar;
  1888. begin
  1889. case typ of
  1890. s32real,s64real:
  1891. { found this solution in stabsread.c from GDB v4.16 }
  1892. stabstring:=stabstr_evaluate('r$1;${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1893. s64currency,s64comp:
  1894. stabstring:=stabstr_evaluate('r$1;-${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1895. s80real:
  1896. { under dos at least you must give a size of twelve instead of 10 !! }
  1897. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  1898. stabstring:=stabstr_evaluate('r$1;12;0;',[tstoreddef(s32inttype.def).numberstring]);
  1899. else
  1900. internalerror(10005);
  1901. end;
  1902. end;
  1903. procedure tfloatdef.concatstabto(asmlist:taasmoutput);
  1904. begin
  1905. if (stab_state in [stab_state_writing,stab_state_written]) then
  1906. exit;
  1907. tstoreddef(s32inttype.def).concatstabto(asmlist);
  1908. inherited concatstabto(asmlist);
  1909. end;
  1910. {$endif GDB}
  1911. procedure tfloatdef.write_rtti_data(rt:trttitype);
  1912. const
  1913. {tfloattype = (s32real,s64real,s80real,s64bit,s128bit);}
  1914. translate : array[tfloattype] of byte =
  1915. (ftSingle,ftDouble,ftExtended,ftComp,ftCurr,ftFloat128);
  1916. begin
  1917. rttiList.concat(Tai_const.Create_8bit(tkFloat));
  1918. write_rtti_name;
  1919. rttiList.concat(Tai_const.Create_8bit(translate[typ]));
  1920. end;
  1921. function tfloatdef.is_publishable : boolean;
  1922. begin
  1923. is_publishable:=true;
  1924. end;
  1925. function tfloatdef.gettypename : string;
  1926. const
  1927. names : array[tfloattype] of string[20] = (
  1928. 'Single','Double','Extended','Comp','Currency','Float128');
  1929. begin
  1930. gettypename:=names[typ];
  1931. end;
  1932. {****************************************************************************
  1933. TFILEDEF
  1934. ****************************************************************************}
  1935. constructor tfiledef.createtext;
  1936. begin
  1937. inherited create;
  1938. deftype:=filedef;
  1939. filetyp:=ft_text;
  1940. typedfiletype.reset;
  1941. setsize;
  1942. end;
  1943. constructor tfiledef.createuntyped;
  1944. begin
  1945. inherited create;
  1946. deftype:=filedef;
  1947. filetyp:=ft_untyped;
  1948. typedfiletype.reset;
  1949. setsize;
  1950. end;
  1951. constructor tfiledef.createtyped(const tt : ttype);
  1952. begin
  1953. inherited create;
  1954. deftype:=filedef;
  1955. filetyp:=ft_typed;
  1956. typedfiletype:=tt;
  1957. setsize;
  1958. end;
  1959. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1960. begin
  1961. inherited ppuloaddef(ppufile);
  1962. deftype:=filedef;
  1963. filetyp:=tfiletyp(ppufile.getbyte);
  1964. if filetyp=ft_typed then
  1965. ppufile.gettype(typedfiletype)
  1966. else
  1967. typedfiletype.reset;
  1968. setsize;
  1969. end;
  1970. procedure tfiledef.buildderef;
  1971. begin
  1972. inherited buildderef;
  1973. if filetyp=ft_typed then
  1974. typedfiletype.buildderef;
  1975. end;
  1976. procedure tfiledef.deref;
  1977. begin
  1978. inherited deref;
  1979. if filetyp=ft_typed then
  1980. typedfiletype.resolve;
  1981. end;
  1982. procedure tfiledef.setsize;
  1983. begin
  1984. {$ifdef cpu64bit}
  1985. case filetyp of
  1986. ft_text :
  1987. savesize:=612;
  1988. ft_typed,
  1989. ft_untyped :
  1990. savesize:=352;
  1991. end;
  1992. {$else cpu64bit}
  1993. case filetyp of
  1994. ft_text :
  1995. savesize:=576;
  1996. ft_typed,
  1997. ft_untyped :
  1998. savesize:=316;
  1999. end;
  2000. {$endif cpu64bit}
  2001. end;
  2002. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  2003. begin
  2004. inherited ppuwritedef(ppufile);
  2005. ppufile.putbyte(byte(filetyp));
  2006. if filetyp=ft_typed then
  2007. ppufile.puttype(typedfiletype);
  2008. ppufile.writeentry(ibfiledef);
  2009. end;
  2010. {$ifdef GDB}
  2011. function tfiledef.stabstring : pchar;
  2012. begin
  2013. {$IfDef GDBknowsfiles}
  2014. case filetyp of
  2015. ft_typed :
  2016. stabstring := strpnew('d'+typedfiletype.def.numberstring{+';'});
  2017. ft_untyped :
  2018. stabstring := strpnew('d'+voiddef.numberstring{+';'});
  2019. ft_text :
  2020. stabstring := strpnew('d'+cchartype^.numberstring{+';'});
  2021. end;
  2022. {$Else}
  2023. {$ifdef cpu64bit}
  2024. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$2,64,64;'+
  2025. '_PRIVATE:ar$1;1;64;$3,128,256;USERDATA:ar$1;1;16;$3,384,128;'+
  2026. 'NAME:ar$1;0;255;$4,512,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2027. tstoreddef(s64inttype.def).numberstring,
  2028. tstoreddef(u8inttype.def).numberstring,
  2029. tstoreddef(cchartype.def).numberstring]);
  2030. {$else cpu64bit}
  2031. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$1,64,32;'+
  2032. '_PRIVATE:ar$1;1;32;$3,96,256;USERDATA:ar$1;1;16;$2,352,128;'+
  2033. 'NAME:ar$1;0;255;$3,480,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2034. tstoreddef(u8inttype.def).numberstring,
  2035. tstoreddef(cchartype.def).numberstring]);
  2036. {$endif cpu64bit}
  2037. {$EndIf}
  2038. end;
  2039. procedure tfiledef.concatstabto(asmlist:taasmoutput);
  2040. begin
  2041. if (stab_state in [stab_state_writing,stab_state_written]) then
  2042. exit;
  2043. {$IfDef GDBknowsfiles}
  2044. case filetyp of
  2045. ft_typed :
  2046. tstoreddef(typedfiletype.def).concatstabto(asmlist);
  2047. ft_untyped :
  2048. tstoreddef(voidtype.def).concatstabto(asmlist);
  2049. ft_text :
  2050. tstoreddef(cchartype.def).concatstabto(asmlist);
  2051. end;
  2052. {$Else}
  2053. tstoreddef(s32inttype.def).concatstabto(asmlist);
  2054. {$ifdef cpu64bit}
  2055. tstoreddef(s64inttype.def).concatstabto(asmlist);
  2056. {$endif cpu64bit}
  2057. tstoreddef(u8inttype.def).concatstabto(asmlist);
  2058. tstoreddef(cchartype.def).concatstabto(asmlist);
  2059. {$EndIf}
  2060. inherited concatstabto(asmlist);
  2061. end;
  2062. {$endif GDB}
  2063. function tfiledef.gettypename : string;
  2064. begin
  2065. case filetyp of
  2066. ft_untyped:
  2067. gettypename:='File';
  2068. ft_typed:
  2069. gettypename:='File Of '+typedfiletype.def.typename;
  2070. ft_text:
  2071. gettypename:='Text'
  2072. end;
  2073. end;
  2074. function tfiledef.getmangledparaname : string;
  2075. begin
  2076. case filetyp of
  2077. ft_untyped:
  2078. getmangledparaname:='FILE';
  2079. ft_typed:
  2080. getmangledparaname:='FILE$OF$'+typedfiletype.def.mangledparaname;
  2081. ft_text:
  2082. getmangledparaname:='TEXT'
  2083. end;
  2084. end;
  2085. {****************************************************************************
  2086. TVARIANTDEF
  2087. ****************************************************************************}
  2088. constructor tvariantdef.create(v : tvarianttype);
  2089. begin
  2090. inherited create;
  2091. varianttype:=v;
  2092. deftype:=variantdef;
  2093. setsize;
  2094. end;
  2095. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2096. begin
  2097. inherited ppuloaddef(ppufile);
  2098. varianttype:=tvarianttype(ppufile.getbyte);
  2099. deftype:=variantdef;
  2100. setsize;
  2101. end;
  2102. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2103. begin
  2104. inherited ppuwritedef(ppufile);
  2105. ppufile.putbyte(byte(varianttype));
  2106. ppufile.writeentry(ibvariantdef);
  2107. end;
  2108. procedure tvariantdef.setsize;
  2109. begin
  2110. savesize:=16;
  2111. end;
  2112. function tvariantdef.gettypename : string;
  2113. begin
  2114. case varianttype of
  2115. vt_normalvariant:
  2116. gettypename:='Variant';
  2117. vt_olevariant:
  2118. gettypename:='OleVariant';
  2119. end;
  2120. end;
  2121. procedure tvariantdef.write_rtti_data(rt:trttitype);
  2122. begin
  2123. rttiList.concat(Tai_const.Create_8bit(tkVariant));
  2124. end;
  2125. function tvariantdef.needs_inittable : boolean;
  2126. begin
  2127. needs_inittable:=true;
  2128. end;
  2129. {$ifdef GDB}
  2130. function tvariantdef.stabstring : pchar;
  2131. begin
  2132. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2133. end;
  2134. function tvariantdef.numberstring:string;
  2135. begin
  2136. result:=tstoreddef(voidtype.def).numberstring;
  2137. end;
  2138. procedure tvariantdef.concatstabto(asmlist : taasmoutput);
  2139. begin
  2140. { don't know how to handle this }
  2141. end;
  2142. {$endif GDB}
  2143. {****************************************************************************
  2144. TPOINTERDEF
  2145. ****************************************************************************}
  2146. constructor tpointerdef.create(const tt : ttype);
  2147. begin
  2148. inherited create;
  2149. deftype:=pointerdef;
  2150. pointertype:=tt;
  2151. is_far:=false;
  2152. savesize:=sizeof(aint);
  2153. end;
  2154. constructor tpointerdef.createfar(const tt : ttype);
  2155. begin
  2156. inherited create;
  2157. deftype:=pointerdef;
  2158. pointertype:=tt;
  2159. is_far:=true;
  2160. savesize:=sizeof(aint);
  2161. end;
  2162. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2163. begin
  2164. inherited ppuloaddef(ppufile);
  2165. deftype:=pointerdef;
  2166. ppufile.gettype(pointertype);
  2167. is_far:=(ppufile.getbyte<>0);
  2168. savesize:=sizeof(aint);
  2169. end;
  2170. function tpointerdef.getcopy : tstoreddef;
  2171. begin
  2172. result:=tpointerdef.create(pointertype);
  2173. tpointerdef(result).is_far:=is_far;
  2174. tpointerdef(result).savesize:=savesize;
  2175. end;
  2176. procedure tpointerdef.buildderef;
  2177. begin
  2178. inherited buildderef;
  2179. pointertype.buildderef;
  2180. end;
  2181. procedure tpointerdef.deref;
  2182. begin
  2183. inherited deref;
  2184. pointertype.resolve;
  2185. end;
  2186. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2187. begin
  2188. inherited ppuwritedef(ppufile);
  2189. ppufile.puttype(pointertype);
  2190. ppufile.putbyte(byte(is_far));
  2191. ppufile.writeentry(ibpointerdef);
  2192. end;
  2193. {$ifdef GDB}
  2194. function tpointerdef.stabstring : pchar;
  2195. begin
  2196. stabstring := strpnew('*'+tstoreddef(pointertype.def).numberstring);
  2197. end;
  2198. procedure tpointerdef.concatstabto(asmlist : taasmoutput);
  2199. var st,nb : string;
  2200. begin
  2201. if (stab_state in [stab_state_writing,stab_state_written]) then
  2202. exit;
  2203. stab_state:=stab_state_writing;
  2204. tstoreddef(pointertype.def).concatstabto(asmlist);
  2205. if (pointertype.def.deftype in [recorddef,objectdef]) then
  2206. begin
  2207. if pointertype.def.deftype=objectdef then
  2208. nb:=tobjectdef(pointertype.def).classnumberstring
  2209. else
  2210. nb:=tstoreddef(pointertype.def).numberstring;
  2211. {to avoid infinite recursion in record with next-like fields }
  2212. if tstoreddef(pointertype.def).stab_state=stab_state_writing then
  2213. begin
  2214. if assigned(pointertype.def.typesym) then
  2215. begin
  2216. if assigned(typesym) then
  2217. st := ttypesym(typesym).name
  2218. else
  2219. st := ' ';
  2220. asmlist.concat(Tai_stabs.create(stabstr_evaluate(
  2221. '"$1:t${numberstring}=*$2=xs$3:",${N_LSYM},0,0,0',
  2222. [st,nb,pointertype.def.typesym.name])));
  2223. end;
  2224. stab_state:=stab_state_written;
  2225. end
  2226. else
  2227. begin
  2228. stab_state:=stab_state_used;
  2229. inherited concatstabto(asmlist);
  2230. end;
  2231. end
  2232. else
  2233. begin
  2234. stab_state:=stab_state_used;
  2235. inherited concatstabto(asmlist);
  2236. end;
  2237. end;
  2238. {$endif GDB}
  2239. function tpointerdef.gettypename : string;
  2240. begin
  2241. if is_far then
  2242. gettypename:='^'+pointertype.def.typename+';far'
  2243. else
  2244. gettypename:='^'+pointertype.def.typename;
  2245. end;
  2246. {****************************************************************************
  2247. TCLASSREFDEF
  2248. ****************************************************************************}
  2249. constructor tclassrefdef.create(const t:ttype);
  2250. begin
  2251. inherited create(t);
  2252. deftype:=classrefdef;
  2253. end;
  2254. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2255. begin
  2256. { be careful, tclassdefref inherits from tpointerdef }
  2257. inherited ppuloaddef(ppufile);
  2258. deftype:=classrefdef;
  2259. ppufile.gettype(pointertype);
  2260. is_far:=false;
  2261. savesize:=sizeof(aint);
  2262. end;
  2263. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2264. begin
  2265. { be careful, tclassdefref inherits from tpointerdef }
  2266. inherited ppuwritedef(ppufile);
  2267. ppufile.puttype(pointertype);
  2268. ppufile.writeentry(ibclassrefdef);
  2269. end;
  2270. {$ifdef GDB}
  2271. function tclassrefdef.stabstring : pchar;
  2272. begin
  2273. stabstring:=strpnew(tstoreddef(pvmttype.def).numberstring);
  2274. end;
  2275. {$endif GDB}
  2276. function tclassrefdef.gettypename : string;
  2277. begin
  2278. gettypename:='Class Of '+pointertype.def.typename;
  2279. end;
  2280. {***************************************************************************
  2281. TSETDEF
  2282. ***************************************************************************}
  2283. constructor tsetdef.create(const t:ttype;high : longint);
  2284. begin
  2285. inherited create;
  2286. deftype:=setdef;
  2287. elementtype:=t;
  2288. if high<32 then
  2289. begin
  2290. settype:=smallset;
  2291. {$ifdef testvarsets}
  2292. if aktsetalloc=0 THEN { $PACKSET Fixed?}
  2293. {$endif}
  2294. savesize:=Sizeof(longint)
  2295. {$ifdef testvarsets}
  2296. else {No, use $PACKSET VALUE for rounding}
  2297. savesize:=aktsetalloc*((high+aktsetalloc*8-1) DIV (aktsetalloc*8))
  2298. {$endif}
  2299. ;
  2300. end
  2301. else
  2302. if high<256 then
  2303. begin
  2304. settype:=normset;
  2305. savesize:=32;
  2306. end
  2307. else
  2308. {$ifdef testvarsets}
  2309. if high<$10000 then
  2310. begin
  2311. settype:=varset;
  2312. savesize:=4*((high+31) div 32);
  2313. end
  2314. else
  2315. {$endif testvarsets}
  2316. Message(sym_e_ill_type_decl_set);
  2317. end;
  2318. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2319. begin
  2320. inherited ppuloaddef(ppufile);
  2321. deftype:=setdef;
  2322. ppufile.gettype(elementtype);
  2323. settype:=tsettype(ppufile.getbyte);
  2324. case settype of
  2325. normset : savesize:=32;
  2326. varset : savesize:=ppufile.getlongint;
  2327. smallset : savesize:=Sizeof(longint);
  2328. end;
  2329. end;
  2330. destructor tsetdef.destroy;
  2331. begin
  2332. inherited destroy;
  2333. end;
  2334. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2335. begin
  2336. inherited ppuwritedef(ppufile);
  2337. ppufile.puttype(elementtype);
  2338. ppufile.putbyte(byte(settype));
  2339. if settype=varset then
  2340. ppufile.putlongint(savesize);
  2341. ppufile.writeentry(ibsetdef);
  2342. end;
  2343. {$ifdef GDB}
  2344. function tsetdef.stabstring : pchar;
  2345. begin
  2346. stabstring:=stabstr_evaluate('@s$1;S$2',[tostr(savesize*8),tstoreddef(elementtype.def).numberstring]);
  2347. end;
  2348. procedure tsetdef.concatstabto(asmlist:taasmoutput);
  2349. begin
  2350. if (stab_state in [stab_state_writing,stab_state_written]) then
  2351. exit;
  2352. tstoreddef(elementtype.def).concatstabto(asmlist);
  2353. inherited concatstabto(asmlist);
  2354. end;
  2355. {$endif GDB}
  2356. procedure tsetdef.buildderef;
  2357. begin
  2358. inherited buildderef;
  2359. elementtype.buildderef;
  2360. end;
  2361. procedure tsetdef.deref;
  2362. begin
  2363. inherited deref;
  2364. elementtype.resolve;
  2365. end;
  2366. procedure tsetdef.write_child_rtti_data(rt:trttitype);
  2367. begin
  2368. tstoreddef(elementtype.def).get_rtti_label(rt);
  2369. end;
  2370. procedure tsetdef.write_rtti_data(rt:trttitype);
  2371. begin
  2372. rttiList.concat(Tai_const.Create_8bit(tkSet));
  2373. write_rtti_name;
  2374. rttiList.concat(Tai_const.Create_8bit(otULong));
  2375. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2376. end;
  2377. function tsetdef.is_publishable : boolean;
  2378. begin
  2379. is_publishable:=(settype=smallset);
  2380. end;
  2381. function tsetdef.gettypename : string;
  2382. begin
  2383. if assigned(elementtype.def) then
  2384. gettypename:='Set Of '+elementtype.def.typename
  2385. else
  2386. gettypename:='Empty Set';
  2387. end;
  2388. {***************************************************************************
  2389. TFORMALDEF
  2390. ***************************************************************************}
  2391. constructor tformaldef.create;
  2392. var
  2393. stregdef : boolean;
  2394. begin
  2395. stregdef:=registerdef;
  2396. registerdef:=false;
  2397. inherited create;
  2398. deftype:=formaldef;
  2399. registerdef:=stregdef;
  2400. { formaldef must be registered at unit level !! }
  2401. if registerdef and assigned(current_module) then
  2402. if assigned(current_module.localsymtable) then
  2403. tsymtable(current_module.localsymtable).registerdef(self)
  2404. else if assigned(current_module.globalsymtable) then
  2405. tsymtable(current_module.globalsymtable).registerdef(self);
  2406. savesize:=0;
  2407. end;
  2408. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2409. begin
  2410. inherited ppuloaddef(ppufile);
  2411. deftype:=formaldef;
  2412. savesize:=0;
  2413. end;
  2414. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2415. begin
  2416. inherited ppuwritedef(ppufile);
  2417. ppufile.writeentry(ibformaldef);
  2418. end;
  2419. {$ifdef GDB}
  2420. function tformaldef.stabstring : pchar;
  2421. begin
  2422. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2423. end;
  2424. function tformaldef.numberstring:string;
  2425. begin
  2426. result:=tstoreddef(voidtype.def).numberstring;
  2427. end;
  2428. procedure tformaldef.concatstabto(asmlist : taasmoutput);
  2429. begin
  2430. { formaldef can't be stab'ed !}
  2431. end;
  2432. {$endif GDB}
  2433. function tformaldef.gettypename : string;
  2434. begin
  2435. gettypename:='<Formal type>';
  2436. end;
  2437. {***************************************************************************
  2438. TARRAYDEF
  2439. ***************************************************************************}
  2440. constructor tarraydef.create(l,h : aint;const t : ttype);
  2441. begin
  2442. inherited create;
  2443. deftype:=arraydef;
  2444. lowrange:=l;
  2445. highrange:=h;
  2446. rangetype:=t;
  2447. elementtype.reset;
  2448. IsVariant:=false;
  2449. IsConstructor:=false;
  2450. IsArrayOfConst:=false;
  2451. IsDynamicArray:=false;
  2452. IsConvertedPointer:=false;
  2453. end;
  2454. constructor tarraydef.create_from_pointer(const elemt : ttype);
  2455. begin
  2456. self.create(0,$7fffffff,s32inttype);
  2457. IsConvertedPointer:=true;
  2458. setelementtype(elemt);
  2459. end;
  2460. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2461. begin
  2462. inherited ppuloaddef(ppufile);
  2463. deftype:=arraydef;
  2464. { the addresses are calculated later }
  2465. ppufile.gettype(_elementtype);
  2466. ppufile.gettype(rangetype);
  2467. lowrange:=ppufile.getaint;
  2468. highrange:=ppufile.getaint;
  2469. IsArrayOfConst:=boolean(ppufile.getbyte);
  2470. IsDynamicArray:=boolean(ppufile.getbyte);
  2471. IsVariant:=false;
  2472. IsConstructor:=false;
  2473. end;
  2474. procedure tarraydef.buildderef;
  2475. begin
  2476. inherited buildderef;
  2477. _elementtype.buildderef;
  2478. rangetype.buildderef;
  2479. end;
  2480. procedure tarraydef.deref;
  2481. begin
  2482. inherited deref;
  2483. _elementtype.resolve;
  2484. rangetype.resolve;
  2485. end;
  2486. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2487. begin
  2488. inherited ppuwritedef(ppufile);
  2489. ppufile.puttype(_elementtype);
  2490. ppufile.puttype(rangetype);
  2491. ppufile.putaint(lowrange);
  2492. ppufile.putaint(highrange);
  2493. ppufile.putbyte(byte(IsArrayOfConst));
  2494. ppufile.putbyte(byte(IsDynamicArray));
  2495. ppufile.writeentry(ibarraydef);
  2496. end;
  2497. {$ifdef GDB}
  2498. function tarraydef.stabstring : pchar;
  2499. begin
  2500. stabstring:=stabstr_evaluate('ar$1;$2;$3;$4',[Tstoreddef(rangetype.def).numberstring,
  2501. tostr(lowrange),tostr(highrange),Tstoreddef(_elementtype.def).numberstring]);
  2502. end;
  2503. procedure tarraydef.concatstabto(asmlist:taasmoutput);
  2504. begin
  2505. if (stab_state in [stab_state_writing,stab_state_written]) then
  2506. exit;
  2507. tstoreddef(rangetype.def).concatstabto(asmlist);
  2508. tstoreddef(_elementtype.def).concatstabto(asmlist);
  2509. inherited concatstabto(asmlist);
  2510. end;
  2511. {$endif GDB}
  2512. function tarraydef.elesize : aint;
  2513. begin
  2514. elesize:=_elementtype.def.size;
  2515. end;
  2516. function tarraydef.elecount : aint;
  2517. {$ifdef cpu64bit}
  2518. var
  2519. qhigh,qlow : qword;
  2520. {$endif cpu64bit}
  2521. begin
  2522. if IsDynamicArray then
  2523. begin
  2524. result:=0;
  2525. exit;
  2526. end;
  2527. {$ifdef cpu64bit}
  2528. if (highrange>0) and (lowrange<0) then
  2529. begin
  2530. qhigh:=highrange;
  2531. qlow:=qword(-lowrange);
  2532. { prevent overflow, return -1 to indicate overflow }
  2533. if qhigh+qlow>qword(high(aint)-1) then
  2534. result:=-1
  2535. else
  2536. result:=qhigh+qlow+1;
  2537. end
  2538. else
  2539. {$endif cpu64bit}
  2540. result:=int64(highrange)-lowrange+1;
  2541. end;
  2542. function tarraydef.size : aint;
  2543. var
  2544. cachedelecount,
  2545. cachedelesize : aint;
  2546. begin
  2547. if IsDynamicArray then
  2548. begin
  2549. size:=sizeof(aint);
  2550. exit;
  2551. end;
  2552. { Tarraydef.size may never be called for an open array! }
  2553. if highrange<lowrange then
  2554. internalerror(99080501);
  2555. cachedelesize:=elesize;
  2556. cachedelecount:=elecount;
  2557. { prevent overflow, return -1 to indicate overflow }
  2558. if (cachedelesize <> 0) and
  2559. (
  2560. (cachedelecount < 0) or
  2561. ((high(aint) div cachedelesize) < cachedelecount) or
  2562. { also lowrange*elesize must be < high(aint) to prevent overflow when
  2563. accessing the array, see ncgmem (PFV) }
  2564. ((high(aint) div cachedelesize) < abs(lowrange))
  2565. ) then
  2566. result:=-1
  2567. else
  2568. result:=cachedelesize*cachedelecount;
  2569. end;
  2570. procedure tarraydef.setelementtype(t: ttype);
  2571. begin
  2572. _elementtype:=t;
  2573. if not(IsDynamicArray or
  2574. IsConvertedPointer or
  2575. (highrange<lowrange)) then
  2576. begin
  2577. if (size=-1) then
  2578. Message(sym_e_segment_too_large);
  2579. end;
  2580. end;
  2581. function tarraydef.alignment : longint;
  2582. begin
  2583. { alignment is the size of the elements }
  2584. if elementtype.def.deftype=recorddef then
  2585. alignment:=elementtype.def.alignment
  2586. else
  2587. alignment:=elesize;
  2588. end;
  2589. function tarraydef.needs_inittable : boolean;
  2590. begin
  2591. needs_inittable:=IsDynamicArray or elementtype.def.needs_inittable;
  2592. end;
  2593. procedure tarraydef.write_child_rtti_data(rt:trttitype);
  2594. begin
  2595. tstoreddef(elementtype.def).get_rtti_label(rt);
  2596. end;
  2597. procedure tarraydef.write_rtti_data(rt:trttitype);
  2598. begin
  2599. if IsDynamicArray then
  2600. rttiList.concat(Tai_const.Create_8bit(tkdynarray))
  2601. else
  2602. rttiList.concat(Tai_const.Create_8bit(tkarray));
  2603. write_rtti_name;
  2604. {$ifdef cpurequiresproperalignment}
  2605. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2606. {$endif cpurequiresproperalignment}
  2607. { size of elements }
  2608. rttiList.concat(Tai_const.Create_aint(elesize));
  2609. if not(IsDynamicArray) then
  2610. rttiList.concat(Tai_const.Create_aint(elecount));
  2611. { element type }
  2612. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2613. { variant type }
  2614. // !!!!!!!!!!!!!!!!
  2615. end;
  2616. function tarraydef.gettypename : string;
  2617. begin
  2618. if isarrayofconst or isConstructor then
  2619. begin
  2620. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2621. gettypename:='Array Of Const'
  2622. else
  2623. gettypename:='Array Of '+elementtype.def.typename;
  2624. end
  2625. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2626. gettypename:='Array Of '+elementtype.def.typename
  2627. else
  2628. begin
  2629. if rangetype.def.deftype=enumdef then
  2630. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2631. else
  2632. gettypename:='Array['+tostr(lowrange)+'..'+
  2633. tostr(highrange)+'] Of '+elementtype.def.typename
  2634. end;
  2635. end;
  2636. function tarraydef.getmangledparaname : string;
  2637. begin
  2638. if isarrayofconst then
  2639. getmangledparaname:='array_of_const'
  2640. else
  2641. if ((highrange=-1) and (lowrange=0)) then
  2642. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2643. else
  2644. internalerror(200204176);
  2645. end;
  2646. {***************************************************************************
  2647. tabstractrecorddef
  2648. ***************************************************************************}
  2649. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2650. begin
  2651. if t=gs_record then
  2652. getsymtable:=symtable
  2653. else
  2654. getsymtable:=nil;
  2655. end;
  2656. {$ifdef GDB}
  2657. procedure tabstractrecorddef.field_addname(p:Tnamedindexitem;arg:pointer);
  2658. var
  2659. newrec:Pchar;
  2660. spec:string[3];
  2661. varsize : aint;
  2662. state : ^Trecord_stabgen_state;
  2663. begin
  2664. state:=arg;
  2665. { static variables from objects are like global objects }
  2666. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2667. begin
  2668. if (sp_protected in tsym(p).symoptions) then
  2669. spec:='/1'
  2670. else if (sp_private in tsym(p).symoptions) then
  2671. spec:='/0'
  2672. else
  2673. spec:='';
  2674. varsize:=tvarsym(p).vartype.def.size;
  2675. { open arrays made overflows !! }
  2676. if varsize>$fffffff then
  2677. varsize:=$fffffff;
  2678. newrec:=stabstr_evaluate('$1:$2,$3,$4;',[p.name,
  2679. spec+tstoreddef(tvarsym(p).vartype.def).numberstring,
  2680. tostr(tvarsym(p).fieldoffset*8),tostr(varsize*8)]);
  2681. if state^.stabsize+strlen(newrec)>=state^.staballoc-256 then
  2682. begin
  2683. inc(state^.staballoc,memsizeinc);
  2684. reallocmem(state^.stabstring,state^.staballoc);
  2685. end;
  2686. strcopy(state^.stabstring+state^.stabsize,newrec);
  2687. inc(state^.stabsize,strlen(newrec));
  2688. strdispose(newrec);
  2689. {This should be used for case !!}
  2690. inc(state^.recoffset,Tvarsym(p).vartype.def.size);
  2691. end;
  2692. end;
  2693. procedure tabstractrecorddef.field_concatstabto(p:Tnamedindexitem;arg:pointer);
  2694. begin
  2695. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2696. tstoreddef(tvarsym(p).vartype.def).concatstabto(taasmoutput(arg));
  2697. end;
  2698. {$endif GDB}
  2699. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2700. begin
  2701. if (FRTTIType=fullrtti) or
  2702. ((tsym(sym).typ=varsym) and
  2703. tvarsym(sym).vartype.def.needs_inittable) then
  2704. inc(Count);
  2705. end;
  2706. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2707. begin
  2708. if (FRTTIType=fullrtti) or
  2709. ((tsym(sym).typ=varsym) and
  2710. tvarsym(sym).vartype.def.needs_inittable) then
  2711. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2712. end;
  2713. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2714. begin
  2715. if (FRTTIType=fullrtti) or
  2716. ((tsym(sym).typ=varsym) and
  2717. tvarsym(sym).vartype.def.needs_inittable) then
  2718. begin
  2719. rttiList.concat(Tai_const.Create_sym(tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2720. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  2721. end;
  2722. end;
  2723. {***************************************************************************
  2724. trecorddef
  2725. ***************************************************************************}
  2726. constructor trecorddef.create(p : tsymtable);
  2727. begin
  2728. inherited create;
  2729. deftype:=recorddef;
  2730. symtable:=p;
  2731. symtable.defowner:=self;
  2732. isunion:=false;
  2733. end;
  2734. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2735. begin
  2736. inherited ppuloaddef(ppufile);
  2737. deftype:=recorddef;
  2738. symtable:=trecordsymtable.create(0);
  2739. trecordsymtable(symtable).datasize:=ppufile.getaint;
  2740. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2741. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2742. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2743. trecordsymtable(symtable).ppuload(ppufile);
  2744. symtable.defowner:=self;
  2745. isunion:=false;
  2746. end;
  2747. destructor trecorddef.destroy;
  2748. begin
  2749. if assigned(symtable) then
  2750. symtable.free;
  2751. inherited destroy;
  2752. end;
  2753. function trecorddef.needs_inittable : boolean;
  2754. begin
  2755. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2756. end;
  2757. procedure trecorddef.buildderef;
  2758. var
  2759. oldrecsyms : tsymtable;
  2760. begin
  2761. inherited buildderef;
  2762. oldrecsyms:=aktrecordsymtable;
  2763. aktrecordsymtable:=symtable;
  2764. { now build the definitions }
  2765. tstoredsymtable(symtable).buildderef;
  2766. aktrecordsymtable:=oldrecsyms;
  2767. end;
  2768. procedure trecorddef.deref;
  2769. var
  2770. oldrecsyms : tsymtable;
  2771. begin
  2772. inherited deref;
  2773. oldrecsyms:=aktrecordsymtable;
  2774. aktrecordsymtable:=symtable;
  2775. { now dereference the definitions }
  2776. tstoredsymtable(symtable).deref;
  2777. aktrecordsymtable:=oldrecsyms;
  2778. { assign TGUID? load only from system unit (unitid=1) }
  2779. if not(assigned(rec_tguid)) and
  2780. (upper(typename)='TGUID') and
  2781. assigned(owner) and
  2782. assigned(owner.name) and
  2783. (owner.name^='SYSTEM') then
  2784. rec_tguid:=self;
  2785. end;
  2786. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2787. begin
  2788. inherited ppuwritedef(ppufile);
  2789. ppufile.putaint(trecordsymtable(symtable).datasize);
  2790. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2791. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2792. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2793. ppufile.writeentry(ibrecorddef);
  2794. trecordsymtable(symtable).ppuwrite(ppufile);
  2795. end;
  2796. function trecorddef.size:aint;
  2797. begin
  2798. result:=trecordsymtable(symtable).datasize;
  2799. end;
  2800. function trecorddef.alignment:longint;
  2801. begin
  2802. alignment:=trecordsymtable(symtable).recordalignment;
  2803. end;
  2804. function trecorddef.padalignment:longint;
  2805. begin
  2806. padalignment := trecordsymtable(symtable).padalignment;
  2807. end;
  2808. {$ifdef GDB}
  2809. function trecorddef.stabstring : pchar;
  2810. var
  2811. state:Trecord_stabgen_state;
  2812. begin
  2813. getmem(state.stabstring,memsizeinc);
  2814. state.staballoc:=memsizeinc;
  2815. strpcopy(state.stabstring,'s'+tostr(size));
  2816. state.recoffset:=0;
  2817. state.stabsize:=strlen(state.stabstring);
  2818. symtable.foreach(@field_addname,@state);
  2819. state.stabstring[state.stabsize]:=';';
  2820. state.stabstring[state.stabsize+1]:=#0;
  2821. reallocmem(state.stabstring,state.stabsize+2);
  2822. stabstring:=state.stabstring;
  2823. end;
  2824. procedure trecorddef.concatstabto(asmlist:taasmoutput);
  2825. begin
  2826. if (stab_state in [stab_state_writing,stab_state_written]) then
  2827. exit;
  2828. symtable.foreach(@field_concatstabto,asmlist);
  2829. inherited concatstabto(asmlist);
  2830. end;
  2831. {$endif GDB}
  2832. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2833. begin
  2834. FRTTIType:=rt;
  2835. symtable.foreach(@generate_field_rtti,nil);
  2836. end;
  2837. procedure trecorddef.write_rtti_data(rt:trttitype);
  2838. begin
  2839. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2840. write_rtti_name;
  2841. {$ifdef cpurequiresproperalignment}
  2842. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2843. {$endif cpurequiresproperalignment}
  2844. rttiList.concat(Tai_const.Create_32bit(size));
  2845. Count:=0;
  2846. FRTTIType:=rt;
  2847. symtable.foreach(@count_field_rtti,nil);
  2848. rttiList.concat(Tai_const.Create_32bit(Count));
  2849. symtable.foreach(@write_field_rtti,nil);
  2850. end;
  2851. function trecorddef.gettypename : string;
  2852. begin
  2853. gettypename:='<record type>'
  2854. end;
  2855. {***************************************************************************
  2856. TABSTRACTPROCDEF
  2857. ***************************************************************************}
  2858. constructor tabstractprocdef.create(level:byte);
  2859. begin
  2860. inherited create;
  2861. parast:=tparasymtable.create(level);
  2862. parast.defowner:=self;
  2863. parast.next:=owner;
  2864. para:=TLinkedList.Create;
  2865. minparacount:=0;
  2866. maxparacount:=0;
  2867. proctypeoption:=potype_none;
  2868. proccalloption:=pocall_none;
  2869. procoptions:=[];
  2870. rettype:=voidtype;
  2871. {$ifdef i386}
  2872. fpu_used:=0;
  2873. {$endif i386}
  2874. savesize:=sizeof(aint);
  2875. requiredargarea:=0;
  2876. has_paraloc_info:=false;
  2877. funcret_paraloc[callerside].init;
  2878. funcret_paraloc[calleeside].init;
  2879. end;
  2880. destructor tabstractprocdef.destroy;
  2881. begin
  2882. if assigned(para) then
  2883. begin
  2884. {$ifdef MEMDEBUG}
  2885. memprocpara.start;
  2886. {$endif MEMDEBUG}
  2887. para.free;
  2888. {$ifdef MEMDEBUG}
  2889. memprocpara.stop;
  2890. {$endif MEMDEBUG}
  2891. end;
  2892. if assigned(parast) then
  2893. begin
  2894. {$ifdef MEMDEBUG}
  2895. memprocparast.start;
  2896. {$endif MEMDEBUG}
  2897. parast.free;
  2898. {$ifdef MEMDEBUG}
  2899. memprocparast.stop;
  2900. {$endif MEMDEBUG}
  2901. end;
  2902. funcret_paraloc[callerside].done;
  2903. funcret_paraloc[calleeside].done;
  2904. inherited destroy;
  2905. end;
  2906. procedure tabstractprocdef.releasemem;
  2907. begin
  2908. para.free;
  2909. para:=nil;
  2910. parast.free;
  2911. parast:=nil;
  2912. end;
  2913. function tabstractprocdef.concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2914. var
  2915. hp : TParaItem;
  2916. begin
  2917. hp:=TParaItem.Create;
  2918. hp.paratyp:=tvarsym(sym).varspez;
  2919. hp.parasym:=sym;
  2920. hp.paratype:=tt;
  2921. hp.is_hidden:=vhidden;
  2922. hp.defaultvalue:=defval;
  2923. { Parameters are stored from left to right }
  2924. if assigned(afterpara) then
  2925. Para.insertafter(hp,afterpara)
  2926. else
  2927. Para.concat(hp);
  2928. { Don't count hidden parameters }
  2929. if not vhidden then
  2930. begin
  2931. if not assigned(defval) then
  2932. inc(minparacount);
  2933. inc(maxparacount);
  2934. end;
  2935. concatpara:=hp;
  2936. end;
  2937. function tabstractprocdef.insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2938. var
  2939. hp : TParaItem;
  2940. begin
  2941. hp:=TParaItem.Create;
  2942. hp.paratyp:=tvarsym(sym).varspez;
  2943. hp.parasym:=sym;
  2944. hp.paratype:=tt;
  2945. hp.is_hidden:=vhidden;
  2946. hp.defaultvalue:=defval;
  2947. { Parameters are stored from left to right }
  2948. Para.insert(hp);
  2949. { Don't count hidden parameters }
  2950. if (not vhidden) then
  2951. begin
  2952. if not assigned(defval) then
  2953. inc(minparacount);
  2954. inc(maxparacount);
  2955. end;
  2956. insertpara:=hp;
  2957. end;
  2958. procedure tabstractprocdef.removepara(currpara:tparaitem);
  2959. begin
  2960. { Don't count hidden parameters }
  2961. if (not currpara.is_hidden) then
  2962. begin
  2963. if not assigned(currpara.defaultvalue) then
  2964. dec(minparacount);
  2965. dec(maxparacount);
  2966. end;
  2967. Para.Remove(currpara);
  2968. currpara.free;
  2969. end;
  2970. { all functions returning in FPU are
  2971. assume to use 2 FPU registers
  2972. until the function implementation
  2973. is processed PM }
  2974. procedure tabstractprocdef.test_if_fpu_result;
  2975. begin
  2976. {$ifdef i386}
  2977. if assigned(rettype.def) and
  2978. (rettype.def.deftype=floatdef) then
  2979. fpu_used:=maxfpuregs;
  2980. {$endif i386}
  2981. end;
  2982. procedure tabstractprocdef.buildderef;
  2983. var
  2984. hp : TParaItem;
  2985. begin
  2986. { released procdef? }
  2987. if not assigned(parast) then
  2988. exit;
  2989. inherited buildderef;
  2990. rettype.buildderef;
  2991. { parast }
  2992. tparasymtable(parast).buildderef;
  2993. { paraitems }
  2994. hp:=TParaItem(Para.first);
  2995. while assigned(hp) do
  2996. begin
  2997. hp.paratype.buildderef;
  2998. hp.defaultvaluederef.build(hp.defaultvalue);
  2999. hp.parasymderef.build(hp.parasym);
  3000. hp:=TParaItem(hp.next);
  3001. end;
  3002. end;
  3003. procedure tabstractprocdef.deref;
  3004. var
  3005. hp : TParaItem;
  3006. begin
  3007. inherited deref;
  3008. rettype.resolve;
  3009. { parast }
  3010. tparasymtable(parast).deref;
  3011. { paraitems }
  3012. minparacount:=0;
  3013. maxparacount:=0;
  3014. hp:=TParaItem(Para.first);
  3015. while assigned(hp) do
  3016. begin
  3017. hp.paratype.resolve;
  3018. hp.defaultvalue:=tsym(hp.defaultvaluederef.resolve);
  3019. hp.parasym:=tvarsym(hp.parasymderef.resolve);
  3020. { connect parasym to paraitem }
  3021. tvarsym(hp.parasym).paraitem:=hp;
  3022. { Don't count hidden parameters }
  3023. if (not hp.is_hidden) then
  3024. begin
  3025. if not assigned(hp.defaultvalue) then
  3026. inc(minparacount);
  3027. inc(maxparacount);
  3028. end;
  3029. hp:=TParaItem(hp.next);
  3030. end;
  3031. end;
  3032. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  3033. var
  3034. hp : TParaItem;
  3035. count,i : word;
  3036. begin
  3037. inherited ppuloaddef(ppufile);
  3038. parast:=nil;
  3039. Para:=TLinkedList.Create;
  3040. minparacount:=0;
  3041. maxparacount:=0;
  3042. ppufile.gettype(rettype);
  3043. {$ifdef i386}
  3044. fpu_used:=ppufile.getbyte;
  3045. {$else}
  3046. ppufile.getbyte;
  3047. {$endif i386}
  3048. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3049. proccalloption:=tproccalloption(ppufile.getbyte);
  3050. ppufile.getsmallset(procoptions);
  3051. if po_explicitparaloc in procoptions then
  3052. ppufile.getdata(funcret_paraloc,sizeof(funcret_paraloc));
  3053. { get the number of parameters }
  3054. count:=ppufile.getbyte;
  3055. savesize:=sizeof(aint);
  3056. has_paraloc_info:=false;
  3057. for i:=1 to count do
  3058. begin
  3059. hp:=TParaItem.Create;
  3060. hp.paratyp:=tvarspez(ppufile.getbyte);
  3061. ppufile.gettype(hp.paratype);
  3062. ppufile.getderef(hp.defaultvaluederef);
  3063. hp.defaultvalue:=nil;
  3064. ppufile.getderef(hp.parasymderef);
  3065. hp.parasym:=nil;
  3066. hp.is_hidden:=boolean(ppufile.getbyte);
  3067. if po_explicitparaloc in procoptions then
  3068. begin
  3069. ppufile.getdata(hp.paraloc[callerside].add_location^,sizeof(hp.paraloc[callerside].location^));
  3070. has_paraloc_info:=true;
  3071. end;
  3072. { Parameters are stored left to right in both ppu and memory }
  3073. Para.concat(hp);
  3074. end;
  3075. end;
  3076. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3077. var
  3078. hp : TParaItem;
  3079. oldintfcrc : boolean;
  3080. begin
  3081. { released procdef? }
  3082. if not assigned(parast) then
  3083. exit;
  3084. inherited ppuwritedef(ppufile);
  3085. ppufile.puttype(rettype);
  3086. oldintfcrc:=ppufile.do_interface_crc;
  3087. ppufile.do_interface_crc:=false;
  3088. {$ifdef i386}
  3089. if simplify_ppu then
  3090. fpu_used:=0;
  3091. ppufile.putbyte(fpu_used);
  3092. {$else}
  3093. ppufile.putbyte(0);
  3094. {$endif}
  3095. ppufile.putbyte(ord(proctypeoption));
  3096. ppufile.putbyte(ord(proccalloption));
  3097. ppufile.putsmallset(procoptions);
  3098. ppufile.do_interface_crc:=oldintfcrc;
  3099. if po_explicitparaloc in procoptions then
  3100. ppufile.putdata(funcret_paraloc,sizeof(funcret_paraloc));
  3101. { we need to store the count including vs_hidden }
  3102. ppufile.putbyte(para.count);
  3103. hp:=TParaItem(Para.first);
  3104. while assigned(hp) do
  3105. begin
  3106. ppufile.putbyte(byte(hp.paratyp));
  3107. ppufile.puttype(hp.paratype);
  3108. ppufile.putderef(hp.defaultvaluederef);
  3109. ppufile.putderef(hp.parasymderef);
  3110. ppufile.putbyte(byte(hp.is_hidden));
  3111. if po_explicitparaloc in procoptions then
  3112. begin
  3113. hp.paraloc[callerside].check_simple_location;
  3114. ppufile.putdata(hp.paraloc[callerside].location^,sizeof(hp.paraloc[callerside].location^));
  3115. end;
  3116. hp:=TParaItem(hp.next);
  3117. end;
  3118. end;
  3119. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  3120. var
  3121. hs,s : string;
  3122. hp : TParaItem;
  3123. hpc : tconstsym;
  3124. first : boolean;
  3125. begin
  3126. hp:=TParaItem(Para.first);
  3127. s:='';
  3128. first:=true;
  3129. while assigned(hp) do
  3130. begin
  3131. if (not hp.is_hidden) or
  3132. (showhidden) then
  3133. begin
  3134. if first then
  3135. begin
  3136. s:=s+'(';
  3137. first:=false;
  3138. end
  3139. else
  3140. s:=s+',';
  3141. case hp.paratyp of
  3142. vs_var :
  3143. s:=s+'var';
  3144. vs_const :
  3145. s:=s+'const';
  3146. vs_out :
  3147. s:=s+'out';
  3148. end;
  3149. if assigned(hp.paratype.def.typesym) then
  3150. begin
  3151. if s<>'(' then
  3152. s:=s+' ';
  3153. hs:=hp.paratype.def.typesym.realname;
  3154. if hs[1]<>'$' then
  3155. s:=s+hp.paratype.def.typesym.realname
  3156. else
  3157. s:=s+hp.paratype.def.gettypename;
  3158. end
  3159. else
  3160. s:=s+hp.paratype.def.gettypename;
  3161. { default value }
  3162. if assigned(hp.defaultvalue) then
  3163. begin
  3164. hpc:=tconstsym(hp.defaultvalue);
  3165. hs:='';
  3166. case hpc.consttyp of
  3167. conststring,
  3168. constresourcestring :
  3169. hs:=strpas(pchar(hpc.value.valueptr));
  3170. constreal :
  3171. str(pbestreal(hpc.value.valueptr)^,hs);
  3172. constpointer :
  3173. hs:=tostr(hpc.value.valueordptr);
  3174. constord :
  3175. begin
  3176. if is_boolean(hpc.consttype.def) then
  3177. begin
  3178. if hpc.value.valueord<>0 then
  3179. hs:='TRUE'
  3180. else
  3181. hs:='FALSE';
  3182. end
  3183. else
  3184. hs:=tostr(hpc.value.valueord);
  3185. end;
  3186. constnil :
  3187. hs:='nil';
  3188. constset :
  3189. hs:='<set>';
  3190. end;
  3191. if hs<>'' then
  3192. s:=s+'="'+hs+'"';
  3193. end;
  3194. end;
  3195. hp:=TParaItem(hp.next);
  3196. end;
  3197. if not first then
  3198. s:=s+')';
  3199. if (po_varargs in procoptions) then
  3200. s:=s+';VarArgs';
  3201. typename_paras:=s;
  3202. end;
  3203. function tabstractprocdef.is_methodpointer:boolean;
  3204. begin
  3205. result:=false;
  3206. end;
  3207. function tabstractprocdef.is_addressonly:boolean;
  3208. begin
  3209. result:=true;
  3210. end;
  3211. {$ifdef GDB}
  3212. function tabstractprocdef.stabstring : pchar;
  3213. begin
  3214. stabstring := strpnew('abstractproc'+numberstring+';');
  3215. end;
  3216. {$endif GDB}
  3217. {***************************************************************************
  3218. TPROCDEF
  3219. ***************************************************************************}
  3220. constructor tprocdef.create(level:byte);
  3221. begin
  3222. inherited create(level);
  3223. deftype:=procdef;
  3224. has_mangledname:=false;
  3225. _mangledname:=nil;
  3226. fileinfo:=aktfilepos;
  3227. extnumber:=$ffff;
  3228. aliasnames:=tstringlist.create;
  3229. funcretsym:=nil;
  3230. localst := nil;
  3231. defref:=nil;
  3232. lastwritten:=nil;
  3233. refcount:=0;
  3234. if (cs_browser in aktmoduleswitches) and make_ref then
  3235. begin
  3236. defref:=tref.create(defref,@akttokenpos);
  3237. inc(refcount);
  3238. end;
  3239. lastref:=defref;
  3240. forwarddef:=true;
  3241. interfacedef:=false;
  3242. hasforward:=false;
  3243. _class := nil;
  3244. new(inlininginfo);
  3245. fillchar(inlininginfo^,sizeof(tinlininginfo),0);
  3246. overloadnumber:=0;
  3247. {$ifdef GDB}
  3248. isstabwritten := false;
  3249. {$endif GDB}
  3250. end;
  3251. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3252. var
  3253. level : byte;
  3254. begin
  3255. inherited ppuload(ppufile);
  3256. deftype:=procdef;
  3257. has_mangledname:=boolean(ppufile.getbyte);
  3258. if has_mangledname then
  3259. _mangledname:=stringdup(ppufile.getstring)
  3260. else
  3261. _mangledname:=nil;
  3262. overloadnumber:=ppufile.getword;
  3263. extnumber:=ppufile.getword;
  3264. level:=ppufile.getbyte;
  3265. ppufile.getderef(_classderef);
  3266. ppufile.getderef(procsymderef);
  3267. ppufile.getposinfo(fileinfo);
  3268. ppufile.getsmallset(symoptions);
  3269. {$ifdef powerpc}
  3270. { library symbol for AmigaOS/MorphOS }
  3271. ppufile.getderef(libsymderef);
  3272. {$endif powerpc}
  3273. { inline stuff }
  3274. if proccalloption=pocall_inline then
  3275. begin
  3276. ppufile.getderef(funcretsymderef);
  3277. new(inlininginfo);
  3278. ppufile.getsmallset(inlininginfo^.flags);
  3279. inlininginfo^.inlinenode:=boolean(ppufile.getbyte);
  3280. end
  3281. else
  3282. funcretsym:=nil;
  3283. { load para symtable }
  3284. parast:=tparasymtable.create(level);
  3285. tparasymtable(parast).ppuload(ppufile);
  3286. parast.defowner:=self;
  3287. { load local symtable }
  3288. if ((proccalloption=pocall_inline) or
  3289. ((current_module.flags and uf_local_browser)<>0)) then
  3290. begin
  3291. localst:=tlocalsymtable.create(level);
  3292. tlocalsymtable(localst).ppuload(ppufile);
  3293. localst.defowner:=self;
  3294. end
  3295. else
  3296. localst:=nil;
  3297. { inline stuff }
  3298. if proccalloption=pocall_inline then
  3299. inlininginfo^.code:=ppuloadnodetree(ppufile)
  3300. else
  3301. inlininginfo := nil;
  3302. { default values for no persistent data }
  3303. if (cs_link_deffile in aktglobalswitches) and
  3304. (tf_need_export in target_info.flags) and
  3305. (po_exports in procoptions) then
  3306. deffile.AddExport(mangledname);
  3307. aliasnames:=tstringlist.create;
  3308. forwarddef:=false;
  3309. interfacedef:=false;
  3310. hasforward:=false;
  3311. lastref:=nil;
  3312. lastwritten:=nil;
  3313. defref:=nil;
  3314. refcount:=0;
  3315. {$ifdef GDB}
  3316. isstabwritten := false;
  3317. {$endif GDB}
  3318. end;
  3319. destructor tprocdef.destroy;
  3320. begin
  3321. if assigned(defref) then
  3322. begin
  3323. defref.freechain;
  3324. defref.free;
  3325. end;
  3326. aliasnames.free;
  3327. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3328. begin
  3329. {$ifdef MEMDEBUG}
  3330. memproclocalst.start;
  3331. {$endif MEMDEBUG}
  3332. localst.free;
  3333. {$ifdef MEMDEBUG}
  3334. memproclocalst.start;
  3335. {$endif MEMDEBUG}
  3336. end;
  3337. if (proccalloption=pocall_inline) and assigned(inlininginfo) then
  3338. begin
  3339. {$ifdef MEMDEBUG}
  3340. memprocnodetree.start;
  3341. {$endif MEMDEBUG}
  3342. tnode(inlininginfo^.code).free;
  3343. {$ifdef MEMDEBUG}
  3344. memprocnodetree.start;
  3345. {$endif MEMDEBUG}
  3346. end;
  3347. if assigned(inlininginfo) then
  3348. dispose(inlininginfo);
  3349. if (po_msgstr in procoptions) then
  3350. strdispose(messageinf.str);
  3351. if assigned(_mangledname) then
  3352. begin
  3353. {$ifdef MEMDEBUG}
  3354. memmanglednames.start;
  3355. {$endif MEMDEBUG}
  3356. stringdispose(_mangledname);
  3357. {$ifdef MEMDEBUG}
  3358. memmanglednames.stop;
  3359. {$endif MEMDEBUG}
  3360. end;
  3361. inherited destroy;
  3362. end;
  3363. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3364. var
  3365. oldintfcrc : boolean;
  3366. oldparasymtable,
  3367. oldlocalsymtable : tsymtable;
  3368. begin
  3369. { released procdef? }
  3370. if not assigned(parast) then
  3371. exit;
  3372. oldparasymtable:=aktparasymtable;
  3373. oldlocalsymtable:=aktlocalsymtable;
  3374. aktparasymtable:=parast;
  3375. aktlocalsymtable:=localst;
  3376. inherited ppuwrite(ppufile);
  3377. oldintfcrc:=ppufile.do_interface_crc;
  3378. ppufile.do_interface_crc:=false;
  3379. ppufile.do_interface_crc:=oldintfcrc;
  3380. ppufile.putbyte(byte(has_mangledname));
  3381. if has_mangledname then
  3382. ppufile.putstring(_mangledname^);
  3383. ppufile.putword(overloadnumber);
  3384. ppufile.putword(extnumber);
  3385. ppufile.putbyte(parast.symtablelevel);
  3386. ppufile.putderef(_classderef);
  3387. ppufile.putderef(procsymderef);
  3388. ppufile.putposinfo(fileinfo);
  3389. ppufile.putsmallset(symoptions);
  3390. {$ifdef powerpc}
  3391. { library symbol for AmigaOS/MorphOS }
  3392. ppufile.putderef(libsymderef);
  3393. {$endif powerpc}
  3394. { inline stuff }
  3395. oldintfcrc:=ppufile.do_crc;
  3396. ppufile.do_crc:=false;
  3397. if proccalloption=pocall_inline then
  3398. begin
  3399. ppufile.putderef(funcretsymderef);
  3400. ppufile.putsmallset(inlininginfo^.flags);
  3401. ppufile.putbyte(byte(inlininginfo^.inlinenode));
  3402. end;
  3403. ppufile.do_crc:=oldintfcrc;
  3404. { write this entry }
  3405. ppufile.writeentry(ibprocdef);
  3406. { Save the para symtable, this is taken from the interface }
  3407. tparasymtable(parast).ppuwrite(ppufile);
  3408. { save localsymtable for inline procedures or when local
  3409. browser info is requested, this has no influence on the crc }
  3410. if (proccalloption=pocall_inline) or
  3411. ((current_module.flags and uf_local_browser)<>0) then
  3412. begin
  3413. { we must write a localsymtable }
  3414. if not assigned(localst) then
  3415. insert_localst;
  3416. oldintfcrc:=ppufile.do_crc;
  3417. ppufile.do_crc:=false;
  3418. tlocalsymtable(localst).ppuwrite(ppufile);
  3419. ppufile.do_crc:=oldintfcrc;
  3420. end;
  3421. { node tree for inlining }
  3422. oldintfcrc:=ppufile.do_crc;
  3423. ppufile.do_crc:=false;
  3424. if proccalloption=pocall_inline then
  3425. ppuwritenodetree(ppufile,inlininginfo^.code);
  3426. ppufile.do_crc:=oldintfcrc;
  3427. aktparasymtable:=oldparasymtable;
  3428. aktlocalsymtable:=oldlocalsymtable;
  3429. end;
  3430. procedure tprocdef.insert_localst;
  3431. begin
  3432. localst:=tlocalsymtable.create(parast.symtablelevel);
  3433. localst.defowner:=self;
  3434. { this is used by insert
  3435. to check same names in parast and localst }
  3436. localst.next:=parast;
  3437. end;
  3438. function tprocdef.fullprocname(showhidden:boolean):string;
  3439. var
  3440. s : string;
  3441. t : ttoken;
  3442. begin
  3443. {$ifdef EXTDEBUG}
  3444. showhidden:=true;
  3445. {$endif EXTDEBUG}
  3446. s:='';
  3447. if assigned(_class) then
  3448. begin
  3449. if po_classmethod in procoptions then
  3450. s:=s+'class ';
  3451. s:=s+_class.objrealname^+'.';
  3452. end;
  3453. if proctypeoption=potype_operator then
  3454. begin
  3455. for t:=NOTOKEN to last_overloaded do
  3456. if procsym.realname='$'+overloaded_names[t] then
  3457. begin
  3458. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3459. break;
  3460. end;
  3461. end
  3462. else
  3463. s:=s+procsym.realname+typename_paras(showhidden);
  3464. case proctypeoption of
  3465. potype_constructor:
  3466. s:='constructor '+s;
  3467. potype_destructor:
  3468. s:='destructor '+s;
  3469. else
  3470. if assigned(rettype.def) and
  3471. not(is_void(rettype.def)) then
  3472. s:=s+':'+rettype.def.gettypename;
  3473. end;
  3474. { forced calling convention? }
  3475. if (po_hascallingconvention in procoptions) then
  3476. s:=s+';'+ProcCallOptionStr[proccalloption];
  3477. fullprocname:=s;
  3478. end;
  3479. function tprocdef.is_methodpointer:boolean;
  3480. begin
  3481. result:=assigned(_class);
  3482. end;
  3483. function tprocdef.is_addressonly:boolean;
  3484. begin
  3485. result:=assigned(owner) and
  3486. (owner.symtabletype<>objectsymtable);
  3487. end;
  3488. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3489. begin
  3490. is_visible_for_object:=false;
  3491. { private symbols are allowed when we are in the same
  3492. module as they are defined }
  3493. if (sp_private in symoptions) and
  3494. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3495. (owner.defowner.owner.unitid<>0) then
  3496. exit;
  3497. { protected symbols are vissible in the module that defines them and
  3498. also visible to related objects. The related object must be defined
  3499. in the current module }
  3500. if (sp_protected in symoptions) and
  3501. (
  3502. (
  3503. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3504. (owner.defowner.owner.unitid<>0)
  3505. ) and
  3506. not(
  3507. assigned(currobjdef) and
  3508. (currobjdef.owner.unitid=0) and
  3509. currobjdef.is_related(tobjectdef(owner.defowner))
  3510. )
  3511. ) then
  3512. exit;
  3513. is_visible_for_object:=true;
  3514. end;
  3515. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3516. begin
  3517. case t of
  3518. gs_local :
  3519. getsymtable:=localst;
  3520. gs_para :
  3521. getsymtable:=parast;
  3522. else
  3523. getsymtable:=nil;
  3524. end;
  3525. end;
  3526. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3527. var
  3528. pos : tfileposinfo;
  3529. move_last : boolean;
  3530. oldparasymtable,
  3531. oldlocalsymtable : tsymtable;
  3532. begin
  3533. oldparasymtable:=aktparasymtable;
  3534. oldlocalsymtable:=aktlocalsymtable;
  3535. aktparasymtable:=parast;
  3536. aktlocalsymtable:=localst;
  3537. move_last:=lastwritten=lastref;
  3538. while (not ppufile.endofentry) do
  3539. begin
  3540. ppufile.getposinfo(pos);
  3541. inc(refcount);
  3542. lastref:=tref.create(lastref,@pos);
  3543. lastref.is_written:=true;
  3544. if refcount=1 then
  3545. defref:=lastref;
  3546. end;
  3547. if move_last then
  3548. lastwritten:=lastref;
  3549. if ((current_module.flags and uf_local_browser)<>0) and
  3550. assigned(localst) and
  3551. locals then
  3552. begin
  3553. tparasymtable(parast).load_references(ppufile,locals);
  3554. tlocalsymtable(localst).load_references(ppufile,locals);
  3555. end;
  3556. aktparasymtable:=oldparasymtable;
  3557. aktlocalsymtable:=oldlocalsymtable;
  3558. end;
  3559. Const
  3560. local_symtable_index : word = $8001;
  3561. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3562. var
  3563. ref : tref;
  3564. pdo : tobjectdef;
  3565. move_last : boolean;
  3566. d : tderef;
  3567. oldparasymtable,
  3568. oldlocalsymtable : tsymtable;
  3569. begin
  3570. d.reset;
  3571. move_last:=lastwritten=lastref;
  3572. if move_last and
  3573. (((current_module.flags and uf_local_browser)=0) or
  3574. not locals) then
  3575. exit;
  3576. oldparasymtable:=aktparasymtable;
  3577. oldlocalsymtable:=aktlocalsymtable;
  3578. aktparasymtable:=parast;
  3579. aktlocalsymtable:=localst;
  3580. { write address of this symbol }
  3581. d.build(self);
  3582. ppufile.putderef(d);
  3583. { write refs }
  3584. if assigned(lastwritten) then
  3585. ref:=lastwritten
  3586. else
  3587. ref:=defref;
  3588. while assigned(ref) do
  3589. begin
  3590. if ref.moduleindex=current_module.unit_index then
  3591. begin
  3592. ppufile.putposinfo(ref.posinfo);
  3593. ref.is_written:=true;
  3594. if move_last then
  3595. lastwritten:=ref;
  3596. end
  3597. else if not ref.is_written then
  3598. move_last:=false
  3599. else if move_last then
  3600. lastwritten:=ref;
  3601. ref:=ref.nextref;
  3602. end;
  3603. ppufile.writeentry(ibdefref);
  3604. write_references:=true;
  3605. if ((current_module.flags and uf_local_browser)<>0) and
  3606. assigned(localst) and
  3607. locals then
  3608. begin
  3609. pdo:=_class;
  3610. if (owner.symtabletype<>localsymtable) then
  3611. while assigned(pdo) do
  3612. begin
  3613. if pdo.symtable<>aktrecordsymtable then
  3614. begin
  3615. pdo.symtable.unitid:=local_symtable_index;
  3616. inc(local_symtable_index);
  3617. end;
  3618. pdo:=pdo.childof;
  3619. end;
  3620. parast.unitid:=local_symtable_index;
  3621. inc(local_symtable_index);
  3622. localst.unitid:=local_symtable_index;
  3623. inc(local_symtable_index);
  3624. tstoredsymtable(parast).write_references(ppufile,locals);
  3625. tstoredsymtable(localst).write_references(ppufile,locals);
  3626. { decrement for }
  3627. local_symtable_index:=local_symtable_index-2;
  3628. pdo:=_class;
  3629. if (owner.symtabletype<>localsymtable) then
  3630. while assigned(pdo) do
  3631. begin
  3632. if pdo.symtable<>aktrecordsymtable then
  3633. dec(local_symtable_index);
  3634. pdo:=pdo.childof;
  3635. end;
  3636. end;
  3637. aktparasymtable:=oldparasymtable;
  3638. aktlocalsymtable:=oldlocalsymtable;
  3639. end;
  3640. {$ifdef GDB}
  3641. function tprocdef.numberstring : string;
  3642. begin
  3643. { procdefs are always available }
  3644. stab_state:=stab_state_written;
  3645. result:=inherited numberstring;
  3646. end;
  3647. function tprocdef.stabstring: pchar;
  3648. Var
  3649. RType : Char;
  3650. Obj,Info : String;
  3651. stabsstr : string;
  3652. p : pchar;
  3653. begin
  3654. obj := procsym.name;
  3655. info := '';
  3656. if tprocsym(procsym).is_global then
  3657. RType := 'F'
  3658. else
  3659. RType := 'f';
  3660. if assigned(owner) then
  3661. begin
  3662. if (owner.symtabletype = objectsymtable) then
  3663. obj := owner.name^+'__'+procsym.name;
  3664. if not(cs_gdb_valgrind in aktglobalswitches) and
  3665. (owner.symtabletype=localsymtable) and
  3666. assigned(owner.defowner) and
  3667. assigned(tprocdef(owner.defowner).procsym) then
  3668. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3669. end;
  3670. stabsstr:=mangledname;
  3671. getmem(p,length(stabsstr)+255);
  3672. strpcopy(p,'"'+obj+':'+RType
  3673. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3674. +',0,'+
  3675. tostr(fileinfo.line)
  3676. +',');
  3677. strpcopy(strend(p),stabsstr);
  3678. stabstring:=strnew(p);
  3679. freemem(p,length(stabsstr)+255);
  3680. end;
  3681. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3682. begin
  3683. { released procdef? }
  3684. if not assigned(parast) then
  3685. exit;
  3686. if (proccalloption=pocall_internproc) then
  3687. exit;
  3688. { be sure to have a number assigned for this def }
  3689. numberstring;
  3690. { write stabs }
  3691. stab_state:=stab_state_writing;
  3692. asmList.concat(Tai_stabs.Create(stabstring));
  3693. if not(po_external in procoptions) then
  3694. begin
  3695. tstoredsymtable(parast).concatstabto(asmlist);
  3696. { local type defs and vars should not be written
  3697. inside the main proc stab }
  3698. if assigned(localst) and
  3699. (localst.symtablelevel>main_program_level) then
  3700. tstoredsymtable(localst).concatstabto(asmlist);
  3701. end;
  3702. stab_state:=stab_state_written;
  3703. end;
  3704. {$endif GDB}
  3705. procedure tprocdef.buildderef;
  3706. var
  3707. oldparasymtable,
  3708. oldlocalsymtable : tsymtable;
  3709. begin
  3710. oldparasymtable:=aktparasymtable;
  3711. oldlocalsymtable:=aktlocalsymtable;
  3712. aktparasymtable:=parast;
  3713. aktlocalsymtable:=localst;
  3714. inherited buildderef;
  3715. _classderef.build(_class);
  3716. { procsym that originaly defined this definition, should be in the
  3717. same symtable }
  3718. procsymderef.build(procsym);
  3719. {$ifdef powerpc}
  3720. { library symbol for AmigaOS/MorphOS }
  3721. libsymderef.build(libsym);
  3722. {$endif powerpc}
  3723. aktparasymtable:=oldparasymtable;
  3724. aktlocalsymtable:=oldlocalsymtable;
  3725. end;
  3726. procedure tprocdef.buildderefimpl;
  3727. var
  3728. oldparasymtable,
  3729. oldlocalsymtable : tsymtable;
  3730. begin
  3731. { released procdef? }
  3732. if not assigned(parast) then
  3733. exit;
  3734. oldparasymtable:=aktparasymtable;
  3735. oldlocalsymtable:=aktlocalsymtable;
  3736. aktparasymtable:=parast;
  3737. aktlocalsymtable:=localst;
  3738. inherited buildderefimpl;
  3739. { Locals }
  3740. if assigned(localst) and
  3741. ((proccalloption=pocall_inline) or
  3742. ((current_module.flags and uf_local_browser)<>0)) then
  3743. begin
  3744. tlocalsymtable(localst).buildderef;
  3745. tlocalsymtable(localst).buildderefimpl;
  3746. end;
  3747. { inline tree }
  3748. if (proccalloption=pocall_inline) then
  3749. begin
  3750. funcretsymderef.build(funcretsym);
  3751. inlininginfo^.code.buildderefimpl;
  3752. end;
  3753. aktparasymtable:=oldparasymtable;
  3754. aktlocalsymtable:=oldlocalsymtable;
  3755. end;
  3756. procedure tprocdef.deref;
  3757. var
  3758. oldparasymtable,
  3759. oldlocalsymtable : tsymtable;
  3760. begin
  3761. { released procdef? }
  3762. if not assigned(parast) then
  3763. exit;
  3764. oldparasymtable:=aktparasymtable;
  3765. oldlocalsymtable:=aktlocalsymtable;
  3766. aktparasymtable:=parast;
  3767. aktlocalsymtable:=localst;
  3768. inherited deref;
  3769. _class:=tobjectdef(_classderef.resolve);
  3770. { procsym that originaly defined this definition, should be in the
  3771. same symtable }
  3772. procsym:=tprocsym(procsymderef.resolve);
  3773. {$ifdef powerpc}
  3774. { library symbol for AmigaOS/MorphOS }
  3775. libsym:=tvarsym(libsymderef.resolve);
  3776. {$endif powerpc}
  3777. aktparasymtable:=oldparasymtable;
  3778. aktlocalsymtable:=oldlocalsymtable;
  3779. end;
  3780. procedure tprocdef.derefimpl;
  3781. var
  3782. oldparasymtable,
  3783. oldlocalsymtable : tsymtable;
  3784. begin
  3785. oldparasymtable:=aktparasymtable;
  3786. oldlocalsymtable:=aktlocalsymtable;
  3787. aktparasymtable:=parast;
  3788. aktlocalsymtable:=localst;
  3789. { Locals }
  3790. if assigned(localst) then
  3791. begin
  3792. tlocalsymtable(localst).deref;
  3793. tlocalsymtable(localst).derefimpl;
  3794. end;
  3795. { Inline }
  3796. if (proccalloption=pocall_inline) then
  3797. begin
  3798. inlininginfo^.code.derefimpl;
  3799. { funcretsym, this is always located in the localst }
  3800. funcretsym:=tsym(funcretsymderef.resolve);
  3801. end
  3802. else
  3803. begin
  3804. { safety }
  3805. funcretsym:=nil;
  3806. end;
  3807. aktparasymtable:=oldparasymtable;
  3808. aktlocalsymtable:=oldlocalsymtable;
  3809. end;
  3810. function tprocdef.gettypename : string;
  3811. begin
  3812. gettypename := FullProcName(false);
  3813. end;
  3814. function tprocdef.mangledname : string;
  3815. var
  3816. hp : TParaItem;
  3817. begin
  3818. if assigned(_mangledname) then
  3819. begin
  3820. {$ifdef compress}
  3821. mangledname:=minilzw_decode(_mangledname^);
  3822. {$else}
  3823. mangledname:=_mangledname^;
  3824. {$endif}
  3825. exit;
  3826. end;
  3827. { we need to use the symtable where the procsym is inserted,
  3828. because that is visible to the world }
  3829. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3830. if overloadnumber>0 then
  3831. mangledname:=mangledname+'$'+tostr(overloadnumber);
  3832. { add parameter types }
  3833. hp:=TParaItem(Para.first);
  3834. while assigned(hp) do
  3835. begin
  3836. if not hp.is_hidden then
  3837. mangledname:=mangledname+'$'+hp.paratype.def.mangledparaname;
  3838. hp:=TParaItem(hp.next);
  3839. end;
  3840. {$ifdef compress}
  3841. _mangledname:=stringdup(minilzw_encode(mangledname));
  3842. {$else}
  3843. _mangledname:=stringdup(mangledname);
  3844. {$endif}
  3845. end;
  3846. function tprocdef.cplusplusmangledname : string;
  3847. function getcppparaname(p : tdef) : string;
  3848. const
  3849. ordtype2str : array[tbasetype] of string[2] = (
  3850. '',
  3851. 'Uc','Us','Ui','Us',
  3852. 'Sc','s','i','x',
  3853. 'b','b','b',
  3854. 'c','w','x');
  3855. var
  3856. s : string;
  3857. begin
  3858. case p.deftype of
  3859. orddef:
  3860. s:=ordtype2str[torddef(p).typ];
  3861. pointerdef:
  3862. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3863. else
  3864. internalerror(2103001);
  3865. end;
  3866. getcppparaname:=s;
  3867. end;
  3868. var
  3869. s,s2 : string;
  3870. param : TParaItem;
  3871. begin
  3872. s := procsym.realname;
  3873. if procsym.owner.symtabletype=objectsymtable then
  3874. begin
  3875. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3876. case proctypeoption of
  3877. potype_destructor:
  3878. s:='_$_'+tostr(length(s2))+s2;
  3879. potype_constructor:
  3880. s:='___'+tostr(length(s2))+s2;
  3881. else
  3882. s:='_'+s+'__'+tostr(length(s2))+s2;
  3883. end;
  3884. end
  3885. else s:=s+'__';
  3886. s:=s+'F';
  3887. { concat modifiers }
  3888. { !!!!! }
  3889. { now we handle the parameters }
  3890. param := TParaItem(Para.first);
  3891. if assigned(param) then
  3892. while assigned(param) do
  3893. begin
  3894. s2:=getcppparaname(param.paratype.def);
  3895. if param.paratyp in [vs_var,vs_out] then
  3896. s2:='R'+s2;
  3897. s:=s+s2;
  3898. param:=TParaItem(param.next);
  3899. end
  3900. else
  3901. s:=s+'v';
  3902. cplusplusmangledname:=s;
  3903. end;
  3904. procedure tprocdef.setmangledname(const s : string);
  3905. begin
  3906. stringdispose(_mangledname);
  3907. {$ifdef compress}
  3908. _mangledname:=stringdup(minilzw_encode(s));
  3909. {$else}
  3910. _mangledname:=stringdup(s);
  3911. {$endif}
  3912. has_mangledname:=true;
  3913. end;
  3914. {***************************************************************************
  3915. TPROCVARDEF
  3916. ***************************************************************************}
  3917. constructor tprocvardef.create(level:byte);
  3918. begin
  3919. inherited create(level);
  3920. deftype:=procvardef;
  3921. end;
  3922. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3923. begin
  3924. inherited ppuload(ppufile);
  3925. deftype:=procvardef;
  3926. { load para symtable }
  3927. parast:=tparasymtable.create(unknown_level);
  3928. tparasymtable(parast).ppuload(ppufile);
  3929. parast.defowner:=self;
  3930. end;
  3931. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3932. var
  3933. oldparasymtable,
  3934. oldlocalsymtable : tsymtable;
  3935. begin
  3936. oldparasymtable:=aktparasymtable;
  3937. oldlocalsymtable:=aktlocalsymtable;
  3938. aktparasymtable:=parast;
  3939. aktlocalsymtable:=nil;
  3940. { here we cannot get a real good value so just give something }
  3941. { plausible (PM) }
  3942. { a more secure way would be
  3943. to allways store in a temp }
  3944. {$ifdef i386}
  3945. if is_fpu(rettype.def) then
  3946. fpu_used:={2}maxfpuregs
  3947. else
  3948. fpu_used:=0;
  3949. {$endif i386}
  3950. inherited ppuwrite(ppufile);
  3951. { Write this entry }
  3952. ppufile.writeentry(ibprocvardef);
  3953. { Save the para symtable, this is taken from the interface }
  3954. tparasymtable(parast).ppuwrite(ppufile);
  3955. aktparasymtable:=oldparasymtable;
  3956. aktlocalsymtable:=oldlocalsymtable;
  3957. end;
  3958. procedure tprocvardef.buildderef;
  3959. var
  3960. oldparasymtable,
  3961. oldlocalsymtable : tsymtable;
  3962. begin
  3963. oldparasymtable:=aktparasymtable;
  3964. oldlocalsymtable:=aktlocalsymtable;
  3965. aktparasymtable:=parast;
  3966. aktlocalsymtable:=nil;
  3967. inherited buildderef;
  3968. aktparasymtable:=oldparasymtable;
  3969. aktlocalsymtable:=oldlocalsymtable;
  3970. end;
  3971. procedure tprocvardef.deref;
  3972. var
  3973. oldparasymtable,
  3974. oldlocalsymtable : tsymtable;
  3975. begin
  3976. oldparasymtable:=aktparasymtable;
  3977. oldlocalsymtable:=aktlocalsymtable;
  3978. aktparasymtable:=parast;
  3979. aktlocalsymtable:=nil;
  3980. inherited deref;
  3981. aktparasymtable:=oldparasymtable;
  3982. aktlocalsymtable:=oldlocalsymtable;
  3983. end;
  3984. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3985. begin
  3986. case t of
  3987. gs_para :
  3988. getsymtable:=parast;
  3989. else
  3990. getsymtable:=nil;
  3991. end;
  3992. end;
  3993. function tprocvardef.size : aint;
  3994. begin
  3995. if (po_methodpointer in procoptions) and
  3996. not(po_addressonly in procoptions) then
  3997. size:=2*sizeof(aint)
  3998. else
  3999. size:=sizeof(aint);
  4000. end;
  4001. function tprocvardef.is_methodpointer:boolean;
  4002. begin
  4003. result:=(po_methodpointer in procoptions);
  4004. end;
  4005. function tprocvardef.is_addressonly:boolean;
  4006. begin
  4007. result:=not(po_methodpointer in procoptions) or
  4008. (po_addressonly in procoptions);
  4009. end;
  4010. {$ifdef GDB}
  4011. function tprocvardef.stabstring : pchar;
  4012. var
  4013. nss : pchar;
  4014. { i : longint; }
  4015. begin
  4016. { i := maxparacount; }
  4017. getmem(nss,1024);
  4018. { it is not a function but a function pointer !! (PM) }
  4019. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)});
  4020. { this confuses gdb !!
  4021. we should use 'F' instead of 'f' but
  4022. as we use c++ language mode
  4023. it does not like that either
  4024. Please do not remove this part
  4025. might be used once
  4026. gdb for pascal is ready PM }
  4027. {$ifdef disabled}
  4028. param := para1;
  4029. i := 0;
  4030. while assigned(param) do
  4031. begin
  4032. inc(i);
  4033. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  4034. {Here we have lost the parameter names !!}
  4035. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  4036. strcat(nss,pst);
  4037. strdispose(pst);
  4038. param := param^.next;
  4039. end;
  4040. {$endif}
  4041. {strpcopy(strend(nss),';');}
  4042. stabstring := strnew(nss);
  4043. freemem(nss,1024);
  4044. end;
  4045. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  4046. begin
  4047. if (stab_state in [stab_state_writing,stab_state_written]) then
  4048. exit;
  4049. tstoreddef(rettype.def).concatstabto(asmlist);
  4050. inherited concatstabto(asmlist);
  4051. end;
  4052. {$endif GDB}
  4053. procedure tprocvardef.write_rtti_data(rt:trttitype);
  4054. var
  4055. pdc : TParaItem;
  4056. methodkind, paraspec : byte;
  4057. begin
  4058. if po_methodpointer in procoptions then
  4059. begin
  4060. { write method id and name }
  4061. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  4062. write_rtti_name;
  4063. { write kind of method (can only be function or procedure)}
  4064. if rettype.def = voidtype.def then
  4065. methodkind := mkProcedure
  4066. else
  4067. methodkind := mkFunction;
  4068. rttiList.concat(Tai_const.Create_8bit(methodkind));
  4069. { get # of parameters }
  4070. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  4071. { write parameter info. The parameters must be written in reverse order
  4072. if this method uses right to left parameter pushing! }
  4073. if proccalloption in pushleftright_pocalls then
  4074. pdc:=TParaItem(Para.first)
  4075. else
  4076. pdc:=TParaItem(Para.last);
  4077. while assigned(pdc) do
  4078. begin
  4079. { only store user visible parameters }
  4080. if not pdc.is_hidden then
  4081. begin
  4082. case pdc.paratyp of
  4083. vs_value: paraspec := 0;
  4084. vs_const: paraspec := pfConst;
  4085. vs_var : paraspec := pfVar;
  4086. vs_out : paraspec := pfOut;
  4087. end;
  4088. { write flags for current parameter }
  4089. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4090. { write name of current parameter }
  4091. if assigned(pdc.parasym) then
  4092. begin
  4093. rttiList.concat(Tai_const.Create_8bit(length(pdc.parasym.realname)));
  4094. rttiList.concat(Tai_string.Create(pdc.parasym.realname));
  4095. end
  4096. else
  4097. rttiList.concat(Tai_const.Create_8bit(0));
  4098. { write name of type of current parameter }
  4099. tstoreddef(pdc.paratype.def).write_rtti_name;
  4100. end;
  4101. if proccalloption in pushleftright_pocalls then
  4102. pdc:=TParaItem(pdc.next)
  4103. else
  4104. pdc:=TParaItem(pdc.previous);
  4105. end;
  4106. { write name of result type }
  4107. tstoreddef(rettype.def).write_rtti_name;
  4108. end;
  4109. end;
  4110. function tprocvardef.is_publishable : boolean;
  4111. begin
  4112. is_publishable:=(po_methodpointer in procoptions);
  4113. end;
  4114. function tprocvardef.gettypename : string;
  4115. var
  4116. s: string;
  4117. showhidden : boolean;
  4118. begin
  4119. {$ifdef EXTDEBUG}
  4120. showhidden:=true;
  4121. {$else EXTDEBUG}
  4122. showhidden:=false;
  4123. {$endif EXTDEBUG}
  4124. s:='<';
  4125. if po_classmethod in procoptions then
  4126. s := s+'class method type of'
  4127. else
  4128. if po_addressonly in procoptions then
  4129. s := s+'address of'
  4130. else
  4131. s := s+'procedure variable type of';
  4132. if assigned(rettype.def) and
  4133. (rettype.def<>voidtype.def) then
  4134. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4135. else
  4136. s:=s+' procedure'+typename_paras(showhidden);
  4137. if po_methodpointer in procoptions then
  4138. s := s+' of object';
  4139. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4140. end;
  4141. {***************************************************************************
  4142. TOBJECTDEF
  4143. ***************************************************************************}
  4144. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4145. begin
  4146. inherited create;
  4147. objecttype:=ot;
  4148. deftype:=objectdef;
  4149. objectoptions:=[];
  4150. childof:=nil;
  4151. symtable:=tobjectsymtable.create(n,aktpackrecords);
  4152. { create space for vmt !! }
  4153. vmt_offset:=0;
  4154. symtable.defowner:=self;
  4155. lastvtableindex:=0;
  4156. set_parent(c);
  4157. objname:=stringdup(upper(n));
  4158. objrealname:=stringdup(n);
  4159. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4160. prepareguid;
  4161. { setup implemented interfaces }
  4162. if objecttype in [odt_class,odt_interfacecorba] then
  4163. implementedinterfaces:=timplementedinterfaces.create
  4164. else
  4165. implementedinterfaces:=nil;
  4166. {$ifdef GDB}
  4167. writing_class_record_stab:=false;
  4168. {$endif GDB}
  4169. end;
  4170. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4171. var
  4172. i,implintfcount: longint;
  4173. d : tderef;
  4174. begin
  4175. inherited ppuloaddef(ppufile);
  4176. deftype:=objectdef;
  4177. objecttype:=tobjectdeftype(ppufile.getbyte);
  4178. objrealname:=stringdup(ppufile.getstring);
  4179. objname:=stringdup(upper(objrealname^));
  4180. symtable:=tobjectsymtable.create(objrealname^,0);
  4181. tobjectsymtable(symtable).datasize:=ppufile.getaint;
  4182. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  4183. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  4184. vmt_offset:=ppufile.getlongint;
  4185. ppufile.getderef(childofderef);
  4186. ppufile.getsmallset(objectoptions);
  4187. { load guid }
  4188. iidstr:=nil;
  4189. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4190. begin
  4191. new(iidguid);
  4192. ppufile.getguid(iidguid^);
  4193. iidstr:=stringdup(ppufile.getstring);
  4194. lastvtableindex:=ppufile.getlongint;
  4195. end;
  4196. { load implemented interfaces }
  4197. if objecttype in [odt_class,odt_interfacecorba] then
  4198. begin
  4199. implementedinterfaces:=timplementedinterfaces.create;
  4200. implintfcount:=ppufile.getlongint;
  4201. for i:=1 to implintfcount do
  4202. begin
  4203. ppufile.getderef(d);
  4204. implementedinterfaces.addintf_deref(d);
  4205. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4206. end;
  4207. end
  4208. else
  4209. implementedinterfaces:=nil;
  4210. tobjectsymtable(symtable).ppuload(ppufile);
  4211. symtable.defowner:=self;
  4212. { handles the predefined class tobject }
  4213. { the last TOBJECT which is loaded gets }
  4214. { it ! }
  4215. if (childof=nil) and
  4216. (objecttype=odt_class) and
  4217. (objname^='TOBJECT') then
  4218. class_tobject:=self;
  4219. if (childof=nil) and
  4220. (objecttype=odt_interfacecom) and
  4221. (objname^='IUNKNOWN') then
  4222. interface_iunknown:=self;
  4223. {$ifdef GDB}
  4224. writing_class_record_stab:=false;
  4225. {$endif GDB}
  4226. end;
  4227. destructor tobjectdef.destroy;
  4228. begin
  4229. if assigned(symtable) then
  4230. symtable.free;
  4231. stringdispose(objname);
  4232. stringdispose(objrealname);
  4233. if assigned(iidstr) then
  4234. stringdispose(iidstr);
  4235. if assigned(implementedinterfaces) then
  4236. implementedinterfaces.free;
  4237. if assigned(iidguid) then
  4238. dispose(iidguid);
  4239. inherited destroy;
  4240. end;
  4241. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4242. var
  4243. implintfcount : longint;
  4244. i : longint;
  4245. begin
  4246. inherited ppuwritedef(ppufile);
  4247. ppufile.putbyte(byte(objecttype));
  4248. ppufile.putstring(objrealname^);
  4249. ppufile.putaint(tobjectsymtable(symtable).datasize);
  4250. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  4251. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  4252. ppufile.putlongint(vmt_offset);
  4253. ppufile.putderef(childofderef);
  4254. ppufile.putsmallset(objectoptions);
  4255. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4256. begin
  4257. ppufile.putguid(iidguid^);
  4258. ppufile.putstring(iidstr^);
  4259. ppufile.putlongint(lastvtableindex);
  4260. end;
  4261. if objecttype in [odt_class,odt_interfacecorba] then
  4262. begin
  4263. implintfcount:=implementedinterfaces.count;
  4264. ppufile.putlongint(implintfcount);
  4265. for i:=1 to implintfcount do
  4266. begin
  4267. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4268. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4269. end;
  4270. end;
  4271. ppufile.writeentry(ibobjectdef);
  4272. tobjectsymtable(symtable).ppuwrite(ppufile);
  4273. end;
  4274. function tobjectdef.gettypename:string;
  4275. begin
  4276. gettypename:=typename;
  4277. end;
  4278. procedure tobjectdef.buildderef;
  4279. var
  4280. oldrecsyms : tsymtable;
  4281. begin
  4282. inherited buildderef;
  4283. childofderef.build(childof);
  4284. oldrecsyms:=aktrecordsymtable;
  4285. aktrecordsymtable:=symtable;
  4286. tstoredsymtable(symtable).buildderef;
  4287. aktrecordsymtable:=oldrecsyms;
  4288. if objecttype in [odt_class,odt_interfacecorba] then
  4289. implementedinterfaces.buildderef;
  4290. end;
  4291. procedure tobjectdef.deref;
  4292. var
  4293. oldrecsyms : tsymtable;
  4294. begin
  4295. inherited deref;
  4296. childof:=tobjectdef(childofderef.resolve);
  4297. oldrecsyms:=aktrecordsymtable;
  4298. aktrecordsymtable:=symtable;
  4299. tstoredsymtable(symtable).deref;
  4300. aktrecordsymtable:=oldrecsyms;
  4301. if objecttype in [odt_class,odt_interfacecorba] then
  4302. implementedinterfaces.deref;
  4303. end;
  4304. function tobjectdef.getparentdef:tdef;
  4305. begin
  4306. result:=childof;
  4307. end;
  4308. procedure tobjectdef.prepareguid;
  4309. begin
  4310. { set up guid }
  4311. if not assigned(iidguid) then
  4312. begin
  4313. new(iidguid);
  4314. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4315. end;
  4316. { setup iidstring }
  4317. if not assigned(iidstr) then
  4318. iidstr:=stringdup(''); { default is empty string }
  4319. end;
  4320. procedure tobjectdef.set_parent( c : tobjectdef);
  4321. begin
  4322. { nothing to do if the parent was not forward !}
  4323. if assigned(childof) then
  4324. exit;
  4325. childof:=c;
  4326. { some options are inherited !! }
  4327. if assigned(c) then
  4328. begin
  4329. { only important for classes }
  4330. lastvtableindex:=c.lastvtableindex;
  4331. objectoptions:=objectoptions+(c.objectoptions*
  4332. [oo_has_virtual,oo_has_private,oo_has_protected,
  4333. oo_has_constructor,oo_has_destructor]);
  4334. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4335. begin
  4336. { add the data of the anchestor class }
  4337. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4338. if (oo_has_vmt in objectoptions) and
  4339. (oo_has_vmt in c.objectoptions) then
  4340. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  4341. { if parent has a vmt field then
  4342. the offset is the same for the child PM }
  4343. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4344. begin
  4345. vmt_offset:=c.vmt_offset;
  4346. include(objectoptions,oo_has_vmt);
  4347. end;
  4348. end;
  4349. end;
  4350. end;
  4351. procedure tobjectdef.insertvmt;
  4352. begin
  4353. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4354. exit;
  4355. if (oo_has_vmt in objectoptions) then
  4356. internalerror(12345)
  4357. else
  4358. begin
  4359. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4360. tobjectsymtable(symtable).fieldalignment);
  4361. vmt_offset:=tobjectsymtable(symtable).datasize;
  4362. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  4363. include(objectoptions,oo_has_vmt);
  4364. end;
  4365. end;
  4366. procedure tobjectdef.check_forwards;
  4367. begin
  4368. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4369. tstoredsymtable(symtable).check_forwards;
  4370. if (oo_is_forward in objectoptions) then
  4371. begin
  4372. { ok, in future, the forward can be resolved }
  4373. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4374. exclude(objectoptions,oo_is_forward);
  4375. end;
  4376. end;
  4377. { true, if self inherits from d (or if they are equal) }
  4378. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4379. var
  4380. hp : tobjectdef;
  4381. begin
  4382. hp:=self;
  4383. while assigned(hp) do
  4384. begin
  4385. if hp=d then
  4386. begin
  4387. is_related:=true;
  4388. exit;
  4389. end;
  4390. hp:=hp.childof;
  4391. end;
  4392. is_related:=false;
  4393. end;
  4394. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4395. var
  4396. p : pprocdeflist;
  4397. begin
  4398. { if we found already a destructor, then we exit }
  4399. if assigned(sd) then
  4400. exit;
  4401. if tsym(sym).typ=procsym then
  4402. begin
  4403. p:=tprocsym(sym).defs;
  4404. while assigned(p) do
  4405. begin
  4406. if p^.def.proctypeoption=potype_destructor then
  4407. begin
  4408. sd:=p^.def;
  4409. exit;
  4410. end;
  4411. p:=p^.next;
  4412. end;
  4413. end;
  4414. end;*)
  4415. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4416. begin
  4417. { if we found already a destructor, then we exit }
  4418. if (ppointer(sd)^=nil) and
  4419. (Tsym(sym).typ=procsym) then
  4420. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4421. end;
  4422. function tobjectdef.searchdestructor : tprocdef;
  4423. var
  4424. o : tobjectdef;
  4425. sd : tprocdef;
  4426. begin
  4427. searchdestructor:=nil;
  4428. o:=self;
  4429. sd:=nil;
  4430. while assigned(o) do
  4431. begin
  4432. o.symtable.foreach_static(@_searchdestructor,@sd);
  4433. if assigned(sd) then
  4434. begin
  4435. searchdestructor:=sd;
  4436. exit;
  4437. end;
  4438. o:=o.childof;
  4439. end;
  4440. end;
  4441. function tobjectdef.size : aint;
  4442. begin
  4443. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4444. result:=sizeof(aint)
  4445. else
  4446. result:=tobjectsymtable(symtable).datasize;
  4447. end;
  4448. function tobjectdef.alignment:longint;
  4449. begin
  4450. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4451. alignment:=sizeof(aint)
  4452. else
  4453. alignment:=tobjectsymtable(symtable).recordalignment;
  4454. end;
  4455. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4456. begin
  4457. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4458. case objecttype of
  4459. odt_class:
  4460. { the +2*sizeof(Aint) is size and -size }
  4461. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  4462. odt_interfacecom,odt_interfacecorba:
  4463. vmtmethodoffset:=index*sizeof(aint);
  4464. else
  4465. {$ifdef WITHDMT}
  4466. vmtmethodoffset:=(index+4)*sizeof(aint);
  4467. {$else WITHDMT}
  4468. vmtmethodoffset:=(index+3)*sizeof(aint);
  4469. {$endif WITHDMT}
  4470. end;
  4471. end;
  4472. function tobjectdef.vmt_mangledname : string;
  4473. begin
  4474. if not(oo_has_vmt in objectoptions) then
  4475. Message1(parser_n_object_has_no_vmt,objrealname^);
  4476. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4477. end;
  4478. function tobjectdef.rtti_name : string;
  4479. begin
  4480. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4481. end;
  4482. {$ifdef GDB}
  4483. procedure tobjectdef.proc_addname(p :tnamedindexitem;arg:pointer);
  4484. var virtualind,argnames : string;
  4485. newrec : pchar;
  4486. pd : tprocdef;
  4487. lindex : longint;
  4488. para : TParaItem;
  4489. arglength : byte;
  4490. sp : char;
  4491. state:^Trecord_stabgen_state;
  4492. olds:integer;
  4493. begin
  4494. state:=arg;
  4495. if tsym(p).typ = procsym then
  4496. begin
  4497. pd := tprocsym(p).first_procdef;
  4498. if (po_virtualmethod in pd.procoptions) then
  4499. begin
  4500. lindex := pd.extnumber;
  4501. {doesnt seem to be necessary
  4502. lindex := lindex or $80000000;}
  4503. virtualind := '*'+tostr(lindex)+';'+pd._class.classnumberstring+';'
  4504. end
  4505. else
  4506. virtualind := '.';
  4507. { used by gdbpas to recognize constructor and destructors }
  4508. if (pd.proctypeoption=potype_constructor) then
  4509. argnames:='__ct__'
  4510. else if (pd.proctypeoption=potype_destructor) then
  4511. argnames:='__dt__'
  4512. else
  4513. argnames := '';
  4514. { arguments are not listed here }
  4515. {we don't need another definition}
  4516. para := TParaItem(pd.Para.first);
  4517. while assigned(para) do
  4518. begin
  4519. if Para.paratype.def.deftype = formaldef then
  4520. begin
  4521. case Para.paratyp of
  4522. vs_var :
  4523. argnames := argnames+'3var';
  4524. vs_const :
  4525. argnames:=argnames+'5const';
  4526. vs_out :
  4527. argnames:=argnames+'3out';
  4528. end;
  4529. end
  4530. else
  4531. begin
  4532. { if the arg definition is like (v: ^byte;..
  4533. there is no sym attached to data !!! }
  4534. if assigned(Para.paratype.def.typesym) then
  4535. begin
  4536. arglength := length(Para.paratype.def.typesym.name);
  4537. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4538. end
  4539. else
  4540. argnames:=argnames+'11unnamedtype';
  4541. end;
  4542. para := TParaItem(Para.next);
  4543. end;
  4544. { here 2A must be changed for private and protected }
  4545. { 0 is private 1 protected and 2 public }
  4546. if (sp_private in tsym(p).symoptions) then
  4547. sp:='0'
  4548. else if (sp_protected in tsym(p).symoptions) then
  4549. sp:='1'
  4550. else
  4551. sp:='2';
  4552. newrec:=stabstr_evaluate('$1::$2=##$3;:$4;$5A$6;',[p.name,pd.numberstring,
  4553. Tstoreddef(pd.rettype.def).numberstring,argnames,sp,
  4554. virtualind]);
  4555. { get spare place for a string at the end }
  4556. olds:=state^.stabsize;
  4557. inc(state^.stabsize,strlen(newrec));
  4558. if state^.stabsize>=state^.staballoc-256 then
  4559. begin
  4560. inc(state^.staballoc,memsizeinc);
  4561. reallocmem(state^.stabstring,state^.staballoc);
  4562. end;
  4563. strcopy(state^.stabstring+olds,newrec);
  4564. strdispose(newrec);
  4565. {This should be used for case !!
  4566. RecOffset := RecOffset + pd.size;}
  4567. end;
  4568. end;
  4569. procedure tobjectdef.proc_concatstabto(p :tnamedindexitem;arg:pointer);
  4570. var
  4571. pd : tprocdef;
  4572. begin
  4573. if tsym(p).typ = procsym then
  4574. begin
  4575. pd := tprocsym(p).first_procdef;
  4576. tstoreddef(pd.rettype.def).concatstabto(taasmoutput(arg));
  4577. end;
  4578. end;
  4579. function tobjectdef.stabstring : pchar;
  4580. var anc : tobjectdef;
  4581. state:Trecord_stabgen_state;
  4582. ts : string;
  4583. begin
  4584. if not (objecttype=odt_class) or writing_class_record_stab then
  4585. begin
  4586. state.staballoc:=memsizeinc;
  4587. getmem(state.stabstring,state.staballoc);
  4588. strpcopy(state.stabstring,'s'+tostr(tobjectsymtable(symtable).datasize));
  4589. if assigned(childof) then
  4590. begin
  4591. {only one ancestor not virtual, public, at base offset 0 }
  4592. { !1 , 0 2 0 , }
  4593. strpcopy(strend(state.stabstring),'!1,020,'+childof.classnumberstring+';');
  4594. end;
  4595. {virtual table to implement yet}
  4596. state.recoffset:=0;
  4597. state.stabsize:=strlen(state.stabstring);
  4598. symtable.foreach(@field_addname,@state);
  4599. if (oo_has_vmt in objectoptions) then
  4600. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4601. begin
  4602. ts:='$vf'+classnumberstring+':'+tstoreddef(vmtarraytype.def).numberstring+','+tostr(vmt_offset*8)+';';
  4603. strpcopy(state.stabstring+state.stabsize,ts);
  4604. inc(state.stabsize,length(ts));
  4605. end;
  4606. symtable.foreach(@proc_addname,@state);
  4607. if (oo_has_vmt in objectoptions) then
  4608. begin
  4609. anc := self;
  4610. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4611. anc := anc.childof;
  4612. { just in case anc = self }
  4613. ts:=';~%'+anc.classnumberstring+';';
  4614. end
  4615. else
  4616. ts:=';';
  4617. strpcopy(state.stabstring+state.stabsize,ts);
  4618. inc(state.stabsize,length(ts));
  4619. reallocmem(state.stabstring,state.stabsize+1);
  4620. stabstring:=state.stabstring;
  4621. end
  4622. else
  4623. begin
  4624. stabstring:=strpnew('*'+classnumberstring);
  4625. end;
  4626. end;
  4627. procedure tobjectdef.set_globalnb;
  4628. begin
  4629. globalnb:=PglobalTypeCount^;
  4630. inc(PglobalTypeCount^);
  4631. { classes need two type numbers, the globalnb is set to the ptr }
  4632. if objecttype=odt_class then
  4633. begin
  4634. globalnb:=PGlobalTypeCount^;
  4635. inc(PglobalTypeCount^);
  4636. end;
  4637. end;
  4638. function tobjectdef.classnumberstring : string;
  4639. begin
  4640. if objecttype=odt_class then
  4641. begin
  4642. if globalnb=0 then
  4643. numberstring;
  4644. dec(globalnb);
  4645. classnumberstring:=numberstring;
  4646. inc(globalnb);
  4647. end
  4648. else
  4649. classnumberstring:=numberstring;
  4650. end;
  4651. function tobjectdef.allstabstring : pchar;
  4652. var
  4653. stabchar : string[2];
  4654. ss,st : pchar;
  4655. sname : string;
  4656. begin
  4657. ss := stabstring;
  4658. getmem(st,strlen(ss)+512);
  4659. stabchar := 't';
  4660. if deftype in tagtypes then
  4661. stabchar := 'Tt';
  4662. if assigned(typesym) then
  4663. sname := typesym.name
  4664. else
  4665. sname := ' ';
  4666. if writing_class_record_stab then
  4667. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4668. else
  4669. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4670. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,0,0');
  4671. allstabstring := strnew(st);
  4672. freemem(st,strlen(ss)+512);
  4673. strdispose(ss);
  4674. end;
  4675. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4676. var
  4677. oldtypesym : tsym;
  4678. stab_str : pchar;
  4679. anc : tobjectdef;
  4680. begin
  4681. if (stab_state in [stab_state_writing,stab_state_written]) then
  4682. exit;
  4683. stab_state:=stab_state_writing;
  4684. tstoreddef(vmtarraytype.def).concatstabto(asmlist);
  4685. { first the parents }
  4686. anc:=self;
  4687. while assigned(anc.childof) do
  4688. begin
  4689. anc:=anc.childof;
  4690. anc.concatstabto(asmlist);
  4691. end;
  4692. symtable.foreach(@field_concatstabto,asmlist);
  4693. symtable.foreach(@proc_concatstabto,asmlist);
  4694. stab_state:=stab_state_used;
  4695. if objecttype=odt_class then
  4696. begin
  4697. { Write the record class itself }
  4698. writing_class_record_stab:=true;
  4699. inherited concatstabto(asmlist);
  4700. writing_class_record_stab:=false;
  4701. { Write the invisible pointer class }
  4702. oldtypesym:=typesym;
  4703. typesym:=nil;
  4704. stab_str := allstabstring;
  4705. asmList.concat(Tai_stabs.Create(stab_str));
  4706. typesym:=oldtypesym;
  4707. end
  4708. else
  4709. inherited concatstabto(asmlist);
  4710. end;
  4711. {$endif GDB}
  4712. function tobjectdef.needs_inittable : boolean;
  4713. begin
  4714. case objecttype of
  4715. odt_class :
  4716. needs_inittable:=false;
  4717. odt_interfacecom:
  4718. needs_inittable:=true;
  4719. odt_interfacecorba:
  4720. needs_inittable:=is_related(interface_iunknown);
  4721. odt_object:
  4722. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4723. else
  4724. internalerror(200108267);
  4725. end;
  4726. end;
  4727. function tobjectdef.members_need_inittable : boolean;
  4728. begin
  4729. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4730. end;
  4731. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4732. begin
  4733. if needs_prop_entry(tsym(sym)) and
  4734. (tsym(sym).typ<>varsym) then
  4735. inc(count);
  4736. end;
  4737. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4738. var
  4739. proctypesinfo : byte;
  4740. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4741. var
  4742. typvalue : byte;
  4743. hp : psymlistitem;
  4744. address : longint;
  4745. def : tdef;
  4746. begin
  4747. if not(assigned(proc) and assigned(proc.firstsym)) then
  4748. begin
  4749. rttiList.concat(Tai_const.create(ait_const_ptr,1));
  4750. typvalue:=3;
  4751. end
  4752. else if proc.firstsym^.sym.typ=varsym then
  4753. begin
  4754. address:=0;
  4755. hp:=proc.firstsym;
  4756. def:=nil;
  4757. while assigned(hp) do
  4758. begin
  4759. case hp^.sltype of
  4760. sl_load :
  4761. begin
  4762. def:=tvarsym(hp^.sym).vartype.def;
  4763. inc(address,tvarsym(hp^.sym).fieldoffset);
  4764. end;
  4765. sl_subscript :
  4766. begin
  4767. if not(assigned(def) and (def.deftype=recorddef)) then
  4768. internalerror(200402171);
  4769. inc(address,tvarsym(hp^.sym).fieldoffset);
  4770. def:=tvarsym(hp^.sym).vartype.def;
  4771. end;
  4772. sl_vec :
  4773. begin
  4774. if not(assigned(def) and (def.deftype=arraydef)) then
  4775. internalerror(200402172);
  4776. def:=tarraydef(def).elementtype.def;
  4777. inc(address,def.size*hp^.value);
  4778. end;
  4779. end;
  4780. hp:=hp^.next;
  4781. end;
  4782. rttiList.concat(Tai_const.create(ait_const_ptr,address));
  4783. typvalue:=0;
  4784. end
  4785. else
  4786. begin
  4787. { When there was an error then procdef is not assigned }
  4788. if not assigned(proc.procdef) then
  4789. exit;
  4790. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4791. begin
  4792. rttiList.concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4793. typvalue:=1;
  4794. end
  4795. else
  4796. begin
  4797. { virtual method, write vmt offset }
  4798. rttiList.concat(Tai_const.create(ait_const_ptr,
  4799. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4800. typvalue:=2;
  4801. end;
  4802. end;
  4803. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4804. end;
  4805. begin
  4806. if needs_prop_entry(tsym(sym)) then
  4807. case tsym(sym).typ of
  4808. varsym:
  4809. begin
  4810. {$ifdef dummy}
  4811. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4812. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4813. internalerror(1509992);
  4814. { access to implicit class property as field }
  4815. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4816. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label),AT_DATA,0));
  4817. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4818. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4819. { by default stored }
  4820. rttiList.concat(Tai_const.Create_32bit(1));
  4821. { index as well as ... }
  4822. rttiList.concat(Tai_const.Create_32bit(0));
  4823. { default value are zero }
  4824. rttiList.concat(Tai_const.Create_32bit(0));
  4825. rttiList.concat(Tai_const.Create_16bit(count));
  4826. inc(count);
  4827. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4828. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4829. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4830. {$endif dummy}
  4831. end;
  4832. propertysym:
  4833. begin
  4834. if ppo_indexed in tpropertysym(sym).propoptions then
  4835. proctypesinfo:=$40
  4836. else
  4837. proctypesinfo:=0;
  4838. rttiList.concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4839. writeproc(tpropertysym(sym).readaccess,0);
  4840. writeproc(tpropertysym(sym).writeaccess,2);
  4841. { isn't it stored ? }
  4842. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4843. begin
  4844. rttiList.concat(Tai_const.create_sym(nil));
  4845. proctypesinfo:=proctypesinfo or (3 shl 4);
  4846. end
  4847. else
  4848. writeproc(tpropertysym(sym).storedaccess,4);
  4849. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4850. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4851. rttiList.concat(Tai_const.Create_16bit(count));
  4852. inc(count);
  4853. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4854. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4855. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4856. {$ifdef cpurequiresproperalignment}
  4857. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4858. {$endif cpurequiresproperalignment}
  4859. end;
  4860. else internalerror(1509992);
  4861. end;
  4862. end;
  4863. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4864. begin
  4865. if needs_prop_entry(tsym(sym)) then
  4866. begin
  4867. case tsym(sym).typ of
  4868. propertysym:
  4869. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4870. varsym:
  4871. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4872. else
  4873. internalerror(1509991);
  4874. end;
  4875. end;
  4876. end;
  4877. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4878. begin
  4879. FRTTIType:=rt;
  4880. case rt of
  4881. initrtti :
  4882. symtable.foreach(@generate_field_rtti,nil);
  4883. fullrtti :
  4884. symtable.foreach(@generate_published_child_rtti,nil);
  4885. else
  4886. internalerror(200108301);
  4887. end;
  4888. end;
  4889. type
  4890. tclasslistitem = class(TLinkedListItem)
  4891. index : longint;
  4892. p : tobjectdef;
  4893. end;
  4894. var
  4895. classtablelist : tlinkedlist;
  4896. tablecount : longint;
  4897. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4898. var
  4899. hp : tclasslistitem;
  4900. begin
  4901. hp:=tclasslistitem(classtablelist.first);
  4902. while assigned(hp) do
  4903. if hp.p=p then
  4904. begin
  4905. searchclasstablelist:=hp;
  4906. exit;
  4907. end
  4908. else
  4909. hp:=tclasslistitem(hp.next);
  4910. searchclasstablelist:=nil;
  4911. end;
  4912. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4913. var
  4914. hp : tclasslistitem;
  4915. begin
  4916. if needs_prop_entry(tsym(sym)) and
  4917. (tsym(sym).typ=varsym) then
  4918. begin
  4919. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4920. internalerror(0206001);
  4921. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4922. if not(assigned(hp)) then
  4923. begin
  4924. hp:=tclasslistitem.create;
  4925. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4926. hp.index:=tablecount;
  4927. classtablelist.concat(hp);
  4928. inc(tablecount);
  4929. end;
  4930. inc(count);
  4931. end;
  4932. end;
  4933. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4934. var
  4935. hp : tclasslistitem;
  4936. begin
  4937. if needs_prop_entry(tsym(sym)) and
  4938. (tsym(sym).typ=varsym) then
  4939. begin
  4940. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4941. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4942. if not(assigned(hp)) then
  4943. internalerror(0206002);
  4944. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4945. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4946. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4947. end;
  4948. end;
  4949. function tobjectdef.generate_field_table : tasmlabel;
  4950. var
  4951. fieldtable,
  4952. classtable : tasmlabel;
  4953. hp : tclasslistitem;
  4954. begin
  4955. classtablelist:=TLinkedList.Create;
  4956. objectlibrary.getdatalabel(fieldtable);
  4957. objectlibrary.getdatalabel(classtable);
  4958. count:=0;
  4959. tablecount:=0;
  4960. maybe_new_object_file(rttiList);
  4961. new_section(rttiList,sec_rodata,classtable.name,const_align(sizeof(aint)));
  4962. { fields }
  4963. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4964. rttiList.concat(Tai_label.Create(fieldtable));
  4965. rttiList.concat(Tai_const.Create_16bit(count));
  4966. rttiList.concat(Tai_const.Create_sym(classtable));
  4967. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4968. { generate the class table }
  4969. rttilist.concat(tai_align.create(const_align(sizeof(aint))));
  4970. rttiList.concat(Tai_label.Create(classtable));
  4971. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4972. hp:=tclasslistitem(classtablelist.first);
  4973. while assigned(hp) do
  4974. begin
  4975. rttiList.concat(Tai_const.Createname(tobjectdef(hp.p).vmt_mangledname,AT_DATA,0));
  4976. hp:=tclasslistitem(hp.next);
  4977. end;
  4978. generate_field_table:=fieldtable;
  4979. classtablelist.free;
  4980. end;
  4981. function tobjectdef.next_free_name_index : longint;
  4982. var
  4983. i : longint;
  4984. begin
  4985. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4986. i:=childof.next_free_name_index
  4987. else
  4988. i:=0;
  4989. count:=0;
  4990. symtable.foreach(@count_published_properties,nil);
  4991. next_free_name_index:=i+count;
  4992. end;
  4993. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4994. begin
  4995. case objecttype of
  4996. odt_class:
  4997. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4998. odt_object:
  4999. rttiList.concat(Tai_const.Create_8bit(tkobject));
  5000. odt_interfacecom:
  5001. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  5002. odt_interfacecorba:
  5003. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  5004. else
  5005. exit;
  5006. end;
  5007. { generate the name }
  5008. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  5009. rttiList.concat(Tai_string.Create(objrealname^));
  5010. {$ifdef cpurequiresproperalignment}
  5011. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5012. {$endif cpurequiresproperalignment}
  5013. case rt of
  5014. initrtti :
  5015. begin
  5016. rttiList.concat(Tai_const.Create_32bit(size));
  5017. if objecttype in [odt_class,odt_object] then
  5018. begin
  5019. count:=0;
  5020. FRTTIType:=rt;
  5021. symtable.foreach(@count_field_rtti,nil);
  5022. rttiList.concat(Tai_const.Create_32bit(count));
  5023. symtable.foreach(@write_field_rtti,nil);
  5024. end;
  5025. end;
  5026. fullrtti :
  5027. begin
  5028. if (oo_has_vmt in objectoptions) and
  5029. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5030. rttiList.concat(Tai_const.Createname(vmt_mangledname,AT_DATA,0))
  5031. else
  5032. rttiList.concat(Tai_const.create_sym(nil));
  5033. { write owner typeinfo }
  5034. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5035. rttiList.concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  5036. else
  5037. rttiList.concat(Tai_const.create_sym(nil));
  5038. { count total number of properties }
  5039. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5040. count:=childof.next_free_name_index
  5041. else
  5042. count:=0;
  5043. { write it }
  5044. symtable.foreach(@count_published_properties,nil);
  5045. rttiList.concat(Tai_const.Create_16bit(count));
  5046. { write unit name }
  5047. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  5048. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  5049. {$ifdef cpurequiresproperalignment}
  5050. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5051. {$endif cpurequiresproperalignment}
  5052. { write published properties count }
  5053. count:=0;
  5054. symtable.foreach(@count_published_properties,nil);
  5055. rttiList.concat(Tai_const.Create_16bit(count));
  5056. {$ifdef cpurequiresproperalignment}
  5057. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5058. {$endif cpurequiresproperalignment}
  5059. { count is used to write nameindex }
  5060. { but we need an offset of the owner }
  5061. { to give each property an own slot }
  5062. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5063. count:=childof.next_free_name_index
  5064. else
  5065. count:=0;
  5066. symtable.foreach(@write_property_info,nil);
  5067. end;
  5068. end;
  5069. end;
  5070. function tobjectdef.is_publishable : boolean;
  5071. begin
  5072. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  5073. end;
  5074. {****************************************************************************
  5075. TIMPLEMENTEDINTERFACES
  5076. ****************************************************************************}
  5077. type
  5078. tnamemap = class(TNamedIndexItem)
  5079. newname: pstring;
  5080. constructor create(const aname, anewname: string);
  5081. destructor destroy; override;
  5082. end;
  5083. constructor tnamemap.create(const aname, anewname: string);
  5084. begin
  5085. inherited createname(name);
  5086. newname:=stringdup(anewname);
  5087. end;
  5088. destructor tnamemap.destroy;
  5089. begin
  5090. stringdispose(newname);
  5091. inherited destroy;
  5092. end;
  5093. type
  5094. tprocdefstore = class(TNamedIndexItem)
  5095. procdef: tprocdef;
  5096. constructor create(aprocdef: tprocdef);
  5097. end;
  5098. constructor tprocdefstore.create(aprocdef: tprocdef);
  5099. begin
  5100. inherited create;
  5101. procdef:=aprocdef;
  5102. end;
  5103. type
  5104. timplintfentry = class(TNamedIndexItem)
  5105. intf: tobjectdef;
  5106. intfderef : tderef;
  5107. ioffs: longint;
  5108. namemappings: tdictionary;
  5109. procdefs: TIndexArray;
  5110. constructor create(aintf: tobjectdef);
  5111. constructor create_deref(const d:tderef);
  5112. destructor destroy; override;
  5113. end;
  5114. constructor timplintfentry.create(aintf: tobjectdef);
  5115. begin
  5116. inherited create;
  5117. intf:=aintf;
  5118. ioffs:=-1;
  5119. namemappings:=nil;
  5120. procdefs:=nil;
  5121. end;
  5122. constructor timplintfentry.create_deref(const d:tderef);
  5123. begin
  5124. inherited create;
  5125. intf:=nil;
  5126. intfderef:=d;
  5127. ioffs:=-1;
  5128. namemappings:=nil;
  5129. procdefs:=nil;
  5130. end;
  5131. destructor timplintfentry.destroy;
  5132. begin
  5133. if assigned(namemappings) then
  5134. namemappings.free;
  5135. if assigned(procdefs) then
  5136. procdefs.free;
  5137. inherited destroy;
  5138. end;
  5139. constructor timplementedinterfaces.create;
  5140. begin
  5141. finterfaces:=tindexarray.create(1);
  5142. end;
  5143. destructor timplementedinterfaces.destroy;
  5144. begin
  5145. finterfaces.destroy;
  5146. end;
  5147. function timplementedinterfaces.count: longint;
  5148. begin
  5149. count:=finterfaces.count;
  5150. end;
  5151. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5152. begin
  5153. if (intfindex<1) or (intfindex>count) then
  5154. InternalError(200006123);
  5155. end;
  5156. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5157. begin
  5158. checkindex(intfindex);
  5159. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5160. end;
  5161. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5162. begin
  5163. checkindex(intfindex);
  5164. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5165. end;
  5166. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5167. begin
  5168. checkindex(intfindex);
  5169. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5170. end;
  5171. function timplementedinterfaces.searchintf(def: tdef): longint;
  5172. var
  5173. i: longint;
  5174. begin
  5175. i:=1;
  5176. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5177. if i<=count then
  5178. searchintf:=i
  5179. else
  5180. searchintf:=-1;
  5181. end;
  5182. procedure timplementedinterfaces.buildderef;
  5183. var
  5184. i: longint;
  5185. begin
  5186. for i:=1 to count do
  5187. with timplintfentry(finterfaces.search(i)) do
  5188. intfderef.build(intf);
  5189. end;
  5190. procedure timplementedinterfaces.deref;
  5191. var
  5192. i: longint;
  5193. begin
  5194. for i:=1 to count do
  5195. with timplintfentry(finterfaces.search(i)) do
  5196. intf:=tobjectdef(intfderef.resolve);
  5197. end;
  5198. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5199. begin
  5200. finterfaces.insert(timplintfentry.create_deref(d));
  5201. end;
  5202. procedure timplementedinterfaces.addintf(def: tdef);
  5203. begin
  5204. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5205. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5206. internalerror(200006124);
  5207. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5208. end;
  5209. procedure timplementedinterfaces.clearmappings;
  5210. var
  5211. i: longint;
  5212. begin
  5213. for i:=1 to count do
  5214. with timplintfentry(finterfaces.search(i)) do
  5215. begin
  5216. if assigned(namemappings) then
  5217. namemappings.free;
  5218. namemappings:=nil;
  5219. end;
  5220. end;
  5221. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5222. begin
  5223. checkindex(intfindex);
  5224. with timplintfentry(finterfaces.search(intfindex)) do
  5225. begin
  5226. if not assigned(namemappings) then
  5227. namemappings:=tdictionary.create;
  5228. namemappings.insert(tnamemap.create(name,newname));
  5229. end;
  5230. end;
  5231. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5232. begin
  5233. checkindex(intfindex);
  5234. if not assigned(nextexist) then
  5235. with timplintfentry(finterfaces.search(intfindex)) do
  5236. begin
  5237. if assigned(namemappings) then
  5238. nextexist:=namemappings.search(name)
  5239. else
  5240. nextexist:=nil;
  5241. end;
  5242. if assigned(nextexist) then
  5243. begin
  5244. getmappings:=tnamemap(nextexist).newname^;
  5245. nextexist:=tnamemap(nextexist).listnext;
  5246. end
  5247. else
  5248. getmappings:='';
  5249. end;
  5250. procedure timplementedinterfaces.clearimplprocs;
  5251. var
  5252. i: longint;
  5253. begin
  5254. for i:=1 to count do
  5255. with timplintfentry(finterfaces.search(i)) do
  5256. begin
  5257. if assigned(procdefs) then
  5258. procdefs.free;
  5259. procdefs:=nil;
  5260. end;
  5261. end;
  5262. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5263. begin
  5264. checkindex(intfindex);
  5265. with timplintfentry(finterfaces.search(intfindex)) do
  5266. begin
  5267. if not assigned(procdefs) then
  5268. procdefs:=tindexarray.create(4);
  5269. procdefs.insert(tprocdefstore.create(procdef));
  5270. end;
  5271. end;
  5272. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5273. begin
  5274. checkindex(intfindex);
  5275. with timplintfentry(finterfaces.search(intfindex)) do
  5276. if assigned(procdefs) then
  5277. implproccount:=procdefs.count
  5278. else
  5279. implproccount:=0;
  5280. end;
  5281. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5282. begin
  5283. checkindex(intfindex);
  5284. with timplintfentry(finterfaces.search(intfindex)) do
  5285. if assigned(procdefs) then
  5286. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5287. else
  5288. internalerror(200006131);
  5289. end;
  5290. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5291. var
  5292. possible: boolean;
  5293. i: longint;
  5294. iiep1: TIndexArray;
  5295. iiep2: TIndexArray;
  5296. begin
  5297. checkindex(intfindex);
  5298. checkindex(remainindex);
  5299. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5300. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5301. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5302. begin
  5303. possible:=true;
  5304. weight:=0;
  5305. end
  5306. else
  5307. begin
  5308. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5309. i:=1;
  5310. while (possible) and (i<=iiep1.count) do
  5311. begin
  5312. possible:=
  5313. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5314. inc(i);
  5315. end;
  5316. if possible then
  5317. weight:=iiep1.count;
  5318. end;
  5319. isimplmergepossible:=possible;
  5320. end;
  5321. {****************************************************************************
  5322. TFORWARDDEF
  5323. ****************************************************************************}
  5324. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5325. var
  5326. oldregisterdef : boolean;
  5327. begin
  5328. { never register the forwarddefs, they are disposed at the
  5329. end of the type declaration block }
  5330. oldregisterdef:=registerdef;
  5331. registerdef:=false;
  5332. inherited create;
  5333. registerdef:=oldregisterdef;
  5334. deftype:=forwarddef;
  5335. tosymname:=stringdup(s);
  5336. forwardpos:=pos;
  5337. end;
  5338. function tforwarddef.gettypename:string;
  5339. begin
  5340. gettypename:='unresolved forward to '+tosymname^;
  5341. end;
  5342. destructor tforwarddef.destroy;
  5343. begin
  5344. if assigned(tosymname) then
  5345. stringdispose(tosymname);
  5346. inherited destroy;
  5347. end;
  5348. {****************************************************************************
  5349. TERRORDEF
  5350. ****************************************************************************}
  5351. constructor terrordef.create;
  5352. begin
  5353. inherited create;
  5354. deftype:=errordef;
  5355. end;
  5356. {$ifdef GDB}
  5357. function terrordef.stabstring : pchar;
  5358. begin
  5359. stabstring:=strpnew('error'+numberstring);
  5360. end;
  5361. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5362. begin
  5363. { No internal error needed, an normal error is already
  5364. thrown }
  5365. end;
  5366. {$endif GDB}
  5367. function terrordef.gettypename:string;
  5368. begin
  5369. gettypename:='<erroneous type>';
  5370. end;
  5371. function terrordef.getmangledparaname:string;
  5372. begin
  5373. getmangledparaname:='error';
  5374. end;
  5375. {****************************************************************************
  5376. Definition Helpers
  5377. ****************************************************************************}
  5378. function is_interfacecom(def: tdef): boolean;
  5379. begin
  5380. is_interfacecom:=
  5381. assigned(def) and
  5382. (def.deftype=objectdef) and
  5383. (tobjectdef(def).objecttype=odt_interfacecom);
  5384. end;
  5385. function is_interfacecorba(def: tdef): boolean;
  5386. begin
  5387. is_interfacecorba:=
  5388. assigned(def) and
  5389. (def.deftype=objectdef) and
  5390. (tobjectdef(def).objecttype=odt_interfacecorba);
  5391. end;
  5392. function is_interface(def: tdef): boolean;
  5393. begin
  5394. is_interface:=
  5395. assigned(def) and
  5396. (def.deftype=objectdef) and
  5397. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5398. end;
  5399. function is_class(def: tdef): boolean;
  5400. begin
  5401. is_class:=
  5402. assigned(def) and
  5403. (def.deftype=objectdef) and
  5404. (tobjectdef(def).objecttype=odt_class);
  5405. end;
  5406. function is_object(def: tdef): boolean;
  5407. begin
  5408. is_object:=
  5409. assigned(def) and
  5410. (def.deftype=objectdef) and
  5411. (tobjectdef(def).objecttype=odt_object);
  5412. end;
  5413. function is_cppclass(def: tdef): boolean;
  5414. begin
  5415. is_cppclass:=
  5416. assigned(def) and
  5417. (def.deftype=objectdef) and
  5418. (tobjectdef(def).objecttype=odt_cppclass);
  5419. end;
  5420. function is_class_or_interface(def: tdef): boolean;
  5421. begin
  5422. is_class_or_interface:=
  5423. assigned(def) and
  5424. (def.deftype=objectdef) and
  5425. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5426. end;
  5427. end.
  5428. {
  5429. $Log$
  5430. Revision 1.264 2004-11-03 09:46:34 florian
  5431. * fixed writing of para locations for procedures with explicit locations for parameters
  5432. Revision 1.263 2004/11/01 23:30:11 peter
  5433. * support > 32bit accesses for x86_64
  5434. * rewrote array size checking to support 64bit
  5435. Revision 1.262 2004/11/01 15:33:12 florian
  5436. * fixed type information for dyn. arrays on 64 bit systems
  5437. Revision 1.261 2004/10/31 21:45:03 peter
  5438. * generic tlocation
  5439. * move tlocation to cgutils
  5440. Revision 1.260 2004/10/26 15:02:33 peter
  5441. * align arraydef rtti
  5442. Revision 1.259 2004/10/15 09:14:17 mazen
  5443. - remove $IFDEF DELPHI and related code
  5444. - remove $IFDEF FPCPROCVAR and related code
  5445. Revision 1.258 2004/10/10 21:08:55 peter
  5446. * parameter regvar fixes
  5447. Revision 1.257 2004/10/04 21:23:15 florian
  5448. * rtti alignment fixed
  5449. Revision 1.256 2004/09/21 23:36:51 hajny
  5450. * SetTextLineEnding implemented, FileRec.Name position alignment for CPU64
  5451. Revision 1.255 2004/09/21 17:25:12 peter
  5452. * paraloc branch merged
  5453. Revision 1.254 2004/09/14 16:33:17 peter
  5454. * restart sorting of enums when deref is called, this is needed when
  5455. a unit is reloaded
  5456. Revision 1.253.4.1 2004/08/31 20:43:06 peter
  5457. * paraloc patch
  5458. Revision 1.253 2004/08/27 21:59:26 peter
  5459. browser disabled
  5460. uf_local_symtable ppu flag when a localsymtable is stored
  5461. Revision 1.252 2004/08/17 16:29:21 jonas
  5462. + padalgingment field for recordsymtables (saved by recorddefs)
  5463. + support for Macintosh PowerPC alignment (if the first field of a record
  5464. or union has an alignment > 4, then the record or union size must be
  5465. padded to a multiple of this size)
  5466. Revision 1.251 2004/08/15 15:05:16 peter
  5467. * fixed padding of records to alignment
  5468. Revision 1.250 2004/08/14 14:50:42 florian
  5469. * fixed several sparc alignment issues
  5470. + Jonas' inline node patch; non functional yet
  5471. Revision 1.249 2004/08/07 14:52:45 florian
  5472. * fixed web bug 3226: type p = type pointer;
  5473. Revision 1.248 2004/07/19 19:15:50 florian
  5474. * fixed funcret_paraloc writing in units
  5475. Revision 1.247 2004/07/14 21:37:41 olle
  5476. - removed unused types
  5477. Revision 1.246 2004/07/12 09:14:04 jonas
  5478. * inline procedures at the node tree level, but only under some very
  5479. limited circumstances for now (only procedures, and only if they have
  5480. no or only vs_out/vs_var parameters).
  5481. * fixed ppudump for inline procedures
  5482. * fixed ppudump for ppc
  5483. Revision 1.245 2004/07/09 22:17:32 peter
  5484. * revert has_localst patch
  5485. * replace aktstaticsymtable/aktglobalsymtable with current_module
  5486. Revision 1.244 2004/07/06 19:52:04 peter
  5487. * fix storing of localst in ppu
  5488. Revision 1.243 2004/06/20 08:55:30 florian
  5489. * logs truncated
  5490. Revision 1.242 2004/06/18 15:16:46 peter
  5491. * remove obsolete cardinal() typecasts
  5492. Revision 1.241 2004/06/16 20:07:09 florian
  5493. * dwarf branch merged
  5494. Revision 1.240 2004/05/25 18:51:14 peter
  5495. * range check error
  5496. Revision 1.239 2004/05/23 20:57:10 peter
  5497. * removed unused voidprocdef
  5498. Revision 1.238 2004/05/23 15:23:30 peter
  5499. * fixed qword(longint) that removed sign from the number
  5500. * removed code in the compiler that relied on wrong qword(longint)
  5501. code generation
  5502. }