symdef.pas 189 KB

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