symdef.pas 193 KB

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