symdef.pas 192 KB

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