symdef.pas 201 KB

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