symdef.pas 189 KB

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