symdef.pas 200 KB

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