symdef.pas 207 KB

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