symdef.pas 192 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283
  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. { size of elements }
  2588. rttiList.concat(Tai_const.Create_32bit(elesize));
  2589. { count of elements, prevent overflow for 0..maxlongint }
  2590. if not(IsDynamicArray) then
  2591. rttiList.concat(Tai_const.Create_32bit(min(int64(highrange)-lowrange+1,maxlongint)));
  2592. { element type }
  2593. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2594. { variant type }
  2595. // !!!!!!!!!!!!!!!!
  2596. end;
  2597. function tarraydef.gettypename : string;
  2598. begin
  2599. if isarrayofconst or isConstructor then
  2600. begin
  2601. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2602. gettypename:='Array Of Const'
  2603. else
  2604. gettypename:='Array Of '+elementtype.def.typename;
  2605. end
  2606. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2607. gettypename:='Array Of '+elementtype.def.typename
  2608. else
  2609. begin
  2610. if rangetype.def.deftype=enumdef then
  2611. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2612. else
  2613. gettypename:='Array['+tostr(lowrange)+'..'+
  2614. tostr(highrange)+'] Of '+elementtype.def.typename
  2615. end;
  2616. end;
  2617. function tarraydef.getmangledparaname : string;
  2618. begin
  2619. if isarrayofconst then
  2620. getmangledparaname:='array_of_const'
  2621. else
  2622. if ((highrange=-1) and (lowrange=0)) then
  2623. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2624. else
  2625. internalerror(200204176);
  2626. end;
  2627. {***************************************************************************
  2628. tabstractrecorddef
  2629. ***************************************************************************}
  2630. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2631. begin
  2632. if t=gs_record then
  2633. getsymtable:=symtable
  2634. else
  2635. getsymtable:=nil;
  2636. end;
  2637. {$ifdef GDB}
  2638. procedure tabstractrecorddef.field_addname(p:Tnamedindexitem;arg:pointer);
  2639. var
  2640. newrec:Pchar;
  2641. spec:string[3];
  2642. varsize:longint;
  2643. state:^Trecord_stabgen_state;
  2644. begin
  2645. state:=arg;
  2646. { static variables from objects are like global objects }
  2647. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2648. begin
  2649. if (sp_protected in tsym(p).symoptions) then
  2650. spec:='/1'
  2651. else if (sp_private in tsym(p).symoptions) then
  2652. spec:='/0'
  2653. else
  2654. spec:='';
  2655. varsize:=tvarsym(p).vartype.def.size;
  2656. { open arrays made overflows !! }
  2657. if varsize>$fffffff then
  2658. varsize:=$fffffff;
  2659. newrec:=stabstr_evaluate('$1:$2,$3,$4;',[p.name,
  2660. spec+tstoreddef(tvarsym(p).vartype.def).numberstring,
  2661. tostr(tvarsym(p).fieldoffset*8),tostr(varsize*8)]);
  2662. if state^.stabsize+strlen(newrec)>=state^.staballoc-256 then
  2663. begin
  2664. inc(state^.staballoc,memsizeinc);
  2665. reallocmem(state^.stabstring,state^.staballoc);
  2666. end;
  2667. strcopy(state^.stabstring+state^.stabsize,newrec);
  2668. inc(state^.stabsize,strlen(newrec));
  2669. strdispose(newrec);
  2670. {This should be used for case !!}
  2671. inc(state^.recoffset,Tvarsym(p).vartype.def.size);
  2672. end;
  2673. end;
  2674. procedure tabstractrecorddef.field_concatstabto(p:Tnamedindexitem;arg:pointer);
  2675. begin
  2676. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2677. tstoreddef(tvarsym(p).vartype.def).concatstabto(taasmoutput(arg));
  2678. end;
  2679. {$endif GDB}
  2680. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2681. begin
  2682. if (FRTTIType=fullrtti) or
  2683. ((tsym(sym).typ=varsym) and
  2684. tvarsym(sym).vartype.def.needs_inittable) then
  2685. inc(Count);
  2686. end;
  2687. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2688. begin
  2689. if (FRTTIType=fullrtti) or
  2690. ((tsym(sym).typ=varsym) and
  2691. tvarsym(sym).vartype.def.needs_inittable) then
  2692. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2693. end;
  2694. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2695. begin
  2696. if (FRTTIType=fullrtti) or
  2697. ((tsym(sym).typ=varsym) and
  2698. tvarsym(sym).vartype.def.needs_inittable) then
  2699. begin
  2700. rttiList.concat(Tai_const.Create_sym(tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2701. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  2702. end;
  2703. end;
  2704. {***************************************************************************
  2705. trecorddef
  2706. ***************************************************************************}
  2707. constructor trecorddef.create(p : tsymtable);
  2708. begin
  2709. inherited create;
  2710. deftype:=recorddef;
  2711. symtable:=p;
  2712. symtable.defowner:=self;
  2713. isunion:=false;
  2714. end;
  2715. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2716. begin
  2717. inherited ppuloaddef(ppufile);
  2718. deftype:=recorddef;
  2719. symtable:=trecordsymtable.create(0);
  2720. trecordsymtable(symtable).datasize:=ppufile.getlongint;
  2721. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2722. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2723. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2724. trecordsymtable(symtable).ppuload(ppufile);
  2725. symtable.defowner:=self;
  2726. isunion:=false;
  2727. end;
  2728. destructor trecorddef.destroy;
  2729. begin
  2730. if assigned(symtable) then
  2731. symtable.free;
  2732. inherited destroy;
  2733. end;
  2734. function trecorddef.needs_inittable : boolean;
  2735. begin
  2736. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2737. end;
  2738. procedure trecorddef.buildderef;
  2739. var
  2740. oldrecsyms : tsymtable;
  2741. begin
  2742. inherited buildderef;
  2743. oldrecsyms:=aktrecordsymtable;
  2744. aktrecordsymtable:=symtable;
  2745. { now build the definitions }
  2746. tstoredsymtable(symtable).buildderef;
  2747. aktrecordsymtable:=oldrecsyms;
  2748. end;
  2749. procedure trecorddef.deref;
  2750. var
  2751. oldrecsyms : tsymtable;
  2752. begin
  2753. inherited deref;
  2754. oldrecsyms:=aktrecordsymtable;
  2755. aktrecordsymtable:=symtable;
  2756. { now dereference the definitions }
  2757. tstoredsymtable(symtable).deref;
  2758. aktrecordsymtable:=oldrecsyms;
  2759. { assign TGUID? load only from system unit (unitid=1) }
  2760. if not(assigned(rec_tguid)) and
  2761. (upper(typename)='TGUID') and
  2762. assigned(owner) and
  2763. assigned(owner.name) and
  2764. (owner.name^='SYSTEM') then
  2765. rec_tguid:=self;
  2766. end;
  2767. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2768. begin
  2769. inherited ppuwritedef(ppufile);
  2770. ppufile.putlongint(trecordsymtable(symtable).datasize);
  2771. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2772. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2773. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2774. ppufile.writeentry(ibrecorddef);
  2775. trecordsymtable(symtable).ppuwrite(ppufile);
  2776. end;
  2777. function trecorddef.size:longint;
  2778. begin
  2779. result:=trecordsymtable(symtable).datasize;
  2780. end;
  2781. function trecorddef.alignment:longint;
  2782. begin
  2783. alignment:=trecordsymtable(symtable).recordalignment;
  2784. end;
  2785. function trecorddef.padalignment:longint;
  2786. begin
  2787. padalignment := trecordsymtable(symtable).padalignment;
  2788. end;
  2789. {$ifdef GDB}
  2790. function trecorddef.stabstring : pchar;
  2791. var
  2792. state:Trecord_stabgen_state;
  2793. begin
  2794. getmem(state.stabstring,memsizeinc);
  2795. state.staballoc:=memsizeinc;
  2796. strpcopy(state.stabstring,'s'+tostr(size));
  2797. state.recoffset:=0;
  2798. state.stabsize:=strlen(state.stabstring);
  2799. symtable.foreach(@field_addname,@state);
  2800. state.stabstring[state.stabsize]:=';';
  2801. state.stabstring[state.stabsize+1]:=#0;
  2802. reallocmem(state.stabstring,state.stabsize+2);
  2803. stabstring:=state.stabstring;
  2804. end;
  2805. procedure trecorddef.concatstabto(asmlist:taasmoutput);
  2806. begin
  2807. if (stab_state in [stab_state_writing,stab_state_written]) then
  2808. exit;
  2809. symtable.foreach(@field_concatstabto,asmlist);
  2810. inherited concatstabto(asmlist);
  2811. end;
  2812. {$endif GDB}
  2813. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2814. begin
  2815. FRTTIType:=rt;
  2816. symtable.foreach(@generate_field_rtti,nil);
  2817. end;
  2818. procedure trecorddef.write_rtti_data(rt:trttitype);
  2819. begin
  2820. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2821. write_rtti_name;
  2822. {$ifdef cpurequiresproperalignment}
  2823. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2824. {$endif cpurequiresproperalignment}
  2825. rttiList.concat(Tai_const.Create_32bit(size));
  2826. Count:=0;
  2827. FRTTIType:=rt;
  2828. symtable.foreach(@count_field_rtti,nil);
  2829. rttiList.concat(Tai_const.Create_32bit(Count));
  2830. symtable.foreach(@write_field_rtti,nil);
  2831. end;
  2832. function trecorddef.gettypename : string;
  2833. begin
  2834. gettypename:='<record type>'
  2835. end;
  2836. {***************************************************************************
  2837. TABSTRACTPROCDEF
  2838. ***************************************************************************}
  2839. constructor tabstractprocdef.create(level:byte);
  2840. begin
  2841. inherited create;
  2842. parast:=tparasymtable.create(level);
  2843. parast.defowner:=self;
  2844. parast.next:=owner;
  2845. para:=TLinkedList.Create;
  2846. minparacount:=0;
  2847. maxparacount:=0;
  2848. proctypeoption:=potype_none;
  2849. proccalloption:=pocall_none;
  2850. procoptions:=[];
  2851. rettype:=voidtype;
  2852. {$ifdef i386}
  2853. fpu_used:=0;
  2854. {$endif i386}
  2855. savesize:=sizeof(aint);
  2856. requiredargarea:=0;
  2857. has_paraloc_info:=false;
  2858. funcret_paraloc[callerside].init;
  2859. funcret_paraloc[calleeside].init;
  2860. end;
  2861. destructor tabstractprocdef.destroy;
  2862. begin
  2863. if assigned(para) then
  2864. begin
  2865. {$ifdef MEMDEBUG}
  2866. memprocpara.start;
  2867. {$endif MEMDEBUG}
  2868. para.free;
  2869. {$ifdef MEMDEBUG}
  2870. memprocpara.stop;
  2871. {$endif MEMDEBUG}
  2872. end;
  2873. if assigned(parast) then
  2874. begin
  2875. {$ifdef MEMDEBUG}
  2876. memprocparast.start;
  2877. {$endif MEMDEBUG}
  2878. parast.free;
  2879. {$ifdef MEMDEBUG}
  2880. memprocparast.stop;
  2881. {$endif MEMDEBUG}
  2882. end;
  2883. funcret_paraloc[callerside].done;
  2884. funcret_paraloc[calleeside].done;
  2885. inherited destroy;
  2886. end;
  2887. procedure tabstractprocdef.releasemem;
  2888. begin
  2889. para.free;
  2890. para:=nil;
  2891. parast.free;
  2892. parast:=nil;
  2893. end;
  2894. function tabstractprocdef.concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2895. var
  2896. hp : TParaItem;
  2897. begin
  2898. hp:=TParaItem.Create;
  2899. hp.paratyp:=tvarsym(sym).varspez;
  2900. hp.parasym:=sym;
  2901. hp.paratype:=tt;
  2902. hp.is_hidden:=vhidden;
  2903. hp.defaultvalue:=defval;
  2904. { Parameters are stored from left to right }
  2905. if assigned(afterpara) then
  2906. Para.insertafter(hp,afterpara)
  2907. else
  2908. Para.concat(hp);
  2909. { Don't count hidden parameters }
  2910. if not vhidden then
  2911. begin
  2912. if not assigned(defval) then
  2913. inc(minparacount);
  2914. inc(maxparacount);
  2915. end;
  2916. concatpara:=hp;
  2917. end;
  2918. function tabstractprocdef.insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2919. var
  2920. hp : TParaItem;
  2921. begin
  2922. hp:=TParaItem.Create;
  2923. hp.paratyp:=tvarsym(sym).varspez;
  2924. hp.parasym:=sym;
  2925. hp.paratype:=tt;
  2926. hp.is_hidden:=vhidden;
  2927. hp.defaultvalue:=defval;
  2928. { Parameters are stored from left to right }
  2929. Para.insert(hp);
  2930. { Don't count hidden parameters }
  2931. if (not vhidden) then
  2932. begin
  2933. if not assigned(defval) then
  2934. inc(minparacount);
  2935. inc(maxparacount);
  2936. end;
  2937. insertpara:=hp;
  2938. end;
  2939. procedure tabstractprocdef.removepara(currpara:tparaitem);
  2940. begin
  2941. { Don't count hidden parameters }
  2942. if (not currpara.is_hidden) then
  2943. begin
  2944. if not assigned(currpara.defaultvalue) then
  2945. dec(minparacount);
  2946. dec(maxparacount);
  2947. end;
  2948. Para.Remove(currpara);
  2949. currpara.free;
  2950. end;
  2951. { all functions returning in FPU are
  2952. assume to use 2 FPU registers
  2953. until the function implementation
  2954. is processed PM }
  2955. procedure tabstractprocdef.test_if_fpu_result;
  2956. begin
  2957. {$ifdef i386}
  2958. if assigned(rettype.def) and
  2959. (rettype.def.deftype=floatdef) then
  2960. fpu_used:=maxfpuregs;
  2961. {$endif i386}
  2962. end;
  2963. procedure tabstractprocdef.buildderef;
  2964. var
  2965. hp : TParaItem;
  2966. begin
  2967. { released procdef? }
  2968. if not assigned(parast) then
  2969. exit;
  2970. inherited buildderef;
  2971. rettype.buildderef;
  2972. { parast }
  2973. tparasymtable(parast).buildderef;
  2974. { paraitems }
  2975. hp:=TParaItem(Para.first);
  2976. while assigned(hp) do
  2977. begin
  2978. hp.paratype.buildderef;
  2979. hp.defaultvaluederef.build(hp.defaultvalue);
  2980. hp.parasymderef.build(hp.parasym);
  2981. hp:=TParaItem(hp.next);
  2982. end;
  2983. end;
  2984. procedure tabstractprocdef.deref;
  2985. var
  2986. hp : TParaItem;
  2987. begin
  2988. inherited deref;
  2989. rettype.resolve;
  2990. { parast }
  2991. tparasymtable(parast).deref;
  2992. { paraitems }
  2993. minparacount:=0;
  2994. maxparacount:=0;
  2995. hp:=TParaItem(Para.first);
  2996. while assigned(hp) do
  2997. begin
  2998. hp.paratype.resolve;
  2999. hp.defaultvalue:=tsym(hp.defaultvaluederef.resolve);
  3000. hp.parasym:=tvarsym(hp.parasymderef.resolve);
  3001. { connect parasym to paraitem }
  3002. tvarsym(hp.parasym).paraitem:=hp;
  3003. { Don't count hidden parameters }
  3004. if (not hp.is_hidden) then
  3005. begin
  3006. if not assigned(hp.defaultvalue) then
  3007. inc(minparacount);
  3008. inc(maxparacount);
  3009. end;
  3010. hp:=TParaItem(hp.next);
  3011. end;
  3012. end;
  3013. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  3014. var
  3015. hp : TParaItem;
  3016. count,i : word;
  3017. begin
  3018. inherited ppuloaddef(ppufile);
  3019. parast:=nil;
  3020. Para:=TLinkedList.Create;
  3021. minparacount:=0;
  3022. maxparacount:=0;
  3023. ppufile.gettype(rettype);
  3024. {$ifdef i386}
  3025. fpu_used:=ppufile.getbyte;
  3026. {$else}
  3027. ppufile.getbyte;
  3028. {$endif i386}
  3029. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3030. proccalloption:=tproccalloption(ppufile.getbyte);
  3031. ppufile.getsmallset(procoptions);
  3032. if po_explicitparaloc in procoptions then
  3033. ppufile.getdata(funcret_paraloc,sizeof(funcret_paraloc));
  3034. { get the number of parameters }
  3035. count:=ppufile.getbyte;
  3036. savesize:=sizeof(aint);
  3037. has_paraloc_info:=false;
  3038. for i:=1 to count do
  3039. begin
  3040. hp:=TParaItem.Create;
  3041. hp.paratyp:=tvarspez(ppufile.getbyte);
  3042. ppufile.gettype(hp.paratype);
  3043. ppufile.getderef(hp.defaultvaluederef);
  3044. hp.defaultvalue:=nil;
  3045. ppufile.getderef(hp.parasymderef);
  3046. hp.parasym:=nil;
  3047. hp.is_hidden:=boolean(ppufile.getbyte);
  3048. if po_explicitparaloc in procoptions then
  3049. begin
  3050. ppufile.getdata(hp.paraloc,sizeof(hp.paraloc));
  3051. has_paraloc_info:=true;
  3052. end;
  3053. { Parameters are stored left to right in both ppu and memory }
  3054. Para.concat(hp);
  3055. end;
  3056. end;
  3057. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3058. var
  3059. hp : TParaItem;
  3060. oldintfcrc : boolean;
  3061. begin
  3062. { released procdef? }
  3063. if not assigned(parast) then
  3064. exit;
  3065. inherited ppuwritedef(ppufile);
  3066. ppufile.puttype(rettype);
  3067. oldintfcrc:=ppufile.do_interface_crc;
  3068. ppufile.do_interface_crc:=false;
  3069. {$ifdef i386}
  3070. if simplify_ppu then
  3071. fpu_used:=0;
  3072. ppufile.putbyte(fpu_used);
  3073. {$else}
  3074. ppufile.putbyte(0);
  3075. {$endif}
  3076. ppufile.putbyte(ord(proctypeoption));
  3077. ppufile.putbyte(ord(proccalloption));
  3078. ppufile.putsmallset(procoptions);
  3079. ppufile.do_interface_crc:=oldintfcrc;
  3080. if po_explicitparaloc in procoptions then
  3081. ppufile.putdata(funcret_paraloc,sizeof(funcret_paraloc));
  3082. { we need to store the count including vs_hidden }
  3083. ppufile.putbyte(para.count);
  3084. hp:=TParaItem(Para.first);
  3085. while assigned(hp) do
  3086. begin
  3087. ppufile.putbyte(byte(hp.paratyp));
  3088. ppufile.puttype(hp.paratype);
  3089. ppufile.putderef(hp.defaultvaluederef);
  3090. ppufile.putderef(hp.parasymderef);
  3091. ppufile.putbyte(byte(hp.is_hidden));
  3092. if po_explicitparaloc in procoptions then
  3093. ppufile.putdata(hp.paraloc,sizeof(hp.paraloc));
  3094. hp:=TParaItem(hp.next);
  3095. end;
  3096. end;
  3097. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  3098. var
  3099. hs,s : string;
  3100. hp : TParaItem;
  3101. hpc : tconstsym;
  3102. first : boolean;
  3103. begin
  3104. hp:=TParaItem(Para.first);
  3105. s:='';
  3106. first:=true;
  3107. while assigned(hp) do
  3108. begin
  3109. if (not hp.is_hidden) or
  3110. (showhidden) then
  3111. begin
  3112. if first then
  3113. begin
  3114. s:=s+'(';
  3115. first:=false;
  3116. end
  3117. else
  3118. s:=s+',';
  3119. case hp.paratyp of
  3120. vs_var :
  3121. s:=s+'var';
  3122. vs_const :
  3123. s:=s+'const';
  3124. vs_out :
  3125. s:=s+'out';
  3126. end;
  3127. if assigned(hp.paratype.def.typesym) then
  3128. begin
  3129. if s<>'(' then
  3130. s:=s+' ';
  3131. hs:=hp.paratype.def.typesym.realname;
  3132. if hs[1]<>'$' then
  3133. s:=s+hp.paratype.def.typesym.realname
  3134. else
  3135. s:=s+hp.paratype.def.gettypename;
  3136. end
  3137. else
  3138. s:=s+hp.paratype.def.gettypename;
  3139. { default value }
  3140. if assigned(hp.defaultvalue) then
  3141. begin
  3142. hpc:=tconstsym(hp.defaultvalue);
  3143. hs:='';
  3144. case hpc.consttyp of
  3145. conststring,
  3146. constresourcestring :
  3147. hs:=strpas(pchar(hpc.value.valueptr));
  3148. constreal :
  3149. str(pbestreal(hpc.value.valueptr)^,hs);
  3150. constpointer :
  3151. hs:=tostr(hpc.value.valueordptr);
  3152. constord :
  3153. begin
  3154. if is_boolean(hpc.consttype.def) then
  3155. begin
  3156. if hpc.value.valueord<>0 then
  3157. hs:='TRUE'
  3158. else
  3159. hs:='FALSE';
  3160. end
  3161. else
  3162. hs:=tostr(hpc.value.valueord);
  3163. end;
  3164. constnil :
  3165. hs:='nil';
  3166. constset :
  3167. hs:='<set>';
  3168. end;
  3169. if hs<>'' then
  3170. s:=s+'="'+hs+'"';
  3171. end;
  3172. end;
  3173. hp:=TParaItem(hp.next);
  3174. end;
  3175. if not first then
  3176. s:=s+')';
  3177. if (po_varargs in procoptions) then
  3178. s:=s+';VarArgs';
  3179. typename_paras:=s;
  3180. end;
  3181. function tabstractprocdef.is_methodpointer:boolean;
  3182. begin
  3183. result:=false;
  3184. end;
  3185. function tabstractprocdef.is_addressonly:boolean;
  3186. begin
  3187. result:=true;
  3188. end;
  3189. {$ifdef GDB}
  3190. function tabstractprocdef.stabstring : pchar;
  3191. begin
  3192. stabstring := strpnew('abstractproc'+numberstring+';');
  3193. end;
  3194. {$endif GDB}
  3195. {***************************************************************************
  3196. TPROCDEF
  3197. ***************************************************************************}
  3198. constructor tprocdef.create(level:byte);
  3199. begin
  3200. inherited create(level);
  3201. deftype:=procdef;
  3202. has_mangledname:=false;
  3203. _mangledname:=nil;
  3204. fileinfo:=aktfilepos;
  3205. extnumber:=$ffff;
  3206. aliasnames:=tstringlist.create;
  3207. funcretsym:=nil;
  3208. localst := nil;
  3209. defref:=nil;
  3210. lastwritten:=nil;
  3211. refcount:=0;
  3212. if (cs_browser in aktmoduleswitches) and make_ref then
  3213. begin
  3214. defref:=tref.create(defref,@akttokenpos);
  3215. inc(refcount);
  3216. end;
  3217. lastref:=defref;
  3218. forwarddef:=true;
  3219. interfacedef:=false;
  3220. hasforward:=false;
  3221. _class := nil;
  3222. new(inlininginfo);
  3223. fillchar(inlininginfo^,sizeof(tinlininginfo),0);
  3224. overloadnumber:=0;
  3225. {$ifdef GDB}
  3226. isstabwritten := false;
  3227. {$endif GDB}
  3228. end;
  3229. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3230. var
  3231. level : byte;
  3232. begin
  3233. inherited ppuload(ppufile);
  3234. deftype:=procdef;
  3235. has_mangledname:=boolean(ppufile.getbyte);
  3236. if has_mangledname then
  3237. _mangledname:=stringdup(ppufile.getstring)
  3238. else
  3239. _mangledname:=nil;
  3240. overloadnumber:=ppufile.getword;
  3241. extnumber:=ppufile.getword;
  3242. level:=ppufile.getbyte;
  3243. ppufile.getderef(_classderef);
  3244. ppufile.getderef(procsymderef);
  3245. ppufile.getposinfo(fileinfo);
  3246. ppufile.getsmallset(symoptions);
  3247. {$ifdef powerpc}
  3248. { library symbol for AmigaOS/MorphOS }
  3249. ppufile.getderef(libsymderef);
  3250. {$endif powerpc}
  3251. { inline stuff }
  3252. if proccalloption=pocall_inline then
  3253. begin
  3254. ppufile.getderef(funcretsymderef);
  3255. new(inlininginfo);
  3256. ppufile.getsmallset(inlininginfo^.flags);
  3257. inlininginfo^.inlinenode:=boolean(ppufile.getbyte);
  3258. end
  3259. else
  3260. funcretsym:=nil;
  3261. { load para symtable }
  3262. parast:=tparasymtable.create(level);
  3263. tparasymtable(parast).ppuload(ppufile);
  3264. parast.defowner:=self;
  3265. { load local symtable }
  3266. if ((proccalloption=pocall_inline) or
  3267. ((current_module.flags and uf_local_browser)<>0)) then
  3268. begin
  3269. localst:=tlocalsymtable.create(level);
  3270. tlocalsymtable(localst).ppuload(ppufile);
  3271. localst.defowner:=self;
  3272. end
  3273. else
  3274. localst:=nil;
  3275. { inline stuff }
  3276. if proccalloption=pocall_inline then
  3277. inlininginfo^.code:=ppuloadnodetree(ppufile)
  3278. else
  3279. inlininginfo := nil;
  3280. { default values for no persistent data }
  3281. if (cs_link_deffile in aktglobalswitches) and
  3282. (tf_need_export in target_info.flags) and
  3283. (po_exports in procoptions) then
  3284. deffile.AddExport(mangledname);
  3285. aliasnames:=tstringlist.create;
  3286. forwarddef:=false;
  3287. interfacedef:=false;
  3288. hasforward:=false;
  3289. lastref:=nil;
  3290. lastwritten:=nil;
  3291. defref:=nil;
  3292. refcount:=0;
  3293. {$ifdef GDB}
  3294. isstabwritten := false;
  3295. {$endif GDB}
  3296. end;
  3297. destructor tprocdef.destroy;
  3298. begin
  3299. if assigned(defref) then
  3300. begin
  3301. defref.freechain;
  3302. defref.free;
  3303. end;
  3304. aliasnames.free;
  3305. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3306. begin
  3307. {$ifdef MEMDEBUG}
  3308. memproclocalst.start;
  3309. {$endif MEMDEBUG}
  3310. localst.free;
  3311. {$ifdef MEMDEBUG}
  3312. memproclocalst.start;
  3313. {$endif MEMDEBUG}
  3314. end;
  3315. if (proccalloption=pocall_inline) and assigned(inlininginfo) then
  3316. begin
  3317. {$ifdef MEMDEBUG}
  3318. memprocnodetree.start;
  3319. {$endif MEMDEBUG}
  3320. tnode(inlininginfo^.code).free;
  3321. {$ifdef MEMDEBUG}
  3322. memprocnodetree.start;
  3323. {$endif MEMDEBUG}
  3324. end;
  3325. if assigned(inlininginfo) then
  3326. dispose(inlininginfo);
  3327. if (po_msgstr in procoptions) then
  3328. strdispose(messageinf.str);
  3329. if assigned(_mangledname) then
  3330. begin
  3331. {$ifdef MEMDEBUG}
  3332. memmanglednames.start;
  3333. {$endif MEMDEBUG}
  3334. stringdispose(_mangledname);
  3335. {$ifdef MEMDEBUG}
  3336. memmanglednames.stop;
  3337. {$endif MEMDEBUG}
  3338. end;
  3339. inherited destroy;
  3340. end;
  3341. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3342. var
  3343. oldintfcrc : boolean;
  3344. oldparasymtable,
  3345. oldlocalsymtable : tsymtable;
  3346. begin
  3347. { released procdef? }
  3348. if not assigned(parast) then
  3349. exit;
  3350. oldparasymtable:=aktparasymtable;
  3351. oldlocalsymtable:=aktlocalsymtable;
  3352. aktparasymtable:=parast;
  3353. aktlocalsymtable:=localst;
  3354. inherited ppuwrite(ppufile);
  3355. oldintfcrc:=ppufile.do_interface_crc;
  3356. ppufile.do_interface_crc:=false;
  3357. ppufile.do_interface_crc:=oldintfcrc;
  3358. ppufile.putbyte(byte(has_mangledname));
  3359. if has_mangledname then
  3360. ppufile.putstring(_mangledname^);
  3361. ppufile.putword(overloadnumber);
  3362. ppufile.putword(extnumber);
  3363. ppufile.putbyte(parast.symtablelevel);
  3364. ppufile.putderef(_classderef);
  3365. ppufile.putderef(procsymderef);
  3366. ppufile.putposinfo(fileinfo);
  3367. ppufile.putsmallset(symoptions);
  3368. {$ifdef powerpc}
  3369. { library symbol for AmigaOS/MorphOS }
  3370. ppufile.putderef(libsymderef);
  3371. {$endif powerpc}
  3372. { inline stuff }
  3373. oldintfcrc:=ppufile.do_crc;
  3374. ppufile.do_crc:=false;
  3375. if proccalloption=pocall_inline then
  3376. begin
  3377. ppufile.putderef(funcretsymderef);
  3378. ppufile.putsmallset(inlininginfo^.flags);
  3379. ppufile.putbyte(byte(inlininginfo^.inlinenode));
  3380. end;
  3381. ppufile.do_crc:=oldintfcrc;
  3382. { write this entry }
  3383. ppufile.writeentry(ibprocdef);
  3384. { Save the para symtable, this is taken from the interface }
  3385. tparasymtable(parast).ppuwrite(ppufile);
  3386. { save localsymtable for inline procedures or when local
  3387. browser info is requested, this has no influence on the crc }
  3388. if (proccalloption=pocall_inline) or
  3389. ((current_module.flags and uf_local_browser)<>0) then
  3390. begin
  3391. { we must write a localsymtable }
  3392. if not assigned(localst) then
  3393. insert_localst;
  3394. oldintfcrc:=ppufile.do_crc;
  3395. ppufile.do_crc:=false;
  3396. tlocalsymtable(localst).ppuwrite(ppufile);
  3397. ppufile.do_crc:=oldintfcrc;
  3398. end;
  3399. { node tree for inlining }
  3400. oldintfcrc:=ppufile.do_crc;
  3401. ppufile.do_crc:=false;
  3402. if proccalloption=pocall_inline then
  3403. ppuwritenodetree(ppufile,inlininginfo^.code);
  3404. ppufile.do_crc:=oldintfcrc;
  3405. aktparasymtable:=oldparasymtable;
  3406. aktlocalsymtable:=oldlocalsymtable;
  3407. end;
  3408. procedure tprocdef.insert_localst;
  3409. begin
  3410. localst:=tlocalsymtable.create(parast.symtablelevel);
  3411. localst.defowner:=self;
  3412. { this is used by insert
  3413. to check same names in parast and localst }
  3414. localst.next:=parast;
  3415. end;
  3416. function tprocdef.fullprocname(showhidden:boolean):string;
  3417. var
  3418. s : string;
  3419. t : ttoken;
  3420. begin
  3421. {$ifdef EXTDEBUG}
  3422. showhidden:=true;
  3423. {$endif EXTDEBUG}
  3424. s:='';
  3425. if assigned(_class) then
  3426. begin
  3427. if po_classmethod in procoptions then
  3428. s:=s+'class ';
  3429. s:=s+_class.objrealname^+'.';
  3430. end;
  3431. if proctypeoption=potype_operator then
  3432. begin
  3433. for t:=NOTOKEN to last_overloaded do
  3434. if procsym.realname='$'+overloaded_names[t] then
  3435. begin
  3436. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3437. break;
  3438. end;
  3439. end
  3440. else
  3441. s:=s+procsym.realname+typename_paras(showhidden);
  3442. case proctypeoption of
  3443. potype_constructor:
  3444. s:='constructor '+s;
  3445. potype_destructor:
  3446. s:='destructor '+s;
  3447. else
  3448. if assigned(rettype.def) and
  3449. not(is_void(rettype.def)) then
  3450. s:=s+':'+rettype.def.gettypename;
  3451. end;
  3452. { forced calling convention? }
  3453. if (po_hascallingconvention in procoptions) then
  3454. s:=s+';'+ProcCallOptionStr[proccalloption];
  3455. fullprocname:=s;
  3456. end;
  3457. function tprocdef.is_methodpointer:boolean;
  3458. begin
  3459. result:=assigned(_class);
  3460. end;
  3461. function tprocdef.is_addressonly:boolean;
  3462. begin
  3463. result:=assigned(owner) and
  3464. (owner.symtabletype<>objectsymtable);
  3465. end;
  3466. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3467. begin
  3468. is_visible_for_object:=false;
  3469. { private symbols are allowed when we are in the same
  3470. module as they are defined }
  3471. if (sp_private in symoptions) and
  3472. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3473. (owner.defowner.owner.unitid<>0) then
  3474. exit;
  3475. { protected symbols are vissible in the module that defines them and
  3476. also visible to related objects. The related object must be defined
  3477. in the current module }
  3478. if (sp_protected in symoptions) and
  3479. (
  3480. (
  3481. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3482. (owner.defowner.owner.unitid<>0)
  3483. ) and
  3484. not(
  3485. assigned(currobjdef) and
  3486. (currobjdef.owner.unitid=0) and
  3487. currobjdef.is_related(tobjectdef(owner.defowner))
  3488. )
  3489. ) then
  3490. exit;
  3491. is_visible_for_object:=true;
  3492. end;
  3493. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3494. begin
  3495. case t of
  3496. gs_local :
  3497. getsymtable:=localst;
  3498. gs_para :
  3499. getsymtable:=parast;
  3500. else
  3501. getsymtable:=nil;
  3502. end;
  3503. end;
  3504. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3505. var
  3506. pos : tfileposinfo;
  3507. move_last : boolean;
  3508. oldparasymtable,
  3509. oldlocalsymtable : tsymtable;
  3510. begin
  3511. oldparasymtable:=aktparasymtable;
  3512. oldlocalsymtable:=aktlocalsymtable;
  3513. aktparasymtable:=parast;
  3514. aktlocalsymtable:=localst;
  3515. move_last:=lastwritten=lastref;
  3516. while (not ppufile.endofentry) do
  3517. begin
  3518. ppufile.getposinfo(pos);
  3519. inc(refcount);
  3520. lastref:=tref.create(lastref,@pos);
  3521. lastref.is_written:=true;
  3522. if refcount=1 then
  3523. defref:=lastref;
  3524. end;
  3525. if move_last then
  3526. lastwritten:=lastref;
  3527. if ((current_module.flags and uf_local_browser)<>0) and
  3528. assigned(localst) and
  3529. locals then
  3530. begin
  3531. tparasymtable(parast).load_references(ppufile,locals);
  3532. tlocalsymtable(localst).load_references(ppufile,locals);
  3533. end;
  3534. aktparasymtable:=oldparasymtable;
  3535. aktlocalsymtable:=oldlocalsymtable;
  3536. end;
  3537. Const
  3538. local_symtable_index : word = $8001;
  3539. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3540. var
  3541. ref : tref;
  3542. pdo : tobjectdef;
  3543. move_last : boolean;
  3544. d : tderef;
  3545. oldparasymtable,
  3546. oldlocalsymtable : tsymtable;
  3547. begin
  3548. d.reset;
  3549. move_last:=lastwritten=lastref;
  3550. if move_last and
  3551. (((current_module.flags and uf_local_browser)=0) or
  3552. not locals) then
  3553. exit;
  3554. oldparasymtable:=aktparasymtable;
  3555. oldlocalsymtable:=aktlocalsymtable;
  3556. aktparasymtable:=parast;
  3557. aktlocalsymtable:=localst;
  3558. { write address of this symbol }
  3559. d.build(self);
  3560. ppufile.putderef(d);
  3561. { write refs }
  3562. if assigned(lastwritten) then
  3563. ref:=lastwritten
  3564. else
  3565. ref:=defref;
  3566. while assigned(ref) do
  3567. begin
  3568. if ref.moduleindex=current_module.unit_index then
  3569. begin
  3570. ppufile.putposinfo(ref.posinfo);
  3571. ref.is_written:=true;
  3572. if move_last then
  3573. lastwritten:=ref;
  3574. end
  3575. else if not ref.is_written then
  3576. move_last:=false
  3577. else if move_last then
  3578. lastwritten:=ref;
  3579. ref:=ref.nextref;
  3580. end;
  3581. ppufile.writeentry(ibdefref);
  3582. write_references:=true;
  3583. if ((current_module.flags and uf_local_browser)<>0) and
  3584. assigned(localst) and
  3585. locals then
  3586. begin
  3587. pdo:=_class;
  3588. if (owner.symtabletype<>localsymtable) then
  3589. while assigned(pdo) do
  3590. begin
  3591. if pdo.symtable<>aktrecordsymtable then
  3592. begin
  3593. pdo.symtable.unitid:=local_symtable_index;
  3594. inc(local_symtable_index);
  3595. end;
  3596. pdo:=pdo.childof;
  3597. end;
  3598. parast.unitid:=local_symtable_index;
  3599. inc(local_symtable_index);
  3600. localst.unitid:=local_symtable_index;
  3601. inc(local_symtable_index);
  3602. tstoredsymtable(parast).write_references(ppufile,locals);
  3603. tstoredsymtable(localst).write_references(ppufile,locals);
  3604. { decrement for }
  3605. local_symtable_index:=local_symtable_index-2;
  3606. pdo:=_class;
  3607. if (owner.symtabletype<>localsymtable) then
  3608. while assigned(pdo) do
  3609. begin
  3610. if pdo.symtable<>aktrecordsymtable then
  3611. dec(local_symtable_index);
  3612. pdo:=pdo.childof;
  3613. end;
  3614. end;
  3615. aktparasymtable:=oldparasymtable;
  3616. aktlocalsymtable:=oldlocalsymtable;
  3617. end;
  3618. {$ifdef GDB}
  3619. function tprocdef.numberstring : string;
  3620. begin
  3621. { procdefs are always available }
  3622. stab_state:=stab_state_written;
  3623. result:=inherited numberstring;
  3624. end;
  3625. function tprocdef.stabstring: pchar;
  3626. Var
  3627. RType : Char;
  3628. Obj,Info : String;
  3629. stabsstr : string;
  3630. p : pchar;
  3631. begin
  3632. obj := procsym.name;
  3633. info := '';
  3634. if tprocsym(procsym).is_global then
  3635. RType := 'F'
  3636. else
  3637. RType := 'f';
  3638. if assigned(owner) then
  3639. begin
  3640. if (owner.symtabletype = objectsymtable) then
  3641. obj := owner.name^+'__'+procsym.name;
  3642. if not(cs_gdb_valgrind in aktglobalswitches) and
  3643. (owner.symtabletype=localsymtable) and
  3644. assigned(owner.defowner) and
  3645. assigned(tprocdef(owner.defowner).procsym) then
  3646. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3647. end;
  3648. stabsstr:=mangledname;
  3649. getmem(p,length(stabsstr)+255);
  3650. strpcopy(p,'"'+obj+':'+RType
  3651. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3652. +',0,'+
  3653. tostr(fileinfo.line)
  3654. +',');
  3655. strpcopy(strend(p),stabsstr);
  3656. stabstring:=strnew(p);
  3657. freemem(p,length(stabsstr)+255);
  3658. end;
  3659. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3660. begin
  3661. { released procdef? }
  3662. if not assigned(parast) then
  3663. exit;
  3664. if (proccalloption=pocall_internproc) then
  3665. exit;
  3666. { be sure to have a number assigned for this def }
  3667. numberstring;
  3668. { write stabs }
  3669. stab_state:=stab_state_writing;
  3670. asmList.concat(Tai_stabs.Create(stabstring));
  3671. if not(po_external in procoptions) then
  3672. begin
  3673. tstoredsymtable(parast).concatstabto(asmlist);
  3674. { local type defs and vars should not be written
  3675. inside the main proc stab }
  3676. if assigned(localst) and
  3677. (localst.symtablelevel>main_program_level) then
  3678. tstoredsymtable(localst).concatstabto(asmlist);
  3679. end;
  3680. stab_state:=stab_state_written;
  3681. end;
  3682. {$endif GDB}
  3683. procedure tprocdef.buildderef;
  3684. var
  3685. oldparasymtable,
  3686. oldlocalsymtable : tsymtable;
  3687. begin
  3688. oldparasymtable:=aktparasymtable;
  3689. oldlocalsymtable:=aktlocalsymtable;
  3690. aktparasymtable:=parast;
  3691. aktlocalsymtable:=localst;
  3692. inherited buildderef;
  3693. _classderef.build(_class);
  3694. { procsym that originaly defined this definition, should be in the
  3695. same symtable }
  3696. procsymderef.build(procsym);
  3697. {$ifdef powerpc}
  3698. { library symbol for AmigaOS/MorphOS }
  3699. libsymderef.build(libsym);
  3700. {$endif powerpc}
  3701. aktparasymtable:=oldparasymtable;
  3702. aktlocalsymtable:=oldlocalsymtable;
  3703. end;
  3704. procedure tprocdef.buildderefimpl;
  3705. var
  3706. oldparasymtable,
  3707. oldlocalsymtable : tsymtable;
  3708. begin
  3709. { released procdef? }
  3710. if not assigned(parast) then
  3711. exit;
  3712. oldparasymtable:=aktparasymtable;
  3713. oldlocalsymtable:=aktlocalsymtable;
  3714. aktparasymtable:=parast;
  3715. aktlocalsymtable:=localst;
  3716. inherited buildderefimpl;
  3717. { Locals }
  3718. if assigned(localst) and
  3719. ((proccalloption=pocall_inline) or
  3720. ((current_module.flags and uf_local_browser)<>0)) then
  3721. begin
  3722. tlocalsymtable(localst).buildderef;
  3723. tlocalsymtable(localst).buildderefimpl;
  3724. end;
  3725. { inline tree }
  3726. if (proccalloption=pocall_inline) then
  3727. begin
  3728. funcretsymderef.build(funcretsym);
  3729. inlininginfo^.code.buildderefimpl;
  3730. end;
  3731. aktparasymtable:=oldparasymtable;
  3732. aktlocalsymtable:=oldlocalsymtable;
  3733. end;
  3734. procedure tprocdef.deref;
  3735. var
  3736. oldparasymtable,
  3737. oldlocalsymtable : tsymtable;
  3738. begin
  3739. { released procdef? }
  3740. if not assigned(parast) then
  3741. exit;
  3742. oldparasymtable:=aktparasymtable;
  3743. oldlocalsymtable:=aktlocalsymtable;
  3744. aktparasymtable:=parast;
  3745. aktlocalsymtable:=localst;
  3746. inherited deref;
  3747. _class:=tobjectdef(_classderef.resolve);
  3748. { procsym that originaly defined this definition, should be in the
  3749. same symtable }
  3750. procsym:=tprocsym(procsymderef.resolve);
  3751. {$ifdef powerpc}
  3752. { library symbol for AmigaOS/MorphOS }
  3753. libsym:=tvarsym(libsymderef.resolve);
  3754. {$endif powerpc}
  3755. aktparasymtable:=oldparasymtable;
  3756. aktlocalsymtable:=oldlocalsymtable;
  3757. end;
  3758. procedure tprocdef.derefimpl;
  3759. var
  3760. oldparasymtable,
  3761. oldlocalsymtable : tsymtable;
  3762. begin
  3763. oldparasymtable:=aktparasymtable;
  3764. oldlocalsymtable:=aktlocalsymtable;
  3765. aktparasymtable:=parast;
  3766. aktlocalsymtable:=localst;
  3767. { Locals }
  3768. if assigned(localst) then
  3769. begin
  3770. tlocalsymtable(localst).deref;
  3771. tlocalsymtable(localst).derefimpl;
  3772. end;
  3773. { Inline }
  3774. if (proccalloption=pocall_inline) then
  3775. begin
  3776. inlininginfo^.code.derefimpl;
  3777. { funcretsym, this is always located in the localst }
  3778. funcretsym:=tsym(funcretsymderef.resolve);
  3779. end
  3780. else
  3781. begin
  3782. { safety }
  3783. funcretsym:=nil;
  3784. end;
  3785. aktparasymtable:=oldparasymtable;
  3786. aktlocalsymtable:=oldlocalsymtable;
  3787. end;
  3788. function tprocdef.gettypename : string;
  3789. begin
  3790. gettypename := FullProcName(false);
  3791. end;
  3792. function tprocdef.mangledname : string;
  3793. var
  3794. hp : TParaItem;
  3795. begin
  3796. if assigned(_mangledname) then
  3797. begin
  3798. {$ifdef compress}
  3799. mangledname:=minilzw_decode(_mangledname^);
  3800. {$else}
  3801. mangledname:=_mangledname^;
  3802. {$endif}
  3803. exit;
  3804. end;
  3805. { we need to use the symtable where the procsym is inserted,
  3806. because that is visible to the world }
  3807. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3808. if overloadnumber>0 then
  3809. mangledname:=mangledname+'$'+tostr(overloadnumber);
  3810. { add parameter types }
  3811. hp:=TParaItem(Para.first);
  3812. while assigned(hp) do
  3813. begin
  3814. if not hp.is_hidden then
  3815. mangledname:=mangledname+'$'+hp.paratype.def.mangledparaname;
  3816. hp:=TParaItem(hp.next);
  3817. end;
  3818. {$ifdef compress}
  3819. _mangledname:=stringdup(minilzw_encode(mangledname));
  3820. {$else}
  3821. _mangledname:=stringdup(mangledname);
  3822. {$endif}
  3823. end;
  3824. function tprocdef.cplusplusmangledname : string;
  3825. function getcppparaname(p : tdef) : string;
  3826. const
  3827. ordtype2str : array[tbasetype] of string[2] = (
  3828. '',
  3829. 'Uc','Us','Ui','Us',
  3830. 'Sc','s','i','x',
  3831. 'b','b','b',
  3832. 'c','w','x');
  3833. var
  3834. s : string;
  3835. begin
  3836. case p.deftype of
  3837. orddef:
  3838. s:=ordtype2str[torddef(p).typ];
  3839. pointerdef:
  3840. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3841. else
  3842. internalerror(2103001);
  3843. end;
  3844. getcppparaname:=s;
  3845. end;
  3846. var
  3847. s,s2 : string;
  3848. param : TParaItem;
  3849. begin
  3850. s := procsym.realname;
  3851. if procsym.owner.symtabletype=objectsymtable then
  3852. begin
  3853. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3854. case proctypeoption of
  3855. potype_destructor:
  3856. s:='_$_'+tostr(length(s2))+s2;
  3857. potype_constructor:
  3858. s:='___'+tostr(length(s2))+s2;
  3859. else
  3860. s:='_'+s+'__'+tostr(length(s2))+s2;
  3861. end;
  3862. end
  3863. else s:=s+'__';
  3864. s:=s+'F';
  3865. { concat modifiers }
  3866. { !!!!! }
  3867. { now we handle the parameters }
  3868. param := TParaItem(Para.first);
  3869. if assigned(param) then
  3870. while assigned(param) do
  3871. begin
  3872. s2:=getcppparaname(param.paratype.def);
  3873. if param.paratyp in [vs_var,vs_out] then
  3874. s2:='R'+s2;
  3875. s:=s+s2;
  3876. param:=TParaItem(param.next);
  3877. end
  3878. else
  3879. s:=s+'v';
  3880. cplusplusmangledname:=s;
  3881. end;
  3882. procedure tprocdef.setmangledname(const s : string);
  3883. begin
  3884. stringdispose(_mangledname);
  3885. {$ifdef compress}
  3886. _mangledname:=stringdup(minilzw_encode(s));
  3887. {$else}
  3888. _mangledname:=stringdup(s);
  3889. {$endif}
  3890. has_mangledname:=true;
  3891. end;
  3892. {***************************************************************************
  3893. TPROCVARDEF
  3894. ***************************************************************************}
  3895. constructor tprocvardef.create(level:byte);
  3896. begin
  3897. inherited create(level);
  3898. deftype:=procvardef;
  3899. end;
  3900. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3901. begin
  3902. inherited ppuload(ppufile);
  3903. deftype:=procvardef;
  3904. { load para symtable }
  3905. parast:=tparasymtable.create(unknown_level);
  3906. tparasymtable(parast).ppuload(ppufile);
  3907. parast.defowner:=self;
  3908. end;
  3909. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3910. var
  3911. oldparasymtable,
  3912. oldlocalsymtable : tsymtable;
  3913. begin
  3914. oldparasymtable:=aktparasymtable;
  3915. oldlocalsymtable:=aktlocalsymtable;
  3916. aktparasymtable:=parast;
  3917. aktlocalsymtable:=nil;
  3918. { here we cannot get a real good value so just give something }
  3919. { plausible (PM) }
  3920. { a more secure way would be
  3921. to allways store in a temp }
  3922. {$ifdef i386}
  3923. if is_fpu(rettype.def) then
  3924. fpu_used:={2}maxfpuregs
  3925. else
  3926. fpu_used:=0;
  3927. {$endif i386}
  3928. inherited ppuwrite(ppufile);
  3929. { Write this entry }
  3930. ppufile.writeentry(ibprocvardef);
  3931. { Save the para symtable, this is taken from the interface }
  3932. tparasymtable(parast).ppuwrite(ppufile);
  3933. aktparasymtable:=oldparasymtable;
  3934. aktlocalsymtable:=oldlocalsymtable;
  3935. end;
  3936. procedure tprocvardef.buildderef;
  3937. var
  3938. oldparasymtable,
  3939. oldlocalsymtable : tsymtable;
  3940. begin
  3941. oldparasymtable:=aktparasymtable;
  3942. oldlocalsymtable:=aktlocalsymtable;
  3943. aktparasymtable:=parast;
  3944. aktlocalsymtable:=nil;
  3945. inherited buildderef;
  3946. aktparasymtable:=oldparasymtable;
  3947. aktlocalsymtable:=oldlocalsymtable;
  3948. end;
  3949. procedure tprocvardef.deref;
  3950. var
  3951. oldparasymtable,
  3952. oldlocalsymtable : tsymtable;
  3953. begin
  3954. oldparasymtable:=aktparasymtable;
  3955. oldlocalsymtable:=aktlocalsymtable;
  3956. aktparasymtable:=parast;
  3957. aktlocalsymtable:=nil;
  3958. inherited deref;
  3959. aktparasymtable:=oldparasymtable;
  3960. aktlocalsymtable:=oldlocalsymtable;
  3961. end;
  3962. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3963. begin
  3964. case t of
  3965. gs_para :
  3966. getsymtable:=parast;
  3967. else
  3968. getsymtable:=nil;
  3969. end;
  3970. end;
  3971. function tprocvardef.size : longint;
  3972. begin
  3973. if (po_methodpointer in procoptions) and
  3974. not(po_addressonly in procoptions) then
  3975. size:=2*sizeof(aint)
  3976. else
  3977. size:=sizeof(aint);
  3978. end;
  3979. function tprocvardef.is_methodpointer:boolean;
  3980. begin
  3981. result:=(po_methodpointer in procoptions);
  3982. end;
  3983. function tprocvardef.is_addressonly:boolean;
  3984. begin
  3985. result:=not(po_methodpointer in procoptions) or
  3986. (po_addressonly in procoptions);
  3987. end;
  3988. {$ifdef GDB}
  3989. function tprocvardef.stabstring : pchar;
  3990. var
  3991. nss : pchar;
  3992. { i : longint; }
  3993. begin
  3994. { i := maxparacount; }
  3995. getmem(nss,1024);
  3996. { it is not a function but a function pointer !! (PM) }
  3997. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)});
  3998. { this confuses gdb !!
  3999. we should use 'F' instead of 'f' but
  4000. as we use c++ language mode
  4001. it does not like that either
  4002. Please do not remove this part
  4003. might be used once
  4004. gdb for pascal is ready PM }
  4005. {$ifdef disabled}
  4006. param := para1;
  4007. i := 0;
  4008. while assigned(param) do
  4009. begin
  4010. inc(i);
  4011. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  4012. {Here we have lost the parameter names !!}
  4013. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  4014. strcat(nss,pst);
  4015. strdispose(pst);
  4016. param := param^.next;
  4017. end;
  4018. {$endif}
  4019. {strpcopy(strend(nss),';');}
  4020. stabstring := strnew(nss);
  4021. freemem(nss,1024);
  4022. end;
  4023. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  4024. begin
  4025. if (stab_state in [stab_state_writing,stab_state_written]) then
  4026. exit;
  4027. tstoreddef(rettype.def).concatstabto(asmlist);
  4028. inherited concatstabto(asmlist);
  4029. end;
  4030. {$endif GDB}
  4031. procedure tprocvardef.write_rtti_data(rt:trttitype);
  4032. var
  4033. pdc : TParaItem;
  4034. methodkind, paraspec : byte;
  4035. begin
  4036. if po_methodpointer in procoptions then
  4037. begin
  4038. { write method id and name }
  4039. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  4040. write_rtti_name;
  4041. { write kind of method (can only be function or procedure)}
  4042. if rettype.def = voidtype.def then
  4043. methodkind := mkProcedure
  4044. else
  4045. methodkind := mkFunction;
  4046. rttiList.concat(Tai_const.Create_8bit(methodkind));
  4047. { get # of parameters }
  4048. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  4049. { write parameter info. The parameters must be written in reverse order
  4050. if this method uses right to left parameter pushing! }
  4051. if proccalloption in pushleftright_pocalls then
  4052. pdc:=TParaItem(Para.first)
  4053. else
  4054. pdc:=TParaItem(Para.last);
  4055. while assigned(pdc) do
  4056. begin
  4057. { only store user visible parameters }
  4058. if not pdc.is_hidden then
  4059. begin
  4060. case pdc.paratyp of
  4061. vs_value: paraspec := 0;
  4062. vs_const: paraspec := pfConst;
  4063. vs_var : paraspec := pfVar;
  4064. vs_out : paraspec := pfOut;
  4065. end;
  4066. { write flags for current parameter }
  4067. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4068. { write name of current parameter }
  4069. if assigned(pdc.parasym) then
  4070. begin
  4071. rttiList.concat(Tai_const.Create_8bit(length(pdc.parasym.realname)));
  4072. rttiList.concat(Tai_string.Create(pdc.parasym.realname));
  4073. end
  4074. else
  4075. rttiList.concat(Tai_const.Create_8bit(0));
  4076. { write name of type of current parameter }
  4077. tstoreddef(pdc.paratype.def).write_rtti_name;
  4078. end;
  4079. if proccalloption in pushleftright_pocalls then
  4080. pdc:=TParaItem(pdc.next)
  4081. else
  4082. pdc:=TParaItem(pdc.previous);
  4083. end;
  4084. { write name of result type }
  4085. tstoreddef(rettype.def).write_rtti_name;
  4086. end;
  4087. end;
  4088. function tprocvardef.is_publishable : boolean;
  4089. begin
  4090. is_publishable:=(po_methodpointer in procoptions);
  4091. end;
  4092. function tprocvardef.gettypename : string;
  4093. var
  4094. s: string;
  4095. showhidden : boolean;
  4096. begin
  4097. {$ifdef EXTDEBUG}
  4098. showhidden:=true;
  4099. {$else EXTDEBUG}
  4100. showhidden:=false;
  4101. {$endif EXTDEBUG}
  4102. s:='<';
  4103. if po_classmethod in procoptions then
  4104. s := s+'class method type of'
  4105. else
  4106. if po_addressonly in procoptions then
  4107. s := s+'address of'
  4108. else
  4109. s := s+'procedure variable type of';
  4110. if assigned(rettype.def) and
  4111. (rettype.def<>voidtype.def) then
  4112. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4113. else
  4114. s:=s+' procedure'+typename_paras(showhidden);
  4115. if po_methodpointer in procoptions then
  4116. s := s+' of object';
  4117. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4118. end;
  4119. {***************************************************************************
  4120. TOBJECTDEF
  4121. ***************************************************************************}
  4122. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4123. begin
  4124. inherited create;
  4125. objecttype:=ot;
  4126. deftype:=objectdef;
  4127. objectoptions:=[];
  4128. childof:=nil;
  4129. symtable:=tobjectsymtable.create(n,aktpackrecords);
  4130. { create space for vmt !! }
  4131. vmt_offset:=0;
  4132. symtable.defowner:=self;
  4133. lastvtableindex:=0;
  4134. set_parent(c);
  4135. objname:=stringdup(upper(n));
  4136. objrealname:=stringdup(n);
  4137. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4138. prepareguid;
  4139. { setup implemented interfaces }
  4140. if objecttype in [odt_class,odt_interfacecorba] then
  4141. implementedinterfaces:=timplementedinterfaces.create
  4142. else
  4143. implementedinterfaces:=nil;
  4144. {$ifdef GDB}
  4145. writing_class_record_stab:=false;
  4146. {$endif GDB}
  4147. end;
  4148. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4149. var
  4150. i,implintfcount: longint;
  4151. d : tderef;
  4152. begin
  4153. inherited ppuloaddef(ppufile);
  4154. deftype:=objectdef;
  4155. objecttype:=tobjectdeftype(ppufile.getbyte);
  4156. objrealname:=stringdup(ppufile.getstring);
  4157. objname:=stringdup(upper(objrealname^));
  4158. symtable:=tobjectsymtable.create(objrealname^,0);
  4159. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  4160. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  4161. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  4162. vmt_offset:=ppufile.getlongint;
  4163. ppufile.getderef(childofderef);
  4164. ppufile.getsmallset(objectoptions);
  4165. { load guid }
  4166. iidstr:=nil;
  4167. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4168. begin
  4169. new(iidguid);
  4170. ppufile.getguid(iidguid^);
  4171. iidstr:=stringdup(ppufile.getstring);
  4172. lastvtableindex:=ppufile.getlongint;
  4173. end;
  4174. { load implemented interfaces }
  4175. if objecttype in [odt_class,odt_interfacecorba] then
  4176. begin
  4177. implementedinterfaces:=timplementedinterfaces.create;
  4178. implintfcount:=ppufile.getlongint;
  4179. for i:=1 to implintfcount do
  4180. begin
  4181. ppufile.getderef(d);
  4182. implementedinterfaces.addintf_deref(d);
  4183. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4184. end;
  4185. end
  4186. else
  4187. implementedinterfaces:=nil;
  4188. tobjectsymtable(symtable).ppuload(ppufile);
  4189. symtable.defowner:=self;
  4190. { handles the predefined class tobject }
  4191. { the last TOBJECT which is loaded gets }
  4192. { it ! }
  4193. if (childof=nil) and
  4194. (objecttype=odt_class) and
  4195. (objname^='TOBJECT') then
  4196. class_tobject:=self;
  4197. if (childof=nil) and
  4198. (objecttype=odt_interfacecom) and
  4199. (objname^='IUNKNOWN') then
  4200. interface_iunknown:=self;
  4201. {$ifdef GDB}
  4202. writing_class_record_stab:=false;
  4203. {$endif GDB}
  4204. end;
  4205. destructor tobjectdef.destroy;
  4206. begin
  4207. if assigned(symtable) then
  4208. symtable.free;
  4209. stringdispose(objname);
  4210. stringdispose(objrealname);
  4211. if assigned(iidstr) then
  4212. stringdispose(iidstr);
  4213. if assigned(implementedinterfaces) then
  4214. implementedinterfaces.free;
  4215. if assigned(iidguid) then
  4216. dispose(iidguid);
  4217. inherited destroy;
  4218. end;
  4219. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4220. var
  4221. implintfcount : longint;
  4222. i : longint;
  4223. begin
  4224. inherited ppuwritedef(ppufile);
  4225. ppufile.putbyte(byte(objecttype));
  4226. ppufile.putstring(objrealname^);
  4227. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4228. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  4229. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  4230. ppufile.putlongint(vmt_offset);
  4231. ppufile.putderef(childofderef);
  4232. ppufile.putsmallset(objectoptions);
  4233. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4234. begin
  4235. ppufile.putguid(iidguid^);
  4236. ppufile.putstring(iidstr^);
  4237. ppufile.putlongint(lastvtableindex);
  4238. end;
  4239. if objecttype in [odt_class,odt_interfacecorba] then
  4240. begin
  4241. implintfcount:=implementedinterfaces.count;
  4242. ppufile.putlongint(implintfcount);
  4243. for i:=1 to implintfcount do
  4244. begin
  4245. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4246. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4247. end;
  4248. end;
  4249. ppufile.writeentry(ibobjectdef);
  4250. tobjectsymtable(symtable).ppuwrite(ppufile);
  4251. end;
  4252. function tobjectdef.gettypename:string;
  4253. begin
  4254. gettypename:=typename;
  4255. end;
  4256. procedure tobjectdef.buildderef;
  4257. var
  4258. oldrecsyms : tsymtable;
  4259. begin
  4260. inherited buildderef;
  4261. childofderef.build(childof);
  4262. oldrecsyms:=aktrecordsymtable;
  4263. aktrecordsymtable:=symtable;
  4264. tstoredsymtable(symtable).buildderef;
  4265. aktrecordsymtable:=oldrecsyms;
  4266. if objecttype in [odt_class,odt_interfacecorba] then
  4267. implementedinterfaces.buildderef;
  4268. end;
  4269. procedure tobjectdef.deref;
  4270. var
  4271. oldrecsyms : tsymtable;
  4272. begin
  4273. inherited deref;
  4274. childof:=tobjectdef(childofderef.resolve);
  4275. oldrecsyms:=aktrecordsymtable;
  4276. aktrecordsymtable:=symtable;
  4277. tstoredsymtable(symtable).deref;
  4278. aktrecordsymtable:=oldrecsyms;
  4279. if objecttype in [odt_class,odt_interfacecorba] then
  4280. implementedinterfaces.deref;
  4281. end;
  4282. function tobjectdef.getparentdef:tdef;
  4283. begin
  4284. result:=childof;
  4285. end;
  4286. procedure tobjectdef.prepareguid;
  4287. begin
  4288. { set up guid }
  4289. if not assigned(iidguid) then
  4290. begin
  4291. new(iidguid);
  4292. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4293. end;
  4294. { setup iidstring }
  4295. if not assigned(iidstr) then
  4296. iidstr:=stringdup(''); { default is empty string }
  4297. end;
  4298. procedure tobjectdef.set_parent( c : tobjectdef);
  4299. begin
  4300. { nothing to do if the parent was not forward !}
  4301. if assigned(childof) then
  4302. exit;
  4303. childof:=c;
  4304. { some options are inherited !! }
  4305. if assigned(c) then
  4306. begin
  4307. { only important for classes }
  4308. lastvtableindex:=c.lastvtableindex;
  4309. objectoptions:=objectoptions+(c.objectoptions*
  4310. [oo_has_virtual,oo_has_private,oo_has_protected,
  4311. oo_has_constructor,oo_has_destructor]);
  4312. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4313. begin
  4314. { add the data of the anchestor class }
  4315. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4316. if (oo_has_vmt in objectoptions) and
  4317. (oo_has_vmt in c.objectoptions) then
  4318. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  4319. { if parent has a vmt field then
  4320. the offset is the same for the child PM }
  4321. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4322. begin
  4323. vmt_offset:=c.vmt_offset;
  4324. include(objectoptions,oo_has_vmt);
  4325. end;
  4326. end;
  4327. end;
  4328. end;
  4329. procedure tobjectdef.insertvmt;
  4330. begin
  4331. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4332. exit;
  4333. if (oo_has_vmt in objectoptions) then
  4334. internalerror(12345)
  4335. else
  4336. begin
  4337. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4338. tobjectsymtable(symtable).fieldalignment);
  4339. vmt_offset:=tobjectsymtable(symtable).datasize;
  4340. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  4341. include(objectoptions,oo_has_vmt);
  4342. end;
  4343. end;
  4344. procedure tobjectdef.check_forwards;
  4345. begin
  4346. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4347. tstoredsymtable(symtable).check_forwards;
  4348. if (oo_is_forward in objectoptions) then
  4349. begin
  4350. { ok, in future, the forward can be resolved }
  4351. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4352. exclude(objectoptions,oo_is_forward);
  4353. end;
  4354. end;
  4355. { true, if self inherits from d (or if they are equal) }
  4356. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4357. var
  4358. hp : tobjectdef;
  4359. begin
  4360. hp:=self;
  4361. while assigned(hp) do
  4362. begin
  4363. if hp=d then
  4364. begin
  4365. is_related:=true;
  4366. exit;
  4367. end;
  4368. hp:=hp.childof;
  4369. end;
  4370. is_related:=false;
  4371. end;
  4372. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4373. var
  4374. p : pprocdeflist;
  4375. begin
  4376. { if we found already a destructor, then we exit }
  4377. if assigned(sd) then
  4378. exit;
  4379. if tsym(sym).typ=procsym then
  4380. begin
  4381. p:=tprocsym(sym).defs;
  4382. while assigned(p) do
  4383. begin
  4384. if p^.def.proctypeoption=potype_destructor then
  4385. begin
  4386. sd:=p^.def;
  4387. exit;
  4388. end;
  4389. p:=p^.next;
  4390. end;
  4391. end;
  4392. end;*)
  4393. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4394. begin
  4395. { if we found already a destructor, then we exit }
  4396. if (ppointer(sd)^=nil) and
  4397. (Tsym(sym).typ=procsym) then
  4398. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4399. end;
  4400. function tobjectdef.searchdestructor : tprocdef;
  4401. var
  4402. o : tobjectdef;
  4403. sd : tprocdef;
  4404. begin
  4405. searchdestructor:=nil;
  4406. o:=self;
  4407. sd:=nil;
  4408. while assigned(o) do
  4409. begin
  4410. o.symtable.foreach_static(@_searchdestructor,@sd);
  4411. if assigned(sd) then
  4412. begin
  4413. searchdestructor:=sd;
  4414. exit;
  4415. end;
  4416. o:=o.childof;
  4417. end;
  4418. end;
  4419. function tobjectdef.size : longint;
  4420. begin
  4421. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4422. result:=sizeof(aint)
  4423. else
  4424. result:=tobjectsymtable(symtable).datasize;
  4425. end;
  4426. function tobjectdef.alignment:longint;
  4427. begin
  4428. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4429. alignment:=sizeof(aint)
  4430. else
  4431. alignment:=tobjectsymtable(symtable).recordalignment;
  4432. end;
  4433. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4434. begin
  4435. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4436. case objecttype of
  4437. odt_class:
  4438. { the +2*sizeof(Aint) is size and -size }
  4439. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  4440. odt_interfacecom,odt_interfacecorba:
  4441. vmtmethodoffset:=index*sizeof(aint);
  4442. else
  4443. {$ifdef WITHDMT}
  4444. vmtmethodoffset:=(index+4)*sizeof(aint);
  4445. {$else WITHDMT}
  4446. vmtmethodoffset:=(index+3)*sizeof(aint);
  4447. {$endif WITHDMT}
  4448. end;
  4449. end;
  4450. function tobjectdef.vmt_mangledname : string;
  4451. begin
  4452. if not(oo_has_vmt in objectoptions) then
  4453. Message1(parser_n_object_has_no_vmt,objrealname^);
  4454. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4455. end;
  4456. function tobjectdef.rtti_name : string;
  4457. begin
  4458. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4459. end;
  4460. {$ifdef GDB}
  4461. procedure tobjectdef.proc_addname(p :tnamedindexitem;arg:pointer);
  4462. var virtualind,argnames : string;
  4463. newrec : pchar;
  4464. pd : tprocdef;
  4465. lindex : longint;
  4466. para : TParaItem;
  4467. arglength : byte;
  4468. sp : char;
  4469. state:^Trecord_stabgen_state;
  4470. olds:integer;
  4471. begin
  4472. state:=arg;
  4473. if tsym(p).typ = procsym then
  4474. begin
  4475. pd := tprocsym(p).first_procdef;
  4476. if (po_virtualmethod in pd.procoptions) then
  4477. begin
  4478. lindex := pd.extnumber;
  4479. {doesnt seem to be necessary
  4480. lindex := lindex or $80000000;}
  4481. virtualind := '*'+tostr(lindex)+';'+pd._class.classnumberstring+';'
  4482. end
  4483. else
  4484. virtualind := '.';
  4485. { used by gdbpas to recognize constructor and destructors }
  4486. if (pd.proctypeoption=potype_constructor) then
  4487. argnames:='__ct__'
  4488. else if (pd.proctypeoption=potype_destructor) then
  4489. argnames:='__dt__'
  4490. else
  4491. argnames := '';
  4492. { arguments are not listed here }
  4493. {we don't need another definition}
  4494. para := TParaItem(pd.Para.first);
  4495. while assigned(para) do
  4496. begin
  4497. if Para.paratype.def.deftype = formaldef then
  4498. begin
  4499. case Para.paratyp of
  4500. vs_var :
  4501. argnames := argnames+'3var';
  4502. vs_const :
  4503. argnames:=argnames+'5const';
  4504. vs_out :
  4505. argnames:=argnames+'3out';
  4506. end;
  4507. end
  4508. else
  4509. begin
  4510. { if the arg definition is like (v: ^byte;..
  4511. there is no sym attached to data !!! }
  4512. if assigned(Para.paratype.def.typesym) then
  4513. begin
  4514. arglength := length(Para.paratype.def.typesym.name);
  4515. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4516. end
  4517. else
  4518. argnames:=argnames+'11unnamedtype';
  4519. end;
  4520. para := TParaItem(Para.next);
  4521. end;
  4522. { here 2A must be changed for private and protected }
  4523. { 0 is private 1 protected and 2 public }
  4524. if (sp_private in tsym(p).symoptions) then
  4525. sp:='0'
  4526. else if (sp_protected in tsym(p).symoptions) then
  4527. sp:='1'
  4528. else
  4529. sp:='2';
  4530. newrec:=stabstr_evaluate('$1::$2=##$3;:$4;$5A$6;',[p.name,pd.numberstring,
  4531. Tstoreddef(pd.rettype.def).numberstring,argnames,sp,
  4532. virtualind]);
  4533. { get spare place for a string at the end }
  4534. olds:=state^.stabsize;
  4535. inc(state^.stabsize,strlen(newrec));
  4536. if state^.stabsize>=state^.staballoc-256 then
  4537. begin
  4538. inc(state^.staballoc,memsizeinc);
  4539. reallocmem(state^.stabstring,state^.staballoc);
  4540. end;
  4541. strcopy(state^.stabstring+olds,newrec);
  4542. strdispose(newrec);
  4543. {This should be used for case !!
  4544. RecOffset := RecOffset + pd.size;}
  4545. end;
  4546. end;
  4547. procedure tobjectdef.proc_concatstabto(p :tnamedindexitem;arg:pointer);
  4548. var
  4549. pd : tprocdef;
  4550. begin
  4551. if tsym(p).typ = procsym then
  4552. begin
  4553. pd := tprocsym(p).first_procdef;
  4554. tstoreddef(pd.rettype.def).concatstabto(taasmoutput(arg));
  4555. end;
  4556. end;
  4557. function tobjectdef.stabstring : pchar;
  4558. var anc : tobjectdef;
  4559. state:Trecord_stabgen_state;
  4560. ts : string;
  4561. begin
  4562. if not (objecttype=odt_class) or writing_class_record_stab then
  4563. begin
  4564. state.staballoc:=memsizeinc;
  4565. getmem(state.stabstring,state.staballoc);
  4566. strpcopy(state.stabstring,'s'+tostr(tobjectsymtable(symtable).datasize));
  4567. if assigned(childof) then
  4568. begin
  4569. {only one ancestor not virtual, public, at base offset 0 }
  4570. { !1 , 0 2 0 , }
  4571. strpcopy(strend(state.stabstring),'!1,020,'+childof.classnumberstring+';');
  4572. end;
  4573. {virtual table to implement yet}
  4574. state.recoffset:=0;
  4575. state.stabsize:=strlen(state.stabstring);
  4576. symtable.foreach(@field_addname,@state);
  4577. if (oo_has_vmt in objectoptions) then
  4578. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4579. begin
  4580. ts:='$vf'+classnumberstring+':'+tstoreddef(vmtarraytype.def).numberstring+','+tostr(vmt_offset*8)+';';
  4581. strpcopy(state.stabstring+state.stabsize,ts);
  4582. inc(state.stabsize,length(ts));
  4583. end;
  4584. symtable.foreach(@proc_addname,@state);
  4585. if (oo_has_vmt in objectoptions) then
  4586. begin
  4587. anc := self;
  4588. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4589. anc := anc.childof;
  4590. { just in case anc = self }
  4591. ts:=';~%'+anc.classnumberstring+';';
  4592. end
  4593. else
  4594. ts:=';';
  4595. strpcopy(state.stabstring+state.stabsize,ts);
  4596. inc(state.stabsize,length(ts));
  4597. reallocmem(state.stabstring,state.stabsize+1);
  4598. stabstring:=state.stabstring;
  4599. end
  4600. else
  4601. begin
  4602. stabstring:=strpnew('*'+classnumberstring);
  4603. end;
  4604. end;
  4605. procedure tobjectdef.set_globalnb;
  4606. begin
  4607. globalnb:=PglobalTypeCount^;
  4608. inc(PglobalTypeCount^);
  4609. { classes need two type numbers, the globalnb is set to the ptr }
  4610. if objecttype=odt_class then
  4611. begin
  4612. globalnb:=PGlobalTypeCount^;
  4613. inc(PglobalTypeCount^);
  4614. end;
  4615. end;
  4616. function tobjectdef.classnumberstring : string;
  4617. begin
  4618. if objecttype=odt_class then
  4619. begin
  4620. if globalnb=0 then
  4621. numberstring;
  4622. dec(globalnb);
  4623. classnumberstring:=numberstring;
  4624. inc(globalnb);
  4625. end
  4626. else
  4627. classnumberstring:=numberstring;
  4628. end;
  4629. function tobjectdef.allstabstring : pchar;
  4630. var
  4631. stabchar : string[2];
  4632. ss,st : pchar;
  4633. sname : string;
  4634. begin
  4635. ss := stabstring;
  4636. getmem(st,strlen(ss)+512);
  4637. stabchar := 't';
  4638. if deftype in tagtypes then
  4639. stabchar := 'Tt';
  4640. if assigned(typesym) then
  4641. sname := typesym.name
  4642. else
  4643. sname := ' ';
  4644. if writing_class_record_stab then
  4645. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4646. else
  4647. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4648. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,0,0');
  4649. allstabstring := strnew(st);
  4650. freemem(st,strlen(ss)+512);
  4651. strdispose(ss);
  4652. end;
  4653. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4654. var
  4655. oldtypesym : tsym;
  4656. stab_str : pchar;
  4657. anc : tobjectdef;
  4658. begin
  4659. if (stab_state in [stab_state_writing,stab_state_written]) then
  4660. exit;
  4661. stab_state:=stab_state_writing;
  4662. tstoreddef(vmtarraytype.def).concatstabto(asmlist);
  4663. { first the parents }
  4664. anc:=self;
  4665. while assigned(anc.childof) do
  4666. begin
  4667. anc:=anc.childof;
  4668. anc.concatstabto(asmlist);
  4669. end;
  4670. symtable.foreach(@field_concatstabto,asmlist);
  4671. symtable.foreach(@proc_concatstabto,asmlist);
  4672. stab_state:=stab_state_used;
  4673. if objecttype=odt_class then
  4674. begin
  4675. { Write the record class itself }
  4676. writing_class_record_stab:=true;
  4677. inherited concatstabto(asmlist);
  4678. writing_class_record_stab:=false;
  4679. { Write the invisible pointer class }
  4680. oldtypesym:=typesym;
  4681. typesym:=nil;
  4682. stab_str := allstabstring;
  4683. asmList.concat(Tai_stabs.Create(stab_str));
  4684. typesym:=oldtypesym;
  4685. end
  4686. else
  4687. inherited concatstabto(asmlist);
  4688. end;
  4689. {$endif GDB}
  4690. function tobjectdef.needs_inittable : boolean;
  4691. begin
  4692. case objecttype of
  4693. odt_class :
  4694. needs_inittable:=false;
  4695. odt_interfacecom:
  4696. needs_inittable:=true;
  4697. odt_interfacecorba:
  4698. needs_inittable:=is_related(interface_iunknown);
  4699. odt_object:
  4700. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4701. else
  4702. internalerror(200108267);
  4703. end;
  4704. end;
  4705. function tobjectdef.members_need_inittable : boolean;
  4706. begin
  4707. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4708. end;
  4709. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4710. begin
  4711. if needs_prop_entry(tsym(sym)) and
  4712. (tsym(sym).typ<>varsym) then
  4713. inc(count);
  4714. end;
  4715. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4716. var
  4717. proctypesinfo : byte;
  4718. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4719. var
  4720. typvalue : byte;
  4721. hp : psymlistitem;
  4722. address : longint;
  4723. def : tdef;
  4724. begin
  4725. if not(assigned(proc) and assigned(proc.firstsym)) then
  4726. begin
  4727. rttiList.concat(Tai_const.create(ait_const_ptr,1));
  4728. typvalue:=3;
  4729. end
  4730. else if proc.firstsym^.sym.typ=varsym then
  4731. begin
  4732. address:=0;
  4733. hp:=proc.firstsym;
  4734. def:=nil;
  4735. while assigned(hp) do
  4736. begin
  4737. case hp^.sltype of
  4738. sl_load :
  4739. begin
  4740. def:=tvarsym(hp^.sym).vartype.def;
  4741. inc(address,tvarsym(hp^.sym).fieldoffset);
  4742. end;
  4743. sl_subscript :
  4744. begin
  4745. if not(assigned(def) and (def.deftype=recorddef)) then
  4746. internalerror(200402171);
  4747. inc(address,tvarsym(hp^.sym).fieldoffset);
  4748. def:=tvarsym(hp^.sym).vartype.def;
  4749. end;
  4750. sl_vec :
  4751. begin
  4752. if not(assigned(def) and (def.deftype=arraydef)) then
  4753. internalerror(200402172);
  4754. def:=tarraydef(def).elementtype.def;
  4755. inc(address,def.size*hp^.value);
  4756. end;
  4757. end;
  4758. hp:=hp^.next;
  4759. end;
  4760. rttiList.concat(Tai_const.create(ait_const_ptr,address));
  4761. typvalue:=0;
  4762. end
  4763. else
  4764. begin
  4765. { When there was an error then procdef is not assigned }
  4766. if not assigned(proc.procdef) then
  4767. exit;
  4768. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4769. begin
  4770. rttiList.concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4771. typvalue:=1;
  4772. end
  4773. else
  4774. begin
  4775. { virtual method, write vmt offset }
  4776. rttiList.concat(Tai_const.create(ait_const_ptr,
  4777. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4778. typvalue:=2;
  4779. end;
  4780. end;
  4781. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4782. end;
  4783. begin
  4784. if needs_prop_entry(tsym(sym)) then
  4785. case tsym(sym).typ of
  4786. varsym:
  4787. begin
  4788. {$ifdef dummy}
  4789. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4790. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4791. internalerror(1509992);
  4792. { access to implicit class property as field }
  4793. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4794. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label),AT_DATA,0));
  4795. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4796. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4797. { by default stored }
  4798. rttiList.concat(Tai_const.Create_32bit(1));
  4799. { index as well as ... }
  4800. rttiList.concat(Tai_const.Create_32bit(0));
  4801. { default value are zero }
  4802. rttiList.concat(Tai_const.Create_32bit(0));
  4803. rttiList.concat(Tai_const.Create_16bit(count));
  4804. inc(count);
  4805. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4806. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4807. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4808. {$endif dummy}
  4809. end;
  4810. propertysym:
  4811. begin
  4812. if ppo_indexed in tpropertysym(sym).propoptions then
  4813. proctypesinfo:=$40
  4814. else
  4815. proctypesinfo:=0;
  4816. rttiList.concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4817. writeproc(tpropertysym(sym).readaccess,0);
  4818. writeproc(tpropertysym(sym).writeaccess,2);
  4819. { isn't it stored ? }
  4820. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4821. begin
  4822. rttiList.concat(Tai_const.create_sym(nil));
  4823. proctypesinfo:=proctypesinfo or (3 shl 4);
  4824. end
  4825. else
  4826. writeproc(tpropertysym(sym).storedaccess,4);
  4827. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4828. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4829. rttiList.concat(Tai_const.Create_16bit(count));
  4830. inc(count);
  4831. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4832. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4833. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4834. {$ifdef cpurequiresproperalignment}
  4835. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4836. {$endif cpurequiresproperalignment}
  4837. end;
  4838. else internalerror(1509992);
  4839. end;
  4840. end;
  4841. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4842. begin
  4843. if needs_prop_entry(tsym(sym)) then
  4844. begin
  4845. case tsym(sym).typ of
  4846. propertysym:
  4847. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4848. varsym:
  4849. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4850. else
  4851. internalerror(1509991);
  4852. end;
  4853. end;
  4854. end;
  4855. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4856. begin
  4857. FRTTIType:=rt;
  4858. case rt of
  4859. initrtti :
  4860. symtable.foreach(@generate_field_rtti,nil);
  4861. fullrtti :
  4862. symtable.foreach(@generate_published_child_rtti,nil);
  4863. else
  4864. internalerror(200108301);
  4865. end;
  4866. end;
  4867. type
  4868. tclasslistitem = class(TLinkedListItem)
  4869. index : longint;
  4870. p : tobjectdef;
  4871. end;
  4872. var
  4873. classtablelist : tlinkedlist;
  4874. tablecount : longint;
  4875. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4876. var
  4877. hp : tclasslistitem;
  4878. begin
  4879. hp:=tclasslistitem(classtablelist.first);
  4880. while assigned(hp) do
  4881. if hp.p=p then
  4882. begin
  4883. searchclasstablelist:=hp;
  4884. exit;
  4885. end
  4886. else
  4887. hp:=tclasslistitem(hp.next);
  4888. searchclasstablelist:=nil;
  4889. end;
  4890. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4891. var
  4892. hp : tclasslistitem;
  4893. begin
  4894. if needs_prop_entry(tsym(sym)) and
  4895. (tsym(sym).typ=varsym) then
  4896. begin
  4897. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4898. internalerror(0206001);
  4899. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4900. if not(assigned(hp)) then
  4901. begin
  4902. hp:=tclasslistitem.create;
  4903. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4904. hp.index:=tablecount;
  4905. classtablelist.concat(hp);
  4906. inc(tablecount);
  4907. end;
  4908. inc(count);
  4909. end;
  4910. end;
  4911. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4912. var
  4913. hp : tclasslistitem;
  4914. begin
  4915. if needs_prop_entry(tsym(sym)) and
  4916. (tsym(sym).typ=varsym) then
  4917. begin
  4918. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4919. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4920. if not(assigned(hp)) then
  4921. internalerror(0206002);
  4922. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4923. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4924. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4925. end;
  4926. end;
  4927. function tobjectdef.generate_field_table : tasmlabel;
  4928. var
  4929. fieldtable,
  4930. classtable : tasmlabel;
  4931. hp : tclasslistitem;
  4932. begin
  4933. classtablelist:=TLinkedList.Create;
  4934. objectlibrary.getdatalabel(fieldtable);
  4935. objectlibrary.getdatalabel(classtable);
  4936. count:=0;
  4937. tablecount:=0;
  4938. maybe_new_object_file(rttiList);
  4939. new_section(rttiList,sec_rodata,classtable.name,const_align(sizeof(aint)));
  4940. { fields }
  4941. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4942. rttiList.concat(Tai_label.Create(fieldtable));
  4943. rttiList.concat(Tai_const.Create_16bit(count));
  4944. rttiList.concat(Tai_const.Create_sym(classtable));
  4945. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4946. { generate the class table }
  4947. rttilist.concat(tai_align.create(const_align(sizeof(aint))));
  4948. rttiList.concat(Tai_label.Create(classtable));
  4949. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4950. hp:=tclasslistitem(classtablelist.first);
  4951. while assigned(hp) do
  4952. begin
  4953. rttiList.concat(Tai_const.Createname(tobjectdef(hp.p).vmt_mangledname,AT_DATA,0));
  4954. hp:=tclasslistitem(hp.next);
  4955. end;
  4956. generate_field_table:=fieldtable;
  4957. classtablelist.free;
  4958. end;
  4959. function tobjectdef.next_free_name_index : longint;
  4960. var
  4961. i : longint;
  4962. begin
  4963. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4964. i:=childof.next_free_name_index
  4965. else
  4966. i:=0;
  4967. count:=0;
  4968. symtable.foreach(@count_published_properties,nil);
  4969. next_free_name_index:=i+count;
  4970. end;
  4971. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4972. begin
  4973. case objecttype of
  4974. odt_class:
  4975. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4976. odt_object:
  4977. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4978. odt_interfacecom:
  4979. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4980. odt_interfacecorba:
  4981. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4982. else
  4983. exit;
  4984. end;
  4985. { generate the name }
  4986. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4987. rttiList.concat(Tai_string.Create(objrealname^));
  4988. {$ifdef cpurequiresproperalignment}
  4989. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4990. {$endif cpurequiresproperalignment}
  4991. case rt of
  4992. initrtti :
  4993. begin
  4994. rttiList.concat(Tai_const.Create_32bit(size));
  4995. if objecttype in [odt_class,odt_object] then
  4996. begin
  4997. count:=0;
  4998. FRTTIType:=rt;
  4999. symtable.foreach(@count_field_rtti,nil);
  5000. rttiList.concat(Tai_const.Create_32bit(count));
  5001. symtable.foreach(@write_field_rtti,nil);
  5002. end;
  5003. end;
  5004. fullrtti :
  5005. begin
  5006. if (oo_has_vmt in objectoptions) and
  5007. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5008. rttiList.concat(Tai_const.Createname(vmt_mangledname,AT_DATA,0))
  5009. else
  5010. rttiList.concat(Tai_const.create_sym(nil));
  5011. { write owner typeinfo }
  5012. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5013. rttiList.concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  5014. else
  5015. rttiList.concat(Tai_const.create_sym(nil));
  5016. { count total number of properties }
  5017. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5018. count:=childof.next_free_name_index
  5019. else
  5020. count:=0;
  5021. { write it }
  5022. symtable.foreach(@count_published_properties,nil);
  5023. rttiList.concat(Tai_const.Create_16bit(count));
  5024. { write unit name }
  5025. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  5026. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  5027. {$ifdef cpurequiresproperalignment}
  5028. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5029. {$endif cpurequiresproperalignment}
  5030. { write published properties count }
  5031. count:=0;
  5032. symtable.foreach(@count_published_properties,nil);
  5033. rttiList.concat(Tai_const.Create_16bit(count));
  5034. {$ifdef cpurequiresproperalignment}
  5035. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5036. {$endif cpurequiresproperalignment}
  5037. { count is used to write nameindex }
  5038. { but we need an offset of the owner }
  5039. { to give each property an own slot }
  5040. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5041. count:=childof.next_free_name_index
  5042. else
  5043. count:=0;
  5044. symtable.foreach(@write_property_info,nil);
  5045. end;
  5046. end;
  5047. end;
  5048. function tobjectdef.is_publishable : boolean;
  5049. begin
  5050. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  5051. end;
  5052. {****************************************************************************
  5053. TIMPLEMENTEDINTERFACES
  5054. ****************************************************************************}
  5055. type
  5056. tnamemap = class(TNamedIndexItem)
  5057. newname: pstring;
  5058. constructor create(const aname, anewname: string);
  5059. destructor destroy; override;
  5060. end;
  5061. constructor tnamemap.create(const aname, anewname: string);
  5062. begin
  5063. inherited createname(name);
  5064. newname:=stringdup(anewname);
  5065. end;
  5066. destructor tnamemap.destroy;
  5067. begin
  5068. stringdispose(newname);
  5069. inherited destroy;
  5070. end;
  5071. type
  5072. tprocdefstore = class(TNamedIndexItem)
  5073. procdef: tprocdef;
  5074. constructor create(aprocdef: tprocdef);
  5075. end;
  5076. constructor tprocdefstore.create(aprocdef: tprocdef);
  5077. begin
  5078. inherited create;
  5079. procdef:=aprocdef;
  5080. end;
  5081. type
  5082. timplintfentry = class(TNamedIndexItem)
  5083. intf: tobjectdef;
  5084. intfderef : tderef;
  5085. ioffs: longint;
  5086. namemappings: tdictionary;
  5087. procdefs: TIndexArray;
  5088. constructor create(aintf: tobjectdef);
  5089. constructor create_deref(const d:tderef);
  5090. destructor destroy; override;
  5091. end;
  5092. constructor timplintfentry.create(aintf: tobjectdef);
  5093. begin
  5094. inherited create;
  5095. intf:=aintf;
  5096. ioffs:=-1;
  5097. namemappings:=nil;
  5098. procdefs:=nil;
  5099. end;
  5100. constructor timplintfentry.create_deref(const d:tderef);
  5101. begin
  5102. inherited create;
  5103. intf:=nil;
  5104. intfderef:=d;
  5105. ioffs:=-1;
  5106. namemappings:=nil;
  5107. procdefs:=nil;
  5108. end;
  5109. destructor timplintfentry.destroy;
  5110. begin
  5111. if assigned(namemappings) then
  5112. namemappings.free;
  5113. if assigned(procdefs) then
  5114. procdefs.free;
  5115. inherited destroy;
  5116. end;
  5117. constructor timplementedinterfaces.create;
  5118. begin
  5119. finterfaces:=tindexarray.create(1);
  5120. end;
  5121. destructor timplementedinterfaces.destroy;
  5122. begin
  5123. finterfaces.destroy;
  5124. end;
  5125. function timplementedinterfaces.count: longint;
  5126. begin
  5127. count:=finterfaces.count;
  5128. end;
  5129. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5130. begin
  5131. if (intfindex<1) or (intfindex>count) then
  5132. InternalError(200006123);
  5133. end;
  5134. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5135. begin
  5136. checkindex(intfindex);
  5137. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5138. end;
  5139. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5140. begin
  5141. checkindex(intfindex);
  5142. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5143. end;
  5144. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5145. begin
  5146. checkindex(intfindex);
  5147. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5148. end;
  5149. function timplementedinterfaces.searchintf(def: tdef): longint;
  5150. var
  5151. i: longint;
  5152. begin
  5153. i:=1;
  5154. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5155. if i<=count then
  5156. searchintf:=i
  5157. else
  5158. searchintf:=-1;
  5159. end;
  5160. procedure timplementedinterfaces.buildderef;
  5161. var
  5162. i: longint;
  5163. begin
  5164. for i:=1 to count do
  5165. with timplintfentry(finterfaces.search(i)) do
  5166. intfderef.build(intf);
  5167. end;
  5168. procedure timplementedinterfaces.deref;
  5169. var
  5170. i: longint;
  5171. begin
  5172. for i:=1 to count do
  5173. with timplintfentry(finterfaces.search(i)) do
  5174. intf:=tobjectdef(intfderef.resolve);
  5175. end;
  5176. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5177. begin
  5178. finterfaces.insert(timplintfentry.create_deref(d));
  5179. end;
  5180. procedure timplementedinterfaces.addintf(def: tdef);
  5181. begin
  5182. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5183. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5184. internalerror(200006124);
  5185. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5186. end;
  5187. procedure timplementedinterfaces.clearmappings;
  5188. var
  5189. i: longint;
  5190. begin
  5191. for i:=1 to count do
  5192. with timplintfentry(finterfaces.search(i)) do
  5193. begin
  5194. if assigned(namemappings) then
  5195. namemappings.free;
  5196. namemappings:=nil;
  5197. end;
  5198. end;
  5199. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5200. begin
  5201. checkindex(intfindex);
  5202. with timplintfentry(finterfaces.search(intfindex)) do
  5203. begin
  5204. if not assigned(namemappings) then
  5205. namemappings:=tdictionary.create;
  5206. namemappings.insert(tnamemap.create(name,newname));
  5207. end;
  5208. end;
  5209. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5210. begin
  5211. checkindex(intfindex);
  5212. if not assigned(nextexist) then
  5213. with timplintfentry(finterfaces.search(intfindex)) do
  5214. begin
  5215. if assigned(namemappings) then
  5216. nextexist:=namemappings.search(name)
  5217. else
  5218. nextexist:=nil;
  5219. end;
  5220. if assigned(nextexist) then
  5221. begin
  5222. getmappings:=tnamemap(nextexist).newname^;
  5223. nextexist:=tnamemap(nextexist).listnext;
  5224. end
  5225. else
  5226. getmappings:='';
  5227. end;
  5228. procedure timplementedinterfaces.clearimplprocs;
  5229. var
  5230. i: longint;
  5231. begin
  5232. for i:=1 to count do
  5233. with timplintfentry(finterfaces.search(i)) do
  5234. begin
  5235. if assigned(procdefs) then
  5236. procdefs.free;
  5237. procdefs:=nil;
  5238. end;
  5239. end;
  5240. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5241. begin
  5242. checkindex(intfindex);
  5243. with timplintfentry(finterfaces.search(intfindex)) do
  5244. begin
  5245. if not assigned(procdefs) then
  5246. procdefs:=tindexarray.create(4);
  5247. procdefs.insert(tprocdefstore.create(procdef));
  5248. end;
  5249. end;
  5250. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5251. begin
  5252. checkindex(intfindex);
  5253. with timplintfentry(finterfaces.search(intfindex)) do
  5254. if assigned(procdefs) then
  5255. implproccount:=procdefs.count
  5256. else
  5257. implproccount:=0;
  5258. end;
  5259. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5260. begin
  5261. checkindex(intfindex);
  5262. with timplintfentry(finterfaces.search(intfindex)) do
  5263. if assigned(procdefs) then
  5264. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5265. else
  5266. internalerror(200006131);
  5267. end;
  5268. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5269. var
  5270. possible: boolean;
  5271. i: longint;
  5272. iiep1: TIndexArray;
  5273. iiep2: TIndexArray;
  5274. begin
  5275. checkindex(intfindex);
  5276. checkindex(remainindex);
  5277. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5278. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5279. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5280. begin
  5281. possible:=true;
  5282. weight:=0;
  5283. end
  5284. else
  5285. begin
  5286. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5287. i:=1;
  5288. while (possible) and (i<=iiep1.count) do
  5289. begin
  5290. possible:=
  5291. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5292. inc(i);
  5293. end;
  5294. if possible then
  5295. weight:=iiep1.count;
  5296. end;
  5297. isimplmergepossible:=possible;
  5298. end;
  5299. {****************************************************************************
  5300. TFORWARDDEF
  5301. ****************************************************************************}
  5302. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5303. var
  5304. oldregisterdef : boolean;
  5305. begin
  5306. { never register the forwarddefs, they are disposed at the
  5307. end of the type declaration block }
  5308. oldregisterdef:=registerdef;
  5309. registerdef:=false;
  5310. inherited create;
  5311. registerdef:=oldregisterdef;
  5312. deftype:=forwarddef;
  5313. tosymname:=stringdup(s);
  5314. forwardpos:=pos;
  5315. end;
  5316. function tforwarddef.gettypename:string;
  5317. begin
  5318. gettypename:='unresolved forward to '+tosymname^;
  5319. end;
  5320. destructor tforwarddef.destroy;
  5321. begin
  5322. if assigned(tosymname) then
  5323. stringdispose(tosymname);
  5324. inherited destroy;
  5325. end;
  5326. {****************************************************************************
  5327. TERRORDEF
  5328. ****************************************************************************}
  5329. constructor terrordef.create;
  5330. begin
  5331. inherited create;
  5332. deftype:=errordef;
  5333. end;
  5334. {$ifdef GDB}
  5335. function terrordef.stabstring : pchar;
  5336. begin
  5337. stabstring:=strpnew('error'+numberstring);
  5338. end;
  5339. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5340. begin
  5341. { No internal error needed, an normal error is already
  5342. thrown }
  5343. end;
  5344. {$endif GDB}
  5345. function terrordef.gettypename:string;
  5346. begin
  5347. gettypename:='<erroneous type>';
  5348. end;
  5349. function terrordef.getmangledparaname:string;
  5350. begin
  5351. getmangledparaname:='error';
  5352. end;
  5353. {****************************************************************************
  5354. Definition Helpers
  5355. ****************************************************************************}
  5356. function is_interfacecom(def: tdef): boolean;
  5357. begin
  5358. is_interfacecom:=
  5359. assigned(def) and
  5360. (def.deftype=objectdef) and
  5361. (tobjectdef(def).objecttype=odt_interfacecom);
  5362. end;
  5363. function is_interfacecorba(def: tdef): boolean;
  5364. begin
  5365. is_interfacecorba:=
  5366. assigned(def) and
  5367. (def.deftype=objectdef) and
  5368. (tobjectdef(def).objecttype=odt_interfacecorba);
  5369. end;
  5370. function is_interface(def: tdef): boolean;
  5371. begin
  5372. is_interface:=
  5373. assigned(def) and
  5374. (def.deftype=objectdef) and
  5375. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5376. end;
  5377. function is_class(def: tdef): boolean;
  5378. begin
  5379. is_class:=
  5380. assigned(def) and
  5381. (def.deftype=objectdef) and
  5382. (tobjectdef(def).objecttype=odt_class);
  5383. end;
  5384. function is_object(def: tdef): boolean;
  5385. begin
  5386. is_object:=
  5387. assigned(def) and
  5388. (def.deftype=objectdef) and
  5389. (tobjectdef(def).objecttype=odt_object);
  5390. end;
  5391. function is_cppclass(def: tdef): boolean;
  5392. begin
  5393. is_cppclass:=
  5394. assigned(def) and
  5395. (def.deftype=objectdef) and
  5396. (tobjectdef(def).objecttype=odt_cppclass);
  5397. end;
  5398. function is_class_or_interface(def: tdef): boolean;
  5399. begin
  5400. is_class_or_interface:=
  5401. assigned(def) and
  5402. (def.deftype=objectdef) and
  5403. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5404. end;
  5405. end.
  5406. {
  5407. $Log$
  5408. Revision 1.259 2004-10-15 09:14:17 mazen
  5409. - remove $IFDEF DELPHI and related code
  5410. - remove $IFDEF FPCPROCVAR and related code
  5411. Revision 1.258 2004/10/10 21:08:55 peter
  5412. * parameter regvar fixes
  5413. Revision 1.257 2004/10/04 21:23:15 florian
  5414. * rtti alignment fixed
  5415. Revision 1.256 2004/09/21 23:36:51 hajny
  5416. * SetTextLineEnding implemented, FileRec.Name position alignment for CPU64
  5417. Revision 1.255 2004/09/21 17:25:12 peter
  5418. * paraloc branch merged
  5419. Revision 1.254 2004/09/14 16:33:17 peter
  5420. * restart sorting of enums when deref is called, this is needed when
  5421. a unit is reloaded
  5422. Revision 1.253.4.1 2004/08/31 20:43:06 peter
  5423. * paraloc patch
  5424. Revision 1.253 2004/08/27 21:59:26 peter
  5425. browser disabled
  5426. uf_local_symtable ppu flag when a localsymtable is stored
  5427. Revision 1.252 2004/08/17 16:29:21 jonas
  5428. + padalgingment field for recordsymtables (saved by recorddefs)
  5429. + support for Macintosh PowerPC alignment (if the first field of a record
  5430. or union has an alignment > 4, then the record or union size must be
  5431. padded to a multiple of this size)
  5432. Revision 1.251 2004/08/15 15:05:16 peter
  5433. * fixed padding of records to alignment
  5434. Revision 1.250 2004/08/14 14:50:42 florian
  5435. * fixed several sparc alignment issues
  5436. + Jonas' inline node patch; non functional yet
  5437. Revision 1.249 2004/08/07 14:52:45 florian
  5438. * fixed web bug 3226: type p = type pointer;
  5439. Revision 1.248 2004/07/19 19:15:50 florian
  5440. * fixed funcret_paraloc writing in units
  5441. Revision 1.247 2004/07/14 21:37:41 olle
  5442. - removed unused types
  5443. Revision 1.246 2004/07/12 09:14:04 jonas
  5444. * inline procedures at the node tree level, but only under some very
  5445. limited circumstances for now (only procedures, and only if they have
  5446. no or only vs_out/vs_var parameters).
  5447. * fixed ppudump for inline procedures
  5448. * fixed ppudump for ppc
  5449. Revision 1.245 2004/07/09 22:17:32 peter
  5450. * revert has_localst patch
  5451. * replace aktstaticsymtable/aktglobalsymtable with current_module
  5452. Revision 1.244 2004/07/06 19:52:04 peter
  5453. * fix storing of localst in ppu
  5454. Revision 1.243 2004/06/20 08:55:30 florian
  5455. * logs truncated
  5456. Revision 1.242 2004/06/18 15:16:46 peter
  5457. * remove obsolete cardinal() typecasts
  5458. Revision 1.241 2004/06/16 20:07:09 florian
  5459. * dwarf branch merged
  5460. Revision 1.240 2004/05/25 18:51:14 peter
  5461. * range check error
  5462. Revision 1.239 2004/05/23 20:57:10 peter
  5463. * removed unused voidprocdef
  5464. Revision 1.238 2004/05/23 15:23:30 peter
  5465. * fixed qword(longint) that removed sign from the number
  5466. * removed code in the compiler that relied on wrong qword(longint)
  5467. code generation
  5468. }