symdef.pas 197 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427
  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. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  2068. savesize:=632
  2069. else
  2070. savesize:=628;
  2071. ft_typed,
  2072. ft_untyped :
  2073. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  2074. savesize:=372
  2075. else
  2076. savesize:=368;
  2077. end;
  2078. {$else cpu64bit}
  2079. case filetyp of
  2080. ft_text :
  2081. savesize:=592;
  2082. ft_typed,
  2083. ft_untyped :
  2084. savesize:=332;
  2085. end;
  2086. {$endif cpu64bit}
  2087. end;
  2088. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  2089. begin
  2090. inherited ppuwritedef(ppufile);
  2091. ppufile.putbyte(byte(filetyp));
  2092. if filetyp=ft_typed then
  2093. ppufile.puttype(typedfiletype);
  2094. ppufile.writeentry(ibfiledef);
  2095. end;
  2096. {$ifdef GDB}
  2097. function tfiledef.stabstring : pchar;
  2098. begin
  2099. {$IfDef GDBknowsfiles}
  2100. case filetyp of
  2101. ft_typed :
  2102. stabstring := strpnew('d'+typedfiletype.def.numberstring{+';'});
  2103. ft_untyped :
  2104. stabstring := strpnew('d'+voiddef.numberstring{+';'});
  2105. ft_text :
  2106. stabstring := strpnew('d'+cchartype^.numberstring{+';'});
  2107. end;
  2108. {$Else}
  2109. {$ifdef cpu64bit}
  2110. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$2,64,64;'+
  2111. '_PRIVATE:ar$1;1;64;$3,128,256;USERDATA:ar$1;1;16;$3,384,128;'+
  2112. 'NAME:ar$1;0;255;$4,512,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2113. tstoreddef(s64inttype.def).numberstring,
  2114. tstoreddef(u8inttype.def).numberstring,
  2115. tstoreddef(cchartype.def).numberstring]);
  2116. {$else cpu64bit}
  2117. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$1,64,32;'+
  2118. '_PRIVATE:ar$1;1;32;$3,96,256;USERDATA:ar$1;1;16;$2,352,128;'+
  2119. 'NAME:ar$1;0;255;$3,480,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2120. tstoreddef(u8inttype.def).numberstring,
  2121. tstoreddef(cchartype.def).numberstring]);
  2122. {$endif cpu64bit}
  2123. {$EndIf}
  2124. end;
  2125. procedure tfiledef.concatstabto(asmlist:taasmoutput);
  2126. begin
  2127. if (stab_state in [stab_state_writing,stab_state_written]) then
  2128. exit;
  2129. {$IfDef GDBknowsfiles}
  2130. case filetyp of
  2131. ft_typed :
  2132. tstoreddef(typedfiletype.def).concatstabto(asmlist);
  2133. ft_untyped :
  2134. tstoreddef(voidtype.def).concatstabto(asmlist);
  2135. ft_text :
  2136. tstoreddef(cchartype.def).concatstabto(asmlist);
  2137. end;
  2138. {$Else}
  2139. tstoreddef(s32inttype.def).concatstabto(asmlist);
  2140. {$ifdef cpu64bit}
  2141. tstoreddef(s64inttype.def).concatstabto(asmlist);
  2142. {$endif cpu64bit}
  2143. tstoreddef(u8inttype.def).concatstabto(asmlist);
  2144. tstoreddef(cchartype.def).concatstabto(asmlist);
  2145. {$EndIf}
  2146. inherited concatstabto(asmlist);
  2147. end;
  2148. {$endif GDB}
  2149. function tfiledef.gettypename : string;
  2150. begin
  2151. case filetyp of
  2152. ft_untyped:
  2153. gettypename:='File';
  2154. ft_typed:
  2155. gettypename:='File Of '+typedfiletype.def.typename;
  2156. ft_text:
  2157. gettypename:='Text'
  2158. end;
  2159. end;
  2160. function tfiledef.getmangledparaname : string;
  2161. begin
  2162. case filetyp of
  2163. ft_untyped:
  2164. getmangledparaname:='FILE';
  2165. ft_typed:
  2166. getmangledparaname:='FILE$OF$'+typedfiletype.def.mangledparaname;
  2167. ft_text:
  2168. getmangledparaname:='TEXT'
  2169. end;
  2170. end;
  2171. {****************************************************************************
  2172. TVARIANTDEF
  2173. ****************************************************************************}
  2174. constructor tvariantdef.create(v : tvarianttype);
  2175. begin
  2176. inherited create;
  2177. varianttype:=v;
  2178. deftype:=variantdef;
  2179. setsize;
  2180. end;
  2181. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2182. begin
  2183. inherited ppuloaddef(ppufile);
  2184. varianttype:=tvarianttype(ppufile.getbyte);
  2185. deftype:=variantdef;
  2186. setsize;
  2187. end;
  2188. function tvariantdef.getcopy : tstoreddef;
  2189. begin
  2190. result:=tvariantdef.create(varianttype);
  2191. end;
  2192. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2193. begin
  2194. inherited ppuwritedef(ppufile);
  2195. ppufile.putbyte(byte(varianttype));
  2196. ppufile.writeentry(ibvariantdef);
  2197. end;
  2198. procedure tvariantdef.setsize;
  2199. begin
  2200. savesize:=16;
  2201. end;
  2202. function tvariantdef.gettypename : string;
  2203. begin
  2204. case varianttype of
  2205. vt_normalvariant:
  2206. gettypename:='Variant';
  2207. vt_olevariant:
  2208. gettypename:='OleVariant';
  2209. end;
  2210. end;
  2211. procedure tvariantdef.write_rtti_data(rt:trttitype);
  2212. begin
  2213. rttiList.concat(Tai_const.Create_8bit(tkVariant));
  2214. end;
  2215. function tvariantdef.needs_inittable : boolean;
  2216. begin
  2217. needs_inittable:=true;
  2218. end;
  2219. {$ifdef GDB}
  2220. function tvariantdef.stabstring : pchar;
  2221. begin
  2222. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2223. end;
  2224. function tvariantdef.numberstring:string;
  2225. begin
  2226. result:=tstoreddef(voidtype.def).numberstring;
  2227. end;
  2228. procedure tvariantdef.concatstabto(asmlist : taasmoutput);
  2229. begin
  2230. { don't know how to handle this }
  2231. end;
  2232. {$endif GDB}
  2233. function tvariantdef.is_publishable : boolean;
  2234. begin
  2235. is_publishable:=true;
  2236. end;
  2237. {****************************************************************************
  2238. TPOINTERDEF
  2239. ****************************************************************************}
  2240. constructor tpointerdef.create(const tt : ttype);
  2241. begin
  2242. inherited create;
  2243. deftype:=pointerdef;
  2244. pointertype:=tt;
  2245. is_far:=false;
  2246. savesize:=sizeof(aint);
  2247. end;
  2248. constructor tpointerdef.createfar(const tt : ttype);
  2249. begin
  2250. inherited create;
  2251. deftype:=pointerdef;
  2252. pointertype:=tt;
  2253. is_far:=true;
  2254. savesize:=sizeof(aint);
  2255. end;
  2256. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2257. begin
  2258. inherited ppuloaddef(ppufile);
  2259. deftype:=pointerdef;
  2260. ppufile.gettype(pointertype);
  2261. is_far:=(ppufile.getbyte<>0);
  2262. savesize:=sizeof(aint);
  2263. end;
  2264. function tpointerdef.getcopy : tstoreddef;
  2265. begin
  2266. result:=tpointerdef.create(pointertype);
  2267. tpointerdef(result).is_far:=is_far;
  2268. tpointerdef(result).savesize:=savesize;
  2269. end;
  2270. procedure tpointerdef.buildderef;
  2271. begin
  2272. inherited buildderef;
  2273. pointertype.buildderef;
  2274. end;
  2275. procedure tpointerdef.deref;
  2276. begin
  2277. inherited deref;
  2278. pointertype.resolve;
  2279. end;
  2280. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2281. begin
  2282. inherited ppuwritedef(ppufile);
  2283. ppufile.puttype(pointertype);
  2284. ppufile.putbyte(byte(is_far));
  2285. ppufile.writeentry(ibpointerdef);
  2286. end;
  2287. {$ifdef GDB}
  2288. function tpointerdef.stabstring : pchar;
  2289. begin
  2290. stabstring := strpnew('*'+tstoreddef(pointertype.def).numberstring);
  2291. end;
  2292. procedure tpointerdef.concatstabto(asmlist : taasmoutput);
  2293. var st,nb : string;
  2294. begin
  2295. if (stab_state in [stab_state_writing,stab_state_written]) then
  2296. exit;
  2297. stab_state:=stab_state_writing;
  2298. tstoreddef(pointertype.def).concatstabto(asmlist);
  2299. if (pointertype.def.deftype in [recorddef,objectdef]) then
  2300. begin
  2301. if pointertype.def.deftype=objectdef then
  2302. nb:=tobjectdef(pointertype.def).classnumberstring
  2303. else
  2304. nb:=tstoreddef(pointertype.def).numberstring;
  2305. {to avoid infinite recursion in record with next-like fields }
  2306. if tstoreddef(pointertype.def).stab_state=stab_state_writing then
  2307. begin
  2308. if assigned(pointertype.def.typesym) then
  2309. begin
  2310. if assigned(typesym) then
  2311. st := ttypesym(typesym).name
  2312. else
  2313. st := ' ';
  2314. asmlist.concat(Tai_stabs.create(stabstr_evaluate(
  2315. '"$1:t${numberstring}=*$2=xs$3:",${N_LSYM},0,0,0',
  2316. [st,nb,pointertype.def.typesym.name])));
  2317. end;
  2318. stab_state:=stab_state_written;
  2319. end
  2320. else
  2321. begin
  2322. stab_state:=stab_state_used;
  2323. inherited concatstabto(asmlist);
  2324. end;
  2325. end
  2326. else
  2327. begin
  2328. stab_state:=stab_state_used;
  2329. inherited concatstabto(asmlist);
  2330. end;
  2331. end;
  2332. {$endif GDB}
  2333. function tpointerdef.gettypename : string;
  2334. begin
  2335. if is_far then
  2336. gettypename:='^'+pointertype.def.typename+';far'
  2337. else
  2338. gettypename:='^'+pointertype.def.typename;
  2339. end;
  2340. {****************************************************************************
  2341. TCLASSREFDEF
  2342. ****************************************************************************}
  2343. constructor tclassrefdef.create(const t:ttype);
  2344. begin
  2345. inherited create(t);
  2346. deftype:=classrefdef;
  2347. end;
  2348. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2349. begin
  2350. { be careful, tclassdefref inherits from tpointerdef }
  2351. inherited ppuloaddef(ppufile);
  2352. deftype:=classrefdef;
  2353. ppufile.gettype(pointertype);
  2354. is_far:=false;
  2355. savesize:=sizeof(aint);
  2356. end;
  2357. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2358. begin
  2359. { be careful, tclassdefref inherits from tpointerdef }
  2360. inherited ppuwritedef(ppufile);
  2361. ppufile.puttype(pointertype);
  2362. ppufile.writeentry(ibclassrefdef);
  2363. end;
  2364. {$ifdef GDB}
  2365. function tclassrefdef.stabstring : pchar;
  2366. begin
  2367. stabstring:=strpnew(tstoreddef(pvmttype.def).numberstring);
  2368. end;
  2369. {$endif GDB}
  2370. function tclassrefdef.gettypename : string;
  2371. begin
  2372. gettypename:='Class Of '+pointertype.def.typename;
  2373. end;
  2374. function tclassrefdef.is_publishable : boolean;
  2375. begin
  2376. is_publishable:=true;
  2377. end;
  2378. {***************************************************************************
  2379. TSETDEF
  2380. ***************************************************************************}
  2381. constructor tsetdef.create(const t:ttype;high : longint);
  2382. begin
  2383. inherited create;
  2384. deftype:=setdef;
  2385. elementtype:=t;
  2386. if high<32 then
  2387. begin
  2388. settype:=smallset;
  2389. {$ifdef testvarsets}
  2390. if aktsetalloc=0 THEN { $PACKSET Fixed?}
  2391. {$endif}
  2392. savesize:=Sizeof(longint)
  2393. {$ifdef testvarsets}
  2394. else {No, use $PACKSET VALUE for rounding}
  2395. savesize:=aktsetalloc*((high+aktsetalloc*8-1) DIV (aktsetalloc*8))
  2396. {$endif}
  2397. ;
  2398. end
  2399. else
  2400. if high<256 then
  2401. begin
  2402. settype:=normset;
  2403. savesize:=32;
  2404. end
  2405. else
  2406. {$ifdef testvarsets}
  2407. if high<$10000 then
  2408. begin
  2409. settype:=varset;
  2410. savesize:=4*((high+31) div 32);
  2411. end
  2412. else
  2413. {$endif testvarsets}
  2414. Message(sym_e_ill_type_decl_set);
  2415. end;
  2416. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2417. begin
  2418. inherited ppuloaddef(ppufile);
  2419. deftype:=setdef;
  2420. ppufile.gettype(elementtype);
  2421. settype:=tsettype(ppufile.getbyte);
  2422. case settype of
  2423. normset : savesize:=32;
  2424. varset : savesize:=ppufile.getlongint;
  2425. smallset : savesize:=Sizeof(longint);
  2426. end;
  2427. end;
  2428. destructor tsetdef.destroy;
  2429. begin
  2430. inherited destroy;
  2431. end;
  2432. function tsetdef.getcopy : tstoreddef;
  2433. begin
  2434. case settype of
  2435. smallset:
  2436. result:=tsetdef.create(elementtype,31);
  2437. normset:
  2438. result:=tsetdef.create(elementtype,255);
  2439. else
  2440. internalerror(2004121202);
  2441. end;
  2442. end;
  2443. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2444. begin
  2445. inherited ppuwritedef(ppufile);
  2446. ppufile.puttype(elementtype);
  2447. ppufile.putbyte(byte(settype));
  2448. if settype=varset then
  2449. ppufile.putlongint(savesize);
  2450. ppufile.writeentry(ibsetdef);
  2451. end;
  2452. {$ifdef GDB}
  2453. function tsetdef.stabstring : pchar;
  2454. begin
  2455. stabstring:=stabstr_evaluate('@s$1;S$2',[tostr(savesize*8),tstoreddef(elementtype.def).numberstring]);
  2456. end;
  2457. procedure tsetdef.concatstabto(asmlist:taasmoutput);
  2458. begin
  2459. if (stab_state in [stab_state_writing,stab_state_written]) then
  2460. exit;
  2461. tstoreddef(elementtype.def).concatstabto(asmlist);
  2462. inherited concatstabto(asmlist);
  2463. end;
  2464. {$endif GDB}
  2465. procedure tsetdef.buildderef;
  2466. begin
  2467. inherited buildderef;
  2468. elementtype.buildderef;
  2469. end;
  2470. procedure tsetdef.deref;
  2471. begin
  2472. inherited deref;
  2473. elementtype.resolve;
  2474. end;
  2475. procedure tsetdef.write_child_rtti_data(rt:trttitype);
  2476. begin
  2477. tstoreddef(elementtype.def).get_rtti_label(rt);
  2478. end;
  2479. procedure tsetdef.write_rtti_data(rt:trttitype);
  2480. begin
  2481. rttiList.concat(Tai_const.Create_8bit(tkSet));
  2482. write_rtti_name;
  2483. {$ifdef cpurequiresproperalignment}
  2484. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2485. {$endif cpurequiresproperalignment}
  2486. rttiList.concat(Tai_const.Create_8bit(otULong));
  2487. {$ifdef cpurequiresproperalignment}
  2488. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2489. {$endif cpurequiresproperalignment}
  2490. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2491. end;
  2492. function tsetdef.is_publishable : boolean;
  2493. begin
  2494. is_publishable:=(settype=smallset);
  2495. end;
  2496. function tsetdef.gettypename : string;
  2497. begin
  2498. if assigned(elementtype.def) then
  2499. gettypename:='Set Of '+elementtype.def.typename
  2500. else
  2501. gettypename:='Empty Set';
  2502. end;
  2503. {***************************************************************************
  2504. TFORMALDEF
  2505. ***************************************************************************}
  2506. constructor tformaldef.create;
  2507. var
  2508. stregdef : boolean;
  2509. begin
  2510. stregdef:=registerdef;
  2511. registerdef:=false;
  2512. inherited create;
  2513. deftype:=formaldef;
  2514. registerdef:=stregdef;
  2515. { formaldef must be registered at unit level !! }
  2516. if registerdef and assigned(current_module) then
  2517. if assigned(current_module.localsymtable) then
  2518. tsymtable(current_module.localsymtable).registerdef(self)
  2519. else if assigned(current_module.globalsymtable) then
  2520. tsymtable(current_module.globalsymtable).registerdef(self);
  2521. savesize:=0;
  2522. end;
  2523. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2524. begin
  2525. inherited ppuloaddef(ppufile);
  2526. deftype:=formaldef;
  2527. savesize:=0;
  2528. end;
  2529. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2530. begin
  2531. inherited ppuwritedef(ppufile);
  2532. ppufile.writeentry(ibformaldef);
  2533. end;
  2534. {$ifdef GDB}
  2535. function tformaldef.stabstring : pchar;
  2536. begin
  2537. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2538. end;
  2539. function tformaldef.numberstring:string;
  2540. begin
  2541. result:=tstoreddef(voidtype.def).numberstring;
  2542. end;
  2543. procedure tformaldef.concatstabto(asmlist : taasmoutput);
  2544. begin
  2545. { formaldef can't be stab'ed !}
  2546. end;
  2547. {$endif GDB}
  2548. function tformaldef.gettypename : string;
  2549. begin
  2550. gettypename:='<Formal type>';
  2551. end;
  2552. {***************************************************************************
  2553. TARRAYDEF
  2554. ***************************************************************************}
  2555. constructor tarraydef.create(l,h : aint;const t : ttype);
  2556. begin
  2557. inherited create;
  2558. deftype:=arraydef;
  2559. lowrange:=l;
  2560. highrange:=h;
  2561. rangetype:=t;
  2562. elementtype.reset;
  2563. IsVariant:=false;
  2564. IsConstructor:=false;
  2565. IsArrayOfConst:=false;
  2566. IsDynamicArray:=false;
  2567. IsConvertedPointer:=false;
  2568. end;
  2569. constructor tarraydef.create_from_pointer(const elemt : ttype);
  2570. begin
  2571. self.create(0,$7fffffff,s32inttype);
  2572. IsConvertedPointer:=true;
  2573. setelementtype(elemt);
  2574. end;
  2575. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2576. begin
  2577. inherited ppuloaddef(ppufile);
  2578. deftype:=arraydef;
  2579. { the addresses are calculated later }
  2580. ppufile.gettype(_elementtype);
  2581. ppufile.gettype(rangetype);
  2582. lowrange:=ppufile.getaint;
  2583. highrange:=ppufile.getaint;
  2584. IsArrayOfConst:=boolean(ppufile.getbyte);
  2585. IsDynamicArray:=boolean(ppufile.getbyte);
  2586. IsVariant:=false;
  2587. IsConstructor:=false;
  2588. end;
  2589. function tarraydef.getcopy : tstoreddef;
  2590. begin
  2591. result:=tarraydef.create(lowrange,highrange,rangetype);
  2592. tarraydef(result).IsConvertedPointer:=IsConvertedPointer;
  2593. tarraydef(result).IsDynamicArray:=IsDynamicArray;
  2594. tarraydef(result).IsVariant:=IsVariant;
  2595. tarraydef(result).IsConstructor:=IsConstructor;
  2596. tarraydef(result).IsArrayOfConst:=IsArrayOfConst;
  2597. tarraydef(result)._elementtype:=_elementtype;
  2598. end;
  2599. procedure tarraydef.buildderef;
  2600. begin
  2601. inherited buildderef;
  2602. _elementtype.buildderef;
  2603. rangetype.buildderef;
  2604. end;
  2605. procedure tarraydef.deref;
  2606. begin
  2607. inherited deref;
  2608. _elementtype.resolve;
  2609. rangetype.resolve;
  2610. end;
  2611. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2612. begin
  2613. inherited ppuwritedef(ppufile);
  2614. ppufile.puttype(_elementtype);
  2615. ppufile.puttype(rangetype);
  2616. ppufile.putaint(lowrange);
  2617. ppufile.putaint(highrange);
  2618. ppufile.putbyte(byte(IsArrayOfConst));
  2619. ppufile.putbyte(byte(IsDynamicArray));
  2620. ppufile.writeentry(ibarraydef);
  2621. end;
  2622. {$ifdef GDB}
  2623. function tarraydef.stabstring : pchar;
  2624. begin
  2625. stabstring:=stabstr_evaluate('ar$1;$2;$3;$4',[Tstoreddef(rangetype.def).numberstring,
  2626. tostr(lowrange),tostr(highrange),Tstoreddef(_elementtype.def).numberstring]);
  2627. end;
  2628. procedure tarraydef.concatstabto(asmlist:taasmoutput);
  2629. begin
  2630. if (stab_state in [stab_state_writing,stab_state_written]) then
  2631. exit;
  2632. tstoreddef(rangetype.def).concatstabto(asmlist);
  2633. tstoreddef(_elementtype.def).concatstabto(asmlist);
  2634. inherited concatstabto(asmlist);
  2635. end;
  2636. {$endif GDB}
  2637. function tarraydef.elesize : aint;
  2638. begin
  2639. elesize:=_elementtype.def.size;
  2640. end;
  2641. function tarraydef.elecount : aint;
  2642. var
  2643. qhigh,qlow : qword;
  2644. begin
  2645. if IsDynamicArray then
  2646. begin
  2647. result:=0;
  2648. exit;
  2649. end;
  2650. if (highrange>0) and (lowrange<0) then
  2651. begin
  2652. qhigh:=highrange;
  2653. qlow:=qword(-lowrange);
  2654. { prevent overflow, return -1 to indicate overflow }
  2655. if qhigh+qlow>qword(high(aint)-1) then
  2656. result:=-1
  2657. else
  2658. result:=qhigh+qlow+1;
  2659. end
  2660. else
  2661. result:=int64(highrange)-lowrange+1;
  2662. end;
  2663. function tarraydef.size : aint;
  2664. var
  2665. cachedelecount,
  2666. cachedelesize : aint;
  2667. begin
  2668. if IsDynamicArray then
  2669. begin
  2670. size:=sizeof(aint);
  2671. exit;
  2672. end;
  2673. { Tarraydef.size may never be called for an open array! }
  2674. if highrange<lowrange then
  2675. internalerror(99080501);
  2676. cachedelesize:=elesize;
  2677. cachedelecount:=elecount;
  2678. { prevent overflow, return -1 to indicate overflow }
  2679. if (cachedelesize <> 0) and
  2680. (
  2681. (cachedelecount < 0) or
  2682. ((high(aint) div cachedelesize) < cachedelecount) or
  2683. { also lowrange*elesize must be < high(aint) to prevent overflow when
  2684. accessing the array, see ncgmem (PFV) }
  2685. ((high(aint) div cachedelesize) < abs(lowrange))
  2686. ) then
  2687. result:=-1
  2688. else
  2689. result:=cachedelesize*cachedelecount;
  2690. end;
  2691. procedure tarraydef.setelementtype(t: ttype);
  2692. begin
  2693. _elementtype:=t;
  2694. if not(IsDynamicArray or
  2695. IsConvertedPointer or
  2696. (highrange<lowrange)) then
  2697. begin
  2698. if (size=-1) then
  2699. Message(sym_e_segment_too_large);
  2700. end;
  2701. end;
  2702. function tarraydef.alignment : longint;
  2703. begin
  2704. { alignment is the size of the elements }
  2705. if (elementtype.def.deftype in [arraydef,recorddef]) or
  2706. ((elementtype.def.deftype=objectdef) and
  2707. is_object(elementtype.def)) then
  2708. alignment:=elementtype.def.alignment
  2709. else
  2710. alignment:=elesize;
  2711. end;
  2712. function tarraydef.needs_inittable : boolean;
  2713. begin
  2714. needs_inittable:=IsDynamicArray or elementtype.def.needs_inittable;
  2715. end;
  2716. procedure tarraydef.write_child_rtti_data(rt:trttitype);
  2717. begin
  2718. tstoreddef(elementtype.def).get_rtti_label(rt);
  2719. end;
  2720. procedure tarraydef.write_rtti_data(rt:trttitype);
  2721. begin
  2722. if IsDynamicArray then
  2723. rttiList.concat(Tai_const.Create_8bit(tkdynarray))
  2724. else
  2725. rttiList.concat(Tai_const.Create_8bit(tkarray));
  2726. write_rtti_name;
  2727. {$ifdef cpurequiresproperalignment}
  2728. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2729. {$endif cpurequiresproperalignment}
  2730. { size of elements }
  2731. rttiList.concat(Tai_const.Create_aint(elesize));
  2732. if not(IsDynamicArray) then
  2733. rttiList.concat(Tai_const.Create_aint(elecount));
  2734. { element type }
  2735. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2736. { variant type }
  2737. // !!!!!!!!!!!!!!!!
  2738. end;
  2739. function tarraydef.gettypename : string;
  2740. begin
  2741. if isarrayofconst or isConstructor then
  2742. begin
  2743. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2744. gettypename:='Array Of Const'
  2745. else
  2746. gettypename:='Array Of '+elementtype.def.typename;
  2747. end
  2748. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2749. gettypename:='Array Of '+elementtype.def.typename
  2750. else
  2751. begin
  2752. if rangetype.def.deftype=enumdef then
  2753. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2754. else
  2755. gettypename:='Array['+tostr(lowrange)+'..'+
  2756. tostr(highrange)+'] Of '+elementtype.def.typename
  2757. end;
  2758. end;
  2759. function tarraydef.getmangledparaname : string;
  2760. begin
  2761. if isarrayofconst then
  2762. getmangledparaname:='array_of_const'
  2763. else
  2764. if ((highrange=-1) and (lowrange=0)) then
  2765. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2766. else
  2767. internalerror(200204176);
  2768. end;
  2769. {***************************************************************************
  2770. tabstractrecorddef
  2771. ***************************************************************************}
  2772. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2773. begin
  2774. if t=gs_record then
  2775. getsymtable:=symtable
  2776. else
  2777. getsymtable:=nil;
  2778. end;
  2779. {$ifdef GDB}
  2780. procedure tabstractrecorddef.field_addname(p:Tnamedindexitem;arg:pointer);
  2781. var
  2782. newrec:Pchar;
  2783. spec:string[3];
  2784. varsize : aint;
  2785. state : ^Trecord_stabgen_state;
  2786. begin
  2787. state:=arg;
  2788. { static variables from objects are like global objects }
  2789. if (Tsym(p).typ=fieldvarsym) and not (sp_static in Tsym(p).symoptions) then
  2790. begin
  2791. if (sp_protected in tsym(p).symoptions) then
  2792. spec:='/1'
  2793. else if (sp_private in tsym(p).symoptions) then
  2794. spec:='/0'
  2795. else
  2796. spec:='';
  2797. varsize:=tfieldvarsym(p).vartype.def.size;
  2798. { open arrays made overflows !! }
  2799. if varsize>$fffffff then
  2800. varsize:=$fffffff;
  2801. newrec:=stabstr_evaluate('$1:$2,$3,$4;',[p.name,
  2802. spec+tstoreddef(tfieldvarsym(p).vartype.def).numberstring,
  2803. tostr(tfieldvarsym(p).fieldoffset*8),tostr(varsize*8)]);
  2804. if state^.stabsize+strlen(newrec)>=state^.staballoc-256 then
  2805. begin
  2806. inc(state^.staballoc,memsizeinc);
  2807. reallocmem(state^.stabstring,state^.staballoc);
  2808. end;
  2809. strcopy(state^.stabstring+state^.stabsize,newrec);
  2810. inc(state^.stabsize,strlen(newrec));
  2811. strdispose(newrec);
  2812. {This should be used for case !!}
  2813. inc(state^.recoffset,Tfieldvarsym(p).vartype.def.size);
  2814. end;
  2815. end;
  2816. procedure tabstractrecorddef.field_concatstabto(p:Tnamedindexitem;arg:pointer);
  2817. begin
  2818. if (Tsym(p).typ=fieldvarsym) and not (sp_static in Tsym(p).symoptions) then
  2819. tstoreddef(tfieldvarsym(p).vartype.def).concatstabto(taasmoutput(arg));
  2820. end;
  2821. {$endif GDB}
  2822. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2823. begin
  2824. if (FRTTIType=fullrtti) or
  2825. ((tsym(sym).typ=fieldvarsym) and
  2826. tfieldvarsym(sym).vartype.def.needs_inittable) then
  2827. inc(Count);
  2828. end;
  2829. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2830. begin
  2831. if (FRTTIType=fullrtti) or
  2832. ((tsym(sym).typ=fieldvarsym) and
  2833. tfieldvarsym(sym).vartype.def.needs_inittable) then
  2834. tstoreddef(tfieldvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2835. end;
  2836. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2837. begin
  2838. if (FRTTIType=fullrtti) or
  2839. ((tsym(sym).typ=fieldvarsym) and
  2840. tfieldvarsym(sym).vartype.def.needs_inittable) then
  2841. begin
  2842. rttiList.concat(Tai_const.Create_sym(tstoreddef(tfieldvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2843. rttiList.concat(Tai_const.Create_32bit(tfieldvarsym(sym).fieldoffset));
  2844. end;
  2845. end;
  2846. {***************************************************************************
  2847. trecorddef
  2848. ***************************************************************************}
  2849. constructor trecorddef.create(p : tsymtable);
  2850. begin
  2851. inherited create;
  2852. deftype:=recorddef;
  2853. symtable:=p;
  2854. symtable.defowner:=self;
  2855. isunion:=false;
  2856. end;
  2857. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2858. begin
  2859. inherited ppuloaddef(ppufile);
  2860. deftype:=recorddef;
  2861. symtable:=trecordsymtable.create(0);
  2862. trecordsymtable(symtable).datasize:=ppufile.getaint;
  2863. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2864. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2865. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2866. trecordsymtable(symtable).ppuload(ppufile);
  2867. symtable.defowner:=self;
  2868. isunion:=false;
  2869. end;
  2870. destructor trecorddef.destroy;
  2871. begin
  2872. if assigned(symtable) then
  2873. symtable.free;
  2874. inherited destroy;
  2875. end;
  2876. function trecorddef.getcopy : tstoreddef;
  2877. begin
  2878. result:=trecorddef.create(symtable.getcopy);
  2879. trecorddef(result).isunion:=isunion;
  2880. end;
  2881. function trecorddef.needs_inittable : boolean;
  2882. begin
  2883. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2884. end;
  2885. procedure trecorddef.buildderef;
  2886. var
  2887. oldrecsyms : tsymtable;
  2888. begin
  2889. inherited buildderef;
  2890. oldrecsyms:=aktrecordsymtable;
  2891. aktrecordsymtable:=symtable;
  2892. { now build the definitions }
  2893. tstoredsymtable(symtable).buildderef;
  2894. aktrecordsymtable:=oldrecsyms;
  2895. end;
  2896. procedure trecorddef.deref;
  2897. var
  2898. oldrecsyms : tsymtable;
  2899. begin
  2900. inherited deref;
  2901. oldrecsyms:=aktrecordsymtable;
  2902. aktrecordsymtable:=symtable;
  2903. { now dereference the definitions }
  2904. tstoredsymtable(symtable).deref;
  2905. aktrecordsymtable:=oldrecsyms;
  2906. { assign TGUID? load only from system unit }
  2907. if not(assigned(rec_tguid)) and
  2908. (upper(typename)='TGUID') and
  2909. assigned(owner) and
  2910. assigned(owner.name) and
  2911. (owner.name^='SYSTEM') then
  2912. rec_tguid:=self;
  2913. end;
  2914. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2915. begin
  2916. inherited ppuwritedef(ppufile);
  2917. ppufile.putaint(trecordsymtable(symtable).datasize);
  2918. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2919. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2920. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2921. ppufile.writeentry(ibrecorddef);
  2922. trecordsymtable(symtable).ppuwrite(ppufile);
  2923. end;
  2924. function trecorddef.size:aint;
  2925. begin
  2926. result:=trecordsymtable(symtable).datasize;
  2927. end;
  2928. function trecorddef.alignment:longint;
  2929. begin
  2930. alignment:=trecordsymtable(symtable).recordalignment;
  2931. end;
  2932. function trecorddef.padalignment:longint;
  2933. begin
  2934. padalignment := trecordsymtable(symtable).padalignment;
  2935. end;
  2936. {$ifdef GDB}
  2937. function trecorddef.stabstring : pchar;
  2938. var
  2939. state:Trecord_stabgen_state;
  2940. begin
  2941. getmem(state.stabstring,memsizeinc);
  2942. state.staballoc:=memsizeinc;
  2943. strpcopy(state.stabstring,'s'+tostr(size));
  2944. state.recoffset:=0;
  2945. state.stabsize:=strlen(state.stabstring);
  2946. symtable.foreach(@field_addname,@state);
  2947. state.stabstring[state.stabsize]:=';';
  2948. state.stabstring[state.stabsize+1]:=#0;
  2949. reallocmem(state.stabstring,state.stabsize+2);
  2950. stabstring:=state.stabstring;
  2951. end;
  2952. procedure trecorddef.concatstabto(asmlist:taasmoutput);
  2953. begin
  2954. if (stab_state in [stab_state_writing,stab_state_written]) then
  2955. exit;
  2956. symtable.foreach(@field_concatstabto,asmlist);
  2957. inherited concatstabto(asmlist);
  2958. end;
  2959. {$endif GDB}
  2960. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2961. begin
  2962. FRTTIType:=rt;
  2963. symtable.foreach(@generate_field_rtti,nil);
  2964. end;
  2965. procedure trecorddef.write_rtti_data(rt:trttitype);
  2966. begin
  2967. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2968. write_rtti_name;
  2969. {$ifdef cpurequiresproperalignment}
  2970. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2971. {$endif cpurequiresproperalignment}
  2972. rttiList.concat(Tai_const.Create_32bit(size));
  2973. Count:=0;
  2974. FRTTIType:=rt;
  2975. symtable.foreach(@count_field_rtti,nil);
  2976. rttiList.concat(Tai_const.Create_32bit(Count));
  2977. symtable.foreach(@write_field_rtti,nil);
  2978. end;
  2979. function trecorddef.gettypename : string;
  2980. begin
  2981. gettypename:='<record type>'
  2982. end;
  2983. {***************************************************************************
  2984. TABSTRACTPROCDEF
  2985. ***************************************************************************}
  2986. constructor tabstractprocdef.create(level:byte);
  2987. begin
  2988. inherited create;
  2989. parast:=tparasymtable.create(level);
  2990. parast.defowner:=self;
  2991. parast.next:=owner;
  2992. paras:=nil;
  2993. minparacount:=0;
  2994. maxparacount:=0;
  2995. proctypeoption:=potype_none;
  2996. proccalloption:=pocall_none;
  2997. procoptions:=[];
  2998. rettype:=voidtype;
  2999. {$ifdef i386}
  3000. fpu_used:=0;
  3001. {$endif i386}
  3002. savesize:=sizeof(aint);
  3003. requiredargarea:=0;
  3004. has_paraloc_info:=false;
  3005. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  3006. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  3007. end;
  3008. destructor tabstractprocdef.destroy;
  3009. begin
  3010. if assigned(paras) then
  3011. begin
  3012. {$ifdef MEMDEBUG}
  3013. memprocpara.start;
  3014. {$endif MEMDEBUG}
  3015. paras.free;
  3016. {$ifdef MEMDEBUG}
  3017. memprocpara.stop;
  3018. {$endif MEMDEBUG}
  3019. end;
  3020. if assigned(parast) then
  3021. begin
  3022. {$ifdef MEMDEBUG}
  3023. memprocparast.start;
  3024. {$endif MEMDEBUG}
  3025. parast.free;
  3026. {$ifdef MEMDEBUG}
  3027. memprocparast.stop;
  3028. {$endif MEMDEBUG}
  3029. end;
  3030. inherited destroy;
  3031. end;
  3032. procedure tabstractprocdef.releasemem;
  3033. begin
  3034. if assigned(paras) then
  3035. begin
  3036. paras.free;
  3037. paras:=nil;
  3038. end;
  3039. parast.free;
  3040. parast:=nil;
  3041. end;
  3042. procedure tabstractprocdef.count_para(p:tnamedindexitem;arg:pointer);
  3043. begin
  3044. if (tsym(p).typ<>paravarsym) then
  3045. exit;
  3046. inc(plongint(arg)^);
  3047. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  3048. begin
  3049. if not assigned(tparavarsym(p).defaultconstsym) then
  3050. inc(minparacount);
  3051. inc(maxparacount);
  3052. end;
  3053. end;
  3054. procedure tabstractprocdef.insert_para(p:tnamedindexitem;arg:pointer);
  3055. begin
  3056. if (tsym(p).typ<>paravarsym) then
  3057. exit;
  3058. paras.add(p);
  3059. end;
  3060. procedure tabstractprocdef.calcparas;
  3061. var
  3062. paracount : longint;
  3063. begin
  3064. { This can already be assigned when
  3065. we need to reresolve this unit (PFV) }
  3066. if assigned(paras) then
  3067. paras.free;
  3068. paras:=tparalist.create;
  3069. paracount:=0;
  3070. minparacount:=0;
  3071. maxparacount:=0;
  3072. parast.foreach(@count_para,@paracount);
  3073. paras.capacity:=paracount;
  3074. { Insert parameters in table }
  3075. parast.foreach(@insert_para,nil);
  3076. { Order parameters }
  3077. paras.sortparas;
  3078. end;
  3079. { all functions returning in FPU are
  3080. assume to use 2 FPU registers
  3081. until the function implementation
  3082. is processed PM }
  3083. procedure tabstractprocdef.test_if_fpu_result;
  3084. begin
  3085. {$ifdef i386}
  3086. if assigned(rettype.def) and
  3087. (rettype.def.deftype=floatdef) then
  3088. fpu_used:=maxfpuregs;
  3089. {$endif i386}
  3090. end;
  3091. procedure tabstractprocdef.buildderef;
  3092. begin
  3093. { released procdef? }
  3094. if not assigned(parast) then
  3095. exit;
  3096. inherited buildderef;
  3097. rettype.buildderef;
  3098. { parast }
  3099. tparasymtable(parast).buildderef;
  3100. end;
  3101. procedure tabstractprocdef.deref;
  3102. begin
  3103. inherited deref;
  3104. rettype.resolve;
  3105. { parast }
  3106. tparasymtable(parast).deref;
  3107. { recalculated parameters }
  3108. calcparas;
  3109. end;
  3110. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  3111. var
  3112. b : byte;
  3113. begin
  3114. inherited ppuloaddef(ppufile);
  3115. parast:=nil;
  3116. Paras:=nil;
  3117. minparacount:=0;
  3118. maxparacount:=0;
  3119. ppufile.gettype(rettype);
  3120. {$ifdef i386}
  3121. fpu_used:=ppufile.getbyte;
  3122. {$else}
  3123. ppufile.getbyte;
  3124. {$endif i386}
  3125. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3126. proccalloption:=tproccalloption(ppufile.getbyte);
  3127. ppufile.getsmallset(procoptions);
  3128. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  3129. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  3130. if po_explicitparaloc in procoptions then
  3131. begin
  3132. b:=ppufile.getbyte;
  3133. if b<>sizeof(funcretloc[callerside]) then
  3134. internalerror(200411154);
  3135. ppufile.getdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  3136. end;
  3137. savesize:=sizeof(aint);
  3138. has_paraloc_info:=(po_explicitparaloc in procoptions);
  3139. end;
  3140. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3141. var
  3142. oldintfcrc : boolean;
  3143. begin
  3144. { released procdef? }
  3145. if not assigned(parast) then
  3146. exit;
  3147. inherited ppuwritedef(ppufile);
  3148. ppufile.puttype(rettype);
  3149. oldintfcrc:=ppufile.do_interface_crc;
  3150. ppufile.do_interface_crc:=false;
  3151. {$ifdef i386}
  3152. if simplify_ppu then
  3153. fpu_used:=0;
  3154. ppufile.putbyte(fpu_used);
  3155. {$else}
  3156. ppufile.putbyte(0);
  3157. {$endif}
  3158. ppufile.putbyte(ord(proctypeoption));
  3159. ppufile.putbyte(ord(proccalloption));
  3160. ppufile.putsmallset(procoptions);
  3161. ppufile.do_interface_crc:=oldintfcrc;
  3162. if (po_explicitparaloc in procoptions) then
  3163. begin
  3164. { Make a 'valid' funcretloc for procedures }
  3165. ppufile.putbyte(sizeof(funcretloc[callerside]));
  3166. ppufile.putdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  3167. end;
  3168. end;
  3169. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  3170. var
  3171. hs,s : string;
  3172. hp : TParavarsym;
  3173. hpc : tconstsym;
  3174. first : boolean;
  3175. i : integer;
  3176. begin
  3177. s:='';
  3178. first:=true;
  3179. for i:=0 to paras.count-1 do
  3180. begin
  3181. hp:=tparavarsym(paras[i]);
  3182. if not(vo_is_hidden_para in hp.varoptions) or
  3183. (showhidden) then
  3184. begin
  3185. if first then
  3186. begin
  3187. s:=s+'(';
  3188. first:=false;
  3189. end
  3190. else
  3191. s:=s+',';
  3192. case hp.varspez of
  3193. vs_var :
  3194. s:=s+'var';
  3195. vs_const :
  3196. s:=s+'const';
  3197. vs_out :
  3198. s:=s+'out';
  3199. end;
  3200. if assigned(hp.vartype.def.typesym) then
  3201. begin
  3202. if s<>'(' then
  3203. s:=s+' ';
  3204. hs:=hp.vartype.def.typesym.realname;
  3205. if hs[1]<>'$' then
  3206. s:=s+hp.vartype.def.typesym.realname
  3207. else
  3208. s:=s+hp.vartype.def.gettypename;
  3209. end
  3210. else
  3211. s:=s+hp.vartype.def.gettypename;
  3212. { default value }
  3213. if assigned(hp.defaultconstsym) then
  3214. begin
  3215. hpc:=tconstsym(hp.defaultconstsym);
  3216. hs:='';
  3217. case hpc.consttyp of
  3218. conststring,
  3219. constresourcestring :
  3220. hs:=strpas(pchar(hpc.value.valueptr));
  3221. constreal :
  3222. str(pbestreal(hpc.value.valueptr)^,hs);
  3223. constpointer :
  3224. hs:=tostr(hpc.value.valueordptr);
  3225. constord :
  3226. begin
  3227. if is_boolean(hpc.consttype.def) then
  3228. begin
  3229. if hpc.value.valueord<>0 then
  3230. hs:='TRUE'
  3231. else
  3232. hs:='FALSE';
  3233. end
  3234. else
  3235. hs:=tostr(hpc.value.valueord);
  3236. end;
  3237. constnil :
  3238. hs:='nil';
  3239. constset :
  3240. hs:='<set>';
  3241. end;
  3242. if hs<>'' then
  3243. s:=s+'="'+hs+'"';
  3244. end;
  3245. end;
  3246. end;
  3247. if not first then
  3248. s:=s+')';
  3249. if (po_varargs in procoptions) then
  3250. s:=s+';VarArgs';
  3251. typename_paras:=s;
  3252. end;
  3253. function tabstractprocdef.is_methodpointer:boolean;
  3254. begin
  3255. result:=false;
  3256. end;
  3257. function tabstractprocdef.is_addressonly:boolean;
  3258. begin
  3259. result:=true;
  3260. end;
  3261. {$ifdef GDB}
  3262. function tabstractprocdef.stabstring : pchar;
  3263. begin
  3264. stabstring := strpnew('abstractproc'+numberstring+';');
  3265. end;
  3266. {$endif GDB}
  3267. {***************************************************************************
  3268. TPROCDEF
  3269. ***************************************************************************}
  3270. constructor tprocdef.create(level:byte);
  3271. begin
  3272. inherited create(level);
  3273. deftype:=procdef;
  3274. _mangledname:=nil;
  3275. fileinfo:=aktfilepos;
  3276. extnumber:=$ffff;
  3277. aliasnames:=tstringlist.create;
  3278. funcretsym:=nil;
  3279. localst := nil;
  3280. defref:=nil;
  3281. lastwritten:=nil;
  3282. refcount:=0;
  3283. if (cs_browser in aktmoduleswitches) and make_ref then
  3284. begin
  3285. defref:=tref.create(defref,@akttokenpos);
  3286. inc(refcount);
  3287. end;
  3288. lastref:=defref;
  3289. forwarddef:=true;
  3290. interfacedef:=false;
  3291. hasforward:=false;
  3292. _class := nil;
  3293. import_dll:=nil;
  3294. import_name:=nil;
  3295. import_nr:=0;
  3296. inlininginfo:=nil;
  3297. {$ifdef GDB}
  3298. isstabwritten := false;
  3299. {$endif GDB}
  3300. end;
  3301. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3302. var
  3303. level : byte;
  3304. begin
  3305. inherited ppuload(ppufile);
  3306. deftype:=procdef;
  3307. if po_has_mangledname in procoptions then
  3308. _mangledname:=stringdup(ppufile.getstring)
  3309. else
  3310. _mangledname:=nil;
  3311. extnumber:=ppufile.getword;
  3312. level:=ppufile.getbyte;
  3313. ppufile.getderef(_classderef);
  3314. ppufile.getderef(procsymderef);
  3315. ppufile.getposinfo(fileinfo);
  3316. ppufile.getsmallset(symoptions);
  3317. {$ifdef powerpc}
  3318. { library symbol for AmigaOS/MorphOS }
  3319. ppufile.getderef(libsymderef);
  3320. {$endif powerpc}
  3321. { import stuff }
  3322. import_dll:=nil;
  3323. import_name:=nil;
  3324. import_nr:=0;
  3325. { inline stuff }
  3326. if (po_has_inlininginfo in procoptions) then
  3327. begin
  3328. ppufile.getderef(funcretsymderef);
  3329. new(inlininginfo);
  3330. ppufile.getsmallset(inlininginfo^.flags);
  3331. end
  3332. else
  3333. begin
  3334. inlininginfo:=nil;
  3335. funcretsym:=nil;
  3336. end;
  3337. { load para symtable }
  3338. parast:=tparasymtable.create(level);
  3339. tparasymtable(parast).ppuload(ppufile);
  3340. parast.defowner:=self;
  3341. { load local symtable }
  3342. if (po_has_inlininginfo in procoptions) or
  3343. ((current_module.flags and uf_local_browser)<>0) then
  3344. begin
  3345. localst:=tlocalsymtable.create(level);
  3346. tlocalsymtable(localst).ppuload(ppufile);
  3347. localst.defowner:=self;
  3348. end
  3349. else
  3350. localst:=nil;
  3351. { inline stuff }
  3352. if (po_has_inlininginfo in procoptions) then
  3353. inlininginfo^.code:=ppuloadnodetree(ppufile);
  3354. { default values for no persistent data }
  3355. if (cs_link_deffile in aktglobalswitches) and
  3356. (tf_need_export in target_info.flags) and
  3357. (po_exports in procoptions) then
  3358. deffile.AddExport(mangledname);
  3359. aliasnames:=tstringlist.create;
  3360. forwarddef:=false;
  3361. interfacedef:=false;
  3362. hasforward:=false;
  3363. lastref:=nil;
  3364. lastwritten:=nil;
  3365. defref:=nil;
  3366. refcount:=0;
  3367. {$ifdef GDB}
  3368. isstabwritten := false;
  3369. {$endif GDB}
  3370. { Disable po_has_inlining until the derefimpl is done }
  3371. exclude(procoptions,po_has_inlininginfo);
  3372. end;
  3373. destructor tprocdef.destroy;
  3374. begin
  3375. if assigned(defref) then
  3376. begin
  3377. defref.freechain;
  3378. defref.free;
  3379. end;
  3380. aliasnames.free;
  3381. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3382. begin
  3383. {$ifdef MEMDEBUG}
  3384. memproclocalst.start;
  3385. {$endif MEMDEBUG}
  3386. localst.free;
  3387. {$ifdef MEMDEBUG}
  3388. memproclocalst.start;
  3389. {$endif MEMDEBUG}
  3390. end;
  3391. if assigned(inlininginfo) then
  3392. begin
  3393. {$ifdef MEMDEBUG}
  3394. memprocnodetree.start;
  3395. {$endif MEMDEBUG}
  3396. tnode(inlininginfo^.code).free;
  3397. {$ifdef MEMDEBUG}
  3398. memprocnodetree.start;
  3399. {$endif MEMDEBUG}
  3400. dispose(inlininginfo);
  3401. end;
  3402. stringdispose(import_dll);
  3403. stringdispose(import_name);
  3404. if (po_msgstr in procoptions) then
  3405. strdispose(messageinf.str);
  3406. if assigned(_mangledname) then
  3407. begin
  3408. {$ifdef MEMDEBUG}
  3409. memmanglednames.start;
  3410. {$endif MEMDEBUG}
  3411. stringdispose(_mangledname);
  3412. {$ifdef MEMDEBUG}
  3413. memmanglednames.stop;
  3414. {$endif MEMDEBUG}
  3415. end;
  3416. inherited destroy;
  3417. end;
  3418. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3419. var
  3420. oldintfcrc : boolean;
  3421. oldparasymtable,
  3422. oldlocalsymtable : tsymtable;
  3423. begin
  3424. { released procdef? }
  3425. if not assigned(parast) then
  3426. exit;
  3427. oldparasymtable:=aktparasymtable;
  3428. oldlocalsymtable:=aktlocalsymtable;
  3429. aktparasymtable:=parast;
  3430. aktlocalsymtable:=localst;
  3431. inherited ppuwrite(ppufile);
  3432. oldintfcrc:=ppufile.do_interface_crc;
  3433. ppufile.do_interface_crc:=false;
  3434. ppufile.do_interface_crc:=oldintfcrc;
  3435. if po_has_mangledname in procoptions then
  3436. ppufile.putstring(_mangledname^);
  3437. ppufile.putword(extnumber);
  3438. ppufile.putbyte(parast.symtablelevel);
  3439. ppufile.putderef(_classderef);
  3440. ppufile.putderef(procsymderef);
  3441. ppufile.putposinfo(fileinfo);
  3442. ppufile.putsmallset(symoptions);
  3443. {$ifdef powerpc}
  3444. { library symbol for AmigaOS/MorphOS }
  3445. ppufile.putderef(libsymderef);
  3446. {$endif powerpc}
  3447. { inline stuff }
  3448. oldintfcrc:=ppufile.do_crc;
  3449. ppufile.do_crc:=false;
  3450. if (po_has_inlininginfo in procoptions) then
  3451. begin
  3452. ppufile.putderef(funcretsymderef);
  3453. ppufile.putsmallset(inlininginfo^.flags);
  3454. end;
  3455. ppufile.do_crc:=oldintfcrc;
  3456. { write this entry }
  3457. ppufile.writeentry(ibprocdef);
  3458. { Save the para symtable, this is taken from the interface }
  3459. tparasymtable(parast).ppuwrite(ppufile);
  3460. { save localsymtable for inline procedures or when local
  3461. browser info is requested, this has no influence on the crc }
  3462. if (po_has_inlininginfo in procoptions) or
  3463. ((current_module.flags and uf_local_browser)<>0) then
  3464. begin
  3465. { we must write a localsymtable }
  3466. if not assigned(localst) then
  3467. insert_localst;
  3468. oldintfcrc:=ppufile.do_crc;
  3469. ppufile.do_crc:=false;
  3470. tlocalsymtable(localst).ppuwrite(ppufile);
  3471. ppufile.do_crc:=oldintfcrc;
  3472. end;
  3473. { node tree for inlining }
  3474. oldintfcrc:=ppufile.do_crc;
  3475. ppufile.do_crc:=false;
  3476. if (po_has_inlininginfo in procoptions) then
  3477. ppuwritenodetree(ppufile,inlininginfo^.code);
  3478. ppufile.do_crc:=oldintfcrc;
  3479. aktparasymtable:=oldparasymtable;
  3480. aktlocalsymtable:=oldlocalsymtable;
  3481. end;
  3482. procedure tprocdef.insert_localst;
  3483. begin
  3484. localst:=tlocalsymtable.create(parast.symtablelevel);
  3485. localst.defowner:=self;
  3486. { this is used by insert
  3487. to check same names in parast and localst }
  3488. localst.next:=parast;
  3489. end;
  3490. function tprocdef.fullprocname(showhidden:boolean):string;
  3491. var
  3492. s : string;
  3493. t : ttoken;
  3494. begin
  3495. {$ifdef EXTDEBUG}
  3496. showhidden:=true;
  3497. {$endif EXTDEBUG}
  3498. s:='';
  3499. if owner.symtabletype=localsymtable then
  3500. s:=s+'local ';
  3501. if assigned(_class) then
  3502. begin
  3503. if po_classmethod in procoptions then
  3504. s:=s+'class ';
  3505. s:=s+_class.objrealname^+'.';
  3506. end;
  3507. if proctypeoption=potype_operator then
  3508. begin
  3509. for t:=NOTOKEN to last_overloaded do
  3510. if procsym.realname='$'+overloaded_names[t] then
  3511. begin
  3512. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3513. break;
  3514. end;
  3515. end
  3516. else
  3517. s:=s+procsym.realname+typename_paras(showhidden);
  3518. case proctypeoption of
  3519. potype_constructor:
  3520. s:='constructor '+s;
  3521. potype_destructor:
  3522. s:='destructor '+s;
  3523. else
  3524. if assigned(rettype.def) and
  3525. not(is_void(rettype.def)) then
  3526. s:=s+':'+rettype.def.gettypename;
  3527. end;
  3528. { forced calling convention? }
  3529. if (po_hascallingconvention in procoptions) then
  3530. s:=s+';'+ProcCallOptionStr[proccalloption];
  3531. fullprocname:=s;
  3532. end;
  3533. function tprocdef.is_methodpointer:boolean;
  3534. begin
  3535. result:=assigned(_class);
  3536. end;
  3537. function tprocdef.is_addressonly:boolean;
  3538. begin
  3539. result:=assigned(owner) and
  3540. (owner.symtabletype<>objectsymtable);
  3541. end;
  3542. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3543. begin
  3544. is_visible_for_object:=false;
  3545. { private symbols are allowed when we are in the same
  3546. module as they are defined }
  3547. if (sp_private in symoptions) and
  3548. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3549. not(owner.defowner.owner.iscurrentunit) then
  3550. exit;
  3551. { protected symbols are vissible in the module that defines them and
  3552. also visible to related objects. The related object must be defined
  3553. in the current module }
  3554. if (sp_protected in symoptions) and
  3555. (
  3556. (
  3557. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3558. not(owner.defowner.owner.iscurrentunit)
  3559. ) and
  3560. not(
  3561. assigned(currobjdef) and
  3562. (currobjdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3563. (currobjdef.owner.iscurrentunit) and
  3564. currobjdef.is_related(tobjectdef(owner.defowner))
  3565. )
  3566. ) then
  3567. exit;
  3568. is_visible_for_object:=true;
  3569. end;
  3570. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3571. begin
  3572. case t of
  3573. gs_local :
  3574. getsymtable:=localst;
  3575. gs_para :
  3576. getsymtable:=parast;
  3577. else
  3578. getsymtable:=nil;
  3579. end;
  3580. end;
  3581. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3582. var
  3583. pos : tfileposinfo;
  3584. move_last : boolean;
  3585. oldparasymtable,
  3586. oldlocalsymtable : tsymtable;
  3587. begin
  3588. oldparasymtable:=aktparasymtable;
  3589. oldlocalsymtable:=aktlocalsymtable;
  3590. aktparasymtable:=parast;
  3591. aktlocalsymtable:=localst;
  3592. move_last:=lastwritten=lastref;
  3593. while (not ppufile.endofentry) do
  3594. begin
  3595. ppufile.getposinfo(pos);
  3596. inc(refcount);
  3597. lastref:=tref.create(lastref,@pos);
  3598. lastref.is_written:=true;
  3599. if refcount=1 then
  3600. defref:=lastref;
  3601. end;
  3602. if move_last then
  3603. lastwritten:=lastref;
  3604. if ((current_module.flags and uf_local_browser)<>0) and
  3605. assigned(localst) and
  3606. locals then
  3607. begin
  3608. tparasymtable(parast).load_references(ppufile,locals);
  3609. tlocalsymtable(localst).load_references(ppufile,locals);
  3610. end;
  3611. aktparasymtable:=oldparasymtable;
  3612. aktlocalsymtable:=oldlocalsymtable;
  3613. end;
  3614. Const
  3615. local_symtable_index : word = $8001;
  3616. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3617. var
  3618. ref : tref;
  3619. {$ifdef supportbrowser}
  3620. pdo : tobjectdef;
  3621. {$endif supportbrowser}
  3622. move_last : boolean;
  3623. d : tderef;
  3624. oldparasymtable,
  3625. oldlocalsymtable : tsymtable;
  3626. begin
  3627. d.reset;
  3628. move_last:=lastwritten=lastref;
  3629. if move_last and
  3630. (((current_module.flags and uf_local_browser)=0) or
  3631. not locals) then
  3632. exit;
  3633. oldparasymtable:=aktparasymtable;
  3634. oldlocalsymtable:=aktlocalsymtable;
  3635. aktparasymtable:=parast;
  3636. aktlocalsymtable:=localst;
  3637. { write address of this symbol }
  3638. d.build(self);
  3639. ppufile.putderef(d);
  3640. { write refs }
  3641. if assigned(lastwritten) then
  3642. ref:=lastwritten
  3643. else
  3644. ref:=defref;
  3645. while assigned(ref) do
  3646. begin
  3647. if ref.moduleindex=current_module.unit_index then
  3648. begin
  3649. ppufile.putposinfo(ref.posinfo);
  3650. ref.is_written:=true;
  3651. if move_last then
  3652. lastwritten:=ref;
  3653. end
  3654. else if not ref.is_written then
  3655. move_last:=false
  3656. else if move_last then
  3657. lastwritten:=ref;
  3658. ref:=ref.nextref;
  3659. end;
  3660. ppufile.writeentry(ibdefref);
  3661. write_references:=true;
  3662. {$ifdef supportbrowser}
  3663. if ((current_module.flags and uf_local_browser)<>0) and
  3664. assigned(localst) and
  3665. locals then
  3666. begin
  3667. pdo:=_class;
  3668. if (owner.symtabletype<>localsymtable) then
  3669. while assigned(pdo) do
  3670. begin
  3671. if pdo.symtable<>aktrecordsymtable then
  3672. begin
  3673. pdo.symtable.moduleid:=local_symtable_index;
  3674. inc(local_symtable_index);
  3675. end;
  3676. pdo:=pdo.childof;
  3677. end;
  3678. parast.moduleid:=local_symtable_index;
  3679. inc(local_symtable_index);
  3680. localst.moduleid:=local_symtable_index;
  3681. inc(local_symtable_index);
  3682. tstoredsymtable(parast).write_references(ppufile,locals);
  3683. tstoredsymtable(localst).write_references(ppufile,locals);
  3684. { decrement for }
  3685. local_symtable_index:=local_symtable_index-2;
  3686. pdo:=_class;
  3687. if (owner.symtabletype<>localsymtable) then
  3688. while assigned(pdo) do
  3689. begin
  3690. if pdo.symtable<>aktrecordsymtable then
  3691. dec(local_symtable_index);
  3692. pdo:=pdo.childof;
  3693. end;
  3694. end;
  3695. {$endif supportbrowser}
  3696. aktparasymtable:=oldparasymtable;
  3697. aktlocalsymtable:=oldlocalsymtable;
  3698. end;
  3699. {$ifdef GDB}
  3700. function tprocdef.numberstring : string;
  3701. begin
  3702. { procdefs are always available }
  3703. stab_state:=stab_state_written;
  3704. result:=inherited numberstring;
  3705. end;
  3706. function tprocdef.stabstring: pchar;
  3707. Var
  3708. RType : Char;
  3709. Obj,Info : String;
  3710. stabsstr : string;
  3711. p : pchar;
  3712. begin
  3713. obj := procsym.name;
  3714. info := '';
  3715. if tprocsym(procsym).is_global then
  3716. RType := 'F'
  3717. else
  3718. RType := 'f';
  3719. if assigned(owner) then
  3720. begin
  3721. if (owner.symtabletype = objectsymtable) then
  3722. obj := owner.name^+'__'+procsym.name;
  3723. if not(cs_gdb_valgrind in aktglobalswitches) and
  3724. (owner.symtabletype=localsymtable) and
  3725. assigned(owner.defowner) and
  3726. assigned(tprocdef(owner.defowner).procsym) then
  3727. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3728. end;
  3729. stabsstr:=mangledname;
  3730. getmem(p,length(stabsstr)+255);
  3731. strpcopy(p,'"'+obj+':'+RType
  3732. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3733. +',0,'+
  3734. tostr(fileinfo.line)
  3735. +',');
  3736. strpcopy(strend(p),stabsstr);
  3737. stabstring:=strnew(p);
  3738. freemem(p,length(stabsstr)+255);
  3739. end;
  3740. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3741. begin
  3742. { released procdef? }
  3743. if not assigned(parast) then
  3744. exit;
  3745. if (proccalloption=pocall_internproc) then
  3746. exit;
  3747. { be sure to have a number assigned for this def }
  3748. numberstring;
  3749. { write stabs }
  3750. stab_state:=stab_state_writing;
  3751. asmList.concat(Tai_stabs.Create(stabstring));
  3752. if not(po_external in procoptions) then
  3753. begin
  3754. tparasymtable(parast).concatstabto(asmlist);
  3755. { local type defs and vars should not be written
  3756. inside the main proc stab }
  3757. if assigned(localst) and
  3758. (localst.symtabletype=localsymtable) then
  3759. tlocalsymtable(localst).concatstabto(asmlist);
  3760. end;
  3761. stab_state:=stab_state_written;
  3762. end;
  3763. {$endif GDB}
  3764. procedure tprocdef.buildderef;
  3765. var
  3766. oldparasymtable,
  3767. oldlocalsymtable : tsymtable;
  3768. begin
  3769. oldparasymtable:=aktparasymtable;
  3770. oldlocalsymtable:=aktlocalsymtable;
  3771. aktparasymtable:=parast;
  3772. aktlocalsymtable:=localst;
  3773. inherited buildderef;
  3774. _classderef.build(_class);
  3775. { procsym that originaly defined this definition, should be in the
  3776. same symtable }
  3777. procsymderef.build(procsym);
  3778. {$ifdef powerpc}
  3779. { library symbol for AmigaOS/MorphOS }
  3780. libsymderef.build(libsym);
  3781. {$endif powerpc}
  3782. aktparasymtable:=oldparasymtable;
  3783. aktlocalsymtable:=oldlocalsymtable;
  3784. end;
  3785. procedure tprocdef.buildderefimpl;
  3786. var
  3787. oldparasymtable,
  3788. oldlocalsymtable : tsymtable;
  3789. begin
  3790. { released procdef? }
  3791. if not assigned(parast) then
  3792. exit;
  3793. oldparasymtable:=aktparasymtable;
  3794. oldlocalsymtable:=aktlocalsymtable;
  3795. aktparasymtable:=parast;
  3796. aktlocalsymtable:=localst;
  3797. inherited buildderefimpl;
  3798. { Locals }
  3799. if assigned(localst) and
  3800. ((po_has_inlininginfo in procoptions) or
  3801. ((current_module.flags and uf_local_browser)<>0)) then
  3802. begin
  3803. tlocalsymtable(localst).buildderef;
  3804. tlocalsymtable(localst).buildderefimpl;
  3805. end;
  3806. { inline tree }
  3807. if (po_has_inlininginfo in procoptions) then
  3808. begin
  3809. funcretsymderef.build(funcretsym);
  3810. inlininginfo^.code.buildderefimpl;
  3811. end;
  3812. aktparasymtable:=oldparasymtable;
  3813. aktlocalsymtable:=oldlocalsymtable;
  3814. end;
  3815. procedure tprocdef.deref;
  3816. var
  3817. oldparasymtable,
  3818. oldlocalsymtable : tsymtable;
  3819. begin
  3820. { released procdef? }
  3821. if not assigned(parast) then
  3822. exit;
  3823. oldparasymtable:=aktparasymtable;
  3824. oldlocalsymtable:=aktlocalsymtable;
  3825. aktparasymtable:=parast;
  3826. aktlocalsymtable:=localst;
  3827. inherited deref;
  3828. _class:=tobjectdef(_classderef.resolve);
  3829. { procsym that originaly defined this definition, should be in the
  3830. same symtable }
  3831. procsym:=tprocsym(procsymderef.resolve);
  3832. {$ifdef powerpc}
  3833. { library symbol for AmigaOS/MorphOS }
  3834. libsym:=tsym(libsymderef.resolve);
  3835. {$endif powerpc}
  3836. aktparasymtable:=oldparasymtable;
  3837. aktlocalsymtable:=oldlocalsymtable;
  3838. end;
  3839. procedure tprocdef.derefimpl;
  3840. var
  3841. oldparasymtable,
  3842. oldlocalsymtable : tsymtable;
  3843. begin
  3844. oldparasymtable:=aktparasymtable;
  3845. oldlocalsymtable:=aktlocalsymtable;
  3846. aktparasymtable:=parast;
  3847. aktlocalsymtable:=localst;
  3848. { Enable has_inlininginfo when the inlininginfo
  3849. structure is available. The has_inlininginfo was disabled
  3850. after the load, since the data was invalid }
  3851. if assigned(inlininginfo) then
  3852. include(procoptions,po_has_inlininginfo);
  3853. { Locals }
  3854. if assigned(localst) then
  3855. begin
  3856. tlocalsymtable(localst).deref;
  3857. tlocalsymtable(localst).derefimpl;
  3858. end;
  3859. { Inline }
  3860. if (po_has_inlininginfo in procoptions) then
  3861. begin
  3862. inlininginfo^.code.derefimpl;
  3863. { funcretsym, this is always located in the localst }
  3864. funcretsym:=tsym(funcretsymderef.resolve);
  3865. end
  3866. else
  3867. begin
  3868. { safety }
  3869. funcretsym:=nil;
  3870. end;
  3871. aktparasymtable:=oldparasymtable;
  3872. aktlocalsymtable:=oldlocalsymtable;
  3873. end;
  3874. function tprocdef.gettypename : string;
  3875. begin
  3876. gettypename := FullProcName(false);
  3877. end;
  3878. function tprocdef.mangledname : string;
  3879. var
  3880. hp : TParavarsym;
  3881. hs : string;
  3882. crc : dword;
  3883. newlen,
  3884. oldlen,
  3885. i : integer;
  3886. begin
  3887. if assigned(_mangledname) then
  3888. begin
  3889. {$ifdef compress}
  3890. mangledname:=minilzw_decode(_mangledname^);
  3891. {$else}
  3892. mangledname:=_mangledname^;
  3893. {$endif}
  3894. exit;
  3895. end;
  3896. { we need to use the symtable where the procsym is inserted,
  3897. because that is visible to the world }
  3898. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3899. oldlen:=length(mangledname);
  3900. { add parameter types }
  3901. for i:=0 to paras.count-1 do
  3902. begin
  3903. hp:=tparavarsym(paras[i]);
  3904. if not(vo_is_hidden_para in hp.varoptions) then
  3905. mangledname:=mangledname+'$'+hp.vartype.def.mangledparaname;
  3906. end;
  3907. { add resulttype, add $$ as separator to make it unique from a
  3908. parameter separator }
  3909. if not is_void(rettype.def) then
  3910. mangledname:=mangledname+'$$'+rettype.def.mangledparaname;
  3911. newlen:=length(mangledname);
  3912. { Replace with CRC if the parameter line is very long }
  3913. if (newlen-oldlen>12) and
  3914. ((newlen>128) or (newlen-oldlen>64)) then
  3915. begin
  3916. crc:=$ffffffff;
  3917. for i:=0 to paras.count-1 do
  3918. begin
  3919. hp:=tparavarsym(paras[i]);
  3920. if not(vo_is_hidden_para in hp.varoptions) then
  3921. begin
  3922. hs:=hp.vartype.def.mangledparaname;
  3923. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3924. end;
  3925. end;
  3926. hs:=hp.vartype.def.mangledparaname;
  3927. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3928. mangledname:=Copy(mangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  3929. end;
  3930. {$ifdef compress}
  3931. _mangledname:=stringdup(minilzw_encode(mangledname));
  3932. {$else}
  3933. _mangledname:=stringdup(mangledname);
  3934. {$endif}
  3935. end;
  3936. function tprocdef.cplusplusmangledname : string;
  3937. function getcppparaname(p : tdef) : string;
  3938. const
  3939. ordtype2str : array[tbasetype] of string[2] = (
  3940. '',
  3941. 'Uc','Us','Ui','Us',
  3942. 'Sc','s','i','x',
  3943. 'b','b','b',
  3944. 'c','w','x');
  3945. var
  3946. s : string;
  3947. begin
  3948. case p.deftype of
  3949. orddef:
  3950. s:=ordtype2str[torddef(p).typ];
  3951. pointerdef:
  3952. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3953. else
  3954. internalerror(2103001);
  3955. end;
  3956. getcppparaname:=s;
  3957. end;
  3958. var
  3959. s,s2 : string;
  3960. hp : TParavarsym;
  3961. i : integer;
  3962. begin
  3963. s := procsym.realname;
  3964. if procsym.owner.symtabletype=objectsymtable then
  3965. begin
  3966. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3967. case proctypeoption of
  3968. potype_destructor:
  3969. s:='_$_'+tostr(length(s2))+s2;
  3970. potype_constructor:
  3971. s:='___'+tostr(length(s2))+s2;
  3972. else
  3973. s:='_'+s+'__'+tostr(length(s2))+s2;
  3974. end;
  3975. end
  3976. else s:=s+'__';
  3977. s:=s+'F';
  3978. { concat modifiers }
  3979. { !!!!! }
  3980. { now we handle the parameters }
  3981. if maxparacount>0 then
  3982. begin
  3983. for i:=0 to paras.count-1 do
  3984. begin
  3985. hp:=tparavarsym(paras[i]);
  3986. s2:=getcppparaname(hp.vartype.def);
  3987. if hp.varspez in [vs_var,vs_out] then
  3988. s2:='R'+s2;
  3989. s:=s+s2;
  3990. end;
  3991. end
  3992. else
  3993. s:=s+'v';
  3994. cplusplusmangledname:=s;
  3995. end;
  3996. procedure tprocdef.setmangledname(const s : string);
  3997. begin
  3998. { This is not allowed anymore, the forward declaration
  3999. already needs to create the correct mangledname, no changes
  4000. afterwards are allowed (PFV) }
  4001. if assigned(_mangledname) then
  4002. internalerror(200411171);
  4003. {$ifdef compress}
  4004. _mangledname:=stringdup(minilzw_encode(s));
  4005. {$else}
  4006. _mangledname:=stringdup(s);
  4007. {$endif}
  4008. include(procoptions,po_has_mangledname);
  4009. end;
  4010. {***************************************************************************
  4011. TPROCVARDEF
  4012. ***************************************************************************}
  4013. constructor tprocvardef.create(level:byte);
  4014. begin
  4015. inherited create(level);
  4016. deftype:=procvardef;
  4017. end;
  4018. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  4019. begin
  4020. inherited ppuload(ppufile);
  4021. deftype:=procvardef;
  4022. { load para symtable }
  4023. parast:=tparasymtable.create(unknown_level);
  4024. tparasymtable(parast).ppuload(ppufile);
  4025. parast.defowner:=self;
  4026. end;
  4027. function tprocvardef.getcopy : tstoreddef;
  4028. begin
  4029. result:=self;
  4030. (*
  4031. { saves a definition to the return type }
  4032. rettype : ttype;
  4033. parast : tsymtable;
  4034. paras : tparalist;
  4035. proctypeoption : tproctypeoption;
  4036. proccalloption : tproccalloption;
  4037. procoptions : tprocoptions;
  4038. requiredargarea : aint;
  4039. { number of user visibile parameters }
  4040. maxparacount,
  4041. minparacount : byte;
  4042. {$ifdef i386}
  4043. fpu_used : longint; { how many stack fpu must be empty }
  4044. {$endif i386}
  4045. funcretloc : array[tcallercallee] of TLocation;
  4046. has_paraloc_info : boolean; { paraloc info is available }
  4047. tprocvardef = class(tabstractprocdef)
  4048. constructor create(level:byte);
  4049. constructor ppuload(ppufile:tcompilerppufile);
  4050. function getcopy : tstoreddef;override;
  4051. *)
  4052. end;
  4053. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  4054. var
  4055. oldparasymtable,
  4056. oldlocalsymtable : tsymtable;
  4057. begin
  4058. oldparasymtable:=aktparasymtable;
  4059. oldlocalsymtable:=aktlocalsymtable;
  4060. aktparasymtable:=parast;
  4061. aktlocalsymtable:=nil;
  4062. { here we cannot get a real good value so just give something }
  4063. { plausible (PM) }
  4064. { a more secure way would be
  4065. to allways store in a temp }
  4066. {$ifdef i386}
  4067. if is_fpu(rettype.def) then
  4068. fpu_used:={2}maxfpuregs
  4069. else
  4070. fpu_used:=0;
  4071. {$endif i386}
  4072. inherited ppuwrite(ppufile);
  4073. { Write this entry }
  4074. ppufile.writeentry(ibprocvardef);
  4075. { Save the para symtable, this is taken from the interface }
  4076. tparasymtable(parast).ppuwrite(ppufile);
  4077. aktparasymtable:=oldparasymtable;
  4078. aktlocalsymtable:=oldlocalsymtable;
  4079. end;
  4080. procedure tprocvardef.buildderef;
  4081. var
  4082. oldparasymtable,
  4083. oldlocalsymtable : tsymtable;
  4084. begin
  4085. oldparasymtable:=aktparasymtable;
  4086. oldlocalsymtable:=aktlocalsymtable;
  4087. aktparasymtable:=parast;
  4088. aktlocalsymtable:=nil;
  4089. inherited buildderef;
  4090. aktparasymtable:=oldparasymtable;
  4091. aktlocalsymtable:=oldlocalsymtable;
  4092. end;
  4093. procedure tprocvardef.deref;
  4094. var
  4095. oldparasymtable,
  4096. oldlocalsymtable : tsymtable;
  4097. begin
  4098. oldparasymtable:=aktparasymtable;
  4099. oldlocalsymtable:=aktlocalsymtable;
  4100. aktparasymtable:=parast;
  4101. aktlocalsymtable:=nil;
  4102. inherited deref;
  4103. aktparasymtable:=oldparasymtable;
  4104. aktlocalsymtable:=oldlocalsymtable;
  4105. end;
  4106. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  4107. begin
  4108. case t of
  4109. gs_para :
  4110. getsymtable:=parast;
  4111. else
  4112. getsymtable:=nil;
  4113. end;
  4114. end;
  4115. function tprocvardef.size : aint;
  4116. begin
  4117. if (po_methodpointer in procoptions) and
  4118. not(po_addressonly in procoptions) then
  4119. size:=2*sizeof(aint)
  4120. else
  4121. size:=sizeof(aint);
  4122. end;
  4123. function tprocvardef.is_methodpointer:boolean;
  4124. begin
  4125. result:=(po_methodpointer in procoptions);
  4126. end;
  4127. function tprocvardef.is_addressonly:boolean;
  4128. begin
  4129. result:=not(po_methodpointer in procoptions) or
  4130. (po_addressonly in procoptions);
  4131. end;
  4132. function tprocvardef.getmangledparaname:string;
  4133. begin
  4134. result:='procvar';
  4135. end;
  4136. {$ifdef GDB}
  4137. function tprocvardef.stabstring : pchar;
  4138. var
  4139. nss : pchar;
  4140. { i : longint; }
  4141. begin
  4142. { i := maxparacount; }
  4143. getmem(nss,1024);
  4144. { it is not a function but a function pointer !! (PM) }
  4145. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)});
  4146. { this confuses gdb !!
  4147. we should use 'F' instead of 'f' but
  4148. as we use c++ language mode
  4149. it does not like that either
  4150. Please do not remove this part
  4151. might be used once
  4152. gdb for pascal is ready PM }
  4153. {$ifdef disabled}
  4154. param := para1;
  4155. i := 0;
  4156. while assigned(param) do
  4157. begin
  4158. inc(i);
  4159. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  4160. {Here we have lost the parameter names !!}
  4161. pst := strpnew('p'+tostr(i)+':'+param^.vartype.def.numberstring+','+vartyp+';');
  4162. strcat(nss,pst);
  4163. strdispose(pst);
  4164. param := param^.next;
  4165. end;
  4166. {$endif}
  4167. {strpcopy(strend(nss),';');}
  4168. stabstring := strnew(nss);
  4169. freemem(nss,1024);
  4170. end;
  4171. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  4172. begin
  4173. if (stab_state in [stab_state_writing,stab_state_written]) then
  4174. exit;
  4175. tstoreddef(rettype.def).concatstabto(asmlist);
  4176. inherited concatstabto(asmlist);
  4177. end;
  4178. {$endif GDB}
  4179. procedure tprocvardef.write_rtti_data(rt:trttitype);
  4180. procedure write_para(parasym:tparavarsym);
  4181. var
  4182. paraspec : byte;
  4183. begin
  4184. { only store user visible parameters }
  4185. if not(vo_is_hidden_para in parasym.varoptions) then
  4186. begin
  4187. case parasym.varspez of
  4188. vs_value: paraspec := 0;
  4189. vs_const: paraspec := pfConst;
  4190. vs_var : paraspec := pfVar;
  4191. vs_out : paraspec := pfOut;
  4192. end;
  4193. { write flags for current parameter }
  4194. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4195. { write name of current parameter }
  4196. rttiList.concat(Tai_const.Create_8bit(length(parasym.realname)));
  4197. rttiList.concat(Tai_string.Create(parasym.realname));
  4198. { write name of type of current parameter }
  4199. tstoreddef(parasym.vartype.def).write_rtti_name;
  4200. end;
  4201. end;
  4202. var
  4203. methodkind : byte;
  4204. i : integer;
  4205. begin
  4206. if po_methodpointer in procoptions then
  4207. begin
  4208. { write method id and name }
  4209. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  4210. write_rtti_name;
  4211. {$ifdef cpurequiresproperalignment}
  4212. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4213. {$endif cpurequiresproperalignment}
  4214. { write kind of method (can only be function or procedure)}
  4215. if rettype.def = voidtype.def then
  4216. methodkind := mkProcedure
  4217. else
  4218. methodkind := mkFunction;
  4219. rttiList.concat(Tai_const.Create_8bit(methodkind));
  4220. { get # of parameters }
  4221. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  4222. { write parameter info. The parameters must be written in reverse order
  4223. if this method uses right to left parameter pushing! }
  4224. if proccalloption in pushleftright_pocalls then
  4225. begin
  4226. for i:=0 to paras.count-1 do
  4227. write_para(tparavarsym(paras[i]));
  4228. end
  4229. else
  4230. begin
  4231. for i:=paras.count-1 downto 0 do
  4232. write_para(tparavarsym(paras[i]));
  4233. end;
  4234. { write name of result type }
  4235. tstoreddef(rettype.def).write_rtti_name;
  4236. end;
  4237. end;
  4238. function tprocvardef.is_publishable : boolean;
  4239. begin
  4240. is_publishable:=(po_methodpointer in procoptions);
  4241. end;
  4242. function tprocvardef.gettypename : string;
  4243. var
  4244. s: string;
  4245. showhidden : boolean;
  4246. begin
  4247. {$ifdef EXTDEBUG}
  4248. showhidden:=true;
  4249. {$else EXTDEBUG}
  4250. showhidden:=false;
  4251. {$endif EXTDEBUG}
  4252. s:='<';
  4253. if po_classmethod in procoptions then
  4254. s := s+'class method type of'
  4255. else
  4256. if po_addressonly in procoptions then
  4257. s := s+'address of'
  4258. else
  4259. s := s+'procedure variable type of';
  4260. if po_local in procoptions then
  4261. s := s+' local';
  4262. if assigned(rettype.def) and
  4263. (rettype.def<>voidtype.def) then
  4264. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4265. else
  4266. s:=s+' procedure'+typename_paras(showhidden);
  4267. if po_methodpointer in procoptions then
  4268. s := s+' of object';
  4269. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4270. end;
  4271. {***************************************************************************
  4272. TOBJECTDEF
  4273. ***************************************************************************}
  4274. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4275. begin
  4276. inherited create;
  4277. objecttype:=ot;
  4278. deftype:=objectdef;
  4279. objectoptions:=[];
  4280. childof:=nil;
  4281. symtable:=tobjectsymtable.create(n,aktpackrecords);
  4282. { create space for vmt !! }
  4283. vmt_offset:=0;
  4284. symtable.defowner:=self;
  4285. lastvtableindex:=0;
  4286. set_parent(c);
  4287. objname:=stringdup(upper(n));
  4288. objrealname:=stringdup(n);
  4289. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4290. prepareguid;
  4291. { setup implemented interfaces }
  4292. if objecttype in [odt_class,odt_interfacecorba] then
  4293. implementedinterfaces:=timplementedinterfaces.create
  4294. else
  4295. implementedinterfaces:=nil;
  4296. {$ifdef GDB}
  4297. writing_class_record_stab:=false;
  4298. {$endif GDB}
  4299. end;
  4300. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4301. var
  4302. i,implintfcount: longint;
  4303. d : tderef;
  4304. begin
  4305. inherited ppuloaddef(ppufile);
  4306. deftype:=objectdef;
  4307. objecttype:=tobjectdeftype(ppufile.getbyte);
  4308. objrealname:=stringdup(ppufile.getstring);
  4309. objname:=stringdup(upper(objrealname^));
  4310. symtable:=tobjectsymtable.create(objrealname^,0);
  4311. tobjectsymtable(symtable).datasize:=ppufile.getaint;
  4312. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  4313. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  4314. vmt_offset:=ppufile.getlongint;
  4315. ppufile.getderef(childofderef);
  4316. ppufile.getsmallset(objectoptions);
  4317. { load guid }
  4318. iidstr:=nil;
  4319. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4320. begin
  4321. new(iidguid);
  4322. ppufile.getguid(iidguid^);
  4323. iidstr:=stringdup(ppufile.getstring);
  4324. lastvtableindex:=ppufile.getlongint;
  4325. end;
  4326. { load implemented interfaces }
  4327. if objecttype in [odt_class,odt_interfacecorba] then
  4328. begin
  4329. implementedinterfaces:=timplementedinterfaces.create;
  4330. implintfcount:=ppufile.getlongint;
  4331. for i:=1 to implintfcount do
  4332. begin
  4333. ppufile.getderef(d);
  4334. implementedinterfaces.addintf_deref(d,ppufile.getlongint);
  4335. end;
  4336. end
  4337. else
  4338. implementedinterfaces:=nil;
  4339. tobjectsymtable(symtable).ppuload(ppufile);
  4340. symtable.defowner:=self;
  4341. { handles the predefined class tobject }
  4342. { the last TOBJECT which is loaded gets }
  4343. { it ! }
  4344. if (childof=nil) and
  4345. (objecttype=odt_class) and
  4346. (objname^='TOBJECT') then
  4347. class_tobject:=self;
  4348. if (childof=nil) and
  4349. (objecttype=odt_interfacecom) and
  4350. (objname^='IUNKNOWN') then
  4351. interface_iunknown:=self;
  4352. {$ifdef GDB}
  4353. writing_class_record_stab:=false;
  4354. {$endif GDB}
  4355. end;
  4356. destructor tobjectdef.destroy;
  4357. begin
  4358. if assigned(symtable) then
  4359. symtable.free;
  4360. stringdispose(objname);
  4361. stringdispose(objrealname);
  4362. if assigned(iidstr) then
  4363. stringdispose(iidstr);
  4364. if assigned(implementedinterfaces) then
  4365. implementedinterfaces.free;
  4366. if assigned(iidguid) then
  4367. dispose(iidguid);
  4368. inherited destroy;
  4369. end;
  4370. function tobjectdef.getcopy : tstoreddef;
  4371. begin
  4372. result:=inherited getcopy;
  4373. (*
  4374. result:=tobjectdef.create(objecttype,objname^,childof);
  4375. childofderef : tderef;
  4376. objname,
  4377. objrealname : pstring;
  4378. objectoptions : tobjectoptions;
  4379. { to be able to have a variable vmt position }
  4380. { and no vmt field for objects without virtuals }
  4381. vmt_offset : longint;
  4382. {$ifdef GDB}
  4383. writing_class_record_stab : boolean;
  4384. {$endif GDB}
  4385. objecttype : tobjectdeftype;
  4386. iidguid: pguid;
  4387. iidstr: pstring;
  4388. lastvtableindex: longint;
  4389. { store implemented interfaces defs and name mappings }
  4390. implementedinterfaces: timplementedinterfaces;
  4391. *)
  4392. end;
  4393. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4394. var
  4395. implintfcount : longint;
  4396. i : longint;
  4397. begin
  4398. inherited ppuwritedef(ppufile);
  4399. ppufile.putbyte(byte(objecttype));
  4400. ppufile.putstring(objrealname^);
  4401. ppufile.putaint(tobjectsymtable(symtable).datasize);
  4402. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  4403. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  4404. ppufile.putlongint(vmt_offset);
  4405. ppufile.putderef(childofderef);
  4406. ppufile.putsmallset(objectoptions);
  4407. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4408. begin
  4409. ppufile.putguid(iidguid^);
  4410. ppufile.putstring(iidstr^);
  4411. ppufile.putlongint(lastvtableindex);
  4412. end;
  4413. if objecttype in [odt_class,odt_interfacecorba] then
  4414. begin
  4415. implintfcount:=implementedinterfaces.count;
  4416. ppufile.putlongint(implintfcount);
  4417. for i:=1 to implintfcount do
  4418. begin
  4419. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4420. ppufile.putlongint(implementedinterfaces.ioffsets(i));
  4421. end;
  4422. end;
  4423. ppufile.writeentry(ibobjectdef);
  4424. tobjectsymtable(symtable).ppuwrite(ppufile);
  4425. end;
  4426. function tobjectdef.gettypename:string;
  4427. begin
  4428. gettypename:=typename;
  4429. end;
  4430. procedure tobjectdef.buildderef;
  4431. var
  4432. oldrecsyms : tsymtable;
  4433. begin
  4434. inherited buildderef;
  4435. childofderef.build(childof);
  4436. oldrecsyms:=aktrecordsymtable;
  4437. aktrecordsymtable:=symtable;
  4438. tstoredsymtable(symtable).buildderef;
  4439. aktrecordsymtable:=oldrecsyms;
  4440. if objecttype in [odt_class,odt_interfacecorba] then
  4441. implementedinterfaces.buildderef;
  4442. end;
  4443. procedure tobjectdef.deref;
  4444. var
  4445. oldrecsyms : tsymtable;
  4446. begin
  4447. inherited deref;
  4448. childof:=tobjectdef(childofderef.resolve);
  4449. oldrecsyms:=aktrecordsymtable;
  4450. aktrecordsymtable:=symtable;
  4451. tstoredsymtable(symtable).deref;
  4452. aktrecordsymtable:=oldrecsyms;
  4453. if objecttype in [odt_class,odt_interfacecorba] then
  4454. implementedinterfaces.deref;
  4455. end;
  4456. function tobjectdef.getparentdef:tdef;
  4457. begin
  4458. result:=childof;
  4459. end;
  4460. procedure tobjectdef.prepareguid;
  4461. begin
  4462. { set up guid }
  4463. if not assigned(iidguid) then
  4464. begin
  4465. new(iidguid);
  4466. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4467. end;
  4468. { setup iidstring }
  4469. if not assigned(iidstr) then
  4470. iidstr:=stringdup(''); { default is empty string }
  4471. end;
  4472. procedure tobjectdef.set_parent( c : tobjectdef);
  4473. begin
  4474. { nothing to do if the parent was not forward !}
  4475. if assigned(childof) then
  4476. exit;
  4477. childof:=c;
  4478. { some options are inherited !! }
  4479. if assigned(c) then
  4480. begin
  4481. { only important for classes }
  4482. lastvtableindex:=c.lastvtableindex;
  4483. objectoptions:=objectoptions+(c.objectoptions*
  4484. [oo_has_virtual,oo_has_private,oo_has_protected,
  4485. oo_has_constructor,oo_has_destructor]);
  4486. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4487. begin
  4488. { add the data of the anchestor class }
  4489. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4490. if (oo_has_vmt in objectoptions) and
  4491. (oo_has_vmt in c.objectoptions) then
  4492. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  4493. { if parent has a vmt field then
  4494. the offset is the same for the child PM }
  4495. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4496. begin
  4497. vmt_offset:=c.vmt_offset;
  4498. include(objectoptions,oo_has_vmt);
  4499. end;
  4500. end;
  4501. end;
  4502. end;
  4503. procedure tobjectdef.insertvmt;
  4504. begin
  4505. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4506. exit;
  4507. if (oo_has_vmt in objectoptions) then
  4508. internalerror(12345)
  4509. else
  4510. begin
  4511. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4512. tobjectsymtable(symtable).fieldalignment);
  4513. {$ifdef cpurequiresproperalignment}
  4514. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,sizeof(aint));
  4515. {$endif cpurequiresproperalignment}
  4516. vmt_offset:=tobjectsymtable(symtable).datasize;
  4517. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  4518. include(objectoptions,oo_has_vmt);
  4519. end;
  4520. end;
  4521. procedure tobjectdef.check_forwards;
  4522. begin
  4523. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4524. tstoredsymtable(symtable).check_forwards;
  4525. if (oo_is_forward in objectoptions) then
  4526. begin
  4527. { ok, in future, the forward can be resolved }
  4528. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4529. exclude(objectoptions,oo_is_forward);
  4530. end;
  4531. end;
  4532. { true, if self inherits from d (or if they are equal) }
  4533. function tobjectdef.is_related(d : tdef) : boolean;
  4534. var
  4535. hp : tobjectdef;
  4536. begin
  4537. hp:=self;
  4538. while assigned(hp) do
  4539. begin
  4540. if hp=d then
  4541. begin
  4542. is_related:=true;
  4543. exit;
  4544. end;
  4545. hp:=hp.childof;
  4546. end;
  4547. is_related:=false;
  4548. end;
  4549. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4550. var
  4551. p : pprocdeflist;
  4552. begin
  4553. { if we found already a destructor, then we exit }
  4554. if assigned(sd) then
  4555. exit;
  4556. if tsym(sym).typ=procsym then
  4557. begin
  4558. p:=tprocsym(sym).defs;
  4559. while assigned(p) do
  4560. begin
  4561. if p^.def.proctypeoption=potype_destructor then
  4562. begin
  4563. sd:=p^.def;
  4564. exit;
  4565. end;
  4566. p:=p^.next;
  4567. end;
  4568. end;
  4569. end;*)
  4570. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4571. begin
  4572. { if we found already a destructor, then we exit }
  4573. if (ppointer(sd)^=nil) and
  4574. (Tsym(sym).typ=procsym) then
  4575. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4576. end;
  4577. function tobjectdef.searchdestructor : tprocdef;
  4578. var
  4579. o : tobjectdef;
  4580. sd : tprocdef;
  4581. begin
  4582. searchdestructor:=nil;
  4583. o:=self;
  4584. sd:=nil;
  4585. while assigned(o) do
  4586. begin
  4587. o.symtable.foreach_static(@_searchdestructor,@sd);
  4588. if assigned(sd) then
  4589. begin
  4590. searchdestructor:=sd;
  4591. exit;
  4592. end;
  4593. o:=o.childof;
  4594. end;
  4595. end;
  4596. function tobjectdef.size : aint;
  4597. begin
  4598. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4599. result:=sizeof(aint)
  4600. else
  4601. result:=tobjectsymtable(symtable).datasize;
  4602. end;
  4603. function tobjectdef.alignment:longint;
  4604. begin
  4605. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4606. alignment:=sizeof(aint)
  4607. else
  4608. alignment:=tobjectsymtable(symtable).recordalignment;
  4609. end;
  4610. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4611. begin
  4612. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4613. case objecttype of
  4614. odt_class:
  4615. { the +2*sizeof(Aint) is size and -size }
  4616. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  4617. odt_interfacecom,odt_interfacecorba:
  4618. vmtmethodoffset:=index*sizeof(aint);
  4619. else
  4620. {$ifdef WITHDMT}
  4621. vmtmethodoffset:=(index+4)*sizeof(aint);
  4622. {$else WITHDMT}
  4623. vmtmethodoffset:=(index+3)*sizeof(aint);
  4624. {$endif WITHDMT}
  4625. end;
  4626. end;
  4627. function tobjectdef.vmt_mangledname : string;
  4628. begin
  4629. if not(oo_has_vmt in objectoptions) then
  4630. Message1(parser_n_object_has_no_vmt,objrealname^);
  4631. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4632. end;
  4633. function tobjectdef.rtti_name : string;
  4634. begin
  4635. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4636. end;
  4637. {$ifdef GDB}
  4638. procedure tobjectdef.proc_addname(p :tnamedindexitem;arg:pointer);
  4639. var virtualind,argnames : string;
  4640. newrec : pchar;
  4641. pd : tprocdef;
  4642. lindex : longint;
  4643. arglength : byte;
  4644. sp : char;
  4645. state:^Trecord_stabgen_state;
  4646. olds:integer;
  4647. i : integer;
  4648. parasym : tparavarsym;
  4649. begin
  4650. state:=arg;
  4651. if tsym(p).typ = procsym then
  4652. begin
  4653. pd := tprocsym(p).first_procdef;
  4654. if (po_virtualmethod in pd.procoptions) then
  4655. begin
  4656. lindex := pd.extnumber;
  4657. {doesnt seem to be necessary
  4658. lindex := lindex or $80000000;}
  4659. virtualind := '*'+tostr(lindex)+';'+pd._class.classnumberstring+';'
  4660. end
  4661. else
  4662. virtualind := '.';
  4663. { used by gdbpas to recognize constructor and destructors }
  4664. if (pd.proctypeoption=potype_constructor) then
  4665. argnames:='__ct__'
  4666. else if (pd.proctypeoption=potype_destructor) then
  4667. argnames:='__dt__'
  4668. else
  4669. argnames := '';
  4670. { arguments are not listed here }
  4671. {we don't need another definition}
  4672. for i:=0 to pd.paras.count-1 do
  4673. begin
  4674. parasym:=tparavarsym(pd.paras[i]);
  4675. if Parasym.vartype.def.deftype = formaldef then
  4676. begin
  4677. case Parasym.varspez of
  4678. vs_var :
  4679. argnames := argnames+'3var';
  4680. vs_const :
  4681. argnames:=argnames+'5const';
  4682. vs_out :
  4683. argnames:=argnames+'3out';
  4684. end;
  4685. end
  4686. else
  4687. begin
  4688. { if the arg definition is like (v: ^byte;..
  4689. there is no sym attached to data !!! }
  4690. if assigned(Parasym.vartype.def.typesym) then
  4691. begin
  4692. arglength := length(Parasym.vartype.def.typesym.name);
  4693. argnames := argnames + tostr(arglength)+Parasym.vartype.def.typesym.name;
  4694. end
  4695. else
  4696. argnames:=argnames+'11unnamedtype';
  4697. end;
  4698. end;
  4699. { here 2A must be changed for private and protected }
  4700. { 0 is private 1 protected and 2 public }
  4701. if (sp_private in tsym(p).symoptions) then
  4702. sp:='0'
  4703. else if (sp_protected in tsym(p).symoptions) then
  4704. sp:='1'
  4705. else
  4706. sp:='2';
  4707. newrec:=stabstr_evaluate('$1::$2=##$3;:$4;$5A$6;',[p.name,pd.numberstring,
  4708. Tstoreddef(pd.rettype.def).numberstring,argnames,sp,
  4709. virtualind]);
  4710. { get spare place for a string at the end }
  4711. olds:=state^.stabsize;
  4712. inc(state^.stabsize,strlen(newrec));
  4713. if state^.stabsize>=state^.staballoc-256 then
  4714. begin
  4715. inc(state^.staballoc,memsizeinc);
  4716. reallocmem(state^.stabstring,state^.staballoc);
  4717. end;
  4718. strcopy(state^.stabstring+olds,newrec);
  4719. strdispose(newrec);
  4720. {This should be used for case !!
  4721. RecOffset := RecOffset + pd.size;}
  4722. end;
  4723. end;
  4724. procedure tobjectdef.proc_concatstabto(p :tnamedindexitem;arg:pointer);
  4725. var
  4726. pd : tprocdef;
  4727. begin
  4728. if tsym(p).typ = procsym then
  4729. begin
  4730. pd := tprocsym(p).first_procdef;
  4731. tstoreddef(pd.rettype.def).concatstabto(taasmoutput(arg));
  4732. end;
  4733. end;
  4734. function tobjectdef.stabstring : pchar;
  4735. var anc : tobjectdef;
  4736. state:Trecord_stabgen_state;
  4737. ts : string;
  4738. begin
  4739. if not (objecttype=odt_class) or writing_class_record_stab then
  4740. begin
  4741. state.staballoc:=memsizeinc;
  4742. getmem(state.stabstring,state.staballoc);
  4743. strpcopy(state.stabstring,'s'+tostr(tobjectsymtable(symtable).datasize));
  4744. if assigned(childof) then
  4745. begin
  4746. {only one ancestor not virtual, public, at base offset 0 }
  4747. { !1 , 0 2 0 , }
  4748. strpcopy(strend(state.stabstring),'!1,020,'+childof.classnumberstring+';');
  4749. end;
  4750. {virtual table to implement yet}
  4751. state.recoffset:=0;
  4752. state.stabsize:=strlen(state.stabstring);
  4753. symtable.foreach(@field_addname,@state);
  4754. if (oo_has_vmt in objectoptions) then
  4755. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4756. begin
  4757. ts:='$vf'+classnumberstring+':'+tstoreddef(vmtarraytype.def).numberstring+','+tostr(vmt_offset*8)+';';
  4758. strpcopy(state.stabstring+state.stabsize,ts);
  4759. inc(state.stabsize,length(ts));
  4760. end;
  4761. symtable.foreach(@proc_addname,@state);
  4762. if (oo_has_vmt in objectoptions) then
  4763. begin
  4764. anc := self;
  4765. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4766. anc := anc.childof;
  4767. { just in case anc = self }
  4768. ts:=';~%'+anc.classnumberstring+';';
  4769. end
  4770. else
  4771. ts:=';';
  4772. strpcopy(state.stabstring+state.stabsize,ts);
  4773. inc(state.stabsize,length(ts));
  4774. reallocmem(state.stabstring,state.stabsize+1);
  4775. stabstring:=state.stabstring;
  4776. end
  4777. else
  4778. begin
  4779. stabstring:=strpnew('*'+classnumberstring);
  4780. end;
  4781. end;
  4782. procedure tobjectdef.set_globalnb;
  4783. begin
  4784. globalnb:=PglobalTypeCount^;
  4785. inc(PglobalTypeCount^);
  4786. { classes need two type numbers, the globalnb is set to the ptr }
  4787. if objecttype=odt_class then
  4788. begin
  4789. globalnb:=PGlobalTypeCount^;
  4790. inc(PglobalTypeCount^);
  4791. end;
  4792. end;
  4793. function tobjectdef.classnumberstring : string;
  4794. begin
  4795. if objecttype=odt_class then
  4796. begin
  4797. if globalnb=0 then
  4798. numberstring;
  4799. dec(globalnb);
  4800. classnumberstring:=numberstring;
  4801. inc(globalnb);
  4802. end
  4803. else
  4804. classnumberstring:=numberstring;
  4805. end;
  4806. function tobjectdef.allstabstring : pchar;
  4807. var
  4808. stabchar : string[2];
  4809. ss,st : pchar;
  4810. sname : string;
  4811. begin
  4812. ss := stabstring;
  4813. getmem(st,strlen(ss)+512);
  4814. stabchar := 't';
  4815. if deftype in tagtypes then
  4816. stabchar := 'Tt';
  4817. if assigned(typesym) then
  4818. sname := typesym.name
  4819. else
  4820. sname := ' ';
  4821. if writing_class_record_stab then
  4822. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4823. else
  4824. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4825. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,0,0');
  4826. allstabstring := strnew(st);
  4827. freemem(st,strlen(ss)+512);
  4828. strdispose(ss);
  4829. end;
  4830. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4831. var
  4832. oldtypesym : tsym;
  4833. stab_str : pchar;
  4834. anc : tobjectdef;
  4835. begin
  4836. if (stab_state in [stab_state_writing,stab_state_written]) then
  4837. exit;
  4838. stab_state:=stab_state_writing;
  4839. tstoreddef(vmtarraytype.def).concatstabto(asmlist);
  4840. { first the parents }
  4841. anc:=self;
  4842. while assigned(anc.childof) do
  4843. begin
  4844. anc:=anc.childof;
  4845. anc.concatstabto(asmlist);
  4846. end;
  4847. symtable.foreach(@field_concatstabto,asmlist);
  4848. symtable.foreach(@proc_concatstabto,asmlist);
  4849. stab_state:=stab_state_used;
  4850. if objecttype=odt_class then
  4851. begin
  4852. { Write the record class itself }
  4853. writing_class_record_stab:=true;
  4854. inherited concatstabto(asmlist);
  4855. writing_class_record_stab:=false;
  4856. { Write the invisible pointer class }
  4857. oldtypesym:=typesym;
  4858. typesym:=nil;
  4859. stab_str := allstabstring;
  4860. asmList.concat(Tai_stabs.Create(stab_str));
  4861. typesym:=oldtypesym;
  4862. end
  4863. else
  4864. inherited concatstabto(asmlist);
  4865. end;
  4866. {$endif GDB}
  4867. function tobjectdef.needs_inittable : boolean;
  4868. begin
  4869. case objecttype of
  4870. odt_class :
  4871. needs_inittable:=false;
  4872. odt_interfacecom:
  4873. needs_inittable:=true;
  4874. odt_interfacecorba:
  4875. needs_inittable:=is_related(interface_iunknown);
  4876. odt_object:
  4877. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4878. else
  4879. internalerror(200108267);
  4880. end;
  4881. end;
  4882. function tobjectdef.members_need_inittable : boolean;
  4883. begin
  4884. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4885. end;
  4886. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4887. begin
  4888. if needs_prop_entry(tsym(sym)) and
  4889. (tsym(sym).typ<>fieldvarsym) then
  4890. inc(count);
  4891. end;
  4892. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4893. var
  4894. proctypesinfo : byte;
  4895. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4896. var
  4897. typvalue : byte;
  4898. hp : psymlistitem;
  4899. address : longint;
  4900. def : tdef;
  4901. begin
  4902. if not(assigned(proc) and assigned(proc.firstsym)) then
  4903. begin
  4904. rttiList.concat(Tai_const.create(ait_const_ptr,1));
  4905. typvalue:=3;
  4906. end
  4907. else if proc.firstsym^.sym.typ=fieldvarsym then
  4908. begin
  4909. address:=0;
  4910. hp:=proc.firstsym;
  4911. def:=nil;
  4912. while assigned(hp) do
  4913. begin
  4914. case hp^.sltype of
  4915. sl_load :
  4916. begin
  4917. def:=tfieldvarsym(hp^.sym).vartype.def;
  4918. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  4919. end;
  4920. sl_subscript :
  4921. begin
  4922. if not(assigned(def) and (def.deftype=recorddef)) then
  4923. internalerror(200402171);
  4924. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  4925. def:=tfieldvarsym(hp^.sym).vartype.def;
  4926. end;
  4927. sl_vec :
  4928. begin
  4929. if not(assigned(def) and (def.deftype=arraydef)) then
  4930. internalerror(200402172);
  4931. def:=tarraydef(def).elementtype.def;
  4932. inc(address,def.size*hp^.value);
  4933. end;
  4934. end;
  4935. hp:=hp^.next;
  4936. end;
  4937. rttiList.concat(Tai_const.create(ait_const_ptr,address));
  4938. typvalue:=0;
  4939. end
  4940. else
  4941. begin
  4942. { When there was an error then procdef is not assigned }
  4943. if not assigned(proc.procdef) then
  4944. exit;
  4945. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4946. begin
  4947. rttiList.concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4948. typvalue:=1;
  4949. end
  4950. else
  4951. begin
  4952. { virtual method, write vmt offset }
  4953. rttiList.concat(Tai_const.create(ait_const_ptr,
  4954. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4955. typvalue:=2;
  4956. end;
  4957. end;
  4958. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4959. end;
  4960. begin
  4961. if needs_prop_entry(tsym(sym)) then
  4962. case tsym(sym).typ of
  4963. fieldvarsym:
  4964. begin
  4965. {$ifdef dummy}
  4966. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4967. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4968. internalerror(1509992);
  4969. { access to implicit class property as field }
  4970. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4971. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label),AT_DATA,0));
  4972. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4973. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4974. { by default stored }
  4975. rttiList.concat(Tai_const.Create_32bit(1));
  4976. { index as well as ... }
  4977. rttiList.concat(Tai_const.Create_32bit(0));
  4978. { default value are zero }
  4979. rttiList.concat(Tai_const.Create_32bit(0));
  4980. rttiList.concat(Tai_const.Create_16bit(count));
  4981. inc(count);
  4982. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4983. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4984. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4985. {$endif dummy}
  4986. end;
  4987. propertysym:
  4988. begin
  4989. if ppo_indexed in tpropertysym(sym).propoptions then
  4990. proctypesinfo:=$40
  4991. else
  4992. proctypesinfo:=0;
  4993. rttiList.concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4994. writeproc(tpropertysym(sym).readaccess,0);
  4995. writeproc(tpropertysym(sym).writeaccess,2);
  4996. { isn't it stored ? }
  4997. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4998. begin
  4999. rttiList.concat(Tai_const.create_sym(nil));
  5000. proctypesinfo:=proctypesinfo or (3 shl 4);
  5001. end
  5002. else
  5003. writeproc(tpropertysym(sym).storedaccess,4);
  5004. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  5005. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  5006. rttiList.concat(Tai_const.Create_16bit(count));
  5007. inc(count);
  5008. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  5009. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  5010. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  5011. {$ifdef cpurequiresproperalignment}
  5012. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5013. {$endif cpurequiresproperalignment}
  5014. end;
  5015. else internalerror(1509992);
  5016. end;
  5017. end;
  5018. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  5019. begin
  5020. if needs_prop_entry(tsym(sym)) then
  5021. begin
  5022. case tsym(sym).typ of
  5023. propertysym:
  5024. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  5025. fieldvarsym:
  5026. tstoreddef(tfieldvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  5027. else
  5028. internalerror(1509991);
  5029. end;
  5030. end;
  5031. end;
  5032. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  5033. begin
  5034. FRTTIType:=rt;
  5035. case rt of
  5036. initrtti :
  5037. symtable.foreach(@generate_field_rtti,nil);
  5038. fullrtti :
  5039. symtable.foreach(@generate_published_child_rtti,nil);
  5040. else
  5041. internalerror(200108301);
  5042. end;
  5043. end;
  5044. type
  5045. tclasslistitem = class(TLinkedListItem)
  5046. index : longint;
  5047. p : tobjectdef;
  5048. end;
  5049. var
  5050. classtablelist : tlinkedlist;
  5051. tablecount : longint;
  5052. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  5053. var
  5054. hp : tclasslistitem;
  5055. begin
  5056. hp:=tclasslistitem(classtablelist.first);
  5057. while assigned(hp) do
  5058. if hp.p=p then
  5059. begin
  5060. searchclasstablelist:=hp;
  5061. exit;
  5062. end
  5063. else
  5064. hp:=tclasslistitem(hp.next);
  5065. searchclasstablelist:=nil;
  5066. end;
  5067. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  5068. var
  5069. hp : tclasslistitem;
  5070. begin
  5071. if needs_prop_entry(tsym(sym)) and
  5072. (tsym(sym).typ=fieldvarsym) then
  5073. begin
  5074. if tfieldvarsym(sym).vartype.def.deftype<>objectdef then
  5075. internalerror(0206001);
  5076. hp:=searchclasstablelist(tobjectdef(tfieldvarsym(sym).vartype.def));
  5077. if not(assigned(hp)) then
  5078. begin
  5079. hp:=tclasslistitem.create;
  5080. hp.p:=tobjectdef(tfieldvarsym(sym).vartype.def);
  5081. hp.index:=tablecount;
  5082. classtablelist.concat(hp);
  5083. inc(tablecount);
  5084. end;
  5085. inc(count);
  5086. end;
  5087. end;
  5088. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  5089. var
  5090. hp : tclasslistitem;
  5091. begin
  5092. if needs_prop_entry(tsym(sym)) and
  5093. (tsym(sym).typ=fieldvarsym) then
  5094. begin
  5095. {$ifdef cpurequiresproperalignment}
  5096. rttilist.concat(Tai_align.Create(sizeof(AInt)));
  5097. {$endif cpurequiresproperalignment}
  5098. rttiList.concat(Tai_const.Create_aint(tfieldvarsym(sym).fieldoffset));
  5099. hp:=searchclasstablelist(tobjectdef(tfieldvarsym(sym).vartype.def));
  5100. if not(assigned(hp)) then
  5101. internalerror(0206002);
  5102. rttiList.concat(Tai_const.Create_16bit(hp.index));
  5103. rttiList.concat(Tai_const.Create_8bit(length(tfieldvarsym(sym).realname)));
  5104. rttiList.concat(Tai_string.Create(tfieldvarsym(sym).realname));
  5105. end;
  5106. end;
  5107. function tobjectdef.generate_field_table : tasmlabel;
  5108. var
  5109. fieldtable,
  5110. classtable : tasmlabel;
  5111. hp : tclasslistitem;
  5112. begin
  5113. classtablelist:=TLinkedList.Create;
  5114. objectlibrary.getdatalabel(fieldtable);
  5115. objectlibrary.getdatalabel(classtable);
  5116. count:=0;
  5117. tablecount:=0;
  5118. maybe_new_object_file(rttiList);
  5119. new_section(rttiList,sec_rodata,classtable.name,const_align(sizeof(aint)));
  5120. { fields }
  5121. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  5122. rttiList.concat(Tai_label.Create(fieldtable));
  5123. rttiList.concat(Tai_const.Create_16bit(count));
  5124. {$ifdef cpurequiresproperalignment}
  5125. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5126. {$endif cpurequiresproperalignment}
  5127. rttiList.concat(Tai_const.Create_sym(classtable));
  5128. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  5129. { generate the class table }
  5130. rttilist.concat(tai_align.create(const_align(sizeof(aint))));
  5131. rttiList.concat(Tai_label.Create(classtable));
  5132. rttiList.concat(Tai_const.Create_16bit(tablecount));
  5133. {$ifdef cpurequiresproperalignment}
  5134. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5135. {$endif cpurequiresproperalignment}
  5136. hp:=tclasslistitem(classtablelist.first);
  5137. while assigned(hp) do
  5138. begin
  5139. rttiList.concat(Tai_const.Createname(tobjectdef(hp.p).vmt_mangledname,AT_DATA,0));
  5140. hp:=tclasslistitem(hp.next);
  5141. end;
  5142. generate_field_table:=fieldtable;
  5143. classtablelist.free;
  5144. end;
  5145. function tobjectdef.next_free_name_index : longint;
  5146. var
  5147. i : longint;
  5148. begin
  5149. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5150. i:=childof.next_free_name_index
  5151. else
  5152. i:=0;
  5153. count:=0;
  5154. symtable.foreach(@count_published_properties,nil);
  5155. next_free_name_index:=i+count;
  5156. end;
  5157. procedure tobjectdef.write_rtti_data(rt:trttitype);
  5158. begin
  5159. case objecttype of
  5160. odt_class:
  5161. rttiList.concat(Tai_const.Create_8bit(tkclass));
  5162. odt_object:
  5163. rttiList.concat(Tai_const.Create_8bit(tkobject));
  5164. odt_interfacecom:
  5165. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  5166. odt_interfacecorba:
  5167. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  5168. else
  5169. exit;
  5170. end;
  5171. { generate the name }
  5172. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  5173. rttiList.concat(Tai_string.Create(objrealname^));
  5174. {$ifdef cpurequiresproperalignment}
  5175. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5176. {$endif cpurequiresproperalignment}
  5177. case rt of
  5178. initrtti :
  5179. begin
  5180. rttiList.concat(Tai_const.Create_32bit(size));
  5181. if objecttype in [odt_class,odt_object] then
  5182. begin
  5183. count:=0;
  5184. FRTTIType:=rt;
  5185. symtable.foreach(@count_field_rtti,nil);
  5186. rttiList.concat(Tai_const.Create_32bit(count));
  5187. symtable.foreach(@write_field_rtti,nil);
  5188. end;
  5189. end;
  5190. fullrtti :
  5191. begin
  5192. if (oo_has_vmt in objectoptions) and
  5193. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5194. rttiList.concat(Tai_const.Createname(vmt_mangledname,AT_DATA,0))
  5195. else
  5196. rttiList.concat(Tai_const.create_sym(nil));
  5197. { write owner typeinfo }
  5198. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5199. rttiList.concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  5200. else
  5201. rttiList.concat(Tai_const.create_sym(nil));
  5202. { count total number of properties }
  5203. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5204. count:=childof.next_free_name_index
  5205. else
  5206. count:=0;
  5207. { write it }
  5208. symtable.foreach(@count_published_properties,nil);
  5209. rttiList.concat(Tai_const.Create_16bit(count));
  5210. { write unit name }
  5211. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  5212. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  5213. {$ifdef cpurequiresproperalignment}
  5214. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5215. {$endif cpurequiresproperalignment}
  5216. { write published properties count }
  5217. count:=0;
  5218. symtable.foreach(@count_published_properties,nil);
  5219. rttiList.concat(Tai_const.Create_16bit(count));
  5220. {$ifdef cpurequiresproperalignment}
  5221. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5222. {$endif cpurequiresproperalignment}
  5223. { count is used to write nameindex }
  5224. { but we need an offset of the owner }
  5225. { to give each property an own slot }
  5226. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5227. count:=childof.next_free_name_index
  5228. else
  5229. count:=0;
  5230. symtable.foreach(@write_property_info,nil);
  5231. end;
  5232. end;
  5233. end;
  5234. function tobjectdef.is_publishable : boolean;
  5235. begin
  5236. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  5237. end;
  5238. {****************************************************************************
  5239. TIMPLEMENTEDINTERFACES
  5240. ****************************************************************************}
  5241. type
  5242. tnamemap = class(TNamedIndexItem)
  5243. newname: pstring;
  5244. constructor create(const aname, anewname: string);
  5245. destructor destroy; override;
  5246. end;
  5247. constructor tnamemap.create(const aname, anewname: string);
  5248. begin
  5249. inherited createname(name);
  5250. newname:=stringdup(anewname);
  5251. end;
  5252. destructor tnamemap.destroy;
  5253. begin
  5254. stringdispose(newname);
  5255. inherited destroy;
  5256. end;
  5257. type
  5258. tprocdefstore = class(TNamedIndexItem)
  5259. procdef: tprocdef;
  5260. constructor create(aprocdef: tprocdef);
  5261. end;
  5262. constructor tprocdefstore.create(aprocdef: tprocdef);
  5263. begin
  5264. inherited create;
  5265. procdef:=aprocdef;
  5266. end;
  5267. constructor timplintfentry.create(aintf: tobjectdef);
  5268. begin
  5269. inherited create;
  5270. intf:=aintf;
  5271. ioffset:=-1;
  5272. namemappings:=nil;
  5273. procdefs:=nil;
  5274. end;
  5275. constructor timplintfentry.create_deref(const d:tderef);
  5276. begin
  5277. inherited create;
  5278. intf:=nil;
  5279. intfderef:=d;
  5280. ioffset:=-1;
  5281. namemappings:=nil;
  5282. procdefs:=nil;
  5283. end;
  5284. destructor timplintfentry.destroy;
  5285. begin
  5286. if assigned(namemappings) then
  5287. namemappings.free;
  5288. if assigned(procdefs) then
  5289. procdefs.free;
  5290. inherited destroy;
  5291. end;
  5292. constructor timplementedinterfaces.create;
  5293. begin
  5294. finterfaces:=tindexarray.create(1);
  5295. end;
  5296. destructor timplementedinterfaces.destroy;
  5297. begin
  5298. finterfaces.destroy;
  5299. end;
  5300. function timplementedinterfaces.count: longint;
  5301. begin
  5302. count:=finterfaces.count;
  5303. end;
  5304. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5305. begin
  5306. if (intfindex<1) or (intfindex>count) then
  5307. InternalError(200006123);
  5308. end;
  5309. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5310. begin
  5311. checkindex(intfindex);
  5312. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5313. end;
  5314. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5315. begin
  5316. checkindex(intfindex);
  5317. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5318. end;
  5319. function timplementedinterfaces.ioffsets(intfindex: longint): longint;
  5320. begin
  5321. checkindex(intfindex);
  5322. ioffsets:=timplintfentry(finterfaces.search(intfindex)).ioffset;
  5323. end;
  5324. procedure timplementedinterfaces.setioffsets(intfindex,iofs:longint);
  5325. begin
  5326. checkindex(intfindex);
  5327. timplintfentry(finterfaces.search(intfindex)).ioffset:=iofs;
  5328. end;
  5329. function timplementedinterfaces.implindex(intfindex:longint):longint;
  5330. begin
  5331. checkindex(intfindex);
  5332. result:=timplintfentry(finterfaces.search(intfindex)).implindex;
  5333. end;
  5334. procedure timplementedinterfaces.setimplindex(intfindex,implidx:longint);
  5335. begin
  5336. checkindex(intfindex);
  5337. timplintfentry(finterfaces.search(intfindex)).implindex:=implidx;
  5338. end;
  5339. function timplementedinterfaces.searchintf(def: tdef): longint;
  5340. var
  5341. i: longint;
  5342. begin
  5343. i:=1;
  5344. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5345. if i<=count then
  5346. searchintf:=i
  5347. else
  5348. searchintf:=-1;
  5349. end;
  5350. procedure timplementedinterfaces.buildderef;
  5351. var
  5352. i: longint;
  5353. begin
  5354. for i:=1 to count do
  5355. with timplintfentry(finterfaces.search(i)) do
  5356. intfderef.build(intf);
  5357. end;
  5358. procedure timplementedinterfaces.deref;
  5359. var
  5360. i: longint;
  5361. begin
  5362. for i:=1 to count do
  5363. with timplintfentry(finterfaces.search(i)) do
  5364. intf:=tobjectdef(intfderef.resolve);
  5365. end;
  5366. procedure timplementedinterfaces.addintf_deref(const d:tderef;iofs:longint);
  5367. var
  5368. hintf : timplintfentry;
  5369. begin
  5370. hintf:=timplintfentry.create_deref(d);
  5371. hintf.ioffset:=iofs;
  5372. finterfaces.insert(hintf);
  5373. end;
  5374. procedure timplementedinterfaces.addintf(def: tdef);
  5375. begin
  5376. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5377. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5378. internalerror(200006124);
  5379. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5380. end;
  5381. procedure timplementedinterfaces.clearmappings;
  5382. var
  5383. i: longint;
  5384. begin
  5385. for i:=1 to count do
  5386. with timplintfentry(finterfaces.search(i)) do
  5387. begin
  5388. if assigned(namemappings) then
  5389. namemappings.free;
  5390. namemappings:=nil;
  5391. end;
  5392. end;
  5393. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5394. begin
  5395. checkindex(intfindex);
  5396. with timplintfentry(finterfaces.search(intfindex)) do
  5397. begin
  5398. if not assigned(namemappings) then
  5399. namemappings:=tdictionary.create;
  5400. namemappings.insert(tnamemap.create(name,newname));
  5401. end;
  5402. end;
  5403. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5404. begin
  5405. checkindex(intfindex);
  5406. if not assigned(nextexist) then
  5407. with timplintfentry(finterfaces.search(intfindex)) do
  5408. begin
  5409. if assigned(namemappings) then
  5410. nextexist:=namemappings.search(name)
  5411. else
  5412. nextexist:=nil;
  5413. end;
  5414. if assigned(nextexist) then
  5415. begin
  5416. getmappings:=tnamemap(nextexist).newname^;
  5417. nextexist:=tnamemap(nextexist).listnext;
  5418. end
  5419. else
  5420. getmappings:='';
  5421. end;
  5422. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5423. var
  5424. found : boolean;
  5425. i : longint;
  5426. begin
  5427. checkindex(intfindex);
  5428. with timplintfentry(finterfaces.search(intfindex)) do
  5429. begin
  5430. if not assigned(procdefs) then
  5431. procdefs:=tindexarray.create(4);
  5432. { No duplicate entries of the same procdef }
  5433. found:=false;
  5434. for i:=1 to procdefs.count do
  5435. if tprocdefstore(procdefs.search(i)).procdef=procdef then
  5436. begin
  5437. found:=true;
  5438. break;
  5439. end;
  5440. if not found then
  5441. procdefs.insert(tprocdefstore.create(procdef));
  5442. end;
  5443. end;
  5444. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5445. begin
  5446. checkindex(intfindex);
  5447. with timplintfentry(finterfaces.search(intfindex)) do
  5448. if assigned(procdefs) then
  5449. implproccount:=procdefs.count
  5450. else
  5451. implproccount:=0;
  5452. end;
  5453. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5454. begin
  5455. checkindex(intfindex);
  5456. with timplintfentry(finterfaces.search(intfindex)) do
  5457. if assigned(procdefs) then
  5458. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5459. else
  5460. internalerror(200006131);
  5461. end;
  5462. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5463. var
  5464. possible: boolean;
  5465. i: longint;
  5466. iiep1: TIndexArray;
  5467. iiep2: TIndexArray;
  5468. begin
  5469. checkindex(intfindex);
  5470. checkindex(remainindex);
  5471. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5472. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5473. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5474. begin
  5475. possible:=true;
  5476. weight:=0;
  5477. end
  5478. else
  5479. begin
  5480. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5481. i:=1;
  5482. while (possible) and (i<=iiep1.count) do
  5483. begin
  5484. possible:=
  5485. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5486. inc(i);
  5487. end;
  5488. if possible then
  5489. weight:=iiep1.count;
  5490. end;
  5491. isimplmergepossible:=possible;
  5492. end;
  5493. {****************************************************************************
  5494. TFORWARDDEF
  5495. ****************************************************************************}
  5496. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5497. var
  5498. oldregisterdef : boolean;
  5499. begin
  5500. { never register the forwarddefs, they are disposed at the
  5501. end of the type declaration block }
  5502. oldregisterdef:=registerdef;
  5503. registerdef:=false;
  5504. inherited create;
  5505. registerdef:=oldregisterdef;
  5506. deftype:=forwarddef;
  5507. tosymname:=stringdup(s);
  5508. forwardpos:=pos;
  5509. end;
  5510. function tforwarddef.gettypename:string;
  5511. begin
  5512. gettypename:='unresolved forward to '+tosymname^;
  5513. end;
  5514. destructor tforwarddef.destroy;
  5515. begin
  5516. if assigned(tosymname) then
  5517. stringdispose(tosymname);
  5518. inherited destroy;
  5519. end;
  5520. {****************************************************************************
  5521. TERRORDEF
  5522. ****************************************************************************}
  5523. constructor terrordef.create;
  5524. begin
  5525. inherited create;
  5526. deftype:=errordef;
  5527. end;
  5528. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  5529. begin
  5530. { Can't write errordefs to ppu }
  5531. internalerror(200411063);
  5532. end;
  5533. {$ifdef GDB}
  5534. function terrordef.stabstring : pchar;
  5535. begin
  5536. stabstring:=strpnew('error'+numberstring);
  5537. end;
  5538. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5539. begin
  5540. { No internal error needed, an normal error is already
  5541. thrown }
  5542. end;
  5543. {$endif GDB}
  5544. function terrordef.gettypename:string;
  5545. begin
  5546. gettypename:='<erroneous type>';
  5547. end;
  5548. function terrordef.getmangledparaname:string;
  5549. begin
  5550. getmangledparaname:='error';
  5551. end;
  5552. {****************************************************************************
  5553. Definition Helpers
  5554. ****************************************************************************}
  5555. function is_interfacecom(def: tdef): boolean;
  5556. begin
  5557. is_interfacecom:=
  5558. assigned(def) and
  5559. (def.deftype=objectdef) and
  5560. (tobjectdef(def).objecttype=odt_interfacecom);
  5561. end;
  5562. function is_interfacecorba(def: tdef): boolean;
  5563. begin
  5564. is_interfacecorba:=
  5565. assigned(def) and
  5566. (def.deftype=objectdef) and
  5567. (tobjectdef(def).objecttype=odt_interfacecorba);
  5568. end;
  5569. function is_interface(def: tdef): boolean;
  5570. begin
  5571. is_interface:=
  5572. assigned(def) and
  5573. (def.deftype=objectdef) and
  5574. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5575. end;
  5576. function is_class(def: tdef): boolean;
  5577. begin
  5578. is_class:=
  5579. assigned(def) and
  5580. (def.deftype=objectdef) and
  5581. (tobjectdef(def).objecttype=odt_class);
  5582. end;
  5583. function is_object(def: tdef): boolean;
  5584. begin
  5585. is_object:=
  5586. assigned(def) and
  5587. (def.deftype=objectdef) and
  5588. (tobjectdef(def).objecttype=odt_object);
  5589. end;
  5590. function is_cppclass(def: tdef): boolean;
  5591. begin
  5592. is_cppclass:=
  5593. assigned(def) and
  5594. (def.deftype=objectdef) and
  5595. (tobjectdef(def).objecttype=odt_cppclass);
  5596. end;
  5597. function is_class_or_interface(def: tdef): boolean;
  5598. begin
  5599. is_class_or_interface:=
  5600. assigned(def) and
  5601. (def.deftype=objectdef) and
  5602. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5603. end;
  5604. {$ifdef x86}
  5605. function use_sse(def : tdef) : boolean;
  5606. begin
  5607. use_sse:=(is_single(def) and (aktfputype in sse_singlescalar)) or
  5608. (is_double(def) and (aktfputype in sse_doublescalar));
  5609. end;
  5610. {$endif x86}
  5611. end.