symdef.pas 202 KB

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