symdef.pas 178 KB

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