symdef.pas 187 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953
  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;
  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;
  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_openbsd,system_x86_64_netbsd,
  1838. system_x86_64_solaris,system_x86_64_embedded] then
  1839. savesize:=16
  1840. else
  1841. savesize:=12;
  1842. s64real,
  1843. s64currency,
  1844. s64comp : savesize:=8;
  1845. else
  1846. savesize:=0;
  1847. end;
  1848. end;
  1849. function tfloatdef.getvardef : longint;
  1850. const
  1851. floattype2vardef : array[tfloattype] of longint = (
  1852. varSingle,varDouble,varUndefined,varUndefined,
  1853. varUndefined,varCurrency,varUndefined);
  1854. begin
  1855. if (upper(typename)='TDATETIME') and
  1856. assigned(owner) and
  1857. assigned(owner.name) and
  1858. (owner.name^='SYSTEM') then
  1859. result:=varDate
  1860. else
  1861. result:=floattype2vardef[floattype];
  1862. end;
  1863. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1864. begin
  1865. inherited ppuwrite(ppufile);
  1866. ppufile.putbyte(byte(floattype));
  1867. ppufile.writeentry(ibfloatdef);
  1868. end;
  1869. function tfloatdef.is_publishable : boolean;
  1870. begin
  1871. is_publishable:=true;
  1872. end;
  1873. function tfloatdef.GetTypeName : string;
  1874. const
  1875. names : array[tfloattype] of string[20] = (
  1876. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  1877. begin
  1878. GetTypeName:=names[floattype];
  1879. end;
  1880. {****************************************************************************
  1881. TFILEDEF
  1882. ****************************************************************************}
  1883. constructor tfiledef.createtext;
  1884. begin
  1885. inherited create(filedef);
  1886. filetyp:=ft_text;
  1887. typedfiledef:=nil;
  1888. setsize;
  1889. end;
  1890. constructor tfiledef.createuntyped;
  1891. begin
  1892. inherited create(filedef);
  1893. filetyp:=ft_untyped;
  1894. typedfiledef:=nil;
  1895. setsize;
  1896. end;
  1897. constructor tfiledef.createtyped(def:tdef);
  1898. begin
  1899. inherited create(filedef);
  1900. filetyp:=ft_typed;
  1901. typedfiledef:=def;
  1902. setsize;
  1903. end;
  1904. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1905. begin
  1906. inherited ppuload(filedef,ppufile);
  1907. filetyp:=tfiletyp(ppufile.getbyte);
  1908. if filetyp=ft_typed then
  1909. ppufile.getderef(typedfiledefderef)
  1910. else
  1911. typedfiledef:=nil;
  1912. setsize;
  1913. end;
  1914. function tfiledef.getcopy : tstoreddef;
  1915. begin
  1916. case filetyp of
  1917. ft_typed:
  1918. result:=tfiledef.createtyped(typedfiledef);
  1919. ft_untyped:
  1920. result:=tfiledef.createuntyped;
  1921. ft_text:
  1922. result:=tfiledef.createtext;
  1923. else
  1924. internalerror(2004121201);
  1925. end;
  1926. end;
  1927. procedure tfiledef.buildderef;
  1928. begin
  1929. inherited buildderef;
  1930. if filetyp=ft_typed then
  1931. typedfiledefderef.build(typedfiledef);
  1932. end;
  1933. procedure tfiledef.deref;
  1934. begin
  1935. inherited deref;
  1936. if filetyp=ft_typed then
  1937. typedfiledef:=tdef(typedfiledefderef.resolve);
  1938. end;
  1939. procedure tfiledef.setsize;
  1940. begin
  1941. {$ifdef cpu64bitaddr}
  1942. case filetyp of
  1943. ft_text :
  1944. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1945. savesize:=634{+8}
  1946. else
  1947. savesize:=630{+8};
  1948. ft_typed,
  1949. ft_untyped :
  1950. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1951. savesize:=372
  1952. else
  1953. savesize:=368;
  1954. end;
  1955. {$endif cpu64bitaddr}
  1956. {$ifdef cpu32bitaddr}
  1957. case filetyp of
  1958. ft_text :
  1959. savesize:=594{+4};
  1960. ft_typed,
  1961. ft_untyped :
  1962. savesize:=332;
  1963. end;
  1964. {$endif cpu32bitaddr}
  1965. {$ifdef cpu8bitaddr}
  1966. case filetyp of
  1967. ft_text :
  1968. savesize:=127;
  1969. ft_typed,
  1970. ft_untyped :
  1971. savesize:=127;
  1972. end;
  1973. {$endif cpu8bitaddr}
  1974. end;
  1975. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1976. begin
  1977. inherited ppuwrite(ppufile);
  1978. ppufile.putbyte(byte(filetyp));
  1979. if filetyp=ft_typed then
  1980. ppufile.putderef(typedfiledefderef);
  1981. ppufile.writeentry(ibfiledef);
  1982. end;
  1983. function tfiledef.GetTypeName : string;
  1984. begin
  1985. case filetyp of
  1986. ft_untyped:
  1987. GetTypeName:='File';
  1988. ft_typed:
  1989. GetTypeName:='File Of '+typedfiledef.typename;
  1990. ft_text:
  1991. GetTypeName:='Text'
  1992. end;
  1993. end;
  1994. function tfiledef.getmangledparaname : string;
  1995. begin
  1996. case filetyp of
  1997. ft_untyped:
  1998. getmangledparaname:='FILE';
  1999. ft_typed:
  2000. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  2001. ft_text:
  2002. getmangledparaname:='TEXT'
  2003. end;
  2004. end;
  2005. {****************************************************************************
  2006. TVARIANTDEF
  2007. ****************************************************************************}
  2008. constructor tvariantdef.create(v : tvarianttype);
  2009. begin
  2010. inherited create(variantdef);
  2011. varianttype:=v;
  2012. setsize;
  2013. end;
  2014. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2015. begin
  2016. inherited ppuload(variantdef,ppufile);
  2017. varianttype:=tvarianttype(ppufile.getbyte);
  2018. setsize;
  2019. end;
  2020. function tvariantdef.getcopy : tstoreddef;
  2021. begin
  2022. result:=tvariantdef.create(varianttype);
  2023. end;
  2024. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2025. begin
  2026. inherited ppuwrite(ppufile);
  2027. ppufile.putbyte(byte(varianttype));
  2028. ppufile.writeentry(ibvariantdef);
  2029. end;
  2030. function tvariantdef.getvardef : longint;
  2031. begin
  2032. Result:=varVariant;
  2033. end;
  2034. procedure tvariantdef.setsize;
  2035. begin
  2036. {$ifdef cpu64bitaddr}
  2037. savesize:=24;
  2038. {$else cpu64bitaddr}
  2039. savesize:=16;
  2040. {$endif cpu64bitaddr}
  2041. end;
  2042. function tvariantdef.GetTypeName : string;
  2043. begin
  2044. case varianttype of
  2045. vt_normalvariant:
  2046. GetTypeName:='Variant';
  2047. vt_olevariant:
  2048. GetTypeName:='OleVariant';
  2049. end;
  2050. end;
  2051. function tvariantdef.needs_inittable : boolean;
  2052. begin
  2053. needs_inittable:=true;
  2054. end;
  2055. function tvariantdef.is_publishable : boolean;
  2056. begin
  2057. is_publishable:=true;
  2058. end;
  2059. {****************************************************************************
  2060. TABSTRACtpointerdef
  2061. ****************************************************************************}
  2062. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  2063. begin
  2064. inherited create(dt);
  2065. pointeddef:=def;
  2066. savesize:=sizeof(pint);
  2067. end;
  2068. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2069. begin
  2070. inherited ppuload(dt,ppufile);
  2071. ppufile.getderef(pointeddefderef);
  2072. savesize:=sizeof(pint);
  2073. end;
  2074. procedure tabstractpointerdef.buildderef;
  2075. begin
  2076. inherited buildderef;
  2077. pointeddefderef.build(pointeddef);
  2078. end;
  2079. procedure tabstractpointerdef.deref;
  2080. begin
  2081. inherited deref;
  2082. pointeddef:=tdef(pointeddefderef.resolve);
  2083. end;
  2084. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2085. begin
  2086. inherited ppuwrite(ppufile);
  2087. ppufile.putderef(pointeddefderef);
  2088. end;
  2089. {****************************************************************************
  2090. tpointerdef
  2091. ****************************************************************************}
  2092. constructor tpointerdef.create(def:tdef);
  2093. begin
  2094. inherited create(pointerdef,def);
  2095. is_far:=false;
  2096. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2097. end;
  2098. constructor tpointerdef.createfar(def:tdef);
  2099. begin
  2100. inherited create(pointerdef,def);
  2101. is_far:=true;
  2102. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2103. end;
  2104. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2105. begin
  2106. inherited ppuload(pointerdef,ppufile);
  2107. is_far:=(ppufile.getbyte<>0);
  2108. has_pointer_math:=(ppufile.getbyte<>0);
  2109. end;
  2110. function tpointerdef.getcopy : tstoreddef;
  2111. begin
  2112. { don't use direct pointeddef if it is a forwarddef because in other case
  2113. one of them will be destroyed on forward type resolve and the second will
  2114. point to garbage }
  2115. if pointeddef.typ=forwarddef then
  2116. result:=tpointerdef.create(tforwarddef(pointeddef).getcopy)
  2117. else
  2118. result:=tpointerdef.create(pointeddef);
  2119. tpointerdef(result).is_far:=is_far;
  2120. tpointerdef(result).has_pointer_math:=has_pointer_math;
  2121. tpointerdef(result).savesize:=savesize;
  2122. end;
  2123. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2124. begin
  2125. inherited ppuwrite(ppufile);
  2126. ppufile.putbyte(byte(is_far));
  2127. ppufile.putbyte(byte(has_pointer_math));
  2128. ppufile.writeentry(ibpointerdef);
  2129. end;
  2130. function tpointerdef.GetTypeName : string;
  2131. begin
  2132. if is_far then
  2133. GetTypeName:='^'+pointeddef.typename+';far'
  2134. else
  2135. GetTypeName:='^'+pointeddef.typename;
  2136. end;
  2137. {****************************************************************************
  2138. TCLASSREFDEF
  2139. ****************************************************************************}
  2140. constructor tclassrefdef.create(def:tdef);
  2141. begin
  2142. inherited create(classrefdef,def);
  2143. end;
  2144. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2145. begin
  2146. inherited ppuload(classrefdef,ppufile);
  2147. end;
  2148. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2149. begin
  2150. inherited ppuwrite(ppufile);
  2151. ppufile.writeentry(ibclassrefdef);
  2152. end;
  2153. function tclassrefdef.getcopy:tstoreddef;
  2154. begin
  2155. if pointeddef.typ=forwarddef then
  2156. result:=tclassrefdef.create(tforwarddef(pointeddef).getcopy)
  2157. else
  2158. result:=tclassrefdef.create(pointeddef);
  2159. tclassrefdef(result).savesize:=savesize;
  2160. end;
  2161. function tclassrefdef.GetTypeName : string;
  2162. begin
  2163. GetTypeName:='Class Of '+pointeddef.typename;
  2164. end;
  2165. function tclassrefdef.is_publishable : boolean;
  2166. begin
  2167. result:=true;
  2168. end;
  2169. function tclassrefdef.rtti_mangledname(rt: trttitype): string;
  2170. begin
  2171. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  2172. result:=inherited rtti_mangledname(rt)
  2173. else
  2174. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  2175. end;
  2176. procedure tclassrefdef.register_created_object_type;
  2177. begin
  2178. tobjectdef(pointeddef).register_created_classref_type;
  2179. end;
  2180. {***************************************************************************
  2181. TSETDEF
  2182. ***************************************************************************}
  2183. constructor tsetdef.create(def:tdef;low, high : asizeint);
  2184. var
  2185. setallocbits: aint;
  2186. packedsavesize: aint;
  2187. begin
  2188. inherited create(setdef);
  2189. elementdef:=def;
  2190. setmax:=high;
  2191. if (current_settings.setalloc=0) then
  2192. begin
  2193. setbase:=0;
  2194. if (high<32) then
  2195. savesize:=Sizeof(longint)
  2196. else if (high<256) then
  2197. savesize:=32
  2198. else
  2199. savesize:=(high+7) div 8
  2200. end
  2201. else
  2202. begin
  2203. setallocbits:=current_settings.setalloc*8;
  2204. setbase:=low and not(setallocbits-1);
  2205. packedsavesize:=current_settings.setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  2206. savesize:=packedsavesize;
  2207. if savesize=3 then
  2208. savesize:=4;
  2209. end;
  2210. end;
  2211. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2212. begin
  2213. inherited ppuload(setdef,ppufile);
  2214. ppufile.getderef(elementdefderef);
  2215. savesize:=ppufile.getaint;
  2216. setbase:=ppufile.getaint;
  2217. setmax:=ppufile.getaint;
  2218. end;
  2219. function tsetdef.getcopy : tstoreddef;
  2220. begin
  2221. result:=tsetdef.create(elementdef,setbase,setmax);
  2222. { the copy might have been created with a different setalloc setting }
  2223. tsetdef(result).savesize:=savesize;
  2224. end;
  2225. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2226. begin
  2227. inherited ppuwrite(ppufile);
  2228. ppufile.putderef(elementdefderef);
  2229. ppufile.putaint(savesize);
  2230. ppufile.putaint(setbase);
  2231. ppufile.putaint(setmax);
  2232. ppufile.writeentry(ibsetdef);
  2233. end;
  2234. procedure tsetdef.buildderef;
  2235. begin
  2236. inherited buildderef;
  2237. elementdefderef.build(elementdef);
  2238. end;
  2239. procedure tsetdef.deref;
  2240. begin
  2241. inherited deref;
  2242. elementdef:=tdef(elementdefderef.resolve);
  2243. end;
  2244. function tsetdef.is_publishable : boolean;
  2245. begin
  2246. is_publishable:=savesize in [1,2,4];
  2247. end;
  2248. function tsetdef.GetTypeName : string;
  2249. begin
  2250. if assigned(elementdef) then
  2251. GetTypeName:='Set Of '+elementdef.typename
  2252. else
  2253. GetTypeName:='Empty Set';
  2254. end;
  2255. {***************************************************************************
  2256. TFORMALDEF
  2257. ***************************************************************************}
  2258. constructor tformaldef.create(Atyped:boolean);
  2259. begin
  2260. inherited create(formaldef);
  2261. typed:=Atyped;
  2262. savesize:=0;
  2263. end;
  2264. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2265. begin
  2266. inherited ppuload(formaldef,ppufile);
  2267. typed:=boolean(ppufile.getbyte);
  2268. savesize:=0;
  2269. end;
  2270. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2271. begin
  2272. inherited ppuwrite(ppufile);
  2273. ppufile.putbyte(byte(typed));
  2274. ppufile.writeentry(ibformaldef);
  2275. end;
  2276. function tformaldef.GetTypeName : string;
  2277. begin
  2278. if typed then
  2279. GetTypeName:='<Typed formal type>'
  2280. else
  2281. GetTypeName:='<Formal type>';
  2282. end;
  2283. {***************************************************************************
  2284. TARRAYDEF
  2285. ***************************************************************************}
  2286. constructor tarraydef.create(l,h:asizeint;def:tdef);
  2287. begin
  2288. inherited create(arraydef);
  2289. lowrange:=l;
  2290. highrange:=h;
  2291. rangedef:=def;
  2292. _elementdef:=nil;
  2293. arrayoptions:=[];
  2294. symtable:=tarraysymtable.create(self);
  2295. end;
  2296. destructor tarraydef.destroy;
  2297. begin
  2298. symtable.free;
  2299. symtable:=nil;
  2300. inherited;
  2301. end;
  2302. constructor tarraydef.create_from_pointer(def:tdef);
  2303. begin
  2304. { use -1 so that the elecount will not overflow }
  2305. self.create(0,high(aint)-1,ptrsinttype);
  2306. arrayoptions:=[ado_IsConvertedPointer];
  2307. setelementdef(def);
  2308. end;
  2309. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2310. begin
  2311. inherited ppuload(arraydef,ppufile);
  2312. { the addresses are calculated later }
  2313. ppufile.getderef(_elementdefderef);
  2314. ppufile.getderef(rangedefderef);
  2315. lowrange:=ppufile.getaint;
  2316. highrange:=ppufile.getaint;
  2317. ppufile.getsmallset(arrayoptions);
  2318. symtable:=tarraysymtable.create(self);
  2319. tarraysymtable(symtable).ppuload(ppufile)
  2320. end;
  2321. function tarraydef.getcopy : tstoreddef;
  2322. begin
  2323. result:=tarraydef.create(lowrange,highrange,rangedef);
  2324. tarraydef(result).arrayoptions:=arrayoptions;
  2325. tarraydef(result)._elementdef:=_elementdef;
  2326. end;
  2327. procedure tarraydef.buildderef;
  2328. begin
  2329. inherited buildderef;
  2330. tarraysymtable(symtable).buildderef;
  2331. _elementdefderef.build(_elementdef);
  2332. rangedefderef.build(rangedef);
  2333. end;
  2334. procedure tarraydef.deref;
  2335. begin
  2336. inherited deref;
  2337. tarraysymtable(symtable).deref;
  2338. _elementdef:=tdef(_elementdefderef.resolve);
  2339. rangedef:=tdef(rangedefderef.resolve);
  2340. end;
  2341. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2342. begin
  2343. inherited ppuwrite(ppufile);
  2344. ppufile.putderef(_elementdefderef);
  2345. ppufile.putderef(rangedefderef);
  2346. ppufile.putaint(lowrange);
  2347. ppufile.putaint(highrange);
  2348. ppufile.putsmallset(arrayoptions);
  2349. ppufile.writeentry(ibarraydef);
  2350. tarraysymtable(symtable).ppuwrite(ppufile);
  2351. end;
  2352. function tarraydef.elesize : asizeint;
  2353. begin
  2354. if (ado_IsBitPacked in arrayoptions) then
  2355. internalerror(2006080101);
  2356. if assigned(_elementdef) then
  2357. result:=_elementdef.size
  2358. else
  2359. result:=0;
  2360. end;
  2361. function tarraydef.elepackedbitsize : asizeint;
  2362. begin
  2363. if not(ado_IsBitPacked in arrayoptions) then
  2364. internalerror(2006080102);
  2365. if assigned(_elementdef) then
  2366. result:=_elementdef.packedbitsize
  2367. else
  2368. result:=0;
  2369. end;
  2370. function tarraydef.elecount : asizeuint;
  2371. var
  2372. qhigh,qlow : qword;
  2373. begin
  2374. if ado_IsDynamicArray in arrayoptions then
  2375. begin
  2376. result:=0;
  2377. exit;
  2378. end;
  2379. if (highrange>0) and (lowrange<0) then
  2380. begin
  2381. qhigh:=highrange;
  2382. qlow:=qword(-lowrange);
  2383. { prevent overflow, return 0 to indicate overflow }
  2384. if qhigh+qlow>qword(high(asizeint)-1) then
  2385. result:=0
  2386. else
  2387. result:=qhigh+qlow+1;
  2388. end
  2389. else
  2390. result:=int64(highrange)-lowrange+1;
  2391. end;
  2392. function tarraydef.size : asizeint;
  2393. var
  2394. cachedelecount : asizeuint;
  2395. cachedelesize : asizeint;
  2396. begin
  2397. if ado_IsDynamicArray in arrayoptions then
  2398. begin
  2399. size:=sizeof(pint);
  2400. exit;
  2401. end;
  2402. { Tarraydef.size may never be called for an open array! }
  2403. if highrange<lowrange then
  2404. internalerror(99080501);
  2405. if not (ado_IsBitPacked in arrayoptions) then
  2406. cachedelesize:=elesize
  2407. else
  2408. cachedelesize := elepackedbitsize;
  2409. cachedelecount:=elecount;
  2410. if (cachedelesize = 0) then
  2411. begin
  2412. size := 0;
  2413. exit;
  2414. end;
  2415. if (cachedelecount = 0) then
  2416. begin
  2417. size := -1;
  2418. exit;
  2419. end;
  2420. { prevent overflow, return -1 to indicate overflow }
  2421. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  2422. if (cachedelecount > asizeuint(high(asizeint))) or
  2423. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  2424. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  2425. accessing the array, see ncgmem (PFV) }
  2426. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  2427. begin
  2428. result:=-1;
  2429. exit;
  2430. end;
  2431. result:=cachedelesize*asizeint(cachedelecount);
  2432. if (ado_IsBitPacked in arrayoptions) then
  2433. { can't just add 7 and divide by 8, because that may overflow }
  2434. result:=result div 8 + ord((result mod 8)<>0);
  2435. end;
  2436. procedure tarraydef.setelementdef(def:tdef);
  2437. begin
  2438. _elementdef:=def;
  2439. if not(
  2440. (ado_IsDynamicArray in arrayoptions) or
  2441. (ado_IsConvertedPointer in arrayoptions) or
  2442. (highrange<lowrange)
  2443. ) and
  2444. (size=-1) then
  2445. Message(sym_e_segment_too_large);
  2446. end;
  2447. function tarraydef.alignment : shortint;
  2448. begin
  2449. { alignment of dyn. arrays doesn't depend on the element size }
  2450. if (ado_IsDynamicArray in arrayoptions) then
  2451. alignment:=size_2_align(sizeof(pint))
  2452. { alignment is the alignment of the elements }
  2453. else if (elementdef.typ in [arraydef,recorddef,orddef,enumdef,floatdef]) or
  2454. ((elementdef.typ=objectdef) and
  2455. is_object(elementdef)) then
  2456. alignment:=elementdef.alignment
  2457. { alignment is the size of the elements }
  2458. else if not (ado_IsBitPacked in arrayoptions) then
  2459. alignment:=size_2_align(elesize)
  2460. else
  2461. alignment:=packedbitsloadsize(elepackedbitsize);
  2462. end;
  2463. function tarraydef.needs_inittable : boolean;
  2464. begin
  2465. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  2466. end;
  2467. function tarraydef.GetTypeName : string;
  2468. begin
  2469. if (ado_IsConstString in arrayoptions) then
  2470. result:='Constant String'
  2471. else if (ado_isarrayofconst in arrayoptions) or
  2472. (ado_isConstructor in arrayoptions) then
  2473. begin
  2474. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  2475. GetTypeName:='Array Of Const'
  2476. else
  2477. GetTypeName:='Array Of Const/Constant Open Array of '+elementdef.typename;
  2478. end
  2479. else if (ado_IsDynamicArray in arrayoptions) then
  2480. GetTypeName:='Dynamic Array Of '+elementdef.typename
  2481. else if ((highrange=-1) and (lowrange=0)) then
  2482. GetTypeName:='Open Array Of '+elementdef.typename
  2483. else
  2484. begin
  2485. result := '';
  2486. if (ado_IsBitPacked in arrayoptions) then
  2487. result:='Packed ';
  2488. if rangedef.typ=enumdef then
  2489. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  2490. else
  2491. result:=result+'Array['+tostr(lowrange)+'..'+
  2492. tostr(highrange)+'] Of '+elementdef.typename
  2493. end;
  2494. end;
  2495. function tarraydef.getmangledparaname : string;
  2496. begin
  2497. if ado_isarrayofconst in arrayoptions then
  2498. getmangledparaname:='array_of_const'
  2499. else
  2500. if ((highrange=-1) and (lowrange=0)) then
  2501. getmangledparaname:='array_of_'+elementdef.mangledparaname
  2502. else
  2503. internalerror(200204176);
  2504. end;
  2505. function tarraydef.is_publishable : boolean;
  2506. begin
  2507. Result:=ado_IsDynamicArray in arrayoptions;
  2508. end;
  2509. {***************************************************************************
  2510. tabstractrecorddef
  2511. ***************************************************************************}
  2512. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp);
  2513. begin
  2514. inherited create(dt);
  2515. objname:=stringdup(upper(n));
  2516. objrealname:=stringdup(n);
  2517. objectoptions:=[];
  2518. end;
  2519. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2520. begin
  2521. inherited ppuload(dt,ppufile);
  2522. objrealname:=stringdup(ppufile.getstring);
  2523. objname:=stringdup(upper(objrealname^));
  2524. ppufile.getsmallset(objectoptions);
  2525. end;
  2526. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  2527. begin
  2528. inherited ppuwrite(ppufile);
  2529. ppufile.putstring(objrealname^);
  2530. ppufile.putsmallset(objectoptions);
  2531. end;
  2532. destructor tabstractrecorddef.destroy;
  2533. begin
  2534. stringdispose(objname);
  2535. stringdispose(objrealname);
  2536. inherited destroy;
  2537. end;
  2538. procedure tabstractrecorddef.check_forwards;
  2539. begin
  2540. tstoredsymtable(symtable).check_forwards;
  2541. end;
  2542. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  2543. var
  2544. i: longint;
  2545. sym: tsym;
  2546. begin
  2547. for i:=0 to symtable.SymList.Count-1 do
  2548. begin
  2549. sym:=tsym(symtable.SymList[i]);
  2550. if sym.typ=procsym then
  2551. begin
  2552. result:=tprocsym(sym).find_procdef_bytype(pt);
  2553. if assigned(result) then
  2554. exit;
  2555. end;
  2556. end;
  2557. result:=nil;
  2558. end;
  2559. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  2560. begin
  2561. if t=gs_record then
  2562. GetSymtable:=symtable
  2563. else
  2564. GetSymtable:=nil;
  2565. end;
  2566. function tabstractrecorddef.is_packed:boolean;
  2567. begin
  2568. result:=tabstractrecordsymtable(symtable).is_packed;
  2569. end;
  2570. function tabstractrecorddef.RttiName: string;
  2571. begin
  2572. Result:=OwnerHierarchyName+objrealname^;
  2573. end;
  2574. function tabstractrecorddef.search_enumerator_get: tprocdef;
  2575. var
  2576. sym : tsym;
  2577. i : integer;
  2578. pd : tprocdef;
  2579. hashedid : THashedIDString;
  2580. begin
  2581. result:=nil;
  2582. hashedid.id:='GETENUMERATOR';
  2583. sym:=tsym(symtable.FindWithHash(hashedid));
  2584. if assigned(sym) and (sym.typ=procsym) then
  2585. begin
  2586. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  2587. begin
  2588. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  2589. if (pd.proctypeoption = potype_function) and
  2590. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  2591. (pd.visibility >= vis_public) then
  2592. begin
  2593. result:=pd;
  2594. exit;
  2595. end;
  2596. end;
  2597. end;
  2598. end;
  2599. function tabstractrecorddef.search_enumerator_move: tprocdef;
  2600. var
  2601. sym : tsym;
  2602. i : integer;
  2603. pd : tprocdef;
  2604. hashedid : THashedIDString;
  2605. begin
  2606. result:=nil;
  2607. // first search for po_enumerator_movenext method modifier
  2608. // then search for public function MoveNext: Boolean
  2609. for i:=0 to symtable.SymList.Count-1 do
  2610. begin
  2611. sym:=TSym(symtable.SymList[i]);
  2612. if (sym.typ=procsym) then
  2613. begin
  2614. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  2615. if assigned(pd) then
  2616. begin
  2617. result:=pd;
  2618. exit;
  2619. end;
  2620. end;
  2621. end;
  2622. hashedid.id:='MOVENEXT';
  2623. sym:=tsym(symtable.FindWithHash(hashedid));
  2624. if assigned(sym) and (sym.typ=procsym) then
  2625. begin
  2626. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  2627. begin
  2628. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  2629. if (pd.proctypeoption = potype_function) and
  2630. is_boolean(pd.returndef) and
  2631. (pd.minparacount = 0) and
  2632. (pd.visibility >= vis_public) then
  2633. begin
  2634. result:=pd;
  2635. exit;
  2636. end;
  2637. end;
  2638. end;
  2639. end;
  2640. function tabstractrecorddef.search_enumerator_current: tsym;
  2641. var
  2642. sym: tsym;
  2643. i: integer;
  2644. hashedid : THashedIDString;
  2645. begin
  2646. result:=nil;
  2647. // first search for ppo_enumerator_current property modifier
  2648. // then search for public property Current
  2649. for i:=0 to symtable.SymList.Count-1 do
  2650. begin
  2651. sym:=TSym(symtable.SymList[i]);
  2652. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  2653. begin
  2654. result:=sym;
  2655. exit;
  2656. end;
  2657. end;
  2658. hashedid.id:='CURRENT';
  2659. sym:=tsym(symtable.FindWithHash(hashedid));
  2660. if assigned(sym) and (sym.typ=propertysym) and
  2661. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  2662. begin
  2663. result:=sym;
  2664. exit;
  2665. end;
  2666. end;
  2667. {***************************************************************************
  2668. trecorddef
  2669. ***************************************************************************}
  2670. constructor trecorddef.create(const n:string; p:TSymtable);
  2671. begin
  2672. inherited create(n,recorddef);
  2673. symtable:=p;
  2674. { we can own the symtable only if nobody else owns a copy so far }
  2675. if symtable.refcount=1 then
  2676. symtable.defowner:=self;
  2677. isunion:=false;
  2678. end;
  2679. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2680. begin
  2681. inherited ppuload(recorddef,ppufile);
  2682. if df_copied_def in defoptions then
  2683. ppufile.getderef(cloneddefderef)
  2684. else
  2685. begin
  2686. symtable:=trecordsymtable.create(objrealname^,0);
  2687. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2688. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2689. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2690. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  2691. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  2692. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  2693. trecordsymtable(symtable).ppuload(ppufile);
  2694. { requires usefieldalignment to be set }
  2695. symtable.defowner:=self;
  2696. end;
  2697. isunion:=false;
  2698. end;
  2699. destructor trecorddef.destroy;
  2700. begin
  2701. if assigned(symtable) then
  2702. begin
  2703. symtable.free;
  2704. symtable:=nil;
  2705. end;
  2706. inherited destroy;
  2707. end;
  2708. function trecorddef.getcopy : tstoreddef;
  2709. begin
  2710. result:=trecorddef.create(objrealname^,symtable.getcopy);
  2711. trecorddef(result).isunion:=isunion;
  2712. include(trecorddef(result).defoptions,df_copied_def);
  2713. end;
  2714. function trecorddef.needs_inittable : boolean;
  2715. begin
  2716. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2717. end;
  2718. procedure trecorddef.buildderef;
  2719. begin
  2720. inherited buildderef;
  2721. if df_copied_def in defoptions then
  2722. cloneddefderef.build(symtable.defowner)
  2723. else
  2724. tstoredsymtable(symtable).buildderef;
  2725. end;
  2726. procedure trecorddef.deref;
  2727. begin
  2728. inherited deref;
  2729. { now dereference the definitions }
  2730. if df_copied_def in defoptions then
  2731. begin
  2732. cloneddef:=trecorddef(cloneddefderef.resolve);
  2733. symtable:=cloneddef.symtable.getcopy;
  2734. end
  2735. else
  2736. tstoredsymtable(symtable).deref;
  2737. { assign TGUID? load only from system unit }
  2738. if not(assigned(rec_tguid)) and
  2739. (upper(typename)='TGUID') and
  2740. assigned(owner) and
  2741. assigned(owner.name) and
  2742. (owner.name^='SYSTEM') then
  2743. rec_tguid:=self;
  2744. { assign JMP_BUF? load only from system unit }
  2745. if not(assigned(rec_jmp_buf)) and
  2746. (upper(typename)='JMP_BUF') and
  2747. assigned(owner) and
  2748. assigned(owner.name) and
  2749. (owner.name^='SYSTEM') then
  2750. rec_jmp_buf:=self;
  2751. end;
  2752. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2753. begin
  2754. inherited ppuwrite(ppufile);
  2755. if df_copied_def in defoptions then
  2756. ppufile.putderef(cloneddefderef)
  2757. else
  2758. begin
  2759. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2760. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2761. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2762. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  2763. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  2764. ppufile.putword(trecordsymtable(symtable).paddingsize);
  2765. end;
  2766. ppufile.writeentry(ibrecorddef);
  2767. if not(df_copied_def in defoptions) then
  2768. trecordsymtable(symtable).ppuwrite(ppufile);
  2769. end;
  2770. function trecorddef.size:asizeint;
  2771. begin
  2772. result:=trecordsymtable(symtable).datasize;
  2773. end;
  2774. function trecorddef.alignment:shortint;
  2775. begin
  2776. alignment:=trecordsymtable(symtable).recordalignment;
  2777. end;
  2778. function trecorddef.padalignment:shortint;
  2779. begin
  2780. padalignment := trecordsymtable(symtable).padalignment;
  2781. end;
  2782. function trecorddef.GetTypeName : string;
  2783. begin
  2784. GetTypeName:='<record type>'
  2785. end;
  2786. {***************************************************************************
  2787. TABSTRACTPROCDEF
  2788. ***************************************************************************}
  2789. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  2790. begin
  2791. inherited create(dt);
  2792. parast:=tparasymtable.create(self,level);
  2793. paras:=nil;
  2794. minparacount:=0;
  2795. maxparacount:=0;
  2796. proctypeoption:=potype_none;
  2797. proccalloption:=pocall_none;
  2798. procoptions:=[];
  2799. returndef:=voidtype;
  2800. savesize:=sizeof(pint);
  2801. callerargareasize:=0;
  2802. calleeargareasize:=0;
  2803. has_paraloc_info:=callnoside;
  2804. funcretloc[callerside].init;
  2805. funcretloc[calleeside].init;
  2806. check_mark_as_nested;
  2807. end;
  2808. destructor tabstractprocdef.destroy;
  2809. begin
  2810. if assigned(paras) then
  2811. begin
  2812. {$ifdef MEMDEBUG}
  2813. memprocpara.start;
  2814. {$endif MEMDEBUG}
  2815. paras.free;
  2816. paras:=nil;
  2817. {$ifdef MEMDEBUG}
  2818. memprocpara.stop;
  2819. {$endif MEMDEBUG}
  2820. end;
  2821. if assigned(parast) then
  2822. begin
  2823. {$ifdef MEMDEBUG}
  2824. memprocparast.start;
  2825. {$endif MEMDEBUG}
  2826. parast.free;
  2827. parast:=nil;
  2828. {$ifdef MEMDEBUG}
  2829. memprocparast.stop;
  2830. {$endif MEMDEBUG}
  2831. end;
  2832. funcretloc[callerside].done;
  2833. funcretloc[calleeside].done;
  2834. inherited destroy;
  2835. end;
  2836. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  2837. begin
  2838. if (tsym(p).typ<>paravarsym) then
  2839. exit;
  2840. inc(plongint(arg)^);
  2841. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  2842. begin
  2843. if not assigned(tparavarsym(p).defaultconstsym) then
  2844. inc(minparacount);
  2845. inc(maxparacount);
  2846. end;
  2847. end;
  2848. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  2849. begin
  2850. if (tsym(p).typ<>paravarsym) then
  2851. exit;
  2852. paras.add(p);
  2853. end;
  2854. procedure tabstractprocdef.calcparas;
  2855. var
  2856. paracount : longint;
  2857. begin
  2858. { This can already be assigned when
  2859. we need to reresolve this unit (PFV) }
  2860. if assigned(paras) then
  2861. paras.free;
  2862. paras:=tparalist.create(false);
  2863. paracount:=0;
  2864. minparacount:=0;
  2865. maxparacount:=0;
  2866. parast.SymList.ForEachCall(@count_para,@paracount);
  2867. paras.capacity:=paracount;
  2868. { Insert parameters in table }
  2869. parast.SymList.ForEachCall(@insert_para,nil);
  2870. { Order parameters }
  2871. paras.sortparas;
  2872. end;
  2873. procedure tabstractprocdef.buildderef;
  2874. begin
  2875. { released procdef? }
  2876. if not assigned(parast) then
  2877. exit;
  2878. inherited buildderef;
  2879. returndefderef.build(returndef);
  2880. { parast }
  2881. tparasymtable(parast).buildderef;
  2882. end;
  2883. procedure tabstractprocdef.deref;
  2884. begin
  2885. inherited deref;
  2886. returndef:=tdef(returndefderef.resolve);
  2887. { parast }
  2888. tparasymtable(parast).deref;
  2889. { recalculated parameters }
  2890. calcparas;
  2891. end;
  2892. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2893. begin
  2894. inherited ppuload(dt,ppufile);
  2895. parast:=nil;
  2896. Paras:=nil;
  2897. minparacount:=0;
  2898. maxparacount:=0;
  2899. ppufile.getderef(returndefderef);
  2900. { TODO: remove fpu_used loading}
  2901. ppufile.getbyte;
  2902. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2903. proccalloption:=tproccalloption(ppufile.getbyte);
  2904. ppufile.getnormalset(procoptions);
  2905. funcretloc[callerside].init;
  2906. if po_explicitparaloc in procoptions then
  2907. funcretloc[callerside].ppuload(ppufile);
  2908. savesize:=sizeof(pint);
  2909. if (po_explicitparaloc in procoptions) then
  2910. has_paraloc_info:=callerside;
  2911. end;
  2912. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2913. var
  2914. oldintfcrc : boolean;
  2915. begin
  2916. { released procdef? }
  2917. if not assigned(parast) then
  2918. exit;
  2919. inherited ppuwrite(ppufile);
  2920. ppufile.putderef(returndefderef);
  2921. oldintfcrc:=ppufile.do_interface_crc;
  2922. ppufile.do_interface_crc:=false;
  2923. ppufile.putbyte(0);
  2924. ppufile.putbyte(ord(proctypeoption));
  2925. ppufile.putbyte(ord(proccalloption));
  2926. ppufile.putnormalset(procoptions);
  2927. ppufile.do_interface_crc:=oldintfcrc;
  2928. if (po_explicitparaloc in procoptions) then
  2929. funcretloc[callerside].ppuwrite(ppufile);
  2930. end;
  2931. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2932. var
  2933. hs,s : string;
  2934. hp : TParavarsym;
  2935. hpc : tconstsym;
  2936. first : boolean;
  2937. i : integer;
  2938. begin
  2939. s:='';
  2940. first:=true;
  2941. for i:=0 to paras.count-1 do
  2942. begin
  2943. hp:=tparavarsym(paras[i]);
  2944. if not(vo_is_hidden_para in hp.varoptions) or
  2945. (showhidden) then
  2946. begin
  2947. if first then
  2948. begin
  2949. s:=s+'(';
  2950. first:=false;
  2951. end
  2952. else
  2953. s:=s+',';
  2954. if vo_is_hidden_para in hp.varoptions then
  2955. s:=s+'<';
  2956. case hp.varspez of
  2957. vs_var :
  2958. s:=s+'var ';
  2959. vs_const :
  2960. s:=s+'const ';
  2961. vs_out :
  2962. s:=s+'out ';
  2963. vs_constref :
  2964. s:=s+'constref ';
  2965. end;
  2966. if hp.univpara then
  2967. s:=s+'univ ';
  2968. if assigned(hp.vardef.typesym) then
  2969. begin
  2970. hs:=hp.vardef.typesym.realname;
  2971. if hs[1]<>'$' then
  2972. s:=s+hs
  2973. else
  2974. s:=s+hp.vardef.GetTypeName;
  2975. end
  2976. else
  2977. s:=s+hp.vardef.GetTypeName;
  2978. { default value }
  2979. if assigned(hp.defaultconstsym) then
  2980. begin
  2981. hpc:=tconstsym(hp.defaultconstsym);
  2982. hs:='';
  2983. case hpc.consttyp of
  2984. conststring,
  2985. constresourcestring :
  2986. begin
  2987. If hpc.value.len>0 then
  2988. begin
  2989. setLength(hs,hpc.value.len);
  2990. { don't write past the end of hs if the constant
  2991. is > 255 chars }
  2992. move(hpc.value.valueptr^,hs[1],length(hs));
  2993. { make sure that constant strings with newline chars
  2994. don't create a linebreak in the assembler code,
  2995. since comments are line-based. Also remove nulls
  2996. because the comments are written as a pchar. }
  2997. ReplaceCase(hs,#0,'.');
  2998. ReplaceCase(hs,#10,'.');
  2999. ReplaceCase(hs,#13,'.');
  3000. end;
  3001. end;
  3002. constreal :
  3003. str(pbestreal(hpc.value.valueptr)^,hs);
  3004. constpointer :
  3005. hs:=tostr(hpc.value.valueordptr);
  3006. constord :
  3007. begin
  3008. if is_boolean(hpc.constdef) then
  3009. begin
  3010. if hpc.value.valueord<>0 then
  3011. hs:='TRUE'
  3012. else
  3013. hs:='FALSE';
  3014. end
  3015. else
  3016. hs:=tostr(hpc.value.valueord);
  3017. end;
  3018. constnil :
  3019. hs:='nil';
  3020. constset :
  3021. hs:='<set>';
  3022. end;
  3023. if hs<>'' then
  3024. s:=s+'="'+hs+'"';
  3025. end;
  3026. if vo_is_hidden_para in hp.varoptions then
  3027. s:=s+'>';
  3028. end;
  3029. end;
  3030. if not first then
  3031. s:=s+')';
  3032. if (po_varargs in procoptions) then
  3033. s:=s+';VarArgs';
  3034. typename_paras:=s;
  3035. end;
  3036. function tabstractprocdef.is_methodpointer:boolean;
  3037. begin
  3038. result:=false;
  3039. end;
  3040. function tabstractprocdef.is_addressonly:boolean;
  3041. begin
  3042. result:=true;
  3043. end;
  3044. function tabstractprocdef.no_self_node: boolean;
  3045. begin
  3046. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  3047. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  3048. end;
  3049. procedure tabstractprocdef.check_mark_as_nested;
  3050. begin
  3051. { nested procvars require that nested functions use the Delphi-style
  3052. nested procedure calling convention }
  3053. if (parast.symtablelevel>normal_function_level) and
  3054. (m_nested_procvars in current_settings.modeswitches) then
  3055. include(procoptions,po_delphi_nested_cc);
  3056. end;
  3057. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  3058. begin
  3059. if (side in [callerside,callbothsides]) and
  3060. not(has_paraloc_info in [callerside,callbothsides]) then
  3061. begin
  3062. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  3063. if has_paraloc_info in [calleeside,callbothsides] then
  3064. has_paraloc_info:=callbothsides
  3065. else
  3066. has_paraloc_info:=callerside;
  3067. end;
  3068. if (side in [calleeside,callbothsides]) and
  3069. not(has_paraloc_info in [calleeside,callbothsides]) then
  3070. begin
  3071. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  3072. if has_paraloc_info in [callerside,callbothsides] then
  3073. has_paraloc_info:=callbothsides
  3074. else
  3075. has_paraloc_info:=calleeside;
  3076. end;
  3077. end;
  3078. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  3079. var
  3080. p: tparavarsym;
  3081. ploc: PCGParalocation;
  3082. i: longint;
  3083. begin
  3084. result:=false;
  3085. init_paraloc_info(side);
  3086. for i:=0 to parast.SymList.Count-1 do
  3087. if tsym(parast.SymList[i]).typ=paravarsym then
  3088. begin
  3089. p:=tparavarsym(parast.SymList[i]);
  3090. { check if no parameter is located on the stack }
  3091. if is_open_array(p.vardef) or
  3092. is_array_of_const(p.vardef) then
  3093. begin
  3094. result:=true;
  3095. exit;
  3096. end;
  3097. ploc:=p.paraloc[side].location;
  3098. while assigned(ploc) do
  3099. begin
  3100. if (ploc^.loc=LOC_REFERENCE) then
  3101. begin
  3102. result:=true;
  3103. exit
  3104. end;
  3105. ploc:=ploc^.next;
  3106. end;
  3107. end;
  3108. end;
  3109. {***************************************************************************
  3110. TPROCDEF
  3111. ***************************************************************************}
  3112. constructor tprocdef.create(level:byte);
  3113. begin
  3114. inherited create(procdef,level);
  3115. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  3116. _mangledname:=nil;
  3117. fileinfo:=current_filepos;
  3118. extnumber:=$ffff;
  3119. aliasnames:=TCmdStrList.create;
  3120. funcretsym:=nil;
  3121. forwarddef:=true;
  3122. interfacedef:=false;
  3123. hasforward:=false;
  3124. struct := nil;
  3125. import_dll:=nil;
  3126. import_name:=nil;
  3127. import_nr:=0;
  3128. inlininginfo:=nil;
  3129. deprecatedmsg:=nil;
  3130. {$ifdef i386}
  3131. fpu_used:=maxfpuregs;
  3132. {$endif i386}
  3133. interruptvector:=-1;
  3134. end;
  3135. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3136. var
  3137. i,aliasnamescount : longint;
  3138. level : byte;
  3139. begin
  3140. inherited ppuload(procdef,ppufile);
  3141. if po_has_mangledname in procoptions then
  3142. _mangledname:=stringdup(ppufile.getstring)
  3143. else
  3144. _mangledname:=nil;
  3145. extnumber:=ppufile.getword;
  3146. level:=ppufile.getbyte;
  3147. ppufile.getderef(structderef);
  3148. ppufile.getderef(procsymderef);
  3149. ppufile.getposinfo(fileinfo);
  3150. visibility:=tvisibility(ppufile.getbyte);
  3151. ppufile.getsmallset(symoptions);
  3152. if sp_has_deprecated_msg in symoptions then
  3153. deprecatedmsg:=stringdup(ppufile.getstring)
  3154. else
  3155. deprecatedmsg:=nil;
  3156. {$ifdef powerpc}
  3157. { library symbol for AmigaOS/MorphOS }
  3158. ppufile.getderef(libsymderef);
  3159. {$endif powerpc}
  3160. { import stuff }
  3161. if po_has_importdll in procoptions then
  3162. import_dll:=stringdup(ppufile.getstring)
  3163. else
  3164. import_dll:=nil;
  3165. if po_has_importname in procoptions then
  3166. import_name:=stringdup(ppufile.getstring)
  3167. else
  3168. import_name:=nil;
  3169. import_nr:=ppufile.getword;
  3170. {$ifdef FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3171. if target_info.system in systems_interrupt_table then
  3172. interruptvector:=ppufile.getlongint;
  3173. {$endif FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3174. if (po_msgint in procoptions) then
  3175. messageinf.i:=ppufile.getlongint;
  3176. if (po_msgstr in procoptions) then
  3177. messageinf.str:=stringdup(ppufile.getstring);
  3178. if (po_dispid in procoptions) then
  3179. dispid:=ppufile.getlongint;
  3180. { inline stuff }
  3181. if (po_has_inlininginfo in procoptions) then
  3182. begin
  3183. ppufile.getderef(funcretsymderef);
  3184. new(inlininginfo);
  3185. ppufile.getsmallset(inlininginfo^.flags);
  3186. end
  3187. else
  3188. begin
  3189. inlininginfo:=nil;
  3190. funcretsym:=nil;
  3191. end;
  3192. aliasnames:=TCmdStrList.create;
  3193. { count alias names }
  3194. aliasnamescount:=ppufile.getbyte;
  3195. for i:=1 to aliasnamescount do
  3196. aliasnames.insert(ppufile.getstring);
  3197. { load para symtable }
  3198. parast:=tparasymtable.create(self,level);
  3199. tparasymtable(parast).ppuload(ppufile);
  3200. { load local symtable }
  3201. if (po_has_inlininginfo in procoptions) then
  3202. begin
  3203. localst:=tlocalsymtable.create(self,level);
  3204. tlocalsymtable(localst).ppuload(ppufile);
  3205. end
  3206. else
  3207. localst:=nil;
  3208. { inline stuff }
  3209. if (po_has_inlininginfo in procoptions) then
  3210. inlininginfo^.code:=ppuloadnodetree(ppufile);
  3211. { default values for no persistent data }
  3212. if (cs_link_deffile in current_settings.globalswitches) and
  3213. (tf_need_export in target_info.flags) and
  3214. (po_exports in procoptions) then
  3215. deffile.AddExport(mangledname);
  3216. forwarddef:=false;
  3217. interfacedef:=false;
  3218. hasforward:=false;
  3219. { Disable po_has_inlining until the derefimpl is done }
  3220. exclude(procoptions,po_has_inlininginfo);
  3221. {$ifdef i386}
  3222. fpu_used:=maxfpuregs;
  3223. {$endif i386}
  3224. end;
  3225. destructor tprocdef.destroy;
  3226. begin
  3227. aliasnames.free;
  3228. aliasnames:=nil;
  3229. if assigned(localst) and
  3230. (localst.symtabletype<>staticsymtable) then
  3231. begin
  3232. {$ifdef MEMDEBUG}
  3233. memproclocalst.start;
  3234. {$endif MEMDEBUG}
  3235. localst.free;
  3236. localst:=nil;
  3237. {$ifdef MEMDEBUG}
  3238. memproclocalst.start;
  3239. {$endif MEMDEBUG}
  3240. end;
  3241. if assigned(inlininginfo) then
  3242. begin
  3243. {$ifdef MEMDEBUG}
  3244. memprocnodetree.start;
  3245. {$endif MEMDEBUG}
  3246. tnode(inlininginfo^.code).free;
  3247. {$ifdef MEMDEBUG}
  3248. memprocnodetree.start;
  3249. {$endif MEMDEBUG}
  3250. dispose(inlininginfo);
  3251. inlininginfo:=nil;
  3252. end;
  3253. stringdispose(resultname);
  3254. stringdispose(import_dll);
  3255. stringdispose(import_name);
  3256. stringdispose(deprecatedmsg);
  3257. if (po_msgstr in procoptions) then
  3258. stringdispose(messageinf.str);
  3259. if assigned(_mangledname) then
  3260. begin
  3261. {$ifdef MEMDEBUG}
  3262. memmanglednames.start;
  3263. {$endif MEMDEBUG}
  3264. stringdispose(_mangledname);
  3265. {$ifdef MEMDEBUG}
  3266. memmanglednames.stop;
  3267. {$endif MEMDEBUG}
  3268. end;
  3269. inherited destroy;
  3270. end;
  3271. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3272. var
  3273. oldintfcrc : boolean;
  3274. aliasnamescount : longint;
  3275. item : TCmdStrListItem;
  3276. begin
  3277. { released procdef? }
  3278. if not assigned(parast) then
  3279. exit;
  3280. inherited ppuwrite(ppufile);
  3281. if po_has_mangledname in procoptions then
  3282. ppufile.putstring(_mangledname^);
  3283. ppufile.putword(extnumber);
  3284. ppufile.putbyte(parast.symtablelevel);
  3285. ppufile.putderef(structderef);
  3286. ppufile.putderef(procsymderef);
  3287. ppufile.putposinfo(fileinfo);
  3288. ppufile.putbyte(byte(visibility));
  3289. ppufile.putsmallset(symoptions);
  3290. if sp_has_deprecated_msg in symoptions then
  3291. ppufile.putstring(deprecatedmsg^);
  3292. {$ifdef powerpc}
  3293. { library symbol for AmigaOS/MorphOS }
  3294. ppufile.putderef(libsymderef);
  3295. {$endif powerpc}
  3296. { import }
  3297. if po_has_importdll in procoptions then
  3298. ppufile.putstring(import_dll^);
  3299. if po_has_importname in procoptions then
  3300. ppufile.putstring(import_name^);
  3301. ppufile.putword(import_nr);
  3302. {$ifdef FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3303. if target_info.system in systems_interrupt_table then
  3304. ppufile.putlongint(interruptvector);
  3305. {$endif FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  3306. if (po_msgint in procoptions) then
  3307. ppufile.putlongint(messageinf.i);
  3308. if (po_msgstr in procoptions) then
  3309. ppufile.putstring(messageinf.str^);
  3310. if (po_dispid in procoptions) then
  3311. ppufile.putlongint(dispid);
  3312. { inline stuff }
  3313. oldintfcrc:=ppufile.do_crc;
  3314. ppufile.do_crc:=false;
  3315. if (po_has_inlininginfo in procoptions) then
  3316. begin
  3317. ppufile.putderef(funcretsymderef);
  3318. ppufile.putsmallset(inlininginfo^.flags);
  3319. end;
  3320. { count alias names }
  3321. aliasnamescount:=0;
  3322. item:=TCmdStrListItem(aliasnames.first);
  3323. while assigned(item) do
  3324. begin
  3325. inc(aliasnamescount);
  3326. item:=TCmdStrListItem(item.next);
  3327. end;
  3328. if aliasnamescount>255 then
  3329. internalerror(200711021);
  3330. ppufile.putbyte(aliasnamescount);
  3331. item:=TCmdStrListItem(aliasnames.first);
  3332. while assigned(item) do
  3333. begin
  3334. ppufile.putstring(item.str);
  3335. item:=TCmdStrListItem(item.next);
  3336. end;
  3337. ppufile.do_crc:=oldintfcrc;
  3338. { write this entry }
  3339. ppufile.writeentry(ibprocdef);
  3340. { Save the para symtable, this is taken from the interface }
  3341. tparasymtable(parast).ppuwrite(ppufile);
  3342. { save localsymtable for inline procedures or when local
  3343. browser info is requested, this has no influence on the crc }
  3344. if (po_has_inlininginfo in procoptions) then
  3345. begin
  3346. oldintfcrc:=ppufile.do_crc;
  3347. ppufile.do_crc:=false;
  3348. tlocalsymtable(localst).ppuwrite(ppufile);
  3349. ppufile.do_crc:=oldintfcrc;
  3350. end;
  3351. { node tree for inlining }
  3352. oldintfcrc:=ppufile.do_crc;
  3353. ppufile.do_crc:=false;
  3354. if (po_has_inlininginfo in procoptions) then
  3355. ppuwritenodetree(ppufile,inlininginfo^.code);
  3356. ppufile.do_crc:=oldintfcrc;
  3357. end;
  3358. function tprocdef.fullprocname(showhidden:boolean):string;
  3359. var
  3360. s : string;
  3361. t : ttoken;
  3362. begin
  3363. {$ifdef EXTDEBUG}
  3364. showhidden:=true;
  3365. {$endif EXTDEBUG}
  3366. s:='';
  3367. if assigned(struct) then
  3368. begin
  3369. s:=struct.RttiName+'.';
  3370. if (po_classmethod in procoptions) and
  3371. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  3372. s:='class ' + s;
  3373. end;
  3374. if proctypeoption=potype_operator then
  3375. begin
  3376. for t:=NOTOKEN to last_overloaded do
  3377. if procsym.realname='$'+overloaded_names[t] then
  3378. begin
  3379. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3380. break;
  3381. end;
  3382. end
  3383. else
  3384. s:=s+procsym.realname+typename_paras(showhidden);
  3385. case proctypeoption of
  3386. potype_constructor:
  3387. s:='constructor '+s;
  3388. potype_destructor:
  3389. s:='destructor '+s;
  3390. potype_class_constructor:
  3391. s:='class constructor '+s;
  3392. potype_class_destructor:
  3393. s:='class destructor '+s;
  3394. else
  3395. if assigned(returndef) and
  3396. not(is_void(returndef)) then
  3397. s:=s+':'+returndef.GetTypeName;
  3398. end;
  3399. if owner.symtabletype=localsymtable then
  3400. s:=s+' is nested';
  3401. s:=s+';';
  3402. { forced calling convention? }
  3403. if (po_hascallingconvention in procoptions) then
  3404. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  3405. if (po_staticmethod in procoptions) and
  3406. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  3407. s:=s+' Static;';
  3408. fullprocname:=s;
  3409. end;
  3410. function tprocdef.is_methodpointer:boolean;
  3411. begin
  3412. { don't check assigned(_class), that's also the case for nested
  3413. procedures inside methods }
  3414. result:=owner.symtabletype=ObjectSymtable;
  3415. end;
  3416. function tprocdef.is_addressonly:boolean;
  3417. begin
  3418. result:=assigned(owner) and
  3419. (owner.symtabletype<>ObjectSymtable) and
  3420. (not(m_nested_procvars in current_settings.modeswitches) or
  3421. not is_nested_pd(self));
  3422. end;
  3423. procedure tprocdef.make_external;
  3424. begin
  3425. include(procoptions,po_external);
  3426. forwarddef:=false;
  3427. end;
  3428. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  3429. begin
  3430. case t of
  3431. gs_local :
  3432. GetSymtable:=localst;
  3433. gs_para :
  3434. GetSymtable:=parast;
  3435. else
  3436. GetSymtable:=nil;
  3437. end;
  3438. end;
  3439. procedure tprocdef.buildderef;
  3440. begin
  3441. inherited buildderef;
  3442. structderef.build(struct);
  3443. { procsym that originaly defined this definition, should be in the
  3444. same symtable }
  3445. procsymderef.build(procsym);
  3446. {$ifdef powerpc}
  3447. { library symbol for AmigaOS/MorphOS }
  3448. libsymderef.build(libsym);
  3449. {$endif powerpc}
  3450. end;
  3451. procedure tprocdef.buildderefimpl;
  3452. begin
  3453. inherited buildderefimpl;
  3454. { Localst is not available for main/unit init }
  3455. if assigned(localst) then
  3456. begin
  3457. tlocalsymtable(localst).buildderef;
  3458. tlocalsymtable(localst).buildderefimpl;
  3459. end;
  3460. { inline tree }
  3461. if (po_has_inlininginfo in procoptions) then
  3462. begin
  3463. funcretsymderef.build(funcretsym);
  3464. inlininginfo^.code.buildderefimpl;
  3465. end;
  3466. end;
  3467. procedure tprocdef.deref;
  3468. begin
  3469. inherited deref;
  3470. struct:=tabstractrecorddef(structderef.resolve);
  3471. { procsym that originaly defined this definition, should be in the
  3472. same symtable }
  3473. procsym:=tprocsym(procsymderef.resolve);
  3474. {$ifdef powerpc}
  3475. { library symbol for AmigaOS/MorphOS }
  3476. libsym:=tsym(libsymderef.resolve);
  3477. {$endif powerpc}
  3478. end;
  3479. procedure tprocdef.derefimpl;
  3480. begin
  3481. { Enable has_inlininginfo when the inlininginfo
  3482. structure is available. The has_inlininginfo was disabled
  3483. after the load, since the data was invalid }
  3484. if assigned(inlininginfo) then
  3485. include(procoptions,po_has_inlininginfo);
  3486. { Locals }
  3487. if assigned(localst) then
  3488. begin
  3489. tlocalsymtable(localst).deref;
  3490. tlocalsymtable(localst).derefimpl;
  3491. end;
  3492. { Inline }
  3493. if (po_has_inlininginfo in procoptions) then
  3494. begin
  3495. inlininginfo^.code.derefimpl;
  3496. { funcretsym, this is always located in the localst }
  3497. funcretsym:=tsym(funcretsymderef.resolve);
  3498. end
  3499. else
  3500. begin
  3501. { safety }
  3502. { Not safe! A unit may be reresolved after its interface has been
  3503. parsed but before its implementation has been parsed, and in that
  3504. case the funcretsym is still required!
  3505. funcretsym:=nil; }
  3506. end;
  3507. end;
  3508. function tprocdef.GetTypeName : string;
  3509. begin
  3510. GetTypeName := FullProcName(false);
  3511. end;
  3512. function tprocdef.mangledname : string;
  3513. var
  3514. hp : TParavarsym;
  3515. hs : string;
  3516. crc : dword;
  3517. newlen,
  3518. oldlen,
  3519. i : integer;
  3520. begin
  3521. if assigned(_mangledname) then
  3522. begin
  3523. {$ifdef compress}
  3524. mangledname:=minilzw_decode(_mangledname^);
  3525. {$else}
  3526. mangledname:=_mangledname^;
  3527. {$endif}
  3528. exit;
  3529. end;
  3530. { we need to use the symtable where the procsym is inserted,
  3531. because that is visible to the world }
  3532. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3533. oldlen:=length(mangledname);
  3534. { add parameter types }
  3535. for i:=0 to paras.count-1 do
  3536. begin
  3537. hp:=tparavarsym(paras[i]);
  3538. if not(vo_is_hidden_para in hp.varoptions) then
  3539. mangledname:=mangledname+'$'+hp.vardef.mangledparaname;
  3540. end;
  3541. { add resultdef, add $$ as separator to make it unique from a
  3542. parameter separator }
  3543. if not is_void(returndef) then
  3544. mangledname:=mangledname+'$$'+returndef.mangledparaname;
  3545. newlen:=length(mangledname);
  3546. { Replace with CRC if the parameter line is very long }
  3547. if (newlen-oldlen>12) and
  3548. ((newlen>100) or (newlen-oldlen>64)) then
  3549. begin
  3550. crc:=0;
  3551. for i:=0 to paras.count-1 do
  3552. begin
  3553. hp:=tparavarsym(paras[i]);
  3554. if not(vo_is_hidden_para in hp.varoptions) then
  3555. begin
  3556. hs:=hp.vardef.mangledparaname;
  3557. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3558. end;
  3559. end;
  3560. hs:=hp.vardef.mangledparaname;
  3561. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3562. mangledname:=Copy(mangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  3563. end;
  3564. {$ifdef compress}
  3565. _mangledname:=stringdup(minilzw_encode(mangledname));
  3566. {$else}
  3567. _mangledname:=stringdup(mangledname);
  3568. {$endif}
  3569. end;
  3570. function tprocdef.cplusplusmangledname : string;
  3571. function getcppparaname(p : tdef) : string;
  3572. const
  3573. {$ifdef NAMEMANGLING_GCC2}
  3574. ordtype2str : array[tordtype] of string[2] = (
  3575. '',
  3576. 'Uc','Us','Ui','Us',
  3577. 'Sc','s','i','x',
  3578. 'b','b','b','b','b',
  3579. 'c','w','x');
  3580. {$else NAMEMANGLING_GCC2}
  3581. ordtype2str : array[tordtype] of string[1] = (
  3582. 'v',
  3583. 'h','t','j','y',
  3584. 'a','s','i','x',
  3585. 'b','b','b','b',
  3586. 'b','b','b','b',
  3587. 'c','w','x');
  3588. floattype2str : array[tfloattype] of string[1] = (
  3589. 'f','d','e','e',
  3590. 'd','d','g');
  3591. {$endif NAMEMANGLING_GCC2}
  3592. var
  3593. s : string;
  3594. begin
  3595. case p.typ of
  3596. orddef:
  3597. s:=ordtype2str[torddef(p).ordtype];
  3598. pointerdef:
  3599. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  3600. {$ifndef NAMEMANGLING_GCC2}
  3601. floatdef:
  3602. s:=floattype2str[tfloatdef(p).floattype];
  3603. {$endif NAMEMANGLING_GCC2}
  3604. else
  3605. internalerror(2103001);
  3606. end;
  3607. getcppparaname:=s;
  3608. end;
  3609. var
  3610. s,s2 : string;
  3611. hp : TParavarsym;
  3612. i : integer;
  3613. begin
  3614. {$ifdef NAMEMANGLING_GCC2}
  3615. { outdated gcc 2.x name mangling scheme }
  3616. s := procsym.realname;
  3617. if procsym.owner.symtabletype=ObjectSymtable then
  3618. begin
  3619. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  3620. case proctypeoption of
  3621. potype_destructor:
  3622. s:='_$_'+tostr(length(s2))+s2;
  3623. potype_constructor:
  3624. s:='___'+tostr(length(s2))+s2;
  3625. else
  3626. s:='_'+s+'__'+tostr(length(s2))+s2;
  3627. end;
  3628. end
  3629. else s:=s+'__';
  3630. s:=s+'F';
  3631. { concat modifiers }
  3632. { !!!!! }
  3633. { now we handle the parameters }
  3634. if maxparacount>0 then
  3635. begin
  3636. for i:=0 to paras.count-1 do
  3637. begin
  3638. hp:=tparavarsym(paras[i]);
  3639. { no hidden parameters form part of a C++ mangled name:
  3640. a) self is not included
  3641. b) there are no "high" or other hidden parameters
  3642. }
  3643. if vo_is_hidden_para in hp.varoptions then
  3644. continue;
  3645. s2:=getcppparaname(hp.vardef);
  3646. if hp.varspez in [vs_var,vs_out] then
  3647. s2:='R'+s2;
  3648. s:=s+s2;
  3649. end;
  3650. end
  3651. else
  3652. s:=s+'v';
  3653. cplusplusmangledname:=s;
  3654. {$else NAMEMANGLING_GCC2}
  3655. { gcc 3.x and 4.x name mangling scheme }
  3656. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  3657. if procsym.owner.symtabletype=ObjectSymtable then
  3658. begin
  3659. s:='_ZN';
  3660. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  3661. s:=s+tostr(length(s2))+s2;
  3662. case proctypeoption of
  3663. potype_constructor:
  3664. s:=s+'C1';
  3665. potype_destructor:
  3666. s:=s+'D1';
  3667. else
  3668. s:=s+tostr(length(procsym.realname))+procsym.realname;
  3669. end;
  3670. s:=s+'E';
  3671. end
  3672. else
  3673. s:=procsym.realname;
  3674. { now we handle the parameters }
  3675. if maxparacount>0 then
  3676. begin
  3677. for i:=0 to paras.count-1 do
  3678. begin
  3679. hp:=tparavarsym(paras[i]);
  3680. { no hidden parameters form part of a C++ mangled name:
  3681. a) self is not included
  3682. b) there are no "high" or other hidden parameters
  3683. }
  3684. if vo_is_hidden_para in hp.varoptions then
  3685. continue;
  3686. s2:=getcppparaname(hp.vardef);
  3687. if hp.varspez in [vs_var,vs_out] then
  3688. s2:='R'+s2;
  3689. s:=s+s2;
  3690. end;
  3691. end
  3692. else
  3693. s:=s+'v';
  3694. cplusplusmangledname:=s;
  3695. {$endif NAMEMANGLING_GCC2}
  3696. end;
  3697. function tprocdef.objcmangledname : string;
  3698. var
  3699. manglednamelen: longint;
  3700. iscatmethod : boolean;
  3701. begin
  3702. if not (po_msgstr in procoptions) then
  3703. internalerror(2009030901);
  3704. { we may very well need longer strings to handle these... }
  3705. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  3706. length('+"[ ]"')+length(messageinf.str^);
  3707. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  3708. if (iscatmethod) then
  3709. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  3710. if manglednamelen>255 then
  3711. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  3712. if not(po_classmethod in procoptions) then
  3713. result:='"-['
  3714. else
  3715. result:='"+[';
  3716. { quotes are necessary because the +/- otherwise confuse the assembler
  3717. into expecting a number
  3718. }
  3719. if iscatmethod then
  3720. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  3721. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  3722. if iscatmethod then
  3723. result:=result+')';
  3724. result:=result+' '+messageinf.str^+']"';
  3725. end;
  3726. procedure tprocdef.setmangledname(const s : string);
  3727. begin
  3728. { This is not allowed anymore, the forward declaration
  3729. already needs to create the correct mangledname, no changes
  3730. afterwards are allowed (PFV) }
  3731. { Exception: interface definitions in mode macpas, since in that }
  3732. { case no reference to the old name can exist yet (JM) }
  3733. if assigned(_mangledname) then
  3734. if ((m_mac in current_settings.modeswitches) and
  3735. (interfacedef)) then
  3736. stringdispose(_mangledname)
  3737. else
  3738. internalerror(200411171);
  3739. {$ifdef compress}
  3740. _mangledname:=stringdup(minilzw_encode(s));
  3741. {$else}
  3742. _mangledname:=stringdup(s);
  3743. {$endif}
  3744. include(procoptions,po_has_mangledname);
  3745. end;
  3746. {***************************************************************************
  3747. TPROCVARDEF
  3748. ***************************************************************************}
  3749. constructor tprocvardef.create(level:byte);
  3750. begin
  3751. inherited create(procvardef,level);
  3752. end;
  3753. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3754. begin
  3755. inherited ppuload(procvardef,ppufile);
  3756. { load para symtable }
  3757. parast:=tparasymtable.create(self,ppufile.getbyte);
  3758. tparasymtable(parast).ppuload(ppufile);
  3759. end;
  3760. function tprocvardef.getcopy : tstoreddef;
  3761. var
  3762. i : tcallercallee;
  3763. j : longint;
  3764. begin
  3765. result:=tprocvardef.create(parast.symtablelevel);
  3766. tprocvardef(result).returndef:=returndef;
  3767. tprocvardef(result).returndefderef:=returndefderef;
  3768. tprocvardef(result).parast:=parast.getcopy;
  3769. tprocvardef(result).savesize:=savesize;
  3770. { create paralist copy }
  3771. tprocvardef(result).paras:=tparalist.create(false);
  3772. tprocvardef(result).paras.count:=paras.count;
  3773. for j:=0 to paras.count-1 do
  3774. tprocvardef(result).paras[j]:=paras[j];
  3775. tprocvardef(result).proctypeoption:=proctypeoption;
  3776. tprocvardef(result).proccalloption:=proccalloption;
  3777. tprocvardef(result).procoptions:=procoptions;
  3778. tprocvardef(result).callerargareasize:=callerargareasize;
  3779. tprocvardef(result).calleeargareasize:=calleeargareasize;
  3780. tprocvardef(result).maxparacount:=maxparacount;
  3781. tprocvardef(result).minparacount:=minparacount;
  3782. for i:=low(tcallercallee) to high(tcallercallee) do
  3783. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  3784. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  3785. {$ifdef m68k}
  3786. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  3787. {$endif}
  3788. end;
  3789. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3790. begin
  3791. inherited ppuwrite(ppufile);
  3792. { Save the para symtable level (necessary to distinguish nested
  3793. procvars) }
  3794. ppufile.putbyte(parast.symtablelevel);
  3795. { Write this entry }
  3796. ppufile.writeentry(ibprocvardef);
  3797. { Save the para symtable, this is taken from the interface }
  3798. tparasymtable(parast).ppuwrite(ppufile);
  3799. end;
  3800. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  3801. begin
  3802. case t of
  3803. gs_para :
  3804. GetSymtable:=parast;
  3805. else
  3806. GetSymtable:=nil;
  3807. end;
  3808. end;
  3809. function tprocvardef.size : asizeint;
  3810. begin
  3811. if ((po_methodpointer in procoptions) or
  3812. is_nested_pd(self)) and
  3813. not(po_addressonly in procoptions) then
  3814. size:=2*sizeof(pint)
  3815. else
  3816. size:=sizeof(pint);
  3817. end;
  3818. function tprocvardef.is_methodpointer:boolean;
  3819. begin
  3820. result:=(po_methodpointer in procoptions);
  3821. end;
  3822. function tprocvardef.is_addressonly:boolean;
  3823. begin
  3824. result:=(not(po_methodpointer in procoptions) and
  3825. not is_nested_pd(self)) or
  3826. (po_addressonly in procoptions);
  3827. end;
  3828. function tprocvardef.getmangledparaname:string;
  3829. begin
  3830. if not(po_methodpointer in procoptions) then
  3831. if not is_nested_pd(self) then
  3832. result:='procvar'
  3833. else
  3834. result:='nestedprovar'
  3835. else
  3836. result:='procvarofobj'
  3837. end;
  3838. function tprocvardef.is_publishable : boolean;
  3839. begin
  3840. is_publishable:=(po_methodpointer in procoptions);
  3841. end;
  3842. function tprocvardef.GetTypeName : string;
  3843. var
  3844. s: string;
  3845. showhidden : boolean;
  3846. begin
  3847. {$ifdef EXTDEBUG}
  3848. showhidden:=true;
  3849. {$else EXTDEBUG}
  3850. showhidden:=false;
  3851. {$endif EXTDEBUG}
  3852. s:='<';
  3853. if po_classmethod in procoptions then
  3854. s := s+'class method type of'
  3855. else
  3856. if po_addressonly in procoptions then
  3857. s := s+'address of'
  3858. else
  3859. s := s+'procedure variable type of';
  3860. if assigned(returndef) and
  3861. (returndef<>voidtype) then
  3862. s:=s+' function'+typename_paras(showhidden)+':'+returndef.GetTypeName
  3863. else
  3864. s:=s+' procedure'+typename_paras(showhidden);
  3865. if po_methodpointer in procoptions then
  3866. s := s+' of object';
  3867. if is_nested_pd(self) then
  3868. s := s+' is nested';
  3869. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3870. end;
  3871. {***************************************************************************
  3872. TOBJECTDEF
  3873. ***************************************************************************}
  3874. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  3875. begin
  3876. inherited create(n,objectdef);
  3877. fcurrent_dispid:=0;
  3878. objecttype:=ot;
  3879. childof:=nil;
  3880. if objecttype=odt_helper then
  3881. owner.includeoption(sto_has_helper);
  3882. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  3883. { create space for vmt !! }
  3884. vmtentries:=TFPList.Create;
  3885. vmt_offset:=0;
  3886. set_parent(c);
  3887. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  3888. prepareguid;
  3889. { setup implemented interfaces }
  3890. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol] then
  3891. ImplementedInterfaces:=TFPObjectList.Create(true)
  3892. else
  3893. ImplementedInterfaces:=nil;
  3894. writing_class_record_dbginfo:=false;
  3895. end;
  3896. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3897. var
  3898. i,
  3899. implintfcount : longint;
  3900. d : tderef;
  3901. ImplIntf : TImplementedInterface;
  3902. vmtentry : pvmtentry;
  3903. begin
  3904. inherited ppuload(objectdef,ppufile);
  3905. objecttype:=tobjecttyp(ppufile.getbyte);
  3906. objextname:=stringdup(ppufile.getstring);
  3907. { only used for external Objective-C classes/protocols }
  3908. if (objextname^='') then
  3909. stringdispose(objextname);
  3910. import_lib:=stringdup(ppufile.getstring);
  3911. { only used for external C++ classes }
  3912. if (import_lib^='') then
  3913. stringdispose(import_lib);
  3914. symtable:=tObjectSymtable.create(self,objrealname^,0);
  3915. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  3916. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  3917. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  3918. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  3919. vmt_offset:=ppufile.getlongint;
  3920. ppufile.getderef(childofderef);
  3921. { load guid }
  3922. iidstr:=nil;
  3923. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3924. begin
  3925. new(iidguid);
  3926. ppufile.getguid(iidguid^);
  3927. iidstr:=stringdup(ppufile.getstring);
  3928. end;
  3929. if objecttype=odt_helper then
  3930. ppufile.getderef(extendeddefderef);
  3931. vmtentries:=TFPList.Create;
  3932. vmtentries.count:=ppufile.getlongint;
  3933. for i:=0 to vmtentries.count-1 do
  3934. begin
  3935. ppufile.getderef(d);
  3936. new(vmtentry);
  3937. vmtentry^.procdef:=nil;
  3938. vmtentry^.procdefderef:=d;
  3939. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  3940. vmtentries[i]:=vmtentry;
  3941. end;
  3942. { load implemented interfaces }
  3943. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol] then
  3944. begin
  3945. ImplementedInterfaces:=TFPObjectList.Create(true);
  3946. implintfcount:=ppufile.getlongint;
  3947. for i:=0 to implintfcount-1 do
  3948. begin
  3949. ppufile.getderef(d);
  3950. ImplIntf:=TImplementedInterface.Create_deref(d);
  3951. ImplIntf.IOffset:=ppufile.getlongint;
  3952. ImplementedInterfaces.Add(ImplIntf);
  3953. end;
  3954. end
  3955. else
  3956. ImplementedInterfaces:=nil;
  3957. if df_copied_def in defoptions then
  3958. ppufile.getderef(cloneddefderef)
  3959. else
  3960. tObjectSymtable(symtable).ppuload(ppufile);
  3961. { handles the predefined class tobject }
  3962. { the last TOBJECT which is loaded gets }
  3963. { it ! }
  3964. if (childof=nil) and
  3965. (objecttype=odt_class) and
  3966. (objname^='TOBJECT') then
  3967. class_tobject:=self;
  3968. if (childof=nil) and
  3969. (objecttype=odt_interfacecom) then
  3970. if (objname^='IUNKNOWN') then
  3971. interface_iunknown:=self
  3972. else
  3973. if (objname^='IDISPATCH') then
  3974. interface_idispatch:=self;
  3975. if (childof=nil) and
  3976. (objecttype=odt_objcclass) and
  3977. (objname^='PROTOCOL') then
  3978. objc_protocoltype:=self;
  3979. writing_class_record_dbginfo:=false;
  3980. end;
  3981. destructor tobjectdef.destroy;
  3982. begin
  3983. if assigned(symtable) then
  3984. begin
  3985. symtable.free;
  3986. symtable:=nil;
  3987. end;
  3988. stringdispose(objextname);
  3989. stringdispose(import_lib);
  3990. stringdispose(iidstr);
  3991. if assigned(ImplementedInterfaces) then
  3992. begin
  3993. ImplementedInterfaces.free;
  3994. ImplementedInterfaces:=nil;
  3995. end;
  3996. if assigned(iidguid) then
  3997. begin
  3998. dispose(iidguid);
  3999. iidguid:=nil;
  4000. end;
  4001. if assigned(vmtentries) then
  4002. begin
  4003. resetvmtentries;
  4004. vmtentries.free;
  4005. vmtentries:=nil;
  4006. end;
  4007. if assigned(vmcallstaticinfo) then
  4008. begin
  4009. freemem(vmcallstaticinfo);
  4010. vmcallstaticinfo:=nil;
  4011. end;
  4012. inherited destroy;
  4013. end;
  4014. function tobjectdef.getcopy : tstoreddef;
  4015. var
  4016. i : longint;
  4017. begin
  4018. result:=tobjectdef.create(objecttype,objrealname^,childof);
  4019. { the constructor allocates a symtable which we release to avoid memory leaks }
  4020. tobjectdef(result).symtable.free;
  4021. tobjectdef(result).symtable:=symtable.getcopy;
  4022. if assigned(objextname) then
  4023. tobjectdef(result).objextname:=stringdup(objextname^);
  4024. if assigned(import_lib) then
  4025. tobjectdef(result).import_lib:=stringdup(import_lib^);
  4026. tobjectdef(result).objectoptions:=objectoptions;
  4027. include(tobjectdef(result).defoptions,df_copied_def);
  4028. tobjectdef(result).extendeddef:=extendeddef;
  4029. tobjectdef(result).vmt_offset:=vmt_offset;
  4030. if assigned(iidguid) then
  4031. begin
  4032. new(tobjectdef(result).iidguid);
  4033. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  4034. end;
  4035. if assigned(iidstr) then
  4036. tobjectdef(result).iidstr:=stringdup(iidstr^);
  4037. if assigned(ImplementedInterfaces) then
  4038. begin
  4039. for i:=0 to ImplementedInterfaces.count-1 do
  4040. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  4041. end;
  4042. if assigned(vmtentries) then
  4043. begin
  4044. tobjectdef(result).vmtentries:=TFPList.Create;
  4045. tobjectdef(result).copyvmtentries(self);
  4046. end;
  4047. end;
  4048. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4049. var
  4050. i : longint;
  4051. vmtentry : pvmtentry;
  4052. ImplIntf : TImplementedInterface;
  4053. old_do_indirect_crc: boolean;
  4054. begin
  4055. { if class1 in unit A changes, and class2 in unit B inherits from it
  4056. (so unit B uses unit A), then unit B with class2 will be recompiled.
  4057. However, if there is also a class3 in unit C that only depends on
  4058. unit B, then unit C will not be recompiled because nothing changed
  4059. to the interface of unit B. Nevertheless, unit C can indirectly
  4060. depend on unit A via derefs, and these must be updated -> the
  4061. indirect crc keeps track of such changes. }
  4062. old_do_indirect_crc:=ppufile.do_indirect_crc;
  4063. ppufile.do_indirect_crc:=true;
  4064. inherited ppuwrite(ppufile);
  4065. ppufile.putbyte(byte(objecttype));
  4066. if assigned(objextname) then
  4067. ppufile.putstring(objextname^)
  4068. else
  4069. ppufile.putstring('');
  4070. if assigned(import_lib) then
  4071. ppufile.putstring(import_lib^)
  4072. else
  4073. ppufile.putstring('');
  4074. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  4075. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  4076. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  4077. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  4078. ppufile.putlongint(vmt_offset);
  4079. ppufile.putderef(childofderef);
  4080. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  4081. begin
  4082. ppufile.putguid(iidguid^);
  4083. ppufile.putstring(iidstr^);
  4084. end;
  4085. if objecttype=odt_helper then
  4086. ppufile.putderef(extendeddefderef);
  4087. ppufile.putlongint(vmtentries.count);
  4088. for i:=0 to vmtentries.count-1 do
  4089. begin
  4090. vmtentry:=pvmtentry(vmtentries[i]);
  4091. ppufile.putderef(vmtentry^.procdefderef);
  4092. ppufile.putbyte(byte(vmtentry^.visibility));
  4093. end;
  4094. if assigned(ImplementedInterfaces) then
  4095. begin
  4096. ppufile.putlongint(ImplementedInterfaces.Count);
  4097. for i:=0 to ImplementedInterfaces.Count-1 do
  4098. begin
  4099. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  4100. ppufile.putderef(ImplIntf.intfdefderef);
  4101. ppufile.putlongint(ImplIntf.Ioffset);
  4102. end;
  4103. end;
  4104. if df_copied_def in defoptions then
  4105. ppufile.putderef(cloneddefderef);
  4106. ppufile.writeentry(ibobjectdef);
  4107. if not(df_copied_def in defoptions) then
  4108. tObjectSymtable(symtable).ppuwrite(ppufile);
  4109. ppufile.do_indirect_crc:=old_do_indirect_crc;
  4110. end;
  4111. function tobjectdef.GetTypeName:string;
  4112. begin
  4113. { in this case we will go in endless recursion, because then }
  4114. { there is no tsym associated yet with the def. It can occur }
  4115. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  4116. { instead of the actual type name }
  4117. if not assigned(typesym) then
  4118. result:='<Currently Parsed Class>'
  4119. else
  4120. result:=typesymbolprettyname;
  4121. end;
  4122. procedure tobjectdef.buildderef;
  4123. var
  4124. i : longint;
  4125. vmtentry : pvmtentry;
  4126. begin
  4127. inherited buildderef;
  4128. childofderef.build(childof);
  4129. if df_copied_def in defoptions then
  4130. cloneddefderef.build(symtable.defowner)
  4131. else
  4132. tstoredsymtable(symtable).buildderef;
  4133. if objecttype=odt_helper then
  4134. extendeddefderef.build(extendeddef);
  4135. for i:=0 to vmtentries.count-1 do
  4136. begin
  4137. vmtentry:=pvmtentry(vmtentries[i]);
  4138. vmtentry^.procdefderef.build(vmtentry^.procdef);
  4139. end;
  4140. if assigned(ImplementedInterfaces) then
  4141. begin
  4142. for i:=0 to ImplementedInterfaces.count-1 do
  4143. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  4144. end;
  4145. end;
  4146. procedure tobjectdef.deref;
  4147. var
  4148. i : longint;
  4149. vmtentry : pvmtentry;
  4150. begin
  4151. inherited deref;
  4152. childof:=tobjectdef(childofderef.resolve);
  4153. if df_copied_def in defoptions then
  4154. begin
  4155. cloneddef:=tobjectdef(cloneddefderef.resolve);
  4156. symtable:=cloneddef.symtable.getcopy;
  4157. end
  4158. else
  4159. tstoredsymtable(symtable).deref;
  4160. if objecttype=odt_helper then
  4161. extendeddef:=tdef(extendeddefderef.resolve);
  4162. for i:=0 to vmtentries.count-1 do
  4163. begin
  4164. vmtentry:=pvmtentry(vmtentries[i]);
  4165. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  4166. end;
  4167. if assigned(ImplementedInterfaces) then
  4168. begin
  4169. for i:=0 to ImplementedInterfaces.count-1 do
  4170. TImplementedInterface(ImplementedInterfaces[i]).deref;
  4171. end;
  4172. end;
  4173. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  4174. var
  4175. pd: tprocdef absolute def;
  4176. st: tsymtable;
  4177. psym: tsym;
  4178. nname: TIDString;
  4179. begin
  4180. if (tdef(def).typ<>procdef) then
  4181. exit;
  4182. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  4183. owner = symtable in which objcclassdef is defined
  4184. }
  4185. st:=pd.owner.defowner.owner;
  4186. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  4187. { check for an existing procsym with our special name }
  4188. psym:=tsym(st.find(nname));
  4189. if not assigned(psym) then
  4190. begin
  4191. psym:=tprocsym.create(nname);
  4192. { avoid warning about this symbol being unused }
  4193. psym.IncRefCount;
  4194. { don't check for duplicates:
  4195. a) we checked above
  4196. b) in case we are in the implementation section of a unit, this
  4197. will also check for this symbol in the interface section
  4198. (since you normally cannot have symbols with the same name
  4199. both interface and implementation), and it's possible to
  4200. have class helpers for the same class in the interface and
  4201. in the implementation, and they cannot be merged since only
  4202. the once in the interface must be saved to the ppu/visible
  4203. from other units }
  4204. st.insert(psym,false);
  4205. end
  4206. else if (psym.typ<>procsym) then
  4207. internalerror(2009111501);
  4208. { add ourselves to this special procsym }
  4209. tprocsym(psym).procdeflist.add(def);
  4210. end;
  4211. procedure tobjectdef.buildderefimpl;
  4212. begin
  4213. inherited buildderefimpl;
  4214. if not (df_copied_def in defoptions) then
  4215. tstoredsymtable(symtable).buildderefimpl;
  4216. end;
  4217. procedure tobjectdef.derefimpl;
  4218. begin
  4219. inherited derefimpl;
  4220. if not (df_copied_def in defoptions) then
  4221. tstoredsymtable(symtable).derefimpl;
  4222. { the procdefs are not owned by the class helper procsyms, so they
  4223. are not stored/restored either -> re-add them here }
  4224. if (objecttype=odt_objcclass) or
  4225. (oo_is_classhelper in objectoptions) then
  4226. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  4227. end;
  4228. procedure tobjectdef.resetvmtentries;
  4229. var
  4230. i : longint;
  4231. begin
  4232. for i:=0 to vmtentries.Count-1 do
  4233. Dispose(pvmtentry(vmtentries[i]));
  4234. vmtentries.clear;
  4235. end;
  4236. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  4237. var
  4238. i : longint;
  4239. vmtentry : pvmtentry;
  4240. begin
  4241. resetvmtentries;
  4242. vmtentries.count:=objdef.vmtentries.count;
  4243. for i:=0 to objdef.vmtentries.count-1 do
  4244. begin
  4245. new(vmtentry);
  4246. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  4247. vmtentries[i]:=vmtentry;
  4248. end;
  4249. end;
  4250. function tobjectdef.getparentdef:tdef;
  4251. begin
  4252. { TODO: Remove getparentdef hack}
  4253. { With 2 forward declared classes with the child class before the
  4254. parent class the child class is written earlier to the ppu. Leaving it
  4255. possible to have a reference to the parent class for property overriding,
  4256. but the parent class still has the childof not resolved yet (PFV) }
  4257. if childof=nil then
  4258. childof:=tobjectdef(childofderef.resolve);
  4259. result:=childof;
  4260. end;
  4261. procedure tobjectdef.prepareguid;
  4262. begin
  4263. { set up guid }
  4264. if not assigned(iidguid) then
  4265. begin
  4266. new(iidguid);
  4267. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4268. end;
  4269. { setup iidstring }
  4270. if not assigned(iidstr) then
  4271. iidstr:=stringdup(''); { default is empty string }
  4272. end;
  4273. procedure tobjectdef.set_parent( c : tobjectdef);
  4274. begin
  4275. if assigned(childof) then
  4276. exit;
  4277. childof:=c;
  4278. if not assigned(c) then
  4279. exit;
  4280. { inherit options and status }
  4281. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  4282. { add the data of the anchestor class/object }
  4283. if (objecttype in [odt_class,odt_object,odt_objcclass]) then
  4284. begin
  4285. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  4286. { inherit recordalignment }
  4287. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  4288. { if both the parent and this record use C-alignment, also inherit
  4289. the current field alignment }
  4290. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  4291. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  4292. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  4293. { the padding is not inherited for Objective-C classes (maybe not
  4294. for cppclass either?) }
  4295. if objecttype=odt_objcclass then
  4296. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  4297. if (oo_has_vmt in objectoptions) and
  4298. (oo_has_vmt in c.objectoptions) then
  4299. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  4300. { if parent has a vmt field then the offset is the same for the child PM }
  4301. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4302. begin
  4303. vmt_offset:=c.vmt_offset;
  4304. include(objectoptions,oo_has_vmt);
  4305. end;
  4306. end;
  4307. end;
  4308. procedure tobjectdef.insertvmt;
  4309. var
  4310. vs: tfieldvarsym;
  4311. begin
  4312. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol] then
  4313. exit;
  4314. if (oo_has_vmt in objectoptions) then
  4315. internalerror(12345)
  4316. else
  4317. begin
  4318. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  4319. tObjectSymtable(symtable).fieldalignment);
  4320. if (tf_requires_proper_alignment in target_info.flags) then
  4321. begin
  4322. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  4323. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  4324. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  4325. end;
  4326. vs:=tfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  4327. hidesym(vs);
  4328. tObjectSymtable(symtable).insert(vs);
  4329. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  4330. if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  4331. vmt_offset:=vs.fieldoffset
  4332. else
  4333. vmt_offset:=vs.fieldoffset div 8;
  4334. include(objectoptions,oo_has_vmt);
  4335. end;
  4336. end;
  4337. procedure tobjectdef.check_forwards;
  4338. begin
  4339. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol]) then
  4340. inherited;
  4341. if (oo_is_forward in objectoptions) then
  4342. begin
  4343. { ok, in future, the forward can be resolved }
  4344. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4345. exclude(objectoptions,oo_is_forward);
  4346. end;
  4347. end;
  4348. { true if prot implements d (or if they are equal) }
  4349. function is_related_protocol(prot: tobjectdef; d : tdef) : boolean;
  4350. var
  4351. i : longint;
  4352. begin
  4353. { objcprotocols have multiple inheritance, all protocols from which
  4354. the current protocol inherits are stored in implementedinterfaces }
  4355. result:=prot=d;
  4356. if result then
  4357. exit;
  4358. for i:=0 to prot.ImplementedInterfaces.count-1 do
  4359. begin
  4360. result:=is_related_protocol(TImplementedInterface(prot.ImplementedInterfaces[i]).intfdef,d);
  4361. if result then
  4362. exit;
  4363. end;
  4364. end;
  4365. { true, if self inherits from d (or if they are equal) }
  4366. function tobjectdef.is_related(d : tdef) : boolean;
  4367. var
  4368. realself,
  4369. hp : tobjectdef;
  4370. begin
  4371. if self=d then
  4372. begin
  4373. is_related:=true;
  4374. exit;
  4375. end;
  4376. if (d.typ<>objectdef) then
  4377. begin
  4378. is_related:=false;
  4379. exit;
  4380. end;
  4381. realself:=find_real_objcclass_definition(self,false);
  4382. d:=find_real_objcclass_definition(tobjectdef(d),false);
  4383. { Objective-C protocols can use multiple inheritance }
  4384. if (realself.objecttype=odt_objcprotocol) then
  4385. begin
  4386. is_related:=is_related_protocol(realself,d);
  4387. exit
  4388. end;
  4389. { formally declared Objective-C classes match Objective-C classes with
  4390. the same name (still required even though we looked up the real
  4391. definitions above, because these may be two different formal
  4392. declarations) }
  4393. if (realself.objecttype=odt_objcclass) and
  4394. (tobjectdef(d).objecttype=odt_objcclass) and
  4395. ((oo_is_formal in objectoptions) or
  4396. (oo_is_formal in tobjectdef(d).objectoptions)) and
  4397. (objrealname^=tobjectdef(d).objrealname^) then
  4398. begin
  4399. is_related:=true;
  4400. exit;
  4401. end;
  4402. hp:=realself.childof;
  4403. while assigned(hp) do
  4404. begin
  4405. if hp=d then
  4406. begin
  4407. is_related:=true;
  4408. exit;
  4409. end;
  4410. hp:=hp.childof;
  4411. end;
  4412. is_related:=false;
  4413. end;
  4414. function tobjectdef.find_destructor: tprocdef;
  4415. var
  4416. objdef: tobjectdef;
  4417. begin
  4418. objdef:=self;
  4419. while assigned(objdef) do
  4420. begin
  4421. result:=objdef.find_procdef_bytype(potype_destructor);
  4422. if assigned(result) then
  4423. exit;
  4424. objdef:=objdef.childof;
  4425. end;
  4426. result:=nil;
  4427. end;
  4428. function tobjectdef.implements_any_interfaces: boolean;
  4429. begin
  4430. result := (ImplementedInterfaces.Count > 0) or
  4431. (assigned(childof) and childof.implements_any_interfaces);
  4432. end;
  4433. function tobjectdef.size : asizeint;
  4434. begin
  4435. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper] then
  4436. result:=sizeof(pint)
  4437. else
  4438. result:=tObjectSymtable(symtable).datasize;
  4439. end;
  4440. function tobjectdef.alignment:shortint;
  4441. begin
  4442. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper] then
  4443. alignment:=sizeof(pint)
  4444. else
  4445. alignment:=tObjectSymtable(symtable).recordalignment;
  4446. end;
  4447. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4448. begin
  4449. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4450. case objecttype of
  4451. odt_class:
  4452. { the +2*sizeof(pint) is size and -size }
  4453. vmtmethodoffset:=(index+10)*sizeof(pint)+2*sizeof(pint);
  4454. odt_helper,
  4455. odt_objcclass,
  4456. odt_objcprotocol:
  4457. vmtmethodoffset:=0;
  4458. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  4459. vmtmethodoffset:=index*sizeof(pint);
  4460. else
  4461. {$ifdef WITHDMT}
  4462. vmtmethodoffset:=(index+4)*sizeof(pint);
  4463. {$else WITHDMT}
  4464. vmtmethodoffset:=(index+3)*sizeof(pint);
  4465. {$endif WITHDMT}
  4466. end;
  4467. end;
  4468. function tobjectdef.vmt_mangledname : string;
  4469. begin
  4470. if not(oo_has_vmt in objectoptions) then
  4471. Message1(parser_n_object_has_no_vmt,objrealname^);
  4472. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4473. end;
  4474. function tobjectdef.needs_inittable : boolean;
  4475. begin
  4476. case objecttype of
  4477. odt_helper,
  4478. odt_class :
  4479. needs_inittable:=false;
  4480. odt_dispinterface,
  4481. odt_interfacecom:
  4482. needs_inittable:=true;
  4483. odt_interfacecorba:
  4484. needs_inittable:=is_related(interface_iunknown);
  4485. odt_object:
  4486. needs_inittable:=tObjectSymtable(symtable).needs_init_final;
  4487. odt_cppclass,
  4488. odt_objcclass,
  4489. odt_objcprotocol:
  4490. needs_inittable:=false;
  4491. else
  4492. internalerror(200108267);
  4493. end;
  4494. end;
  4495. function tobjectdef.rtti_mangledname(rt: trttitype): string;
  4496. begin
  4497. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  4498. result:=inherited rtti_mangledname(rt)
  4499. else
  4500. begin
  4501. { necessary in case of a dynamic array of nsobject, or
  4502. if an nsobject field appears in a record that needs
  4503. init/finalisation }
  4504. if rt=initrtti then
  4505. begin
  4506. result:=voidpointertype.rtti_mangledname(rt);
  4507. exit;
  4508. end;
  4509. if not(target_info.system in systems_objc_nfabi) then
  4510. begin
  4511. result:=target_asm.labelprefix;
  4512. case objecttype of
  4513. odt_objcclass:
  4514. begin
  4515. case rt of
  4516. objcclassrtti:
  4517. if not(oo_is_classhelper in objectoptions) then
  4518. result:=result+'_OBJC_CLASS_'
  4519. else
  4520. result:=result+'_OBJC_CATEGORY_';
  4521. objcmetartti:
  4522. if not(oo_is_classhelper in objectoptions) then
  4523. result:=result+'_OBJC_METACLASS_'
  4524. else
  4525. internalerror(2009111511);
  4526. else
  4527. internalerror(2009092302);
  4528. end;
  4529. end;
  4530. odt_objcprotocol:
  4531. result:=result+'_OBJC_PROTOCOL_';
  4532. end;
  4533. end
  4534. else
  4535. begin
  4536. case objecttype of
  4537. odt_objcclass:
  4538. begin
  4539. if (oo_is_classhelper in objectoptions) and
  4540. (rt<>objcclassrtti) then
  4541. internalerror(2009111512);
  4542. case rt of
  4543. objcclassrtti:
  4544. if not(oo_is_classhelper in objectoptions) then
  4545. result:='_OBJC_CLASS_$_'
  4546. else
  4547. result:='_OBJC_$_CATEGORY_';
  4548. objcmetartti:
  4549. result:='_OBJC_METACLASS_$_';
  4550. objcclassrortti:
  4551. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  4552. objcmetarortti:
  4553. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  4554. else
  4555. internalerror(2009092303);
  4556. end;
  4557. end;
  4558. odt_objcprotocol:
  4559. begin
  4560. result:=lower(target_asm.labelprefix);
  4561. case rt of
  4562. objcclassrtti:
  4563. result:=result+'_OBJC_PROTOCOL_$_';
  4564. objcmetartti:
  4565. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  4566. else
  4567. internalerror(2009092501);
  4568. end;
  4569. end;
  4570. end;
  4571. end;
  4572. result:=result+objextname^;
  4573. end;
  4574. end;
  4575. function tobjectdef.members_need_inittable : boolean;
  4576. begin
  4577. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  4578. end;
  4579. function tobjectdef.find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  4580. var
  4581. ImplIntf : TImplementedInterface;
  4582. i : longint;
  4583. begin
  4584. result:=nil;
  4585. if not assigned(ImplementedInterfaces) then
  4586. exit;
  4587. for i:=0 to ImplementedInterfaces.Count-1 do
  4588. begin
  4589. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  4590. if ImplIntf.intfdef=aintfdef then
  4591. begin
  4592. result:=ImplIntf;
  4593. exit;
  4594. end;
  4595. end;
  4596. end;
  4597. function tobjectdef.is_publishable : boolean;
  4598. begin
  4599. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  4600. end;
  4601. function tobjectdef.get_next_dispid: longint;
  4602. begin
  4603. inc(fcurrent_dispid);
  4604. result:=fcurrent_dispid;
  4605. end;
  4606. function tobjectdef.search_enumerator_get: tprocdef;
  4607. begin
  4608. result:=inherited;
  4609. if not assigned(result) and assigned(childof) then
  4610. result:=childof.search_enumerator_get;
  4611. end;
  4612. function tobjectdef.search_enumerator_move: tprocdef;
  4613. begin
  4614. result:=inherited;
  4615. if not assigned(result) and assigned(childof) then
  4616. result:=childof.search_enumerator_move;
  4617. end;
  4618. function tobjectdef.search_enumerator_current: tsym;
  4619. begin
  4620. result:=inherited;
  4621. if not assigned(result) and assigned(childof) then
  4622. result:=childof.search_enumerator_current;
  4623. end;
  4624. procedure tobjectdef.register_created_classref_type;
  4625. begin
  4626. if not classref_created_in_current_module then
  4627. begin
  4628. classref_created_in_current_module:=true;
  4629. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  4630. end;
  4631. end;
  4632. procedure tobjectdef.register_created_object_type;
  4633. begin
  4634. if not created_in_current_module then
  4635. begin
  4636. created_in_current_module:=true;
  4637. current_module.wpoinfo.addcreatedobjtype(self);
  4638. end;
  4639. end;
  4640. procedure tobjectdef.register_maybe_created_object_type;
  4641. begin
  4642. { if we know it has been created for sure, no need
  4643. to also record that it maybe can be created in
  4644. this module
  4645. }
  4646. if not (created_in_current_module) and
  4647. not (maybe_created_in_current_module) then
  4648. begin
  4649. maybe_created_in_current_module:=true;
  4650. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  4651. end;
  4652. end;
  4653. procedure tobjectdef.register_vmt_call(index: longint);
  4654. begin
  4655. if (is_object(self) or is_class(self)) then
  4656. current_module.wpoinfo.addcalledvmtentry(self,index);
  4657. end;
  4658. procedure check_and_finish_msg(data: tobject; arg: pointer);
  4659. var
  4660. def: tdef absolute data;
  4661. pd: tprocdef absolute data;
  4662. i,
  4663. paracount: longint;
  4664. begin
  4665. if (def.typ=procdef) then
  4666. begin
  4667. { add all messages also under a dummy name to the symtable in
  4668. which the objcclass/protocol/category is declared, so they can
  4669. be called via id.<name>
  4670. }
  4671. create_class_helper_for_procdef(pd,nil);
  4672. { we have to wait until now to set the mangled name because it
  4673. depends on the (possibly external) class name, which is defined
  4674. at the very end. }
  4675. if not(po_msgstr in pd.procoptions) then
  4676. begin
  4677. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  4678. { recover to avoid internalerror later on }
  4679. include(pd.procoptions,po_msgstr);
  4680. pd.messageinf.str:=stringdup('MissingDeclaration');
  4681. end;
  4682. { Mangled name is already set in case this is a copy of
  4683. another type. }
  4684. if not(po_has_mangledname in pd.procoptions) then
  4685. begin
  4686. { check whether the number of formal parameters is correct,
  4687. and whether they have valid Objective-C types }
  4688. paracount:=0;
  4689. for i:=1 to length(pd.messageinf.str^) do
  4690. if pd.messageinf.str^[i]=':' then
  4691. inc(paracount);
  4692. for i:=0 to pd.paras.count-1 do
  4693. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  4694. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  4695. dec(paracount);
  4696. if (paracount<>0) then
  4697. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  4698. pd.setmangledname(pd.objcmangledname);
  4699. end
  4700. else
  4701. { all checks already done }
  4702. exit;
  4703. if not(oo_is_external in pd.struct.objectoptions) then
  4704. begin
  4705. if (po_varargs in pd.procoptions) then
  4706. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  4707. else
  4708. begin
  4709. { check for "array of const" parameters }
  4710. for i:=0 to pd.parast.symlist.count-1 do
  4711. begin
  4712. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  4713. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  4714. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  4715. end;
  4716. end;
  4717. end;
  4718. end;
  4719. end;
  4720. procedure mark_private_fields_used(data: tobject; arg: pointer);
  4721. var
  4722. sym: tsym absolute data;
  4723. begin
  4724. if (sym.typ=fieldvarsym) and
  4725. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  4726. sym.IncRefCount;
  4727. end;
  4728. procedure tobjectdef.finish_objc_data;
  4729. begin
  4730. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  4731. if (oo_is_external in objectoptions) then
  4732. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  4733. end;
  4734. procedure verify_objc_vardef(data: tobject; arg: pointer);
  4735. var
  4736. sym: tabstractvarsym absolute data;
  4737. res: pboolean absolute arg;
  4738. founderrordef: tdef;
  4739. begin
  4740. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  4741. exit;
  4742. if (sym.typ=paravarsym) and
  4743. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  4744. is_array_of_const(tparavarsym(sym).vardef)) then
  4745. exit;
  4746. if not objcchecktype(sym.vardef,founderrordef) then
  4747. begin
  4748. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  4749. res^:=false;
  4750. end;
  4751. end;
  4752. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  4753. var
  4754. def: tdef absolute data;
  4755. res: pboolean absolute arg;
  4756. founderrordef: tdef;
  4757. begin
  4758. if (def.typ<>procdef) then
  4759. exit;
  4760. { check parameter types for validity }
  4761. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  4762. { check the result type for validity }
  4763. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  4764. begin
  4765. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  4766. res^:=false;
  4767. end;
  4768. end;
  4769. function tobjectdef.check_objc_types: boolean;
  4770. begin
  4771. { done in separate step from finish_objc_data, because when
  4772. finish_objc_data is called, not all forwarddefs have been resolved
  4773. yet and we need to know all types here }
  4774. result:=true;
  4775. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  4776. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  4777. end;
  4778. procedure do_cpp_import_info(data: tobject; arg: pointer);
  4779. var
  4780. def: tdef absolute data;
  4781. pd: tprocdef absolute data;
  4782. begin
  4783. if (def.typ=procdef) then
  4784. begin
  4785. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  4786. if (oo_is_external in pd.struct.objectoptions) then
  4787. begin
  4788. { copied from psub.read_proc }
  4789. if assigned(tobjectdef(pd.struct).import_lib) then
  4790. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  4791. else
  4792. begin
  4793. { add import name to external list for DLL scanning }
  4794. if tf_has_dllscanner in target_info.flags then
  4795. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  4796. end;
  4797. end;
  4798. end;
  4799. end;
  4800. procedure tobjectdef.finish_cpp_data;
  4801. begin
  4802. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  4803. end;
  4804. {****************************************************************************
  4805. TImplementedInterface
  4806. ****************************************************************************}
  4807. constructor TImplementedInterface.create(aintf: tobjectdef);
  4808. begin
  4809. inherited create;
  4810. intfdef:=aintf;
  4811. IOffset:=-1;
  4812. IType:=etStandard;
  4813. NameMappings:=nil;
  4814. procdefs:=nil;
  4815. end;
  4816. constructor TImplementedInterface.create_deref(d:tderef);
  4817. begin
  4818. inherited create;
  4819. intfdef:=nil;
  4820. intfdefderef:=d;
  4821. IOffset:=-1;
  4822. IType:=etStandard;
  4823. NameMappings:=nil;
  4824. procdefs:=nil;
  4825. end;
  4826. destructor TImplementedInterface.destroy;
  4827. var
  4828. i : longint;
  4829. mappedname : pshortstring;
  4830. begin
  4831. if assigned(NameMappings) then
  4832. begin
  4833. for i:=0 to NameMappings.Count-1 do
  4834. begin
  4835. mappedname:=pshortstring(NameMappings[i]);
  4836. stringdispose(mappedname);
  4837. end;
  4838. NameMappings.free;
  4839. NameMappings:=nil;
  4840. end;
  4841. if assigned(procdefs) then
  4842. begin
  4843. procdefs.free;
  4844. procdefs:=nil;
  4845. end;
  4846. inherited destroy;
  4847. end;
  4848. procedure TImplementedInterface.buildderef;
  4849. begin
  4850. intfdefderef.build(intfdef);
  4851. end;
  4852. procedure TImplementedInterface.deref;
  4853. begin
  4854. intfdef:=tobjectdef(intfdefderef.resolve);
  4855. end;
  4856. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  4857. begin
  4858. if not assigned(NameMappings) then
  4859. NameMappings:=TFPHashList.Create;
  4860. NameMappings.Add(origname,stringdup(newname));
  4861. end;
  4862. function TImplementedInterface.GetMapping(const origname: string):string;
  4863. var
  4864. mappedname : pshortstring;
  4865. begin
  4866. result:='';
  4867. if not assigned(NameMappings) then
  4868. exit;
  4869. mappedname:=PShortstring(NameMappings.Find(origname));
  4870. if assigned(mappedname) then
  4871. result:=mappedname^;
  4872. end;
  4873. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  4874. begin
  4875. if not assigned(procdefs) then
  4876. procdefs:=TFPObjectList.Create(false);
  4877. { duplicate entries must be stored, because multiple }
  4878. { interfaces can declare methods with the same name }
  4879. { and all of these get their own VMT entry }
  4880. procdefs.Add(pd);
  4881. end;
  4882. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  4883. var
  4884. i : longint;
  4885. begin
  4886. result:=false;
  4887. { interfaces being implemented through delegation are not mergable (FK) }
  4888. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  4889. exit;
  4890. weight:=0;
  4891. { empty interface is mergeable }
  4892. if ProcDefs.Count=0 then
  4893. begin
  4894. result:=true;
  4895. exit;
  4896. end;
  4897. { The interface to merge must at least the number of
  4898. procedures of this interface }
  4899. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  4900. exit;
  4901. for i:=0 to ProcDefs.Count-1 do
  4902. begin
  4903. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  4904. exit;
  4905. end;
  4906. weight:=ProcDefs.Count;
  4907. result:=true;
  4908. end;
  4909. function TImplementedInterface.getcopy:TImplementedInterface;
  4910. begin
  4911. Result:=TImplementedInterface.Create(nil);
  4912. { 1) the procdefs list will be freed once for each copy
  4913. 2) since the procdefs list owns its elements, those will also be freed for each copy
  4914. 3) idem for the name mappings
  4915. }
  4916. { warning: this is completely wrong on so many levels...
  4917. Move(pointer(self)^,pointer(result)^,InstanceSize);
  4918. We need to make clean copies of the different fields
  4919. this is not implemented yet, and thus we generate an internal
  4920. error instead PM 2011-06-14 }
  4921. internalerror(2011061401);
  4922. end;
  4923. {****************************************************************************
  4924. TFORWARDDEF
  4925. ****************************************************************************}
  4926. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  4927. begin
  4928. inherited create(forwarddef);
  4929. tosymname:=stringdup(s);
  4930. forwardpos:=pos;
  4931. end;
  4932. function tforwarddef.GetTypeName:string;
  4933. begin
  4934. GetTypeName:='unresolved forward to '+tosymname^;
  4935. end;
  4936. destructor tforwarddef.destroy;
  4937. begin
  4938. stringdispose(tosymname);
  4939. inherited destroy;
  4940. end;
  4941. function tforwarddef.getcopy:tstoreddef;
  4942. begin
  4943. result:=tforwarddef.create(tosymname^, forwardpos);
  4944. end;
  4945. {****************************************************************************
  4946. TUNDEFINEDDEF
  4947. ****************************************************************************}
  4948. constructor tundefineddef.create;
  4949. begin
  4950. inherited create(undefineddef);
  4951. end;
  4952. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  4953. begin
  4954. inherited ppuload(undefineddef,ppufile);
  4955. end;
  4956. function tundefineddef.GetTypeName:string;
  4957. begin
  4958. GetTypeName:='<undefined type>';
  4959. end;
  4960. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  4961. begin
  4962. inherited ppuwrite(ppufile);
  4963. ppufile.writeentry(ibundefineddef);
  4964. end;
  4965. {****************************************************************************
  4966. TERRORDEF
  4967. ****************************************************************************}
  4968. constructor terrordef.create;
  4969. begin
  4970. inherited create(errordef);
  4971. { prevent consecutive faults }
  4972. savesize:=1;
  4973. end;
  4974. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  4975. begin
  4976. { Can't write errordefs to ppu }
  4977. internalerror(200411063);
  4978. end;
  4979. function terrordef.GetTypeName:string;
  4980. begin
  4981. GetTypeName:='<erroneous type>';
  4982. end;
  4983. function terrordef.getmangledparaname:string;
  4984. begin
  4985. getmangledparaname:='error';
  4986. end;
  4987. {****************************************************************************
  4988. Definition Helpers
  4989. ****************************************************************************}
  4990. function is_interfacecom(def: tdef): boolean;
  4991. begin
  4992. is_interfacecom:=
  4993. assigned(def) and
  4994. (def.typ=objectdef) and
  4995. (tobjectdef(def).objecttype=odt_interfacecom);
  4996. end;
  4997. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  4998. begin
  4999. is_interfacecom_or_dispinterface:=
  5000. assigned(def) and
  5001. (def.typ=objectdef) and
  5002. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  5003. end;
  5004. function is_interfacecorba(def: tdef): boolean;
  5005. begin
  5006. is_interfacecorba:=
  5007. assigned(def) and
  5008. (def.typ=objectdef) and
  5009. (tobjectdef(def).objecttype=odt_interfacecorba);
  5010. end;
  5011. function is_interface(def: tdef): boolean;
  5012. begin
  5013. is_interface:=
  5014. assigned(def) and
  5015. (def.typ=objectdef) and
  5016. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5017. end;
  5018. function is_dispinterface(def: tdef): boolean;
  5019. begin
  5020. result:=
  5021. assigned(def) and
  5022. (def.typ=objectdef) and
  5023. (tobjectdef(def).objecttype=odt_dispinterface);
  5024. end;
  5025. function is_class(def: tdef): boolean;
  5026. begin
  5027. is_class:=
  5028. assigned(def) and
  5029. (def.typ=objectdef) and
  5030. (tobjectdef(def).objecttype=odt_class);
  5031. end;
  5032. function is_object(def: tdef): boolean;
  5033. begin
  5034. is_object:=
  5035. assigned(def) and
  5036. (def.typ=objectdef) and
  5037. (tobjectdef(def).objecttype=odt_object);
  5038. end;
  5039. function is_cppclass(def: tdef): boolean;
  5040. begin
  5041. is_cppclass:=
  5042. assigned(def) and
  5043. (def.typ=objectdef) and
  5044. (tobjectdef(def).objecttype=odt_cppclass);
  5045. end;
  5046. function is_objcclass(def: tdef): boolean;
  5047. begin
  5048. is_objcclass:=
  5049. assigned(def) and
  5050. (def.typ=objectdef) and
  5051. (tobjectdef(def).objecttype=odt_objcclass);
  5052. end;
  5053. function is_objectpascal_helper(def: tdef): boolean;
  5054. begin
  5055. result:=
  5056. assigned(def) and
  5057. (def.typ=objectdef) and
  5058. (tobjectdef(def).objecttype=odt_helper);
  5059. end;
  5060. function is_objcclassref(def: tdef): boolean;
  5061. begin
  5062. is_objcclassref:=
  5063. assigned(def) and
  5064. (def.typ=classrefdef) and
  5065. is_objcclass(tclassrefdef(def).pointeddef);
  5066. end;
  5067. function is_objcprotocol(def: tdef): boolean;
  5068. begin
  5069. result:=
  5070. assigned(def) and
  5071. (def.typ=objectdef) and
  5072. (tobjectdef(def).objecttype=odt_objcprotocol);
  5073. end;
  5074. function is_objccategory(def: tdef): boolean;
  5075. begin
  5076. result:=
  5077. assigned(def) and
  5078. (def.typ=objectdef) and
  5079. { if used as a forward type }
  5080. ((tobjectdef(def).objecttype=odt_objccategory) or
  5081. { if used as after it has been resolved }
  5082. ((tobjectdef(def).objecttype=odt_objcclass) and
  5083. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  5084. end;
  5085. function is_objc_class_or_protocol(def: tdef): boolean;
  5086. begin
  5087. result:=
  5088. assigned(def) and
  5089. (def.typ=objectdef) and
  5090. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  5091. end;
  5092. function is_objc_protocol_or_category(def: tdef): boolean;
  5093. begin
  5094. result:=
  5095. assigned(def) and
  5096. (def.typ=objectdef) and
  5097. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  5098. ((tobjectdef(def).objecttype = odt_objcclass) and
  5099. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  5100. end;
  5101. function is_classhelper(def: tdef): boolean;
  5102. begin
  5103. result:=
  5104. is_objectpascal_helper(def) or
  5105. is_objccategory(def);
  5106. end;
  5107. function is_class_or_interface(def: tdef): boolean;
  5108. begin
  5109. result:=
  5110. assigned(def) and
  5111. (def.typ=objectdef) and
  5112. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5113. end;
  5114. function is_class_or_interface_or_objc(def: tdef): boolean;
  5115. begin
  5116. result:=
  5117. assigned(def) and
  5118. (def.typ=objectdef) and
  5119. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  5120. end;
  5121. function is_class_or_interface_or_object(def: tdef): boolean;
  5122. begin
  5123. result:=
  5124. assigned(def) and
  5125. (def.typ=objectdef) and
  5126. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  5127. end;
  5128. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  5129. begin
  5130. result:=
  5131. assigned(def) and
  5132. (def.typ=objectdef) and
  5133. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5134. end;
  5135. function is_implicit_pointer_object_type(def: tdef): boolean;
  5136. begin
  5137. result:=
  5138. assigned(def) and
  5139. (def.typ=objectdef) and
  5140. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper]);
  5141. end;
  5142. function is_class_or_object(def: tdef): boolean;
  5143. begin
  5144. result:=
  5145. assigned(def) and
  5146. (def.typ=objectdef) and
  5147. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  5148. end;
  5149. function is_record(def: tdef): boolean;
  5150. begin
  5151. result:=
  5152. assigned(def) and
  5153. (def.typ=recorddef);
  5154. end;
  5155. procedure loadobjctypes;
  5156. begin
  5157. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  5158. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  5159. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  5160. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  5161. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  5162. end;
  5163. procedure maybeloadcocoatypes;
  5164. var
  5165. tsym: ttypesym;
  5166. begin
  5167. if assigned(objc_fastenumeration) then
  5168. exit;
  5169. tsym:=search_named_unit_globaltype('COCOAALL','NSFASTENUMERATIONPROTOCOL',false);
  5170. if assigned(tsym) then
  5171. objc_fastenumeration:=tobjectdef(tsym.typedef)
  5172. else
  5173. objc_fastenumeration:=nil;
  5174. tsym:=search_named_unit_globaltype('COCOAALL','NSFASTENUMERATIONSTATE',false);
  5175. if assigned(tsym) then
  5176. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  5177. else
  5178. objc_fastenumerationstate:=nil;
  5179. end;
  5180. function use_vectorfpu(def : tdef) : boolean;
  5181. begin
  5182. {$ifdef x86}
  5183. {$define use_vectorfpuimplemented}
  5184. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  5185. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  5186. {$endif x86}
  5187. {$ifdef arm}
  5188. {$define use_vectorfpuimplemented}
  5189. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  5190. {$endif arm}
  5191. {$ifndef use_vectorfpuimplemented}
  5192. use_vectorfpu:=false;
  5193. {$endif}
  5194. end;
  5195. end.