symdef.pas 197 KB

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