symdef.pas 202 KB

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