symdef.pas 201 KB

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