symdef.pas 181 KB

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