symdef.pas 194 KB

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