symdef.pas 185 KB

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