symdef.pas 179 KB

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