symdef.pas 185 KB

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