2
0

symdef.pas 198 KB

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