symdef.pas 196 KB

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