symdef.pas 198 KB

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