symdef.pas 190 KB

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