symdef.pas 198 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379
  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. { forced calling convention? }
  3256. if (po_hascallingconvention in procoptions) then
  3257. s:=s+';'+ProcCallOptionStr[proccalloption];
  3258. fullprocname:=s;
  3259. end;
  3260. function tprocdef.is_methodpointer:boolean;
  3261. begin
  3262. result:=assigned(_class);
  3263. end;
  3264. function tprocdef.is_addressonly:boolean;
  3265. begin
  3266. result:=assigned(owner) and
  3267. (owner.symtabletype<>objectsymtable);
  3268. end;
  3269. (*
  3270. function tprocdef.is_visible_for_proc(currprocdef:tprocdef):boolean;
  3271. begin
  3272. is_visible_for_proc:=false;
  3273. { private symbols are allowed when we are in the same
  3274. module as they are defined }
  3275. if (sp_private in symoptions) and
  3276. assigned(owner.defowner) and
  3277. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3278. (owner.defowner.owner.unitid<>0) then
  3279. exit;
  3280. { protected symbols are vissible in the module that defines them and
  3281. also visible to related objects }
  3282. if (sp_protected in symoptions) and
  3283. (
  3284. (
  3285. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3286. (owner.defowner.owner.unitid<>0)
  3287. ) and
  3288. not(
  3289. assigned(currprocdef) and
  3290. assigned(currprocdef._class) and
  3291. currprocdef._class.is_related(tobjectdef(owner.defowner))
  3292. )
  3293. ) then
  3294. exit;
  3295. is_visible_for_proc:=true;
  3296. end;
  3297. *)
  3298. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3299. begin
  3300. is_visible_for_object:=false;
  3301. { private symbols are allowed when we are in the same
  3302. module as they are defined }
  3303. if (sp_private in symoptions) and
  3304. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3305. (owner.defowner.owner.unitid<>0) then
  3306. exit;
  3307. { protected symbols are vissible in the module that defines them and
  3308. also visible to related objects. The related object must be defined
  3309. in the current module }
  3310. if (sp_protected in symoptions) and
  3311. (
  3312. (
  3313. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3314. (owner.defowner.owner.unitid<>0)
  3315. ) and
  3316. not(
  3317. assigned(currobjdef) and
  3318. (currobjdef.owner.unitid=0) and
  3319. currobjdef.is_related(tobjectdef(owner.defowner))
  3320. )
  3321. ) then
  3322. exit;
  3323. is_visible_for_object:=true;
  3324. end;
  3325. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3326. begin
  3327. case t of
  3328. gs_local :
  3329. getsymtable:=localst;
  3330. gs_para :
  3331. getsymtable:=parast;
  3332. else
  3333. getsymtable:=nil;
  3334. end;
  3335. end;
  3336. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3337. var
  3338. pos : tfileposinfo;
  3339. move_last : boolean;
  3340. oldparasymtable,
  3341. oldlocalsymtable : tsymtable;
  3342. begin
  3343. oldparasymtable:=aktparasymtable;
  3344. oldlocalsymtable:=aktlocalsymtable;
  3345. aktparasymtable:=parast;
  3346. aktlocalsymtable:=localst;
  3347. move_last:=lastwritten=lastref;
  3348. while (not ppufile.endofentry) do
  3349. begin
  3350. ppufile.getposinfo(pos);
  3351. inc(refcount);
  3352. lastref:=tref.create(lastref,@pos);
  3353. lastref.is_written:=true;
  3354. if refcount=1 then
  3355. defref:=lastref;
  3356. end;
  3357. if move_last then
  3358. lastwritten:=lastref;
  3359. if ((current_module.flags and uf_local_browser)<>0) and
  3360. locals then
  3361. begin
  3362. tparasymtable(parast).load_references(ppufile,locals);
  3363. tlocalsymtable(localst).load_references(ppufile,locals);
  3364. end;
  3365. aktparasymtable:=oldparasymtable;
  3366. aktlocalsymtable:=oldlocalsymtable;
  3367. end;
  3368. Const
  3369. local_symtable_index : word = $8001;
  3370. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3371. var
  3372. ref : tref;
  3373. pdo : tobjectdef;
  3374. move_last : boolean;
  3375. d : tderef;
  3376. oldparasymtable,
  3377. oldlocalsymtable : tsymtable;
  3378. begin
  3379. d.reset;
  3380. move_last:=lastwritten=lastref;
  3381. if move_last and
  3382. (((current_module.flags and uf_local_browser)=0) or
  3383. not locals) then
  3384. exit;
  3385. oldparasymtable:=aktparasymtable;
  3386. oldlocalsymtable:=aktlocalsymtable;
  3387. aktparasymtable:=parast;
  3388. aktlocalsymtable:=localst;
  3389. { write address of this symbol }
  3390. ppufile.putderef(self,d);
  3391. { write refs }
  3392. if assigned(lastwritten) then
  3393. ref:=lastwritten
  3394. else
  3395. ref:=defref;
  3396. while assigned(ref) do
  3397. begin
  3398. if ref.moduleindex=current_module.unit_index then
  3399. begin
  3400. ppufile.putposinfo(ref.posinfo);
  3401. ref.is_written:=true;
  3402. if move_last then
  3403. lastwritten:=ref;
  3404. end
  3405. else if not ref.is_written then
  3406. move_last:=false
  3407. else if move_last then
  3408. lastwritten:=ref;
  3409. ref:=ref.nextref;
  3410. end;
  3411. ppufile.writeentry(ibdefref);
  3412. write_references:=true;
  3413. if ((current_module.flags and uf_local_browser)<>0) and
  3414. locals then
  3415. begin
  3416. pdo:=_class;
  3417. if (owner.symtabletype<>localsymtable) then
  3418. while assigned(pdo) do
  3419. begin
  3420. if pdo.symtable<>aktrecordsymtable then
  3421. begin
  3422. pdo.symtable.unitid:=local_symtable_index;
  3423. inc(local_symtable_index);
  3424. end;
  3425. pdo:=pdo.childof;
  3426. end;
  3427. parast.unitid:=local_symtable_index;
  3428. inc(local_symtable_index);
  3429. localst.unitid:=local_symtable_index;
  3430. inc(local_symtable_index);
  3431. tstoredsymtable(parast).write_references(ppufile,locals);
  3432. tstoredsymtable(localst).write_references(ppufile,locals);
  3433. { decrement for }
  3434. local_symtable_index:=local_symtable_index-2;
  3435. pdo:=_class;
  3436. if (owner.symtabletype<>localsymtable) then
  3437. while assigned(pdo) do
  3438. begin
  3439. if pdo.symtable<>aktrecordsymtable then
  3440. dec(local_symtable_index);
  3441. pdo:=pdo.childof;
  3442. end;
  3443. end;
  3444. aktparasymtable:=oldparasymtable;
  3445. aktlocalsymtable:=oldlocalsymtable;
  3446. end;
  3447. {$ifdef GDB}
  3448. {$ifdef unused}
  3449. { procedure addparaname(p : tsym);
  3450. var vs : char;
  3451. begin
  3452. if tvarsym(p).varspez = vs_value then vs := '1'
  3453. else vs := '0';
  3454. strpcopy(strend(StabRecString),p^.name+':'+tstoreddef(tvarsym(p).vartype.def).numberstring+','+vs+';');
  3455. end; }
  3456. function tprocdef.stabstring : pchar;
  3457. var
  3458. i : longint;
  3459. stabrecstring : pchar;
  3460. begin
  3461. getmem(StabRecString,1024);
  3462. strpcopy(StabRecString,'f'+tstoreddef(rettype.def).numberstring);
  3463. i:=maxparacount;
  3464. if i>0 then
  3465. begin
  3466. strpcopy(strend(StabRecString),','+tostr(i)+';');
  3467. (* confuse gdb !! PM
  3468. if assigned(parast) then
  3469. parast.foreach({$ifdef FPCPROCVAR}@{$endif}addparaname)
  3470. else
  3471. begin
  3472. param := para1;
  3473. i := 0;
  3474. while assigned(param) do
  3475. begin
  3476. inc(i);
  3477. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3478. {Here we have lost the parameter names !!}
  3479. {using lower case parameters }
  3480. strpcopy(strend(stabrecstring),'p'+tostr(i)
  3481. +':'+param^.paratype.def.numberstring+','+vartyp+';');
  3482. param := param^.next;
  3483. end;
  3484. end; *)
  3485. {strpcopy(strend(StabRecString),';');}
  3486. end;
  3487. stabstring := strnew(stabrecstring);
  3488. freemem(stabrecstring,1024);
  3489. end;
  3490. {$endif unused}
  3491. function tprocdef.stabstring: pchar;
  3492. Var RType : Char;
  3493. Obj,Info : String;
  3494. stabsstr : string;
  3495. p : pchar;
  3496. begin
  3497. obj := procsym.name;
  3498. info := '';
  3499. if tprocsym(procsym).is_global then
  3500. RType := 'F'
  3501. else
  3502. RType := 'f';
  3503. if assigned(owner) then
  3504. begin
  3505. if (owner.symtabletype = objectsymtable) then
  3506. obj := owner.name^+'__'+procsym.name;
  3507. { this code was correct only as long as the local symboltable
  3508. of the parent had the same name as the function
  3509. but this is no true anymore !! PM
  3510. if (owner.symtabletype=localsymtable) and assigned(owner.name) then
  3511. info := ','+name+','+owner.name^; }
  3512. if (owner.symtabletype=localsymtable) and
  3513. assigned(owner.defowner) and
  3514. assigned(tprocdef(owner.defowner).procsym) then
  3515. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3516. end;
  3517. stabsstr:=mangledname;
  3518. getmem(p,length(stabsstr)+255);
  3519. strpcopy(p,'"'+obj+':'+RType
  3520. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3521. +',0,'+
  3522. tostr(fileinfo.line)
  3523. +',');
  3524. strpcopy(strend(p),stabsstr);
  3525. stabstring:=strnew(p);
  3526. freemem(p,length(stabsstr)+255);
  3527. end;
  3528. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3529. begin
  3530. if (proccalloption=pocall_internproc) then
  3531. exit;
  3532. if not isstabwritten then
  3533. asmList.concat(Tai_stabs.Create(stabstring));
  3534. isstabwritten := true;
  3535. if not(po_external in procoptions) then
  3536. begin
  3537. tstoredsymtable(parast).concatstabto(asmlist);
  3538. { local type defs and vars should not be written
  3539. inside the main proc stab }
  3540. if assigned(localst) and
  3541. (localst.symtablelevel>main_program_level) then
  3542. tstoredsymtable(localst).concatstabto(asmlist);
  3543. end;
  3544. is_def_stab_written := written;
  3545. end;
  3546. {$endif GDB}
  3547. procedure tprocdef.deref;
  3548. var
  3549. oldparasymtable,
  3550. oldlocalsymtable : tsymtable;
  3551. begin
  3552. oldparasymtable:=aktparasymtable;
  3553. oldlocalsymtable:=aktlocalsymtable;
  3554. aktparasymtable:=parast;
  3555. aktlocalsymtable:=localst;
  3556. inherited deref;
  3557. _class:=tobjectdef(_classderef.resolve);
  3558. { procsym that originaly defined this definition, should be in the
  3559. same symtable }
  3560. procsym:=tprocsym(procsymderef.resolve);
  3561. aktparasymtable:=oldparasymtable;
  3562. aktlocalsymtable:=oldlocalsymtable;
  3563. end;
  3564. procedure tprocdef.derefimpl;
  3565. var
  3566. oldparasymtable,
  3567. oldlocalsymtable : tsymtable;
  3568. begin
  3569. oldparasymtable:=aktparasymtable;
  3570. oldlocalsymtable:=aktlocalsymtable;
  3571. aktparasymtable:=parast;
  3572. aktlocalsymtable:=localst;
  3573. { locals }
  3574. if assigned(localst) then
  3575. begin
  3576. { localst }
  3577. { we can deref both interface and implementation parts }
  3578. tlocalsymtable(localst).deref;
  3579. tlocalsymtable(localst).derefimpl;
  3580. { funcretsym, this is always located in the localst }
  3581. funcretsym:=tsym(funcretsymderef.resolve);
  3582. end
  3583. else
  3584. begin
  3585. { safety }
  3586. funcretsym:=nil;
  3587. end;
  3588. { inline tree }
  3589. if (proccalloption=pocall_inline) then
  3590. code.derefimpl;
  3591. aktparasymtable:=oldparasymtable;
  3592. aktlocalsymtable:=oldlocalsymtable;
  3593. end;
  3594. function tprocdef.gettypename : string;
  3595. begin
  3596. gettypename := FullProcName(false);
  3597. end;
  3598. function tprocdef.mangledname : string;
  3599. var
  3600. s : string;
  3601. hp : TParaItem;
  3602. begin
  3603. if assigned(_mangledname) then
  3604. begin
  3605. mangledname:=_mangledname^;
  3606. exit;
  3607. end;
  3608. { we need to use the symtable where the procsym is inserted,
  3609. because that is visible to the world }
  3610. s:=mangledname_prefix('',procsym.owner)+procsym.name;
  3611. if overloadnumber>0 then
  3612. s:=s+'$'+tostr(overloadnumber);
  3613. { add parameter types }
  3614. hp:=TParaItem(Para.first);
  3615. while assigned(hp) do
  3616. begin
  3617. if not hp.is_hidden then
  3618. s:=s+'$'+hp.paratype.def.mangledparaname;
  3619. hp:=TParaItem(hp.next);
  3620. end;
  3621. _mangledname:=stringdup(s);
  3622. mangledname:=_mangledname^;
  3623. end;
  3624. function tprocdef.cplusplusmangledname : string;
  3625. function getcppparaname(p : tdef) : string;
  3626. const
  3627. ordtype2str : array[tbasetype] of string[2] = (
  3628. '',
  3629. 'Uc','Us','Ui','Us',
  3630. 'Sc','s','i','x',
  3631. 'b','b','b',
  3632. 'c','w','x');
  3633. var
  3634. s : string;
  3635. begin
  3636. case p.deftype of
  3637. orddef:
  3638. s:=ordtype2str[torddef(p).typ];
  3639. pointerdef:
  3640. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3641. else
  3642. internalerror(2103001);
  3643. end;
  3644. getcppparaname:=s;
  3645. end;
  3646. var
  3647. s,s2 : string;
  3648. param : TParaItem;
  3649. begin
  3650. s := procsym.realname;
  3651. if procsym.owner.symtabletype=objectsymtable then
  3652. begin
  3653. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3654. case proctypeoption of
  3655. potype_destructor:
  3656. s:='_$_'+tostr(length(s2))+s2;
  3657. potype_constructor:
  3658. s:='___'+tostr(length(s2))+s2;
  3659. else
  3660. s:='_'+s+'__'+tostr(length(s2))+s2;
  3661. end;
  3662. end
  3663. else s:=s+'__';
  3664. s:=s+'F';
  3665. { concat modifiers }
  3666. { !!!!! }
  3667. { now we handle the parameters }
  3668. param := TParaItem(Para.first);
  3669. if assigned(param) then
  3670. while assigned(param) do
  3671. begin
  3672. s2:=getcppparaname(param.paratype.def);
  3673. if param.paratyp in [vs_var,vs_out] then
  3674. s2:='R'+s2;
  3675. s:=s+s2;
  3676. param:=TParaItem(param.next);
  3677. end
  3678. else
  3679. s:=s+'v';
  3680. cplusplusmangledname:=s;
  3681. end;
  3682. procedure tprocdef.setmangledname(const s : string);
  3683. begin
  3684. stringdispose(_mangledname);
  3685. _mangledname:=stringdup(s);
  3686. has_mangledname:=true;
  3687. end;
  3688. {***************************************************************************
  3689. TPROCVARDEF
  3690. ***************************************************************************}
  3691. constructor tprocvardef.create(level:byte);
  3692. begin
  3693. inherited create(level);
  3694. deftype:=procvardef;
  3695. end;
  3696. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3697. begin
  3698. inherited ppuload(ppufile);
  3699. deftype:=procvardef;
  3700. { load para symtable }
  3701. parast:=tparasymtable.create(unknown_level);
  3702. tparasymtable(parast).ppuload(ppufile);
  3703. parast.defowner:=self;
  3704. end;
  3705. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3706. var
  3707. oldparasymtable,
  3708. oldlocalsymtable : tsymtable;
  3709. begin
  3710. oldparasymtable:=aktparasymtable;
  3711. oldlocalsymtable:=aktlocalsymtable;
  3712. aktparasymtable:=parast;
  3713. aktlocalsymtable:=nil;
  3714. { here we cannot get a real good value so just give something }
  3715. { plausible (PM) }
  3716. { a more secure way would be
  3717. to allways store in a temp }
  3718. if is_fpu(rettype.def) then
  3719. fpu_used:={2}maxfpuregs
  3720. else
  3721. fpu_used:=0;
  3722. inherited ppuwrite(ppufile);
  3723. { Write this entry }
  3724. ppufile.writeentry(ibprocvardef);
  3725. { Save the para symtable, this is taken from the interface }
  3726. tparasymtable(parast).ppuwrite(ppufile);
  3727. aktparasymtable:=oldparasymtable;
  3728. aktlocalsymtable:=oldlocalsymtable;
  3729. end;
  3730. procedure tprocvardef.deref;
  3731. var
  3732. oldparasymtable,
  3733. oldlocalsymtable : tsymtable;
  3734. begin
  3735. oldparasymtable:=aktparasymtable;
  3736. oldlocalsymtable:=aktlocalsymtable;
  3737. aktparasymtable:=parast;
  3738. aktlocalsymtable:=nil;
  3739. inherited deref;
  3740. aktparasymtable:=oldparasymtable;
  3741. aktlocalsymtable:=oldlocalsymtable;
  3742. end;
  3743. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3744. begin
  3745. case t of
  3746. gs_para :
  3747. getsymtable:=parast;
  3748. else
  3749. getsymtable:=nil;
  3750. end;
  3751. end;
  3752. function tprocvardef.size : longint;
  3753. begin
  3754. if (po_methodpointer in procoptions) and
  3755. not(po_addressonly in procoptions) then
  3756. size:=2*POINTER_SIZE
  3757. else
  3758. size:=POINTER_SIZE;
  3759. end;
  3760. function tprocvardef.is_methodpointer:boolean;
  3761. begin
  3762. result:=(po_methodpointer in procoptions);
  3763. end;
  3764. function tprocvardef.is_addressonly:boolean;
  3765. begin
  3766. result:=not(po_methodpointer in procoptions) or
  3767. (po_addressonly in procoptions);
  3768. end;
  3769. {$ifdef GDB}
  3770. function tprocvardef.stabstring : pchar;
  3771. var
  3772. nss : pchar;
  3773. { i : longint; }
  3774. begin
  3775. { i := maxparacount; }
  3776. getmem(nss,1024);
  3777. { it is not a function but a function pointer !! (PM) }
  3778. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)}+';');
  3779. { this confuses gdb !!
  3780. we should use 'F' instead of 'f' but
  3781. as we use c++ language mode
  3782. it does not like that either
  3783. Please do not remove this part
  3784. might be used once
  3785. gdb for pascal is ready PM }
  3786. (*
  3787. param := para1;
  3788. i := 0;
  3789. while assigned(param) do
  3790. begin
  3791. inc(i);
  3792. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3793. {Here we have lost the parameter names !!}
  3794. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3795. strcat(nss,pst);
  3796. strdispose(pst);
  3797. param := param^.next;
  3798. end; *)
  3799. {strpcopy(strend(nss),';');}
  3800. stabstring := strnew(nss);
  3801. freemem(nss,1024);
  3802. end;
  3803. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3804. begin
  3805. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  3806. and (is_def_stab_written = not_written) then
  3807. inherited concatstabto(asmlist);
  3808. is_def_stab_written:=written;
  3809. end;
  3810. {$endif GDB}
  3811. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3812. var
  3813. pdc : TParaItem;
  3814. methodkind, paraspec : byte;
  3815. begin
  3816. if po_methodpointer in procoptions then
  3817. begin
  3818. { write method id and name }
  3819. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  3820. write_rtti_name;
  3821. { write kind of method (can only be function or procedure)}
  3822. if rettype.def = voidtype.def then
  3823. methodkind := mkProcedure
  3824. else
  3825. methodkind := mkFunction;
  3826. rttiList.concat(Tai_const.Create_8bit(methodkind));
  3827. { get # of parameters }
  3828. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  3829. { write parameter info. The parameters must be written in reverse order
  3830. if this method uses right to left parameter pushing! }
  3831. if proccalloption in pushleftright_pocalls then
  3832. pdc:=TParaItem(Para.first)
  3833. else
  3834. pdc:=TParaItem(Para.last);
  3835. while assigned(pdc) do
  3836. begin
  3837. case pdc.paratyp of
  3838. vs_value: paraspec := 0;
  3839. vs_const: paraspec := pfConst;
  3840. vs_var : paraspec := pfVar;
  3841. vs_out : paraspec := pfOut;
  3842. end;
  3843. { write flags for current parameter }
  3844. rttiList.concat(Tai_const.Create_8bit(paraspec));
  3845. { write name of current parameter ### how can I get this??? (sg)}
  3846. rttiList.concat(Tai_const.Create_8bit(0));
  3847. { write name of type of current parameter }
  3848. tstoreddef(pdc.paratype.def).write_rtti_name;
  3849. if proccalloption in pushleftright_pocalls then
  3850. pdc:=TParaItem(pdc.next)
  3851. else
  3852. pdc:=TParaItem(pdc.previous);
  3853. end;
  3854. { write name of result type }
  3855. tstoreddef(rettype.def).write_rtti_name;
  3856. end;
  3857. end;
  3858. function tprocvardef.is_publishable : boolean;
  3859. begin
  3860. is_publishable:=(po_methodpointer in procoptions);
  3861. end;
  3862. function tprocvardef.gettypename : string;
  3863. var
  3864. s: string;
  3865. showhidden : boolean;
  3866. begin
  3867. {$ifdef EXTDEBUG}
  3868. showhidden:=true;
  3869. {$else EXTDEBUG}
  3870. showhidden:=false;
  3871. {$endif EXTDEBUG}
  3872. s:='<';
  3873. if po_classmethod in procoptions then
  3874. s := s+'class method type of'
  3875. else
  3876. if po_addressonly in procoptions then
  3877. s := s+'address of'
  3878. else
  3879. s := s+'procedure variable type of';
  3880. if assigned(rettype.def) and
  3881. (rettype.def<>voidtype.def) then
  3882. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  3883. else
  3884. s:=s+' procedure'+typename_paras(showhidden);
  3885. if po_methodpointer in procoptions then
  3886. s := s+' of object';
  3887. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3888. end;
  3889. {***************************************************************************
  3890. TOBJECTDEF
  3891. ***************************************************************************}
  3892. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  3893. begin
  3894. inherited create;
  3895. objecttype:=ot;
  3896. deftype:=objectdef;
  3897. objectoptions:=[];
  3898. childof:=nil;
  3899. symtable:=tobjectsymtable.create(n);
  3900. { create space for vmt !! }
  3901. vmt_offset:=0;
  3902. symtable.defowner:=self;
  3903. { recordalign -1 means C record packing, that starts
  3904. with an alignment of 1 }
  3905. if aktalignment.recordalignmax=-1 then
  3906. tobjectsymtable(symtable).dataalignment:=1
  3907. else
  3908. tobjectsymtable(symtable).dataalignment:=aktalignment.recordalignmax;
  3909. lastvtableindex:=0;
  3910. set_parent(c);
  3911. objname:=stringdup(upper(n));
  3912. objrealname:=stringdup(n);
  3913. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  3914. prepareguid;
  3915. { setup implemented interfaces }
  3916. if objecttype in [odt_class,odt_interfacecorba] then
  3917. implementedinterfaces:=timplementedinterfaces.create
  3918. else
  3919. implementedinterfaces:=nil;
  3920. {$ifdef GDB}
  3921. writing_class_record_stab:=false;
  3922. {$endif GDB}
  3923. end;
  3924. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3925. var
  3926. i,implintfcount: longint;
  3927. d : tderef;
  3928. begin
  3929. inherited ppuloaddef(ppufile);
  3930. deftype:=objectdef;
  3931. objecttype:=tobjectdeftype(ppufile.getbyte);
  3932. savesize:=ppufile.getlongint;
  3933. vmt_offset:=ppufile.getlongint;
  3934. objrealname:=stringdup(ppufile.getstring);
  3935. objname:=stringdup(upper(objrealname^));
  3936. ppufile.getderef(childofderef);
  3937. ppufile.getsmallset(objectoptions);
  3938. { load guid }
  3939. iidstr:=nil;
  3940. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3941. begin
  3942. new(iidguid);
  3943. ppufile.getguid(iidguid^);
  3944. iidstr:=stringdup(ppufile.getstring);
  3945. lastvtableindex:=ppufile.getlongint;
  3946. end;
  3947. { load implemented interfaces }
  3948. if objecttype in [odt_class,odt_interfacecorba] then
  3949. begin
  3950. implementedinterfaces:=timplementedinterfaces.create;
  3951. implintfcount:=ppufile.getlongint;
  3952. for i:=1 to implintfcount do
  3953. begin
  3954. ppufile.getderef(d);
  3955. implementedinterfaces.addintf_deref(d);
  3956. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  3957. end;
  3958. end
  3959. else
  3960. implementedinterfaces:=nil;
  3961. symtable:=tobjectsymtable.create(objrealname^);
  3962. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  3963. tobjectsymtable(symtable).dataalignment:=ppufile.getbyte;
  3964. tobjectsymtable(symtable).ppuload(ppufile);
  3965. symtable.defowner:=self;
  3966. { handles the predefined class tobject }
  3967. { the last TOBJECT which is loaded gets }
  3968. { it ! }
  3969. if (childof=nil) and
  3970. (objecttype=odt_class) and
  3971. (objname^='TOBJECT') then
  3972. class_tobject:=self;
  3973. if (childof=nil) and
  3974. (objecttype=odt_interfacecom) and
  3975. (objname^='IUNKNOWN') then
  3976. interface_iunknown:=self;
  3977. {$ifdef GDB}
  3978. writing_class_record_stab:=false;
  3979. {$endif GDB}
  3980. end;
  3981. destructor tobjectdef.destroy;
  3982. begin
  3983. if assigned(symtable) then
  3984. symtable.free;
  3985. stringdispose(objname);
  3986. stringdispose(objrealname);
  3987. if assigned(iidstr) then
  3988. stringdispose(iidstr);
  3989. if assigned(implementedinterfaces) then
  3990. implementedinterfaces.free;
  3991. if assigned(iidguid) then
  3992. dispose(iidguid);
  3993. inherited destroy;
  3994. end;
  3995. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3996. var
  3997. implintfcount : longint;
  3998. i : longint;
  3999. begin
  4000. inherited ppuwritedef(ppufile);
  4001. ppufile.putbyte(byte(objecttype));
  4002. ppufile.putlongint(size);
  4003. ppufile.putlongint(vmt_offset);
  4004. ppufile.putstring(objrealname^);
  4005. ppufile.putderef(childof,childofderef);
  4006. ppufile.putsmallset(objectoptions);
  4007. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4008. begin
  4009. ppufile.putguid(iidguid^);
  4010. ppufile.putstring(iidstr^);
  4011. ppufile.putlongint(lastvtableindex);
  4012. end;
  4013. if objecttype in [odt_class,odt_interfacecorba] then
  4014. begin
  4015. implintfcount:=implementedinterfaces.count;
  4016. ppufile.putlongint(implintfcount);
  4017. for i:=1 to implintfcount do
  4018. begin
  4019. ppufile.putderef(implementedinterfaces.interfaces(i),implementedinterfaces.interfacesderef(i));
  4020. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4021. end;
  4022. end;
  4023. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4024. ppufile.putbyte(tobjectsymtable(symtable).dataalignment);
  4025. ppufile.writeentry(ibobjectdef);
  4026. tobjectsymtable(symtable).ppuwrite(ppufile);
  4027. end;
  4028. function tobjectdef.gettypename:string;
  4029. begin
  4030. gettypename:=typename;
  4031. end;
  4032. procedure tobjectdef.deref;
  4033. var
  4034. oldrecsyms : tsymtable;
  4035. begin
  4036. inherited deref;
  4037. childof:=tobjectdef(childofderef.resolve);
  4038. oldrecsyms:=aktrecordsymtable;
  4039. aktrecordsymtable:=symtable;
  4040. tstoredsymtable(symtable).deref;
  4041. aktrecordsymtable:=oldrecsyms;
  4042. if objecttype in [odt_class,odt_interfacecorba] then
  4043. implementedinterfaces.deref;
  4044. end;
  4045. function tobjectdef.getparentdef:tdef;
  4046. begin
  4047. result:=childof;
  4048. end;
  4049. procedure tobjectdef.prepareguid;
  4050. begin
  4051. { set up guid }
  4052. if not assigned(iidguid) then
  4053. begin
  4054. new(iidguid);
  4055. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4056. end;
  4057. { setup iidstring }
  4058. if not assigned(iidstr) then
  4059. iidstr:=stringdup(''); { default is empty string }
  4060. end;
  4061. procedure tobjectdef.set_parent( c : tobjectdef);
  4062. begin
  4063. { nothing to do if the parent was not forward !}
  4064. if assigned(childof) then
  4065. exit;
  4066. childof:=c;
  4067. { some options are inherited !! }
  4068. if assigned(c) then
  4069. begin
  4070. { only important for classes }
  4071. lastvtableindex:=c.lastvtableindex;
  4072. objectoptions:=objectoptions+(c.objectoptions*
  4073. [oo_has_virtual,oo_has_private,oo_has_protected,
  4074. oo_has_constructor,oo_has_destructor]);
  4075. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4076. begin
  4077. { add the data of the anchestor class }
  4078. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4079. if (oo_has_vmt in objectoptions) and
  4080. (oo_has_vmt in c.objectoptions) then
  4081. dec(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4082. { if parent has a vmt field then
  4083. the offset is the same for the child PM }
  4084. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4085. begin
  4086. vmt_offset:=c.vmt_offset;
  4087. include(objectoptions,oo_has_vmt);
  4088. end;
  4089. end;
  4090. end;
  4091. savesize := tobjectsymtable(symtable).datasize;
  4092. end;
  4093. procedure tobjectdef.insertvmt;
  4094. begin
  4095. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4096. exit;
  4097. if (oo_has_vmt in objectoptions) then
  4098. internalerror(12345)
  4099. else
  4100. begin
  4101. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4102. tobjectsymtable(symtable).dataalignment);
  4103. vmt_offset:=tobjectsymtable(symtable).datasize;
  4104. inc(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4105. include(objectoptions,oo_has_vmt);
  4106. end;
  4107. end;
  4108. procedure tobjectdef.check_forwards;
  4109. begin
  4110. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4111. tstoredsymtable(symtable).check_forwards;
  4112. if (oo_is_forward in objectoptions) then
  4113. begin
  4114. { ok, in future, the forward can be resolved }
  4115. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4116. exclude(objectoptions,oo_is_forward);
  4117. end;
  4118. end;
  4119. { true, if self inherits from d (or if they are equal) }
  4120. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4121. var
  4122. hp : tobjectdef;
  4123. begin
  4124. hp:=self;
  4125. while assigned(hp) do
  4126. begin
  4127. if hp=d then
  4128. begin
  4129. is_related:=true;
  4130. exit;
  4131. end;
  4132. hp:=hp.childof;
  4133. end;
  4134. is_related:=false;
  4135. end;
  4136. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4137. var
  4138. p : pprocdeflist;
  4139. begin
  4140. { if we found already a destructor, then we exit }
  4141. if assigned(sd) then
  4142. exit;
  4143. if tsym(sym).typ=procsym then
  4144. begin
  4145. p:=tprocsym(sym).defs;
  4146. while assigned(p) do
  4147. begin
  4148. if p^.def.proctypeoption=potype_destructor then
  4149. begin
  4150. sd:=p^.def;
  4151. exit;
  4152. end;
  4153. p:=p^.next;
  4154. end;
  4155. end;
  4156. end;*)
  4157. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4158. begin
  4159. { if we found already a destructor, then we exit }
  4160. if (ppointer(sd)^=nil) and
  4161. (Tsym(sym).typ=procsym) then
  4162. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4163. end;
  4164. function tobjectdef.searchdestructor : tprocdef;
  4165. var
  4166. o : tobjectdef;
  4167. sd : tprocdef;
  4168. begin
  4169. searchdestructor:=nil;
  4170. o:=self;
  4171. sd:=nil;
  4172. while assigned(o) do
  4173. begin
  4174. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4175. if assigned(sd) then
  4176. begin
  4177. searchdestructor:=sd;
  4178. exit;
  4179. end;
  4180. o:=o.childof;
  4181. end;
  4182. end;
  4183. function tobjectdef.size : longint;
  4184. begin
  4185. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4186. result:=POINTER_SIZE
  4187. else
  4188. result:=tobjectsymtable(symtable).datasize;
  4189. end;
  4190. function tobjectdef.alignment:longint;
  4191. begin
  4192. alignment:=tobjectsymtable(symtable).dataalignment;
  4193. end;
  4194. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4195. begin
  4196. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4197. case objecttype of
  4198. odt_class:
  4199. vmtmethodoffset:=(index+12)*POINTER_SIZE;
  4200. odt_interfacecom,odt_interfacecorba:
  4201. vmtmethodoffset:=index*POINTER_SIZE;
  4202. else
  4203. {$ifdef WITHDMT}
  4204. vmtmethodoffset:=(index+4)*POINTER_SIZE;
  4205. {$else WITHDMT}
  4206. vmtmethodoffset:=(index+3)*POINTER_SIZE;
  4207. {$endif WITHDMT}
  4208. end;
  4209. end;
  4210. function tobjectdef.vmt_mangledname : string;
  4211. begin
  4212. if not(oo_has_vmt in objectoptions) then
  4213. Message1(parser_n_object_has_no_vmt,objrealname^);
  4214. vmt_mangledname:=mangledname_prefix('VMT',owner)+objname^;
  4215. end;
  4216. function tobjectdef.rtti_name : string;
  4217. begin
  4218. rtti_name:=mangledname_prefix('RTTI',owner)+objname^;
  4219. end;
  4220. {$ifdef GDB}
  4221. procedure tobjectdef.addprocname(p :tnamedindexitem;arg:pointer);
  4222. var virtualind,argnames : string;
  4223. news, newrec : pchar;
  4224. pd,ipd : tprocdef;
  4225. lindex : longint;
  4226. para : TParaItem;
  4227. arglength : byte;
  4228. sp : char;
  4229. begin
  4230. If tsym(p).typ = procsym then
  4231. begin
  4232. pd := tprocsym(p).first_procdef;
  4233. { this will be used for full implementation of object stabs
  4234. not yet done }
  4235. ipd := Tprocsym(p).last_procdef;
  4236. if (po_virtualmethod in pd.procoptions) then
  4237. begin
  4238. lindex := pd.extnumber;
  4239. {doesnt seem to be necessary
  4240. lindex := lindex or $80000000;}
  4241. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  4242. end
  4243. else
  4244. virtualind := '.';
  4245. { used by gdbpas to recognize constructor and destructors }
  4246. if (pd.proctypeoption=potype_constructor) then
  4247. argnames:='__ct__'
  4248. else if (pd.proctypeoption=potype_destructor) then
  4249. argnames:='__dt__'
  4250. else
  4251. argnames := '';
  4252. { arguments are not listed here }
  4253. {we don't need another definition}
  4254. para := TParaItem(pd.Para.first);
  4255. while assigned(para) do
  4256. begin
  4257. if Para.paratype.def.deftype = formaldef then
  4258. begin
  4259. if Para.paratyp=vs_var then
  4260. argnames := argnames+'3var'
  4261. else if Para.paratyp=vs_const then
  4262. argnames:=argnames+'5const'
  4263. else if Para.paratyp=vs_out then
  4264. argnames:=argnames+'3out';
  4265. end
  4266. else
  4267. begin
  4268. { if the arg definition is like (v: ^byte;..
  4269. there is no sym attached to data !!! }
  4270. if assigned(Para.paratype.def.typesym) then
  4271. begin
  4272. arglength := length(Para.paratype.def.typesym.name);
  4273. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4274. end
  4275. else
  4276. begin
  4277. argnames:=argnames+'11unnamedtype';
  4278. end;
  4279. end;
  4280. para := TParaItem(Para.next);
  4281. end;
  4282. ipd.is_def_stab_written := written;
  4283. { here 2A must be changed for private and protected }
  4284. { 0 is private 1 protected and 2 public }
  4285. if (sp_private in tsym(p).symoptions) then sp:='0'
  4286. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  4287. else sp:='2';
  4288. newrec := strpnew(p.name+'::'+ipd.numberstring
  4289. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  4290. +virtualind+';');
  4291. { get spare place for a string at the end }
  4292. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  4293. begin
  4294. getmem(news,stabrecsize+memsizeinc);
  4295. strcopy(news,stabrecstring);
  4296. freemem(stabrecstring,stabrecsize);
  4297. stabrecsize:=stabrecsize+memsizeinc;
  4298. stabrecstring:=news;
  4299. end;
  4300. strcat(StabRecstring,newrec);
  4301. {freemem(newrec,memsizeinc); }
  4302. strdispose(newrec);
  4303. {This should be used for case !!
  4304. RecOffset := RecOffset + pd.size;}
  4305. end;
  4306. end;
  4307. function tobjectdef.stabstring : pchar;
  4308. var anc : tobjectdef;
  4309. oldrec : pchar;
  4310. oldrecsize,oldrecoffset : longint;
  4311. str_end : string;
  4312. begin
  4313. if not (objecttype=odt_class) or writing_class_record_stab then
  4314. begin
  4315. oldrec := stabrecstring;
  4316. oldrecsize:=stabrecsize;
  4317. stabrecsize:=memsizeinc;
  4318. GetMem(stabrecstring,stabrecsize);
  4319. strpcopy(stabRecString,'s'+tostr(tobjectsymtable(symtable).datasize));
  4320. if assigned(childof) then
  4321. begin
  4322. {only one ancestor not virtual, public, at base offset 0 }
  4323. { !1 , 0 2 0 , }
  4324. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  4325. end;
  4326. {virtual table to implement yet}
  4327. OldRecOffset:=RecOffset;
  4328. RecOffset := 0;
  4329. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  4330. RecOffset:=OldRecOffset;
  4331. if (oo_has_vmt in objectoptions) then
  4332. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4333. begin
  4334. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  4335. +','+tostr(vmt_offset*8)+';');
  4336. end;
  4337. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname,nil);
  4338. if (oo_has_vmt in objectoptions) then
  4339. begin
  4340. anc := self;
  4341. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4342. anc := anc.childof;
  4343. { just in case anc = self }
  4344. str_end:=';~%'+anc.classnumberstring+';';
  4345. end
  4346. else
  4347. str_end:=';';
  4348. strpcopy(strend(stabrecstring),str_end);
  4349. stabstring := strnew(StabRecString);
  4350. freemem(stabrecstring,stabrecsize);
  4351. stabrecstring := oldrec;
  4352. stabrecsize:=oldrecsize;
  4353. end
  4354. else
  4355. begin
  4356. stabstring:=strpnew('*'+classnumberstring);
  4357. end;
  4358. end;
  4359. procedure tobjectdef.set_globalnb;
  4360. begin
  4361. globalnb:=PglobalTypeCount^;
  4362. inc(PglobalTypeCount^);
  4363. { classes need two type numbers, the globalnb is set to the ptr }
  4364. if objecttype=odt_class then
  4365. begin
  4366. globalnb:=PGlobalTypeCount^;
  4367. inc(PglobalTypeCount^);
  4368. end;
  4369. end;
  4370. function tobjectdef.classnumberstring : string;
  4371. begin
  4372. { write stabs again if needed }
  4373. numberstring;
  4374. if objecttype=odt_class then
  4375. begin
  4376. dec(globalnb);
  4377. classnumberstring:=numberstring;
  4378. inc(globalnb);
  4379. end
  4380. else
  4381. classnumberstring:=numberstring;
  4382. end;
  4383. function tobjectdef.allstabstring : pchar;
  4384. var stabchar : string[2];
  4385. ss,st : pchar;
  4386. sname : string;
  4387. sym_line_no : longint;
  4388. begin
  4389. ss := stabstring;
  4390. getmem(st,strlen(ss)+512);
  4391. stabchar := 't';
  4392. if deftype in tagtypes then
  4393. stabchar := 'Tt';
  4394. if assigned(typesym) then
  4395. begin
  4396. sname := typesym.name;
  4397. sym_line_no:=typesym.fileinfo.line;
  4398. end
  4399. else
  4400. begin
  4401. sname := ' ';
  4402. sym_line_no:=0;
  4403. end;
  4404. if writing_class_record_stab then
  4405. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4406. else
  4407. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4408. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  4409. allstabstring := strnew(st);
  4410. freemem(st,strlen(ss)+512);
  4411. strdispose(ss);
  4412. end;
  4413. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4414. var st : pstring;
  4415. begin
  4416. if objecttype<>odt_class then
  4417. begin
  4418. inherited concatstabto(asmlist);
  4419. exit;
  4420. end;
  4421. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4422. (is_def_stab_written = not_written) then
  4423. begin
  4424. if globalnb=0 then
  4425. set_globalnb;
  4426. { Write the record class itself }
  4427. writing_class_record_stab:=true;
  4428. inherited concatstabto(asmlist);
  4429. writing_class_record_stab:=false;
  4430. { Write the invisible pointer class }
  4431. is_def_stab_written:=not_written;
  4432. if assigned(typesym) then
  4433. begin
  4434. st:=typesym.FName;
  4435. typesym.FName:=stringdup(' ');
  4436. end;
  4437. inherited concatstabto(asmlist);
  4438. if assigned(typesym) then
  4439. begin
  4440. stringdispose(typesym.FName);
  4441. typesym.FName:=st;
  4442. end;
  4443. end;
  4444. end;
  4445. {$endif GDB}
  4446. function tobjectdef.needs_inittable : boolean;
  4447. begin
  4448. case objecttype of
  4449. odt_class :
  4450. needs_inittable:=false;
  4451. odt_interfacecom:
  4452. needs_inittable:=true;
  4453. odt_interfacecorba:
  4454. needs_inittable:=is_related(interface_iunknown);
  4455. odt_object:
  4456. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4457. else
  4458. internalerror(200108267);
  4459. end;
  4460. end;
  4461. function tobjectdef.members_need_inittable : boolean;
  4462. begin
  4463. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4464. end;
  4465. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4466. begin
  4467. if needs_prop_entry(tsym(sym)) and
  4468. (tsym(sym).typ<>varsym) then
  4469. inc(count);
  4470. end;
  4471. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4472. var
  4473. proctypesinfo : byte;
  4474. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4475. var
  4476. typvalue : byte;
  4477. hp : psymlistitem;
  4478. address : longint;
  4479. begin
  4480. if not(assigned(proc) and assigned(proc.firstsym)) then
  4481. begin
  4482. rttiList.concat(Tai_const.Create_32bit(1));
  4483. typvalue:=3;
  4484. end
  4485. else if proc.firstsym^.sym.typ=varsym then
  4486. begin
  4487. address:=0;
  4488. hp:=proc.firstsym;
  4489. while assigned(hp) do
  4490. begin
  4491. inc(address,tvarsym(hp^.sym).fieldoffset);
  4492. hp:=hp^.next;
  4493. end;
  4494. rttiList.concat(Tai_const.Create_32bit(address));
  4495. typvalue:=0;
  4496. end
  4497. else
  4498. begin
  4499. if not assigned(proc.procdef) then
  4500. internalerror(200310074);
  4501. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4502. begin
  4503. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.procdef).mangledname));
  4504. typvalue:=1;
  4505. end
  4506. else
  4507. begin
  4508. { virtual method, write vmt offset }
  4509. rttiList.concat(Tai_const.Create_32bit(
  4510. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4511. typvalue:=2;
  4512. end;
  4513. end;
  4514. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4515. end;
  4516. begin
  4517. if needs_prop_entry(tsym(sym)) then
  4518. case tsym(sym).typ of
  4519. varsym:
  4520. begin
  4521. {$ifdef dummy}
  4522. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4523. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4524. internalerror(1509992);
  4525. { access to implicit class property as field }
  4526. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4527. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4528. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4529. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4530. { per default stored }
  4531. rttiList.concat(Tai_const.Create_32bit(1));
  4532. { index as well as ... }
  4533. rttiList.concat(Tai_const.Create_32bit(0));
  4534. { default value are zero }
  4535. rttiList.concat(Tai_const.Create_32bit(0));
  4536. rttiList.concat(Tai_const.Create_16bit(count));
  4537. inc(count);
  4538. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4539. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4540. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4541. {$endif dummy}
  4542. end;
  4543. propertysym:
  4544. begin
  4545. if ppo_indexed in tpropertysym(sym).propoptions then
  4546. proctypesinfo:=$40
  4547. else
  4548. proctypesinfo:=0;
  4549. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4550. writeproc(tpropertysym(sym).readaccess,0);
  4551. writeproc(tpropertysym(sym).writeaccess,2);
  4552. { isn't it stored ? }
  4553. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4554. begin
  4555. rttiList.concat(Tai_const.Create_32bit(0));
  4556. proctypesinfo:=proctypesinfo or (3 shl 4);
  4557. end
  4558. else
  4559. writeproc(tpropertysym(sym).storedaccess,4);
  4560. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4561. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4562. rttiList.concat(Tai_const.Create_16bit(count));
  4563. inc(count);
  4564. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4565. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4566. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4567. end;
  4568. else internalerror(1509992);
  4569. end;
  4570. end;
  4571. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4572. begin
  4573. if needs_prop_entry(tsym(sym)) then
  4574. begin
  4575. case tsym(sym).typ of
  4576. propertysym:
  4577. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4578. varsym:
  4579. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4580. else
  4581. internalerror(1509991);
  4582. end;
  4583. end;
  4584. end;
  4585. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4586. begin
  4587. FRTTIType:=rt;
  4588. case rt of
  4589. initrtti :
  4590. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4591. fullrtti :
  4592. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4593. else
  4594. internalerror(200108301);
  4595. end;
  4596. end;
  4597. type
  4598. tclasslistitem = class(TLinkedListItem)
  4599. index : longint;
  4600. p : tobjectdef;
  4601. end;
  4602. var
  4603. classtablelist : tlinkedlist;
  4604. tablecount : longint;
  4605. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4606. var
  4607. hp : tclasslistitem;
  4608. begin
  4609. hp:=tclasslistitem(classtablelist.first);
  4610. while assigned(hp) do
  4611. if hp.p=p then
  4612. begin
  4613. searchclasstablelist:=hp;
  4614. exit;
  4615. end
  4616. else
  4617. hp:=tclasslistitem(hp.next);
  4618. searchclasstablelist:=nil;
  4619. end;
  4620. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4621. var
  4622. hp : tclasslistitem;
  4623. begin
  4624. if needs_prop_entry(tsym(sym)) and
  4625. (tsym(sym).typ=varsym) then
  4626. begin
  4627. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4628. internalerror(0206001);
  4629. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4630. if not(assigned(hp)) then
  4631. begin
  4632. hp:=tclasslistitem.create;
  4633. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4634. hp.index:=tablecount;
  4635. classtablelist.concat(hp);
  4636. inc(tablecount);
  4637. end;
  4638. inc(count);
  4639. end;
  4640. end;
  4641. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4642. var
  4643. hp : tclasslistitem;
  4644. begin
  4645. if needs_prop_entry(tsym(sym)) and
  4646. (tsym(sym).typ=varsym) then
  4647. begin
  4648. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4649. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4650. if not(assigned(hp)) then
  4651. internalerror(0206002);
  4652. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4653. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4654. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4655. end;
  4656. end;
  4657. function tobjectdef.generate_field_table : tasmlabel;
  4658. var
  4659. fieldtable,
  4660. classtable : tasmlabel;
  4661. hp : tclasslistitem;
  4662. begin
  4663. classtablelist:=TLinkedList.Create;
  4664. objectlibrary.getdatalabel(fieldtable);
  4665. objectlibrary.getdatalabel(classtable);
  4666. count:=0;
  4667. tablecount:=0;
  4668. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4669. if (cs_create_smart in aktmoduleswitches) then
  4670. rttiList.concat(Tai_cut.Create);
  4671. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4672. rttiList.concat(Tai_label.Create(fieldtable));
  4673. rttiList.concat(Tai_const.Create_16bit(count));
  4674. rttiList.concat(Tai_const_symbol.Create(classtable));
  4675. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4676. { generate the class table }
  4677. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4678. rttiList.concat(Tai_label.Create(classtable));
  4679. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4680. hp:=tclasslistitem(classtablelist.first);
  4681. while assigned(hp) do
  4682. begin
  4683. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4684. hp:=tclasslistitem(hp.next);
  4685. end;
  4686. generate_field_table:=fieldtable;
  4687. classtablelist.free;
  4688. end;
  4689. function tobjectdef.next_free_name_index : longint;
  4690. var
  4691. i : longint;
  4692. begin
  4693. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4694. i:=childof.next_free_name_index
  4695. else
  4696. i:=0;
  4697. count:=0;
  4698. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4699. next_free_name_index:=i+count;
  4700. end;
  4701. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4702. begin
  4703. case objecttype of
  4704. odt_class:
  4705. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4706. odt_object:
  4707. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4708. odt_interfacecom:
  4709. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4710. odt_interfacecorba:
  4711. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4712. else
  4713. exit;
  4714. end;
  4715. { generate the name }
  4716. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4717. rttiList.concat(Tai_string.Create(objrealname^));
  4718. case rt of
  4719. initrtti :
  4720. begin
  4721. rttiList.concat(Tai_const.Create_32bit(size));
  4722. if objecttype in [odt_class,odt_object] then
  4723. begin
  4724. count:=0;
  4725. FRTTIType:=rt;
  4726. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4727. rttiList.concat(Tai_const.Create_32bit(count));
  4728. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4729. end;
  4730. end;
  4731. fullrtti :
  4732. begin
  4733. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4734. rttiList.concat(Tai_const.Create_32bit(0))
  4735. else
  4736. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname));
  4737. { write owner typeinfo }
  4738. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4739. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4740. else
  4741. rttiList.concat(Tai_const.Create_32bit(0));
  4742. { count total number of properties }
  4743. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4744. count:=childof.next_free_name_index
  4745. else
  4746. count:=0;
  4747. { write it }
  4748. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4749. rttiList.concat(Tai_const.Create_16bit(count));
  4750. { write unit name }
  4751. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4752. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4753. { write published properties count }
  4754. count:=0;
  4755. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4756. rttiList.concat(Tai_const.Create_16bit(count));
  4757. { count is used to write nameindex }
  4758. { but we need an offset of the owner }
  4759. { to give each property an own slot }
  4760. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4761. count:=childof.next_free_name_index
  4762. else
  4763. count:=0;
  4764. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4765. end;
  4766. end;
  4767. end;
  4768. function tobjectdef.is_publishable : boolean;
  4769. begin
  4770. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4771. end;
  4772. {****************************************************************************
  4773. TIMPLEMENTEDINTERFACES
  4774. ****************************************************************************}
  4775. type
  4776. tnamemap = class(TNamedIndexItem)
  4777. newname: pstring;
  4778. constructor create(const aname, anewname: string);
  4779. destructor destroy; override;
  4780. end;
  4781. constructor tnamemap.create(const aname, anewname: string);
  4782. begin
  4783. inherited createname(name);
  4784. newname:=stringdup(anewname);
  4785. end;
  4786. destructor tnamemap.destroy;
  4787. begin
  4788. stringdispose(newname);
  4789. inherited destroy;
  4790. end;
  4791. type
  4792. tprocdefstore = class(TNamedIndexItem)
  4793. procdef: tprocdef;
  4794. constructor create(aprocdef: tprocdef);
  4795. end;
  4796. constructor tprocdefstore.create(aprocdef: tprocdef);
  4797. begin
  4798. inherited create;
  4799. procdef:=aprocdef;
  4800. end;
  4801. type
  4802. timplintfentry = class(TNamedIndexItem)
  4803. intf: tobjectdef;
  4804. intfderef : tderef;
  4805. ioffs: longint;
  4806. namemappings: tdictionary;
  4807. procdefs: TIndexArray;
  4808. constructor create(aintf: tobjectdef);
  4809. constructor create_deref(const d:tderef);
  4810. destructor destroy; override;
  4811. end;
  4812. constructor timplintfentry.create(aintf: tobjectdef);
  4813. begin
  4814. inherited create;
  4815. intf:=aintf;
  4816. ioffs:=-1;
  4817. namemappings:=nil;
  4818. procdefs:=nil;
  4819. end;
  4820. constructor timplintfentry.create_deref(const d:tderef);
  4821. begin
  4822. inherited create;
  4823. intf:=nil;
  4824. intfderef:=d;
  4825. ioffs:=-1;
  4826. namemappings:=nil;
  4827. procdefs:=nil;
  4828. end;
  4829. destructor timplintfentry.destroy;
  4830. begin
  4831. if assigned(namemappings) then
  4832. namemappings.free;
  4833. if assigned(procdefs) then
  4834. procdefs.free;
  4835. inherited destroy;
  4836. end;
  4837. constructor timplementedinterfaces.create;
  4838. begin
  4839. finterfaces:=tindexarray.create(1);
  4840. end;
  4841. destructor timplementedinterfaces.destroy;
  4842. begin
  4843. finterfaces.destroy;
  4844. end;
  4845. function timplementedinterfaces.count: longint;
  4846. begin
  4847. count:=finterfaces.count;
  4848. end;
  4849. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4850. begin
  4851. if (intfindex<1) or (intfindex>count) then
  4852. InternalError(200006123);
  4853. end;
  4854. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4855. begin
  4856. checkindex(intfindex);
  4857. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4858. end;
  4859. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  4860. begin
  4861. checkindex(intfindex);
  4862. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  4863. end;
  4864. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  4865. begin
  4866. checkindex(intfindex);
  4867. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  4868. end;
  4869. function timplementedinterfaces.searchintf(def: tdef): longint;
  4870. var
  4871. i: longint;
  4872. begin
  4873. i:=1;
  4874. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4875. if i<=count then
  4876. searchintf:=i
  4877. else
  4878. searchintf:=-1;
  4879. end;
  4880. procedure timplementedinterfaces.deref;
  4881. var
  4882. i: longint;
  4883. begin
  4884. for i:=1 to count do
  4885. with timplintfentry(finterfaces.search(i)) do
  4886. intf:=tobjectdef(intfderef.resolve);
  4887. end;
  4888. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  4889. begin
  4890. finterfaces.insert(timplintfentry.create_deref(d));
  4891. end;
  4892. procedure timplementedinterfaces.addintf(def: tdef);
  4893. begin
  4894. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4895. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4896. internalerror(200006124);
  4897. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4898. end;
  4899. procedure timplementedinterfaces.clearmappings;
  4900. var
  4901. i: longint;
  4902. begin
  4903. for i:=1 to count do
  4904. with timplintfentry(finterfaces.search(i)) do
  4905. begin
  4906. if assigned(namemappings) then
  4907. namemappings.free;
  4908. namemappings:=nil;
  4909. end;
  4910. end;
  4911. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  4912. begin
  4913. checkindex(intfindex);
  4914. with timplintfentry(finterfaces.search(intfindex)) do
  4915. begin
  4916. if not assigned(namemappings) then
  4917. namemappings:=tdictionary.create;
  4918. namemappings.insert(tnamemap.create(name,newname));
  4919. end;
  4920. end;
  4921. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  4922. begin
  4923. checkindex(intfindex);
  4924. if not assigned(nextexist) then
  4925. with timplintfentry(finterfaces.search(intfindex)) do
  4926. begin
  4927. if assigned(namemappings) then
  4928. nextexist:=namemappings.search(name)
  4929. else
  4930. nextexist:=nil;
  4931. end;
  4932. if assigned(nextexist) then
  4933. begin
  4934. getmappings:=tnamemap(nextexist).newname^;
  4935. nextexist:=tnamemap(nextexist).listnext;
  4936. end
  4937. else
  4938. getmappings:='';
  4939. end;
  4940. procedure timplementedinterfaces.clearimplprocs;
  4941. var
  4942. i: longint;
  4943. begin
  4944. for i:=1 to count do
  4945. with timplintfentry(finterfaces.search(i)) do
  4946. begin
  4947. if assigned(procdefs) then
  4948. procdefs.free;
  4949. procdefs:=nil;
  4950. end;
  4951. end;
  4952. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4953. begin
  4954. checkindex(intfindex);
  4955. with timplintfentry(finterfaces.search(intfindex)) do
  4956. begin
  4957. if not assigned(procdefs) then
  4958. procdefs:=tindexarray.create(4);
  4959. procdefs.insert(tprocdefstore.create(procdef));
  4960. end;
  4961. end;
  4962. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4963. begin
  4964. checkindex(intfindex);
  4965. with timplintfentry(finterfaces.search(intfindex)) do
  4966. if assigned(procdefs) then
  4967. implproccount:=procdefs.count
  4968. else
  4969. implproccount:=0;
  4970. end;
  4971. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4972. begin
  4973. checkindex(intfindex);
  4974. with timplintfentry(finterfaces.search(intfindex)) do
  4975. if assigned(procdefs) then
  4976. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4977. else
  4978. internalerror(200006131);
  4979. end;
  4980. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4981. var
  4982. possible: boolean;
  4983. i: longint;
  4984. iiep1: TIndexArray;
  4985. iiep2: TIndexArray;
  4986. begin
  4987. checkindex(intfindex);
  4988. checkindex(remainindex);
  4989. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4990. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4991. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4992. begin
  4993. possible:=true;
  4994. weight:=0;
  4995. end
  4996. else
  4997. begin
  4998. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4999. i:=1;
  5000. while (possible) and (i<=iiep1.count) do
  5001. begin
  5002. possible:=
  5003. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5004. inc(i);
  5005. end;
  5006. if possible then
  5007. weight:=iiep1.count;
  5008. end;
  5009. isimplmergepossible:=possible;
  5010. end;
  5011. {****************************************************************************
  5012. TFORWARDDEF
  5013. ****************************************************************************}
  5014. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5015. var
  5016. oldregisterdef : boolean;
  5017. begin
  5018. { never register the forwarddefs, they are disposed at the
  5019. end of the type declaration block }
  5020. oldregisterdef:=registerdef;
  5021. registerdef:=false;
  5022. inherited create;
  5023. registerdef:=oldregisterdef;
  5024. deftype:=forwarddef;
  5025. tosymname:=stringdup(s);
  5026. forwardpos:=pos;
  5027. end;
  5028. function tforwarddef.gettypename:string;
  5029. begin
  5030. gettypename:='unresolved forward to '+tosymname^;
  5031. end;
  5032. destructor tforwarddef.destroy;
  5033. begin
  5034. if assigned(tosymname) then
  5035. stringdispose(tosymname);
  5036. inherited destroy;
  5037. end;
  5038. {****************************************************************************
  5039. TERRORDEF
  5040. ****************************************************************************}
  5041. constructor terrordef.create;
  5042. begin
  5043. inherited create;
  5044. deftype:=errordef;
  5045. end;
  5046. {$ifdef GDB}
  5047. function terrordef.stabstring : pchar;
  5048. begin
  5049. stabstring:=strpnew('error'+numberstring);
  5050. end;
  5051. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5052. begin
  5053. { No internal error needed, an normal error is already
  5054. thrown }
  5055. end;
  5056. {$endif GDB}
  5057. function terrordef.gettypename:string;
  5058. begin
  5059. gettypename:='<erroneous type>';
  5060. end;
  5061. function terrordef.getmangledparaname:string;
  5062. begin
  5063. getmangledparaname:='error';
  5064. end;
  5065. {****************************************************************************
  5066. GDB Helpers
  5067. ****************************************************************************}
  5068. {$ifdef GDB}
  5069. function typeglobalnumber(const s : string) : string;
  5070. var st : string;
  5071. symt : tsymtable;
  5072. srsym : tsym;
  5073. srsymtable : tsymtable;
  5074. old_make_ref : boolean;
  5075. begin
  5076. old_make_ref:=make_ref;
  5077. make_ref:=false;
  5078. typeglobalnumber := '0';
  5079. srsym := nil;
  5080. if pos('.',s) > 0 then
  5081. begin
  5082. st := copy(s,1,pos('.',s)-1);
  5083. searchsym(st,srsym,srsymtable);
  5084. st := copy(s,pos('.',s)+1,255);
  5085. if assigned(srsym) then
  5086. begin
  5087. if srsym.typ = unitsym then
  5088. begin
  5089. symt := tunitsym(srsym).unitsymtable;
  5090. srsym := tsym(symt.search(st));
  5091. end else srsym := nil;
  5092. end;
  5093. end else st := s;
  5094. if srsym = nil then
  5095. searchsym(st,srsym,srsymtable);
  5096. if (srsym=nil) or
  5097. (srsym.typ<>typesym) then
  5098. begin
  5099. Message(type_e_type_id_expected);
  5100. exit;
  5101. end;
  5102. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  5103. make_ref:=old_make_ref;
  5104. end;
  5105. {$endif GDB}
  5106. {****************************************************************************
  5107. Definition Helpers
  5108. ****************************************************************************}
  5109. procedure reset_global_defs;
  5110. var
  5111. def : tstoreddef;
  5112. {$ifdef debug}
  5113. prevdef : tstoreddef;
  5114. {$endif debug}
  5115. begin
  5116. {$ifdef debug}
  5117. prevdef:=nil;
  5118. {$endif debug}
  5119. {$ifdef GDB}
  5120. pglobaltypecount:=@globaltypecount;
  5121. {$endif GDB}
  5122. def:=firstglobaldef;
  5123. while assigned(def) do
  5124. begin
  5125. {$ifdef GDB}
  5126. if assigned(def.typesym) then
  5127. ttypesym(def.typesym).isusedinstab:=false;
  5128. def.is_def_stab_written:=not_written;
  5129. {$endif GDB}
  5130. if assigned(def.rttitablesym) then
  5131. trttisym(def.rttitablesym).lab := nil;
  5132. if assigned(def.inittablesym) then
  5133. trttisym(def.inittablesym).lab := nil;
  5134. def.localrttilab[initrtti]:=nil;
  5135. def.localrttilab[fullrtti]:=nil;
  5136. {$ifdef debug}
  5137. prevdef:=def;
  5138. {$endif debug}
  5139. def:=def.nextglobal;
  5140. end;
  5141. end;
  5142. function is_interfacecom(def: tdef): boolean;
  5143. begin
  5144. is_interfacecom:=
  5145. assigned(def) and
  5146. (def.deftype=objectdef) and
  5147. (tobjectdef(def).objecttype=odt_interfacecom);
  5148. end;
  5149. function is_interfacecorba(def: tdef): boolean;
  5150. begin
  5151. is_interfacecorba:=
  5152. assigned(def) and
  5153. (def.deftype=objectdef) and
  5154. (tobjectdef(def).objecttype=odt_interfacecorba);
  5155. end;
  5156. function is_interface(def: tdef): boolean;
  5157. begin
  5158. is_interface:=
  5159. assigned(def) and
  5160. (def.deftype=objectdef) and
  5161. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5162. end;
  5163. function is_class(def: tdef): boolean;
  5164. begin
  5165. is_class:=
  5166. assigned(def) and
  5167. (def.deftype=objectdef) and
  5168. (tobjectdef(def).objecttype=odt_class);
  5169. end;
  5170. function is_object(def: tdef): boolean;
  5171. begin
  5172. is_object:=
  5173. assigned(def) and
  5174. (def.deftype=objectdef) and
  5175. (tobjectdef(def).objecttype=odt_object);
  5176. end;
  5177. function is_cppclass(def: tdef): boolean;
  5178. begin
  5179. is_cppclass:=
  5180. assigned(def) and
  5181. (def.deftype=objectdef) and
  5182. (tobjectdef(def).objecttype=odt_cppclass);
  5183. end;
  5184. function is_class_or_interface(def: tdef): boolean;
  5185. begin
  5186. is_class_or_interface:=
  5187. assigned(def) and
  5188. (def.deftype=objectdef) and
  5189. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5190. end;
  5191. end.
  5192. {
  5193. $Log$
  5194. Revision 1.175 2003-10-07 20:43:49 peter
  5195. * Add calling convention in fullprocname when it is specified
  5196. Revision 1.174 2003/10/07 16:06:30 peter
  5197. * tsymlist.def renamed to tsymlist.procdef
  5198. * tsymlist.procdef is now only used to store the procdef
  5199. Revision 1.173 2003/10/06 22:23:41 florian
  5200. + added basic olevariant support
  5201. Revision 1.172 2003/10/05 21:21:52 peter
  5202. * c style array of const generates callparanodes
  5203. * varargs paraloc fixes
  5204. Revision 1.171 2003/10/05 12:56:35 peter
  5205. * don't write procdefs that are released to ppu
  5206. Revision 1.170 2003/10/03 22:00:33 peter
  5207. * parameter alignment fixes
  5208. Revision 1.169 2003/10/02 21:19:42 peter
  5209. * protected visibility fixes
  5210. Revision 1.168 2003/10/01 20:34:49 peter
  5211. * procinfo unit contains tprocinfo
  5212. * cginfo renamed to cgbase
  5213. * moved cgmessage to verbose
  5214. * fixed ppc and sparc compiles
  5215. Revision 1.167 2003/10/01 16:49:05 florian
  5216. * para items are now reversed for pascal calling conventions
  5217. Revision 1.166 2003/10/01 15:32:58 florian
  5218. * fixed FullProcName to handle constructors, destructors and operators correctly
  5219. Revision 1.165 2003/10/01 15:00:02 peter
  5220. * don't write parast,localst debug info for externals
  5221. Revision 1.164 2003/09/23 21:03:35 peter
  5222. * connect parasym to paraitem
  5223. Revision 1.163 2003/09/23 17:56:06 peter
  5224. * locals and paras are allocated in the code generation
  5225. * tvarsym.localloc contains the location of para/local when
  5226. generating code for the current procedure
  5227. Revision 1.162 2003/09/07 22:09:35 peter
  5228. * preparations for different default calling conventions
  5229. * various RA fixes
  5230. Revision 1.161 2003/09/06 22:27:09 florian
  5231. * fixed web bug 2669
  5232. * cosmetic fix in printnode
  5233. * tobjectdef.gettypename implemented
  5234. Revision 1.160 2003/09/03 15:55:01 peter
  5235. * NEWRA branch merged
  5236. Revision 1.159 2003/09/03 11:18:37 florian
  5237. * fixed arm concatcopy
  5238. + arm support in the common compiler sources added
  5239. * moved some generic cg code around
  5240. + tfputype added
  5241. * ...
  5242. Revision 1.158.2.2 2003/08/29 17:28:59 peter
  5243. * next batch of updates
  5244. Revision 1.158.2.1 2003/08/27 19:55:54 peter
  5245. * first tregister patch
  5246. Revision 1.158 2003/08/11 21:18:20 peter
  5247. * start of sparc support for newra
  5248. Revision 1.157 2003/07/08 15:20:56 peter
  5249. * don't allow add/assignments for formaldef
  5250. * formaldef size changed to 0
  5251. Revision 1.156 2003/07/06 21:50:33 jonas
  5252. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  5253. so that it doesn't include ebp and esp anymore
  5254. Revision 1.155 2003/07/06 15:31:21 daniel
  5255. * Fixed register allocator. *Lots* of fixes.
  5256. Revision 1.154 2003/07/02 22:18:04 peter
  5257. * paraloc splitted in callerparaloc,calleeparaloc
  5258. * sparc calling convention updates
  5259. Revision 1.153 2003/06/25 18:31:23 peter
  5260. * sym,def resolving partly rewritten to support also parent objects
  5261. not directly available through the uses clause
  5262. Revision 1.152 2003/06/17 16:34:44 jonas
  5263. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  5264. * renamed all_intregisters to paramanager.get_volatile_registers_int(pocall_default) and made it
  5265. processor dependent
  5266. Revision 1.151 2003/06/08 11:41:21 peter
  5267. * set parast.next to the owner of the procdef
  5268. Revision 1.150 2003/06/07 20:26:32 peter
  5269. * re-resolving added instead of reloading from ppu
  5270. * tderef object added to store deref info for resolving
  5271. Revision 1.149 2003/06/05 20:05:55 peter
  5272. * removed changesettype because that will change the definition
  5273. of the setdef forever and can result in a different between
  5274. original interface and current implementation definition
  5275. Revision 1.148 2003/06/03 13:01:59 daniel
  5276. * Register allocator finished
  5277. Revision 1.147 2003/06/02 22:55:28 florian
  5278. * classes and interfaces can be stored in integer registers
  5279. Revision 1.146 2003/05/26 21:17:18 peter
  5280. * procinlinenode removed
  5281. * aktexit2label removed, fast exit removed
  5282. + tcallnode.inlined_pass_2 added
  5283. Revision 1.145 2003/05/25 11:34:17 peter
  5284. * methodpointer self pushing fixed
  5285. Revision 1.144 2003/05/15 18:58:53 peter
  5286. * removed selfpointer_offset, vmtpointer_offset
  5287. * tvarsym.adjusted_address
  5288. * address in localsymtable is now in the real direction
  5289. * removed some obsolete globals
  5290. Revision 1.143 2003/05/13 08:13:16 jonas
  5291. * patch from Peter for rtti symbols
  5292. Revision 1.142 2003/05/11 21:37:03 peter
  5293. * moved implicit exception frame from ncgutil to psub
  5294. * constructor/destructor helpers moved from cobj/ncgutil to psub
  5295. Revision 1.141 2003/05/09 17:47:03 peter
  5296. * self moved to hidden parameter
  5297. * removed hdisposen,hnewn,selfn
  5298. Revision 1.140 2003/05/05 14:53:16 peter
  5299. * vs_hidden replaced by is_hidden boolean
  5300. Revision 1.139 2003/05/01 07:59:43 florian
  5301. * introduced defaultordconsttype to decribe the default size of ordinal constants
  5302. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  5303. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  5304. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  5305. Revision 1.138 2003/04/27 11:21:34 peter
  5306. * aktprocdef renamed to current_procdef
  5307. * procinfo renamed to current_procinfo
  5308. * procinfo will now be stored in current_module so it can be
  5309. cleaned up properly
  5310. * gen_main_procsym changed to create_main_proc and release_main_proc
  5311. to also generate a tprocinfo structure
  5312. * fixed unit implicit initfinal
  5313. Revision 1.137 2003/04/27 07:29:51 peter
  5314. * current_procdef cleanup, current_procdef is now always nil when parsing
  5315. a new procdef declaration
  5316. * aktprocsym removed
  5317. * lexlevel removed, use symtable.symtablelevel instead
  5318. * implicit init/final code uses the normal genentry/genexit
  5319. * funcret state checking updated for new funcret handling
  5320. Revision 1.136 2003/04/25 20:59:35 peter
  5321. * removed funcretn,funcretsym, function result is now in varsym
  5322. and aliases for result and function name are added using absolutesym
  5323. * vs_hidden parameter for funcret passed in parameter
  5324. * vs_hidden fixes
  5325. * writenode changed to printnode and released from extdebug
  5326. * -vp option added to generate a tree.log with the nodetree
  5327. * nicer printnode for statements, callnode
  5328. Revision 1.135 2003/04/23 20:16:04 peter
  5329. + added currency support based on int64
  5330. + is_64bit for use in cg units instead of is_64bitint
  5331. * removed cgmessage from n386add, replace with internalerrors
  5332. Revision 1.134 2003/04/23 12:35:34 florian
  5333. * fixed several issues with powerpc
  5334. + applied a patch from Jonas for nested function calls (PowerPC only)
  5335. * ...
  5336. Revision 1.133 2003/04/10 17:57:53 peter
  5337. * vs_hidden released
  5338. Revision 1.132 2003/03/18 16:25:50 peter
  5339. * no itnernalerror for errordef.concatstabto()
  5340. Revision 1.131 2003/03/17 16:54:41 peter
  5341. * support DefaultHandler and anonymous inheritance fixed
  5342. for message methods
  5343. Revision 1.130 2003/03/17 15:54:22 peter
  5344. * store symoptions also for procdef
  5345. * check symoptions (private,public) when calculating possible
  5346. overload candidates
  5347. Revision 1.129 2003/02/19 22:00:14 daniel
  5348. * Code generator converted to new register notation
  5349. - Horribily outdated todo.txt removed
  5350. Revision 1.128 2003/02/02 19:25:54 carl
  5351. * Several bugfixes for m68k target (register alloc., opcode emission)
  5352. + VIS target
  5353. + Generic add more complete (still not verified)
  5354. Revision 1.127 2003/01/21 14:36:44 pierre
  5355. * set sizes needs to be passes in bits not bytes to stabs info
  5356. Revision 1.126 2003/01/16 22:11:33 peter
  5357. * fixed tprocdef.is_addressonly
  5358. Revision 1.125 2003/01/15 01:44:33 peter
  5359. * merged methodpointer fixes from 1.0.x
  5360. Revision 1.124 2003/01/09 21:52:37 peter
  5361. * merged some verbosity options.
  5362. * V_LineInfo is a verbosity flag to include line info
  5363. Revision 1.123 2003/01/06 21:16:52 peter
  5364. * po_addressonly added to retrieve the address of a methodpointer
  5365. only, this is used for @tclass.method which has no self pointer
  5366. Revision 1.122 2003/01/05 15:54:15 florian
  5367. + added proper support of type = type <type>; for simple types
  5368. Revision 1.121 2003/01/05 13:36:53 florian
  5369. * x86-64 compiles
  5370. + very basic support for float128 type (x86-64 only)
  5371. Revision 1.120 2003/01/02 19:49:00 peter
  5372. * update self parameter only for methodpointer and methods
  5373. Revision 1.119 2002/12/29 18:25:59 peter
  5374. * tprocdef.gettypename implemented
  5375. Revision 1.118 2002/12/27 15:23:09 peter
  5376. * write class methods in fullname
  5377. Revision 1.117 2002/12/15 19:34:31 florian
  5378. + some front end stuff for vs_hidden added
  5379. Revision 1.116 2002/12/15 11:26:02 peter
  5380. * ignore vs_hidden parameters when choosing overloaded proc
  5381. Revision 1.115 2002/12/07 14:27:09 carl
  5382. * 3% memory optimization
  5383. * changed some types
  5384. + added type checking with different size for call node and for
  5385. parameters
  5386. Revision 1.114 2002/12/01 22:05:27 carl
  5387. * no more warnings for structures over 32K since this is
  5388. handled correctly in this version of the compiler.
  5389. Revision 1.113 2002/11/27 20:04:09 peter
  5390. * tvarsym.get_push_size replaced by paramanager.push_size
  5391. Revision 1.112 2002/11/25 21:05:53 carl
  5392. * several mistakes fixed in message files
  5393. Revision 1.111 2002/11/25 18:43:33 carl
  5394. - removed the invalid if <> checking (Delphi is strange on this)
  5395. + implemented abstract warning on instance creation of class with
  5396. abstract methods.
  5397. * some error message cleanups
  5398. Revision 1.110 2002/11/25 17:43:24 peter
  5399. * splitted defbase in defutil,symutil,defcmp
  5400. * merged isconvertable and is_equal into compare_defs(_ext)
  5401. * made operator search faster by walking the list only once
  5402. Revision 1.109 2002/11/23 22:50:06 carl
  5403. * some small speed optimizations
  5404. + added several new warnings/hints
  5405. Revision 1.108 2002/11/22 22:48:10 carl
  5406. * memory optimization with tconstsym (1.5%)
  5407. Revision 1.107 2002/11/19 16:21:29 pierre
  5408. * correct several stabs generation problems
  5409. Revision 1.106 2002/11/18 17:31:59 peter
  5410. * pass proccalloption to ret_in_xxx and push_xxx functions
  5411. Revision 1.105 2002/11/17 16:31:57 carl
  5412. * memory optimization (3-4%) : cleanup of tai fields,
  5413. cleanup of tdef and tsym fields.
  5414. * make it work for m68k
  5415. Revision 1.104 2002/11/16 19:53:18 carl
  5416. * avoid Range check errors
  5417. Revision 1.103 2002/11/15 16:29:09 peter
  5418. * fixed rtti for int64 (merged)
  5419. Revision 1.102 2002/11/15 01:58:54 peter
  5420. * merged changes from 1.0.7 up to 04-11
  5421. - -V option for generating bug report tracing
  5422. - more tracing for option parsing
  5423. - errors for cdecl and high()
  5424. - win32 import stabs
  5425. - win32 records<=8 are returned in eax:edx (turned off by default)
  5426. - heaptrc update
  5427. - more info for temp management in .s file with EXTDEBUG
  5428. Revision 1.101 2002/11/09 15:31:02 carl
  5429. + align RTTI tables
  5430. Revision 1.100 2002/10/19 15:09:25 peter
  5431. + tobjectdef.members_need_inittable that is used to generate only the
  5432. inittable when it is really used. This saves a lot of useless calls
  5433. to fpc_finalize when destroying classes
  5434. Revision 1.99 2002/10/07 21:30:27 peter
  5435. * removed obsolete rangecheck stuff
  5436. Revision 1.98 2002/10/05 15:14:26 peter
  5437. * getparamangeldname for errordef
  5438. Revision 1.97 2002/10/05 12:43:28 carl
  5439. * fixes for Delphi 6 compilation
  5440. (warning : Some features do not work under Delphi)
  5441. Revision 1.96 2002/09/27 21:13:29 carl
  5442. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  5443. Revision 1.95 2002/09/16 09:31:10 florian
  5444. * fixed currency size
  5445. Revision 1.94 2002/09/09 17:34:15 peter
  5446. * tdicationary.replace added to replace and item in a dictionary. This
  5447. is only allowed for the same name
  5448. * varsyms are inserted in symtable before the types are parsed. This
  5449. fixes the long standing "var longint : longint" bug
  5450. - consume_idlist and idstringlist removed. The loops are inserted
  5451. at the callers place and uses the symtable for duplicate id checking
  5452. Revision 1.93 2002/09/07 15:25:07 peter
  5453. * old logs removed and tabs fixed
  5454. Revision 1.92 2002/09/05 19:29:42 peter
  5455. * memdebug enhancements
  5456. Revision 1.91 2002/08/25 19:25:20 peter
  5457. * sym.insert_in_data removed
  5458. * symtable.insertvardata/insertconstdata added
  5459. * removed insert_in_data call from symtable.insert, it needs to be
  5460. called separatly. This allows to deref the address calculation
  5461. * procedures now calculate the parast addresses after the procedure
  5462. directives are parsed. This fixes the cdecl parast problem
  5463. * push_addr_param has an extra argument that specifies if cdecl is used
  5464. or not
  5465. Revision 1.90 2002/08/18 20:06:25 peter
  5466. * inlining is now also allowed in interface
  5467. * renamed write/load to ppuwrite/ppuload
  5468. * tnode storing in ppu
  5469. * nld,ncon,nbas are already updated for storing in ppu
  5470. Revision 1.89 2002/08/11 15:28:00 florian
  5471. + support of explicit type case <any ordinal type>->pointer
  5472. (delphi mode only)
  5473. Revision 1.88 2002/08/11 14:32:28 peter
  5474. * renamed current_library to objectlibrary
  5475. Revision 1.87 2002/08/11 13:24:13 peter
  5476. * saving of asmsymbols in ppu supported
  5477. * asmsymbollist global is removed and moved into a new class
  5478. tasmlibrarydata that will hold the info of a .a file which
  5479. corresponds with a single module. Added librarydata to tmodule
  5480. to keep the library info stored for the module. In the future the
  5481. objectfiles will also be stored to the tasmlibrarydata class
  5482. * all getlabel/newasmsymbol and friends are moved to the new class
  5483. Revision 1.86 2002/08/09 07:33:03 florian
  5484. * a couple of interface related fixes
  5485. Revision 1.85 2002/07/23 09:51:24 daniel
  5486. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  5487. are worth comitting.
  5488. Revision 1.84 2002/07/20 11:57:57 florian
  5489. * types.pas renamed to defbase.pas because D6 contains a types
  5490. unit so this would conflicts if D6 programms are compiled
  5491. + Willamette/SSE2 instructions to assembler added
  5492. Revision 1.83 2002/07/11 14:41:30 florian
  5493. * start of the new generic parameter handling
  5494. Revision 1.82 2002/07/07 09:52:32 florian
  5495. * powerpc target fixed, very simple units can be compiled
  5496. * some basic stuff for better callparanode handling, far from being finished
  5497. Revision 1.81 2002/07/01 18:46:26 peter
  5498. * internal linker
  5499. * reorganized aasm layer
  5500. Revision 1.80 2002/07/01 16:23:54 peter
  5501. * cg64 patch
  5502. * basics for currency
  5503. * asnode updates for class and interface (not finished)
  5504. Revision 1.79 2002/05/18 13:34:18 peter
  5505. * readded missing revisions
  5506. Revision 1.78 2002/05/16 19:46:44 carl
  5507. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  5508. + try to fix temp allocation (still in ifdef)
  5509. + generic constructor calls
  5510. + start of tassembler / tmodulebase class cleanup
  5511. Revision 1.76 2002/05/12 16:53:10 peter
  5512. * moved entry and exitcode to ncgutil and cgobj
  5513. * foreach gets extra argument for passing local data to the
  5514. iterator function
  5515. * -CR checks also class typecasts at runtime by changing them
  5516. into as
  5517. * fixed compiler to cycle with the -CR option
  5518. * fixed stabs with elf writer, finally the global variables can
  5519. be watched
  5520. * removed a lot of routines from cga unit and replaced them by
  5521. calls to cgobj
  5522. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  5523. u32bit then the other is typecasted also to u32bit without giving
  5524. a rangecheck warning/error.
  5525. * fixed pascal calling method with reversing also the high tree in
  5526. the parast, detected by tcalcst3 test
  5527. Revision 1.75 2002/04/25 20:16:39 peter
  5528. * moved more routines from cga/n386util
  5529. Revision 1.74 2002/04/23 19:16:35 peter
  5530. * add pinline unit that inserts compiler supported functions using
  5531. one or more statements
  5532. * moved finalize and setlength from ninl to pinline
  5533. Revision 1.73 2002/04/21 19:02:05 peter
  5534. * removed newn and disposen nodes, the code is now directly
  5535. inlined from pexpr
  5536. * -an option that will write the secondpass nodes to the .s file, this
  5537. requires EXTDEBUG define to actually write the info
  5538. * fixed various internal errors and crashes due recent code changes
  5539. Revision 1.72 2002/04/20 21:32:25 carl
  5540. + generic FPC_CHECKPOINTER
  5541. + first parameter offset in stack now portable
  5542. * rename some constants
  5543. + move some cpu stuff to other units
  5544. - remove unused constents
  5545. * fix stacksize for some targets
  5546. * fix generic size problems which depend now on EXTEND_SIZE constant
  5547. }