symdef.pas 205 KB

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