symdef.pas 176 KB

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