symdef.pas 209 KB

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