symdef.pas 172 KB

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