symdef.pas 213 KB

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