symdef.pas 185 KB

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