symdef.pas 188 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symdef;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,globals,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,
  28. { ppu }
  29. ppu,
  30. { node }
  31. node,
  32. { aasm }
  33. aasmbase,aasmtai,
  34. cpubase,cpuinfo,
  35. cgbase
  36. {$ifdef Delphi}
  37. ,dmisc
  38. {$endif}
  39. ;
  40. type
  41. {************************************************
  42. TDef
  43. ************************************************}
  44. tstoreddef = class(tdef)
  45. protected
  46. typesymderef : tderef;
  47. public
  48. { persistent (available across units) rtti and init tables }
  49. rttitablesym,
  50. inittablesym : tsym; {trttisym}
  51. rttitablesymderef,
  52. inittablesymderef : tderef;
  53. { local (per module) rtti and init tables }
  54. localrttilab : array[trttitype] of tasmlabel;
  55. { linked list of global definitions }
  56. {$ifdef EXTDEBUG}
  57. fileinfo : tfileposinfo;
  58. {$endif}
  59. {$ifdef GDB}
  60. globalnb : word;
  61. stab_state : tdefstabstatus;
  62. {$endif GDB}
  63. constructor create;
  64. constructor ppuloaddef(ppufile:tcompilerppufile);
  65. procedure reset;
  66. function getcopy : tstoreddef;virtual;
  67. procedure ppuwritedef(ppufile:tcompilerppufile);
  68. procedure ppuwrite(ppufile:tcompilerppufile);virtual;abstract;
  69. procedure buildderef;override;
  70. procedure buildderefimpl;override;
  71. procedure deref;override;
  72. procedure derefimpl;override;
  73. function size:longint;override;
  74. function alignment:longint;override;
  75. function is_publishable : boolean;override;
  76. function needs_inittable : boolean;override;
  77. { debug }
  78. {$ifdef GDB}
  79. function get_var_value(const s:string):string;
  80. function stabstr_evaluate(const s:string;const vars:array of string):Pchar;
  81. function stabstring : pchar;virtual;
  82. procedure concatstabto(asmlist : taasmoutput);virtual;
  83. function numberstring:string;virtual;
  84. procedure set_globalnb;virtual;
  85. function allstabstring : pchar;virtual;
  86. {$endif GDB}
  87. { rtti generation }
  88. procedure write_rtti_name;
  89. procedure write_rtti_data(rt:trttitype);virtual;
  90. procedure write_child_rtti_data(rt:trttitype);virtual;
  91. function get_rtti_label(rt:trttitype):tasmsymbol;
  92. { regvars }
  93. function is_intregable : boolean;
  94. function is_fpuregable : boolean;
  95. private
  96. savesize : longint;
  97. end;
  98. tparaitem = class(TLinkedListItem)
  99. paratype : ttype; { required for procvar }
  100. parasym : tsym;
  101. parasymderef : tderef;
  102. defaultvalue : tsym; { tconstsym }
  103. defaultvaluederef : tderef;
  104. paratyp : tvarspez; { required for procvar }
  105. paraloc : array[tcallercallee] of tparalocation;
  106. is_hidden : boolean; { is this a hidden (implicit) parameter }
  107. {$ifdef EXTDEBUG}
  108. eqval : tequaltype;
  109. {$endif EXTDEBUG}
  110. end;
  111. tfiletyp = (ft_text,ft_typed,ft_untyped);
  112. tfiledef = class(tstoreddef)
  113. filetyp : tfiletyp;
  114. typedfiletype : ttype;
  115. constructor createtext;
  116. constructor createuntyped;
  117. constructor createtyped(const tt : ttype);
  118. constructor ppuload(ppufile:tcompilerppufile);
  119. procedure ppuwrite(ppufile:tcompilerppufile);override;
  120. procedure buildderef;override;
  121. procedure deref;override;
  122. function gettypename:string;override;
  123. function getmangledparaname:string;override;
  124. procedure setsize;
  125. { debug }
  126. {$ifdef GDB}
  127. function stabstring : pchar;override;
  128. procedure concatstabto(asmlist : taasmoutput);override;
  129. {$endif GDB}
  130. end;
  131. tvariantdef = class(tstoreddef)
  132. varianttype : tvarianttype;
  133. constructor create(v : tvarianttype);
  134. constructor ppuload(ppufile:tcompilerppufile);
  135. function gettypename:string;override;
  136. procedure ppuwrite(ppufile:tcompilerppufile);override;
  137. procedure setsize;
  138. function needs_inittable : boolean;override;
  139. procedure write_rtti_data(rt:trttitype);override;
  140. {$ifdef GDB}
  141. function numberstring:string;override;
  142. function stabstring : pchar;override;
  143. procedure concatstabto(asmlist : taasmoutput);override;
  144. {$endif GDB}
  145. end;
  146. tformaldef = class(tstoreddef)
  147. constructor create;
  148. constructor ppuload(ppufile:tcompilerppufile);
  149. procedure ppuwrite(ppufile:tcompilerppufile);override;
  150. function gettypename:string;override;
  151. {$ifdef GDB}
  152. function numberstring:string;override;
  153. function stabstring : pchar;override;
  154. procedure concatstabto(asmlist : taasmoutput);override;
  155. {$endif GDB}
  156. end;
  157. tforwarddef = class(tstoreddef)
  158. tosymname : pstring;
  159. forwardpos : tfileposinfo;
  160. constructor create(const s:string;const pos : tfileposinfo);
  161. destructor destroy;override;
  162. function gettypename:string;override;
  163. end;
  164. terrordef = class(tstoreddef)
  165. constructor create;
  166. function gettypename:string;override;
  167. function getmangledparaname : string;override;
  168. { debug }
  169. {$ifdef GDB}
  170. function stabstring : pchar;override;
  171. procedure concatstabto(asmlist : taasmoutput);override;
  172. {$endif GDB}
  173. end;
  174. { tpointerdef and tclassrefdef should get a common
  175. base class, but I derived tclassrefdef from tpointerdef
  176. to avoid problems with bugs (FK)
  177. }
  178. tpointerdef = class(tstoreddef)
  179. pointertype : ttype;
  180. is_far : boolean;
  181. constructor create(const tt : ttype);
  182. constructor createfar(const tt : ttype);
  183. constructor ppuload(ppufile:tcompilerppufile);
  184. procedure ppuwrite(ppufile:tcompilerppufile);override;
  185. procedure buildderef;override;
  186. procedure deref;override;
  187. function gettypename:string;override;
  188. { debug }
  189. {$ifdef GDB}
  190. function stabstring : pchar;override;
  191. procedure concatstabto(asmlist : taasmoutput);override;
  192. {$endif GDB}
  193. end;
  194. Trecord_stabgen_state=record
  195. stabstring:Pchar;
  196. stabsize,staballoc,recoffset:integer;
  197. end;
  198. tabstractrecorddef= class(tstoreddef)
  199. private
  200. Count : integer;
  201. FRTTIType : trttitype;
  202. {$ifdef GDB}
  203. procedure field_addname(p:Tnamedindexitem;arg:pointer);
  204. procedure field_concatstabto(p:Tnamedindexitem;arg:pointer);
  205. {$endif}
  206. procedure count_field_rtti(sym : tnamedindexitem;arg:pointer);
  207. procedure write_field_rtti(sym : tnamedindexitem;arg:pointer);
  208. procedure generate_field_rtti(sym : tnamedindexitem;arg:pointer);
  209. public
  210. symtable : tsymtable;
  211. function getsymtable(t:tgetsymtable):tsymtable;override;
  212. end;
  213. trecorddef = class(tabstractrecorddef)
  214. public
  215. isunion : boolean;
  216. constructor create(p : tsymtable);
  217. constructor ppuload(ppufile:tcompilerppufile);
  218. destructor destroy;override;
  219. procedure ppuwrite(ppufile:tcompilerppufile);override;
  220. procedure buildderef;override;
  221. procedure deref;override;
  222. function size:longint;override;
  223. function alignment : longint;override;
  224. function gettypename:string;override;
  225. { debug }
  226. {$ifdef GDB}
  227. function stabstring : pchar;override;
  228. procedure concatstabto(asmlist:taasmoutput);override;
  229. {$endif GDB}
  230. function needs_inittable : boolean;override;
  231. { rtti }
  232. procedure write_child_rtti_data(rt:trttitype);override;
  233. procedure write_rtti_data(rt:trttitype);override;
  234. end;
  235. tprocdef = class;
  236. timplementedinterfaces = class;
  237. tobjectdef = class(tabstractrecorddef)
  238. private
  239. {$ifdef GDB}
  240. procedure proc_addname(p :tnamedindexitem;arg:pointer);
  241. procedure proc_concatstabto(p :tnamedindexitem;arg:pointer);
  242. {$endif GDB}
  243. procedure count_published_properties(sym:tnamedindexitem;arg:pointer);
  244. procedure write_property_info(sym : tnamedindexitem;arg:pointer);
  245. procedure generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  246. procedure count_published_fields(sym:tnamedindexitem;arg:pointer);
  247. procedure writefields(sym:tnamedindexitem;arg:pointer);
  248. public
  249. childof : tobjectdef;
  250. childofderef : tderef;
  251. objname,
  252. objrealname : pstring;
  253. objectoptions : tobjectoptions;
  254. { to be able to have a variable vmt position }
  255. { and no vmt field for objects without virtuals }
  256. vmt_offset : longint;
  257. {$ifdef GDB}
  258. writing_class_record_stab : boolean;
  259. {$endif GDB}
  260. objecttype : tobjectdeftype;
  261. iidguid: pguid;
  262. iidstr: pstring;
  263. lastvtableindex: longint;
  264. { store implemented interfaces defs and name mappings }
  265. implementedinterfaces: timplementedinterfaces;
  266. constructor create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  267. constructor ppuload(ppufile:tcompilerppufile);
  268. destructor destroy;override;
  269. procedure ppuwrite(ppufile:tcompilerppufile);override;
  270. function gettypename:string;override;
  271. procedure buildderef;override;
  272. procedure deref;override;
  273. function getparentdef:tdef;override;
  274. function size : longint;override;
  275. function alignment:longint;override;
  276. function vmtmethodoffset(index:longint):longint;
  277. function members_need_inittable : boolean;
  278. { this should be called when this class implements an interface }
  279. procedure prepareguid;
  280. function is_publishable : boolean;override;
  281. function needs_inittable : boolean;override;
  282. function vmt_mangledname : string;
  283. function rtti_name : string;
  284. procedure check_forwards;
  285. function is_related(d : tobjectdef) : boolean;
  286. function next_free_name_index : longint;
  287. procedure insertvmt;
  288. procedure set_parent(c : tobjectdef);
  289. function searchdestructor : tprocdef;
  290. { debug }
  291. {$ifdef GDB}
  292. function stabstring : pchar;override;
  293. procedure set_globalnb;override;
  294. function classnumberstring : string;
  295. procedure concatstabto(asmlist : taasmoutput);override;
  296. function allstabstring : pchar;override;
  297. {$endif GDB}
  298. { rtti }
  299. procedure write_child_rtti_data(rt:trttitype);override;
  300. procedure write_rtti_data(rt:trttitype);override;
  301. function generate_field_table : tasmlabel;
  302. end;
  303. timplementedinterfaces = class
  304. constructor create;
  305. destructor destroy; override;
  306. function count: longint;
  307. function interfaces(intfindex: longint): tobjectdef;
  308. function interfacesderef(intfindex: longint): tderef;
  309. function ioffsets(intfindex: longint): plongint;
  310. function searchintf(def: tdef): longint;
  311. procedure addintf(def: tdef);
  312. procedure buildderef;
  313. procedure deref;
  314. { add interface reference loaded from ppu }
  315. procedure addintf_deref(const d:tderef);
  316. procedure clearmappings;
  317. procedure addmappings(intfindex: longint; const name, newname: string);
  318. function getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  319. procedure clearimplprocs;
  320. procedure addimplproc(intfindex: longint; procdef: tprocdef);
  321. function implproccount(intfindex: longint): longint;
  322. function implprocs(intfindex: longint; procindex: longint): tprocdef;
  323. function isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  324. private
  325. finterfaces: tindexarray;
  326. procedure checkindex(intfindex: longint);
  327. end;
  328. tclassrefdef = class(tpointerdef)
  329. constructor create(const t:ttype);
  330. constructor ppuload(ppufile:tcompilerppufile);
  331. procedure ppuwrite(ppufile:tcompilerppufile);override;
  332. function gettypename:string;override;
  333. { debug }
  334. {$ifdef GDB}
  335. function stabstring : pchar;override;
  336. {$endif GDB}
  337. end;
  338. tarraydef = class(tstoreddef)
  339. lowrange,
  340. highrange : longint;
  341. rangetype : ttype;
  342. IsConvertedPointer,
  343. IsDynamicArray,
  344. IsVariant,
  345. IsConstructor,
  346. IsArrayOfConst : boolean;
  347. protected
  348. _elementtype : ttype;
  349. public
  350. function elesize : longint;
  351. constructor create_from_pointer(const elemt : ttype);
  352. constructor create(l,h : longint;const t : ttype);
  353. constructor ppuload(ppufile:tcompilerppufile);
  354. procedure ppuwrite(ppufile:tcompilerppufile);override;
  355. function gettypename:string;override;
  356. function getmangledparaname : string;override;
  357. procedure setelementtype(t: ttype);
  358. {$ifdef GDB}
  359. function stabstring : pchar;override;
  360. procedure concatstabto(asmlist : taasmoutput);override;
  361. {$endif GDB}
  362. procedure buildderef;override;
  363. procedure deref;override;
  364. function size : longint;override;
  365. function alignment : longint;override;
  366. { returns the label of the range check string }
  367. function needs_inittable : boolean;override;
  368. procedure write_child_rtti_data(rt:trttitype);override;
  369. procedure write_rtti_data(rt:trttitype);override;
  370. property elementtype : ttype Read _ElementType;
  371. end;
  372. torddef = class(tstoreddef)
  373. low,high : TConstExprInt;
  374. typ : tbasetype;
  375. constructor create(t : tbasetype;v,b : TConstExprInt);
  376. constructor ppuload(ppufile:tcompilerppufile);
  377. function getcopy : tstoreddef;override;
  378. procedure ppuwrite(ppufile:tcompilerppufile);override;
  379. function is_publishable : boolean;override;
  380. function gettypename:string;override;
  381. procedure setsize;
  382. { debug }
  383. {$ifdef GDB}
  384. function stabstring : pchar;override;
  385. {$endif GDB}
  386. { rtti }
  387. procedure write_rtti_data(rt:trttitype);override;
  388. end;
  389. tfloatdef = class(tstoreddef)
  390. typ : tfloattype;
  391. constructor create(t : tfloattype);
  392. constructor ppuload(ppufile:tcompilerppufile);
  393. function getcopy : tstoreddef;override;
  394. procedure ppuwrite(ppufile:tcompilerppufile);override;
  395. function gettypename:string;override;
  396. function is_publishable : boolean;override;
  397. procedure setsize;
  398. { debug }
  399. {$ifdef GDB}
  400. function stabstring : pchar;override;
  401. procedure concatstabto(asmlist:taasmoutput);override;
  402. {$endif GDB}
  403. { rtti }
  404. procedure write_rtti_data(rt:trttitype);override;
  405. end;
  406. tabstractprocdef = class(tstoreddef)
  407. { saves a definition to the return type }
  408. rettype : ttype;
  409. parast : tsymtable;
  410. para : tlinkedlist;
  411. proctypeoption : tproctypeoption;
  412. proccalloption : tproccalloption;
  413. procoptions : tprocoptions;
  414. requiredargarea : aint;
  415. maxparacount,
  416. minparacount : byte;
  417. {$ifdef i386}
  418. fpu_used : byte; { how many stack fpu must be empty }
  419. {$endif i386}
  420. funcret_paraloc : array[tcallercallee] of tparalocation;
  421. has_paraloc_info : boolean; { paraloc info is available }
  422. constructor create(level:byte);
  423. constructor ppuload(ppufile:tcompilerppufile);
  424. destructor destroy;override;
  425. procedure ppuwrite(ppufile:tcompilerppufile);override;
  426. procedure buildderef;override;
  427. procedure deref;override;
  428. procedure releasemem;
  429. function concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  430. function insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  431. procedure removepara(currpara:tparaitem);
  432. function typename_paras(showhidden:boolean): string;
  433. procedure test_if_fpu_result;
  434. function is_methodpointer:boolean;virtual;
  435. function is_addressonly:boolean;virtual;
  436. { debug }
  437. {$ifdef GDB}
  438. function stabstring : pchar;override;
  439. {$endif GDB}
  440. end;
  441. tprocvardef = class(tabstractprocdef)
  442. constructor create(level:byte);
  443. constructor ppuload(ppufile:tcompilerppufile);
  444. procedure ppuwrite(ppufile:tcompilerppufile);override;
  445. procedure buildderef;override;
  446. procedure deref;override;
  447. function getsymtable(t:tgetsymtable):tsymtable;override;
  448. function size : longint;override;
  449. function gettypename:string;override;
  450. function is_publishable : boolean;override;
  451. function is_methodpointer:boolean;override;
  452. function is_addressonly:boolean;override;
  453. { debug }
  454. {$ifdef GDB}
  455. function stabstring : pchar;override;
  456. procedure concatstabto(asmlist:taasmoutput);override;
  457. {$endif GDB}
  458. { rtti }
  459. procedure write_rtti_data(rt:trttitype);override;
  460. end;
  461. tmessageinf = record
  462. case integer of
  463. 0 : (str : pchar);
  464. 1 : (i : longint);
  465. end;
  466. tinlininginfo = record
  467. { node tree }
  468. code : tnode;
  469. flags : tprocinfoflags;
  470. end;
  471. pinlininginfo = ^tinlininginfo;
  472. {$ifdef oldregvars}
  473. { register variables }
  474. pregvarinfo = ^tregvarinfo;
  475. tregvarinfo = record
  476. regvars : array[1..maxvarregs] of tsym;
  477. regvars_para : array[1..maxvarregs] of boolean;
  478. regvars_refs : array[1..maxvarregs] of longint;
  479. fpuregvars : array[1..maxfpuvarregs] of tsym;
  480. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  481. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  482. end;
  483. {$endif oldregvars}
  484. tprocdef = class(tabstractprocdef)
  485. private
  486. _mangledname : pstring;
  487. {$ifdef GDB}
  488. isstabwritten : boolean;
  489. {$endif GDB}
  490. public
  491. extnumber : word;
  492. overloadnumber : word;
  493. messageinf : tmessageinf;
  494. {$ifndef EXTDEBUG}
  495. { where is this function defined and what were the symbol
  496. flags, needed here because there
  497. is only one symbol for all overloaded functions
  498. EXTDEBUG has fileinfo in tdef (PFV) }
  499. fileinfo : tfileposinfo;
  500. {$endif}
  501. symoptions : tsymoptions;
  502. { symbol owning this definition }
  503. procsym : tsym;
  504. procsymderef : tderef;
  505. { alias names }
  506. aliasnames : tstringlist;
  507. { symtables }
  508. localst : tsymtable;
  509. funcretsym : tsym;
  510. funcretsymderef : tderef;
  511. { browser info }
  512. lastref,
  513. defref,
  514. lastwritten : tref;
  515. refcount : longint;
  516. _class : tobjectdef;
  517. _classderef : tderef;
  518. {$ifdef powerpc}
  519. { library symbol for AmigaOS/MorphOS }
  520. libsym : tsym;
  521. libsymderef : tderef;
  522. {$endif powerpc}
  523. { name of the result variable to insert in the localsymtable }
  524. resultname : stringid;
  525. { true, if the procedure is only declared
  526. (forward procedure) }
  527. forwarddef,
  528. { true if the procedure is declared in the interface }
  529. interfacedef : boolean;
  530. { true if the procedure has a forward declaration }
  531. hasforward : boolean;
  532. { check the problems of manglednames }
  533. has_mangledname : boolean;
  534. { info for inlining the subroutine, if this pointer is nil,
  535. the procedure can't be inlined }
  536. inlininginfo : pinlininginfo;
  537. {$ifdef oldregvars}
  538. regvarinfo: pregvarinfo;
  539. {$endif oldregvars}
  540. constructor create(level:byte);
  541. constructor ppuload(ppufile:tcompilerppufile);
  542. destructor destroy;override;
  543. procedure ppuwrite(ppufile:tcompilerppufile);override;
  544. procedure buildderef;override;
  545. procedure buildderefimpl;override;
  546. procedure deref;override;
  547. procedure derefimpl;override;
  548. function getsymtable(t:tgetsymtable):tsymtable;override;
  549. function gettypename : string;override;
  550. function mangledname : string;
  551. procedure setmangledname(const s : string);
  552. procedure load_references(ppufile:tcompilerppufile;locals:boolean);
  553. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  554. { inserts the local symbol table, if this is not
  555. no local symbol table is built. Should be called only
  556. when we are sure that a local symbol table will be required.
  557. }
  558. procedure insert_localst;
  559. function fullprocname(showhidden:boolean):string;
  560. function cplusplusmangledname : string;
  561. function is_methodpointer:boolean;override;
  562. function is_addressonly:boolean;override;
  563. function is_visible_for_object(currobjdef:tobjectdef):boolean;
  564. { debug }
  565. {$ifdef GDB}
  566. function numberstring:string;override;
  567. function stabstring : pchar;override;
  568. procedure concatstabto(asmlist : taasmoutput);override;
  569. {$endif GDB}
  570. end;
  571. { single linked list of overloaded procs }
  572. pprocdeflist = ^tprocdeflist;
  573. tprocdeflist = record
  574. def : tprocdef;
  575. defderef : tderef;
  576. own : boolean;
  577. next : pprocdeflist;
  578. end;
  579. tstringdef = class(tstoreddef)
  580. string_typ : tstringtype;
  581. len : longint;
  582. constructor createshort(l : byte);
  583. constructor loadshort(ppufile:tcompilerppufile);
  584. constructor createlong(l : longint);
  585. constructor loadlong(ppufile:tcompilerppufile);
  586. {$ifdef ansistring_bits}
  587. constructor createansi(l:longint;bits:Tstringbits);
  588. constructor loadansi(ppufile:tcompilerppufile;bits:Tstringbits);
  589. {$else}
  590. constructor createansi(l : longint);
  591. constructor loadansi(ppufile:tcompilerppufile);
  592. {$endif}
  593. constructor createwide(l : longint);
  594. constructor loadwide(ppufile:tcompilerppufile);
  595. function getcopy : tstoreddef;override;
  596. function stringtypname:string;
  597. function size : longint;override;
  598. procedure ppuwrite(ppufile:tcompilerppufile);override;
  599. function gettypename:string;override;
  600. function getmangledparaname:string;override;
  601. function is_publishable : boolean;override;
  602. { debug }
  603. {$ifdef GDB}
  604. function stabstring : pchar;override;
  605. procedure concatstabto(asmlist : taasmoutput);override;
  606. {$endif GDB}
  607. { init/final }
  608. function needs_inittable : boolean;override;
  609. { rtti }
  610. procedure write_rtti_data(rt:trttitype);override;
  611. end;
  612. tenumdef = class(tstoreddef)
  613. minval,
  614. maxval : longint;
  615. has_jumps : boolean;
  616. firstenum : tsym; {tenumsym}
  617. basedef : tenumdef;
  618. basedefderef : tderef;
  619. constructor create;
  620. constructor create_subrange(_basedef:tenumdef;_min,_max:longint);
  621. constructor ppuload(ppufile:tcompilerppufile);
  622. destructor destroy;override;
  623. procedure ppuwrite(ppufile:tcompilerppufile);override;
  624. procedure buildderef;override;
  625. procedure deref;override;
  626. function gettypename:string;override;
  627. function is_publishable : boolean;override;
  628. procedure calcsavesize;
  629. procedure setmax(_max:longint);
  630. procedure setmin(_min:longint);
  631. function min:longint;
  632. function max:longint;
  633. { debug }
  634. {$ifdef GDB}
  635. function stabstring : pchar;override;
  636. {$endif GDB}
  637. { rtti }
  638. procedure write_rtti_data(rt:trttitype);override;
  639. procedure write_child_rtti_data(rt:trttitype);override;
  640. private
  641. procedure correct_owner_symtable;
  642. end;
  643. tsetdef = class(tstoreddef)
  644. elementtype : ttype;
  645. settype : tsettype;
  646. constructor create(const t:ttype;high : longint);
  647. constructor ppuload(ppufile:tcompilerppufile);
  648. destructor destroy;override;
  649. procedure ppuwrite(ppufile:tcompilerppufile);override;
  650. procedure buildderef;override;
  651. procedure deref;override;
  652. function gettypename:string;override;
  653. function is_publishable : boolean;override;
  654. { debug }
  655. {$ifdef GDB}
  656. function stabstring : pchar;override;
  657. procedure concatstabto(asmlist : taasmoutput);override;
  658. {$endif GDB}
  659. { rtti }
  660. procedure write_rtti_data(rt:trttitype);override;
  661. procedure write_child_rtti_data(rt:trttitype);override;
  662. end;
  663. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  664. var
  665. aktobjectdef : tobjectdef; { used for private functions check !! }
  666. {$ifdef GDB}
  667. writing_def_stabs : boolean;
  668. { for STAB debugging }
  669. globaltypecount : word;
  670. pglobaltypecount : pword;
  671. {$endif GDB}
  672. { default types }
  673. generrortype, { error in definition }
  674. voidpointertype, { pointer for Void-Pointerdef }
  675. charpointertype, { pointer for Char-Pointerdef }
  676. voidfarpointertype,
  677. cformaltype, { unique formal definition }
  678. voidtype, { Void (procedure) }
  679. cchartype, { Char }
  680. cwidechartype, { WideChar }
  681. booltype, { boolean type }
  682. u8inttype, { 8-Bit unsigned integer }
  683. s8inttype, { 8-Bit signed integer }
  684. u16inttype, { 16-Bit unsigned integer }
  685. s16inttype, { 16-Bit signed integer }
  686. u32inttype, { 32-Bit unsigned integer }
  687. s32inttype, { 32-Bit signed integer }
  688. u64inttype, { 64-bit unsigned integer }
  689. s64inttype, { 64-bit signed integer }
  690. s32floattype, { pointer for realconstn }
  691. s64floattype, { pointer for realconstn }
  692. s80floattype, { pointer to type of temp. floats }
  693. s64currencytype, { pointer to a currency type }
  694. s32fixedtype, { pointer to type of temp. fixed }
  695. cshortstringtype, { pointer to type of short string const }
  696. clongstringtype, { pointer to type of long string const }
  697. {$ifdef ansistring_bits}
  698. cansistringtype16, { pointer to type of ansi string const }
  699. cansistringtype32, { pointer to type of ansi string const }
  700. cansistringtype64, { pointer to type of ansi string const }
  701. {$else}
  702. cansistringtype, { pointer to type of ansi string const }
  703. {$endif}
  704. cwidestringtype, { pointer to type of wide string const }
  705. openshortstringtype, { pointer to type of an open shortstring,
  706. needed for readln() }
  707. openchararraytype, { pointer to type of an open array of char,
  708. needed for readln() }
  709. cfiletype, { get the same definition for all file }
  710. { used for stabs }
  711. methodpointertype, { typecasting of methodpointers to extract self }
  712. { we use only one variant def for every variant class }
  713. cvarianttype,
  714. colevarianttype,
  715. ordpointertype,
  716. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  717. sinttype,
  718. uinttype,
  719. { unsigned ord type with the same size as a pointer }
  720. ptrinttype,
  721. { several types to simulate more or less C++ objects for GDB }
  722. vmttype,
  723. vmtarraytype,
  724. pvmttype : ttype; { type of classrefs, used for stabs }
  725. { pointer to the anchestor of all classes }
  726. class_tobject : tobjectdef;
  727. { pointer to the ancestor of all COM interfaces }
  728. interface_iunknown : tobjectdef;
  729. { pointer to the TGUID type
  730. of all interfaces }
  731. rec_tguid : trecorddef;
  732. const
  733. {$ifdef i386}
  734. pbestrealtype : ^ttype = @s80floattype;
  735. {$endif}
  736. {$ifdef x86_64}
  737. pbestrealtype : ^ttype = @s80floattype;
  738. {$endif}
  739. {$ifdef m68k}
  740. pbestrealtype : ^ttype = @s64floattype;
  741. {$endif}
  742. {$ifdef alpha}
  743. pbestrealtype : ^ttype = @s64floattype;
  744. {$endif}
  745. {$ifdef powerpc}
  746. pbestrealtype : ^ttype = @s64floattype;
  747. {$endif}
  748. {$ifdef ia64}
  749. pbestrealtype : ^ttype = @s64floattype;
  750. {$endif}
  751. {$ifdef SPARC}
  752. pbestrealtype : ^ttype = @s64floattype;
  753. {$endif SPARC}
  754. {$ifdef vis}
  755. pbestrealtype : ^ttype = @s64floattype;
  756. {$endif vis}
  757. {$ifdef ARM}
  758. pbestrealtype : ^ttype = @s64floattype;
  759. {$endif ARM}
  760. function reverseparaitems(p: tparaitem): tparaitem;
  761. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  762. { should be in the types unit, but the types unit uses the node stuff :( }
  763. function is_interfacecom(def: tdef): boolean;
  764. function is_interfacecorba(def: tdef): boolean;
  765. function is_interface(def: tdef): boolean;
  766. function is_object(def: tdef): boolean;
  767. function is_class(def: tdef): boolean;
  768. function is_cppclass(def: tdef): boolean;
  769. function is_class_or_interface(def: tdef): boolean;
  770. implementation
  771. uses
  772. {$ifdef Delphi}
  773. sysutils,
  774. {$else Delphi}
  775. strings,
  776. {$endif Delphi}
  777. { global }
  778. verbose,
  779. { target }
  780. systems,aasmcpu,paramgr,
  781. { symtable }
  782. symsym,symtable,symutil,defutil,
  783. { module }
  784. {$ifdef GDB}
  785. gdb,
  786. {$endif GDB}
  787. fmodule,
  788. { other }
  789. gendef
  790. ;
  791. {****************************************************************************
  792. Helpers
  793. ****************************************************************************}
  794. function reverseparaitems(p: tparaitem): tparaitem;
  795. var
  796. hp1, hp2: tparaitem;
  797. begin
  798. hp1:=nil;
  799. while assigned(p) do
  800. begin
  801. { pull out }
  802. hp2:=p;
  803. p:=tparaitem(p.next);
  804. { pull in }
  805. hp2.next:=hp1;
  806. hp1:=hp2;
  807. end;
  808. reverseparaitems:=hp1;
  809. end;
  810. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  811. var
  812. s,
  813. prefix : string;
  814. begin
  815. prefix:='';
  816. if not assigned(st) then
  817. internalerror(200204212);
  818. { sub procedures }
  819. while (st.symtabletype=localsymtable) do
  820. begin
  821. if st.defowner.deftype<>procdef then
  822. internalerror(200204173);
  823. s:=tprocdef(st.defowner).procsym.name;
  824. if tprocdef(st.defowner).overloadnumber>0 then
  825. s:=s+'$'+tostr(tprocdef(st.defowner).overloadnumber);
  826. prefix:=s+'$'+prefix;
  827. st:=st.defowner.owner;
  828. end;
  829. { object/classes symtable }
  830. if (st.symtabletype=objectsymtable) then
  831. begin
  832. if st.defowner.deftype<>objectdef then
  833. internalerror(200204174);
  834. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  835. st:=st.defowner.owner;
  836. end;
  837. { symtable must now be static or global }
  838. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  839. internalerror(200204175);
  840. result:='';
  841. if typeprefix<>'' then
  842. result:=result+typeprefix+'_';
  843. { Add P$ for program, which can have the same name as
  844. a unit }
  845. if (tsymtable(main_module.localsymtable)=st) and
  846. (not main_module.is_unit) then
  847. result:=result+'P$'+st.name^
  848. else
  849. result:=result+st.name^;
  850. if prefix<>'' then
  851. result:=result+'_'+prefix;
  852. if suffix<>'' then
  853. result:=result+'_'+suffix;
  854. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  855. if (target_info.system = system_powerpc_darwin) and
  856. (result[1] = 'L') then
  857. result := '_' + result;
  858. end;
  859. {****************************************************************************
  860. TDEF (base class for definitions)
  861. ****************************************************************************}
  862. constructor tstoreddef.create;
  863. begin
  864. inherited create;
  865. savesize := 0;
  866. {$ifdef EXTDEBUG}
  867. fileinfo := aktfilepos;
  868. {$endif}
  869. if registerdef then
  870. symtablestack.registerdef(self);
  871. {$ifdef GDB}
  872. stab_state:=stab_state_unused;
  873. globalnb := 0;
  874. {$endif GDB}
  875. fillchar(localrttilab,sizeof(localrttilab),0);
  876. end;
  877. constructor tstoreddef.ppuloaddef(ppufile:tcompilerppufile);
  878. begin
  879. inherited create;
  880. {$ifdef EXTDEBUG}
  881. fillchar(fileinfo,sizeof(fileinfo),0);
  882. {$endif}
  883. {$ifdef GDB}
  884. stab_state:=stab_state_unused;
  885. globalnb := 0;
  886. {$endif GDB}
  887. fillchar(localrttilab,sizeof(localrttilab),0);
  888. { load }
  889. indexnr:=ppufile.getword;
  890. ppufile.getderef(typesymderef);
  891. ppufile.getsmallset(defoptions);
  892. if df_has_rttitable in defoptions then
  893. ppufile.getderef(rttitablesymderef);
  894. if df_has_inittable in defoptions then
  895. ppufile.getderef(inittablesymderef);
  896. end;
  897. procedure Tstoreddef.reset;
  898. begin
  899. {$ifdef GDB}
  900. stab_state:=stab_state_unused;
  901. {$endif GDB}
  902. if assigned(rttitablesym) then
  903. trttisym(rttitablesym).lab := nil;
  904. if assigned(inittablesym) then
  905. trttisym(inittablesym).lab := nil;
  906. localrttilab[initrtti]:=nil;
  907. localrttilab[fullrtti]:=nil;
  908. end;
  909. function tstoreddef.getcopy : tstoreddef;
  910. begin
  911. Message(sym_e_cant_create_unique_type);
  912. getcopy:=terrordef.create;
  913. end;
  914. procedure tstoreddef.ppuwritedef(ppufile:tcompilerppufile);
  915. begin
  916. ppufile.putword(indexnr);
  917. ppufile.putderef(typesymderef);
  918. ppufile.putsmallset(defoptions);
  919. if df_has_rttitable in defoptions then
  920. ppufile.putderef(rttitablesymderef);
  921. if df_has_inittable in defoptions then
  922. ppufile.putderef(inittablesymderef);
  923. {$ifdef GDB}
  924. if globalnb=0 then
  925. begin
  926. if (cs_gdb_dbx in aktglobalswitches) and
  927. assigned(owner) then
  928. globalnb := owner.getnewtypecount
  929. else
  930. set_globalnb;
  931. end;
  932. {$endif GDB}
  933. end;
  934. procedure tstoreddef.buildderef;
  935. begin
  936. typesymderef.build(typesym);
  937. rttitablesymderef.build(rttitablesym);
  938. inittablesymderef.build(inittablesym);
  939. end;
  940. procedure tstoreddef.buildderefimpl;
  941. begin
  942. end;
  943. procedure tstoreddef.deref;
  944. begin
  945. typesym:=ttypesym(typesymderef.resolve);
  946. if df_has_rttitable in defoptions then
  947. rttitablesym:=trttisym(rttitablesymderef.resolve);
  948. if df_has_inittable in defoptions then
  949. inittablesym:=trttisym(inittablesymderef.resolve);
  950. end;
  951. procedure tstoreddef.derefimpl;
  952. begin
  953. end;
  954. function tstoreddef.size : longint;
  955. begin
  956. size:=savesize;
  957. end;
  958. function tstoreddef.alignment : longint;
  959. begin
  960. { natural alignment by default }
  961. alignment:=size_2_align(savesize);
  962. end;
  963. {$ifdef GDB}
  964. procedure tstoreddef.set_globalnb;
  965. begin
  966. globalnb:=PGlobalTypeCount^;
  967. inc(PglobalTypeCount^);
  968. end;
  969. function Tstoreddef.get_var_value(const s:string):string;
  970. begin
  971. if s='numberstring' then
  972. get_var_value:=numberstring
  973. else if s='sym_name' then
  974. if assigned(typesym) then
  975. get_var_value:=Ttypesym(typesym).name
  976. else
  977. get_var_value:=' '
  978. else if s='N_LSYM' then
  979. get_var_value:=tostr(N_LSYM)
  980. else if s='savesize' then
  981. get_var_value:=tostr(savesize);
  982. end;
  983. function Tstoreddef.stabstr_evaluate(const s:string;const vars:array of string):Pchar;
  984. begin
  985. stabstr_evaluate:=string_evaluate(s,@get_var_value,vars);
  986. end;
  987. function tstoreddef.stabstring : pchar;
  988. begin
  989. stabstring:=stabstr_evaluate('t${numberstring};',[]);
  990. end;
  991. function tstoreddef.numberstring : string;
  992. begin
  993. { Stab must already be written, or we must be busy writing it }
  994. if writing_def_stabs and
  995. not(stab_state in [stab_state_writing,stab_state_written]) then
  996. internalerror(200403091);
  997. { Keep track of used stabs, this info is only usefull for stabs
  998. referenced by the symbols. Definitions will always include all
  999. required stabs }
  1000. if stab_state=stab_state_unused then
  1001. stab_state:=stab_state_used;
  1002. { Need a new number? }
  1003. if globalnb=0 then
  1004. begin
  1005. if (cs_gdb_dbx in aktglobalswitches) and
  1006. assigned(owner) then
  1007. globalnb := owner.getnewtypecount
  1008. else
  1009. set_globalnb;
  1010. end;
  1011. if (cs_gdb_dbx in aktglobalswitches) and
  1012. assigned(typesym) and
  1013. (ttypesym(typesym).owner.unitid<>0) then
  1014. result:='('+tostr(ttypesym(typesym).owner.unitid)+','+tostr(tstoreddef(ttypesym(typesym).restype.def).globalnb)+')'
  1015. else
  1016. result:=tostr(globalnb);
  1017. end;
  1018. function tstoreddef.allstabstring : pchar;
  1019. var
  1020. stabchar : string[2];
  1021. ss,st,su : pchar;
  1022. begin
  1023. ss := stabstring;
  1024. stabchar := 't';
  1025. if deftype in tagtypes then
  1026. stabchar := 'Tt';
  1027. { Here we maybe generate a type, so we have to use numberstring }
  1028. st:=stabstr_evaluate('"${sym_name}:$1$2=',[stabchar,numberstring]);
  1029. reallocmem(st,strlen(ss)+512);
  1030. { line info is set to 0 for all defs, because the def can be in an other
  1031. unit and then the linenumber is invalid in the current sourcefile }
  1032. su:=stabstr_evaluate('",${N_LSYM},0,0,0',[]);
  1033. strcopy(strecopy(strend(st),ss),su);
  1034. reallocmem(st,strlen(st)+1);
  1035. allstabstring:=st;
  1036. strdispose(ss);
  1037. strdispose(su);
  1038. end;
  1039. procedure tstoreddef.concatstabto(asmlist : taasmoutput);
  1040. var
  1041. stab_str : pchar;
  1042. begin
  1043. if (stab_state in [stab_state_writing,stab_state_written]) then
  1044. exit;
  1045. If cs_gdb_dbx in aktglobalswitches then
  1046. begin
  1047. { otherwise you get two of each def }
  1048. If assigned(typesym) then
  1049. begin
  1050. if (ttypesym(typesym).owner = nil) or
  1051. ((ttypesym(typesym).owner.symtabletype = globalsymtable) and
  1052. tglobalsymtable(ttypesym(typesym).owner).dbx_count_ok) then
  1053. begin
  1054. {with DBX we get the definition from the other objects }
  1055. stab_state := stab_state_written;
  1056. exit;
  1057. end;
  1058. end;
  1059. end;
  1060. { to avoid infinite loops }
  1061. stab_state := stab_state_writing;
  1062. stab_str := allstabstring;
  1063. asmList.concat(Tai_stabs.Create(stab_str));
  1064. stab_state := stab_state_written;
  1065. end;
  1066. {$endif GDB}
  1067. procedure tstoreddef.write_rtti_name;
  1068. var
  1069. str : string;
  1070. begin
  1071. { name }
  1072. if assigned(typesym) then
  1073. begin
  1074. str:=ttypesym(typesym).realname;
  1075. rttiList.concat(Tai_string.Create(chr(length(str))+str));
  1076. end
  1077. else
  1078. rttiList.concat(Tai_string.Create(#0))
  1079. end;
  1080. procedure tstoreddef.write_rtti_data(rt:trttitype);
  1081. begin
  1082. rttilist.concat(tai_const.create_8bit(tkUnknown));
  1083. write_rtti_name;
  1084. end;
  1085. procedure tstoreddef.write_child_rtti_data(rt:trttitype);
  1086. begin
  1087. end;
  1088. function tstoreddef.get_rtti_label(rt:trttitype) : tasmsymbol;
  1089. begin
  1090. { try to reuse persistent rtti data }
  1091. if (rt=fullrtti) and (df_has_rttitable in defoptions) then
  1092. get_rtti_label:=trttisym(rttitablesym).get_label
  1093. else
  1094. if (rt=initrtti) and (df_has_inittable in defoptions) then
  1095. get_rtti_label:=trttisym(inittablesym).get_label
  1096. else
  1097. begin
  1098. if not assigned(localrttilab[rt]) then
  1099. begin
  1100. objectlibrary.getdatalabel(localrttilab[rt]);
  1101. write_child_rtti_data(rt);
  1102. maybe_new_object_file(rttiList);
  1103. new_section(rttiList,sec_rodata,localrttilab[rt].name,const_align(sizeof(aint)));
  1104. rttiList.concat(Tai_symbol.Create_global(localrttilab[rt],0));
  1105. write_rtti_data(rt);
  1106. rttiList.concat(Tai_symbol_end.Create(localrttilab[rt]));
  1107. end;
  1108. get_rtti_label:=localrttilab[rt];
  1109. end;
  1110. end;
  1111. { returns true, if the definition can be published }
  1112. function tstoreddef.is_publishable : boolean;
  1113. begin
  1114. is_publishable:=false;
  1115. end;
  1116. { needs an init table }
  1117. function tstoreddef.needs_inittable : boolean;
  1118. begin
  1119. needs_inittable:=false;
  1120. end;
  1121. function tstoreddef.is_intregable : boolean;
  1122. begin
  1123. is_intregable:=false;
  1124. case deftype of
  1125. pointerdef,
  1126. enumdef:
  1127. is_intregable:=true;
  1128. procvardef :
  1129. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  1130. orddef :
  1131. case torddef(self).typ of
  1132. bool8bit,bool16bit,bool32bit,
  1133. u8bit,u16bit,u32bit,
  1134. s8bit,s16bit,s32bit,
  1135. uchar, uwidechar:
  1136. is_intregable:=true;
  1137. end;
  1138. objectdef:
  1139. is_intregable:=is_class(self) or is_interface(self);
  1140. setdef:
  1141. is_intregable:=(tsetdef(self).settype=smallset);
  1142. end;
  1143. end;
  1144. function tstoreddef.is_fpuregable : boolean;
  1145. begin
  1146. is_fpuregable:=(deftype=floatdef);
  1147. end;
  1148. {****************************************************************************
  1149. Tstringdef
  1150. ****************************************************************************}
  1151. constructor tstringdef.createshort(l : byte);
  1152. begin
  1153. inherited create;
  1154. string_typ:=st_shortstring;
  1155. deftype:=stringdef;
  1156. len:=l;
  1157. savesize:=len+1;
  1158. end;
  1159. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1160. begin
  1161. inherited ppuloaddef(ppufile);
  1162. string_typ:=st_shortstring;
  1163. deftype:=stringdef;
  1164. len:=ppufile.getbyte;
  1165. savesize:=len+1;
  1166. end;
  1167. constructor tstringdef.createlong(l : longint);
  1168. begin
  1169. inherited create;
  1170. string_typ:=st_longstring;
  1171. deftype:=stringdef;
  1172. len:=l;
  1173. savesize:=sizeof(aint);
  1174. end;
  1175. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1176. begin
  1177. inherited ppuloaddef(ppufile);
  1178. deftype:=stringdef;
  1179. string_typ:=st_longstring;
  1180. len:=ppufile.getlongint;
  1181. savesize:=sizeof(aint);
  1182. end;
  1183. {$ifdef ansistring_bits}
  1184. constructor tstringdef.createansi(l:longint;bits:Tstringbits);
  1185. begin
  1186. inherited create;
  1187. case bits of
  1188. sb_16:
  1189. string_typ:=st_ansistring16;
  1190. sb_32:
  1191. string_typ:=st_ansistring32;
  1192. sb_64:
  1193. string_typ:=st_ansistring64;
  1194. end;
  1195. deftype:=stringdef;
  1196. len:=l;
  1197. savesize:=POINTER_SIZE;
  1198. end;
  1199. constructor tstringdef.loadansi(ppufile:tcompilerppufile;bits:Tstringbits);
  1200. begin
  1201. inherited ppuloaddef(ppufile);
  1202. deftype:=stringdef;
  1203. case bits of
  1204. sb_16:
  1205. string_typ:=st_ansistring16;
  1206. sb_32:
  1207. string_typ:=st_ansistring32;
  1208. sb_64:
  1209. string_typ:=st_ansistring64;
  1210. end;
  1211. len:=ppufile.getlongint;
  1212. savesize:=POINTER_SIZE;
  1213. end;
  1214. {$else}
  1215. constructor tstringdef.createansi(l:longint);
  1216. begin
  1217. inherited create;
  1218. string_typ:=st_ansistring;
  1219. deftype:=stringdef;
  1220. len:=l;
  1221. savesize:=sizeof(aint);
  1222. end;
  1223. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1224. begin
  1225. inherited ppuloaddef(ppufile);
  1226. deftype:=stringdef;
  1227. string_typ:=st_ansistring;
  1228. len:=ppufile.getlongint;
  1229. savesize:=sizeof(aint);
  1230. end;
  1231. {$endif}
  1232. constructor tstringdef.createwide(l : longint);
  1233. begin
  1234. inherited create;
  1235. string_typ:=st_widestring;
  1236. deftype:=stringdef;
  1237. len:=l;
  1238. savesize:=sizeof(aint);
  1239. end;
  1240. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1241. begin
  1242. inherited ppuloaddef(ppufile);
  1243. deftype:=stringdef;
  1244. string_typ:=st_widestring;
  1245. len:=ppufile.getlongint;
  1246. savesize:=sizeof(aint);
  1247. end;
  1248. function tstringdef.getcopy : tstoreddef;
  1249. begin
  1250. result:=tstringdef.create;
  1251. result.deftype:=stringdef;
  1252. tstringdef(result).string_typ:=string_typ;
  1253. tstringdef(result).len:=len;
  1254. tstringdef(result).savesize:=savesize;
  1255. end;
  1256. function tstringdef.stringtypname:string;
  1257. {$ifdef ansistring_bits}
  1258. const
  1259. typname:array[tstringtype] of string[9]=('',
  1260. 'shortstr','longstr','ansistr16','ansistr32','ansistr64','widestr'
  1261. );
  1262. {$else}
  1263. const
  1264. typname:array[tstringtype] of string[8]=('',
  1265. 'shortstr','longstr','ansistr','widestr'
  1266. );
  1267. {$endif}
  1268. begin
  1269. stringtypname:=typname[string_typ];
  1270. end;
  1271. function tstringdef.size : longint;
  1272. begin
  1273. size:=savesize;
  1274. end;
  1275. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1276. begin
  1277. inherited ppuwritedef(ppufile);
  1278. if string_typ=st_shortstring then
  1279. begin
  1280. {$ifdef extdebug}
  1281. if len > 255 then internalerror(12122002);
  1282. {$endif}
  1283. ppufile.putbyte(byte(len))
  1284. end
  1285. else
  1286. ppufile.putlongint(len);
  1287. case string_typ of
  1288. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1289. st_longstring : ppufile.writeentry(iblongstringdef);
  1290. {$ifdef ansistring_bits}
  1291. st_ansistring16 : ppufile.writeentry(ibansistring16def);
  1292. st_ansistring32 : ppufile.writeentry(ibansistring32def);
  1293. st_ansistring64 : ppufile.writeentry(ibansistring64def);
  1294. {$else}
  1295. st_ansistring : ppufile.writeentry(ibansistringdef);
  1296. {$endif}
  1297. st_widestring : ppufile.writeentry(ibwidestringdef);
  1298. end;
  1299. end;
  1300. {$ifdef GDB}
  1301. function tstringdef.stabstring : pchar;
  1302. var
  1303. bytest,charst,longst : string;
  1304. slen : longint;
  1305. begin
  1306. case string_typ of
  1307. st_shortstring:
  1308. begin
  1309. charst:=tstoreddef(cchartype.def).numberstring;
  1310. { this is what I found in stabs.texinfo but
  1311. gdb 4.12 for go32 doesn't understand that !! }
  1312. {$IfDef GDBknowsstrings}
  1313. stabstring:=stabstr_evaluate('n$1;$2',[charst,tostr(len)]);
  1314. {$else}
  1315. { fix length of openshortstring }
  1316. slen:=len;
  1317. if slen=0 then
  1318. slen:=255;
  1319. bytest:=tstoreddef(u8inttype.def).numberstring;
  1320. stabstring:=stabstr_evaluate('s$1length:$2,0,8;st:ar$2;1;$3;$4,8,$5;;',
  1321. [tostr(slen+1),bytest,tostr(slen),charst,tostr(slen*8)]);
  1322. {$EndIf}
  1323. end;
  1324. st_longstring:
  1325. begin
  1326. charst:=tstoreddef(cchartype.def).numberstring;
  1327. { this is what I found in stabs.texinfo but
  1328. gdb 4.12 for go32 doesn't understand that !! }
  1329. {$IfDef GDBknowsstrings}
  1330. stabstring:=stabstr_evaluate('n$1;$2',[charst,tostr(len)]);
  1331. {$else}
  1332. bytest:=tstoreddef(u8inttype.def).numberstring;
  1333. longst:=tstoreddef(u32inttype.def).numberstring;
  1334. stabstring:=stabstr_evaluate('s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  1335. [tostr(len+5),longst,tostr(len),charst,tostr(len*8),bytest]);
  1336. {$EndIf}
  1337. end;
  1338. {$ifdef ansistring_bits}
  1339. st_ansistring16,st_ansistring32,st_ansistring64:
  1340. {$else}
  1341. st_ansistring:
  1342. {$endif}
  1343. begin
  1344. { an ansi string looks like a pchar easy !! }
  1345. charst:=tstoreddef(cchartype.def).numberstring;
  1346. stabstring:=strpnew('*'+charst);
  1347. end;
  1348. st_widestring:
  1349. begin
  1350. { an ansi string looks like a pwidechar easy !! }
  1351. charst:=tstoreddef(cwidechartype.def).numberstring;
  1352. stabstring:=strpnew('*'+charst);
  1353. end;
  1354. end;
  1355. end;
  1356. procedure tstringdef.concatstabto(asmlist:taasmoutput);
  1357. begin
  1358. if (stab_state in [stab_state_writing,stab_state_written]) then
  1359. exit;
  1360. case string_typ of
  1361. st_shortstring:
  1362. begin
  1363. tstoreddef(cchartype.def).concatstabto(asmlist);
  1364. {$IfNDef GDBknowsstrings}
  1365. tstoreddef(u8inttype.def).concatstabto(asmlist);
  1366. {$EndIf}
  1367. end;
  1368. st_longstring:
  1369. begin
  1370. tstoreddef(cchartype.def).concatstabto(asmlist);
  1371. {$IfNDef GDBknowsstrings}
  1372. tstoreddef(u8inttype.def).concatstabto(asmlist);
  1373. tstoreddef(u32inttype.def).concatstabto(asmlist);
  1374. {$EndIf}
  1375. end;
  1376. {$ifdef ansistring_bits}
  1377. st_ansistring16,st_ansistring32,st_ansistring64:
  1378. {$else}
  1379. st_ansistring:
  1380. {$endif}
  1381. tstoreddef(cchartype.def).concatstabto(asmlist);
  1382. st_widestring:
  1383. tstoreddef(cwidechartype.def).concatstabto(asmlist);
  1384. end;
  1385. inherited concatstabto(asmlist);
  1386. end;
  1387. {$endif GDB}
  1388. function tstringdef.needs_inittable : boolean;
  1389. begin
  1390. {$ifdef ansistring_bits}
  1391. needs_inittable:=string_typ in [st_ansistring16,st_ansistring32,st_ansistring64,st_widestring];
  1392. {$else}
  1393. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  1394. {$endif}
  1395. end;
  1396. function tstringdef.gettypename : string;
  1397. {$ifdef ansistring_bits}
  1398. const
  1399. names : array[tstringtype] of string[20] = ('',
  1400. 'shortstring','longstring','ansistring16','ansistring32','ansistring64','widestring');
  1401. {$else}
  1402. const
  1403. names : array[tstringtype] of string[20] = ('',
  1404. 'ShortString','LongString','AnsiString','WideString');
  1405. {$endif}
  1406. begin
  1407. gettypename:=names[string_typ];
  1408. end;
  1409. procedure tstringdef.write_rtti_data(rt:trttitype);
  1410. begin
  1411. case string_typ of
  1412. {$ifdef ansistring_bits}
  1413. st_ansistring16:
  1414. begin
  1415. rttiList.concat(Tai_const.Create_8bit(tkA16String));
  1416. write_rtti_name;
  1417. end;
  1418. st_ansistring32:
  1419. begin
  1420. rttiList.concat(Tai_const.Create_8bit(tkA32String));
  1421. write_rtti_name;
  1422. end;
  1423. st_ansistring64:
  1424. begin
  1425. rttiList.concat(Tai_const.Create_8bit(tkA64String));
  1426. write_rtti_name;
  1427. end;
  1428. {$else}
  1429. st_ansistring:
  1430. begin
  1431. rttiList.concat(Tai_const.Create_8bit(tkAString));
  1432. write_rtti_name;
  1433. end;
  1434. {$endif}
  1435. st_widestring:
  1436. begin
  1437. rttiList.concat(Tai_const.Create_8bit(tkWString));
  1438. write_rtti_name;
  1439. end;
  1440. st_longstring:
  1441. begin
  1442. rttiList.concat(Tai_const.Create_8bit(tkLString));
  1443. write_rtti_name;
  1444. end;
  1445. st_shortstring:
  1446. begin
  1447. rttiList.concat(Tai_const.Create_8bit(tkSString));
  1448. write_rtti_name;
  1449. rttiList.concat(Tai_const.Create_8bit(len));
  1450. end;
  1451. end;
  1452. end;
  1453. function tstringdef.getmangledparaname : string;
  1454. begin
  1455. getmangledparaname:='STRING';
  1456. end;
  1457. function tstringdef.is_publishable : boolean;
  1458. begin
  1459. is_publishable:=true;
  1460. end;
  1461. {****************************************************************************
  1462. TENUMDEF
  1463. ****************************************************************************}
  1464. constructor tenumdef.create;
  1465. begin
  1466. inherited create;
  1467. deftype:=enumdef;
  1468. minval:=0;
  1469. maxval:=0;
  1470. calcsavesize;
  1471. has_jumps:=false;
  1472. basedef:=nil;
  1473. firstenum:=nil;
  1474. correct_owner_symtable;
  1475. end;
  1476. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:longint);
  1477. begin
  1478. inherited create;
  1479. deftype:=enumdef;
  1480. minval:=_min;
  1481. maxval:=_max;
  1482. basedef:=_basedef;
  1483. calcsavesize;
  1484. has_jumps:=false;
  1485. firstenum:=basedef.firstenum;
  1486. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1487. firstenum:=tenumsym(firstenum).nextenum;
  1488. correct_owner_symtable;
  1489. end;
  1490. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1491. begin
  1492. inherited ppuloaddef(ppufile);
  1493. deftype:=enumdef;
  1494. ppufile.getderef(basedefderef);
  1495. minval:=ppufile.getlongint;
  1496. maxval:=ppufile.getlongint;
  1497. savesize:=ppufile.getlongint;
  1498. has_jumps:=false;
  1499. firstenum:=Nil;
  1500. end;
  1501. procedure tenumdef.calcsavesize;
  1502. begin
  1503. if (aktpackenum=4) or (min<0) or (max>65535) then
  1504. savesize:=4
  1505. else
  1506. if (aktpackenum=2) or (min<0) or (max>255) then
  1507. savesize:=2
  1508. else
  1509. savesize:=1;
  1510. end;
  1511. procedure tenumdef.setmax(_max:longint);
  1512. begin
  1513. maxval:=_max;
  1514. calcsavesize;
  1515. end;
  1516. procedure tenumdef.setmin(_min:longint);
  1517. begin
  1518. minval:=_min;
  1519. calcsavesize;
  1520. end;
  1521. function tenumdef.min:longint;
  1522. begin
  1523. min:=minval;
  1524. end;
  1525. function tenumdef.max:longint;
  1526. begin
  1527. max:=maxval;
  1528. end;
  1529. procedure tenumdef.buildderef;
  1530. begin
  1531. inherited buildderef;
  1532. basedefderef.build(basedef);
  1533. end;
  1534. procedure tenumdef.deref;
  1535. begin
  1536. inherited deref;
  1537. basedef:=tenumdef(basedefderef.resolve);
  1538. end;
  1539. destructor tenumdef.destroy;
  1540. begin
  1541. inherited destroy;
  1542. end;
  1543. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1544. begin
  1545. inherited ppuwritedef(ppufile);
  1546. ppufile.putderef(basedefderef);
  1547. ppufile.putlongint(min);
  1548. ppufile.putlongint(max);
  1549. ppufile.putlongint(savesize);
  1550. ppufile.writeentry(ibenumdef);
  1551. end;
  1552. { used for enumdef because the symbols are
  1553. inserted in the owner symtable }
  1554. procedure tenumdef.correct_owner_symtable;
  1555. var
  1556. st : tsymtable;
  1557. begin
  1558. if assigned(owner) and
  1559. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  1560. begin
  1561. owner.defindex.deleteindex(self);
  1562. st:=owner;
  1563. while (st.symtabletype in [recordsymtable,objectsymtable]) do
  1564. st:=st.next;
  1565. st.registerdef(self);
  1566. end;
  1567. end;
  1568. {$ifdef GDB}
  1569. function tenumdef.stabstring : pchar;
  1570. var st:Pchar;
  1571. p:Tenumsym;
  1572. s:string;
  1573. memsize,stl:cardinal;
  1574. begin
  1575. memsize:=memsizeinc;
  1576. getmem(st,memsize);
  1577. { we can specify the size with @s<size>; prefix PM }
  1578. if savesize <> std_param_align then
  1579. strpcopy(st,'@s'+tostr(savesize*8)+';e')
  1580. else
  1581. strpcopy(st,'e');
  1582. p := tenumsym(firstenum);
  1583. stl:=strlen(st);
  1584. while assigned(p) do
  1585. begin
  1586. s :=p.name+':'+tostr(p.value)+',';
  1587. { place for the ending ';' also }
  1588. if (stl+length(s)+1>=memsize) then
  1589. begin
  1590. inc(memsize,memsizeinc);
  1591. reallocmem(st,memsize);
  1592. end;
  1593. strpcopy(st+stl,s);
  1594. inc(stl,length(s));
  1595. p:=p.nextenum;
  1596. end;
  1597. st[stl]:=';';
  1598. st[stl+1]:=#0;
  1599. reallocmem(st,stl+2);
  1600. stabstring:=st;
  1601. end;
  1602. {$endif GDB}
  1603. procedure tenumdef.write_child_rtti_data(rt:trttitype);
  1604. begin
  1605. if assigned(basedef) then
  1606. basedef.get_rtti_label(rt);
  1607. end;
  1608. procedure tenumdef.write_rtti_data(rt:trttitype);
  1609. var
  1610. hp : tenumsym;
  1611. begin
  1612. rttiList.concat(Tai_const.Create_8bit(tkEnumeration));
  1613. write_rtti_name;
  1614. case savesize of
  1615. 1:
  1616. rttiList.concat(Tai_const.Create_8bit(otUByte));
  1617. 2:
  1618. rttiList.concat(Tai_const.Create_8bit(otUWord));
  1619. 4:
  1620. rttiList.concat(Tai_const.Create_8bit(otULong));
  1621. end;
  1622. rttiList.concat(Tai_const.Create_32bit(min));
  1623. rttiList.concat(Tai_const.Create_32bit(max));
  1624. if assigned(basedef) then
  1625. rttiList.concat(Tai_const.Create_sym(basedef.get_rtti_label(rt)))
  1626. else
  1627. rttiList.concat(Tai_const.create_sym(nil));
  1628. hp:=tenumsym(firstenum);
  1629. while assigned(hp) do
  1630. begin
  1631. rttiList.concat(Tai_const.Create_8bit(length(hp.realname)));
  1632. rttiList.concat(Tai_string.Create(hp.realname));
  1633. hp:=hp.nextenum;
  1634. end;
  1635. rttiList.concat(Tai_const.Create_8bit(0));
  1636. end;
  1637. function tenumdef.is_publishable : boolean;
  1638. begin
  1639. is_publishable:=true;
  1640. end;
  1641. function tenumdef.gettypename : string;
  1642. begin
  1643. gettypename:='<enumeration type>';
  1644. end;
  1645. {****************************************************************************
  1646. TORDDEF
  1647. ****************************************************************************}
  1648. constructor torddef.create(t : tbasetype;v,b : TConstExprInt);
  1649. begin
  1650. inherited create;
  1651. deftype:=orddef;
  1652. low:=v;
  1653. high:=b;
  1654. typ:=t;
  1655. setsize;
  1656. end;
  1657. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1658. begin
  1659. inherited ppuloaddef(ppufile);
  1660. deftype:=orddef;
  1661. typ:=tbasetype(ppufile.getbyte);
  1662. if sizeof(TConstExprInt)=8 then
  1663. begin
  1664. low:=ppufile.getint64;
  1665. high:=ppufile.getint64;
  1666. end
  1667. else
  1668. begin
  1669. low:=ppufile.getlongint;
  1670. high:=ppufile.getlongint;
  1671. end;
  1672. setsize;
  1673. end;
  1674. function torddef.getcopy : tstoreddef;
  1675. begin
  1676. result:=torddef.create(typ,low,high);
  1677. result.deftype:=orddef;
  1678. torddef(result).low:=low;
  1679. torddef(result).high:=high;
  1680. torddef(result).typ:=typ;
  1681. torddef(result).savesize:=savesize;
  1682. end;
  1683. procedure torddef.setsize;
  1684. const
  1685. sizetbl : array[tbasetype] of longint = (
  1686. 0,
  1687. 1,2,4,8,
  1688. 1,2,4,8,
  1689. 1,2,4,
  1690. 1,2,8
  1691. );
  1692. begin
  1693. savesize:=sizetbl[typ];
  1694. end;
  1695. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1696. begin
  1697. inherited ppuwritedef(ppufile);
  1698. ppufile.putbyte(byte(typ));
  1699. if sizeof(TConstExprInt)=8 then
  1700. begin
  1701. ppufile.putint64(low);
  1702. ppufile.putint64(high);
  1703. end
  1704. else
  1705. begin
  1706. ppufile.putlongint(low);
  1707. ppufile.putlongint(high);
  1708. end;
  1709. ppufile.writeentry(iborddef);
  1710. end;
  1711. {$ifdef GDB}
  1712. function torddef.stabstring : pchar;
  1713. begin
  1714. if cs_gdb_valgrind in aktglobalswitches then
  1715. begin
  1716. case typ of
  1717. uvoid :
  1718. stabstring := strpnew(numberstring);
  1719. bool8bit,
  1720. bool16bit,
  1721. bool32bit :
  1722. stabstring := stabstr_evaluate('r${numberstring};0;255;',[]);
  1723. u32bit,
  1724. s64bit,
  1725. u64bit :
  1726. stabstring:=stabstr_evaluate('r${numberstring};0;-1;',[]);
  1727. else
  1728. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1729. end;
  1730. end
  1731. else
  1732. begin
  1733. case typ of
  1734. uvoid :
  1735. stabstring := strpnew(numberstring);
  1736. uchar :
  1737. stabstring := strpnew('-20;');
  1738. uwidechar :
  1739. stabstring := strpnew('-30;');
  1740. bool8bit :
  1741. stabstring := strpnew('-21;');
  1742. bool16bit :
  1743. stabstring := strpnew('-22;');
  1744. bool32bit :
  1745. stabstring := strpnew('-23;');
  1746. u64bit :
  1747. stabstring := strpnew('-32;');
  1748. s64bit :
  1749. stabstring := strpnew('-31;');
  1750. {u32bit : stabstring := tstoreddef(s32inttype.def).numberstring+';0;-1;'); }
  1751. else
  1752. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1753. end;
  1754. end;
  1755. end;
  1756. {$endif GDB}
  1757. procedure torddef.write_rtti_data(rt:trttitype);
  1758. procedure dointeger;
  1759. const
  1760. trans : array[tbasetype] of byte =
  1761. (otUByte{otNone},
  1762. otUByte,otUWord,otULong,otUByte{otNone},
  1763. otSByte,otSWord,otSLong,otUByte{otNone},
  1764. otUByte,otUWord,otULong,
  1765. otUByte,otUWord,otUByte);
  1766. begin
  1767. write_rtti_name;
  1768. rttiList.concat(Tai_const.Create_8bit(byte(trans[typ])));
  1769. rttiList.concat(Tai_const.Create_32bit(longint(low)));
  1770. rttiList.concat(Tai_const.Create_32bit(longint(high)));
  1771. end;
  1772. begin
  1773. case typ of
  1774. s64bit :
  1775. begin
  1776. rttiList.concat(Tai_const.Create_8bit(tkInt64));
  1777. write_rtti_name;
  1778. { low }
  1779. rttiList.concat(Tai_const.Create_64bit(int64($80000000) shl 32));
  1780. { high }
  1781. rttiList.concat(Tai_const.Create_64bit((int64($7fffffff) shl 32) or int64($ffffffff)));
  1782. end;
  1783. u64bit :
  1784. begin
  1785. rttiList.concat(Tai_const.Create_8bit(tkQWord));
  1786. write_rtti_name;
  1787. { low }
  1788. rttiList.concat(Tai_const.Create_64bit(0));
  1789. { high }
  1790. rttiList.concat(Tai_const.Create_64bit(int64((int64($ffffffff) shl 32) or int64($ffffffff))));
  1791. end;
  1792. bool8bit:
  1793. begin
  1794. rttiList.concat(Tai_const.Create_8bit(tkBool));
  1795. dointeger;
  1796. end;
  1797. uchar:
  1798. begin
  1799. rttiList.concat(Tai_const.Create_8bit(tkChar));
  1800. dointeger;
  1801. end;
  1802. uwidechar:
  1803. begin
  1804. rttiList.concat(Tai_const.Create_8bit(tkWChar));
  1805. dointeger;
  1806. end;
  1807. else
  1808. begin
  1809. rttiList.concat(Tai_const.Create_8bit(tkInteger));
  1810. dointeger;
  1811. end;
  1812. end;
  1813. end;
  1814. function torddef.is_publishable : boolean;
  1815. begin
  1816. is_publishable:=(typ<>uvoid);
  1817. end;
  1818. function torddef.gettypename : string;
  1819. const
  1820. names : array[tbasetype] of string[20] = (
  1821. 'untyped',
  1822. 'Byte','Word','DWord','QWord',
  1823. 'ShortInt','SmallInt','LongInt','Int64',
  1824. 'Boolean','WordBool','LongBool',
  1825. 'Char','WideChar','Currency');
  1826. begin
  1827. gettypename:=names[typ];
  1828. end;
  1829. {****************************************************************************
  1830. TFLOATDEF
  1831. ****************************************************************************}
  1832. constructor tfloatdef.create(t : tfloattype);
  1833. begin
  1834. inherited create;
  1835. deftype:=floatdef;
  1836. typ:=t;
  1837. setsize;
  1838. end;
  1839. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1840. begin
  1841. inherited ppuloaddef(ppufile);
  1842. deftype:=floatdef;
  1843. typ:=tfloattype(ppufile.getbyte);
  1844. setsize;
  1845. end;
  1846. function tfloatdef.getcopy : tstoreddef;
  1847. begin
  1848. result:=tfloatdef.create(typ);
  1849. result.deftype:=floatdef;
  1850. tfloatdef(result).savesize:=savesize;
  1851. end;
  1852. procedure tfloatdef.setsize;
  1853. begin
  1854. case typ of
  1855. s32real : savesize:=4;
  1856. s80real : savesize:=extended_size;
  1857. s64real,
  1858. s64currency,
  1859. s64comp : savesize:=8;
  1860. else
  1861. savesize:=0;
  1862. end;
  1863. end;
  1864. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1865. begin
  1866. inherited ppuwritedef(ppufile);
  1867. ppufile.putbyte(byte(typ));
  1868. ppufile.writeentry(ibfloatdef);
  1869. end;
  1870. {$ifdef GDB}
  1871. function Tfloatdef.stabstring:Pchar;
  1872. begin
  1873. case typ of
  1874. s32real,s64real:
  1875. { found this solution in stabsread.c from GDB v4.16 }
  1876. stabstring:=stabstr_evaluate('r$1;${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1877. s64currency,s64comp:
  1878. stabstring:=stabstr_evaluate('r$1;-${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1879. s80real:
  1880. { under dos at least you must give a size of twelve instead of 10 !! }
  1881. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  1882. stabstring:=stabstr_evaluate('r$1;12;0;',[tstoreddef(s32inttype.def).numberstring]);
  1883. else
  1884. internalerror(10005);
  1885. end;
  1886. end;
  1887. procedure tfloatdef.concatstabto(asmlist:taasmoutput);
  1888. begin
  1889. if (stab_state in [stab_state_writing,stab_state_written]) then
  1890. exit;
  1891. tstoreddef(s32inttype.def).concatstabto(asmlist);
  1892. inherited concatstabto(asmlist);
  1893. end;
  1894. {$endif GDB}
  1895. procedure tfloatdef.write_rtti_data(rt:trttitype);
  1896. const
  1897. {tfloattype = (s32real,s64real,s80real,s64bit,s128bit);}
  1898. translate : array[tfloattype] of byte =
  1899. (ftSingle,ftDouble,ftExtended,ftComp,ftCurr,ftFloat128);
  1900. begin
  1901. rttiList.concat(Tai_const.Create_8bit(tkFloat));
  1902. write_rtti_name;
  1903. rttiList.concat(Tai_const.Create_8bit(translate[typ]));
  1904. end;
  1905. function tfloatdef.is_publishable : boolean;
  1906. begin
  1907. is_publishable:=true;
  1908. end;
  1909. function tfloatdef.gettypename : string;
  1910. const
  1911. names : array[tfloattype] of string[20] = (
  1912. 'Single','Double','Extended','Comp','Currency','Float128');
  1913. begin
  1914. gettypename:=names[typ];
  1915. end;
  1916. {****************************************************************************
  1917. TFILEDEF
  1918. ****************************************************************************}
  1919. constructor tfiledef.createtext;
  1920. begin
  1921. inherited create;
  1922. deftype:=filedef;
  1923. filetyp:=ft_text;
  1924. typedfiletype.reset;
  1925. setsize;
  1926. end;
  1927. constructor tfiledef.createuntyped;
  1928. begin
  1929. inherited create;
  1930. deftype:=filedef;
  1931. filetyp:=ft_untyped;
  1932. typedfiletype.reset;
  1933. setsize;
  1934. end;
  1935. constructor tfiledef.createtyped(const tt : ttype);
  1936. begin
  1937. inherited create;
  1938. deftype:=filedef;
  1939. filetyp:=ft_typed;
  1940. typedfiletype:=tt;
  1941. setsize;
  1942. end;
  1943. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1944. begin
  1945. inherited ppuloaddef(ppufile);
  1946. deftype:=filedef;
  1947. filetyp:=tfiletyp(ppufile.getbyte);
  1948. if filetyp=ft_typed then
  1949. ppufile.gettype(typedfiletype)
  1950. else
  1951. typedfiletype.reset;
  1952. setsize;
  1953. end;
  1954. procedure tfiledef.buildderef;
  1955. begin
  1956. inherited buildderef;
  1957. if filetyp=ft_typed then
  1958. typedfiletype.buildderef;
  1959. end;
  1960. procedure tfiledef.deref;
  1961. begin
  1962. inherited deref;
  1963. if filetyp=ft_typed then
  1964. typedfiletype.resolve;
  1965. end;
  1966. procedure tfiledef.setsize;
  1967. begin
  1968. {$ifdef cpu64bit}
  1969. case filetyp of
  1970. ft_text :
  1971. savesize:=608;
  1972. ft_typed,
  1973. ft_untyped :
  1974. savesize:=320;
  1975. end;
  1976. {$else cpu64bit}
  1977. case filetyp of
  1978. ft_text :
  1979. savesize:=572;
  1980. ft_typed,
  1981. ft_untyped :
  1982. savesize:=316;
  1983. end;
  1984. {$endif cpu64bit}
  1985. end;
  1986. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1987. begin
  1988. inherited ppuwritedef(ppufile);
  1989. ppufile.putbyte(byte(filetyp));
  1990. if filetyp=ft_typed then
  1991. ppufile.puttype(typedfiletype);
  1992. ppufile.writeentry(ibfiledef);
  1993. end;
  1994. {$ifdef GDB}
  1995. function tfiledef.stabstring : pchar;
  1996. begin
  1997. {$IfDef GDBknowsfiles}
  1998. case filetyp of
  1999. ft_typed :
  2000. stabstring := strpnew('d'+typedfiletype.def.numberstring{+';'});
  2001. ft_untyped :
  2002. stabstring := strpnew('d'+voiddef.numberstring{+';'});
  2003. ft_text :
  2004. stabstring := strpnew('d'+cchartype^.numberstring{+';'});
  2005. end;
  2006. {$Else}
  2007. {$ifdef cpu64bit}
  2008. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$2,64,64;'+
  2009. '_PRIVATE:ar$1;1;64;$3,128,256;USERDATA:ar$1;1;16;$3,384,128;'+
  2010. 'NAME:ar$1;0;255;$4,512,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2011. tstoreddef(s64inttype.def).numberstring,
  2012. tstoreddef(u8inttype.def).numberstring,
  2013. tstoreddef(cchartype.def).numberstring]);
  2014. {$else cpu64bit}
  2015. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$1,64,32;'+
  2016. '_PRIVATE:ar$1;1;32;$3,96,256;USERDATA:ar$1;1;16;$2,352,128;'+
  2017. 'NAME:ar$1;0;255;$3,480,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2018. tstoreddef(u8inttype.def).numberstring,
  2019. tstoreddef(cchartype.def).numberstring]);
  2020. {$endif cpu64bit}
  2021. {$EndIf}
  2022. end;
  2023. procedure tfiledef.concatstabto(asmlist:taasmoutput);
  2024. begin
  2025. if (stab_state in [stab_state_writing,stab_state_written]) then
  2026. exit;
  2027. {$IfDef GDBknowsfiles}
  2028. case filetyp of
  2029. ft_typed :
  2030. tstoreddef(typedfiletype.def).concatstabto(asmlist);
  2031. ft_untyped :
  2032. tstoreddef(voidtype.def).concatstabto(asmlist);
  2033. ft_text :
  2034. tstoreddef(cchartype.def).concatstabto(asmlist);
  2035. end;
  2036. {$Else}
  2037. tstoreddef(s32inttype.def).concatstabto(asmlist);
  2038. {$ifdef cpu64bit}
  2039. tstoreddef(s64inttype.def).concatstabto(asmlist);
  2040. {$endif cpu64bit}
  2041. tstoreddef(u8inttype.def).concatstabto(asmlist);
  2042. tstoreddef(cchartype.def).concatstabto(asmlist);
  2043. {$EndIf}
  2044. inherited concatstabto(asmlist);
  2045. end;
  2046. {$endif GDB}
  2047. function tfiledef.gettypename : string;
  2048. begin
  2049. case filetyp of
  2050. ft_untyped:
  2051. gettypename:='File';
  2052. ft_typed:
  2053. gettypename:='File Of '+typedfiletype.def.typename;
  2054. ft_text:
  2055. gettypename:='Text'
  2056. end;
  2057. end;
  2058. function tfiledef.getmangledparaname : string;
  2059. begin
  2060. case filetyp of
  2061. ft_untyped:
  2062. getmangledparaname:='FILE';
  2063. ft_typed:
  2064. getmangledparaname:='FILE$OF$'+typedfiletype.def.mangledparaname;
  2065. ft_text:
  2066. getmangledparaname:='TEXT'
  2067. end;
  2068. end;
  2069. {****************************************************************************
  2070. TVARIANTDEF
  2071. ****************************************************************************}
  2072. constructor tvariantdef.create(v : tvarianttype);
  2073. begin
  2074. inherited create;
  2075. varianttype:=v;
  2076. deftype:=variantdef;
  2077. setsize;
  2078. end;
  2079. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2080. begin
  2081. inherited ppuloaddef(ppufile);
  2082. varianttype:=tvarianttype(ppufile.getbyte);
  2083. deftype:=variantdef;
  2084. setsize;
  2085. end;
  2086. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2087. begin
  2088. inherited ppuwritedef(ppufile);
  2089. ppufile.putbyte(byte(varianttype));
  2090. ppufile.writeentry(ibvariantdef);
  2091. end;
  2092. procedure tvariantdef.setsize;
  2093. begin
  2094. savesize:=16;
  2095. end;
  2096. function tvariantdef.gettypename : string;
  2097. begin
  2098. case varianttype of
  2099. vt_normalvariant:
  2100. gettypename:='Variant';
  2101. vt_olevariant:
  2102. gettypename:='OleVariant';
  2103. end;
  2104. end;
  2105. procedure tvariantdef.write_rtti_data(rt:trttitype);
  2106. begin
  2107. rttiList.concat(Tai_const.Create_8bit(tkVariant));
  2108. end;
  2109. function tvariantdef.needs_inittable : boolean;
  2110. begin
  2111. needs_inittable:=true;
  2112. end;
  2113. {$ifdef GDB}
  2114. function tvariantdef.stabstring : pchar;
  2115. begin
  2116. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2117. end;
  2118. function tvariantdef.numberstring:string;
  2119. begin
  2120. result:=tstoreddef(voidtype.def).numberstring;
  2121. end;
  2122. procedure tvariantdef.concatstabto(asmlist : taasmoutput);
  2123. begin
  2124. { don't know how to handle this }
  2125. end;
  2126. {$endif GDB}
  2127. {****************************************************************************
  2128. TPOINTERDEF
  2129. ****************************************************************************}
  2130. constructor tpointerdef.create(const tt : ttype);
  2131. begin
  2132. inherited create;
  2133. deftype:=pointerdef;
  2134. pointertype:=tt;
  2135. is_far:=false;
  2136. savesize:=sizeof(aint);
  2137. end;
  2138. constructor tpointerdef.createfar(const tt : ttype);
  2139. begin
  2140. inherited create;
  2141. deftype:=pointerdef;
  2142. pointertype:=tt;
  2143. is_far:=true;
  2144. savesize:=sizeof(aint);
  2145. end;
  2146. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2147. begin
  2148. inherited ppuloaddef(ppufile);
  2149. deftype:=pointerdef;
  2150. ppufile.gettype(pointertype);
  2151. is_far:=(ppufile.getbyte<>0);
  2152. savesize:=sizeof(aint);
  2153. end;
  2154. procedure tpointerdef.buildderef;
  2155. begin
  2156. inherited buildderef;
  2157. pointertype.buildderef;
  2158. end;
  2159. procedure tpointerdef.deref;
  2160. begin
  2161. inherited deref;
  2162. pointertype.resolve;
  2163. end;
  2164. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2165. begin
  2166. inherited ppuwritedef(ppufile);
  2167. ppufile.puttype(pointertype);
  2168. ppufile.putbyte(byte(is_far));
  2169. ppufile.writeentry(ibpointerdef);
  2170. end;
  2171. {$ifdef GDB}
  2172. function tpointerdef.stabstring : pchar;
  2173. begin
  2174. stabstring := strpnew('*'+tstoreddef(pointertype.def).numberstring);
  2175. end;
  2176. procedure tpointerdef.concatstabto(asmlist : taasmoutput);
  2177. var st,nb : string;
  2178. begin
  2179. if (stab_state in [stab_state_writing,stab_state_written]) then
  2180. exit;
  2181. stab_state:=stab_state_writing;
  2182. tstoreddef(pointertype.def).concatstabto(asmlist);
  2183. if (pointertype.def.deftype in [recorddef,objectdef]) then
  2184. begin
  2185. if pointertype.def.deftype=objectdef then
  2186. nb:=tobjectdef(pointertype.def).classnumberstring
  2187. else
  2188. nb:=tstoreddef(pointertype.def).numberstring;
  2189. {to avoid infinite recursion in record with next-like fields }
  2190. if tstoreddef(pointertype.def).stab_state=stab_state_writing then
  2191. begin
  2192. if assigned(pointertype.def.typesym) then
  2193. begin
  2194. if assigned(typesym) then
  2195. st := ttypesym(typesym).name
  2196. else
  2197. st := ' ';
  2198. asmlist.concat(Tai_stabs.create(stabstr_evaluate(
  2199. '"$1:t${numberstring}=*$2=xs$3:",${N_LSYM},0,0,0',
  2200. [st,nb,pointertype.def.typesym.name])));
  2201. end;
  2202. stab_state:=stab_state_written;
  2203. end
  2204. else
  2205. begin
  2206. stab_state:=stab_state_used;
  2207. inherited concatstabto(asmlist);
  2208. end;
  2209. end
  2210. else
  2211. begin
  2212. stab_state:=stab_state_used;
  2213. inherited concatstabto(asmlist);
  2214. end;
  2215. end;
  2216. {$endif GDB}
  2217. function tpointerdef.gettypename : string;
  2218. begin
  2219. if is_far then
  2220. gettypename:='^'+pointertype.def.typename+';far'
  2221. else
  2222. gettypename:='^'+pointertype.def.typename;
  2223. end;
  2224. {****************************************************************************
  2225. TCLASSREFDEF
  2226. ****************************************************************************}
  2227. constructor tclassrefdef.create(const t:ttype);
  2228. begin
  2229. inherited create(t);
  2230. deftype:=classrefdef;
  2231. end;
  2232. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2233. begin
  2234. { be careful, tclassdefref inherits from tpointerdef }
  2235. inherited ppuloaddef(ppufile);
  2236. deftype:=classrefdef;
  2237. ppufile.gettype(pointertype);
  2238. is_far:=false;
  2239. savesize:=sizeof(aint);
  2240. end;
  2241. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2242. begin
  2243. { be careful, tclassdefref inherits from tpointerdef }
  2244. inherited ppuwritedef(ppufile);
  2245. ppufile.puttype(pointertype);
  2246. ppufile.writeentry(ibclassrefdef);
  2247. end;
  2248. {$ifdef GDB}
  2249. function tclassrefdef.stabstring : pchar;
  2250. begin
  2251. stabstring:=strpnew(tstoreddef(pvmttype.def).numberstring);
  2252. end;
  2253. {$endif GDB}
  2254. function tclassrefdef.gettypename : string;
  2255. begin
  2256. gettypename:='Class Of '+pointertype.def.typename;
  2257. end;
  2258. {***************************************************************************
  2259. TSETDEF
  2260. ***************************************************************************}
  2261. constructor tsetdef.create(const t:ttype;high : longint);
  2262. begin
  2263. inherited create;
  2264. deftype:=setdef;
  2265. elementtype:=t;
  2266. if high<32 then
  2267. begin
  2268. settype:=smallset;
  2269. {$ifdef testvarsets}
  2270. if aktsetalloc=0 THEN { $PACKSET Fixed?}
  2271. {$endif}
  2272. savesize:=Sizeof(longint)
  2273. {$ifdef testvarsets}
  2274. else {No, use $PACKSET VALUE for rounding}
  2275. savesize:=aktsetalloc*((high+aktsetalloc*8-1) DIV (aktsetalloc*8))
  2276. {$endif}
  2277. ;
  2278. end
  2279. else
  2280. if high<256 then
  2281. begin
  2282. settype:=normset;
  2283. savesize:=32;
  2284. end
  2285. else
  2286. {$ifdef testvarsets}
  2287. if high<$10000 then
  2288. begin
  2289. settype:=varset;
  2290. savesize:=4*((high+31) div 32);
  2291. end
  2292. else
  2293. {$endif testvarsets}
  2294. Message(sym_e_ill_type_decl_set);
  2295. end;
  2296. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2297. begin
  2298. inherited ppuloaddef(ppufile);
  2299. deftype:=setdef;
  2300. ppufile.gettype(elementtype);
  2301. settype:=tsettype(ppufile.getbyte);
  2302. case settype of
  2303. normset : savesize:=32;
  2304. varset : savesize:=ppufile.getlongint;
  2305. smallset : savesize:=Sizeof(longint);
  2306. end;
  2307. end;
  2308. destructor tsetdef.destroy;
  2309. begin
  2310. inherited destroy;
  2311. end;
  2312. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2313. begin
  2314. inherited ppuwritedef(ppufile);
  2315. ppufile.puttype(elementtype);
  2316. ppufile.putbyte(byte(settype));
  2317. if settype=varset then
  2318. ppufile.putlongint(savesize);
  2319. ppufile.writeentry(ibsetdef);
  2320. end;
  2321. {$ifdef GDB}
  2322. function tsetdef.stabstring : pchar;
  2323. begin
  2324. stabstring:=stabstr_evaluate('@s$1;S$2',[tostr(savesize*8),tstoreddef(elementtype.def).numberstring]);
  2325. end;
  2326. procedure tsetdef.concatstabto(asmlist:taasmoutput);
  2327. begin
  2328. if (stab_state in [stab_state_writing,stab_state_written]) then
  2329. exit;
  2330. tstoreddef(elementtype.def).concatstabto(asmlist);
  2331. inherited concatstabto(asmlist);
  2332. end;
  2333. {$endif GDB}
  2334. procedure tsetdef.buildderef;
  2335. begin
  2336. inherited buildderef;
  2337. elementtype.buildderef;
  2338. end;
  2339. procedure tsetdef.deref;
  2340. begin
  2341. inherited deref;
  2342. elementtype.resolve;
  2343. end;
  2344. procedure tsetdef.write_child_rtti_data(rt:trttitype);
  2345. begin
  2346. tstoreddef(elementtype.def).get_rtti_label(rt);
  2347. end;
  2348. procedure tsetdef.write_rtti_data(rt:trttitype);
  2349. begin
  2350. rttiList.concat(Tai_const.Create_8bit(tkSet));
  2351. write_rtti_name;
  2352. rttiList.concat(Tai_const.Create_8bit(otULong));
  2353. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2354. end;
  2355. function tsetdef.is_publishable : boolean;
  2356. begin
  2357. is_publishable:=(settype=smallset);
  2358. end;
  2359. function tsetdef.gettypename : string;
  2360. begin
  2361. if assigned(elementtype.def) then
  2362. gettypename:='Set Of '+elementtype.def.typename
  2363. else
  2364. gettypename:='Empty Set';
  2365. end;
  2366. {***************************************************************************
  2367. TFORMALDEF
  2368. ***************************************************************************}
  2369. constructor tformaldef.create;
  2370. var
  2371. stregdef : boolean;
  2372. begin
  2373. stregdef:=registerdef;
  2374. registerdef:=false;
  2375. inherited create;
  2376. deftype:=formaldef;
  2377. registerdef:=stregdef;
  2378. { formaldef must be registered at unit level !! }
  2379. if registerdef and assigned(current_module) then
  2380. if assigned(current_module.localsymtable) then
  2381. tsymtable(current_module.localsymtable).registerdef(self)
  2382. else if assigned(current_module.globalsymtable) then
  2383. tsymtable(current_module.globalsymtable).registerdef(self);
  2384. savesize:=0;
  2385. end;
  2386. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2387. begin
  2388. inherited ppuloaddef(ppufile);
  2389. deftype:=formaldef;
  2390. savesize:=0;
  2391. end;
  2392. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2393. begin
  2394. inherited ppuwritedef(ppufile);
  2395. ppufile.writeentry(ibformaldef);
  2396. end;
  2397. {$ifdef GDB}
  2398. function tformaldef.stabstring : pchar;
  2399. begin
  2400. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2401. end;
  2402. function tformaldef.numberstring:string;
  2403. begin
  2404. result:=tstoreddef(voidtype.def).numberstring;
  2405. end;
  2406. procedure tformaldef.concatstabto(asmlist : taasmoutput);
  2407. begin
  2408. { formaldef can't be stab'ed !}
  2409. end;
  2410. {$endif GDB}
  2411. function tformaldef.gettypename : string;
  2412. begin
  2413. gettypename:='<Formal type>';
  2414. end;
  2415. {***************************************************************************
  2416. TARRAYDEF
  2417. ***************************************************************************}
  2418. constructor tarraydef.create(l,h : longint;const t : ttype);
  2419. begin
  2420. inherited create;
  2421. deftype:=arraydef;
  2422. lowrange:=l;
  2423. highrange:=h;
  2424. rangetype:=t;
  2425. elementtype.reset;
  2426. IsVariant:=false;
  2427. IsConstructor:=false;
  2428. IsArrayOfConst:=false;
  2429. IsDynamicArray:=false;
  2430. IsConvertedPointer:=false;
  2431. end;
  2432. constructor tarraydef.create_from_pointer(const elemt : ttype);
  2433. begin
  2434. self.create(0,$7fffffff,s32inttype);
  2435. IsConvertedPointer:=true;
  2436. setelementtype(elemt);
  2437. end;
  2438. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2439. begin
  2440. inherited ppuloaddef(ppufile);
  2441. deftype:=arraydef;
  2442. { the addresses are calculated later }
  2443. ppufile.gettype(_elementtype);
  2444. ppufile.gettype(rangetype);
  2445. lowrange:=ppufile.getlongint;
  2446. highrange:=ppufile.getlongint;
  2447. IsArrayOfConst:=boolean(ppufile.getbyte);
  2448. IsDynamicArray:=boolean(ppufile.getbyte);
  2449. IsVariant:=false;
  2450. IsConstructor:=false;
  2451. end;
  2452. procedure tarraydef.buildderef;
  2453. begin
  2454. inherited buildderef;
  2455. _elementtype.buildderef;
  2456. rangetype.buildderef;
  2457. end;
  2458. procedure tarraydef.deref;
  2459. begin
  2460. inherited deref;
  2461. _elementtype.resolve;
  2462. rangetype.resolve;
  2463. end;
  2464. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2465. begin
  2466. inherited ppuwritedef(ppufile);
  2467. ppufile.puttype(_elementtype);
  2468. ppufile.puttype(rangetype);
  2469. ppufile.putlongint(lowrange);
  2470. ppufile.putlongint(highrange);
  2471. ppufile.putbyte(byte(IsArrayOfConst));
  2472. ppufile.putbyte(byte(IsDynamicArray));
  2473. ppufile.writeentry(ibarraydef);
  2474. end;
  2475. {$ifdef GDB}
  2476. function tarraydef.stabstring : pchar;
  2477. begin
  2478. stabstring:=stabstr_evaluate('ar$1;$2;$3;$4',[Tstoreddef(rangetype.def).numberstring,
  2479. tostr(lowrange),tostr(highrange),Tstoreddef(_elementtype.def).numberstring]);
  2480. end;
  2481. procedure tarraydef.concatstabto(asmlist:taasmoutput);
  2482. begin
  2483. if (stab_state in [stab_state_writing,stab_state_written]) then
  2484. exit;
  2485. tstoreddef(rangetype.def).concatstabto(asmlist);
  2486. tstoreddef(_elementtype.def).concatstabto(asmlist);
  2487. inherited concatstabto(asmlist);
  2488. end;
  2489. {$endif GDB}
  2490. function tarraydef.elesize : longint;
  2491. begin
  2492. elesize:=_elementtype.def.size;
  2493. end;
  2494. function tarraydef.size : longint;
  2495. var
  2496. newsize : TConstExprInt;
  2497. begin
  2498. if IsDynamicArray then
  2499. begin
  2500. size:=sizeof(aint);
  2501. exit;
  2502. end;
  2503. {Tarraydef.size may never be called for an open array!}
  2504. if highrange<lowrange then
  2505. internalerror(99080501);
  2506. newsize:=(int64(highrange)-int64(lowrange)+1)*elesize;
  2507. { prevent an overflow }
  2508. if newsize>high(longint) then
  2509. result:=high(longint)
  2510. else
  2511. result:=newsize;
  2512. end;
  2513. procedure tarraydef.setelementtype(t: ttype);
  2514. var
  2515. cachedsize : TConstExprInt;
  2516. begin
  2517. _elementtype:=t;
  2518. if not(IsDynamicArray or
  2519. IsConvertedPointer or
  2520. (highrange<lowrange)) then
  2521. begin
  2522. { cache element size for performance on multidimensional arrays }
  2523. cachedsize := elesize;
  2524. if (cachedsize>0) and
  2525. (
  2526. {$ifdef cpu64bit}
  2527. {$ifdef VER1_0}
  2528. { 1.0.x can't handle this and while bootstrapping with 1.0.x we can forget about it }
  2529. false
  2530. {$else}
  2531. (TConstExprInt(highrange)-TConstExprInt(lowrange) > $7fffffffffffffff) or
  2532. { () are needed around cachedsize-1 to avoid a possible
  2533. integer overflow for cachedsize=1 !! PM }
  2534. (($7fffffffffffffff div cachedsize + (cachedsize -1)) < (int64(highrange) - int64(lowrange)))
  2535. {$endif VER1_0}
  2536. {$else cpu64bit}
  2537. (TConstExprInt(highrange)-TConstExprInt(lowrange) > $7fffffff) or
  2538. { () are needed around cachedsize-1 to avoid a possible
  2539. integer overflow for cachedsize=1 !! PM }
  2540. (($7fffffff div cachedsize + (cachedsize -1)) < (int64(highrange) - int64(lowrange)))
  2541. {$endif cpu64bit}
  2542. ) Then
  2543. Message(sym_e_segment_too_large);
  2544. end;
  2545. end;
  2546. function tarraydef.alignment : longint;
  2547. begin
  2548. { alignment is the size of the elements }
  2549. if elementtype.def.deftype=recorddef then
  2550. alignment:=elementtype.def.alignment
  2551. else
  2552. alignment:=elesize;
  2553. end;
  2554. function tarraydef.needs_inittable : boolean;
  2555. begin
  2556. needs_inittable:=IsDynamicArray or elementtype.def.needs_inittable;
  2557. end;
  2558. procedure tarraydef.write_child_rtti_data(rt:trttitype);
  2559. begin
  2560. tstoreddef(elementtype.def).get_rtti_label(rt);
  2561. end;
  2562. procedure tarraydef.write_rtti_data(rt:trttitype);
  2563. begin
  2564. if IsDynamicArray then
  2565. rttiList.concat(Tai_const.Create_8bit(tkdynarray))
  2566. else
  2567. rttiList.concat(Tai_const.Create_8bit(tkarray));
  2568. write_rtti_name;
  2569. { size of elements }
  2570. rttiList.concat(Tai_const.Create_32bit(elesize));
  2571. { count of elements, prevent overflow for 0..maxlongint }
  2572. if not(IsDynamicArray) then
  2573. rttiList.concat(Tai_const.Create_32bit(min(int64(highrange)-lowrange+1,maxlongint)));
  2574. { element type }
  2575. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2576. { variant type }
  2577. // !!!!!!!!!!!!!!!!
  2578. end;
  2579. function tarraydef.gettypename : string;
  2580. begin
  2581. if isarrayofconst or isConstructor then
  2582. begin
  2583. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2584. gettypename:='Array Of Const'
  2585. else
  2586. gettypename:='Array Of '+elementtype.def.typename;
  2587. end
  2588. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2589. gettypename:='Array Of '+elementtype.def.typename
  2590. else
  2591. begin
  2592. if rangetype.def.deftype=enumdef then
  2593. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2594. else
  2595. gettypename:='Array['+tostr(lowrange)+'..'+
  2596. tostr(highrange)+'] Of '+elementtype.def.typename
  2597. end;
  2598. end;
  2599. function tarraydef.getmangledparaname : string;
  2600. begin
  2601. if isarrayofconst then
  2602. getmangledparaname:='array_of_const'
  2603. else
  2604. if ((highrange=-1) and (lowrange=0)) then
  2605. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2606. else
  2607. internalerror(200204176);
  2608. end;
  2609. {***************************************************************************
  2610. tabstractrecorddef
  2611. ***************************************************************************}
  2612. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2613. begin
  2614. if t=gs_record then
  2615. getsymtable:=symtable
  2616. else
  2617. getsymtable:=nil;
  2618. end;
  2619. {$ifdef GDB}
  2620. procedure tabstractrecorddef.field_addname(p:Tnamedindexitem;arg:pointer);
  2621. var
  2622. newrec:Pchar;
  2623. spec:string[3];
  2624. varsize:longint;
  2625. state:^Trecord_stabgen_state;
  2626. begin
  2627. state:=arg;
  2628. { static variables from objects are like global objects }
  2629. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2630. begin
  2631. if (sp_protected in tsym(p).symoptions) then
  2632. spec:='/1'
  2633. else if (sp_private in tsym(p).symoptions) then
  2634. spec:='/0'
  2635. else
  2636. spec:='';
  2637. varsize:=tvarsym(p).vartype.def.size;
  2638. { open arrays made overflows !! }
  2639. if varsize>$fffffff then
  2640. varsize:=$fffffff;
  2641. newrec:=stabstr_evaluate('$1:$2,$3,$4;',[p.name,
  2642. spec+tstoreddef(tvarsym(p).vartype.def).numberstring,
  2643. tostr(tvarsym(p).fieldoffset*8),tostr(varsize*8)]);
  2644. if state^.stabsize+strlen(newrec)>=state^.staballoc-256 then
  2645. begin
  2646. inc(state^.staballoc,memsizeinc);
  2647. reallocmem(state^.stabstring,state^.staballoc);
  2648. end;
  2649. strcopy(state^.stabstring+state^.stabsize,newrec);
  2650. inc(state^.stabsize,strlen(newrec));
  2651. strdispose(newrec);
  2652. {This should be used for case !!}
  2653. inc(state^.recoffset,Tvarsym(p).vartype.def.size);
  2654. end;
  2655. end;
  2656. procedure tabstractrecorddef.field_concatstabto(p:Tnamedindexitem;arg:pointer);
  2657. begin
  2658. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2659. tstoreddef(tvarsym(p).vartype.def).concatstabto(taasmoutput(arg));
  2660. end;
  2661. {$endif GDB}
  2662. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2663. begin
  2664. if (FRTTIType=fullrtti) or
  2665. ((tsym(sym).typ=varsym) and
  2666. tvarsym(sym).vartype.def.needs_inittable) then
  2667. inc(Count);
  2668. end;
  2669. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2670. begin
  2671. if (FRTTIType=fullrtti) or
  2672. ((tsym(sym).typ=varsym) and
  2673. tvarsym(sym).vartype.def.needs_inittable) then
  2674. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2675. end;
  2676. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2677. begin
  2678. if (FRTTIType=fullrtti) or
  2679. ((tsym(sym).typ=varsym) and
  2680. tvarsym(sym).vartype.def.needs_inittable) then
  2681. begin
  2682. rttiList.concat(Tai_const.Create_sym(tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2683. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  2684. end;
  2685. end;
  2686. {***************************************************************************
  2687. trecorddef
  2688. ***************************************************************************}
  2689. constructor trecorddef.create(p : tsymtable);
  2690. begin
  2691. inherited create;
  2692. deftype:=recorddef;
  2693. symtable:=p;
  2694. symtable.defowner:=self;
  2695. isunion:=false;
  2696. end;
  2697. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2698. begin
  2699. inherited ppuloaddef(ppufile);
  2700. deftype:=recorddef;
  2701. savesize:=ppufile.getlongint;
  2702. symtable:=trecordsymtable.create(0);
  2703. trecordsymtable(symtable).datasize:=ppufile.getlongint;
  2704. trecordsymtable(symtable).fieldalignment:=ppufile.getbyte;
  2705. trecordsymtable(symtable).recordalignment:=ppufile.getbyte;
  2706. trecordsymtable(symtable).ppuload(ppufile);
  2707. symtable.defowner:=self;
  2708. isunion:=false;
  2709. end;
  2710. destructor trecorddef.destroy;
  2711. begin
  2712. if assigned(symtable) then
  2713. symtable.free;
  2714. inherited destroy;
  2715. end;
  2716. function trecorddef.needs_inittable : boolean;
  2717. begin
  2718. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2719. end;
  2720. procedure trecorddef.buildderef;
  2721. var
  2722. oldrecsyms : tsymtable;
  2723. begin
  2724. inherited buildderef;
  2725. oldrecsyms:=aktrecordsymtable;
  2726. aktrecordsymtable:=symtable;
  2727. { now build the definitions }
  2728. tstoredsymtable(symtable).buildderef;
  2729. aktrecordsymtable:=oldrecsyms;
  2730. end;
  2731. procedure trecorddef.deref;
  2732. var
  2733. oldrecsyms : tsymtable;
  2734. begin
  2735. inherited deref;
  2736. oldrecsyms:=aktrecordsymtable;
  2737. aktrecordsymtable:=symtable;
  2738. { now dereference the definitions }
  2739. tstoredsymtable(symtable).deref;
  2740. aktrecordsymtable:=oldrecsyms;
  2741. { assign TGUID? load only from system unit (unitid=1) }
  2742. if not(assigned(rec_tguid)) and
  2743. (upper(typename)='TGUID') and
  2744. assigned(owner) and
  2745. assigned(owner.name) and
  2746. (owner.name^='SYSTEM') then
  2747. rec_tguid:=self;
  2748. end;
  2749. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2750. begin
  2751. inherited ppuwritedef(ppufile);
  2752. ppufile.putlongint(savesize);
  2753. ppufile.putlongint(trecordsymtable(symtable).datasize);
  2754. ppufile.putbyte(trecordsymtable(symtable).fieldalignment);
  2755. ppufile.putbyte(trecordsymtable(symtable).recordalignment);
  2756. ppufile.writeentry(ibrecorddef);
  2757. trecordsymtable(symtable).ppuwrite(ppufile);
  2758. end;
  2759. function trecorddef.size:longint;
  2760. begin
  2761. result:=trecordsymtable(symtable).datasize;
  2762. end;
  2763. function trecorddef.alignment:longint;
  2764. begin
  2765. alignment:=trecordsymtable(symtable).recordalignment;
  2766. end;
  2767. {$ifdef GDB}
  2768. function trecorddef.stabstring : pchar;
  2769. var
  2770. state:Trecord_stabgen_state;
  2771. begin
  2772. getmem(state.stabstring,memsizeinc);
  2773. state.staballoc:=memsizeinc;
  2774. strpcopy(state.stabstring,'s'+tostr(size));
  2775. state.recoffset:=0;
  2776. state.stabsize:=strlen(state.stabstring);
  2777. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_addname,@state);
  2778. state.stabstring[state.stabsize]:=';';
  2779. state.stabstring[state.stabsize+1]:=#0;
  2780. reallocmem(state.stabstring,state.stabsize+2);
  2781. stabstring:=state.stabstring;
  2782. end;
  2783. procedure trecorddef.concatstabto(asmlist:taasmoutput);
  2784. begin
  2785. if (stab_state in [stab_state_writing,stab_state_written]) then
  2786. exit;
  2787. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_concatstabto,asmlist);
  2788. inherited concatstabto(asmlist);
  2789. end;
  2790. {$endif GDB}
  2791. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2792. begin
  2793. FRTTIType:=rt;
  2794. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  2795. end;
  2796. procedure trecorddef.write_rtti_data(rt:trttitype);
  2797. begin
  2798. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2799. write_rtti_name;
  2800. rttiList.concat(Tai_const.Create_32bit(size));
  2801. Count:=0;
  2802. FRTTIType:=rt;
  2803. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  2804. rttiList.concat(Tai_const.Create_32bit(Count));
  2805. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  2806. end;
  2807. function trecorddef.gettypename : string;
  2808. begin
  2809. gettypename:='<record type>'
  2810. end;
  2811. {***************************************************************************
  2812. TABSTRACTPROCDEF
  2813. ***************************************************************************}
  2814. constructor tabstractprocdef.create(level:byte);
  2815. begin
  2816. inherited create;
  2817. parast:=tparasymtable.create(level);
  2818. parast.defowner:=self;
  2819. parast.next:=owner;
  2820. para:=TLinkedList.Create;
  2821. minparacount:=0;
  2822. maxparacount:=0;
  2823. proctypeoption:=potype_none;
  2824. proccalloption:=pocall_none;
  2825. procoptions:=[];
  2826. rettype:=voidtype;
  2827. {$ifdef i386}
  2828. fpu_used:=0;
  2829. {$endif i386}
  2830. savesize:=sizeof(aint);
  2831. requiredargarea:=0;
  2832. has_paraloc_info:=false;
  2833. end;
  2834. destructor tabstractprocdef.destroy;
  2835. begin
  2836. if assigned(para) then
  2837. begin
  2838. {$ifdef MEMDEBUG}
  2839. memprocpara.start;
  2840. {$endif MEMDEBUG}
  2841. para.free;
  2842. {$ifdef MEMDEBUG}
  2843. memprocpara.stop;
  2844. {$endif MEMDEBUG}
  2845. end;
  2846. if assigned(parast) then
  2847. begin
  2848. {$ifdef MEMDEBUG}
  2849. memprocparast.start;
  2850. {$endif MEMDEBUG}
  2851. parast.free;
  2852. {$ifdef MEMDEBUG}
  2853. memprocparast.stop;
  2854. {$endif MEMDEBUG}
  2855. end;
  2856. inherited destroy;
  2857. end;
  2858. procedure tabstractprocdef.releasemem;
  2859. begin
  2860. para.free;
  2861. para:=nil;
  2862. parast.free;
  2863. parast:=nil;
  2864. end;
  2865. function tabstractprocdef.concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2866. var
  2867. hp : TParaItem;
  2868. begin
  2869. hp:=TParaItem.Create;
  2870. hp.paratyp:=tvarsym(sym).varspez;
  2871. hp.parasym:=sym;
  2872. hp.paratype:=tt;
  2873. hp.is_hidden:=vhidden;
  2874. hp.defaultvalue:=defval;
  2875. { Parameters are stored from left to right }
  2876. if assigned(afterpara) then
  2877. Para.insertafter(hp,afterpara)
  2878. else
  2879. Para.concat(hp);
  2880. { Don't count hidden parameters }
  2881. if not vhidden then
  2882. begin
  2883. if not assigned(defval) then
  2884. inc(minparacount);
  2885. inc(maxparacount);
  2886. end;
  2887. concatpara:=hp;
  2888. end;
  2889. function tabstractprocdef.insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2890. var
  2891. hp : TParaItem;
  2892. begin
  2893. hp:=TParaItem.Create;
  2894. hp.paratyp:=tvarsym(sym).varspez;
  2895. hp.parasym:=sym;
  2896. hp.paratype:=tt;
  2897. hp.is_hidden:=vhidden;
  2898. hp.defaultvalue:=defval;
  2899. { Parameters are stored from left to right }
  2900. Para.insert(hp);
  2901. { Don't count hidden parameters }
  2902. if (not vhidden) then
  2903. begin
  2904. if not assigned(defval) then
  2905. inc(minparacount);
  2906. inc(maxparacount);
  2907. end;
  2908. insertpara:=hp;
  2909. end;
  2910. procedure tabstractprocdef.removepara(currpara:tparaitem);
  2911. begin
  2912. { Don't count hidden parameters }
  2913. if (not currpara.is_hidden) then
  2914. begin
  2915. if not assigned(currpara.defaultvalue) then
  2916. dec(minparacount);
  2917. dec(maxparacount);
  2918. end;
  2919. Para.Remove(currpara);
  2920. currpara.free;
  2921. end;
  2922. { all functions returning in FPU are
  2923. assume to use 2 FPU registers
  2924. until the function implementation
  2925. is processed PM }
  2926. procedure tabstractprocdef.test_if_fpu_result;
  2927. begin
  2928. {$ifdef i386}
  2929. if assigned(rettype.def) and
  2930. (rettype.def.deftype=floatdef) then
  2931. fpu_used:=maxfpuregs;
  2932. {$endif i386}
  2933. end;
  2934. procedure tabstractprocdef.buildderef;
  2935. var
  2936. hp : TParaItem;
  2937. begin
  2938. { released procdef? }
  2939. if not assigned(parast) then
  2940. exit;
  2941. inherited buildderef;
  2942. rettype.buildderef;
  2943. { parast }
  2944. tparasymtable(parast).buildderef;
  2945. { paraitems }
  2946. hp:=TParaItem(Para.first);
  2947. while assigned(hp) do
  2948. begin
  2949. hp.paratype.buildderef;
  2950. hp.defaultvaluederef.build(hp.defaultvalue);
  2951. hp.parasymderef.build(hp.parasym);
  2952. hp:=TParaItem(hp.next);
  2953. end;
  2954. end;
  2955. procedure tabstractprocdef.deref;
  2956. var
  2957. hp : TParaItem;
  2958. begin
  2959. inherited deref;
  2960. rettype.resolve;
  2961. { parast }
  2962. tparasymtable(parast).deref;
  2963. { paraitems }
  2964. minparacount:=0;
  2965. maxparacount:=0;
  2966. hp:=TParaItem(Para.first);
  2967. while assigned(hp) do
  2968. begin
  2969. hp.paratype.resolve;
  2970. hp.defaultvalue:=tsym(hp.defaultvaluederef.resolve);
  2971. hp.parasym:=tvarsym(hp.parasymderef.resolve);
  2972. { connect parasym to paraitem }
  2973. tvarsym(hp.parasym).paraitem:=hp;
  2974. { Don't count hidden parameters }
  2975. if (not hp.is_hidden) then
  2976. begin
  2977. if not assigned(hp.defaultvalue) then
  2978. inc(minparacount);
  2979. inc(maxparacount);
  2980. end;
  2981. hp:=TParaItem(hp.next);
  2982. end;
  2983. end;
  2984. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  2985. var
  2986. hp : TParaItem;
  2987. count,i : word;
  2988. begin
  2989. inherited ppuloaddef(ppufile);
  2990. parast:=nil;
  2991. Para:=TLinkedList.Create;
  2992. minparacount:=0;
  2993. maxparacount:=0;
  2994. ppufile.gettype(rettype);
  2995. {$ifdef i386}
  2996. fpu_used:=ppufile.getbyte;
  2997. {$else}
  2998. ppufile.getbyte;
  2999. {$endif i386}
  3000. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3001. proccalloption:=tproccalloption(ppufile.getbyte);
  3002. ppufile.getsmallset(procoptions);
  3003. { get the number of parameters }
  3004. count:=ppufile.getbyte;
  3005. savesize:=sizeof(aint);
  3006. has_paraloc_info:=false;
  3007. for i:=1 to count do
  3008. begin
  3009. hp:=TParaItem.Create;
  3010. hp.paratyp:=tvarspez(ppufile.getbyte);
  3011. ppufile.gettype(hp.paratype);
  3012. ppufile.getderef(hp.defaultvaluederef);
  3013. hp.defaultvalue:=nil;
  3014. ppufile.getderef(hp.parasymderef);
  3015. hp.parasym:=nil;
  3016. hp.is_hidden:=boolean(ppufile.getbyte);
  3017. if po_explicitparaloc in procoptions then
  3018. begin
  3019. if po_explicitparaloc in procoptions then
  3020. ppufile.getdata(hp.paraloc,sizeof(hp.paraloc));
  3021. has_paraloc_info:=true;
  3022. end;
  3023. { Parameters are stored left to right in both ppu and memory }
  3024. Para.concat(hp);
  3025. end;
  3026. end;
  3027. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3028. var
  3029. hp : TParaItem;
  3030. oldintfcrc : boolean;
  3031. begin
  3032. { released procdef? }
  3033. if not assigned(parast) then
  3034. exit;
  3035. inherited ppuwritedef(ppufile);
  3036. ppufile.puttype(rettype);
  3037. oldintfcrc:=ppufile.do_interface_crc;
  3038. ppufile.do_interface_crc:=false;
  3039. {$ifdef i386}
  3040. if simplify_ppu then
  3041. fpu_used:=0;
  3042. ppufile.putbyte(fpu_used);
  3043. {$else}
  3044. ppufile.putbyte(0);
  3045. {$endif}
  3046. ppufile.putbyte(ord(proctypeoption));
  3047. ppufile.putbyte(ord(proccalloption));
  3048. ppufile.putsmallset(procoptions);
  3049. ppufile.do_interface_crc:=oldintfcrc;
  3050. { we need to store the count including vs_hidden }
  3051. ppufile.putbyte(para.count);
  3052. hp:=TParaItem(Para.first);
  3053. while assigned(hp) do
  3054. begin
  3055. ppufile.putbyte(byte(hp.paratyp));
  3056. ppufile.puttype(hp.paratype);
  3057. ppufile.putderef(hp.defaultvaluederef);
  3058. ppufile.putderef(hp.parasymderef);
  3059. ppufile.putbyte(byte(hp.is_hidden));
  3060. if po_explicitparaloc in procoptions then
  3061. ppufile.putdata(hp.paraloc,sizeof(hp.paraloc));
  3062. hp:=TParaItem(hp.next);
  3063. end;
  3064. end;
  3065. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  3066. var
  3067. hs,s : string;
  3068. hp : TParaItem;
  3069. hpc : tconstsym;
  3070. first : boolean;
  3071. begin
  3072. hp:=TParaItem(Para.first);
  3073. s:='';
  3074. first:=true;
  3075. while assigned(hp) do
  3076. begin
  3077. if (not hp.is_hidden) or
  3078. (showhidden) then
  3079. begin
  3080. if first then
  3081. begin
  3082. s:=s+'(';
  3083. first:=false;
  3084. end
  3085. else
  3086. s:=s+',';
  3087. case hp.paratyp of
  3088. vs_var :
  3089. s:=s+'var';
  3090. vs_const :
  3091. s:=s+'const';
  3092. vs_out :
  3093. s:=s+'out';
  3094. end;
  3095. if assigned(hp.paratype.def.typesym) then
  3096. begin
  3097. if s<>'(' then
  3098. s:=s+' ';
  3099. hs:=hp.paratype.def.typesym.realname;
  3100. if hs[1]<>'$' then
  3101. s:=s+hp.paratype.def.typesym.realname
  3102. else
  3103. s:=s+hp.paratype.def.gettypename;
  3104. end
  3105. else
  3106. s:=s+hp.paratype.def.gettypename;
  3107. { default value }
  3108. if assigned(hp.defaultvalue) then
  3109. begin
  3110. hpc:=tconstsym(hp.defaultvalue);
  3111. hs:='';
  3112. case hpc.consttyp of
  3113. conststring,
  3114. constresourcestring :
  3115. hs:=strpas(pchar(hpc.value.valueptr));
  3116. constreal :
  3117. str(pbestreal(hpc.value.valueptr)^,hs);
  3118. constpointer :
  3119. hs:=tostr(hpc.value.valueordptr);
  3120. constord :
  3121. begin
  3122. if is_boolean(hpc.consttype.def) then
  3123. begin
  3124. if hpc.value.valueord<>0 then
  3125. hs:='TRUE'
  3126. else
  3127. hs:='FALSE';
  3128. end
  3129. else
  3130. hs:=tostr(hpc.value.valueord);
  3131. end;
  3132. constnil :
  3133. hs:='nil';
  3134. constset :
  3135. hs:='<set>';
  3136. end;
  3137. if hs<>'' then
  3138. s:=s+'="'+hs+'"';
  3139. end;
  3140. end;
  3141. hp:=TParaItem(hp.next);
  3142. end;
  3143. if not first then
  3144. s:=s+')';
  3145. if (po_varargs in procoptions) then
  3146. s:=s+';VarArgs';
  3147. typename_paras:=s;
  3148. end;
  3149. function tabstractprocdef.is_methodpointer:boolean;
  3150. begin
  3151. result:=false;
  3152. end;
  3153. function tabstractprocdef.is_addressonly:boolean;
  3154. begin
  3155. result:=true;
  3156. end;
  3157. {$ifdef GDB}
  3158. function tabstractprocdef.stabstring : pchar;
  3159. begin
  3160. stabstring := strpnew('abstractproc'+numberstring+';');
  3161. end;
  3162. {$endif GDB}
  3163. {***************************************************************************
  3164. TPROCDEF
  3165. ***************************************************************************}
  3166. constructor tprocdef.create(level:byte);
  3167. begin
  3168. inherited create(level);
  3169. deftype:=procdef;
  3170. has_mangledname:=false;
  3171. _mangledname:=nil;
  3172. fileinfo:=aktfilepos;
  3173. extnumber:=$ffff;
  3174. aliasnames:=tstringlist.create;
  3175. funcretsym:=nil;
  3176. localst := nil;
  3177. defref:=nil;
  3178. lastwritten:=nil;
  3179. refcount:=0;
  3180. if (cs_browser in aktmoduleswitches) and make_ref then
  3181. begin
  3182. defref:=tref.create(defref,@akttokenpos);
  3183. inc(refcount);
  3184. end;
  3185. lastref:=defref;
  3186. forwarddef:=true;
  3187. interfacedef:=false;
  3188. hasforward:=false;
  3189. _class := nil;
  3190. new(inlininginfo);
  3191. fillchar(inlininginfo^,sizeof(tinlininginfo),0);
  3192. overloadnumber:=0;
  3193. {$ifdef GDB}
  3194. isstabwritten := false;
  3195. {$endif GDB}
  3196. end;
  3197. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3198. var
  3199. level : byte;
  3200. begin
  3201. inherited ppuload(ppufile);
  3202. deftype:=procdef;
  3203. has_mangledname:=boolean(ppufile.getbyte);
  3204. if has_mangledname then
  3205. _mangledname:=stringdup(ppufile.getstring)
  3206. else
  3207. _mangledname:=nil;
  3208. overloadnumber:=ppufile.getword;
  3209. extnumber:=ppufile.getword;
  3210. level:=ppufile.getbyte;
  3211. ppufile.getderef(_classderef);
  3212. ppufile.getderef(procsymderef);
  3213. ppufile.getposinfo(fileinfo);
  3214. ppufile.getsmallset(symoptions);
  3215. {$ifdef powerpc}
  3216. { library symbol for AmigaOS/MorphOS }
  3217. ppufile.getderef(libsymderef);
  3218. {$endif powerpc}
  3219. { inline stuff }
  3220. if proccalloption=pocall_inline then
  3221. begin
  3222. ppufile.getderef(funcretsymderef);
  3223. new(inlininginfo);
  3224. ppufile.getsmallset(inlininginfo^.flags);
  3225. end
  3226. else
  3227. funcretsym:=nil;
  3228. { load para symtable }
  3229. parast:=tparasymtable.create(level);
  3230. tparasymtable(parast).ppuload(ppufile);
  3231. parast.defowner:=self;
  3232. { load local symtable }
  3233. if (proccalloption=pocall_inline) or
  3234. ((current_module.flags and uf_local_browser)<>0) then
  3235. begin
  3236. localst:=tlocalsymtable.create(level);
  3237. tlocalsymtable(localst).ppuload(ppufile);
  3238. localst.defowner:=self;
  3239. end
  3240. else
  3241. localst:=nil;
  3242. { inline stuff }
  3243. if proccalloption=pocall_inline then
  3244. inlininginfo^.code:=ppuloadnodetree(ppufile)
  3245. else
  3246. inlininginfo := nil;
  3247. { default values for no persistent data }
  3248. if (cs_link_deffile in aktglobalswitches) and
  3249. (tf_need_export in target_info.flags) and
  3250. (po_exports in procoptions) then
  3251. deffile.AddExport(mangledname);
  3252. aliasnames:=tstringlist.create;
  3253. forwarddef:=false;
  3254. interfacedef:=false;
  3255. hasforward:=false;
  3256. lastref:=nil;
  3257. lastwritten:=nil;
  3258. defref:=nil;
  3259. refcount:=0;
  3260. {$ifdef GDB}
  3261. isstabwritten := false;
  3262. {$endif GDB}
  3263. end;
  3264. destructor tprocdef.destroy;
  3265. begin
  3266. if assigned(defref) then
  3267. begin
  3268. defref.freechain;
  3269. defref.free;
  3270. end;
  3271. aliasnames.free;
  3272. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3273. begin
  3274. {$ifdef MEMDEBUG}
  3275. memproclocalst.start;
  3276. {$endif MEMDEBUG}
  3277. localst.free;
  3278. {$ifdef MEMDEBUG}
  3279. memproclocalst.start;
  3280. {$endif MEMDEBUG}
  3281. end;
  3282. if (proccalloption=pocall_inline) and assigned(inlininginfo) then
  3283. begin
  3284. {$ifdef MEMDEBUG}
  3285. memprocnodetree.start;
  3286. {$endif MEMDEBUG}
  3287. tnode(inlininginfo^.code).free;
  3288. {$ifdef MEMDEBUG}
  3289. memprocnodetree.start;
  3290. {$endif MEMDEBUG}
  3291. end;
  3292. if assigned(inlininginfo) then
  3293. dispose(inlininginfo);
  3294. if (po_msgstr in procoptions) then
  3295. strdispose(messageinf.str);
  3296. if assigned(_mangledname) then
  3297. begin
  3298. {$ifdef MEMDEBUG}
  3299. memmanglednames.start;
  3300. {$endif MEMDEBUG}
  3301. stringdispose(_mangledname);
  3302. {$ifdef MEMDEBUG}
  3303. memmanglednames.stop;
  3304. {$endif MEMDEBUG}
  3305. end;
  3306. inherited destroy;
  3307. end;
  3308. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3309. var
  3310. oldintfcrc : boolean;
  3311. oldparasymtable,
  3312. oldlocalsymtable : tsymtable;
  3313. begin
  3314. { released procdef? }
  3315. if not assigned(parast) then
  3316. exit;
  3317. oldparasymtable:=aktparasymtable;
  3318. oldlocalsymtable:=aktlocalsymtable;
  3319. aktparasymtable:=parast;
  3320. aktlocalsymtable:=localst;
  3321. inherited ppuwrite(ppufile);
  3322. oldintfcrc:=ppufile.do_interface_crc;
  3323. ppufile.do_interface_crc:=false;
  3324. ppufile.do_interface_crc:=oldintfcrc;
  3325. ppufile.putbyte(byte(has_mangledname));
  3326. if has_mangledname then
  3327. ppufile.putstring(_mangledname^);
  3328. ppufile.putword(overloadnumber);
  3329. ppufile.putword(extnumber);
  3330. ppufile.putbyte(parast.symtablelevel);
  3331. ppufile.putderef(_classderef);
  3332. ppufile.putderef(procsymderef);
  3333. ppufile.putposinfo(fileinfo);
  3334. ppufile.putsmallset(symoptions);
  3335. {$ifdef powerpc}
  3336. { library symbol for AmigaOS/MorphOS }
  3337. ppufile.putderef(libsymderef);
  3338. {$endif powerpc}
  3339. { inline stuff }
  3340. oldintfcrc:=ppufile.do_crc;
  3341. ppufile.do_crc:=false;
  3342. if proccalloption=pocall_inline then
  3343. begin
  3344. ppufile.putderef(funcretsymderef);
  3345. ppufile.putsmallset(inlininginfo^.flags);
  3346. end;
  3347. ppufile.do_crc:=oldintfcrc;
  3348. { write this entry }
  3349. ppufile.writeentry(ibprocdef);
  3350. { Save the para symtable, this is taken from the interface }
  3351. tparasymtable(parast).ppuwrite(ppufile);
  3352. { save localsymtable for inline procedures or when local
  3353. browser info is requested, this has no influence on the crc }
  3354. if (proccalloption=pocall_inline) or
  3355. ((current_module.flags and uf_local_browser)<>0) then
  3356. begin
  3357. oldintfcrc:=ppufile.do_crc;
  3358. ppufile.do_crc:=false;
  3359. if not assigned(localst) then
  3360. insert_localst;
  3361. tlocalsymtable(localst).ppuwrite(ppufile);
  3362. ppufile.do_crc:=oldintfcrc;
  3363. end;
  3364. { node tree for inlining }
  3365. oldintfcrc:=ppufile.do_crc;
  3366. ppufile.do_crc:=false;
  3367. if proccalloption=pocall_inline then
  3368. ppuwritenodetree(ppufile,inlininginfo^.code);
  3369. ppufile.do_crc:=oldintfcrc;
  3370. aktparasymtable:=oldparasymtable;
  3371. aktlocalsymtable:=oldlocalsymtable;
  3372. end;
  3373. procedure tprocdef.insert_localst;
  3374. begin
  3375. localst:=tlocalsymtable.create(parast.symtablelevel);
  3376. localst.defowner:=self;
  3377. { this is used by insert
  3378. to check same names in parast and localst }
  3379. localst.next:=parast;
  3380. end;
  3381. function tprocdef.fullprocname(showhidden:boolean):string;
  3382. var
  3383. s : string;
  3384. t : ttoken;
  3385. begin
  3386. {$ifdef EXTDEBUG}
  3387. showhidden:=true;
  3388. {$endif EXTDEBUG}
  3389. s:='';
  3390. if assigned(_class) then
  3391. begin
  3392. if po_classmethod in procoptions then
  3393. s:=s+'class ';
  3394. s:=s+_class.objrealname^+'.';
  3395. end;
  3396. if proctypeoption=potype_operator then
  3397. begin
  3398. for t:=NOTOKEN to last_overloaded do
  3399. if procsym.realname='$'+overloaded_names[t] then
  3400. begin
  3401. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3402. break;
  3403. end;
  3404. end
  3405. else
  3406. s:=s+procsym.realname+typename_paras(showhidden);
  3407. case proctypeoption of
  3408. potype_constructor:
  3409. s:='constructor '+s;
  3410. potype_destructor:
  3411. s:='destructor '+s;
  3412. else
  3413. if assigned(rettype.def) and
  3414. not(is_void(rettype.def)) then
  3415. s:=s+':'+rettype.def.gettypename;
  3416. end;
  3417. { forced calling convention? }
  3418. if (po_hascallingconvention in procoptions) then
  3419. s:=s+';'+ProcCallOptionStr[proccalloption];
  3420. fullprocname:=s;
  3421. end;
  3422. function tprocdef.is_methodpointer:boolean;
  3423. begin
  3424. result:=assigned(_class);
  3425. end;
  3426. function tprocdef.is_addressonly:boolean;
  3427. begin
  3428. result:=assigned(owner) and
  3429. (owner.symtabletype<>objectsymtable);
  3430. end;
  3431. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3432. begin
  3433. is_visible_for_object:=false;
  3434. { private symbols are allowed when we are in the same
  3435. module as they are defined }
  3436. if (sp_private in symoptions) and
  3437. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3438. (owner.defowner.owner.unitid<>0) then
  3439. exit;
  3440. { protected symbols are vissible in the module that defines them and
  3441. also visible to related objects. The related object must be defined
  3442. in the current module }
  3443. if (sp_protected in symoptions) and
  3444. (
  3445. (
  3446. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3447. (owner.defowner.owner.unitid<>0)
  3448. ) and
  3449. not(
  3450. assigned(currobjdef) and
  3451. (currobjdef.owner.unitid=0) and
  3452. currobjdef.is_related(tobjectdef(owner.defowner))
  3453. )
  3454. ) then
  3455. exit;
  3456. is_visible_for_object:=true;
  3457. end;
  3458. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3459. begin
  3460. case t of
  3461. gs_local :
  3462. getsymtable:=localst;
  3463. gs_para :
  3464. getsymtable:=parast;
  3465. else
  3466. getsymtable:=nil;
  3467. end;
  3468. end;
  3469. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3470. var
  3471. pos : tfileposinfo;
  3472. move_last : boolean;
  3473. oldparasymtable,
  3474. oldlocalsymtable : tsymtable;
  3475. begin
  3476. oldparasymtable:=aktparasymtable;
  3477. oldlocalsymtable:=aktlocalsymtable;
  3478. aktparasymtable:=parast;
  3479. aktlocalsymtable:=localst;
  3480. move_last:=lastwritten=lastref;
  3481. while (not ppufile.endofentry) do
  3482. begin
  3483. ppufile.getposinfo(pos);
  3484. inc(refcount);
  3485. lastref:=tref.create(lastref,@pos);
  3486. lastref.is_written:=true;
  3487. if refcount=1 then
  3488. defref:=lastref;
  3489. end;
  3490. if move_last then
  3491. lastwritten:=lastref;
  3492. if ((current_module.flags and uf_local_browser)<>0) and
  3493. locals then
  3494. begin
  3495. tparasymtable(parast).load_references(ppufile,locals);
  3496. tlocalsymtable(localst).load_references(ppufile,locals);
  3497. end;
  3498. aktparasymtable:=oldparasymtable;
  3499. aktlocalsymtable:=oldlocalsymtable;
  3500. end;
  3501. Const
  3502. local_symtable_index : word = $8001;
  3503. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3504. var
  3505. ref : tref;
  3506. pdo : tobjectdef;
  3507. move_last : boolean;
  3508. d : tderef;
  3509. oldparasymtable,
  3510. oldlocalsymtable : tsymtable;
  3511. begin
  3512. d.reset;
  3513. move_last:=lastwritten=lastref;
  3514. if move_last and
  3515. (((current_module.flags and uf_local_browser)=0) or
  3516. not locals) then
  3517. exit;
  3518. oldparasymtable:=aktparasymtable;
  3519. oldlocalsymtable:=aktlocalsymtable;
  3520. aktparasymtable:=parast;
  3521. aktlocalsymtable:=localst;
  3522. { write address of this symbol }
  3523. d.build(self);
  3524. ppufile.putderef(d);
  3525. { write refs }
  3526. if assigned(lastwritten) then
  3527. ref:=lastwritten
  3528. else
  3529. ref:=defref;
  3530. while assigned(ref) do
  3531. begin
  3532. if ref.moduleindex=current_module.unit_index then
  3533. begin
  3534. ppufile.putposinfo(ref.posinfo);
  3535. ref.is_written:=true;
  3536. if move_last then
  3537. lastwritten:=ref;
  3538. end
  3539. else if not ref.is_written then
  3540. move_last:=false
  3541. else if move_last then
  3542. lastwritten:=ref;
  3543. ref:=ref.nextref;
  3544. end;
  3545. ppufile.writeentry(ibdefref);
  3546. write_references:=true;
  3547. if ((current_module.flags and uf_local_browser)<>0) and
  3548. locals then
  3549. begin
  3550. pdo:=_class;
  3551. if (owner.symtabletype<>localsymtable) then
  3552. while assigned(pdo) do
  3553. begin
  3554. if pdo.symtable<>aktrecordsymtable then
  3555. begin
  3556. pdo.symtable.unitid:=local_symtable_index;
  3557. inc(local_symtable_index);
  3558. end;
  3559. pdo:=pdo.childof;
  3560. end;
  3561. parast.unitid:=local_symtable_index;
  3562. inc(local_symtable_index);
  3563. localst.unitid:=local_symtable_index;
  3564. inc(local_symtable_index);
  3565. tstoredsymtable(parast).write_references(ppufile,locals);
  3566. tstoredsymtable(localst).write_references(ppufile,locals);
  3567. { decrement for }
  3568. local_symtable_index:=local_symtable_index-2;
  3569. pdo:=_class;
  3570. if (owner.symtabletype<>localsymtable) then
  3571. while assigned(pdo) do
  3572. begin
  3573. if pdo.symtable<>aktrecordsymtable then
  3574. dec(local_symtable_index);
  3575. pdo:=pdo.childof;
  3576. end;
  3577. end;
  3578. aktparasymtable:=oldparasymtable;
  3579. aktlocalsymtable:=oldlocalsymtable;
  3580. end;
  3581. {$ifdef GDB}
  3582. function tprocdef.numberstring : string;
  3583. begin
  3584. { procdefs are always available }
  3585. stab_state:=stab_state_written;
  3586. result:=inherited numberstring;
  3587. end;
  3588. function tprocdef.stabstring: pchar;
  3589. Var
  3590. RType : Char;
  3591. Obj,Info : String;
  3592. stabsstr : string;
  3593. p : pchar;
  3594. begin
  3595. obj := procsym.name;
  3596. info := '';
  3597. if tprocsym(procsym).is_global then
  3598. RType := 'F'
  3599. else
  3600. RType := 'f';
  3601. if assigned(owner) then
  3602. begin
  3603. if (owner.symtabletype = objectsymtable) then
  3604. obj := owner.name^+'__'+procsym.name;
  3605. if not(cs_gdb_valgrind in aktglobalswitches) and
  3606. (owner.symtabletype=localsymtable) and
  3607. assigned(owner.defowner) and
  3608. assigned(tprocdef(owner.defowner).procsym) then
  3609. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3610. end;
  3611. stabsstr:=mangledname;
  3612. getmem(p,length(stabsstr)+255);
  3613. strpcopy(p,'"'+obj+':'+RType
  3614. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3615. +',0,'+
  3616. tostr(fileinfo.line)
  3617. +',');
  3618. strpcopy(strend(p),stabsstr);
  3619. stabstring:=strnew(p);
  3620. freemem(p,length(stabsstr)+255);
  3621. end;
  3622. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3623. begin
  3624. { released procdef? }
  3625. if not assigned(parast) then
  3626. exit;
  3627. if (proccalloption=pocall_internproc) then
  3628. exit;
  3629. { be sure to have a number assigned for this def }
  3630. numberstring;
  3631. { write stabs }
  3632. stab_state:=stab_state_writing;
  3633. asmList.concat(Tai_stabs.Create(stabstring));
  3634. if not(po_external in procoptions) then
  3635. begin
  3636. tstoredsymtable(parast).concatstabto(asmlist);
  3637. { local type defs and vars should not be written
  3638. inside the main proc stab }
  3639. if assigned(localst) and
  3640. (localst.symtablelevel>main_program_level) then
  3641. tstoredsymtable(localst).concatstabto(asmlist);
  3642. end;
  3643. stab_state:=stab_state_written;
  3644. end;
  3645. {$endif GDB}
  3646. procedure tprocdef.buildderef;
  3647. var
  3648. oldparasymtable,
  3649. oldlocalsymtable : tsymtable;
  3650. begin
  3651. oldparasymtable:=aktparasymtable;
  3652. oldlocalsymtable:=aktlocalsymtable;
  3653. aktparasymtable:=parast;
  3654. aktlocalsymtable:=localst;
  3655. inherited buildderef;
  3656. _classderef.build(_class);
  3657. { procsym that originaly defined this definition, should be in the
  3658. same symtable }
  3659. procsymderef.build(procsym);
  3660. {$ifdef powerpc}
  3661. { library symbol for AmigaOS/MorphOS }
  3662. libsymderef.build(libsym);
  3663. {$endif powerpc}
  3664. aktparasymtable:=oldparasymtable;
  3665. aktlocalsymtable:=oldlocalsymtable;
  3666. end;
  3667. procedure tprocdef.buildderefimpl;
  3668. var
  3669. oldparasymtable,
  3670. oldlocalsymtable : tsymtable;
  3671. begin
  3672. { released procdef? }
  3673. if not assigned(parast) then
  3674. exit;
  3675. oldparasymtable:=aktparasymtable;
  3676. oldlocalsymtable:=aktlocalsymtable;
  3677. aktparasymtable:=parast;
  3678. aktlocalsymtable:=localst;
  3679. inherited buildderefimpl;
  3680. { Locals }
  3681. if (proccalloption=pocall_inline) or
  3682. ((current_module.flags and uf_local_browser)<>0) then
  3683. begin
  3684. tlocalsymtable(localst).buildderef;
  3685. tlocalsymtable(localst).buildderefimpl;
  3686. funcretsymderef.build(funcretsym);
  3687. end;
  3688. { inline tree }
  3689. if (proccalloption=pocall_inline) then
  3690. inlininginfo^.code.buildderefimpl;
  3691. aktparasymtable:=oldparasymtable;
  3692. aktlocalsymtable:=oldlocalsymtable;
  3693. end;
  3694. procedure tprocdef.deref;
  3695. var
  3696. oldparasymtable,
  3697. oldlocalsymtable : tsymtable;
  3698. begin
  3699. { released procdef? }
  3700. if not assigned(parast) then
  3701. exit;
  3702. oldparasymtable:=aktparasymtable;
  3703. oldlocalsymtable:=aktlocalsymtable;
  3704. aktparasymtable:=parast;
  3705. aktlocalsymtable:=localst;
  3706. inherited deref;
  3707. _class:=tobjectdef(_classderef.resolve);
  3708. { procsym that originaly defined this definition, should be in the
  3709. same symtable }
  3710. procsym:=tprocsym(procsymderef.resolve);
  3711. {$ifdef powerpc}
  3712. { library symbol for AmigaOS/MorphOS }
  3713. libsym:=tvarsym(libsymderef.resolve);
  3714. {$endif powerpc}
  3715. aktparasymtable:=oldparasymtable;
  3716. aktlocalsymtable:=oldlocalsymtable;
  3717. end;
  3718. procedure tprocdef.derefimpl;
  3719. var
  3720. oldparasymtable,
  3721. oldlocalsymtable : tsymtable;
  3722. begin
  3723. oldparasymtable:=aktparasymtable;
  3724. oldlocalsymtable:=aktlocalsymtable;
  3725. aktparasymtable:=parast;
  3726. aktlocalsymtable:=localst;
  3727. { Locals }
  3728. if (proccalloption=pocall_inline) or
  3729. ((current_module.flags and uf_local_browser)<>0) then
  3730. begin
  3731. { we can deref both interface and implementation parts }
  3732. tlocalsymtable(localst).deref;
  3733. tlocalsymtable(localst).derefimpl;
  3734. { funcretsym, this is always located in the localst }
  3735. funcretsym:=tsym(funcretsymderef.resolve);
  3736. end
  3737. else
  3738. begin
  3739. { safety }
  3740. funcretsym:=nil;
  3741. end;
  3742. { inline tree }
  3743. if (proccalloption=pocall_inline) then
  3744. inlininginfo^.code.derefimpl;
  3745. aktparasymtable:=oldparasymtable;
  3746. aktlocalsymtable:=oldlocalsymtable;
  3747. end;
  3748. function tprocdef.gettypename : string;
  3749. begin
  3750. gettypename := FullProcName(false);
  3751. end;
  3752. function tprocdef.mangledname : string;
  3753. var
  3754. hp : TParaItem;
  3755. begin
  3756. if assigned(_mangledname) then
  3757. begin
  3758. {$ifdef compress}
  3759. mangledname:=minilzw_decode(_mangledname^);
  3760. {$else}
  3761. mangledname:=_mangledname^;
  3762. {$endif}
  3763. exit;
  3764. end;
  3765. { we need to use the symtable where the procsym is inserted,
  3766. because that is visible to the world }
  3767. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3768. if overloadnumber>0 then
  3769. mangledname:=mangledname+'$'+tostr(overloadnumber);
  3770. { add parameter types }
  3771. hp:=TParaItem(Para.first);
  3772. while assigned(hp) do
  3773. begin
  3774. if not hp.is_hidden then
  3775. mangledname:=mangledname+'$'+hp.paratype.def.mangledparaname;
  3776. hp:=TParaItem(hp.next);
  3777. end;
  3778. {$ifdef compress}
  3779. _mangledname:=stringdup(minilzw_encode(mangledname));
  3780. {$else}
  3781. _mangledname:=stringdup(mangledname);
  3782. {$endif}
  3783. end;
  3784. function tprocdef.cplusplusmangledname : string;
  3785. function getcppparaname(p : tdef) : string;
  3786. const
  3787. ordtype2str : array[tbasetype] of string[2] = (
  3788. '',
  3789. 'Uc','Us','Ui','Us',
  3790. 'Sc','s','i','x',
  3791. 'b','b','b',
  3792. 'c','w','x');
  3793. var
  3794. s : string;
  3795. begin
  3796. case p.deftype of
  3797. orddef:
  3798. s:=ordtype2str[torddef(p).typ];
  3799. pointerdef:
  3800. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3801. else
  3802. internalerror(2103001);
  3803. end;
  3804. getcppparaname:=s;
  3805. end;
  3806. var
  3807. s,s2 : string;
  3808. param : TParaItem;
  3809. begin
  3810. s := procsym.realname;
  3811. if procsym.owner.symtabletype=objectsymtable then
  3812. begin
  3813. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3814. case proctypeoption of
  3815. potype_destructor:
  3816. s:='_$_'+tostr(length(s2))+s2;
  3817. potype_constructor:
  3818. s:='___'+tostr(length(s2))+s2;
  3819. else
  3820. s:='_'+s+'__'+tostr(length(s2))+s2;
  3821. end;
  3822. end
  3823. else s:=s+'__';
  3824. s:=s+'F';
  3825. { concat modifiers }
  3826. { !!!!! }
  3827. { now we handle the parameters }
  3828. param := TParaItem(Para.first);
  3829. if assigned(param) then
  3830. while assigned(param) do
  3831. begin
  3832. s2:=getcppparaname(param.paratype.def);
  3833. if param.paratyp in [vs_var,vs_out] then
  3834. s2:='R'+s2;
  3835. s:=s+s2;
  3836. param:=TParaItem(param.next);
  3837. end
  3838. else
  3839. s:=s+'v';
  3840. cplusplusmangledname:=s;
  3841. end;
  3842. procedure tprocdef.setmangledname(const s : string);
  3843. begin
  3844. stringdispose(_mangledname);
  3845. {$ifdef compress}
  3846. _mangledname:=stringdup(minilzw_encode(s));
  3847. {$else}
  3848. _mangledname:=stringdup(s);
  3849. {$endif}
  3850. has_mangledname:=true;
  3851. end;
  3852. {***************************************************************************
  3853. TPROCVARDEF
  3854. ***************************************************************************}
  3855. constructor tprocvardef.create(level:byte);
  3856. begin
  3857. inherited create(level);
  3858. deftype:=procvardef;
  3859. end;
  3860. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3861. begin
  3862. inherited ppuload(ppufile);
  3863. deftype:=procvardef;
  3864. { load para symtable }
  3865. parast:=tparasymtable.create(unknown_level);
  3866. tparasymtable(parast).ppuload(ppufile);
  3867. parast.defowner:=self;
  3868. end;
  3869. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3870. var
  3871. oldparasymtable,
  3872. oldlocalsymtable : tsymtable;
  3873. begin
  3874. oldparasymtable:=aktparasymtable;
  3875. oldlocalsymtable:=aktlocalsymtable;
  3876. aktparasymtable:=parast;
  3877. aktlocalsymtable:=nil;
  3878. { here we cannot get a real good value so just give something }
  3879. { plausible (PM) }
  3880. { a more secure way would be
  3881. to allways store in a temp }
  3882. {$ifdef i386}
  3883. if is_fpu(rettype.def) then
  3884. fpu_used:={2}maxfpuregs
  3885. else
  3886. fpu_used:=0;
  3887. {$endif i386}
  3888. inherited ppuwrite(ppufile);
  3889. { Write this entry }
  3890. ppufile.writeentry(ibprocvardef);
  3891. { Save the para symtable, this is taken from the interface }
  3892. tparasymtable(parast).ppuwrite(ppufile);
  3893. aktparasymtable:=oldparasymtable;
  3894. aktlocalsymtable:=oldlocalsymtable;
  3895. end;
  3896. procedure tprocvardef.buildderef;
  3897. var
  3898. oldparasymtable,
  3899. oldlocalsymtable : tsymtable;
  3900. begin
  3901. oldparasymtable:=aktparasymtable;
  3902. oldlocalsymtable:=aktlocalsymtable;
  3903. aktparasymtable:=parast;
  3904. aktlocalsymtable:=nil;
  3905. inherited buildderef;
  3906. aktparasymtable:=oldparasymtable;
  3907. aktlocalsymtable:=oldlocalsymtable;
  3908. end;
  3909. procedure tprocvardef.deref;
  3910. var
  3911. oldparasymtable,
  3912. oldlocalsymtable : tsymtable;
  3913. begin
  3914. oldparasymtable:=aktparasymtable;
  3915. oldlocalsymtable:=aktlocalsymtable;
  3916. aktparasymtable:=parast;
  3917. aktlocalsymtable:=nil;
  3918. inherited deref;
  3919. aktparasymtable:=oldparasymtable;
  3920. aktlocalsymtable:=oldlocalsymtable;
  3921. end;
  3922. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3923. begin
  3924. case t of
  3925. gs_para :
  3926. getsymtable:=parast;
  3927. else
  3928. getsymtable:=nil;
  3929. end;
  3930. end;
  3931. function tprocvardef.size : longint;
  3932. begin
  3933. if (po_methodpointer in procoptions) and
  3934. not(po_addressonly in procoptions) then
  3935. size:=2*sizeof(aint)
  3936. else
  3937. size:=sizeof(aint);
  3938. end;
  3939. function tprocvardef.is_methodpointer:boolean;
  3940. begin
  3941. result:=(po_methodpointer in procoptions);
  3942. end;
  3943. function tprocvardef.is_addressonly:boolean;
  3944. begin
  3945. result:=not(po_methodpointer in procoptions) or
  3946. (po_addressonly in procoptions);
  3947. end;
  3948. {$ifdef GDB}
  3949. function tprocvardef.stabstring : pchar;
  3950. var
  3951. nss : pchar;
  3952. { i : longint; }
  3953. begin
  3954. { i := maxparacount; }
  3955. getmem(nss,1024);
  3956. { it is not a function but a function pointer !! (PM) }
  3957. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)});
  3958. { this confuses gdb !!
  3959. we should use 'F' instead of 'f' but
  3960. as we use c++ language mode
  3961. it does not like that either
  3962. Please do not remove this part
  3963. might be used once
  3964. gdb for pascal is ready PM }
  3965. {$ifdef disabled}
  3966. param := para1;
  3967. i := 0;
  3968. while assigned(param) do
  3969. begin
  3970. inc(i);
  3971. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3972. {Here we have lost the parameter names !!}
  3973. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3974. strcat(nss,pst);
  3975. strdispose(pst);
  3976. param := param^.next;
  3977. end;
  3978. {$endif}
  3979. {strpcopy(strend(nss),';');}
  3980. stabstring := strnew(nss);
  3981. freemem(nss,1024);
  3982. end;
  3983. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3984. begin
  3985. if (stab_state in [stab_state_writing,stab_state_written]) then
  3986. exit;
  3987. tstoreddef(rettype.def).concatstabto(asmlist);
  3988. inherited concatstabto(asmlist);
  3989. end;
  3990. {$endif GDB}
  3991. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3992. var
  3993. pdc : TParaItem;
  3994. methodkind, paraspec : byte;
  3995. begin
  3996. if po_methodpointer in procoptions then
  3997. begin
  3998. { write method id and name }
  3999. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  4000. write_rtti_name;
  4001. { write kind of method (can only be function or procedure)}
  4002. if rettype.def = voidtype.def then
  4003. methodkind := mkProcedure
  4004. else
  4005. methodkind := mkFunction;
  4006. rttiList.concat(Tai_const.Create_8bit(methodkind));
  4007. { get # of parameters }
  4008. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  4009. { write parameter info. The parameters must be written in reverse order
  4010. if this method uses right to left parameter pushing! }
  4011. if proccalloption in pushleftright_pocalls then
  4012. pdc:=TParaItem(Para.first)
  4013. else
  4014. pdc:=TParaItem(Para.last);
  4015. while assigned(pdc) do
  4016. begin
  4017. { only store user visible parameters }
  4018. if not pdc.is_hidden then
  4019. begin
  4020. case pdc.paratyp of
  4021. vs_value: paraspec := 0;
  4022. vs_const: paraspec := pfConst;
  4023. vs_var : paraspec := pfVar;
  4024. vs_out : paraspec := pfOut;
  4025. end;
  4026. { write flags for current parameter }
  4027. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4028. { write name of current parameter }
  4029. if assigned(pdc.parasym) then
  4030. begin
  4031. rttiList.concat(Tai_const.Create_8bit(length(pdc.parasym.realname)));
  4032. rttiList.concat(Tai_string.Create(pdc.parasym.realname));
  4033. end
  4034. else
  4035. rttiList.concat(Tai_const.Create_8bit(0));
  4036. { write name of type of current parameter }
  4037. tstoreddef(pdc.paratype.def).write_rtti_name;
  4038. end;
  4039. if proccalloption in pushleftright_pocalls then
  4040. pdc:=TParaItem(pdc.next)
  4041. else
  4042. pdc:=TParaItem(pdc.previous);
  4043. end;
  4044. { write name of result type }
  4045. tstoreddef(rettype.def).write_rtti_name;
  4046. end;
  4047. end;
  4048. function tprocvardef.is_publishable : boolean;
  4049. begin
  4050. is_publishable:=(po_methodpointer in procoptions);
  4051. end;
  4052. function tprocvardef.gettypename : string;
  4053. var
  4054. s: string;
  4055. showhidden : boolean;
  4056. begin
  4057. {$ifdef EXTDEBUG}
  4058. showhidden:=true;
  4059. {$else EXTDEBUG}
  4060. showhidden:=false;
  4061. {$endif EXTDEBUG}
  4062. s:='<';
  4063. if po_classmethod in procoptions then
  4064. s := s+'class method type of'
  4065. else
  4066. if po_addressonly in procoptions then
  4067. s := s+'address of'
  4068. else
  4069. s := s+'procedure variable type of';
  4070. if assigned(rettype.def) and
  4071. (rettype.def<>voidtype.def) then
  4072. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4073. else
  4074. s:=s+' procedure'+typename_paras(showhidden);
  4075. if po_methodpointer in procoptions then
  4076. s := s+' of object';
  4077. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4078. end;
  4079. {***************************************************************************
  4080. TOBJECTDEF
  4081. ***************************************************************************}
  4082. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4083. begin
  4084. inherited create;
  4085. objecttype:=ot;
  4086. deftype:=objectdef;
  4087. objectoptions:=[];
  4088. childof:=nil;
  4089. symtable:=tobjectsymtable.create(n,aktpackrecords);
  4090. { create space for vmt !! }
  4091. vmt_offset:=0;
  4092. symtable.defowner:=self;
  4093. lastvtableindex:=0;
  4094. set_parent(c);
  4095. objname:=stringdup(upper(n));
  4096. objrealname:=stringdup(n);
  4097. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4098. prepareguid;
  4099. { setup implemented interfaces }
  4100. if objecttype in [odt_class,odt_interfacecorba] then
  4101. implementedinterfaces:=timplementedinterfaces.create
  4102. else
  4103. implementedinterfaces:=nil;
  4104. {$ifdef GDB}
  4105. writing_class_record_stab:=false;
  4106. {$endif GDB}
  4107. end;
  4108. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4109. var
  4110. i,implintfcount: longint;
  4111. d : tderef;
  4112. begin
  4113. inherited ppuloaddef(ppufile);
  4114. deftype:=objectdef;
  4115. objecttype:=tobjectdeftype(ppufile.getbyte);
  4116. savesize:=ppufile.getlongint;
  4117. vmt_offset:=ppufile.getlongint;
  4118. objrealname:=stringdup(ppufile.getstring);
  4119. objname:=stringdup(upper(objrealname^));
  4120. ppufile.getderef(childofderef);
  4121. ppufile.getsmallset(objectoptions);
  4122. { load guid }
  4123. iidstr:=nil;
  4124. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4125. begin
  4126. new(iidguid);
  4127. ppufile.getguid(iidguid^);
  4128. iidstr:=stringdup(ppufile.getstring);
  4129. lastvtableindex:=ppufile.getlongint;
  4130. end;
  4131. { load implemented interfaces }
  4132. if objecttype in [odt_class,odt_interfacecorba] then
  4133. begin
  4134. implementedinterfaces:=timplementedinterfaces.create;
  4135. implintfcount:=ppufile.getlongint;
  4136. for i:=1 to implintfcount do
  4137. begin
  4138. ppufile.getderef(d);
  4139. implementedinterfaces.addintf_deref(d);
  4140. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4141. end;
  4142. end
  4143. else
  4144. implementedinterfaces:=nil;
  4145. symtable:=tobjectsymtable.create(objrealname^,aktpackrecords);
  4146. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  4147. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  4148. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  4149. tobjectsymtable(symtable).ppuload(ppufile);
  4150. symtable.defowner:=self;
  4151. { handles the predefined class tobject }
  4152. { the last TOBJECT which is loaded gets }
  4153. { it ! }
  4154. if (childof=nil) and
  4155. (objecttype=odt_class) and
  4156. (objname^='TOBJECT') then
  4157. class_tobject:=self;
  4158. if (childof=nil) and
  4159. (objecttype=odt_interfacecom) and
  4160. (objname^='IUNKNOWN') then
  4161. interface_iunknown:=self;
  4162. {$ifdef GDB}
  4163. writing_class_record_stab:=false;
  4164. {$endif GDB}
  4165. end;
  4166. destructor tobjectdef.destroy;
  4167. begin
  4168. if assigned(symtable) then
  4169. symtable.free;
  4170. stringdispose(objname);
  4171. stringdispose(objrealname);
  4172. if assigned(iidstr) then
  4173. stringdispose(iidstr);
  4174. if assigned(implementedinterfaces) then
  4175. implementedinterfaces.free;
  4176. if assigned(iidguid) then
  4177. dispose(iidguid);
  4178. inherited destroy;
  4179. end;
  4180. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4181. var
  4182. implintfcount : longint;
  4183. i : longint;
  4184. begin
  4185. inherited ppuwritedef(ppufile);
  4186. ppufile.putbyte(byte(objecttype));
  4187. ppufile.putlongint(size);
  4188. ppufile.putlongint(vmt_offset);
  4189. ppufile.putstring(objrealname^);
  4190. ppufile.putderef(childofderef);
  4191. ppufile.putsmallset(objectoptions);
  4192. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4193. begin
  4194. ppufile.putguid(iidguid^);
  4195. ppufile.putstring(iidstr^);
  4196. ppufile.putlongint(lastvtableindex);
  4197. end;
  4198. if objecttype in [odt_class,odt_interfacecorba] then
  4199. begin
  4200. implintfcount:=implementedinterfaces.count;
  4201. ppufile.putlongint(implintfcount);
  4202. for i:=1 to implintfcount do
  4203. begin
  4204. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4205. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4206. end;
  4207. end;
  4208. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4209. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  4210. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  4211. ppufile.writeentry(ibobjectdef);
  4212. tobjectsymtable(symtable).ppuwrite(ppufile);
  4213. end;
  4214. function tobjectdef.gettypename:string;
  4215. begin
  4216. gettypename:=typename;
  4217. end;
  4218. procedure tobjectdef.buildderef;
  4219. var
  4220. oldrecsyms : tsymtable;
  4221. begin
  4222. inherited buildderef;
  4223. childofderef.build(childof);
  4224. oldrecsyms:=aktrecordsymtable;
  4225. aktrecordsymtable:=symtable;
  4226. tstoredsymtable(symtable).buildderef;
  4227. aktrecordsymtable:=oldrecsyms;
  4228. if objecttype in [odt_class,odt_interfacecorba] then
  4229. implementedinterfaces.buildderef;
  4230. end;
  4231. procedure tobjectdef.deref;
  4232. var
  4233. oldrecsyms : tsymtable;
  4234. begin
  4235. inherited deref;
  4236. childof:=tobjectdef(childofderef.resolve);
  4237. oldrecsyms:=aktrecordsymtable;
  4238. aktrecordsymtable:=symtable;
  4239. tstoredsymtable(symtable).deref;
  4240. aktrecordsymtable:=oldrecsyms;
  4241. if objecttype in [odt_class,odt_interfacecorba] then
  4242. implementedinterfaces.deref;
  4243. end;
  4244. function tobjectdef.getparentdef:tdef;
  4245. begin
  4246. result:=childof;
  4247. end;
  4248. procedure tobjectdef.prepareguid;
  4249. begin
  4250. { set up guid }
  4251. if not assigned(iidguid) then
  4252. begin
  4253. new(iidguid);
  4254. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4255. end;
  4256. { setup iidstring }
  4257. if not assigned(iidstr) then
  4258. iidstr:=stringdup(''); { default is empty string }
  4259. end;
  4260. procedure tobjectdef.set_parent( c : tobjectdef);
  4261. begin
  4262. { nothing to do if the parent was not forward !}
  4263. if assigned(childof) then
  4264. exit;
  4265. childof:=c;
  4266. { some options are inherited !! }
  4267. if assigned(c) then
  4268. begin
  4269. { only important for classes }
  4270. lastvtableindex:=c.lastvtableindex;
  4271. objectoptions:=objectoptions+(c.objectoptions*
  4272. [oo_has_virtual,oo_has_private,oo_has_protected,
  4273. oo_has_constructor,oo_has_destructor]);
  4274. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4275. begin
  4276. { add the data of the anchestor class }
  4277. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4278. if (oo_has_vmt in objectoptions) and
  4279. (oo_has_vmt in c.objectoptions) then
  4280. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  4281. { if parent has a vmt field then
  4282. the offset is the same for the child PM }
  4283. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4284. begin
  4285. vmt_offset:=c.vmt_offset;
  4286. include(objectoptions,oo_has_vmt);
  4287. end;
  4288. end;
  4289. end;
  4290. savesize := tobjectsymtable(symtable).datasize;
  4291. end;
  4292. procedure tobjectdef.insertvmt;
  4293. begin
  4294. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4295. exit;
  4296. if (oo_has_vmt in objectoptions) then
  4297. internalerror(12345)
  4298. else
  4299. begin
  4300. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4301. tobjectsymtable(symtable).fieldalignment);
  4302. vmt_offset:=tobjectsymtable(symtable).datasize;
  4303. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  4304. include(objectoptions,oo_has_vmt);
  4305. end;
  4306. end;
  4307. procedure tobjectdef.check_forwards;
  4308. begin
  4309. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4310. tstoredsymtable(symtable).check_forwards;
  4311. if (oo_is_forward in objectoptions) then
  4312. begin
  4313. { ok, in future, the forward can be resolved }
  4314. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4315. exclude(objectoptions,oo_is_forward);
  4316. end;
  4317. end;
  4318. { true, if self inherits from d (or if they are equal) }
  4319. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4320. var
  4321. hp : tobjectdef;
  4322. begin
  4323. hp:=self;
  4324. while assigned(hp) do
  4325. begin
  4326. if hp=d then
  4327. begin
  4328. is_related:=true;
  4329. exit;
  4330. end;
  4331. hp:=hp.childof;
  4332. end;
  4333. is_related:=false;
  4334. end;
  4335. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4336. var
  4337. p : pprocdeflist;
  4338. begin
  4339. { if we found already a destructor, then we exit }
  4340. if assigned(sd) then
  4341. exit;
  4342. if tsym(sym).typ=procsym then
  4343. begin
  4344. p:=tprocsym(sym).defs;
  4345. while assigned(p) do
  4346. begin
  4347. if p^.def.proctypeoption=potype_destructor then
  4348. begin
  4349. sd:=p^.def;
  4350. exit;
  4351. end;
  4352. p:=p^.next;
  4353. end;
  4354. end;
  4355. end;*)
  4356. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4357. begin
  4358. { if we found already a destructor, then we exit }
  4359. if (ppointer(sd)^=nil) and
  4360. (Tsym(sym).typ=procsym) then
  4361. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4362. end;
  4363. function tobjectdef.searchdestructor : tprocdef;
  4364. var
  4365. o : tobjectdef;
  4366. sd : tprocdef;
  4367. begin
  4368. searchdestructor:=nil;
  4369. o:=self;
  4370. sd:=nil;
  4371. while assigned(o) do
  4372. begin
  4373. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4374. if assigned(sd) then
  4375. begin
  4376. searchdestructor:=sd;
  4377. exit;
  4378. end;
  4379. o:=o.childof;
  4380. end;
  4381. end;
  4382. function tobjectdef.size : longint;
  4383. begin
  4384. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4385. result:=sizeof(aint)
  4386. else
  4387. result:=tobjectsymtable(symtable).datasize;
  4388. end;
  4389. function tobjectdef.alignment:longint;
  4390. begin
  4391. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4392. alignment:=sizeof(aint)
  4393. else
  4394. alignment:=tobjectsymtable(symtable).recordalignment;
  4395. end;
  4396. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4397. begin
  4398. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4399. case objecttype of
  4400. odt_class:
  4401. { the +2*sizeof(Aint) is size and -size }
  4402. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  4403. odt_interfacecom,odt_interfacecorba:
  4404. vmtmethodoffset:=index*sizeof(aint);
  4405. else
  4406. {$ifdef WITHDMT}
  4407. vmtmethodoffset:=(index+4)*sizeof(aint);
  4408. {$else WITHDMT}
  4409. vmtmethodoffset:=(index+3)*sizeof(aint);
  4410. {$endif WITHDMT}
  4411. end;
  4412. end;
  4413. function tobjectdef.vmt_mangledname : string;
  4414. begin
  4415. if not(oo_has_vmt in objectoptions) then
  4416. Message1(parser_n_object_has_no_vmt,objrealname^);
  4417. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4418. end;
  4419. function tobjectdef.rtti_name : string;
  4420. begin
  4421. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4422. end;
  4423. {$ifdef GDB}
  4424. procedure tobjectdef.proc_addname(p :tnamedindexitem;arg:pointer);
  4425. var virtualind,argnames : string;
  4426. newrec : pchar;
  4427. pd : tprocdef;
  4428. lindex : longint;
  4429. para : TParaItem;
  4430. arglength : byte;
  4431. sp : char;
  4432. state:^Trecord_stabgen_state;
  4433. olds:integer;
  4434. begin
  4435. state:=arg;
  4436. if tsym(p).typ = procsym then
  4437. begin
  4438. pd := tprocsym(p).first_procdef;
  4439. if (po_virtualmethod in pd.procoptions) then
  4440. begin
  4441. lindex := pd.extnumber;
  4442. {doesnt seem to be necessary
  4443. lindex := lindex or $80000000;}
  4444. virtualind := '*'+tostr(lindex)+';'+pd._class.classnumberstring+';'
  4445. end
  4446. else
  4447. virtualind := '.';
  4448. { used by gdbpas to recognize constructor and destructors }
  4449. if (pd.proctypeoption=potype_constructor) then
  4450. argnames:='__ct__'
  4451. else if (pd.proctypeoption=potype_destructor) then
  4452. argnames:='__dt__'
  4453. else
  4454. argnames := '';
  4455. { arguments are not listed here }
  4456. {we don't need another definition}
  4457. para := TParaItem(pd.Para.first);
  4458. while assigned(para) do
  4459. begin
  4460. if Para.paratype.def.deftype = formaldef then
  4461. begin
  4462. case Para.paratyp of
  4463. vs_var :
  4464. argnames := argnames+'3var';
  4465. vs_const :
  4466. argnames:=argnames+'5const';
  4467. vs_out :
  4468. argnames:=argnames+'3out';
  4469. end;
  4470. end
  4471. else
  4472. begin
  4473. { if the arg definition is like (v: ^byte;..
  4474. there is no sym attached to data !!! }
  4475. if assigned(Para.paratype.def.typesym) then
  4476. begin
  4477. arglength := length(Para.paratype.def.typesym.name);
  4478. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4479. end
  4480. else
  4481. argnames:=argnames+'11unnamedtype';
  4482. end;
  4483. para := TParaItem(Para.next);
  4484. end;
  4485. { here 2A must be changed for private and protected }
  4486. { 0 is private 1 protected and 2 public }
  4487. if (sp_private in tsym(p).symoptions) then
  4488. sp:='0'
  4489. else if (sp_protected in tsym(p).symoptions) then
  4490. sp:='1'
  4491. else
  4492. sp:='2';
  4493. newrec:=stabstr_evaluate('$1::$2=##$3;:$4;$5A$6;',[p.name,pd.numberstring,
  4494. Tstoreddef(pd.rettype.def).numberstring,argnames,sp,
  4495. virtualind]);
  4496. { get spare place for a string at the end }
  4497. olds:=state^.stabsize;
  4498. inc(state^.stabsize,strlen(newrec));
  4499. if state^.stabsize>=state^.staballoc-256 then
  4500. begin
  4501. inc(state^.staballoc,memsizeinc);
  4502. reallocmem(state^.stabstring,state^.staballoc);
  4503. end;
  4504. strcopy(state^.stabstring+olds,newrec);
  4505. strdispose(newrec);
  4506. {This should be used for case !!
  4507. RecOffset := RecOffset + pd.size;}
  4508. end;
  4509. end;
  4510. procedure tobjectdef.proc_concatstabto(p :tnamedindexitem;arg:pointer);
  4511. var
  4512. pd : tprocdef;
  4513. begin
  4514. if tsym(p).typ = procsym then
  4515. begin
  4516. pd := tprocsym(p).first_procdef;
  4517. tstoreddef(pd.rettype.def).concatstabto(taasmoutput(arg));
  4518. end;
  4519. end;
  4520. function tobjectdef.stabstring : pchar;
  4521. var anc : tobjectdef;
  4522. state:Trecord_stabgen_state;
  4523. ts : string;
  4524. begin
  4525. if not (objecttype=odt_class) or writing_class_record_stab then
  4526. begin
  4527. state.staballoc:=memsizeinc;
  4528. getmem(state.stabstring,state.staballoc);
  4529. strpcopy(state.stabstring,'s'+tostr(tobjectsymtable(symtable).datasize));
  4530. if assigned(childof) then
  4531. begin
  4532. {only one ancestor not virtual, public, at base offset 0 }
  4533. { !1 , 0 2 0 , }
  4534. strpcopy(strend(state.stabstring),'!1,020,'+childof.classnumberstring+';');
  4535. end;
  4536. {virtual table to implement yet}
  4537. state.recoffset:=0;
  4538. state.stabsize:=strlen(state.stabstring);
  4539. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_addname,@state);
  4540. if (oo_has_vmt in objectoptions) then
  4541. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4542. begin
  4543. ts:='$vf'+classnumberstring+':'+tstoreddef(vmtarraytype.def).numberstring+','+tostr(vmt_offset*8)+';';
  4544. strpcopy(state.stabstring+state.stabsize,ts);
  4545. inc(state.stabsize,length(ts));
  4546. end;
  4547. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_addname,@state);
  4548. if (oo_has_vmt in objectoptions) then
  4549. begin
  4550. anc := self;
  4551. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4552. anc := anc.childof;
  4553. { just in case anc = self }
  4554. ts:=';~%'+anc.classnumberstring+';';
  4555. end
  4556. else
  4557. ts:=';';
  4558. strpcopy(state.stabstring+state.stabsize,ts);
  4559. inc(state.stabsize,length(ts));
  4560. reallocmem(state.stabstring,state.stabsize+1);
  4561. stabstring:=state.stabstring;
  4562. end
  4563. else
  4564. begin
  4565. stabstring:=strpnew('*'+classnumberstring);
  4566. end;
  4567. end;
  4568. procedure tobjectdef.set_globalnb;
  4569. begin
  4570. globalnb:=PglobalTypeCount^;
  4571. inc(PglobalTypeCount^);
  4572. { classes need two type numbers, the globalnb is set to the ptr }
  4573. if objecttype=odt_class then
  4574. begin
  4575. globalnb:=PGlobalTypeCount^;
  4576. inc(PglobalTypeCount^);
  4577. end;
  4578. end;
  4579. function tobjectdef.classnumberstring : string;
  4580. begin
  4581. if objecttype=odt_class then
  4582. begin
  4583. if globalnb=0 then
  4584. numberstring;
  4585. dec(globalnb);
  4586. classnumberstring:=numberstring;
  4587. inc(globalnb);
  4588. end
  4589. else
  4590. classnumberstring:=numberstring;
  4591. end;
  4592. function tobjectdef.allstabstring : pchar;
  4593. var
  4594. stabchar : string[2];
  4595. ss,st : pchar;
  4596. sname : string;
  4597. begin
  4598. ss := stabstring;
  4599. getmem(st,strlen(ss)+512);
  4600. stabchar := 't';
  4601. if deftype in tagtypes then
  4602. stabchar := 'Tt';
  4603. if assigned(typesym) then
  4604. sname := typesym.name
  4605. else
  4606. sname := ' ';
  4607. if writing_class_record_stab then
  4608. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4609. else
  4610. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4611. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,0,0');
  4612. allstabstring := strnew(st);
  4613. freemem(st,strlen(ss)+512);
  4614. strdispose(ss);
  4615. end;
  4616. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4617. var
  4618. oldtypesym : tsym;
  4619. stab_str : pchar;
  4620. anc : tobjectdef;
  4621. begin
  4622. if (stab_state in [stab_state_writing,stab_state_written]) then
  4623. exit;
  4624. stab_state:=stab_state_writing;
  4625. tstoreddef(vmtarraytype.def).concatstabto(asmlist);
  4626. { first the parents }
  4627. anc:=self;
  4628. while assigned(anc.childof) do
  4629. begin
  4630. anc:=anc.childof;
  4631. anc.concatstabto(asmlist);
  4632. end;
  4633. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_concatstabto,asmlist);
  4634. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_concatstabto,asmlist);
  4635. stab_state:=stab_state_used;
  4636. if objecttype=odt_class then
  4637. begin
  4638. { Write the record class itself }
  4639. writing_class_record_stab:=true;
  4640. inherited concatstabto(asmlist);
  4641. writing_class_record_stab:=false;
  4642. { Write the invisible pointer class }
  4643. oldtypesym:=typesym;
  4644. typesym:=nil;
  4645. stab_str := allstabstring;
  4646. asmList.concat(Tai_stabs.Create(stab_str));
  4647. typesym:=oldtypesym;
  4648. end
  4649. else
  4650. inherited concatstabto(asmlist);
  4651. end;
  4652. {$endif GDB}
  4653. function tobjectdef.needs_inittable : boolean;
  4654. begin
  4655. case objecttype of
  4656. odt_class :
  4657. needs_inittable:=false;
  4658. odt_interfacecom:
  4659. needs_inittable:=true;
  4660. odt_interfacecorba:
  4661. needs_inittable:=is_related(interface_iunknown);
  4662. odt_object:
  4663. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4664. else
  4665. internalerror(200108267);
  4666. end;
  4667. end;
  4668. function tobjectdef.members_need_inittable : boolean;
  4669. begin
  4670. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4671. end;
  4672. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4673. begin
  4674. if needs_prop_entry(tsym(sym)) and
  4675. (tsym(sym).typ<>varsym) then
  4676. inc(count);
  4677. end;
  4678. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4679. var
  4680. proctypesinfo : byte;
  4681. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4682. var
  4683. typvalue : byte;
  4684. hp : psymlistitem;
  4685. address : longint;
  4686. def : tdef;
  4687. begin
  4688. if not(assigned(proc) and assigned(proc.firstsym)) then
  4689. begin
  4690. rttiList.concat(Tai_const.create(ait_const_ptr,1));
  4691. typvalue:=3;
  4692. end
  4693. else if proc.firstsym^.sym.typ=varsym then
  4694. begin
  4695. address:=0;
  4696. hp:=proc.firstsym;
  4697. def:=nil;
  4698. while assigned(hp) do
  4699. begin
  4700. case hp^.sltype of
  4701. sl_load :
  4702. begin
  4703. def:=tvarsym(hp^.sym).vartype.def;
  4704. inc(address,tvarsym(hp^.sym).fieldoffset);
  4705. end;
  4706. sl_subscript :
  4707. begin
  4708. if not(assigned(def) and (def.deftype=recorddef)) then
  4709. internalerror(200402171);
  4710. inc(address,tvarsym(hp^.sym).fieldoffset);
  4711. def:=tvarsym(hp^.sym).vartype.def;
  4712. end;
  4713. sl_vec :
  4714. begin
  4715. if not(assigned(def) and (def.deftype=arraydef)) then
  4716. internalerror(200402172);
  4717. def:=tarraydef(def).elementtype.def;
  4718. inc(address,def.size*hp^.value);
  4719. end;
  4720. end;
  4721. hp:=hp^.next;
  4722. end;
  4723. rttiList.concat(Tai_const.create(ait_const_ptr,address));
  4724. typvalue:=0;
  4725. end
  4726. else
  4727. begin
  4728. { When there was an error then procdef is not assigned }
  4729. if not assigned(proc.procdef) then
  4730. exit;
  4731. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4732. begin
  4733. rttiList.concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4734. typvalue:=1;
  4735. end
  4736. else
  4737. begin
  4738. { virtual method, write vmt offset }
  4739. rttiList.concat(Tai_const.create(ait_const_ptr,
  4740. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4741. typvalue:=2;
  4742. end;
  4743. end;
  4744. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4745. end;
  4746. begin
  4747. if needs_prop_entry(tsym(sym)) then
  4748. case tsym(sym).typ of
  4749. varsym:
  4750. begin
  4751. {$ifdef dummy}
  4752. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4753. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4754. internalerror(1509992);
  4755. { access to implicit class property as field }
  4756. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4757. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label),AT_DATA,0));
  4758. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4759. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4760. { by default stored }
  4761. rttiList.concat(Tai_const.Create_32bit(1));
  4762. { index as well as ... }
  4763. rttiList.concat(Tai_const.Create_32bit(0));
  4764. { default value are zero }
  4765. rttiList.concat(Tai_const.Create_32bit(0));
  4766. rttiList.concat(Tai_const.Create_16bit(count));
  4767. inc(count);
  4768. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4769. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4770. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4771. {$endif dummy}
  4772. end;
  4773. propertysym:
  4774. begin
  4775. if ppo_indexed in tpropertysym(sym).propoptions then
  4776. proctypesinfo:=$40
  4777. else
  4778. proctypesinfo:=0;
  4779. rttiList.concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4780. writeproc(tpropertysym(sym).readaccess,0);
  4781. writeproc(tpropertysym(sym).writeaccess,2);
  4782. { isn't it stored ? }
  4783. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4784. begin
  4785. rttiList.concat(Tai_const.create_sym(nil));
  4786. proctypesinfo:=proctypesinfo or (3 shl 4);
  4787. end
  4788. else
  4789. writeproc(tpropertysym(sym).storedaccess,4);
  4790. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4791. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4792. rttiList.concat(Tai_const.Create_16bit(count));
  4793. inc(count);
  4794. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4795. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4796. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4797. end;
  4798. else internalerror(1509992);
  4799. end;
  4800. end;
  4801. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4802. begin
  4803. if needs_prop_entry(tsym(sym)) then
  4804. begin
  4805. case tsym(sym).typ of
  4806. propertysym:
  4807. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4808. varsym:
  4809. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4810. else
  4811. internalerror(1509991);
  4812. end;
  4813. end;
  4814. end;
  4815. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4816. begin
  4817. FRTTIType:=rt;
  4818. case rt of
  4819. initrtti :
  4820. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4821. fullrtti :
  4822. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4823. else
  4824. internalerror(200108301);
  4825. end;
  4826. end;
  4827. type
  4828. tclasslistitem = class(TLinkedListItem)
  4829. index : longint;
  4830. p : tobjectdef;
  4831. end;
  4832. var
  4833. classtablelist : tlinkedlist;
  4834. tablecount : longint;
  4835. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4836. var
  4837. hp : tclasslistitem;
  4838. begin
  4839. hp:=tclasslistitem(classtablelist.first);
  4840. while assigned(hp) do
  4841. if hp.p=p then
  4842. begin
  4843. searchclasstablelist:=hp;
  4844. exit;
  4845. end
  4846. else
  4847. hp:=tclasslistitem(hp.next);
  4848. searchclasstablelist:=nil;
  4849. end;
  4850. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4851. var
  4852. hp : tclasslistitem;
  4853. begin
  4854. if needs_prop_entry(tsym(sym)) and
  4855. (tsym(sym).typ=varsym) then
  4856. begin
  4857. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4858. internalerror(0206001);
  4859. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4860. if not(assigned(hp)) then
  4861. begin
  4862. hp:=tclasslistitem.create;
  4863. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4864. hp.index:=tablecount;
  4865. classtablelist.concat(hp);
  4866. inc(tablecount);
  4867. end;
  4868. inc(count);
  4869. end;
  4870. end;
  4871. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4872. var
  4873. hp : tclasslistitem;
  4874. begin
  4875. if needs_prop_entry(tsym(sym)) and
  4876. (tsym(sym).typ=varsym) then
  4877. begin
  4878. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4879. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4880. if not(assigned(hp)) then
  4881. internalerror(0206002);
  4882. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4883. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4884. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4885. end;
  4886. end;
  4887. function tobjectdef.generate_field_table : tasmlabel;
  4888. var
  4889. fieldtable,
  4890. classtable : tasmlabel;
  4891. hp : tclasslistitem;
  4892. begin
  4893. classtablelist:=TLinkedList.Create;
  4894. objectlibrary.getdatalabel(fieldtable);
  4895. objectlibrary.getdatalabel(classtable);
  4896. count:=0;
  4897. tablecount:=0;
  4898. maybe_new_object_file(rttiList);
  4899. new_section(rttiList,sec_rodata,classtable.name,const_align(sizeof(aint)));
  4900. { fields }
  4901. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4902. rttiList.concat(Tai_label.Create(fieldtable));
  4903. rttiList.concat(Tai_const.Create_16bit(count));
  4904. rttiList.concat(Tai_const.Create_sym(classtable));
  4905. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4906. { generate the class table }
  4907. rttilist.concat(tai_align.create(const_align(sizeof(aint))));
  4908. rttiList.concat(Tai_label.Create(classtable));
  4909. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4910. hp:=tclasslistitem(classtablelist.first);
  4911. while assigned(hp) do
  4912. begin
  4913. rttiList.concat(Tai_const.Createname(tobjectdef(hp.p).vmt_mangledname,AT_DATA,0));
  4914. hp:=tclasslistitem(hp.next);
  4915. end;
  4916. generate_field_table:=fieldtable;
  4917. classtablelist.free;
  4918. end;
  4919. function tobjectdef.next_free_name_index : longint;
  4920. var
  4921. i : longint;
  4922. begin
  4923. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4924. i:=childof.next_free_name_index
  4925. else
  4926. i:=0;
  4927. count:=0;
  4928. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4929. next_free_name_index:=i+count;
  4930. end;
  4931. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4932. begin
  4933. case objecttype of
  4934. odt_class:
  4935. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4936. odt_object:
  4937. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4938. odt_interfacecom:
  4939. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4940. odt_interfacecorba:
  4941. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4942. else
  4943. exit;
  4944. end;
  4945. { generate the name }
  4946. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4947. rttiList.concat(Tai_string.Create(objrealname^));
  4948. case rt of
  4949. initrtti :
  4950. begin
  4951. rttiList.concat(Tai_const.Create_32bit(size));
  4952. if objecttype in [odt_class,odt_object] then
  4953. begin
  4954. count:=0;
  4955. FRTTIType:=rt;
  4956. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4957. rttiList.concat(Tai_const.Create_32bit(count));
  4958. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4959. end;
  4960. end;
  4961. fullrtti :
  4962. begin
  4963. if (oo_has_vmt in objectoptions) and
  4964. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4965. rttiList.concat(Tai_const.Createname(vmt_mangledname,AT_DATA,0))
  4966. else
  4967. rttiList.concat(Tai_const.create_sym(nil));
  4968. { write owner typeinfo }
  4969. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4970. rttiList.concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  4971. else
  4972. rttiList.concat(Tai_const.create_sym(nil));
  4973. { count total number of properties }
  4974. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4975. count:=childof.next_free_name_index
  4976. else
  4977. count:=0;
  4978. { write it }
  4979. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4980. rttiList.concat(Tai_const.Create_16bit(count));
  4981. { write unit name }
  4982. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4983. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4984. { write published properties count }
  4985. count:=0;
  4986. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4987. rttiList.concat(Tai_const.Create_16bit(count));
  4988. { count is used to write nameindex }
  4989. { but we need an offset of the owner }
  4990. { to give each property an own slot }
  4991. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4992. count:=childof.next_free_name_index
  4993. else
  4994. count:=0;
  4995. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4996. end;
  4997. end;
  4998. end;
  4999. function tobjectdef.is_publishable : boolean;
  5000. begin
  5001. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  5002. end;
  5003. {****************************************************************************
  5004. TIMPLEMENTEDINTERFACES
  5005. ****************************************************************************}
  5006. type
  5007. tnamemap = class(TNamedIndexItem)
  5008. newname: pstring;
  5009. constructor create(const aname, anewname: string);
  5010. destructor destroy; override;
  5011. end;
  5012. constructor tnamemap.create(const aname, anewname: string);
  5013. begin
  5014. inherited createname(name);
  5015. newname:=stringdup(anewname);
  5016. end;
  5017. destructor tnamemap.destroy;
  5018. begin
  5019. stringdispose(newname);
  5020. inherited destroy;
  5021. end;
  5022. type
  5023. tprocdefstore = class(TNamedIndexItem)
  5024. procdef: tprocdef;
  5025. constructor create(aprocdef: tprocdef);
  5026. end;
  5027. constructor tprocdefstore.create(aprocdef: tprocdef);
  5028. begin
  5029. inherited create;
  5030. procdef:=aprocdef;
  5031. end;
  5032. type
  5033. timplintfentry = class(TNamedIndexItem)
  5034. intf: tobjectdef;
  5035. intfderef : tderef;
  5036. ioffs: longint;
  5037. namemappings: tdictionary;
  5038. procdefs: TIndexArray;
  5039. constructor create(aintf: tobjectdef);
  5040. constructor create_deref(const d:tderef);
  5041. destructor destroy; override;
  5042. end;
  5043. constructor timplintfentry.create(aintf: tobjectdef);
  5044. begin
  5045. inherited create;
  5046. intf:=aintf;
  5047. ioffs:=-1;
  5048. namemappings:=nil;
  5049. procdefs:=nil;
  5050. end;
  5051. constructor timplintfentry.create_deref(const d:tderef);
  5052. begin
  5053. inherited create;
  5054. intf:=nil;
  5055. intfderef:=d;
  5056. ioffs:=-1;
  5057. namemappings:=nil;
  5058. procdefs:=nil;
  5059. end;
  5060. destructor timplintfentry.destroy;
  5061. begin
  5062. if assigned(namemappings) then
  5063. namemappings.free;
  5064. if assigned(procdefs) then
  5065. procdefs.free;
  5066. inherited destroy;
  5067. end;
  5068. constructor timplementedinterfaces.create;
  5069. begin
  5070. finterfaces:=tindexarray.create(1);
  5071. end;
  5072. destructor timplementedinterfaces.destroy;
  5073. begin
  5074. finterfaces.destroy;
  5075. end;
  5076. function timplementedinterfaces.count: longint;
  5077. begin
  5078. count:=finterfaces.count;
  5079. end;
  5080. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5081. begin
  5082. if (intfindex<1) or (intfindex>count) then
  5083. InternalError(200006123);
  5084. end;
  5085. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5086. begin
  5087. checkindex(intfindex);
  5088. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5089. end;
  5090. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5091. begin
  5092. checkindex(intfindex);
  5093. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5094. end;
  5095. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5096. begin
  5097. checkindex(intfindex);
  5098. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5099. end;
  5100. function timplementedinterfaces.searchintf(def: tdef): longint;
  5101. var
  5102. i: longint;
  5103. begin
  5104. i:=1;
  5105. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5106. if i<=count then
  5107. searchintf:=i
  5108. else
  5109. searchintf:=-1;
  5110. end;
  5111. procedure timplementedinterfaces.buildderef;
  5112. var
  5113. i: longint;
  5114. begin
  5115. for i:=1 to count do
  5116. with timplintfentry(finterfaces.search(i)) do
  5117. intfderef.build(intf);
  5118. end;
  5119. procedure timplementedinterfaces.deref;
  5120. var
  5121. i: longint;
  5122. begin
  5123. for i:=1 to count do
  5124. with timplintfentry(finterfaces.search(i)) do
  5125. intf:=tobjectdef(intfderef.resolve);
  5126. end;
  5127. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5128. begin
  5129. finterfaces.insert(timplintfentry.create_deref(d));
  5130. end;
  5131. procedure timplementedinterfaces.addintf(def: tdef);
  5132. begin
  5133. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5134. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5135. internalerror(200006124);
  5136. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5137. end;
  5138. procedure timplementedinterfaces.clearmappings;
  5139. var
  5140. i: longint;
  5141. begin
  5142. for i:=1 to count do
  5143. with timplintfentry(finterfaces.search(i)) do
  5144. begin
  5145. if assigned(namemappings) then
  5146. namemappings.free;
  5147. namemappings:=nil;
  5148. end;
  5149. end;
  5150. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5151. begin
  5152. checkindex(intfindex);
  5153. with timplintfentry(finterfaces.search(intfindex)) do
  5154. begin
  5155. if not assigned(namemappings) then
  5156. namemappings:=tdictionary.create;
  5157. namemappings.insert(tnamemap.create(name,newname));
  5158. end;
  5159. end;
  5160. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5161. begin
  5162. checkindex(intfindex);
  5163. if not assigned(nextexist) then
  5164. with timplintfentry(finterfaces.search(intfindex)) do
  5165. begin
  5166. if assigned(namemappings) then
  5167. nextexist:=namemappings.search(name)
  5168. else
  5169. nextexist:=nil;
  5170. end;
  5171. if assigned(nextexist) then
  5172. begin
  5173. getmappings:=tnamemap(nextexist).newname^;
  5174. nextexist:=tnamemap(nextexist).listnext;
  5175. end
  5176. else
  5177. getmappings:='';
  5178. end;
  5179. procedure timplementedinterfaces.clearimplprocs;
  5180. var
  5181. i: longint;
  5182. begin
  5183. for i:=1 to count do
  5184. with timplintfentry(finterfaces.search(i)) do
  5185. begin
  5186. if assigned(procdefs) then
  5187. procdefs.free;
  5188. procdefs:=nil;
  5189. end;
  5190. end;
  5191. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5192. begin
  5193. checkindex(intfindex);
  5194. with timplintfentry(finterfaces.search(intfindex)) do
  5195. begin
  5196. if not assigned(procdefs) then
  5197. procdefs:=tindexarray.create(4);
  5198. procdefs.insert(tprocdefstore.create(procdef));
  5199. end;
  5200. end;
  5201. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5202. begin
  5203. checkindex(intfindex);
  5204. with timplintfentry(finterfaces.search(intfindex)) do
  5205. if assigned(procdefs) then
  5206. implproccount:=procdefs.count
  5207. else
  5208. implproccount:=0;
  5209. end;
  5210. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5211. begin
  5212. checkindex(intfindex);
  5213. with timplintfentry(finterfaces.search(intfindex)) do
  5214. if assigned(procdefs) then
  5215. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5216. else
  5217. internalerror(200006131);
  5218. end;
  5219. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5220. var
  5221. possible: boolean;
  5222. i: longint;
  5223. iiep1: TIndexArray;
  5224. iiep2: TIndexArray;
  5225. begin
  5226. checkindex(intfindex);
  5227. checkindex(remainindex);
  5228. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5229. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5230. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5231. begin
  5232. possible:=true;
  5233. weight:=0;
  5234. end
  5235. else
  5236. begin
  5237. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5238. i:=1;
  5239. while (possible) and (i<=iiep1.count) do
  5240. begin
  5241. possible:=
  5242. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5243. inc(i);
  5244. end;
  5245. if possible then
  5246. weight:=iiep1.count;
  5247. end;
  5248. isimplmergepossible:=possible;
  5249. end;
  5250. {****************************************************************************
  5251. TFORWARDDEF
  5252. ****************************************************************************}
  5253. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5254. var
  5255. oldregisterdef : boolean;
  5256. begin
  5257. { never register the forwarddefs, they are disposed at the
  5258. end of the type declaration block }
  5259. oldregisterdef:=registerdef;
  5260. registerdef:=false;
  5261. inherited create;
  5262. registerdef:=oldregisterdef;
  5263. deftype:=forwarddef;
  5264. tosymname:=stringdup(s);
  5265. forwardpos:=pos;
  5266. end;
  5267. function tforwarddef.gettypename:string;
  5268. begin
  5269. gettypename:='unresolved forward to '+tosymname^;
  5270. end;
  5271. destructor tforwarddef.destroy;
  5272. begin
  5273. if assigned(tosymname) then
  5274. stringdispose(tosymname);
  5275. inherited destroy;
  5276. end;
  5277. {****************************************************************************
  5278. TERRORDEF
  5279. ****************************************************************************}
  5280. constructor terrordef.create;
  5281. begin
  5282. inherited create;
  5283. deftype:=errordef;
  5284. end;
  5285. {$ifdef GDB}
  5286. function terrordef.stabstring : pchar;
  5287. begin
  5288. stabstring:=strpnew('error'+numberstring);
  5289. end;
  5290. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5291. begin
  5292. { No internal error needed, an normal error is already
  5293. thrown }
  5294. end;
  5295. {$endif GDB}
  5296. function terrordef.gettypename:string;
  5297. begin
  5298. gettypename:='<erroneous type>';
  5299. end;
  5300. function terrordef.getmangledparaname:string;
  5301. begin
  5302. getmangledparaname:='error';
  5303. end;
  5304. {****************************************************************************
  5305. Definition Helpers
  5306. ****************************************************************************}
  5307. function is_interfacecom(def: tdef): boolean;
  5308. begin
  5309. is_interfacecom:=
  5310. assigned(def) and
  5311. (def.deftype=objectdef) and
  5312. (tobjectdef(def).objecttype=odt_interfacecom);
  5313. end;
  5314. function is_interfacecorba(def: tdef): boolean;
  5315. begin
  5316. is_interfacecorba:=
  5317. assigned(def) and
  5318. (def.deftype=objectdef) and
  5319. (tobjectdef(def).objecttype=odt_interfacecorba);
  5320. end;
  5321. function is_interface(def: tdef): boolean;
  5322. begin
  5323. is_interface:=
  5324. assigned(def) and
  5325. (def.deftype=objectdef) and
  5326. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5327. end;
  5328. function is_class(def: tdef): boolean;
  5329. begin
  5330. is_class:=
  5331. assigned(def) and
  5332. (def.deftype=objectdef) and
  5333. (tobjectdef(def).objecttype=odt_class);
  5334. end;
  5335. function is_object(def: tdef): boolean;
  5336. begin
  5337. is_object:=
  5338. assigned(def) and
  5339. (def.deftype=objectdef) and
  5340. (tobjectdef(def).objecttype=odt_object);
  5341. end;
  5342. function is_cppclass(def: tdef): boolean;
  5343. begin
  5344. is_cppclass:=
  5345. assigned(def) and
  5346. (def.deftype=objectdef) and
  5347. (tobjectdef(def).objecttype=odt_cppclass);
  5348. end;
  5349. function is_class_or_interface(def: tdef): boolean;
  5350. begin
  5351. is_class_or_interface:=
  5352. assigned(def) and
  5353. (def.deftype=objectdef) and
  5354. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5355. end;
  5356. end.
  5357. {
  5358. $Log$
  5359. Revision 1.243 2004-06-20 08:55:30 florian
  5360. * logs truncated
  5361. Revision 1.242 2004/06/18 15:16:46 peter
  5362. * remove obsolete cardinal() typecasts
  5363. Revision 1.241 2004/06/16 20:07:09 florian
  5364. * dwarf branch merged
  5365. Revision 1.240 2004/05/25 18:51:14 peter
  5366. * range check error
  5367. Revision 1.239 2004/05/23 20:57:10 peter
  5368. * removed unused voidprocdef
  5369. Revision 1.238 2004/05/23 15:23:30 peter
  5370. * fixed qword(longint) that removed sign from the number
  5371. * removed code in the compiler that relied on wrong qword(longint)
  5372. code generation
  5373. }