symdef.pas 198 KB

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