symdef.pas 176 KB

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