symdef.pas 203 KB

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