symdef.pas 201 KB

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