symdef.pas 208 KB

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