symdef.pas 187 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946
  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. cclasses,
  23. { global }
  24. globtype,globals,tokens,constexp,
  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 }
  42. tstoreddef = class(tdef)
  43. protected
  44. typesymderef : tderef;
  45. public
  46. {$ifdef EXTDEBUG}
  47. fileinfo : tfileposinfo;
  48. {$endif}
  49. { generic support }
  50. genericdef : tstoreddef;
  51. genericdefderef : tderef;
  52. generictokenbuf : tdynamicarray;
  53. { Set if PPU was generated with another
  54. endianess as current compiler or ppudump utils }
  55. change_endian : boolean;
  56. constructor create(dt:tdeftyp);
  57. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  58. destructor destroy;override;
  59. function getcopy : tstoreddef;virtual;
  60. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  61. procedure buildderef;override;
  62. procedure buildderefimpl;override;
  63. procedure deref;override;
  64. procedure derefimpl;override;
  65. function size:asizeint;override;
  66. function getvardef:longint;override;
  67. function alignment:shortint;override;
  68. function is_publishable : boolean;override;
  69. function needs_inittable : boolean;override;
  70. function rtti_mangledname(rt:trttitype):string;override;
  71. function OwnerHierarchyName: string; override;
  72. function in_currentunit: boolean;
  73. { regvars }
  74. function is_intregable : boolean;
  75. function is_fpuregable : boolean;
  76. { generics }
  77. procedure initgeneric;
  78. private
  79. savesize : asizeuint;
  80. end;
  81. tfiletyp = (ft_text,ft_typed,ft_untyped);
  82. tfiledef = class(tstoreddef)
  83. filetyp : tfiletyp;
  84. typedfiledef : tdef;
  85. typedfiledefderef : tderef;
  86. constructor createtext;
  87. constructor createuntyped;
  88. constructor createtyped(def : tdef);
  89. constructor ppuload(ppufile:tcompilerppufile);
  90. function getcopy : tstoreddef;override;
  91. procedure ppuwrite(ppufile:tcompilerppufile);override;
  92. procedure buildderef;override;
  93. procedure deref;override;
  94. function GetTypeName:string;override;
  95. function getmangledparaname:string;override;
  96. procedure setsize;
  97. end;
  98. tvariantdef = class(tstoreddef)
  99. varianttype : tvarianttype;
  100. constructor create(v : tvarianttype);
  101. constructor ppuload(ppufile:tcompilerppufile);
  102. function getcopy : tstoreddef;override;
  103. function GetTypeName:string;override;
  104. procedure ppuwrite(ppufile:tcompilerppufile);override;
  105. function getvardef:longint;override;
  106. procedure setsize;
  107. function is_publishable : boolean;override;
  108. function needs_inittable : boolean;override;
  109. end;
  110. tformaldef = class(tstoreddef)
  111. typed:boolean;
  112. constructor create(Atyped:boolean);
  113. constructor ppuload(ppufile:tcompilerppufile);
  114. procedure ppuwrite(ppufile:tcompilerppufile);override;
  115. function GetTypeName:string;override;
  116. end;
  117. tforwarddef = class(tstoreddef)
  118. tosymname : pshortstring;
  119. forwardpos : tfileposinfo;
  120. constructor create(const s:string;const pos:tfileposinfo);
  121. destructor destroy;override;
  122. function getcopy:tstoreddef;override;
  123. function GetTypeName:string;override;
  124. end;
  125. tundefineddef = class(tstoreddef)
  126. constructor create;
  127. constructor ppuload(ppufile:tcompilerppufile);
  128. procedure ppuwrite(ppufile:tcompilerppufile);override;
  129. function GetTypeName:string;override;
  130. end;
  131. terrordef = class(tstoreddef)
  132. constructor create;
  133. procedure ppuwrite(ppufile:tcompilerppufile);override;
  134. function GetTypeName:string;override;
  135. function getmangledparaname : string;override;
  136. end;
  137. tabstractpointerdef = class(tstoreddef)
  138. pointeddef : tdef;
  139. pointeddefderef : tderef;
  140. constructor create(dt:tdeftyp;def:tdef);
  141. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  142. procedure ppuwrite(ppufile:tcompilerppufile);override;
  143. procedure buildderef;override;
  144. procedure deref;override;
  145. end;
  146. tpointerdef = class(tabstractpointerdef)
  147. is_far : boolean;
  148. has_pointer_math : boolean;
  149. constructor create(def:tdef);
  150. constructor createfar(def:tdef);
  151. function getcopy:tstoreddef;override;
  152. constructor ppuload(ppufile:tcompilerppufile);
  153. procedure ppuwrite(ppufile:tcompilerppufile);override;
  154. function GetTypeName:string;override;
  155. end;
  156. tprocdef = class;
  157. { tabstractrecorddef }
  158. tabstractrecorddef= class(tstoreddef)
  159. objname,
  160. objrealname : PShortString;
  161. symtable : TSymtable;
  162. cloneddef : tabstractrecorddef;
  163. cloneddefderef : tderef;
  164. objectoptions : tobjectoptions;
  165. constructor create(const n:string; dt:tdeftyp);
  166. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  167. procedure ppuwrite(ppufile:tcompilerppufile);override;
  168. destructor destroy; override;
  169. procedure check_forwards; virtual;
  170. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  171. function GetSymtable(t:tGetSymtable):TSymtable;override;
  172. function is_packed:boolean;
  173. function RttiName: string;
  174. { enumerator support }
  175. function search_enumerator_get: tprocdef; virtual;
  176. function search_enumerator_move: tprocdef; virtual;
  177. function search_enumerator_current: tsym; virtual;
  178. end;
  179. trecorddef = class(tabstractrecorddef)
  180. public
  181. isunion : boolean;
  182. constructor create(const n:string; p:TSymtable);
  183. constructor ppuload(ppufile:tcompilerppufile);
  184. destructor destroy;override;
  185. function getcopy : tstoreddef;override;
  186. procedure ppuwrite(ppufile:tcompilerppufile);override;
  187. procedure buildderef;override;
  188. procedure deref;override;
  189. function size:asizeint;override;
  190. function alignment : shortint;override;
  191. function padalignment: shortint;
  192. function GetTypeName:string;override;
  193. { debug }
  194. function needs_inittable : boolean;override;
  195. end;
  196. tobjectdef = class;
  197. { TImplementedInterface }
  198. TImplementedInterface = class
  199. IntfDef : tobjectdef;
  200. IntfDefDeref : tderef;
  201. IType : tinterfaceentrytype;
  202. IOffset : longint;
  203. VtblImplIntf : TImplementedInterface;
  204. NameMappings : TFPHashList;
  205. ProcDefs : TFPObjectList;
  206. ImplementsGetter : tsym;
  207. constructor create(aintf: tobjectdef);
  208. constructor create_deref(d:tderef);
  209. destructor destroy; override;
  210. function getcopy:TImplementedInterface;
  211. procedure buildderef;
  212. procedure deref;
  213. procedure AddMapping(const origname, newname: string);
  214. function GetMapping(const origname: string):string;
  215. procedure AddImplProc(pd:tprocdef);
  216. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  217. end;
  218. { tvmtentry }
  219. tvmtentry = record
  220. procdef : tprocdef;
  221. procdefderef : tderef;
  222. visibility : tvisibility;
  223. end;
  224. pvmtentry = ^tvmtentry;
  225. { tobjectdef }
  226. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  227. pmvcallstaticinfo = ^tmvcallstaticinfo;
  228. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  229. tobjectdef = class(tabstractrecorddef)
  230. private
  231. fcurrent_dispid: longint;
  232. public
  233. dwarf_struct_lab : tasmsymbol;
  234. childof : tobjectdef;
  235. childofderef : tderef;
  236. { for Object Pascal helpers }
  237. extendeddef : tdef;
  238. extendeddefderef: tderef;
  239. { for C++ classes: name of the library this class is imported from }
  240. import_lib,
  241. { for Objective-C: protocols and classes can have the same name there }
  242. objextname : pshortstring;
  243. { to be able to have a variable vmt position }
  244. { and no vmt field for objects without virtuals }
  245. vmtentries : TFPList;
  246. vmcallstaticinfo : pmvcallstaticinfo;
  247. vmt_offset : longint;
  248. iidguid : pguid;
  249. iidstr : pshortstring;
  250. { store implemented interfaces defs and name mappings }
  251. ImplementedInterfaces : TFPObjectList;
  252. writing_class_record_dbginfo,
  253. { a class of this type has been created in this module }
  254. created_in_current_module,
  255. { a loadvmtnode for this class has been created in this
  256. module, so if a classrefdef variable of this or a parent
  257. class is used somewhere to instantiate a class, then this
  258. class may be instantiated
  259. }
  260. maybe_created_in_current_module,
  261. { a "class of" this particular class has been created in
  262. this module
  263. }
  264. classref_created_in_current_module : boolean;
  265. objecttype : tobjecttyp;
  266. constructor create(ot:tobjecttyp;const n:string;c:tobjectdef);
  267. constructor ppuload(ppufile:tcompilerppufile);
  268. destructor destroy;override;
  269. function getcopy : tstoreddef;override;
  270. procedure ppuwrite(ppufile:tcompilerppufile);override;
  271. function GetTypeName:string;override;
  272. procedure buildderef;override;
  273. procedure deref;override;
  274. procedure buildderefimpl;override;
  275. procedure derefimpl;override;
  276. procedure resetvmtentries;
  277. procedure copyvmtentries(objdef:tobjectdef);
  278. function getparentdef:tdef;override;
  279. function size : asizeint;override;
  280. function alignment:shortint;override;
  281. function vmtmethodoffset(index:longint):longint;
  282. function members_need_inittable : boolean;
  283. function find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  284. { this should be called when this class implements an interface }
  285. procedure prepareguid;
  286. function is_publishable : boolean;override;
  287. function is_related(d : tdef) : boolean;override;
  288. function needs_inittable : boolean;override;
  289. function rtti_mangledname(rt:trttitype):string;override;
  290. function vmt_mangledname : string;
  291. procedure check_forwards; override;
  292. procedure insertvmt;
  293. procedure set_parent(c : tobjectdef);
  294. function find_destructor: tprocdef;
  295. function implements_any_interfaces: boolean;
  296. { dispinterface support }
  297. function get_next_dispid: longint;
  298. { enumerator support }
  299. function search_enumerator_get: tprocdef; override;
  300. function search_enumerator_move: tprocdef; override;
  301. function search_enumerator_current: tsym; override;
  302. { WPO }
  303. procedure register_created_object_type;override;
  304. procedure register_maybe_created_object_type;
  305. procedure register_created_classref_type;
  306. procedure register_vmt_call(index:longint);
  307. { ObjC }
  308. procedure finish_objc_data;
  309. function check_objc_types: boolean;
  310. { C++ }
  311. procedure finish_cpp_data;
  312. end;
  313. tclassrefdef = class(tabstractpointerdef)
  314. constructor create(def:tdef);
  315. constructor ppuload(ppufile:tcompilerppufile);
  316. procedure ppuwrite(ppufile:tcompilerppufile);override;
  317. function getcopy:tstoreddef;override;
  318. function GetTypeName:string;override;
  319. function is_publishable : boolean;override;
  320. function rtti_mangledname(rt:trttitype):string;override;
  321. procedure register_created_object_type;override;
  322. end;
  323. tarraydef = class(tstoreddef)
  324. lowrange,
  325. highrange : asizeint;
  326. rangedef : tdef;
  327. rangedefderef : tderef;
  328. arrayoptions : tarraydefoptions;
  329. symtable : TSymtable;
  330. protected
  331. _elementdef : tdef;
  332. _elementdefderef : tderef;
  333. procedure setelementdef(def:tdef);
  334. public
  335. function elesize : asizeint;
  336. function elepackedbitsize : asizeint;
  337. function elecount : asizeuint;
  338. constructor create_from_pointer(def:tdef);
  339. constructor create(l,h:asizeint;def:tdef);
  340. constructor ppuload(ppufile:tcompilerppufile);
  341. destructor destroy; override;
  342. function getcopy : tstoreddef;override;
  343. procedure ppuwrite(ppufile:tcompilerppufile);override;
  344. function GetTypeName:string;override;
  345. function getmangledparaname : string;override;
  346. procedure buildderef;override;
  347. procedure deref;override;
  348. function size : asizeint;override;
  349. function alignment : shortint;override;
  350. { returns the label of the range check string }
  351. function needs_inittable : boolean;override;
  352. property elementdef : tdef read _elementdef write setelementdef;
  353. function is_publishable : boolean;override;
  354. end;
  355. torddef = class(tstoreddef)
  356. low,high : TConstExprInt;
  357. ordtype : tordtype;
  358. constructor create(t : tordtype;v,b : TConstExprInt);
  359. constructor ppuload(ppufile:tcompilerppufile);
  360. function getcopy : tstoreddef;override;
  361. procedure ppuwrite(ppufile:tcompilerppufile);override;
  362. function is_publishable : boolean;override;
  363. function GetTypeName:string;override;
  364. function alignment:shortint;override;
  365. procedure setsize;
  366. function packedbitsize: asizeint; override;
  367. function getvardef : longint;override;
  368. end;
  369. tfloatdef = class(tstoreddef)
  370. floattype : tfloattype;
  371. constructor create(t : tfloattype);
  372. constructor ppuload(ppufile:tcompilerppufile);
  373. function getcopy : tstoreddef;override;
  374. procedure ppuwrite(ppufile:tcompilerppufile);override;
  375. function GetTypeName:string;override;
  376. function is_publishable : boolean;override;
  377. function alignment:shortint;override;
  378. procedure setsize;
  379. function getvardef:longint;override;
  380. end;
  381. { tabstractprocdef }
  382. tabstractprocdef = class(tstoreddef)
  383. { saves a definition to the return type }
  384. returndef : tdef;
  385. returndefderef : tderef;
  386. parast : TSymtable;
  387. paras : tparalist;
  388. proctypeoption : tproctypeoption;
  389. proccalloption : tproccalloption;
  390. procoptions : tprocoptions;
  391. callerargareasize,
  392. calleeargareasize: pint;
  393. {$ifdef m68k}
  394. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  395. {$endif}
  396. funcretloc : array[tcallercallee] of TCGPara;
  397. has_paraloc_info : tcallercallee; { paraloc info is available }
  398. { number of user visible parameters }
  399. maxparacount,
  400. minparacount : byte;
  401. constructor create(dt:tdeftyp;level:byte);
  402. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  403. destructor destroy;override;
  404. procedure ppuwrite(ppufile:tcompilerppufile);override;
  405. procedure buildderef;override;
  406. procedure deref;override;
  407. procedure calcparas;
  408. function typename_paras(showhidden:boolean): string;
  409. function is_methodpointer:boolean;virtual;
  410. function is_addressonly:boolean;virtual;
  411. function no_self_node:boolean;
  412. procedure check_mark_as_nested;
  413. procedure init_paraloc_info(side: tcallercallee);
  414. function stack_tainting_parameter(side: tcallercallee): boolean;
  415. private
  416. procedure count_para(p:TObject;arg:pointer);
  417. procedure insert_para(p:TObject;arg:pointer);
  418. end;
  419. tprocvardef = class(tabstractprocdef)
  420. constructor create(level:byte);
  421. constructor ppuload(ppufile:tcompilerppufile);
  422. function getcopy : tstoreddef;override;
  423. procedure ppuwrite(ppufile:tcompilerppufile);override;
  424. function GetSymtable(t:tGetSymtable):TSymtable;override;
  425. function size : asizeint;override;
  426. function GetTypeName:string;override;
  427. function is_publishable : boolean;override;
  428. function is_methodpointer:boolean;override;
  429. function is_addressonly:boolean;override;
  430. function getmangledparaname:string;override;
  431. end;
  432. tmessageinf = record
  433. case integer of
  434. 0 : (str : pshortstring);
  435. 1 : (i : longint);
  436. end;
  437. tinlininginfo = record
  438. { node tree }
  439. code : tnode;
  440. flags : tprocinfoflags;
  441. end;
  442. pinlininginfo = ^tinlininginfo;
  443. {$ifdef oldregvars}
  444. { register variables }
  445. pregvarinfo = ^tregvarinfo;
  446. tregvarinfo = record
  447. regvars : array[1..maxvarregs] of tsym;
  448. regvars_para : array[1..maxvarregs] of boolean;
  449. regvars_refs : array[1..maxvarregs] of longint;
  450. fpuregvars : array[1..maxfpuvarregs] of tsym;
  451. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  452. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  453. end;
  454. {$endif oldregvars}
  455. { tprocdef }
  456. tprocdef = class(tabstractprocdef)
  457. private
  458. _mangledname : pshortstring;
  459. public
  460. messageinf : tmessageinf;
  461. dispid : longint;
  462. {$ifndef EXTDEBUG}
  463. { where is this function defined and what were the symbol
  464. flags, needed here because there
  465. is only one symbol for all overloaded functions
  466. EXTDEBUG has fileinfo in tdef (PFV) }
  467. fileinfo : tfileposinfo;
  468. {$endif}
  469. symoptions : tsymoptions;
  470. deprecatedmsg : pshortstring;
  471. { symbol owning this definition }
  472. procsym : tsym;
  473. procsymderef : tderef;
  474. { alias names }
  475. aliasnames : TCmdStrList;
  476. { symtables }
  477. localst : TSymtable;
  478. funcretsym : tsym;
  479. funcretsymderef : tderef;
  480. struct : tabstractrecorddef;
  481. structderef : tderef;
  482. {$if defined(powerpc) or defined(m68k)}
  483. { library symbol for AmigaOS/MorphOS }
  484. libsym : tsym;
  485. libsymderef : tderef;
  486. {$endif powerpc or m68k}
  487. { name of the result variable to insert in the localsymtable }
  488. resultname : pshortstring;
  489. { import info }
  490. import_dll,
  491. import_name : pshortstring;
  492. { info for inlining the subroutine, if this pointer is nil,
  493. the procedure can't be inlined }
  494. inlininginfo : pinlininginfo;
  495. {$ifdef oldregvars}
  496. regvarinfo: pregvarinfo;
  497. {$endif oldregvars}
  498. { interrupt vector }
  499. interruptvector : longint;
  500. { First/last assembler symbol/instruction in aasmoutput list.
  501. Note: initialised after compiling the code for the procdef, but
  502. not saved to/restored from ppu. Used when inserting debug info }
  503. procstarttai,
  504. procendtai : tai;
  505. import_nr : word;
  506. extnumber : word;
  507. {$ifdef i386}
  508. fpu_used : byte;
  509. {$endif i386}
  510. visibility : tvisibility;
  511. { true, if the procedure is only declared
  512. (forward procedure) }
  513. forwarddef,
  514. { true if the procedure is declared in the interface }
  515. interfacedef : boolean;
  516. { true if the procedure has a forward declaration }
  517. hasforward : boolean;
  518. constructor create(level:byte);
  519. constructor ppuload(ppufile:tcompilerppufile);
  520. destructor destroy;override;
  521. procedure ppuwrite(ppufile:tcompilerppufile);override;
  522. procedure buildderef;override;
  523. procedure buildderefimpl;override;
  524. procedure deref;override;
  525. procedure derefimpl;override;
  526. function GetSymtable(t:tGetSymtable):TSymtable;override;
  527. function GetTypeName : string;override;
  528. function mangledname : string;
  529. procedure setmangledname(const s : string);
  530. function fullprocname(showhidden:boolean):string;
  531. function cplusplusmangledname : string;
  532. function objcmangledname : string;
  533. function is_methodpointer:boolean;override;
  534. function is_addressonly:boolean;override;
  535. procedure make_external;
  536. end;
  537. { single linked list of overloaded procs }
  538. pprocdeflist = ^tprocdeflist;
  539. tprocdeflist = record
  540. def : tprocdef;
  541. defderef : tderef;
  542. next : pprocdeflist;
  543. end;
  544. tstringdef = class(tstoreddef)
  545. encoding : tstringencoding;
  546. stringtype : tstringtype;
  547. len : asizeint;
  548. constructor createshort(l : byte);
  549. constructor loadshort(ppufile:tcompilerppufile);
  550. constructor createlong(l : asizeint);
  551. constructor loadlong(ppufile:tcompilerppufile);
  552. constructor createansi(aencoding:tstringencoding);
  553. constructor loadansi(ppufile:tcompilerppufile);
  554. constructor createwide;
  555. constructor loadwide(ppufile:tcompilerppufile);
  556. constructor createunicode;
  557. constructor loadunicode(ppufile:tcompilerppufile);
  558. function getcopy : tstoreddef;override;
  559. function stringtypname:string;
  560. procedure ppuwrite(ppufile:tcompilerppufile);override;
  561. function GetTypeName:string;override;
  562. function getmangledparaname:string;override;
  563. function is_publishable : boolean;override;
  564. function alignment : shortint;override;
  565. function needs_inittable : boolean;override;
  566. function getvardef:longint;override;
  567. end;
  568. { tenumdef }
  569. tenumdef = class(tstoreddef)
  570. minval,
  571. maxval : asizeint;
  572. basedef : tenumdef;
  573. basedefderef : tderef;
  574. symtable : TSymtable;
  575. has_jumps : boolean;
  576. constructor create;
  577. constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  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. procedure calcsavesize;
  587. function packedbitsize: asizeint; override;
  588. procedure setmax(_max:asizeint);
  589. procedure setmin(_min:asizeint);
  590. function min:asizeint;
  591. function max:asizeint;
  592. function getfirstsym:tsym;
  593. end;
  594. tsetdef = class(tstoreddef)
  595. elementdef : tdef;
  596. elementdefderef : tderef;
  597. setbase,
  598. setmax : aword;
  599. constructor create(def:tdef;low, high : asizeint);
  600. constructor ppuload(ppufile:tcompilerppufile);
  601. function getcopy : tstoreddef;override;
  602. procedure ppuwrite(ppufile:tcompilerppufile);override;
  603. procedure buildderef;override;
  604. procedure deref;override;
  605. function GetTypeName:string;override;
  606. function is_publishable : boolean;override;
  607. end;
  608. tdefawaresymtablestack = class(TSymtablestack)
  609. private
  610. procedure addhelpers(st: TSymtable);
  611. procedure removehelpers(st: TSymtable);
  612. public
  613. procedure push(st: TSymtable); override;
  614. procedure pop(st: TSymtable); override;
  615. end;
  616. var
  617. current_structdef: tabstractrecorddef; { used for private functions check !! }
  618. current_genericdef: tstoreddef; { used to reject declaration of generic class inside generic class }
  619. current_specializedef: tstoreddef; { used to implement usage of generic class in itself }
  620. { default types }
  621. generrordef, { error in definition }
  622. voidpointertype, { pointer for Void-pointeddef }
  623. charpointertype, { pointer for Char-pointeddef }
  624. widecharpointertype, { pointer for WideChar-pointeddef }
  625. voidfarpointertype,
  626. cundefinedtype,
  627. cformaltype, { unique formal definition }
  628. ctypedformaltype, { unique typed formal definition }
  629. voidtype, { Void (procedure) }
  630. cchartype, { Char }
  631. cwidechartype, { WideChar }
  632. pasbool8type, { boolean type }
  633. pasbool16type,
  634. pasbool32type,
  635. pasbool64type,
  636. bool8type,
  637. bool16type,
  638. bool32type,
  639. bool64type, { implement me }
  640. u8inttype, { 8-Bit unsigned integer }
  641. s8inttype, { 8-Bit signed integer }
  642. u16inttype, { 16-Bit unsigned integer }
  643. s16inttype, { 16-Bit signed integer }
  644. u32inttype, { 32-Bit unsigned integer }
  645. s32inttype, { 32-Bit signed integer }
  646. u64inttype, { 64-bit unsigned integer }
  647. s64inttype, { 64-bit signed integer }
  648. s32floattype, { 32 bit floating point number }
  649. s64floattype, { 64 bit floating point number }
  650. s80floattype, { 80 bit floating point number }
  651. sc80floattype, { 80 bit floating point number but stored like in C }
  652. s64currencytype, { pointer to a currency type }
  653. cshortstringtype, { pointer to type of short string const }
  654. clongstringtype, { pointer to type of long string const }
  655. cansistringtype, { pointer to type of ansi string const }
  656. cwidestringtype, { pointer to type of wide string const }
  657. cunicodestringtype,
  658. openshortstringtype, { pointer to type of an open shortstring,
  659. needed for readln() }
  660. openchararraytype, { pointer to type of an open array of char,
  661. needed for readln() }
  662. cfiletype, { get the same definition for all file }
  663. { used for stabs }
  664. methodpointertype, { typecasting of methodpointers to extract self }
  665. hresultdef,
  666. { we use only one variant def for every variant class }
  667. cvarianttype,
  668. colevarianttype,
  669. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  670. sinttype,
  671. uinttype,
  672. { unsigned and signed ord type with the same size as a pointer }
  673. ptruinttype,
  674. ptrsinttype,
  675. { several types to simulate more or less C++ objects for GDB }
  676. vmttype,
  677. vmtarraytype,
  678. pvmttype : tdef; { type of classrefs, used for stabs }
  679. { pointer to the anchestor of all classes }
  680. class_tobject : tobjectdef;
  681. { pointer to the ancestor of all COM interfaces }
  682. interface_iunknown : tobjectdef;
  683. { pointer to the ancestor of all dispinterfaces }
  684. interface_idispatch : tobjectdef;
  685. { pointer to the TGUID type
  686. of all interfaces }
  687. rec_tguid : trecorddef;
  688. { pointer to jump buffer }
  689. rec_jmp_buf : trecorddef;
  690. { Objective-C base types }
  691. objc_metaclasstype,
  692. objc_superclasstype,
  693. objc_idtype,
  694. objc_seltype : tpointerdef;
  695. objc_objecttype : trecorddef;
  696. { base type of @protocol(protocolname) Objective-C statements }
  697. objc_protocoltype : tobjectdef;
  698. { helper types for for-in "fast enumeration" support in Objective-C 2.0 }
  699. objc_fastenumeration : tobjectdef;
  700. objc_fastenumerationstate : trecorddef;
  701. const
  702. {$ifdef i386}
  703. pbestrealtype : ^tdef = @s80floattype;
  704. {$endif}
  705. {$ifdef x86_64}
  706. pbestrealtype : ^tdef = @s80floattype;
  707. {$endif}
  708. {$ifdef m68k}
  709. pbestrealtype : ^tdef = @s64floattype;
  710. {$endif}
  711. {$ifdef alpha}
  712. pbestrealtype : ^tdef = @s64floattype;
  713. {$endif}
  714. {$ifdef powerpc}
  715. pbestrealtype : ^tdef = @s64floattype;
  716. {$endif}
  717. {$ifdef POWERPC64}
  718. pbestrealtype : ^tdef = @s64floattype;
  719. {$endif}
  720. {$ifdef ia64}
  721. pbestrealtype : ^tdef = @s64floattype;
  722. {$endif}
  723. {$ifdef SPARC}
  724. pbestrealtype : ^tdef = @s64floattype;
  725. {$endif SPARC}
  726. {$ifdef vis}
  727. pbestrealtype : ^tdef = @s64floattype;
  728. {$endif vis}
  729. {$ifdef ARM}
  730. pbestrealtype : ^tdef = @s64floattype;
  731. {$endif ARM}
  732. {$ifdef MIPS}
  733. pbestrealtype : ^tdef = @s64floattype;
  734. {$endif MIPS}
  735. {$ifdef AVR}
  736. pbestrealtype : ^tdef = @s64floattype;
  737. {$endif AVR}
  738. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  739. function make_dllmangledname(const dllname,importname:string;
  740. import_nr : word; pco : tproccalloption):string;
  741. { should be in the types unit, but the types unit uses the node stuff :( }
  742. function is_interfacecom(def: tdef): boolean;
  743. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  744. function is_interfacecorba(def: tdef): boolean;
  745. function is_interface(def: tdef): boolean;
  746. function is_dispinterface(def: tdef): boolean;
  747. function is_object(def: tdef): boolean;
  748. function is_class(def: tdef): boolean;
  749. function is_cppclass(def: tdef): boolean;
  750. function is_objectpascal_helper(def: tdef): boolean;
  751. function is_objcclass(def: tdef): boolean;
  752. function is_objcclassref(def: tdef): boolean;
  753. function is_objcprotocol(def: tdef): boolean;
  754. function is_objccategory(def: tdef): boolean;
  755. function is_objc_class_or_protocol(def: tdef): boolean;
  756. function is_objc_protocol_or_category(def: tdef): boolean;
  757. function is_classhelper(def: tdef): boolean;
  758. function is_class_or_interface(def: tdef): boolean;
  759. function is_class_or_interface_or_objc(def: tdef): boolean;
  760. function is_class_or_interface_or_object(def: tdef): boolean;
  761. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  762. function is_implicit_pointer_object_type(def: tdef): boolean;
  763. function is_class_or_object(def: tdef): boolean;
  764. function is_record(def: tdef): boolean;
  765. procedure loadobjctypes;
  766. procedure maybeloadcocoatypes;
  767. function use_vectorfpu(def : tdef) : boolean;
  768. function getansistringcodepage:tstringencoding; inline;
  769. function getansistringdef:tstringdef; inline;
  770. function getparaencoding(def:tdef):tstringencoding; inline;
  771. implementation
  772. uses
  773. SysUtils,
  774. cutils,
  775. { global }
  776. verbose,
  777. { target }
  778. systems,aasmcpu,paramgr,
  779. { symtable }
  780. symsym,symtable,symutil,defutil,objcdef,
  781. { module }
  782. fmodule,
  783. { other }
  784. gendef,
  785. fpccrc
  786. ;
  787. {****************************************************************************
  788. Helpers
  789. ****************************************************************************}
  790. function getansistringcodepage:tstringencoding; inline;
  791. begin
  792. if cs_explicit_codepage in current_settings.moduleswitches then
  793. result:=current_settings.sourcecodepage
  794. else
  795. result:=0;
  796. end;
  797. function getansistringdef:tstringdef; inline;
  798. var
  799. symtable:tsymtable;
  800. begin
  801. { if codepage is explicitly defined in this mudule we need to return
  802. a replacement for ansistring def }
  803. if cs_explicit_codepage in current_settings.moduleswitches then
  804. begin
  805. if not assigned(current_module) then
  806. internalerror(2011101301);
  807. { codepage can be redeclared only once per unit so we don't need a list of
  808. redefined ansistring but only one pointer }
  809. if not assigned(current_module.ansistrdef) then
  810. begin
  811. { if we did not create it yet we need to do this now }
  812. if current_module.is_unit then
  813. symtable:=current_module.globalsymtable
  814. else
  815. symtable:=current_module.localsymtable;
  816. symtablestack.push(symtable);
  817. current_module.ansistrdef:=tstringdef.createansi(current_settings.sourcecodepage);
  818. symtablestack.pop(symtable);
  819. end;
  820. result:=tstringdef(current_module.ansistrdef);
  821. end
  822. else
  823. result:=tstringdef(cansistringtype);
  824. end;
  825. function getparaencoding(def:tdef):tstringencoding; inline;
  826. begin
  827. { don't pass CP_NONE encoding to internal functions
  828. they expect 0 encoding instead }
  829. result:=tstringdef(def).encoding;
  830. if result=CP_NONE then
  831. result:=0
  832. end;
  833. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  834. var
  835. s,hs,
  836. prefix : string;
  837. oldlen,
  838. newlen,
  839. i : longint;
  840. crc : dword;
  841. hp : tparavarsym;
  842. begin
  843. prefix:='';
  844. if not assigned(st) then
  845. internalerror(200204212);
  846. { sub procedures }
  847. while (st.symtabletype=localsymtable) do
  848. begin
  849. if st.defowner.typ<>procdef then
  850. internalerror(200204173);
  851. { Add the full mangledname of procedure to prevent
  852. conflicts with 2 overloads having both a nested procedure
  853. with the same name, see tb0314 (PFV) }
  854. s:=tprocdef(st.defowner).procsym.name;
  855. oldlen:=length(s);
  856. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  857. begin
  858. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  859. if not(vo_is_hidden_para in hp.varoptions) then
  860. s:=s+'$'+hp.vardef.mangledparaname;
  861. end;
  862. if not is_void(tprocdef(st.defowner).returndef) then
  863. s:=s+'$$'+tprocdef(st.defowner).returndef.mangledparaname;
  864. newlen:=length(s);
  865. { Replace with CRC if the parameter line is very long }
  866. if (newlen-oldlen>12) and
  867. ((newlen+length(prefix)>100) or (newlen-oldlen>32)) then
  868. begin
  869. crc:=0;
  870. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  871. begin
  872. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  873. if not(vo_is_hidden_para in hp.varoptions) then
  874. begin
  875. hs:=hp.vardef.mangledparaname;
  876. crc:=UpdateCrc32(crc,hs[1],length(hs));
  877. end;
  878. end;
  879. hs:=hp.vardef.mangledparaname;
  880. crc:=UpdateCrc32(crc,hs[1],length(hs));
  881. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  882. end;
  883. if prefix<>'' then
  884. prefix:=s+'_'+prefix
  885. else
  886. prefix:=s;
  887. if length(prefix)>100 then
  888. begin
  889. crc:=0;
  890. crc:=UpdateCrc32(crc,prefix[1],length(prefix));
  891. prefix:='$CRC'+hexstr(crc,8);
  892. end;
  893. st:=st.defowner.owner;
  894. end;
  895. { object/classes symtable, nested type definitions in classes require the while loop }
  896. while st.symtabletype in [ObjectSymtable,recordsymtable] do
  897. begin
  898. if not (st.defowner.typ in [objectdef,recorddef]) then
  899. internalerror(200204174);
  900. prefix:=tabstractrecorddef(st.defowner).objname^+'_$_'+prefix;
  901. st:=st.defowner.owner;
  902. end;
  903. { symtable must now be static or global }
  904. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  905. internalerror(200204175);
  906. { The mangled name is made out of at most 4 parts:
  907. 1) Optional typeprefix given as first parameter
  908. with '_$' appended if not empty
  909. 2) Unit name or 'P$'+program name (never empty)
  910. 3) optional prefix variable that contains a unique
  911. name for the local symbol table (prepended with '$_$'
  912. if not empty)
  913. 4) suffix as given as third parameter,
  914. also optional (i.e. can be empty)
  915. prepended by '_$$_' if not empty }
  916. result:='';
  917. if typeprefix<>'' then
  918. result:=result+typeprefix+'_$';
  919. { Add P$ for program, which can have the same name as
  920. a unit }
  921. if (TSymtable(main_module.localsymtable)=st) and
  922. (not main_module.is_unit) then
  923. result:=result+'P$'+st.name^
  924. else
  925. result:=result+st.name^;
  926. if prefix<>'' then
  927. result:=result+'$_$'+prefix;
  928. if suffix<>'' then
  929. result:=result+'_$$_'+suffix;
  930. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  931. { Further, the Mac OS X 10.5 linker does not consider symbols which do not }
  932. { start with '_' as regular symbols (it does not generate N_GSYM entries }
  933. { those in the debug map, leading to troubles with dsymutil). So always }
  934. { add an underscore on darwin. }
  935. if (target_info.system in systems_darwin) then
  936. result := '_' + result;
  937. end;
  938. function make_dllmangledname(const dllname,importname:string;import_nr : word; pco : tproccalloption):string;
  939. var
  940. crc : cardinal;
  941. i : longint;
  942. use_crc : boolean;
  943. dllprefix : string;
  944. begin
  945. if (target_info.system in (systems_all_windows + systems_nativent +
  946. [system_i386_emx, system_i386_os2]))
  947. and (dllname <> '') then
  948. begin
  949. dllprefix:=lower(ExtractFileName(dllname));
  950. { Remove .dll suffix if present }
  951. if copy(dllprefix,length(dllprefix)-3,length(dllprefix))='.dll' then
  952. dllprefix:=copy(dllprefix,1,length(dllprefix)-4);
  953. use_crc:=false;
  954. for i:=1 to length(dllprefix) do
  955. if not (dllprefix[i] in ['a'..'z','A'..'Z','_','0'..'9']) then
  956. begin
  957. use_crc:=true;
  958. break;
  959. end;
  960. if use_crc then
  961. begin
  962. crc:=0;
  963. crc:=UpdateCrc32(crc,dllprefix[1],length(dllprefix));
  964. dllprefix:='_$dll$crc$'+hexstr(crc,8)+'$';
  965. end
  966. else
  967. dllprefix:='_$dll$'+dllprefix+'$';
  968. if importname<>'' then
  969. result:=dllprefix+importname
  970. else
  971. result:=dllprefix+'_index_'+tostr(import_nr);
  972. { Replace ? and @ in import name, since GNU AS does not allow these characters in symbol names. }
  973. { This allows to import VC++ mangled names from DLLs. }
  974. { Do not perform replacement, if external symbol is not imported from DLL. }
  975. if (dllname<>'') then
  976. begin
  977. Replace(result,'?','__q$$');
  978. {$ifdef arm}
  979. { @ symbol is not allowed in ARM assembler only }
  980. Replace(result,'@','__a$$');
  981. {$endif arm}
  982. end;
  983. end
  984. else
  985. begin
  986. if importname<>'' then
  987. begin
  988. if not(pco in [pocall_cdecl,pocall_cppdecl]) then
  989. result:=importname
  990. else
  991. result:=target_info.Cprefix+importname;
  992. end
  993. else
  994. result:='_index_'+tostr(import_nr);
  995. end;
  996. end;
  997. {****************************************************************************
  998. TDEFAWARESYMTABLESTACK
  999. (symtablestack descendant that does some special actions on
  1000. the pushed/popped symtables)
  1001. ****************************************************************************}
  1002. procedure tdefawaresymtablestack.addhelpers(st: TSymtable);
  1003. var
  1004. i: integer;
  1005. s: string;
  1006. list: TFPObjectList;
  1007. def: tdef;
  1008. begin
  1009. { search the symtable from first to last; the helper to use will be the
  1010. last one in the list }
  1011. for i:=0 to st.symlist.count-1 do
  1012. begin
  1013. if not (st.symlist[i] is ttypesym) then
  1014. continue;
  1015. def:=ttypesym(st.SymList[i]).typedef;
  1016. if is_objectpascal_helper(def) and
  1017. (tobjectdef(def).extendeddef.typ in [recorddef,objectdef]) then
  1018. begin
  1019. s:=make_mangledname('',tabstractrecorddef(tobjectdef(def).extendeddef).symtable,'');
  1020. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  1021. if not assigned(list) then
  1022. begin
  1023. list:=TFPObjectList.Create(false);
  1024. current_module.extendeddefs.Add(s,list);
  1025. end;
  1026. list.Add(def);
  1027. end
  1028. else
  1029. { add nested helpers as well }
  1030. if def.typ in [recorddef,objectdef] then
  1031. addhelpers(tabstractrecorddef(def).symtable);
  1032. end;
  1033. end;
  1034. procedure tdefawaresymtablestack.removehelpers(st: TSymtable);
  1035. var
  1036. i, j: integer;
  1037. tmpst: TSymtable;
  1038. list: TFPObjectList;
  1039. begin
  1040. for i:=current_module.extendeddefs.count-1 downto 0 do
  1041. begin
  1042. list:=TFPObjectList(current_module.extendeddefs[i]);
  1043. for j:=list.count-1 downto 0 do
  1044. begin
  1045. if not (list[j] is tobjectdef) then
  1046. Internalerror(2011031501);
  1047. tmpst:=tobjectdef(list[j]).owner;
  1048. repeat
  1049. if tmpst=st then
  1050. begin
  1051. list.delete(j);
  1052. break;
  1053. end
  1054. else
  1055. begin
  1056. if assigned(tmpst.defowner) then
  1057. tmpst:=tmpst.defowner.owner
  1058. else
  1059. tmpst:=nil;
  1060. end;
  1061. until not assigned(tmpst) or (tmpst.symtabletype in [globalsymtable,staticsymtable]);
  1062. end;
  1063. if list.count=0 then
  1064. current_module.extendeddefs.delete(i);
  1065. end;
  1066. end;
  1067. procedure tdefawaresymtablestack.push(st: TSymtable);
  1068. begin
  1069. { nested helpers will be added as well }
  1070. if (st.symtabletype in [globalsymtable,staticsymtable]) and
  1071. (sto_has_helper in st.tableoptions) then
  1072. addhelpers(st);
  1073. inherited push(st);
  1074. end;
  1075. procedure tdefawaresymtablestack.pop(st: TSymtable);
  1076. begin
  1077. inherited pop(st);
  1078. { nested helpers will be removed as well }
  1079. if (st.symtabletype in [globalsymtable,staticsymtable]) and
  1080. (sto_has_helper in st.tableoptions) then
  1081. removehelpers(st);
  1082. end;
  1083. {****************************************************************************
  1084. TDEF (base class for definitions)
  1085. ****************************************************************************}
  1086. constructor tstoreddef.create(dt:tdeftyp);
  1087. var
  1088. insertstack : psymtablestackitem;
  1089. begin
  1090. inherited create(dt);
  1091. savesize := 0;
  1092. {$ifdef EXTDEBUG}
  1093. fileinfo := current_filepos;
  1094. {$endif}
  1095. generictokenbuf:=nil;
  1096. genericdef:=nil;
  1097. change_endian:=false;
  1098. { Don't register forwarddefs, they are disposed at the
  1099. end of an type block }
  1100. if (dt=forwarddef) then
  1101. exit;
  1102. { Register in current_module }
  1103. if assigned(current_module) then
  1104. begin
  1105. current_module.deflist.Add(self);
  1106. DefId:=current_module.deflist.Count-1;
  1107. end;
  1108. { Register in symtable stack }
  1109. if assigned(symtablestack) then
  1110. begin
  1111. insertstack:=symtablestack.stack;
  1112. while assigned(insertstack) and
  1113. (insertstack^.symtable.symtabletype=withsymtable) do
  1114. insertstack:=insertstack^.next;
  1115. if not assigned(insertstack) then
  1116. internalerror(200602044);
  1117. insertstack^.symtable.insertdef(self);
  1118. end;
  1119. end;
  1120. destructor tstoreddef.destroy;
  1121. begin
  1122. { Direct calls are not allowed, use symtable.deletedef() }
  1123. if assigned(owner) then
  1124. internalerror(200612311);
  1125. if assigned(generictokenbuf) then
  1126. begin
  1127. generictokenbuf.free;
  1128. generictokenbuf:=nil;
  1129. end;
  1130. inherited destroy;
  1131. end;
  1132. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1133. var
  1134. sizeleft,i : longint;
  1135. buf : array[0..255] of byte;
  1136. begin
  1137. inherited create(dt);
  1138. DefId:=ppufile.getlongint;
  1139. current_module.deflist[DefId]:=self;
  1140. {$ifdef EXTDEBUG}
  1141. fillchar(fileinfo,sizeof(fileinfo),0);
  1142. {$endif}
  1143. { load }
  1144. ppufile.getderef(typesymderef);
  1145. ppufile.getsmallset(defoptions);
  1146. ppufile.getsmallset(defstates);
  1147. if df_generic in defoptions then
  1148. begin
  1149. sizeleft:=ppufile.getlongint;
  1150. change_endian:=ppufile.change_endian;
  1151. initgeneric;
  1152. while sizeleft>0 do
  1153. begin
  1154. if sizeleft>sizeof(buf) then
  1155. i:=sizeof(buf)
  1156. else
  1157. i:=sizeleft;
  1158. ppufile.getdata(buf,i);
  1159. generictokenbuf.write(buf,i);
  1160. dec(sizeleft,i);
  1161. end;
  1162. end;
  1163. if df_specialization in defoptions then
  1164. ppufile.getderef(genericdefderef);
  1165. end;
  1166. function Tstoreddef.rtti_mangledname(rt:trttitype):string;
  1167. var
  1168. prefix : string[4];
  1169. begin
  1170. if rt=fullrtti then
  1171. begin
  1172. prefix:='RTTI';
  1173. include(defstates,ds_rtti_table_used);
  1174. end
  1175. else
  1176. begin
  1177. prefix:='INIT';
  1178. include(defstates,ds_init_table_used);
  1179. end;
  1180. if assigned(typesym) and
  1181. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  1182. result:=make_mangledname(prefix,owner,typesym.name)
  1183. else
  1184. result:=make_mangledname(prefix,findunitsymtable(owner),'DEF'+tostr(DefId))
  1185. end;
  1186. function tstoreddef.OwnerHierarchyName: string;
  1187. var
  1188. tmp: tdef;
  1189. begin
  1190. tmp:=self;
  1191. result:='';
  1192. repeat
  1193. if tmp.owner.symtabletype in [ObjectSymtable,recordsymtable] then
  1194. tmp:=tdef(tmp.owner.defowner)
  1195. else
  1196. break;
  1197. result:=tabstractrecorddef(tmp).objrealname^+'.'+result;
  1198. until tmp=nil;
  1199. end;
  1200. function tstoreddef.in_currentunit: boolean;
  1201. var
  1202. st: tsymtable;
  1203. begin
  1204. st:=owner;
  1205. while not(st.symtabletype in [globalsymtable,staticsymtable]) do
  1206. st:=st.defowner.owner;
  1207. result:=st.iscurrentunit;
  1208. end;
  1209. function tstoreddef.getcopy : tstoreddef;
  1210. begin
  1211. Message(sym_e_cant_create_unique_type);
  1212. getcopy:=terrordef.create;
  1213. end;
  1214. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  1215. var
  1216. sizeleft,i : longint;
  1217. buf : array[0..255] of byte;
  1218. oldintfcrc : boolean;
  1219. begin
  1220. ppufile.putlongint(DefId);
  1221. ppufile.putderef(typesymderef);
  1222. ppufile.putsmallset(defoptions);
  1223. oldintfcrc:=ppufile.do_crc;
  1224. ppufile.do_crc:=false;
  1225. ppufile.putsmallset(defstates);
  1226. if df_generic in defoptions then
  1227. begin
  1228. if assigned(generictokenbuf) then
  1229. begin
  1230. sizeleft:=generictokenbuf.size;
  1231. generictokenbuf.seek(0);
  1232. end
  1233. else
  1234. sizeleft:=0;
  1235. ppufile.putlongint(sizeleft);
  1236. while sizeleft>0 do
  1237. begin
  1238. if sizeleft>sizeof(buf) then
  1239. i:=sizeof(buf)
  1240. else
  1241. i:=sizeleft;
  1242. generictokenbuf.read(buf,i);
  1243. ppufile.putdata(buf,i);
  1244. dec(sizeleft,i);
  1245. end;
  1246. end;
  1247. ppufile.do_crc:=oldintfcrc;
  1248. if df_specialization in defoptions then
  1249. ppufile.putderef(genericdefderef);
  1250. end;
  1251. procedure tstoreddef.buildderef;
  1252. begin
  1253. typesymderef.build(typesym);
  1254. genericdefderef.build(genericdef);
  1255. end;
  1256. procedure tstoreddef.buildderefimpl;
  1257. begin
  1258. end;
  1259. procedure tstoreddef.deref;
  1260. begin
  1261. typesym:=ttypesym(typesymderef.resolve);
  1262. if df_specialization in defoptions then
  1263. genericdef:=tstoreddef(genericdefderef.resolve);
  1264. end;
  1265. procedure tstoreddef.derefimpl;
  1266. begin
  1267. end;
  1268. function tstoreddef.size : asizeint;
  1269. begin
  1270. size:=savesize;
  1271. end;
  1272. function tstoreddef.getvardef:longint;
  1273. begin
  1274. result:=varUndefined;
  1275. end;
  1276. function tstoreddef.alignment : shortint;
  1277. begin
  1278. { natural alignment by default }
  1279. alignment:=size_2_align(savesize);
  1280. { can happen if savesize = 0, e.g. for voiddef or
  1281. an empty record
  1282. }
  1283. if (alignment=0) then
  1284. alignment:=1;
  1285. end;
  1286. { returns true, if the definition can be published }
  1287. function tstoreddef.is_publishable : boolean;
  1288. begin
  1289. is_publishable:=false;
  1290. end;
  1291. { needs an init table }
  1292. function tstoreddef.needs_inittable : boolean;
  1293. begin
  1294. needs_inittable:=false;
  1295. end;
  1296. function tstoreddef.is_intregable : boolean;
  1297. var
  1298. recsize,temp: longint;
  1299. begin
  1300. is_intregable:=false;
  1301. case typ of
  1302. orddef,
  1303. pointerdef,
  1304. enumdef,
  1305. classrefdef:
  1306. is_intregable:=true;
  1307. procvardef :
  1308. is_intregable:=tprocvardef(self).is_addressonly;
  1309. objectdef:
  1310. is_intregable:=(is_implicit_pointer_object_type(self)) and not needs_inittable;
  1311. setdef:
  1312. is_intregable:=is_smallset(self);
  1313. recorddef:
  1314. begin
  1315. recsize:=size;
  1316. is_intregable:=
  1317. ispowerof2(recsize,temp) and
  1318. (recsize <= sizeof(asizeint));
  1319. end;
  1320. end;
  1321. end;
  1322. function tstoreddef.is_fpuregable : boolean;
  1323. begin
  1324. {$ifdef x86}
  1325. result:=use_vectorfpu(self);
  1326. {$else x86}
  1327. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  1328. {$endif x86}
  1329. end;
  1330. procedure tstoreddef.initgeneric;
  1331. begin
  1332. if assigned(generictokenbuf) then
  1333. internalerror(200512131);
  1334. generictokenbuf:=tdynamicarray.create(256);
  1335. end;
  1336. {****************************************************************************
  1337. Tstringdef
  1338. ****************************************************************************}
  1339. constructor tstringdef.createshort(l : byte);
  1340. begin
  1341. inherited create(stringdef);
  1342. stringtype:=st_shortstring;
  1343. encoding:=0;
  1344. len:=l;
  1345. savesize:=len+1;
  1346. end;
  1347. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1348. begin
  1349. inherited ppuload(stringdef,ppufile);
  1350. stringtype:=st_shortstring;
  1351. encoding:=0;
  1352. len:=ppufile.getbyte;
  1353. savesize:=len+1;
  1354. end;
  1355. constructor tstringdef.createlong(l : asizeint);
  1356. begin
  1357. inherited create(stringdef);
  1358. stringtype:=st_longstring;
  1359. encoding:=0;
  1360. len:=l;
  1361. savesize:=sizeof(pint);
  1362. end;
  1363. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1364. begin
  1365. inherited ppuload(stringdef,ppufile);
  1366. stringtype:=st_longstring;
  1367. encoding:=0;
  1368. len:=ppufile.getasizeint;
  1369. savesize:=sizeof(pint);
  1370. end;
  1371. constructor tstringdef.createansi(aencoding:tstringencoding);
  1372. begin
  1373. inherited create(stringdef);
  1374. stringtype:=st_ansistring;
  1375. encoding:=aencoding;
  1376. len:=-1;
  1377. savesize:=sizeof(pint);
  1378. end;
  1379. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1380. begin
  1381. inherited ppuload(stringdef,ppufile);
  1382. stringtype:=st_ansistring;
  1383. len:=ppufile.getaint;
  1384. encoding:=ppufile.getword;
  1385. savesize:=sizeof(pint);
  1386. end;
  1387. constructor tstringdef.createwide;
  1388. begin
  1389. inherited create(stringdef);
  1390. stringtype:=st_widestring;
  1391. encoding:=CP_UTF16;
  1392. len:=-1;
  1393. savesize:=sizeof(pint);
  1394. end;
  1395. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1396. begin
  1397. inherited ppuload(stringdef,ppufile);
  1398. stringtype:=st_widestring;
  1399. encoding:=CP_UTF16;
  1400. len:=ppufile.getaint;
  1401. savesize:=sizeof(pint);
  1402. end;
  1403. constructor tstringdef.createunicode;
  1404. begin
  1405. inherited create(stringdef);
  1406. stringtype:=st_unicodestring;
  1407. encoding:=CP_UTF16;
  1408. len:=-1;
  1409. savesize:=sizeof(pint);
  1410. end;
  1411. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  1412. begin
  1413. inherited ppuload(stringdef,ppufile);
  1414. stringtype:=st_unicodestring;
  1415. len:=ppufile.getaint;
  1416. encoding:=ppufile.getword;
  1417. savesize:=sizeof(pint);
  1418. end;
  1419. function tstringdef.getcopy : tstoreddef;
  1420. begin
  1421. result:=tstringdef.create(typ);
  1422. result.typ:=stringdef;
  1423. tstringdef(result).stringtype:=stringtype;
  1424. tstringdef(result).encoding:=encoding;
  1425. tstringdef(result).len:=len;
  1426. tstringdef(result).savesize:=savesize;
  1427. end;
  1428. function tstringdef.stringtypname:string;
  1429. const
  1430. typname:array[tstringtype] of string[10]=(
  1431. 'shortstr','longstr','ansistr','widestr','unicodestr'
  1432. );
  1433. begin
  1434. stringtypname:=typname[stringtype];
  1435. end;
  1436. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1437. begin
  1438. inherited ppuwrite(ppufile);
  1439. if stringtype=st_shortstring then
  1440. begin
  1441. {$ifdef extdebug}
  1442. if len > 255 then internalerror(12122002);
  1443. {$endif}
  1444. ppufile.putbyte(byte(len))
  1445. end
  1446. else
  1447. ppufile.putaint(len);
  1448. if stringtype in [st_ansistring,st_unicodestring] then
  1449. ppufile.putword(encoding);
  1450. case stringtype of
  1451. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1452. st_longstring : ppufile.writeentry(iblongstringdef);
  1453. st_ansistring : ppufile.writeentry(ibansistringdef);
  1454. st_widestring : ppufile.writeentry(ibwidestringdef);
  1455. st_unicodestring : ppufile.writeentry(ibunicodestringdef);
  1456. end;
  1457. end;
  1458. function tstringdef.needs_inittable : boolean;
  1459. begin
  1460. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  1461. end;
  1462. function tstringdef.GetTypeName : string;
  1463. const
  1464. names : array[tstringtype] of string[15] = (
  1465. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  1466. begin
  1467. GetTypeName:=names[stringtype];
  1468. end;
  1469. function tstringdef.getvardef : longint;
  1470. const
  1471. vardef : array[tstringtype] of longint = (
  1472. varUndefined,varUndefined,varString,varOleStr,varUString);
  1473. begin
  1474. result:=vardef[stringtype];
  1475. end;
  1476. function tstringdef.alignment : shortint;
  1477. begin
  1478. case stringtype of
  1479. st_unicodestring,
  1480. st_widestring,
  1481. st_ansistring:
  1482. alignment:=size_2_align(savesize);
  1483. st_longstring,
  1484. st_shortstring:
  1485. { char to string accesses byte 0 and 1 with one word access }
  1486. if (tf_requires_proper_alignment in target_info.flags) or
  1487. { macpas needs an alignment of 2 (MetroWerks compatible) }
  1488. (m_mac in current_settings.modeswitches) then
  1489. alignment:=size_2_align(2)
  1490. else
  1491. alignment:=size_2_align(1);
  1492. else
  1493. internalerror(200412301);
  1494. end;
  1495. end;
  1496. function tstringdef.getmangledparaname : string;
  1497. begin
  1498. getmangledparaname:='STRING';
  1499. end;
  1500. function tstringdef.is_publishable : boolean;
  1501. begin
  1502. is_publishable:=true;
  1503. end;
  1504. {****************************************************************************
  1505. TENUMDEF
  1506. ****************************************************************************}
  1507. constructor tenumdef.create;
  1508. begin
  1509. inherited create(enumdef);
  1510. minval:=0;
  1511. maxval:=0;
  1512. calcsavesize;
  1513. has_jumps:=false;
  1514. basedef:=nil;
  1515. symtable:=tenumsymtable.create(self);
  1516. end;
  1517. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  1518. begin
  1519. inherited create(enumdef);
  1520. minval:=_min;
  1521. maxval:=_max;
  1522. basedef:=_basedef;
  1523. calcsavesize;
  1524. has_jumps:=false;
  1525. symtable:=basedef.symtable.getcopy;
  1526. include(defoptions, df_copied_def);
  1527. end;
  1528. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1529. begin
  1530. inherited ppuload(enumdef,ppufile);
  1531. minval:=ppufile.getaint;
  1532. maxval:=ppufile.getaint;
  1533. savesize:=ppufile.getaint;
  1534. has_jumps:=false;
  1535. if df_copied_def in defoptions then
  1536. begin
  1537. symtable:=nil;
  1538. ppufile.getderef(basedefderef);
  1539. end
  1540. else
  1541. begin
  1542. // create with nil defowner first to prevent values changes on insert
  1543. symtable:=tenumsymtable.create(nil);
  1544. tenumsymtable(symtable).ppuload(ppufile);
  1545. symtable.defowner:=self;
  1546. end;
  1547. end;
  1548. destructor tenumdef.destroy;
  1549. begin
  1550. symtable.free;
  1551. symtable:=nil;
  1552. inherited destroy;
  1553. end;
  1554. function tenumdef.getcopy : tstoreddef;
  1555. begin
  1556. if assigned(basedef) then
  1557. result:=tenumdef.create_subrange(basedef,minval,maxval)
  1558. else
  1559. begin
  1560. result:=tenumdef.create;
  1561. tenumdef(result).minval:=minval;
  1562. tenumdef(result).maxval:=maxval;
  1563. tenumdef(result).symtable.free;
  1564. tenumdef(result).symtable:=symtable.getcopy;
  1565. tenumdef(result).basedef:=self;
  1566. end;
  1567. tenumdef(result).has_jumps:=has_jumps;
  1568. tenumdef(result).basedefderef:=basedefderef;
  1569. include(tenumdef(result).defoptions,df_copied_def);
  1570. end;
  1571. procedure tenumdef.calcsavesize;
  1572. begin
  1573. {$IFDEF CPU32} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  1574. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  1575. savesize:=8
  1576. {$IFDEF CPU32} {$pop} {$ENDIF}
  1577. else
  1578. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  1579. savesize:=4
  1580. else
  1581. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1582. savesize:=2
  1583. else
  1584. savesize:=1;
  1585. end;
  1586. function tenumdef.packedbitsize: asizeint;
  1587. var
  1588. sizeval: tconstexprint;
  1589. power: longint;
  1590. begin
  1591. result := 0;
  1592. if (minval >= 0) and
  1593. (maxval <= 1) then
  1594. result := 1
  1595. else
  1596. begin
  1597. if (minval>=0) then
  1598. sizeval:=maxval
  1599. else
  1600. { don't count 0 twice }
  1601. sizeval:=(cutils.max(-minval,maxval)*2)-1;
  1602. { 256 must become 512 etc. }
  1603. nextpowerof2(sizeval+1,power);
  1604. result := power;
  1605. end;
  1606. end;
  1607. procedure tenumdef.setmax(_max:asizeint);
  1608. begin
  1609. maxval:=_max;
  1610. calcsavesize;
  1611. end;
  1612. procedure tenumdef.setmin(_min:asizeint);
  1613. begin
  1614. minval:=_min;
  1615. calcsavesize;
  1616. end;
  1617. function tenumdef.min:asizeint;
  1618. begin
  1619. min:=minval;
  1620. end;
  1621. function tenumdef.max:asizeint;
  1622. begin
  1623. max:=maxval;
  1624. end;
  1625. function tenumdef.getfirstsym: tsym;
  1626. var
  1627. i:integer;
  1628. begin
  1629. for i := 0 to symtable.SymList.Count - 1 do
  1630. begin
  1631. result:=tsym(symtable.SymList[i]);
  1632. if tenumsym(result).value=minval then
  1633. exit;
  1634. end;
  1635. result:=nil;
  1636. end;
  1637. procedure tenumdef.buildderef;
  1638. begin
  1639. inherited buildderef;
  1640. if df_copied_def in defoptions then
  1641. basedefderef.build(basedef)
  1642. else
  1643. tenumsymtable(symtable).buildderef;
  1644. end;
  1645. procedure tenumdef.deref;
  1646. begin
  1647. inherited deref;
  1648. if df_copied_def in defoptions then
  1649. begin
  1650. basedef:=tenumdef(basedefderef.resolve);
  1651. symtable:=basedef.symtable.getcopy;
  1652. end
  1653. else
  1654. tenumsymtable(symtable).deref;
  1655. end;
  1656. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1657. begin
  1658. inherited ppuwrite(ppufile);
  1659. ppufile.putaint(min);
  1660. ppufile.putaint(max);
  1661. ppufile.putaint(savesize);
  1662. if df_copied_def in defoptions then
  1663. ppufile.putderef(basedefderef);
  1664. ppufile.writeentry(ibenumdef);
  1665. if not (df_copied_def in defoptions) then
  1666. tenumsymtable(symtable).ppuwrite(ppufile);
  1667. end;
  1668. function tenumdef.is_publishable : boolean;
  1669. begin
  1670. is_publishable:=true;
  1671. end;
  1672. function tenumdef.GetTypeName : string;
  1673. begin
  1674. GetTypeName:='<enumeration type>';
  1675. end;
  1676. {****************************************************************************
  1677. TORDDEF
  1678. ****************************************************************************}
  1679. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  1680. begin
  1681. inherited create(orddef);
  1682. low:=v;
  1683. high:=b;
  1684. ordtype:=t;
  1685. setsize;
  1686. end;
  1687. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1688. begin
  1689. inherited ppuload(orddef,ppufile);
  1690. ordtype:=tordtype(ppufile.getbyte);
  1691. low:=ppufile.getexprint;
  1692. high:=ppufile.getexprint;
  1693. setsize;
  1694. end;
  1695. function torddef.getcopy : tstoreddef;
  1696. begin
  1697. result:=torddef.create(ordtype,low,high);
  1698. result.typ:=orddef;
  1699. torddef(result).low:=low;
  1700. torddef(result).high:=high;
  1701. torddef(result).ordtype:=ordtype;
  1702. torddef(result).savesize:=savesize;
  1703. end;
  1704. function torddef.alignment:shortint;
  1705. begin
  1706. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) and
  1707. (ordtype in [s64bit,u64bit]) then
  1708. result := 4
  1709. else
  1710. result := inherited alignment;
  1711. end;
  1712. procedure torddef.setsize;
  1713. const
  1714. sizetbl : array[tordtype] of longint = (
  1715. 0,
  1716. 1,2,4,8,
  1717. 1,2,4,8,
  1718. 1,2,4,8,
  1719. 1,2,4,8,
  1720. 1,2,8
  1721. );
  1722. begin
  1723. savesize:=sizetbl[ordtype];
  1724. end;
  1725. function torddef.packedbitsize: asizeint;
  1726. var
  1727. sizeval: tconstexprint;
  1728. power: longint;
  1729. begin
  1730. result := 0;
  1731. if ordtype = uvoid then
  1732. exit;
  1733. {$ifndef cpu64bitalu}
  1734. if (ordtype in [s64bit,u64bit]) then
  1735. {$else not cpu64bitalu}
  1736. if (ordtype = u64bit) or
  1737. ((ordtype = s64bit) and
  1738. ((low <= (system.low(int64) div 2)) or
  1739. (high > (system.high(int64) div 2)))) then
  1740. {$endif cpu64bitalu}
  1741. result := 64
  1742. else if (low >= 0) and
  1743. (high <= 1) then
  1744. result := 1
  1745. else
  1746. begin
  1747. if (low>=0) then
  1748. sizeval:=high
  1749. else
  1750. { don't count 0 twice }
  1751. sizeval:=(cutils.max(-low,high)*2)-1;
  1752. { 256 must become 512 etc. }
  1753. nextpowerof2(sizeval+1,power);
  1754. result := power;
  1755. end;
  1756. end;
  1757. function torddef.getvardef : longint;
  1758. const
  1759. basetype2vardef : array[tordtype] of longint = (
  1760. varUndefined,
  1761. varbyte,varword,varlongword,varqword,
  1762. varshortint,varsmallint,varinteger,varint64,
  1763. varboolean,varboolean,varboolean,varboolean,
  1764. varboolean,varboolean,varUndefined,varUndefined,
  1765. varUndefined,varUndefined,varCurrency);
  1766. begin
  1767. result:=basetype2vardef[ordtype];
  1768. end;
  1769. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1770. begin
  1771. inherited ppuwrite(ppufile);
  1772. ppufile.putbyte(byte(ordtype));
  1773. ppufile.putexprint(low);
  1774. ppufile.putexprint(high);
  1775. ppufile.writeentry(iborddef);
  1776. end;
  1777. function torddef.is_publishable : boolean;
  1778. begin
  1779. is_publishable:=(ordtype<>uvoid);
  1780. end;
  1781. function torddef.GetTypeName : string;
  1782. const
  1783. names : array[tordtype] of string[20] = (
  1784. 'untyped',
  1785. 'Byte','Word','DWord','QWord',
  1786. 'ShortInt','SmallInt','LongInt','Int64',
  1787. 'Boolean','Boolean16','Boolean32','Boolean64',
  1788. 'ByteBool','WordBool','LongBool','QWordBool',
  1789. 'Char','WideChar','Currency');
  1790. begin
  1791. GetTypeName:=names[ordtype];
  1792. end;
  1793. {****************************************************************************
  1794. TFLOATDEF
  1795. ****************************************************************************}
  1796. constructor tfloatdef.create(t : tfloattype);
  1797. begin
  1798. inherited create(floatdef);
  1799. floattype:=t;
  1800. setsize;
  1801. end;
  1802. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1803. begin
  1804. inherited ppuload(floatdef,ppufile);
  1805. floattype:=tfloattype(ppufile.getbyte);
  1806. setsize;
  1807. end;
  1808. function tfloatdef.getcopy : tstoreddef;
  1809. begin
  1810. result:=tfloatdef.create(floattype);
  1811. result.typ:=floatdef;
  1812. tfloatdef(result).savesize:=savesize;
  1813. end;
  1814. function tfloatdef.alignment:shortint;
  1815. begin
  1816. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) then
  1817. case floattype of
  1818. s80real: result:=16;
  1819. s64real,
  1820. s64currency,
  1821. s64comp : result:=4;
  1822. else
  1823. result := inherited alignment;
  1824. end
  1825. else
  1826. result := inherited alignment;
  1827. end;
  1828. procedure tfloatdef.setsize;
  1829. begin
  1830. case floattype of
  1831. s32real : savesize:=4;
  1832. s80real : savesize:=10;
  1833. sc80real:
  1834. if target_info.system in [system_i386_darwin,system_i386_iphonesim,system_x86_64_darwin,
  1835. system_x86_64_linux,system_x86_64_freebsd,
  1836. system_x86_64_solaris,system_x86_64_embedded] then
  1837. savesize:=16
  1838. else
  1839. savesize:=12;
  1840. s64real,
  1841. s64currency,
  1842. s64comp : savesize:=8;
  1843. else
  1844. savesize:=0;
  1845. end;
  1846. end;
  1847. function tfloatdef.getvardef : longint;
  1848. const
  1849. floattype2vardef : array[tfloattype] of longint = (
  1850. varSingle,varDouble,varUndefined,varUndefined,
  1851. varUndefined,varCurrency,varUndefined);
  1852. begin
  1853. if (upper(typename)='TDATETIME') and
  1854. assigned(owner) and
  1855. assigned(owner.name) and
  1856. (owner.name^='SYSTEM') then
  1857. result:=varDate
  1858. else
  1859. result:=floattype2vardef[floattype];
  1860. end;
  1861. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1862. begin
  1863. inherited ppuwrite(ppufile);
  1864. ppufile.putbyte(byte(floattype));
  1865. ppufile.writeentry(ibfloatdef);
  1866. end;
  1867. function tfloatdef.is_publishable : boolean;
  1868. begin
  1869. is_publishable:=true;
  1870. end;
  1871. function tfloatdef.GetTypeName : string;
  1872. const
  1873. names : array[tfloattype] of string[20] = (
  1874. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  1875. begin
  1876. GetTypeName:=names[floattype];
  1877. end;
  1878. {****************************************************************************
  1879. TFILEDEF
  1880. ****************************************************************************}
  1881. constructor tfiledef.createtext;
  1882. begin
  1883. inherited create(filedef);
  1884. filetyp:=ft_text;
  1885. typedfiledef:=nil;
  1886. setsize;
  1887. end;
  1888. constructor tfiledef.createuntyped;
  1889. begin
  1890. inherited create(filedef);
  1891. filetyp:=ft_untyped;
  1892. typedfiledef:=nil;
  1893. setsize;
  1894. end;
  1895. constructor tfiledef.createtyped(def:tdef);
  1896. begin
  1897. inherited create(filedef);
  1898. filetyp:=ft_typed;
  1899. typedfiledef:=def;
  1900. setsize;
  1901. end;
  1902. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1903. begin
  1904. inherited ppuload(filedef,ppufile);
  1905. filetyp:=tfiletyp(ppufile.getbyte);
  1906. if filetyp=ft_typed then
  1907. ppufile.getderef(typedfiledefderef)
  1908. else
  1909. typedfiledef:=nil;
  1910. setsize;
  1911. end;
  1912. function tfiledef.getcopy : tstoreddef;
  1913. begin
  1914. case filetyp of
  1915. ft_typed:
  1916. result:=tfiledef.createtyped(typedfiledef);
  1917. ft_untyped:
  1918. result:=tfiledef.createuntyped;
  1919. ft_text:
  1920. result:=tfiledef.createtext;
  1921. else
  1922. internalerror(2004121201);
  1923. end;
  1924. end;
  1925. procedure tfiledef.buildderef;
  1926. begin
  1927. inherited buildderef;
  1928. if filetyp=ft_typed then
  1929. typedfiledefderef.build(typedfiledef);
  1930. end;
  1931. procedure tfiledef.deref;
  1932. begin
  1933. inherited deref;
  1934. if filetyp=ft_typed then
  1935. typedfiledef:=tdef(typedfiledefderef.resolve);
  1936. end;
  1937. procedure tfiledef.setsize;
  1938. begin
  1939. {$ifdef cpu64bitaddr}
  1940. case filetyp of
  1941. ft_text :
  1942. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1943. savesize:=634{+8}
  1944. else
  1945. savesize:=630{+8};
  1946. ft_typed,
  1947. ft_untyped :
  1948. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1949. savesize:=372
  1950. else
  1951. savesize:=368;
  1952. end;
  1953. {$endif cpu64bitaddr}
  1954. {$ifdef cpu32bitaddr}
  1955. case filetyp of
  1956. ft_text :
  1957. savesize:=594{+4};
  1958. ft_typed,
  1959. ft_untyped :
  1960. savesize:=332;
  1961. end;
  1962. {$endif cpu32bitaddr}
  1963. {$ifdef cpu8bitaddr}
  1964. case filetyp of
  1965. ft_text :
  1966. savesize:=127;
  1967. ft_typed,
  1968. ft_untyped :
  1969. savesize:=127;
  1970. end;
  1971. {$endif cpu8bitaddr}
  1972. end;
  1973. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1974. begin
  1975. inherited ppuwrite(ppufile);
  1976. ppufile.putbyte(byte(filetyp));
  1977. if filetyp=ft_typed then
  1978. ppufile.putderef(typedfiledefderef);
  1979. ppufile.writeentry(ibfiledef);
  1980. end;
  1981. function tfiledef.GetTypeName : string;
  1982. begin
  1983. case filetyp of
  1984. ft_untyped:
  1985. GetTypeName:='File';
  1986. ft_typed:
  1987. GetTypeName:='File Of '+typedfiledef.typename;
  1988. ft_text:
  1989. GetTypeName:='Text'
  1990. end;
  1991. end;
  1992. function tfiledef.getmangledparaname : string;
  1993. begin
  1994. case filetyp of
  1995. ft_untyped:
  1996. getmangledparaname:='FILE';
  1997. ft_typed:
  1998. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  1999. ft_text:
  2000. getmangledparaname:='TEXT'
  2001. end;
  2002. end;
  2003. {****************************************************************************
  2004. TVARIANTDEF
  2005. ****************************************************************************}
  2006. constructor tvariantdef.create(v : tvarianttype);
  2007. begin
  2008. inherited create(variantdef);
  2009. varianttype:=v;
  2010. setsize;
  2011. end;
  2012. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2013. begin
  2014. inherited ppuload(variantdef,ppufile);
  2015. varianttype:=tvarianttype(ppufile.getbyte);
  2016. setsize;
  2017. end;
  2018. function tvariantdef.getcopy : tstoreddef;
  2019. begin
  2020. result:=tvariantdef.create(varianttype);
  2021. end;
  2022. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2023. begin
  2024. inherited ppuwrite(ppufile);
  2025. ppufile.putbyte(byte(varianttype));
  2026. ppufile.writeentry(ibvariantdef);
  2027. end;
  2028. function tvariantdef.getvardef : longint;
  2029. begin
  2030. Result:=varVariant;
  2031. end;
  2032. procedure tvariantdef.setsize;
  2033. begin
  2034. {$ifdef cpu64bitaddr}
  2035. savesize:=24;
  2036. {$else cpu64bitaddr}
  2037. savesize:=16;
  2038. {$endif cpu64bitaddr}
  2039. end;
  2040. function tvariantdef.GetTypeName : string;
  2041. begin
  2042. case varianttype of
  2043. vt_normalvariant:
  2044. GetTypeName:='Variant';
  2045. vt_olevariant:
  2046. GetTypeName:='OleVariant';
  2047. end;
  2048. end;
  2049. function tvariantdef.needs_inittable : boolean;
  2050. begin
  2051. needs_inittable:=true;
  2052. end;
  2053. function tvariantdef.is_publishable : boolean;
  2054. begin
  2055. is_publishable:=true;
  2056. end;
  2057. {****************************************************************************
  2058. TABSTRACtpointerdef
  2059. ****************************************************************************}
  2060. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  2061. begin
  2062. inherited create(dt);
  2063. pointeddef:=def;
  2064. savesize:=sizeof(pint);
  2065. end;
  2066. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2067. begin
  2068. inherited ppuload(dt,ppufile);
  2069. ppufile.getderef(pointeddefderef);
  2070. savesize:=sizeof(pint);
  2071. end;
  2072. procedure tabstractpointerdef.buildderef;
  2073. begin
  2074. inherited buildderef;
  2075. pointeddefderef.build(pointeddef);
  2076. end;
  2077. procedure tabstractpointerdef.deref;
  2078. begin
  2079. inherited deref;
  2080. pointeddef:=tdef(pointeddefderef.resolve);
  2081. end;
  2082. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2083. begin
  2084. inherited ppuwrite(ppufile);
  2085. ppufile.putderef(pointeddefderef);
  2086. end;
  2087. {****************************************************************************
  2088. tpointerdef
  2089. ****************************************************************************}
  2090. constructor tpointerdef.create(def:tdef);
  2091. begin
  2092. inherited create(pointerdef,def);
  2093. is_far:=false;
  2094. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2095. end;
  2096. constructor tpointerdef.createfar(def:tdef);
  2097. begin
  2098. inherited create(pointerdef,def);
  2099. is_far:=true;
  2100. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2101. end;
  2102. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2103. begin
  2104. inherited ppuload(pointerdef,ppufile);
  2105. is_far:=(ppufile.getbyte<>0);
  2106. has_pointer_math:=(ppufile.getbyte<>0);
  2107. end;
  2108. function tpointerdef.getcopy : tstoreddef;
  2109. begin
  2110. { don't use direct pointeddef if it is a forwarddef because in other case
  2111. one of them will be destroyed on forward type resolve and the second will
  2112. point to garbage }
  2113. if pointeddef.typ=forwarddef then
  2114. result:=tpointerdef.create(tforwarddef(pointeddef).getcopy)
  2115. else
  2116. result:=tpointerdef.create(pointeddef);
  2117. tpointerdef(result).is_far:=is_far;
  2118. tpointerdef(result).has_pointer_math:=has_pointer_math;
  2119. tpointerdef(result).savesize:=savesize;
  2120. end;
  2121. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2122. begin
  2123. inherited ppuwrite(ppufile);
  2124. ppufile.putbyte(byte(is_far));
  2125. ppufile.putbyte(byte(has_pointer_math));
  2126. ppufile.writeentry(ibpointerdef);
  2127. end;
  2128. function tpointerdef.GetTypeName : string;
  2129. begin
  2130. if is_far then
  2131. GetTypeName:='^'+pointeddef.typename+';far'
  2132. else
  2133. GetTypeName:='^'+pointeddef.typename;
  2134. end;
  2135. {****************************************************************************
  2136. TCLASSREFDEF
  2137. ****************************************************************************}
  2138. constructor tclassrefdef.create(def:tdef);
  2139. begin
  2140. inherited create(classrefdef,def);
  2141. end;
  2142. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2143. begin
  2144. inherited ppuload(classrefdef,ppufile);
  2145. end;
  2146. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2147. begin
  2148. inherited ppuwrite(ppufile);
  2149. ppufile.writeentry(ibclassrefdef);
  2150. end;
  2151. function tclassrefdef.getcopy:tstoreddef;
  2152. begin
  2153. if pointeddef.typ=forwarddef then
  2154. result:=tclassrefdef.create(tforwarddef(pointeddef).getcopy)
  2155. else
  2156. result:=tclassrefdef.create(pointeddef);
  2157. tclassrefdef(result).savesize:=savesize;
  2158. end;
  2159. function tclassrefdef.GetTypeName : string;
  2160. begin
  2161. GetTypeName:='Class Of '+pointeddef.typename;
  2162. end;
  2163. function tclassrefdef.is_publishable : boolean;
  2164. begin
  2165. result:=true;
  2166. end;
  2167. function tclassrefdef.rtti_mangledname(rt: trttitype): string;
  2168. begin
  2169. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  2170. result:=inherited rtti_mangledname(rt)
  2171. else
  2172. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  2173. end;
  2174. procedure tclassrefdef.register_created_object_type;
  2175. begin
  2176. tobjectdef(pointeddef).register_created_classref_type;
  2177. end;
  2178. {***************************************************************************
  2179. TSETDEF
  2180. ***************************************************************************}
  2181. constructor tsetdef.create(def:tdef;low, high : asizeint);
  2182. var
  2183. setallocbits: aint;
  2184. packedsavesize: aint;
  2185. begin
  2186. inherited create(setdef);
  2187. elementdef:=def;
  2188. setmax:=high;
  2189. if (current_settings.setalloc=0) then
  2190. begin
  2191. setbase:=0;
  2192. if (high<32) then
  2193. savesize:=Sizeof(longint)
  2194. else if (high<256) then
  2195. savesize:=32
  2196. else
  2197. savesize:=(high+7) div 8
  2198. end
  2199. else
  2200. begin
  2201. setallocbits:=current_settings.setalloc*8;
  2202. setbase:=low and not(setallocbits-1);
  2203. packedsavesize:=current_settings.setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  2204. savesize:=packedsavesize;
  2205. if savesize=3 then
  2206. savesize:=4;
  2207. end;
  2208. end;
  2209. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2210. begin
  2211. inherited ppuload(setdef,ppufile);
  2212. ppufile.getderef(elementdefderef);
  2213. savesize:=ppufile.getaint;
  2214. setbase:=ppufile.getaint;
  2215. setmax:=ppufile.getaint;
  2216. end;
  2217. function tsetdef.getcopy : tstoreddef;
  2218. begin
  2219. result:=tsetdef.create(elementdef,setbase,setmax);
  2220. { the copy might have been created with a different setalloc setting }
  2221. tsetdef(result).savesize:=savesize;
  2222. end;
  2223. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2224. begin
  2225. inherited ppuwrite(ppufile);
  2226. ppufile.putderef(elementdefderef);
  2227. ppufile.putaint(savesize);
  2228. ppufile.putaint(setbase);
  2229. ppufile.putaint(setmax);
  2230. ppufile.writeentry(ibsetdef);
  2231. end;
  2232. procedure tsetdef.buildderef;
  2233. begin
  2234. inherited buildderef;
  2235. elementdefderef.build(elementdef);
  2236. end;
  2237. procedure tsetdef.deref;
  2238. begin
  2239. inherited deref;
  2240. elementdef:=tdef(elementdefderef.resolve);
  2241. end;
  2242. function tsetdef.is_publishable : boolean;
  2243. begin
  2244. is_publishable:=savesize in [1,2,4];
  2245. end;
  2246. function tsetdef.GetTypeName : string;
  2247. begin
  2248. if assigned(elementdef) then
  2249. GetTypeName:='Set Of '+elementdef.typename
  2250. else
  2251. GetTypeName:='Empty Set';
  2252. end;
  2253. {***************************************************************************
  2254. TFORMALDEF
  2255. ***************************************************************************}
  2256. constructor tformaldef.create(Atyped:boolean);
  2257. begin
  2258. inherited create(formaldef);
  2259. typed:=Atyped;
  2260. savesize:=0;
  2261. end;
  2262. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2263. begin
  2264. inherited ppuload(formaldef,ppufile);
  2265. typed:=boolean(ppufile.getbyte);
  2266. savesize:=0;
  2267. end;
  2268. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2269. begin
  2270. inherited ppuwrite(ppufile);
  2271. ppufile.putbyte(byte(typed));
  2272. ppufile.writeentry(ibformaldef);
  2273. end;
  2274. function tformaldef.GetTypeName : string;
  2275. begin
  2276. if typed then
  2277. GetTypeName:='<Typed formal type>'
  2278. else
  2279. GetTypeName:='<Formal type>';
  2280. end;
  2281. {***************************************************************************
  2282. TARRAYDEF
  2283. ***************************************************************************}
  2284. constructor tarraydef.create(l,h:asizeint;def:tdef);
  2285. begin
  2286. inherited create(arraydef);
  2287. lowrange:=l;
  2288. highrange:=h;
  2289. rangedef:=def;
  2290. _elementdef:=nil;
  2291. arrayoptions:=[];
  2292. symtable:=tarraysymtable.create(self);
  2293. end;
  2294. destructor tarraydef.destroy;
  2295. begin
  2296. symtable.free;
  2297. symtable:=nil;
  2298. inherited;
  2299. end;
  2300. constructor tarraydef.create_from_pointer(def:tdef);
  2301. begin
  2302. { use -1 so that the elecount will not overflow }
  2303. self.create(0,high(aint)-1,s32inttype);
  2304. arrayoptions:=[ado_IsConvertedPointer];
  2305. setelementdef(def);
  2306. end;
  2307. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2308. begin
  2309. inherited ppuload(arraydef,ppufile);
  2310. { the addresses are calculated later }
  2311. ppufile.getderef(_elementdefderef);
  2312. ppufile.getderef(rangedefderef);
  2313. lowrange:=ppufile.getaint;
  2314. highrange:=ppufile.getaint;
  2315. ppufile.getsmallset(arrayoptions);
  2316. symtable:=tarraysymtable.create(self);
  2317. tarraysymtable(symtable).ppuload(ppufile)
  2318. end;
  2319. function tarraydef.getcopy : tstoreddef;
  2320. begin
  2321. result:=tarraydef.create(lowrange,highrange,rangedef);
  2322. tarraydef(result).arrayoptions:=arrayoptions;
  2323. tarraydef(result)._elementdef:=_elementdef;
  2324. end;
  2325. procedure tarraydef.buildderef;
  2326. begin
  2327. inherited buildderef;
  2328. tarraysymtable(symtable).buildderef;
  2329. _elementdefderef.build(_elementdef);
  2330. rangedefderef.build(rangedef);
  2331. end;
  2332. procedure tarraydef.deref;
  2333. begin
  2334. inherited deref;
  2335. tarraysymtable(symtable).deref;
  2336. _elementdef:=tdef(_elementdefderef.resolve);
  2337. rangedef:=tdef(rangedefderef.resolve);
  2338. end;
  2339. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2340. begin
  2341. inherited ppuwrite(ppufile);
  2342. ppufile.putderef(_elementdefderef);
  2343. ppufile.putderef(rangedefderef);
  2344. ppufile.putaint(lowrange);
  2345. ppufile.putaint(highrange);
  2346. ppufile.putsmallset(arrayoptions);
  2347. ppufile.writeentry(ibarraydef);
  2348. tarraysymtable(symtable).ppuwrite(ppufile);
  2349. end;
  2350. function tarraydef.elesize : asizeint;
  2351. begin
  2352. if (ado_IsBitPacked in arrayoptions) then
  2353. internalerror(2006080101);
  2354. if assigned(_elementdef) then
  2355. result:=_elementdef.size
  2356. else
  2357. result:=0;
  2358. end;
  2359. function tarraydef.elepackedbitsize : asizeint;
  2360. begin
  2361. if not(ado_IsBitPacked in arrayoptions) then
  2362. internalerror(2006080102);
  2363. if assigned(_elementdef) then
  2364. result:=_elementdef.packedbitsize
  2365. else
  2366. result:=0;
  2367. end;
  2368. function tarraydef.elecount : asizeuint;
  2369. var
  2370. qhigh,qlow : qword;
  2371. begin
  2372. if ado_IsDynamicArray in arrayoptions then
  2373. begin
  2374. result:=0;
  2375. exit;
  2376. end;
  2377. if (highrange>0) and (lowrange<0) then
  2378. begin
  2379. qhigh:=highrange;
  2380. qlow:=qword(-lowrange);
  2381. { prevent overflow, return 0 to indicate overflow }
  2382. if qhigh+qlow>qword(high(asizeint)-1) then
  2383. result:=0
  2384. else
  2385. result:=qhigh+qlow+1;
  2386. end
  2387. else
  2388. result:=int64(highrange)-lowrange+1;
  2389. end;
  2390. function tarraydef.size : asizeint;
  2391. var
  2392. cachedelecount : asizeuint;
  2393. cachedelesize : asizeint;
  2394. begin
  2395. if ado_IsDynamicArray in arrayoptions then
  2396. begin
  2397. size:=sizeof(pint);
  2398. exit;
  2399. end;
  2400. { Tarraydef.size may never be called for an open array! }
  2401. if highrange<lowrange then
  2402. internalerror(99080501);
  2403. if not (ado_IsBitPacked in arrayoptions) then
  2404. cachedelesize:=elesize
  2405. else
  2406. cachedelesize := elepackedbitsize;
  2407. cachedelecount:=elecount;
  2408. if (cachedelesize = 0) then
  2409. begin
  2410. size := 0;
  2411. exit;
  2412. end;
  2413. if (cachedelecount = 0) then
  2414. begin
  2415. size := -1;
  2416. exit;
  2417. end;
  2418. { prevent overflow, return -1 to indicate overflow }
  2419. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  2420. if (cachedelecount > asizeuint(high(asizeint))) or
  2421. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  2422. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  2423. accessing the array, see ncgmem (PFV) }
  2424. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  2425. begin
  2426. result:=-1;
  2427. exit;
  2428. end;
  2429. result:=cachedelesize*asizeint(cachedelecount);
  2430. if (ado_IsBitPacked in arrayoptions) then
  2431. { can't just add 7 and divide by 8, because that may overflow }
  2432. result:=result div 8 + ord((result mod 8)<>0);
  2433. end;
  2434. procedure tarraydef.setelementdef(def:tdef);
  2435. begin
  2436. _elementdef:=def;
  2437. if not(
  2438. (ado_IsDynamicArray in arrayoptions) or
  2439. (ado_IsConvertedPointer in arrayoptions) or
  2440. (highrange<lowrange)
  2441. ) and
  2442. (size=-1) then
  2443. Message(sym_e_segment_too_large);
  2444. end;
  2445. function tarraydef.alignment : shortint;
  2446. begin
  2447. { alignment of dyn. arrays doesn't depend on the element size }
  2448. if (ado_IsDynamicArray in arrayoptions) then
  2449. alignment:=size_2_align(sizeof(pint))
  2450. { alignment is the alignment of the elements }
  2451. else if (elementdef.typ in [arraydef,recorddef,orddef,enumdef,floatdef]) or
  2452. ((elementdef.typ=objectdef) and
  2453. is_object(elementdef)) then
  2454. alignment:=elementdef.alignment
  2455. { alignment is the size of the elements }
  2456. else if not (ado_IsBitPacked in arrayoptions) then
  2457. alignment:=size_2_align(elesize)
  2458. else
  2459. alignment:=packedbitsloadsize(elepackedbitsize);
  2460. end;
  2461. function tarraydef.needs_inittable : boolean;
  2462. begin
  2463. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  2464. end;
  2465. function tarraydef.GetTypeName : string;
  2466. begin
  2467. if (ado_IsConstString in arrayoptions) then
  2468. result:='Constant String'
  2469. else if (ado_isarrayofconst in arrayoptions) or
  2470. (ado_isConstructor in arrayoptions) then
  2471. begin
  2472. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  2473. GetTypeName:='Array Of Const'
  2474. else
  2475. GetTypeName:='Array Of Const/Constant Open Array of '+elementdef.typename;
  2476. end
  2477. else if (ado_IsDynamicArray in arrayoptions) then
  2478. GetTypeName:='Dynamic Array Of '+elementdef.typename
  2479. else if ((highrange=-1) and (lowrange=0)) then
  2480. GetTypeName:='Open Array Of '+elementdef.typename
  2481. else
  2482. begin
  2483. result := '';
  2484. if (ado_IsBitPacked in arrayoptions) then
  2485. result:='Packed ';
  2486. if rangedef.typ=enumdef then
  2487. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  2488. else
  2489. result:=result+'Array['+tostr(lowrange)+'..'+
  2490. tostr(highrange)+'] Of '+elementdef.typename
  2491. end;
  2492. end;
  2493. function tarraydef.getmangledparaname : string;
  2494. begin
  2495. if ado_isarrayofconst in arrayoptions then
  2496. getmangledparaname:='array_of_const'
  2497. else
  2498. if ((highrange=-1) and (lowrange=0)) then
  2499. getmangledparaname:='array_of_'+elementdef.mangledparaname
  2500. else
  2501. internalerror(200204176);
  2502. end;
  2503. function tarraydef.is_publishable : boolean;
  2504. begin
  2505. Result:=ado_IsDynamicArray in arrayoptions;
  2506. end;
  2507. {***************************************************************************
  2508. tabstractrecorddef
  2509. ***************************************************************************}
  2510. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp);
  2511. begin
  2512. inherited create(dt);
  2513. objname:=stringdup(upper(n));
  2514. objrealname:=stringdup(n);
  2515. objectoptions:=[];
  2516. end;
  2517. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2518. begin
  2519. inherited ppuload(dt,ppufile);
  2520. objrealname:=stringdup(ppufile.getstring);
  2521. objname:=stringdup(upper(objrealname^));
  2522. ppufile.getsmallset(objectoptions);
  2523. end;
  2524. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  2525. begin
  2526. inherited ppuwrite(ppufile);
  2527. ppufile.putstring(objrealname^);
  2528. ppufile.putsmallset(objectoptions);
  2529. end;
  2530. destructor tabstractrecorddef.destroy;
  2531. begin
  2532. stringdispose(objname);
  2533. stringdispose(objrealname);
  2534. inherited destroy;
  2535. end;
  2536. procedure tabstractrecorddef.check_forwards;
  2537. begin
  2538. tstoredsymtable(symtable).check_forwards;
  2539. end;
  2540. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  2541. var
  2542. i: longint;
  2543. sym: tsym;
  2544. begin
  2545. for i:=0 to symtable.SymList.Count-1 do
  2546. begin
  2547. sym:=tsym(symtable.SymList[i]);
  2548. if sym.typ=procsym then
  2549. begin
  2550. result:=tprocsym(sym).find_procdef_bytype(pt);
  2551. if assigned(result) then
  2552. exit;
  2553. end;
  2554. end;
  2555. result:=nil;
  2556. end;
  2557. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  2558. begin
  2559. if t=gs_record then
  2560. GetSymtable:=symtable
  2561. else
  2562. GetSymtable:=nil;
  2563. end;
  2564. function tabstractrecorddef.is_packed:boolean;
  2565. begin
  2566. result:=tabstractrecordsymtable(symtable).is_packed;
  2567. end;
  2568. function tabstractrecorddef.RttiName: string;
  2569. begin
  2570. Result:=OwnerHierarchyName+objrealname^;
  2571. end;
  2572. function tabstractrecorddef.search_enumerator_get: tprocdef;
  2573. var
  2574. sym : tsym;
  2575. i : integer;
  2576. pd : tprocdef;
  2577. hashedid : THashedIDString;
  2578. begin
  2579. result:=nil;
  2580. hashedid.id:='GETENUMERATOR';
  2581. sym:=tsym(symtable.FindWithHash(hashedid));
  2582. if assigned(sym) and (sym.typ=procsym) then
  2583. begin
  2584. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  2585. begin
  2586. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  2587. if (pd.proctypeoption = potype_function) and
  2588. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  2589. (pd.visibility >= vis_public) then
  2590. begin
  2591. result:=pd;
  2592. exit;
  2593. end;
  2594. end;
  2595. end;
  2596. end;
  2597. function tabstractrecorddef.search_enumerator_move: tprocdef;
  2598. var
  2599. sym : tsym;
  2600. i : integer;
  2601. pd : tprocdef;
  2602. hashedid : THashedIDString;
  2603. begin
  2604. result:=nil;
  2605. // first search for po_enumerator_movenext method modifier
  2606. // then search for public function MoveNext: Boolean
  2607. for i:=0 to symtable.SymList.Count-1 do
  2608. begin
  2609. sym:=TSym(symtable.SymList[i]);
  2610. if (sym.typ=procsym) then
  2611. begin
  2612. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  2613. if assigned(pd) then
  2614. begin
  2615. result:=pd;
  2616. exit;
  2617. end;
  2618. end;
  2619. end;
  2620. hashedid.id:='MOVENEXT';
  2621. sym:=tsym(symtable.FindWithHash(hashedid));
  2622. if assigned(sym) and (sym.typ=procsym) then
  2623. begin
  2624. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  2625. begin
  2626. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  2627. if (pd.proctypeoption = potype_function) and
  2628. is_boolean(pd.returndef) and
  2629. (pd.minparacount = 0) and
  2630. (pd.visibility >= vis_public) then
  2631. begin
  2632. result:=pd;
  2633. exit;
  2634. end;
  2635. end;
  2636. end;
  2637. end;
  2638. function tabstractrecorddef.search_enumerator_current: tsym;
  2639. var
  2640. sym: tsym;
  2641. i: integer;
  2642. hashedid : THashedIDString;
  2643. begin
  2644. result:=nil;
  2645. // first search for ppo_enumerator_current property modifier
  2646. // then search for public property Current
  2647. for i:=0 to symtable.SymList.Count-1 do
  2648. begin
  2649. sym:=TSym(symtable.SymList[i]);
  2650. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  2651. begin
  2652. result:=sym;
  2653. exit;
  2654. end;
  2655. end;
  2656. hashedid.id:='CURRENT';
  2657. sym:=tsym(symtable.FindWithHash(hashedid));
  2658. if assigned(sym) and (sym.typ=propertysym) and
  2659. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  2660. begin
  2661. result:=sym;
  2662. exit;
  2663. end;
  2664. end;
  2665. {***************************************************************************
  2666. trecorddef
  2667. ***************************************************************************}
  2668. constructor trecorddef.create(const n:string; p:TSymtable);
  2669. begin
  2670. inherited create(n,recorddef);
  2671. symtable:=p;
  2672. { we can own the symtable only if nobody else owns a copy so far }
  2673. if symtable.refcount=1 then
  2674. symtable.defowner:=self;
  2675. isunion:=false;
  2676. end;
  2677. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2678. begin
  2679. inherited ppuload(recorddef,ppufile);
  2680. if df_copied_def in defoptions then
  2681. ppufile.getderef(cloneddefderef)
  2682. else
  2683. begin
  2684. symtable:=trecordsymtable.create(objrealname^,0);
  2685. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2686. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2687. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2688. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  2689. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  2690. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  2691. trecordsymtable(symtable).ppuload(ppufile);
  2692. { requires usefieldalignment to be set }
  2693. symtable.defowner:=self;
  2694. end;
  2695. isunion:=false;
  2696. end;
  2697. destructor trecorddef.destroy;
  2698. begin
  2699. if assigned(symtable) then
  2700. begin
  2701. symtable.free;
  2702. symtable:=nil;
  2703. end;
  2704. inherited destroy;
  2705. end;
  2706. function trecorddef.getcopy : tstoreddef;
  2707. begin
  2708. result:=trecorddef.create(objrealname^,symtable.getcopy);
  2709. trecorddef(result).isunion:=isunion;
  2710. include(trecorddef(result).defoptions,df_copied_def);
  2711. end;
  2712. function trecorddef.needs_inittable : boolean;
  2713. begin
  2714. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2715. end;
  2716. procedure trecorddef.buildderef;
  2717. begin
  2718. inherited buildderef;
  2719. if df_copied_def in defoptions then
  2720. cloneddefderef.build(symtable.defowner)
  2721. else
  2722. tstoredsymtable(symtable).buildderef;
  2723. end;
  2724. procedure trecorddef.deref;
  2725. begin
  2726. inherited deref;
  2727. { now dereference the definitions }
  2728. if df_copied_def in defoptions then
  2729. begin
  2730. cloneddef:=trecorddef(cloneddefderef.resolve);
  2731. symtable:=cloneddef.symtable.getcopy;
  2732. end
  2733. else
  2734. tstoredsymtable(symtable).deref;
  2735. { assign TGUID? load only from system unit }
  2736. if not(assigned(rec_tguid)) and
  2737. (upper(typename)='TGUID') and
  2738. assigned(owner) and
  2739. assigned(owner.name) and
  2740. (owner.name^='SYSTEM') then
  2741. rec_tguid:=self;
  2742. { assign JMP_BUF? load only from system unit }
  2743. if not(assigned(rec_jmp_buf)) and
  2744. (upper(typename)='JMP_BUF') and
  2745. assigned(owner) and
  2746. assigned(owner.name) and
  2747. (owner.name^='SYSTEM') then
  2748. rec_jmp_buf:=self;
  2749. end;
  2750. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2751. begin
  2752. inherited ppuwrite(ppufile);
  2753. if df_copied_def in defoptions then
  2754. ppufile.putderef(cloneddefderef)
  2755. else
  2756. begin
  2757. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2758. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2759. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2760. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  2761. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  2762. ppufile.putword(trecordsymtable(symtable).paddingsize);
  2763. end;
  2764. ppufile.writeentry(ibrecorddef);
  2765. if not(df_copied_def in defoptions) then
  2766. trecordsymtable(symtable).ppuwrite(ppufile);
  2767. end;
  2768. function trecorddef.size:asizeint;
  2769. begin
  2770. result:=trecordsymtable(symtable).datasize;
  2771. end;
  2772. function trecorddef.alignment:shortint;
  2773. begin
  2774. alignment:=trecordsymtable(symtable).recordalignment;
  2775. end;
  2776. function trecorddef.padalignment:shortint;
  2777. begin
  2778. padalignment := trecordsymtable(symtable).padalignment;
  2779. end;
  2780. function trecorddef.GetTypeName : string;
  2781. begin
  2782. GetTypeName:='<record type>'
  2783. end;
  2784. {***************************************************************************
  2785. TABSTRACTPROCDEF
  2786. ***************************************************************************}
  2787. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  2788. begin
  2789. inherited create(dt);
  2790. parast:=tparasymtable.create(self,level);
  2791. paras:=nil;
  2792. minparacount:=0;
  2793. maxparacount:=0;
  2794. proctypeoption:=potype_none;
  2795. proccalloption:=pocall_none;
  2796. procoptions:=[];
  2797. returndef:=voidtype;
  2798. savesize:=sizeof(pint);
  2799. callerargareasize:=0;
  2800. calleeargareasize:=0;
  2801. has_paraloc_info:=callnoside;
  2802. funcretloc[callerside].init;
  2803. funcretloc[calleeside].init;
  2804. check_mark_as_nested;
  2805. end;
  2806. destructor tabstractprocdef.destroy;
  2807. begin
  2808. if assigned(paras) then
  2809. begin
  2810. {$ifdef MEMDEBUG}
  2811. memprocpara.start;
  2812. {$endif MEMDEBUG}
  2813. paras.free;
  2814. paras:=nil;
  2815. {$ifdef MEMDEBUG}
  2816. memprocpara.stop;
  2817. {$endif MEMDEBUG}
  2818. end;
  2819. if assigned(parast) then
  2820. begin
  2821. {$ifdef MEMDEBUG}
  2822. memprocparast.start;
  2823. {$endif MEMDEBUG}
  2824. parast.free;
  2825. parast:=nil;
  2826. {$ifdef MEMDEBUG}
  2827. memprocparast.stop;
  2828. {$endif MEMDEBUG}
  2829. end;
  2830. funcretloc[callerside].done;
  2831. funcretloc[calleeside].done;
  2832. inherited destroy;
  2833. end;
  2834. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  2835. begin
  2836. if (tsym(p).typ<>paravarsym) then
  2837. exit;
  2838. inc(plongint(arg)^);
  2839. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  2840. begin
  2841. if not assigned(tparavarsym(p).defaultconstsym) then
  2842. inc(minparacount);
  2843. inc(maxparacount);
  2844. end;
  2845. end;
  2846. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  2847. begin
  2848. if (tsym(p).typ<>paravarsym) then
  2849. exit;
  2850. paras.add(p);
  2851. end;
  2852. procedure tabstractprocdef.calcparas;
  2853. var
  2854. paracount : longint;
  2855. begin
  2856. { This can already be assigned when
  2857. we need to reresolve this unit (PFV) }
  2858. if assigned(paras) then
  2859. paras.free;
  2860. paras:=tparalist.create(false);
  2861. paracount:=0;
  2862. minparacount:=0;
  2863. maxparacount:=0;
  2864. parast.SymList.ForEachCall(@count_para,@paracount);
  2865. paras.capacity:=paracount;
  2866. { Insert parameters in table }
  2867. parast.SymList.ForEachCall(@insert_para,nil);
  2868. { Order parameters }
  2869. paras.sortparas;
  2870. end;
  2871. procedure tabstractprocdef.buildderef;
  2872. begin
  2873. { released procdef? }
  2874. if not assigned(parast) then
  2875. exit;
  2876. inherited buildderef;
  2877. returndefderef.build(returndef);
  2878. { parast }
  2879. tparasymtable(parast).buildderef;
  2880. end;
  2881. procedure tabstractprocdef.deref;
  2882. begin
  2883. inherited deref;
  2884. returndef:=tdef(returndefderef.resolve);
  2885. { parast }
  2886. tparasymtable(parast).deref;
  2887. { recalculated parameters }
  2888. calcparas;
  2889. end;
  2890. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2891. begin
  2892. inherited ppuload(dt,ppufile);
  2893. parast:=nil;
  2894. Paras:=nil;
  2895. minparacount:=0;
  2896. maxparacount:=0;
  2897. ppufile.getderef(returndefderef);
  2898. { TODO: remove fpu_used loading}
  2899. ppufile.getbyte;
  2900. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2901. proccalloption:=tproccalloption(ppufile.getbyte);
  2902. ppufile.getnormalset(procoptions);
  2903. funcretloc[callerside].init;
  2904. if po_explicitparaloc in procoptions then
  2905. funcretloc[callerside].ppuload(ppufile);
  2906. savesize:=sizeof(pint);
  2907. if (po_explicitparaloc in procoptions) then
  2908. has_paraloc_info:=callerside;
  2909. end;
  2910. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2911. var
  2912. oldintfcrc : boolean;
  2913. begin
  2914. { released procdef? }
  2915. if not assigned(parast) then
  2916. exit;
  2917. inherited ppuwrite(ppufile);
  2918. ppufile.putderef(returndefderef);
  2919. oldintfcrc:=ppufile.do_interface_crc;
  2920. ppufile.do_interface_crc:=false;
  2921. ppufile.putbyte(0);
  2922. ppufile.putbyte(ord(proctypeoption));
  2923. ppufile.putbyte(ord(proccalloption));
  2924. ppufile.putnormalset(procoptions);
  2925. ppufile.do_interface_crc:=oldintfcrc;
  2926. if (po_explicitparaloc in procoptions) then
  2927. funcretloc[callerside].ppuwrite(ppufile);
  2928. end;
  2929. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2930. var
  2931. hs,s : string;
  2932. hp : TParavarsym;
  2933. hpc : tconstsym;
  2934. first : boolean;
  2935. i : integer;
  2936. begin
  2937. s:='';
  2938. first:=true;
  2939. for i:=0 to paras.count-1 do
  2940. begin
  2941. hp:=tparavarsym(paras[i]);
  2942. if not(vo_is_hidden_para in hp.varoptions) or
  2943. (showhidden) then
  2944. begin
  2945. if first then
  2946. begin
  2947. s:=s+'(';
  2948. first:=false;
  2949. end
  2950. else
  2951. s:=s+',';
  2952. if vo_is_hidden_para in hp.varoptions then
  2953. s:=s+'<';
  2954. case hp.varspez of
  2955. vs_var :
  2956. s:=s+'var ';
  2957. vs_const :
  2958. s:=s+'const ';
  2959. vs_out :
  2960. s:=s+'out ';
  2961. vs_constref :
  2962. s:=s+'constref ';
  2963. end;
  2964. if hp.univpara then
  2965. s:=s+'univ ';
  2966. if assigned(hp.vardef.typesym) then
  2967. begin
  2968. hs:=hp.vardef.typesym.realname;
  2969. if hs[1]<>'$' then
  2970. s:=s+hs
  2971. else
  2972. s:=s+hp.vardef.GetTypeName;
  2973. end
  2974. else
  2975. s:=s+hp.vardef.GetTypeName;
  2976. { default value }
  2977. if assigned(hp.defaultconstsym) then
  2978. begin
  2979. hpc:=tconstsym(hp.defaultconstsym);
  2980. hs:='';
  2981. case hpc.consttyp of
  2982. conststring,
  2983. constresourcestring :
  2984. begin
  2985. If hpc.value.len>0 then
  2986. begin
  2987. setLength(hs,hpc.value.len);
  2988. { don't write past the end of hs if the constant
  2989. is > 255 chars }
  2990. move(hpc.value.valueptr^,hs[1],length(hs));
  2991. { make sure that constant strings with newline chars
  2992. don't create a linebreak in the assembler code,
  2993. since comments are line-based. Also remove nulls
  2994. because the comments are written as a pchar. }
  2995. ReplaceCase(hs,#0,'.');
  2996. ReplaceCase(hs,#10,'.');
  2997. ReplaceCase(hs,#13,'.');
  2998. end;
  2999. end;
  3000. constreal :
  3001. str(pbestreal(hpc.value.valueptr)^,hs);
  3002. constpointer :
  3003. hs:=tostr(hpc.value.valueordptr);
  3004. constord :
  3005. begin
  3006. if is_boolean(hpc.constdef) then
  3007. begin
  3008. if hpc.value.valueord<>0 then
  3009. hs:='TRUE'
  3010. else
  3011. hs:='FALSE';
  3012. end
  3013. else
  3014. hs:=tostr(hpc.value.valueord);
  3015. end;
  3016. constnil :
  3017. hs:='nil';
  3018. constset :
  3019. hs:='<set>';
  3020. end;
  3021. if hs<>'' then
  3022. s:=s+'="'+hs+'"';
  3023. end;
  3024. if vo_is_hidden_para in hp.varoptions then
  3025. s:=s+'>';
  3026. end;
  3027. end;
  3028. if not first then
  3029. s:=s+')';
  3030. if (po_varargs in procoptions) then
  3031. s:=s+';VarArgs';
  3032. typename_paras:=s;
  3033. end;
  3034. function tabstractprocdef.is_methodpointer:boolean;
  3035. begin
  3036. result:=false;
  3037. end;
  3038. function tabstractprocdef.is_addressonly:boolean;
  3039. begin
  3040. result:=true;
  3041. end;
  3042. function tabstractprocdef.no_self_node: boolean;
  3043. begin
  3044. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  3045. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  3046. end;
  3047. procedure tabstractprocdef.check_mark_as_nested;
  3048. begin
  3049. { nested procvars require that nested functions use the Delphi-style
  3050. nested procedure calling convention }
  3051. if (parast.symtablelevel>normal_function_level) and
  3052. (m_nested_procvars in current_settings.modeswitches) then
  3053. include(procoptions,po_delphi_nested_cc);
  3054. end;
  3055. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  3056. begin
  3057. if (side in [callerside,callbothsides]) and
  3058. not(has_paraloc_info in [callerside,callbothsides]) then
  3059. begin
  3060. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  3061. if has_paraloc_info in [calleeside,callbothsides] then
  3062. has_paraloc_info:=callbothsides
  3063. else
  3064. has_paraloc_info:=callerside;
  3065. end;
  3066. if (side in [calleeside,callbothsides]) and
  3067. not(has_paraloc_info in [calleeside,callbothsides]) then
  3068. begin
  3069. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  3070. if has_paraloc_info in [callerside,callbothsides] then
  3071. has_paraloc_info:=callbothsides
  3072. else
  3073. has_paraloc_info:=calleeside;
  3074. end;
  3075. end;
  3076. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  3077. var
  3078. p: tparavarsym;
  3079. ploc: PCGParalocation;
  3080. i: longint;
  3081. begin
  3082. result:=false;
  3083. init_paraloc_info(side);
  3084. for i:=0 to parast.SymList.Count-1 do
  3085. if tsym(parast.SymList[i]).typ=paravarsym then
  3086. begin
  3087. p:=tparavarsym(parast.SymList[i]);
  3088. { check if no parameter is located on the stack }
  3089. if is_open_array(p.vardef) or
  3090. is_array_of_const(p.vardef) then
  3091. begin
  3092. result:=true;
  3093. exit;
  3094. end;
  3095. ploc:=p.paraloc[side].location;
  3096. while assigned(ploc) do
  3097. begin
  3098. if (ploc^.loc=LOC_REFERENCE) then
  3099. begin
  3100. result:=true;
  3101. exit
  3102. end;
  3103. ploc:=ploc^.next;
  3104. end;
  3105. end;
  3106. end;
  3107. {***************************************************************************
  3108. TPROCDEF
  3109. ***************************************************************************}
  3110. constructor tprocdef.create(level:byte);
  3111. begin
  3112. inherited create(procdef,level);
  3113. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  3114. _mangledname:=nil;
  3115. fileinfo:=current_filepos;
  3116. extnumber:=$ffff;
  3117. aliasnames:=TCmdStrList.create;
  3118. funcretsym:=nil;
  3119. forwarddef:=true;
  3120. interfacedef:=false;
  3121. hasforward:=false;
  3122. struct := nil;
  3123. import_dll:=nil;
  3124. import_name:=nil;
  3125. import_nr:=0;
  3126. inlininginfo:=nil;
  3127. deprecatedmsg:=nil;
  3128. {$ifdef i386}
  3129. fpu_used:=maxfpuregs;
  3130. {$endif i386}
  3131. interruptvector:=-1;
  3132. end;
  3133. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3134. var
  3135. i,aliasnamescount : longint;
  3136. level : byte;
  3137. begin
  3138. inherited ppuload(procdef,ppufile);
  3139. if po_has_mangledname in procoptions then
  3140. _mangledname:=stringdup(ppufile.getstring)
  3141. else
  3142. _mangledname:=nil;
  3143. extnumber:=ppufile.getword;
  3144. level:=ppufile.getbyte;
  3145. ppufile.getderef(structderef);
  3146. ppufile.getderef(procsymderef);
  3147. ppufile.getposinfo(fileinfo);
  3148. visibility:=tvisibility(ppufile.getbyte);
  3149. ppufile.getsmallset(symoptions);
  3150. if sp_has_deprecated_msg in symoptions then
  3151. deprecatedmsg:=stringdup(ppufile.getstring)
  3152. else
  3153. deprecatedmsg:=nil;
  3154. {$ifdef powerpc}
  3155. { library symbol for AmigaOS/MorphOS }
  3156. ppufile.getderef(libsymderef);
  3157. {$endif powerpc}
  3158. { import stuff }
  3159. if po_has_importdll in procoptions then
  3160. import_dll:=stringdup(ppufile.getstring)
  3161. else
  3162. import_dll:=nil;
  3163. if po_has_importname in procoptions then
  3164. import_name:=stringdup(ppufile.getstring)
  3165. else
  3166. import_name:=nil;
  3167. import_nr:=ppufile.getword;
  3168. {$ifdef FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3169. if target_info.system in systems_interrupt_table then
  3170. interruptvector:=ppufile.getlongint;
  3171. {$endif FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3172. if (po_msgint in procoptions) then
  3173. messageinf.i:=ppufile.getlongint;
  3174. if (po_msgstr in procoptions) then
  3175. messageinf.str:=stringdup(ppufile.getstring);
  3176. if (po_dispid in procoptions) then
  3177. dispid:=ppufile.getlongint;
  3178. { inline stuff }
  3179. if (po_has_inlininginfo in procoptions) then
  3180. begin
  3181. ppufile.getderef(funcretsymderef);
  3182. new(inlininginfo);
  3183. ppufile.getsmallset(inlininginfo^.flags);
  3184. end
  3185. else
  3186. begin
  3187. inlininginfo:=nil;
  3188. funcretsym:=nil;
  3189. end;
  3190. aliasnames:=TCmdStrList.create;
  3191. { count alias names }
  3192. aliasnamescount:=ppufile.getbyte;
  3193. for i:=1 to aliasnamescount do
  3194. aliasnames.insert(ppufile.getstring);
  3195. { load para symtable }
  3196. parast:=tparasymtable.create(self,level);
  3197. tparasymtable(parast).ppuload(ppufile);
  3198. { load local symtable }
  3199. if (po_has_inlininginfo in procoptions) then
  3200. begin
  3201. localst:=tlocalsymtable.create(self,level);
  3202. tlocalsymtable(localst).ppuload(ppufile);
  3203. end
  3204. else
  3205. localst:=nil;
  3206. { inline stuff }
  3207. if (po_has_inlininginfo in procoptions) then
  3208. inlininginfo^.code:=ppuloadnodetree(ppufile);
  3209. { default values for no persistent data }
  3210. if (cs_link_deffile in current_settings.globalswitches) and
  3211. (tf_need_export in target_info.flags) and
  3212. (po_exports in procoptions) then
  3213. deffile.AddExport(mangledname);
  3214. forwarddef:=false;
  3215. interfacedef:=false;
  3216. hasforward:=false;
  3217. { Disable po_has_inlining until the derefimpl is done }
  3218. exclude(procoptions,po_has_inlininginfo);
  3219. {$ifdef i386}
  3220. fpu_used:=maxfpuregs;
  3221. {$endif i386}
  3222. end;
  3223. destructor tprocdef.destroy;
  3224. begin
  3225. aliasnames.free;
  3226. aliasnames:=nil;
  3227. if assigned(localst) and
  3228. (localst.symtabletype<>staticsymtable) then
  3229. begin
  3230. {$ifdef MEMDEBUG}
  3231. memproclocalst.start;
  3232. {$endif MEMDEBUG}
  3233. localst.free;
  3234. localst:=nil;
  3235. {$ifdef MEMDEBUG}
  3236. memproclocalst.start;
  3237. {$endif MEMDEBUG}
  3238. end;
  3239. if assigned(inlininginfo) then
  3240. begin
  3241. {$ifdef MEMDEBUG}
  3242. memprocnodetree.start;
  3243. {$endif MEMDEBUG}
  3244. tnode(inlininginfo^.code).free;
  3245. {$ifdef MEMDEBUG}
  3246. memprocnodetree.start;
  3247. {$endif MEMDEBUG}
  3248. dispose(inlininginfo);
  3249. inlininginfo:=nil;
  3250. end;
  3251. stringdispose(resultname);
  3252. stringdispose(import_dll);
  3253. stringdispose(import_name);
  3254. stringdispose(deprecatedmsg);
  3255. if (po_msgstr in procoptions) then
  3256. stringdispose(messageinf.str);
  3257. if assigned(_mangledname) then
  3258. begin
  3259. {$ifdef MEMDEBUG}
  3260. memmanglednames.start;
  3261. {$endif MEMDEBUG}
  3262. stringdispose(_mangledname);
  3263. {$ifdef MEMDEBUG}
  3264. memmanglednames.stop;
  3265. {$endif MEMDEBUG}
  3266. end;
  3267. inherited destroy;
  3268. end;
  3269. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3270. var
  3271. oldintfcrc : boolean;
  3272. aliasnamescount : longint;
  3273. item : TCmdStrListItem;
  3274. begin
  3275. { released procdef? }
  3276. if not assigned(parast) then
  3277. exit;
  3278. inherited ppuwrite(ppufile);
  3279. if po_has_mangledname in procoptions then
  3280. ppufile.putstring(_mangledname^);
  3281. ppufile.putword(extnumber);
  3282. ppufile.putbyte(parast.symtablelevel);
  3283. ppufile.putderef(structderef);
  3284. ppufile.putderef(procsymderef);
  3285. ppufile.putposinfo(fileinfo);
  3286. ppufile.putbyte(byte(visibility));
  3287. ppufile.putsmallset(symoptions);
  3288. if sp_has_deprecated_msg in symoptions then
  3289. ppufile.putstring(deprecatedmsg^);
  3290. {$ifdef powerpc}
  3291. { library symbol for AmigaOS/MorphOS }
  3292. ppufile.putderef(libsymderef);
  3293. {$endif powerpc}
  3294. { import }
  3295. if po_has_importdll in procoptions then
  3296. ppufile.putstring(import_dll^);
  3297. if po_has_importname in procoptions then
  3298. ppufile.putstring(import_name^);
  3299. ppufile.putword(import_nr);
  3300. {$ifdef FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3301. if target_info.system in systems_interrupt_table then
  3302. ppufile.putlongint(interruptvector);
  3303. {$endif FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3304. if (po_msgint in procoptions) then
  3305. ppufile.putlongint(messageinf.i);
  3306. if (po_msgstr in procoptions) then
  3307. ppufile.putstring(messageinf.str^);
  3308. if (po_dispid in procoptions) then
  3309. ppufile.putlongint(dispid);
  3310. { inline stuff }
  3311. oldintfcrc:=ppufile.do_crc;
  3312. ppufile.do_crc:=false;
  3313. if (po_has_inlininginfo in procoptions) then
  3314. begin
  3315. ppufile.putderef(funcretsymderef);
  3316. ppufile.putsmallset(inlininginfo^.flags);
  3317. end;
  3318. { count alias names }
  3319. aliasnamescount:=0;
  3320. item:=TCmdStrListItem(aliasnames.first);
  3321. while assigned(item) do
  3322. begin
  3323. inc(aliasnamescount);
  3324. item:=TCmdStrListItem(item.next);
  3325. end;
  3326. if aliasnamescount>255 then
  3327. internalerror(200711021);
  3328. ppufile.putbyte(aliasnamescount);
  3329. item:=TCmdStrListItem(aliasnames.first);
  3330. while assigned(item) do
  3331. begin
  3332. ppufile.putstring(item.str);
  3333. item:=TCmdStrListItem(item.next);
  3334. end;
  3335. ppufile.do_crc:=oldintfcrc;
  3336. { write this entry }
  3337. ppufile.writeentry(ibprocdef);
  3338. { Save the para symtable, this is taken from the interface }
  3339. tparasymtable(parast).ppuwrite(ppufile);
  3340. { save localsymtable for inline procedures or when local
  3341. browser info is requested, this has no influence on the crc }
  3342. if (po_has_inlininginfo in procoptions) then
  3343. begin
  3344. oldintfcrc:=ppufile.do_crc;
  3345. ppufile.do_crc:=false;
  3346. tlocalsymtable(localst).ppuwrite(ppufile);
  3347. ppufile.do_crc:=oldintfcrc;
  3348. end;
  3349. { node tree for inlining }
  3350. oldintfcrc:=ppufile.do_crc;
  3351. ppufile.do_crc:=false;
  3352. if (po_has_inlininginfo in procoptions) then
  3353. ppuwritenodetree(ppufile,inlininginfo^.code);
  3354. ppufile.do_crc:=oldintfcrc;
  3355. end;
  3356. function tprocdef.fullprocname(showhidden:boolean):string;
  3357. var
  3358. s : string;
  3359. t : ttoken;
  3360. begin
  3361. {$ifdef EXTDEBUG}
  3362. showhidden:=true;
  3363. {$endif EXTDEBUG}
  3364. s:='';
  3365. if assigned(struct) then
  3366. begin
  3367. s:=struct.RttiName+'.';
  3368. if (po_classmethod in procoptions) and
  3369. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  3370. s:='class ' + s;
  3371. end;
  3372. if proctypeoption=potype_operator then
  3373. begin
  3374. for t:=NOTOKEN to last_overloaded do
  3375. if procsym.realname='$'+overloaded_names[t] then
  3376. begin
  3377. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3378. break;
  3379. end;
  3380. end
  3381. else
  3382. s:=s+procsym.realname+typename_paras(showhidden);
  3383. case proctypeoption of
  3384. potype_constructor:
  3385. s:='constructor '+s;
  3386. potype_destructor:
  3387. s:='destructor '+s;
  3388. potype_class_constructor:
  3389. s:='class constructor '+s;
  3390. potype_class_destructor:
  3391. s:='class destructor '+s;
  3392. else
  3393. if assigned(returndef) and
  3394. not(is_void(returndef)) then
  3395. s:=s+':'+returndef.GetTypeName;
  3396. end;
  3397. if owner.symtabletype=localsymtable then
  3398. s:=s+' is nested';
  3399. s:=s+';';
  3400. { forced calling convention? }
  3401. if (po_hascallingconvention in procoptions) then
  3402. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  3403. if (po_staticmethod in procoptions) and
  3404. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  3405. s:=s+' Static;';
  3406. fullprocname:=s;
  3407. end;
  3408. function tprocdef.is_methodpointer:boolean;
  3409. begin
  3410. { don't check assigned(_class), that's also the case for nested
  3411. procedures inside methods }
  3412. result:=owner.symtabletype=ObjectSymtable;
  3413. end;
  3414. function tprocdef.is_addressonly:boolean;
  3415. begin
  3416. result:=assigned(owner) and
  3417. (owner.symtabletype<>ObjectSymtable) and
  3418. (not(m_nested_procvars in current_settings.modeswitches) or
  3419. not is_nested_pd(self));
  3420. end;
  3421. procedure tprocdef.make_external;
  3422. begin
  3423. include(procoptions,po_external);
  3424. forwarddef:=false;
  3425. end;
  3426. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  3427. begin
  3428. case t of
  3429. gs_local :
  3430. GetSymtable:=localst;
  3431. gs_para :
  3432. GetSymtable:=parast;
  3433. else
  3434. GetSymtable:=nil;
  3435. end;
  3436. end;
  3437. procedure tprocdef.buildderef;
  3438. begin
  3439. inherited buildderef;
  3440. structderef.build(struct);
  3441. { procsym that originaly defined this definition, should be in the
  3442. same symtable }
  3443. procsymderef.build(procsym);
  3444. {$ifdef powerpc}
  3445. { library symbol for AmigaOS/MorphOS }
  3446. libsymderef.build(libsym);
  3447. {$endif powerpc}
  3448. end;
  3449. procedure tprocdef.buildderefimpl;
  3450. begin
  3451. inherited buildderefimpl;
  3452. { Localst is not available for main/unit init }
  3453. if assigned(localst) then
  3454. begin
  3455. tlocalsymtable(localst).buildderef;
  3456. tlocalsymtable(localst).buildderefimpl;
  3457. end;
  3458. { inline tree }
  3459. if (po_has_inlininginfo in procoptions) then
  3460. begin
  3461. funcretsymderef.build(funcretsym);
  3462. inlininginfo^.code.buildderefimpl;
  3463. end;
  3464. end;
  3465. procedure tprocdef.deref;
  3466. begin
  3467. inherited deref;
  3468. struct:=tabstractrecorddef(structderef.resolve);
  3469. { procsym that originaly defined this definition, should be in the
  3470. same symtable }
  3471. procsym:=tprocsym(procsymderef.resolve);
  3472. {$ifdef powerpc}
  3473. { library symbol for AmigaOS/MorphOS }
  3474. libsym:=tsym(libsymderef.resolve);
  3475. {$endif powerpc}
  3476. end;
  3477. procedure tprocdef.derefimpl;
  3478. begin
  3479. { Enable has_inlininginfo when the inlininginfo
  3480. structure is available. The has_inlininginfo was disabled
  3481. after the load, since the data was invalid }
  3482. if assigned(inlininginfo) then
  3483. include(procoptions,po_has_inlininginfo);
  3484. { Locals }
  3485. if assigned(localst) then
  3486. begin
  3487. tlocalsymtable(localst).deref;
  3488. tlocalsymtable(localst).derefimpl;
  3489. end;
  3490. { Inline }
  3491. if (po_has_inlininginfo in procoptions) then
  3492. begin
  3493. inlininginfo^.code.derefimpl;
  3494. { funcretsym, this is always located in the localst }
  3495. funcretsym:=tsym(funcretsymderef.resolve);
  3496. end
  3497. else
  3498. begin
  3499. { safety }
  3500. { Not safe! A unit may be reresolved after its interface has been
  3501. parsed but before its implementation has been parsed, and in that
  3502. case the funcretsym is still required!
  3503. funcretsym:=nil; }
  3504. end;
  3505. end;
  3506. function tprocdef.GetTypeName : string;
  3507. begin
  3508. GetTypeName := FullProcName(false);
  3509. end;
  3510. function tprocdef.mangledname : string;
  3511. var
  3512. hp : TParavarsym;
  3513. hs : string;
  3514. crc : dword;
  3515. newlen,
  3516. oldlen,
  3517. i : integer;
  3518. begin
  3519. if assigned(_mangledname) then
  3520. begin
  3521. {$ifdef compress}
  3522. mangledname:=minilzw_decode(_mangledname^);
  3523. {$else}
  3524. mangledname:=_mangledname^;
  3525. {$endif}
  3526. exit;
  3527. end;
  3528. { we need to use the symtable where the procsym is inserted,
  3529. because that is visible to the world }
  3530. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3531. oldlen:=length(mangledname);
  3532. { add parameter types }
  3533. for i:=0 to paras.count-1 do
  3534. begin
  3535. hp:=tparavarsym(paras[i]);
  3536. if not(vo_is_hidden_para in hp.varoptions) then
  3537. mangledname:=mangledname+'$'+hp.vardef.mangledparaname;
  3538. end;
  3539. { add resultdef, add $$ as separator to make it unique from a
  3540. parameter separator }
  3541. if not is_void(returndef) then
  3542. mangledname:=mangledname+'$$'+returndef.mangledparaname;
  3543. newlen:=length(mangledname);
  3544. { Replace with CRC if the parameter line is very long }
  3545. if (newlen-oldlen>12) and
  3546. ((newlen>100) or (newlen-oldlen>64)) then
  3547. begin
  3548. crc:=0;
  3549. for i:=0 to paras.count-1 do
  3550. begin
  3551. hp:=tparavarsym(paras[i]);
  3552. if not(vo_is_hidden_para in hp.varoptions) then
  3553. begin
  3554. hs:=hp.vardef.mangledparaname;
  3555. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3556. end;
  3557. end;
  3558. hs:=hp.vardef.mangledparaname;
  3559. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3560. mangledname:=Copy(mangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  3561. end;
  3562. {$ifdef compress}
  3563. _mangledname:=stringdup(minilzw_encode(mangledname));
  3564. {$else}
  3565. _mangledname:=stringdup(mangledname);
  3566. {$endif}
  3567. end;
  3568. function tprocdef.cplusplusmangledname : string;
  3569. function getcppparaname(p : tdef) : string;
  3570. const
  3571. {$ifdef NAMEMANGLING_GCC2}
  3572. ordtype2str : array[tordtype] of string[2] = (
  3573. '',
  3574. 'Uc','Us','Ui','Us',
  3575. 'Sc','s','i','x',
  3576. 'b','b','b','b','b',
  3577. 'c','w','x');
  3578. {$else NAMEMANGLING_GCC2}
  3579. ordtype2str : array[tordtype] of string[1] = (
  3580. 'v',
  3581. 'h','t','j','y',
  3582. 'a','s','i','x',
  3583. 'b','b','b','b',
  3584. 'b','b','b','b',
  3585. 'c','w','x');
  3586. floattype2str : array[tfloattype] of string[1] = (
  3587. 'f','d','e','e',
  3588. 'd','d','g');
  3589. {$endif NAMEMANGLING_GCC2}
  3590. var
  3591. s : string;
  3592. begin
  3593. case p.typ of
  3594. orddef:
  3595. s:=ordtype2str[torddef(p).ordtype];
  3596. pointerdef:
  3597. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  3598. {$ifndef NAMEMANGLING_GCC2}
  3599. floatdef:
  3600. s:=floattype2str[tfloatdef(p).floattype];
  3601. {$endif NAMEMANGLING_GCC2}
  3602. else
  3603. internalerror(2103001);
  3604. end;
  3605. getcppparaname:=s;
  3606. end;
  3607. var
  3608. s,s2 : string;
  3609. hp : TParavarsym;
  3610. i : integer;
  3611. begin
  3612. {$ifdef NAMEMANGLING_GCC2}
  3613. { outdated gcc 2.x name mangling scheme }
  3614. s := procsym.realname;
  3615. if procsym.owner.symtabletype=ObjectSymtable then
  3616. begin
  3617. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  3618. case proctypeoption of
  3619. potype_destructor:
  3620. s:='_$_'+tostr(length(s2))+s2;
  3621. potype_constructor:
  3622. s:='___'+tostr(length(s2))+s2;
  3623. else
  3624. s:='_'+s+'__'+tostr(length(s2))+s2;
  3625. end;
  3626. end
  3627. else s:=s+'__';
  3628. s:=s+'F';
  3629. { concat modifiers }
  3630. { !!!!! }
  3631. { now we handle the parameters }
  3632. if maxparacount>0 then
  3633. begin
  3634. for i:=0 to paras.count-1 do
  3635. begin
  3636. hp:=tparavarsym(paras[i]);
  3637. { no hidden parameters form part of a C++ mangled name:
  3638. a) self is not included
  3639. b) there are no "high" or other hidden parameters
  3640. }
  3641. if vo_is_hidden_para in hp.varoptions then
  3642. continue;
  3643. s2:=getcppparaname(hp.vardef);
  3644. if hp.varspez in [vs_var,vs_out] then
  3645. s2:='R'+s2;
  3646. s:=s+s2;
  3647. end;
  3648. end
  3649. else
  3650. s:=s+'v';
  3651. cplusplusmangledname:=s;
  3652. {$else NAMEMANGLING_GCC2}
  3653. { gcc 3.x and 4.x name mangling scheme }
  3654. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  3655. if procsym.owner.symtabletype=ObjectSymtable then
  3656. begin
  3657. s:='_ZN';
  3658. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  3659. s:=s+tostr(length(s2))+s2;
  3660. case proctypeoption of
  3661. potype_constructor:
  3662. s:=s+'C1';
  3663. potype_destructor:
  3664. s:=s+'D1';
  3665. else
  3666. s:=s+tostr(length(procsym.realname))+procsym.realname;
  3667. end;
  3668. s:=s+'E';
  3669. end
  3670. else
  3671. s:=procsym.realname;
  3672. { now we handle the parameters }
  3673. if maxparacount>0 then
  3674. begin
  3675. for i:=0 to paras.count-1 do
  3676. begin
  3677. hp:=tparavarsym(paras[i]);
  3678. { no hidden parameters form part of a C++ mangled name:
  3679. a) self is not included
  3680. b) there are no "high" or other hidden parameters
  3681. }
  3682. if vo_is_hidden_para in hp.varoptions then
  3683. continue;
  3684. s2:=getcppparaname(hp.vardef);
  3685. if hp.varspez in [vs_var,vs_out] then
  3686. s2:='R'+s2;
  3687. s:=s+s2;
  3688. end;
  3689. end
  3690. else
  3691. s:=s+'v';
  3692. cplusplusmangledname:=s;
  3693. {$endif NAMEMANGLING_GCC2}
  3694. end;
  3695. function tprocdef.objcmangledname : string;
  3696. var
  3697. manglednamelen: longint;
  3698. iscatmethod : boolean;
  3699. begin
  3700. if not (po_msgstr in procoptions) then
  3701. internalerror(2009030901);
  3702. { we may very well need longer strings to handle these... }
  3703. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  3704. length('+"[ ]"')+length(messageinf.str^);
  3705. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  3706. if (iscatmethod) then
  3707. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  3708. if manglednamelen>255 then
  3709. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  3710. if not(po_classmethod in procoptions) then
  3711. result:='"-['
  3712. else
  3713. result:='"+[';
  3714. { quotes are necessary because the +/- otherwise confuse the assembler
  3715. into expecting a number
  3716. }
  3717. if iscatmethod then
  3718. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  3719. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  3720. if iscatmethod then
  3721. result:=result+')';
  3722. result:=result+' '+messageinf.str^+']"';
  3723. end;
  3724. procedure tprocdef.setmangledname(const s : string);
  3725. begin
  3726. { This is not allowed anymore, the forward declaration
  3727. already needs to create the correct mangledname, no changes
  3728. afterwards are allowed (PFV) }
  3729. { Exception: interface definitions in mode macpas, since in that }
  3730. { case no reference to the old name can exist yet (JM) }
  3731. if assigned(_mangledname) then
  3732. if ((m_mac in current_settings.modeswitches) and
  3733. (interfacedef)) then
  3734. stringdispose(_mangledname)
  3735. else
  3736. internalerror(200411171);
  3737. {$ifdef compress}
  3738. _mangledname:=stringdup(minilzw_encode(s));
  3739. {$else}
  3740. _mangledname:=stringdup(s);
  3741. {$endif}
  3742. include(procoptions,po_has_mangledname);
  3743. end;
  3744. {***************************************************************************
  3745. TPROCVARDEF
  3746. ***************************************************************************}
  3747. constructor tprocvardef.create(level:byte);
  3748. begin
  3749. inherited create(procvardef,level);
  3750. end;
  3751. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3752. begin
  3753. inherited ppuload(procvardef,ppufile);
  3754. { load para symtable }
  3755. parast:=tparasymtable.create(self,ppufile.getbyte);
  3756. tparasymtable(parast).ppuload(ppufile);
  3757. end;
  3758. function tprocvardef.getcopy : tstoreddef;
  3759. var
  3760. i : tcallercallee;
  3761. j : longint;
  3762. begin
  3763. result:=tprocvardef.create(parast.symtablelevel);
  3764. tprocvardef(result).returndef:=returndef;
  3765. tprocvardef(result).returndefderef:=returndefderef;
  3766. tprocvardef(result).parast:=parast.getcopy;
  3767. tprocvardef(result).savesize:=savesize;
  3768. { create paralist copy }
  3769. tprocvardef(result).paras:=tparalist.create(false);
  3770. tprocvardef(result).paras.count:=paras.count;
  3771. for j:=0 to paras.count-1 do
  3772. tprocvardef(result).paras[j]:=paras[j];
  3773. tprocvardef(result).proctypeoption:=proctypeoption;
  3774. tprocvardef(result).proccalloption:=proccalloption;
  3775. tprocvardef(result).procoptions:=procoptions;
  3776. tprocvardef(result).callerargareasize:=callerargareasize;
  3777. tprocvardef(result).calleeargareasize:=calleeargareasize;
  3778. tprocvardef(result).maxparacount:=maxparacount;
  3779. tprocvardef(result).minparacount:=minparacount;
  3780. for i:=low(tcallercallee) to high(tcallercallee) do
  3781. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  3782. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  3783. {$ifdef m68k}
  3784. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  3785. {$endif}
  3786. end;
  3787. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3788. begin
  3789. inherited ppuwrite(ppufile);
  3790. { Save the para symtable level (necessary to distinguish nested
  3791. procvars) }
  3792. ppufile.putbyte(parast.symtablelevel);
  3793. { Write this entry }
  3794. ppufile.writeentry(ibprocvardef);
  3795. { Save the para symtable, this is taken from the interface }
  3796. tparasymtable(parast).ppuwrite(ppufile);
  3797. end;
  3798. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  3799. begin
  3800. case t of
  3801. gs_para :
  3802. GetSymtable:=parast;
  3803. else
  3804. GetSymtable:=nil;
  3805. end;
  3806. end;
  3807. function tprocvardef.size : asizeint;
  3808. begin
  3809. if ((po_methodpointer in procoptions) or
  3810. is_nested_pd(self)) and
  3811. not(po_addressonly in procoptions) then
  3812. size:=2*sizeof(pint)
  3813. else
  3814. size:=sizeof(pint);
  3815. end;
  3816. function tprocvardef.is_methodpointer:boolean;
  3817. begin
  3818. result:=(po_methodpointer in procoptions);
  3819. end;
  3820. function tprocvardef.is_addressonly:boolean;
  3821. begin
  3822. result:=(not(po_methodpointer in procoptions) and
  3823. not is_nested_pd(self)) or
  3824. (po_addressonly in procoptions);
  3825. end;
  3826. function tprocvardef.getmangledparaname:string;
  3827. begin
  3828. if not(po_methodpointer in procoptions) then
  3829. if not is_nested_pd(self) then
  3830. result:='procvar'
  3831. else
  3832. result:='nestedprovar'
  3833. else
  3834. result:='procvarofobj'
  3835. end;
  3836. function tprocvardef.is_publishable : boolean;
  3837. begin
  3838. is_publishable:=(po_methodpointer in procoptions);
  3839. end;
  3840. function tprocvardef.GetTypeName : string;
  3841. var
  3842. s: string;
  3843. showhidden : boolean;
  3844. begin
  3845. {$ifdef EXTDEBUG}
  3846. showhidden:=true;
  3847. {$else EXTDEBUG}
  3848. showhidden:=false;
  3849. {$endif EXTDEBUG}
  3850. s:='<';
  3851. if po_classmethod in procoptions then
  3852. s := s+'class method type of'
  3853. else
  3854. if po_addressonly in procoptions then
  3855. s := s+'address of'
  3856. else
  3857. s := s+'procedure variable type of';
  3858. if assigned(returndef) and
  3859. (returndef<>voidtype) then
  3860. s:=s+' function'+typename_paras(showhidden)+':'+returndef.GetTypeName
  3861. else
  3862. s:=s+' procedure'+typename_paras(showhidden);
  3863. if po_methodpointer in procoptions then
  3864. s := s+' of object';
  3865. if is_nested_pd(self) then
  3866. s := s+' is nested';
  3867. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3868. end;
  3869. {***************************************************************************
  3870. TOBJECTDEF
  3871. ***************************************************************************}
  3872. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  3873. begin
  3874. inherited create(n,objectdef);
  3875. fcurrent_dispid:=0;
  3876. objecttype:=ot;
  3877. childof:=nil;
  3878. if objecttype=odt_helper then
  3879. owner.includeoption(sto_has_helper);
  3880. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  3881. { create space for vmt !! }
  3882. vmtentries:=TFPList.Create;
  3883. vmt_offset:=0;
  3884. set_parent(c);
  3885. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  3886. prepareguid;
  3887. { setup implemented interfaces }
  3888. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol] then
  3889. ImplementedInterfaces:=TFPObjectList.Create(true)
  3890. else
  3891. ImplementedInterfaces:=nil;
  3892. writing_class_record_dbginfo:=false;
  3893. end;
  3894. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3895. var
  3896. i,
  3897. implintfcount : longint;
  3898. d : tderef;
  3899. ImplIntf : TImplementedInterface;
  3900. vmtentry : pvmtentry;
  3901. begin
  3902. inherited ppuload(objectdef,ppufile);
  3903. objecttype:=tobjecttyp(ppufile.getbyte);
  3904. objextname:=stringdup(ppufile.getstring);
  3905. { only used for external Objective-C classes/protocols }
  3906. if (objextname^='') then
  3907. stringdispose(objextname);
  3908. import_lib:=stringdup(ppufile.getstring);
  3909. { only used for external C++ classes }
  3910. if (import_lib^='') then
  3911. stringdispose(import_lib);
  3912. symtable:=tObjectSymtable.create(self,objrealname^,0);
  3913. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  3914. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  3915. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  3916. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  3917. vmt_offset:=ppufile.getlongint;
  3918. ppufile.getderef(childofderef);
  3919. { load guid }
  3920. iidstr:=nil;
  3921. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3922. begin
  3923. new(iidguid);
  3924. ppufile.getguid(iidguid^);
  3925. iidstr:=stringdup(ppufile.getstring);
  3926. end;
  3927. if objecttype=odt_helper then
  3928. ppufile.getderef(extendeddefderef);
  3929. vmtentries:=TFPList.Create;
  3930. vmtentries.count:=ppufile.getlongint;
  3931. for i:=0 to vmtentries.count-1 do
  3932. begin
  3933. ppufile.getderef(d);
  3934. new(vmtentry);
  3935. vmtentry^.procdef:=nil;
  3936. vmtentry^.procdefderef:=d;
  3937. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  3938. vmtentries[i]:=vmtentry;
  3939. end;
  3940. { load implemented interfaces }
  3941. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol] then
  3942. begin
  3943. ImplementedInterfaces:=TFPObjectList.Create(true);
  3944. implintfcount:=ppufile.getlongint;
  3945. for i:=0 to implintfcount-1 do
  3946. begin
  3947. ppufile.getderef(d);
  3948. ImplIntf:=TImplementedInterface.Create_deref(d);
  3949. ImplIntf.IOffset:=ppufile.getlongint;
  3950. ImplementedInterfaces.Add(ImplIntf);
  3951. end;
  3952. end
  3953. else
  3954. ImplementedInterfaces:=nil;
  3955. if df_copied_def in defoptions then
  3956. ppufile.getderef(cloneddefderef)
  3957. else
  3958. tObjectSymtable(symtable).ppuload(ppufile);
  3959. { handles the predefined class tobject }
  3960. { the last TOBJECT which is loaded gets }
  3961. { it ! }
  3962. if (childof=nil) and
  3963. (objecttype=odt_class) and
  3964. (objname^='TOBJECT') then
  3965. class_tobject:=self;
  3966. if (childof=nil) and
  3967. (objecttype=odt_interfacecom) then
  3968. if (objname^='IUNKNOWN') then
  3969. interface_iunknown:=self
  3970. else
  3971. if (objname^='IDISPATCH') then
  3972. interface_idispatch:=self;
  3973. if (childof=nil) and
  3974. (objecttype=odt_objcclass) and
  3975. (objname^='PROTOCOL') then
  3976. objc_protocoltype:=self;
  3977. writing_class_record_dbginfo:=false;
  3978. end;
  3979. destructor tobjectdef.destroy;
  3980. begin
  3981. if assigned(symtable) then
  3982. begin
  3983. symtable.free;
  3984. symtable:=nil;
  3985. end;
  3986. stringdispose(objextname);
  3987. stringdispose(import_lib);
  3988. stringdispose(iidstr);
  3989. if assigned(ImplementedInterfaces) then
  3990. begin
  3991. ImplementedInterfaces.free;
  3992. ImplementedInterfaces:=nil;
  3993. end;
  3994. if assigned(iidguid) then
  3995. begin
  3996. dispose(iidguid);
  3997. iidguid:=nil;
  3998. end;
  3999. if assigned(vmtentries) then
  4000. begin
  4001. resetvmtentries;
  4002. vmtentries.free;
  4003. vmtentries:=nil;
  4004. end;
  4005. if assigned(vmcallstaticinfo) then
  4006. begin
  4007. freemem(vmcallstaticinfo);
  4008. vmcallstaticinfo:=nil;
  4009. end;
  4010. inherited destroy;
  4011. end;
  4012. function tobjectdef.getcopy : tstoreddef;
  4013. var
  4014. i : longint;
  4015. begin
  4016. result:=tobjectdef.create(objecttype,objrealname^,childof);
  4017. { the constructor allocates a symtable which we release to avoid memory leaks }
  4018. tobjectdef(result).symtable.free;
  4019. tobjectdef(result).symtable:=symtable.getcopy;
  4020. if assigned(objextname) then
  4021. tobjectdef(result).objextname:=stringdup(objextname^);
  4022. if assigned(import_lib) then
  4023. tobjectdef(result).import_lib:=stringdup(import_lib^);
  4024. tobjectdef(result).objectoptions:=objectoptions;
  4025. include(tobjectdef(result).defoptions,df_copied_def);
  4026. tobjectdef(result).extendeddef:=extendeddef;
  4027. tobjectdef(result).vmt_offset:=vmt_offset;
  4028. if assigned(iidguid) then
  4029. begin
  4030. new(tobjectdef(result).iidguid);
  4031. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  4032. end;
  4033. if assigned(iidstr) then
  4034. tobjectdef(result).iidstr:=stringdup(iidstr^);
  4035. if assigned(ImplementedInterfaces) then
  4036. begin
  4037. for i:=0 to ImplementedInterfaces.count-1 do
  4038. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  4039. end;
  4040. if assigned(vmtentries) then
  4041. begin
  4042. tobjectdef(result).vmtentries:=TFPList.Create;
  4043. tobjectdef(result).copyvmtentries(self);
  4044. end;
  4045. end;
  4046. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4047. var
  4048. i : longint;
  4049. vmtentry : pvmtentry;
  4050. ImplIntf : TImplementedInterface;
  4051. old_do_indirect_crc: boolean;
  4052. begin
  4053. { if class1 in unit A changes, and class2 in unit B inherits from it
  4054. (so unit B uses unit A), then unit B with class2 will be recompiled.
  4055. However, if there is also a class3 in unit C that only depends on
  4056. unit B, then unit C will not be recompiled because nothing changed
  4057. to the interface of unit B. Nevertheless, unit C can indirectly
  4058. depend on unit A via derefs, and these must be updated -> the
  4059. indirect crc keeps track of such changes. }
  4060. old_do_indirect_crc:=ppufile.do_indirect_crc;
  4061. ppufile.do_indirect_crc:=true;
  4062. inherited ppuwrite(ppufile);
  4063. ppufile.putbyte(byte(objecttype));
  4064. if assigned(objextname) then
  4065. ppufile.putstring(objextname^)
  4066. else
  4067. ppufile.putstring('');
  4068. if assigned(import_lib) then
  4069. ppufile.putstring(import_lib^)
  4070. else
  4071. ppufile.putstring('');
  4072. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  4073. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  4074. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  4075. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  4076. ppufile.putlongint(vmt_offset);
  4077. ppufile.putderef(childofderef);
  4078. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  4079. begin
  4080. ppufile.putguid(iidguid^);
  4081. ppufile.putstring(iidstr^);
  4082. end;
  4083. if objecttype=odt_helper then
  4084. ppufile.putderef(extendeddefderef);
  4085. ppufile.putlongint(vmtentries.count);
  4086. for i:=0 to vmtentries.count-1 do
  4087. begin
  4088. vmtentry:=pvmtentry(vmtentries[i]);
  4089. ppufile.putderef(vmtentry^.procdefderef);
  4090. ppufile.putbyte(byte(vmtentry^.visibility));
  4091. end;
  4092. if assigned(ImplementedInterfaces) then
  4093. begin
  4094. ppufile.putlongint(ImplementedInterfaces.Count);
  4095. for i:=0 to ImplementedInterfaces.Count-1 do
  4096. begin
  4097. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  4098. ppufile.putderef(ImplIntf.intfdefderef);
  4099. ppufile.putlongint(ImplIntf.Ioffset);
  4100. end;
  4101. end;
  4102. if df_copied_def in defoptions then
  4103. ppufile.putderef(cloneddefderef);
  4104. ppufile.writeentry(ibobjectdef);
  4105. if not(df_copied_def in defoptions) then
  4106. tObjectSymtable(symtable).ppuwrite(ppufile);
  4107. ppufile.do_indirect_crc:=old_do_indirect_crc;
  4108. end;
  4109. function tobjectdef.GetTypeName:string;
  4110. begin
  4111. { in this case we will go in endless recursion, because then }
  4112. { there is no tsym associated yet with the def. It can occur }
  4113. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  4114. { instead of the actual type name }
  4115. if not assigned(typesym) then
  4116. result:='<Currently Parsed Class>'
  4117. else
  4118. result:=typesymbolprettyname;
  4119. end;
  4120. procedure tobjectdef.buildderef;
  4121. var
  4122. i : longint;
  4123. vmtentry : pvmtentry;
  4124. begin
  4125. inherited buildderef;
  4126. childofderef.build(childof);
  4127. if df_copied_def in defoptions then
  4128. cloneddefderef.build(symtable.defowner)
  4129. else
  4130. tstoredsymtable(symtable).buildderef;
  4131. if objecttype=odt_helper then
  4132. extendeddefderef.build(extendeddef);
  4133. for i:=0 to vmtentries.count-1 do
  4134. begin
  4135. vmtentry:=pvmtentry(vmtentries[i]);
  4136. vmtentry^.procdefderef.build(vmtentry^.procdef);
  4137. end;
  4138. if assigned(ImplementedInterfaces) then
  4139. begin
  4140. for i:=0 to ImplementedInterfaces.count-1 do
  4141. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  4142. end;
  4143. end;
  4144. procedure tobjectdef.deref;
  4145. var
  4146. i : longint;
  4147. vmtentry : pvmtentry;
  4148. begin
  4149. inherited deref;
  4150. childof:=tobjectdef(childofderef.resolve);
  4151. if df_copied_def in defoptions then
  4152. begin
  4153. cloneddef:=tobjectdef(cloneddefderef.resolve);
  4154. symtable:=cloneddef.symtable.getcopy;
  4155. end
  4156. else
  4157. tstoredsymtable(symtable).deref;
  4158. if objecttype=odt_helper then
  4159. extendeddef:=tdef(extendeddefderef.resolve);
  4160. for i:=0 to vmtentries.count-1 do
  4161. begin
  4162. vmtentry:=pvmtentry(vmtentries[i]);
  4163. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  4164. end;
  4165. if assigned(ImplementedInterfaces) then
  4166. begin
  4167. for i:=0 to ImplementedInterfaces.count-1 do
  4168. TImplementedInterface(ImplementedInterfaces[i]).deref;
  4169. end;
  4170. end;
  4171. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  4172. var
  4173. pd: tprocdef absolute def;
  4174. st: tsymtable;
  4175. psym: tsym;
  4176. nname: TIDString;
  4177. begin
  4178. if (tdef(def).typ<>procdef) then
  4179. exit;
  4180. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  4181. owner = symtable in which objcclassdef is defined
  4182. }
  4183. st:=pd.owner.defowner.owner;
  4184. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  4185. { check for an existing procsym with our special name }
  4186. psym:=tsym(st.find(nname));
  4187. if not assigned(psym) then
  4188. begin
  4189. psym:=tprocsym.create(nname);
  4190. { avoid warning about this symbol being unused }
  4191. psym.IncRefCount;
  4192. { don't check for duplicates:
  4193. a) we checked above
  4194. b) in case we are in the implementation section of a unit, this
  4195. will also check for this symbol in the interface section
  4196. (since you normally cannot have symbols with the same name
  4197. both interface and implementation), and it's possible to
  4198. have class helpers for the same class in the interface and
  4199. in the implementation, and they cannot be merged since only
  4200. the once in the interface must be saved to the ppu/visible
  4201. from other units }
  4202. st.insert(psym,false);
  4203. end
  4204. else if (psym.typ<>procsym) then
  4205. internalerror(2009111501);
  4206. { add ourselves to this special procsym }
  4207. tprocsym(psym).procdeflist.add(def);
  4208. end;
  4209. procedure tobjectdef.buildderefimpl;
  4210. begin
  4211. inherited buildderefimpl;
  4212. if not (df_copied_def in defoptions) then
  4213. tstoredsymtable(symtable).buildderefimpl;
  4214. end;
  4215. procedure tobjectdef.derefimpl;
  4216. begin
  4217. inherited derefimpl;
  4218. if not (df_copied_def in defoptions) then
  4219. tstoredsymtable(symtable).derefimpl;
  4220. { the procdefs are not owned by the class helper procsyms, so they
  4221. are not stored/restored either -> re-add them here }
  4222. if (objecttype=odt_objcclass) or
  4223. (oo_is_classhelper in objectoptions) then
  4224. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  4225. end;
  4226. procedure tobjectdef.resetvmtentries;
  4227. var
  4228. i : longint;
  4229. begin
  4230. for i:=0 to vmtentries.Count-1 do
  4231. Dispose(pvmtentry(vmtentries[i]));
  4232. vmtentries.clear;
  4233. end;
  4234. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  4235. var
  4236. i : longint;
  4237. vmtentry : pvmtentry;
  4238. begin
  4239. resetvmtentries;
  4240. vmtentries.count:=objdef.vmtentries.count;
  4241. for i:=0 to objdef.vmtentries.count-1 do
  4242. begin
  4243. new(vmtentry);
  4244. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  4245. vmtentries[i]:=vmtentry;
  4246. end;
  4247. end;
  4248. function tobjectdef.getparentdef:tdef;
  4249. begin
  4250. { TODO: Remove getparentdef hack}
  4251. { With 2 forward declared classes with the child class before the
  4252. parent class the child class is written earlier to the ppu. Leaving it
  4253. possible to have a reference to the parent class for property overriding,
  4254. but the parent class still has the childof not resolved yet (PFV) }
  4255. if childof=nil then
  4256. childof:=tobjectdef(childofderef.resolve);
  4257. result:=childof;
  4258. end;
  4259. procedure tobjectdef.prepareguid;
  4260. begin
  4261. { set up guid }
  4262. if not assigned(iidguid) then
  4263. begin
  4264. new(iidguid);
  4265. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4266. end;
  4267. { setup iidstring }
  4268. if not assigned(iidstr) then
  4269. iidstr:=stringdup(''); { default is empty string }
  4270. end;
  4271. procedure tobjectdef.set_parent( c : tobjectdef);
  4272. begin
  4273. if assigned(childof) then
  4274. exit;
  4275. childof:=c;
  4276. if not assigned(c) then
  4277. exit;
  4278. { inherit options and status }
  4279. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  4280. { add the data of the anchestor class/object }
  4281. if (objecttype in [odt_class,odt_object,odt_objcclass]) then
  4282. begin
  4283. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  4284. { inherit recordalignment }
  4285. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  4286. { if both the parent and this record use C-alignment, also inherit
  4287. the current field alignment }
  4288. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  4289. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  4290. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  4291. { the padding is not inherited for Objective-C classes (maybe not
  4292. for cppclass either?) }
  4293. if objecttype=odt_objcclass then
  4294. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  4295. if (oo_has_vmt in objectoptions) and
  4296. (oo_has_vmt in c.objectoptions) then
  4297. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  4298. { if parent has a vmt field then the offset is the same for the child PM }
  4299. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4300. begin
  4301. vmt_offset:=c.vmt_offset;
  4302. include(objectoptions,oo_has_vmt);
  4303. end;
  4304. end;
  4305. end;
  4306. procedure tobjectdef.insertvmt;
  4307. var
  4308. vs: tfieldvarsym;
  4309. begin
  4310. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol] then
  4311. exit;
  4312. if (oo_has_vmt in objectoptions) then
  4313. internalerror(12345)
  4314. else
  4315. begin
  4316. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  4317. tObjectSymtable(symtable).fieldalignment);
  4318. if (tf_requires_proper_alignment in target_info.flags) then
  4319. begin
  4320. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  4321. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  4322. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  4323. end;
  4324. vs:=tfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  4325. hidesym(vs);
  4326. tObjectSymtable(symtable).insert(vs);
  4327. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  4328. if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  4329. vmt_offset:=vs.fieldoffset
  4330. else
  4331. vmt_offset:=vs.fieldoffset div 8;
  4332. include(objectoptions,oo_has_vmt);
  4333. end;
  4334. end;
  4335. procedure tobjectdef.check_forwards;
  4336. begin
  4337. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol]) then
  4338. inherited;
  4339. if (oo_is_forward in objectoptions) then
  4340. begin
  4341. { ok, in future, the forward can be resolved }
  4342. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4343. exclude(objectoptions,oo_is_forward);
  4344. end;
  4345. end;
  4346. { true if prot implements d (or if they are equal) }
  4347. function is_related_protocol(prot: tobjectdef; d : tdef) : boolean;
  4348. var
  4349. i : longint;
  4350. begin
  4351. { objcprotocols have multiple inheritance, all protocols from which
  4352. the current protocol inherits are stored in implementedinterfaces }
  4353. result:=prot=d;
  4354. if result then
  4355. exit;
  4356. for i:=0 to prot.ImplementedInterfaces.count-1 do
  4357. begin
  4358. result:=is_related_protocol(TImplementedInterface(prot.ImplementedInterfaces[i]).intfdef,d);
  4359. if result then
  4360. exit;
  4361. end;
  4362. end;
  4363. { true, if self inherits from d (or if they are equal) }
  4364. function tobjectdef.is_related(d : tdef) : boolean;
  4365. var
  4366. hp : tobjectdef;
  4367. begin
  4368. if self=d then
  4369. begin
  4370. is_related:=true;
  4371. exit;
  4372. end;
  4373. if (d.typ<>objectdef) then
  4374. begin
  4375. is_related:=false;
  4376. exit;
  4377. end;
  4378. { Objective-C protocols can use multiple inheritance }
  4379. if (objecttype=odt_objcprotocol) then
  4380. begin
  4381. is_related:=is_related_protocol(self,d);
  4382. exit
  4383. end;
  4384. { formally declared Objective-C classes match Objective-C classes with
  4385. the same name }
  4386. if (objecttype=odt_objcclass) and
  4387. (tobjectdef(d).objecttype=odt_objcclass) and
  4388. ((oo_is_formal in objectoptions) or
  4389. (oo_is_formal in tobjectdef(d).objectoptions)) and
  4390. (objrealname^=tobjectdef(d).objrealname^) then
  4391. begin
  4392. is_related:=true;
  4393. exit;
  4394. end;
  4395. hp:=childof;
  4396. while assigned(hp) do
  4397. begin
  4398. if hp=d then
  4399. begin
  4400. is_related:=true;
  4401. exit;
  4402. end;
  4403. hp:=hp.childof;
  4404. end;
  4405. is_related:=false;
  4406. end;
  4407. function tobjectdef.find_destructor: tprocdef;
  4408. var
  4409. objdef: tobjectdef;
  4410. begin
  4411. objdef:=self;
  4412. while assigned(objdef) do
  4413. begin
  4414. result:=objdef.find_procdef_bytype(potype_destructor);
  4415. if assigned(result) then
  4416. exit;
  4417. objdef:=objdef.childof;
  4418. end;
  4419. result:=nil;
  4420. end;
  4421. function tobjectdef.implements_any_interfaces: boolean;
  4422. begin
  4423. result := (ImplementedInterfaces.Count > 0) or
  4424. (assigned(childof) and childof.implements_any_interfaces);
  4425. end;
  4426. function tobjectdef.size : asizeint;
  4427. begin
  4428. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper] then
  4429. result:=sizeof(pint)
  4430. else
  4431. result:=tObjectSymtable(symtable).datasize;
  4432. end;
  4433. function tobjectdef.alignment:shortint;
  4434. begin
  4435. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper] then
  4436. alignment:=sizeof(pint)
  4437. else
  4438. alignment:=tObjectSymtable(symtable).recordalignment;
  4439. end;
  4440. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4441. begin
  4442. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4443. case objecttype of
  4444. odt_class:
  4445. { the +2*sizeof(pint) is size and -size }
  4446. vmtmethodoffset:=(index+10)*sizeof(pint)+2*sizeof(pint);
  4447. odt_helper,
  4448. odt_objcclass,
  4449. odt_objcprotocol:
  4450. vmtmethodoffset:=0;
  4451. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  4452. vmtmethodoffset:=index*sizeof(pint);
  4453. else
  4454. {$ifdef WITHDMT}
  4455. vmtmethodoffset:=(index+4)*sizeof(pint);
  4456. {$else WITHDMT}
  4457. vmtmethodoffset:=(index+3)*sizeof(pint);
  4458. {$endif WITHDMT}
  4459. end;
  4460. end;
  4461. function tobjectdef.vmt_mangledname : string;
  4462. begin
  4463. if not(oo_has_vmt in objectoptions) then
  4464. Message1(parser_n_object_has_no_vmt,objrealname^);
  4465. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4466. end;
  4467. function tobjectdef.needs_inittable : boolean;
  4468. begin
  4469. case objecttype of
  4470. odt_helper,
  4471. odt_class :
  4472. needs_inittable:=false;
  4473. odt_dispinterface,
  4474. odt_interfacecom:
  4475. needs_inittable:=true;
  4476. odt_interfacecorba:
  4477. needs_inittable:=is_related(interface_iunknown);
  4478. odt_object:
  4479. needs_inittable:=tObjectSymtable(symtable).needs_init_final;
  4480. odt_cppclass,
  4481. odt_objcclass,
  4482. odt_objcprotocol:
  4483. needs_inittable:=false;
  4484. else
  4485. internalerror(200108267);
  4486. end;
  4487. end;
  4488. function tobjectdef.rtti_mangledname(rt: trttitype): string;
  4489. begin
  4490. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  4491. result:=inherited rtti_mangledname(rt)
  4492. else
  4493. begin
  4494. { necessary in case of a dynamic array of nsobject, or
  4495. if an nsobject field appears in a record that needs
  4496. init/finalisation }
  4497. if rt=initrtti then
  4498. begin
  4499. result:=voidpointertype.rtti_mangledname(rt);
  4500. exit;
  4501. end;
  4502. if not(target_info.system in systems_objc_nfabi) then
  4503. begin
  4504. result:=target_asm.labelprefix;
  4505. case objecttype of
  4506. odt_objcclass:
  4507. begin
  4508. case rt of
  4509. objcclassrtti:
  4510. if not(oo_is_classhelper in objectoptions) then
  4511. result:=result+'_OBJC_CLASS_'
  4512. else
  4513. result:=result+'_OBJC_CATEGORY_';
  4514. objcmetartti:
  4515. if not(oo_is_classhelper in objectoptions) then
  4516. result:=result+'_OBJC_METACLASS_'
  4517. else
  4518. internalerror(2009111511);
  4519. else
  4520. internalerror(2009092302);
  4521. end;
  4522. end;
  4523. odt_objcprotocol:
  4524. result:=result+'_OBJC_PROTOCOL_';
  4525. end;
  4526. end
  4527. else
  4528. begin
  4529. case objecttype of
  4530. odt_objcclass:
  4531. begin
  4532. if (oo_is_classhelper in objectoptions) and
  4533. (rt<>objcclassrtti) then
  4534. internalerror(2009111512);
  4535. case rt of
  4536. objcclassrtti:
  4537. if not(oo_is_classhelper in objectoptions) then
  4538. result:='_OBJC_CLASS_$_'
  4539. else
  4540. result:='_OBJC_$_CATEGORY_';
  4541. objcmetartti:
  4542. result:='_OBJC_METACLASS_$_';
  4543. objcclassrortti:
  4544. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  4545. objcmetarortti:
  4546. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  4547. else
  4548. internalerror(2009092303);
  4549. end;
  4550. end;
  4551. odt_objcprotocol:
  4552. begin
  4553. result:=lower(target_asm.labelprefix);
  4554. case rt of
  4555. objcclassrtti:
  4556. result:=result+'_OBJC_PROTOCOL_$_';
  4557. objcmetartti:
  4558. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  4559. else
  4560. internalerror(2009092501);
  4561. end;
  4562. end;
  4563. end;
  4564. end;
  4565. result:=result+objextname^;
  4566. end;
  4567. end;
  4568. function tobjectdef.members_need_inittable : boolean;
  4569. begin
  4570. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  4571. end;
  4572. function tobjectdef.find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  4573. var
  4574. ImplIntf : TImplementedInterface;
  4575. i : longint;
  4576. begin
  4577. result:=nil;
  4578. if not assigned(ImplementedInterfaces) then
  4579. exit;
  4580. for i:=0 to ImplementedInterfaces.Count-1 do
  4581. begin
  4582. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  4583. if ImplIntf.intfdef=aintfdef then
  4584. begin
  4585. result:=ImplIntf;
  4586. exit;
  4587. end;
  4588. end;
  4589. end;
  4590. function tobjectdef.is_publishable : boolean;
  4591. begin
  4592. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  4593. end;
  4594. function tobjectdef.get_next_dispid: longint;
  4595. begin
  4596. inc(fcurrent_dispid);
  4597. result:=fcurrent_dispid;
  4598. end;
  4599. function tobjectdef.search_enumerator_get: tprocdef;
  4600. begin
  4601. result:=inherited;
  4602. if not assigned(result) and assigned(childof) then
  4603. result:=childof.search_enumerator_get;
  4604. end;
  4605. function tobjectdef.search_enumerator_move: tprocdef;
  4606. begin
  4607. result:=inherited;
  4608. if not assigned(result) and assigned(childof) then
  4609. result:=childof.search_enumerator_move;
  4610. end;
  4611. function tobjectdef.search_enumerator_current: tsym;
  4612. begin
  4613. result:=inherited;
  4614. if not assigned(result) and assigned(childof) then
  4615. result:=childof.search_enumerator_current;
  4616. end;
  4617. procedure tobjectdef.register_created_classref_type;
  4618. begin
  4619. if not classref_created_in_current_module then
  4620. begin
  4621. classref_created_in_current_module:=true;
  4622. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  4623. end;
  4624. end;
  4625. procedure tobjectdef.register_created_object_type;
  4626. begin
  4627. if not created_in_current_module then
  4628. begin
  4629. created_in_current_module:=true;
  4630. current_module.wpoinfo.addcreatedobjtype(self);
  4631. end;
  4632. end;
  4633. procedure tobjectdef.register_maybe_created_object_type;
  4634. begin
  4635. { if we know it has been created for sure, no need
  4636. to also record that it maybe can be created in
  4637. this module
  4638. }
  4639. if not (created_in_current_module) and
  4640. not (maybe_created_in_current_module) then
  4641. begin
  4642. maybe_created_in_current_module:=true;
  4643. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  4644. end;
  4645. end;
  4646. procedure tobjectdef.register_vmt_call(index: longint);
  4647. begin
  4648. if (is_object(self) or is_class(self)) then
  4649. current_module.wpoinfo.addcalledvmtentry(self,index);
  4650. end;
  4651. procedure check_and_finish_msg(data: tobject; arg: pointer);
  4652. var
  4653. def: tdef absolute data;
  4654. pd: tprocdef absolute data;
  4655. i,
  4656. paracount: longint;
  4657. begin
  4658. if (def.typ=procdef) then
  4659. begin
  4660. { add all messages also under a dummy name to the symtable in
  4661. which the objcclass/protocol/category is declared, so they can
  4662. be called via id.<name>
  4663. }
  4664. create_class_helper_for_procdef(pd,nil);
  4665. { we have to wait until now to set the mangled name because it
  4666. depends on the (possibly external) class name, which is defined
  4667. at the very end. }
  4668. if not(po_msgstr in pd.procoptions) then
  4669. begin
  4670. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  4671. { recover to avoid internalerror later on }
  4672. include(pd.procoptions,po_msgstr);
  4673. pd.messageinf.str:=stringdup('MissingDeclaration');
  4674. end;
  4675. { Mangled name is already set in case this is a copy of
  4676. another type. }
  4677. if not(po_has_mangledname in pd.procoptions) then
  4678. begin
  4679. { check whether the number of formal parameters is correct,
  4680. and whether they have valid Objective-C types }
  4681. paracount:=0;
  4682. for i:=1 to length(pd.messageinf.str^) do
  4683. if pd.messageinf.str^[i]=':' then
  4684. inc(paracount);
  4685. for i:=0 to pd.paras.count-1 do
  4686. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  4687. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  4688. dec(paracount);
  4689. if (paracount<>0) then
  4690. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  4691. pd.setmangledname(pd.objcmangledname);
  4692. end
  4693. else
  4694. { all checks already done }
  4695. exit;
  4696. if not(oo_is_external in pd.struct.objectoptions) then
  4697. begin
  4698. if (po_varargs in pd.procoptions) then
  4699. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  4700. else
  4701. begin
  4702. { check for "array of const" parameters }
  4703. for i:=0 to pd.parast.symlist.count-1 do
  4704. begin
  4705. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  4706. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  4707. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  4708. end;
  4709. end;
  4710. end;
  4711. end;
  4712. end;
  4713. procedure mark_private_fields_used(data: tobject; arg: pointer);
  4714. var
  4715. sym: tsym absolute data;
  4716. begin
  4717. if (sym.typ=fieldvarsym) and
  4718. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  4719. sym.IncRefCount;
  4720. end;
  4721. procedure tobjectdef.finish_objc_data;
  4722. begin
  4723. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  4724. if (oo_is_external in objectoptions) then
  4725. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  4726. end;
  4727. procedure verify_objc_vardef(data: tobject; arg: pointer);
  4728. var
  4729. sym: tabstractvarsym absolute data;
  4730. res: pboolean absolute arg;
  4731. founderrordef: tdef;
  4732. begin
  4733. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  4734. exit;
  4735. if (sym.typ=paravarsym) and
  4736. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  4737. is_array_of_const(tparavarsym(sym).vardef)) then
  4738. exit;
  4739. if not objcchecktype(sym.vardef,founderrordef) then
  4740. begin
  4741. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  4742. res^:=false;
  4743. end;
  4744. end;
  4745. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  4746. var
  4747. def: tdef absolute data;
  4748. res: pboolean absolute arg;
  4749. founderrordef: tdef;
  4750. begin
  4751. if (def.typ<>procdef) then
  4752. exit;
  4753. { check parameter types for validity }
  4754. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  4755. { check the result type for validity }
  4756. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  4757. begin
  4758. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  4759. res^:=false;
  4760. end;
  4761. end;
  4762. function tobjectdef.check_objc_types: boolean;
  4763. begin
  4764. { done in separate step from finish_objc_data, because when
  4765. finish_objc_data is called, not all forwarddefs have been resolved
  4766. yet and we need to know all types here }
  4767. result:=true;
  4768. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  4769. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  4770. end;
  4771. procedure do_cpp_import_info(data: tobject; arg: pointer);
  4772. var
  4773. def: tdef absolute data;
  4774. pd: tprocdef absolute data;
  4775. begin
  4776. if (def.typ=procdef) then
  4777. begin
  4778. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  4779. if (oo_is_external in pd.struct.objectoptions) then
  4780. begin
  4781. { copied from psub.read_proc }
  4782. if assigned(tobjectdef(pd.struct).import_lib) then
  4783. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  4784. else
  4785. begin
  4786. { add import name to external list for DLL scanning }
  4787. if tf_has_dllscanner in target_info.flags then
  4788. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  4789. end;
  4790. end;
  4791. end;
  4792. end;
  4793. procedure tobjectdef.finish_cpp_data;
  4794. begin
  4795. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  4796. end;
  4797. {****************************************************************************
  4798. TImplementedInterface
  4799. ****************************************************************************}
  4800. constructor TImplementedInterface.create(aintf: tobjectdef);
  4801. begin
  4802. inherited create;
  4803. intfdef:=aintf;
  4804. IOffset:=-1;
  4805. IType:=etStandard;
  4806. NameMappings:=nil;
  4807. procdefs:=nil;
  4808. end;
  4809. constructor TImplementedInterface.create_deref(d:tderef);
  4810. begin
  4811. inherited create;
  4812. intfdef:=nil;
  4813. intfdefderef:=d;
  4814. IOffset:=-1;
  4815. IType:=etStandard;
  4816. NameMappings:=nil;
  4817. procdefs:=nil;
  4818. end;
  4819. destructor TImplementedInterface.destroy;
  4820. var
  4821. i : longint;
  4822. mappedname : pshortstring;
  4823. begin
  4824. if assigned(NameMappings) then
  4825. begin
  4826. for i:=0 to NameMappings.Count-1 do
  4827. begin
  4828. mappedname:=pshortstring(NameMappings[i]);
  4829. stringdispose(mappedname);
  4830. end;
  4831. NameMappings.free;
  4832. NameMappings:=nil;
  4833. end;
  4834. if assigned(procdefs) then
  4835. begin
  4836. procdefs.free;
  4837. procdefs:=nil;
  4838. end;
  4839. inherited destroy;
  4840. end;
  4841. procedure TImplementedInterface.buildderef;
  4842. begin
  4843. intfdefderef.build(intfdef);
  4844. end;
  4845. procedure TImplementedInterface.deref;
  4846. begin
  4847. intfdef:=tobjectdef(intfdefderef.resolve);
  4848. end;
  4849. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  4850. begin
  4851. if not assigned(NameMappings) then
  4852. NameMappings:=TFPHashList.Create;
  4853. NameMappings.Add(origname,stringdup(newname));
  4854. end;
  4855. function TImplementedInterface.GetMapping(const origname: string):string;
  4856. var
  4857. mappedname : pshortstring;
  4858. begin
  4859. result:='';
  4860. if not assigned(NameMappings) then
  4861. exit;
  4862. mappedname:=PShortstring(NameMappings.Find(origname));
  4863. if assigned(mappedname) then
  4864. result:=mappedname^;
  4865. end;
  4866. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  4867. begin
  4868. if not assigned(procdefs) then
  4869. procdefs:=TFPObjectList.Create(false);
  4870. { duplicate entries must be stored, because multiple }
  4871. { interfaces can declare methods with the same name }
  4872. { and all of these get their own VMT entry }
  4873. procdefs.Add(pd);
  4874. end;
  4875. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  4876. var
  4877. i : longint;
  4878. begin
  4879. result:=false;
  4880. { interfaces being implemented through delegation are not mergable (FK) }
  4881. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  4882. exit;
  4883. weight:=0;
  4884. { empty interface is mergeable }
  4885. if ProcDefs.Count=0 then
  4886. begin
  4887. result:=true;
  4888. exit;
  4889. end;
  4890. { The interface to merge must at least the number of
  4891. procedures of this interface }
  4892. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  4893. exit;
  4894. for i:=0 to ProcDefs.Count-1 do
  4895. begin
  4896. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  4897. exit;
  4898. end;
  4899. weight:=ProcDefs.Count;
  4900. result:=true;
  4901. end;
  4902. function TImplementedInterface.getcopy:TImplementedInterface;
  4903. begin
  4904. Result:=TImplementedInterface.Create(nil);
  4905. { 1) the procdefs list will be freed once for each copy
  4906. 2) since the procdefs list owns its elements, those will also be freed for each copy
  4907. 3) idem for the name mappings
  4908. }
  4909. { warning: this is completely wrong on so many levels...
  4910. Move(pointer(self)^,pointer(result)^,InstanceSize);
  4911. We need to make clean copies of the different fields
  4912. this is not implemented yet, and thus we generate an internal
  4913. error instead PM 2011-06-14 }
  4914. internalerror(2011061401);
  4915. end;
  4916. {****************************************************************************
  4917. TFORWARDDEF
  4918. ****************************************************************************}
  4919. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  4920. begin
  4921. inherited create(forwarddef);
  4922. tosymname:=stringdup(s);
  4923. forwardpos:=pos;
  4924. end;
  4925. function tforwarddef.GetTypeName:string;
  4926. begin
  4927. GetTypeName:='unresolved forward to '+tosymname^;
  4928. end;
  4929. destructor tforwarddef.destroy;
  4930. begin
  4931. stringdispose(tosymname);
  4932. inherited destroy;
  4933. end;
  4934. function tforwarddef.getcopy:tstoreddef;
  4935. begin
  4936. result:=tforwarddef.create(tosymname^, forwardpos);
  4937. end;
  4938. {****************************************************************************
  4939. TUNDEFINEDDEF
  4940. ****************************************************************************}
  4941. constructor tundefineddef.create;
  4942. begin
  4943. inherited create(undefineddef);
  4944. end;
  4945. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  4946. begin
  4947. inherited ppuload(undefineddef,ppufile);
  4948. end;
  4949. function tundefineddef.GetTypeName:string;
  4950. begin
  4951. GetTypeName:='<undefined type>';
  4952. end;
  4953. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  4954. begin
  4955. inherited ppuwrite(ppufile);
  4956. ppufile.writeentry(ibundefineddef);
  4957. end;
  4958. {****************************************************************************
  4959. TERRORDEF
  4960. ****************************************************************************}
  4961. constructor terrordef.create;
  4962. begin
  4963. inherited create(errordef);
  4964. { prevent consecutive faults }
  4965. savesize:=1;
  4966. end;
  4967. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  4968. begin
  4969. { Can't write errordefs to ppu }
  4970. internalerror(200411063);
  4971. end;
  4972. function terrordef.GetTypeName:string;
  4973. begin
  4974. GetTypeName:='<erroneous type>';
  4975. end;
  4976. function terrordef.getmangledparaname:string;
  4977. begin
  4978. getmangledparaname:='error';
  4979. end;
  4980. {****************************************************************************
  4981. Definition Helpers
  4982. ****************************************************************************}
  4983. function is_interfacecom(def: tdef): boolean;
  4984. begin
  4985. is_interfacecom:=
  4986. assigned(def) and
  4987. (def.typ=objectdef) and
  4988. (tobjectdef(def).objecttype=odt_interfacecom);
  4989. end;
  4990. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  4991. begin
  4992. is_interfacecom_or_dispinterface:=
  4993. assigned(def) and
  4994. (def.typ=objectdef) and
  4995. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  4996. end;
  4997. function is_interfacecorba(def: tdef): boolean;
  4998. begin
  4999. is_interfacecorba:=
  5000. assigned(def) and
  5001. (def.typ=objectdef) and
  5002. (tobjectdef(def).objecttype=odt_interfacecorba);
  5003. end;
  5004. function is_interface(def: tdef): boolean;
  5005. begin
  5006. is_interface:=
  5007. assigned(def) and
  5008. (def.typ=objectdef) and
  5009. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5010. end;
  5011. function is_dispinterface(def: tdef): boolean;
  5012. begin
  5013. result:=
  5014. assigned(def) and
  5015. (def.typ=objectdef) and
  5016. (tobjectdef(def).objecttype=odt_dispinterface);
  5017. end;
  5018. function is_class(def: tdef): boolean;
  5019. begin
  5020. is_class:=
  5021. assigned(def) and
  5022. (def.typ=objectdef) and
  5023. (tobjectdef(def).objecttype=odt_class);
  5024. end;
  5025. function is_object(def: tdef): boolean;
  5026. begin
  5027. is_object:=
  5028. assigned(def) and
  5029. (def.typ=objectdef) and
  5030. (tobjectdef(def).objecttype=odt_object);
  5031. end;
  5032. function is_cppclass(def: tdef): boolean;
  5033. begin
  5034. is_cppclass:=
  5035. assigned(def) and
  5036. (def.typ=objectdef) and
  5037. (tobjectdef(def).objecttype=odt_cppclass);
  5038. end;
  5039. function is_objcclass(def: tdef): boolean;
  5040. begin
  5041. is_objcclass:=
  5042. assigned(def) and
  5043. (def.typ=objectdef) and
  5044. (tobjectdef(def).objecttype=odt_objcclass);
  5045. end;
  5046. function is_objectpascal_helper(def: tdef): boolean;
  5047. begin
  5048. result:=
  5049. assigned(def) and
  5050. (def.typ=objectdef) and
  5051. (tobjectdef(def).objecttype=odt_helper);
  5052. end;
  5053. function is_objcclassref(def: tdef): boolean;
  5054. begin
  5055. is_objcclassref:=
  5056. assigned(def) and
  5057. (def.typ=classrefdef) and
  5058. is_objcclass(tclassrefdef(def).pointeddef);
  5059. end;
  5060. function is_objcprotocol(def: tdef): boolean;
  5061. begin
  5062. result:=
  5063. assigned(def) and
  5064. (def.typ=objectdef) and
  5065. (tobjectdef(def).objecttype=odt_objcprotocol);
  5066. end;
  5067. function is_objccategory(def: tdef): boolean;
  5068. begin
  5069. result:=
  5070. assigned(def) and
  5071. (def.typ=objectdef) and
  5072. { if used as a forward type }
  5073. ((tobjectdef(def).objecttype=odt_objccategory) or
  5074. { if used as after it has been resolved }
  5075. ((tobjectdef(def).objecttype=odt_objcclass) and
  5076. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  5077. end;
  5078. function is_objc_class_or_protocol(def: tdef): boolean;
  5079. begin
  5080. result:=
  5081. assigned(def) and
  5082. (def.typ=objectdef) and
  5083. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  5084. end;
  5085. function is_objc_protocol_or_category(def: tdef): boolean;
  5086. begin
  5087. result:=
  5088. assigned(def) and
  5089. (def.typ=objectdef) and
  5090. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  5091. ((tobjectdef(def).objecttype = odt_objcclass) and
  5092. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  5093. end;
  5094. function is_classhelper(def: tdef): boolean;
  5095. begin
  5096. result:=
  5097. is_objectpascal_helper(def) or
  5098. is_objccategory(def);
  5099. end;
  5100. function is_class_or_interface(def: tdef): boolean;
  5101. begin
  5102. result:=
  5103. assigned(def) and
  5104. (def.typ=objectdef) and
  5105. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5106. end;
  5107. function is_class_or_interface_or_objc(def: tdef): boolean;
  5108. begin
  5109. result:=
  5110. assigned(def) and
  5111. (def.typ=objectdef) and
  5112. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  5113. end;
  5114. function is_class_or_interface_or_object(def: tdef): boolean;
  5115. begin
  5116. result:=
  5117. assigned(def) and
  5118. (def.typ=objectdef) and
  5119. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  5120. end;
  5121. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  5122. begin
  5123. result:=
  5124. assigned(def) and
  5125. (def.typ=objectdef) and
  5126. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5127. end;
  5128. function is_implicit_pointer_object_type(def: tdef): boolean;
  5129. begin
  5130. result:=
  5131. assigned(def) and
  5132. (def.typ=objectdef) and
  5133. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper]);
  5134. end;
  5135. function is_class_or_object(def: tdef): boolean;
  5136. begin
  5137. result:=
  5138. assigned(def) and
  5139. (def.typ=objectdef) and
  5140. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  5141. end;
  5142. function is_record(def: tdef): boolean;
  5143. begin
  5144. result:=
  5145. assigned(def) and
  5146. (def.typ=recorddef);
  5147. end;
  5148. procedure loadobjctypes;
  5149. begin
  5150. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  5151. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  5152. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  5153. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  5154. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  5155. end;
  5156. procedure maybeloadcocoatypes;
  5157. var
  5158. tsym: ttypesym;
  5159. begin
  5160. if assigned(objc_fastenumeration) then
  5161. exit;
  5162. tsym:=search_named_unit_globaltype('COCOAALL','NSFASTENUMERATIONPROTOCOL',false);
  5163. if assigned(tsym) then
  5164. objc_fastenumeration:=tobjectdef(tsym.typedef)
  5165. else
  5166. objc_fastenumeration:=nil;
  5167. tsym:=search_named_unit_globaltype('COCOAALL','NSFASTENUMERATIONSTATE',false);
  5168. if assigned(tsym) then
  5169. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  5170. else
  5171. objc_fastenumerationstate:=nil;
  5172. end;
  5173. function use_vectorfpu(def : tdef) : boolean;
  5174. begin
  5175. {$ifdef x86}
  5176. {$define use_vectorfpuimplemented}
  5177. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  5178. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  5179. {$endif x86}
  5180. {$ifdef arm}
  5181. {$define use_vectorfpuimplemented}
  5182. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  5183. {$endif arm}
  5184. {$ifndef use_vectorfpuimplemented}
  5185. use_vectorfpu:=false;
  5186. {$endif}
  5187. end;
  5188. end.