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