symdef.pas 177 KB

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