symdef.pas 183 KB

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