symdef.pas 204 KB

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