symdef.pas 173 KB

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