symdef.pas 179 KB

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