symdef.pas 208 KB

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