symdef.pas 196 KB

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