symdef.pas 167 KB

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