symdef.pas 192 KB

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