symdef.pas 192 KB

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