symdef.pas 195 KB

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