symdef.pas 187 KB

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