symdef.pas 187 KB

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