symdef.pas 176 KB

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