symdef.pas 197 KB

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