symdef.pas 167 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620
  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. {$ifdef i386}
  478. usedregisters : longint;
  479. {$else}
  480. usedregisters : tregisterset;
  481. {$endif}
  482. {$endif newcg}
  483. constructor create;
  484. constructor load;
  485. destructor destroy;override;
  486. procedure write;override;
  487. procedure deref;override;
  488. function getsymtable(t:tgetsymtable):tsymtable;override;
  489. function haspara:boolean;
  490. function mangledname : string;
  491. procedure setmangledname(const s : string);
  492. procedure load_references;
  493. function write_references : boolean;
  494. function fullprocname:string;
  495. function fullprocnamewithret:string;
  496. function cplusplusmangledname : string;
  497. { debug }
  498. {$ifdef GDB}
  499. function stabstring : pchar;override;
  500. procedure concatstabto(asmlist : taasmoutput);override;
  501. {$endif GDB}
  502. end;
  503. tstringdef = class(tstoreddef)
  504. string_typ : tstringtype;
  505. len : longint;
  506. constructor createshort(l : byte);
  507. constructor loadshort;
  508. constructor createlong(l : longint);
  509. constructor loadlong;
  510. constructor createansi(l : longint);
  511. constructor loadansi;
  512. constructor createwide(l : longint);
  513. constructor loadwide;
  514. function stringtypname:string;
  515. function size : longint;override;
  516. procedure write;override;
  517. function gettypename:string;override;
  518. function is_publishable : boolean;override;
  519. { debug }
  520. {$ifdef GDB}
  521. function stabstring : pchar;override;
  522. procedure concatstabto(asmlist : taasmoutput);override;
  523. {$endif GDB}
  524. { init/final }
  525. function needs_inittable : boolean;override;
  526. { rtti }
  527. procedure write_rtti_data;override;
  528. end;
  529. tenumdef = class(tstoreddef)
  530. rangenr,
  531. minval,
  532. maxval : longint;
  533. has_jumps : boolean;
  534. firstenum : tsym; {tenumsym}
  535. basedef : tenumdef;
  536. constructor create;
  537. constructor create_subrange(_basedef:tenumdef;_min,_max:longint);
  538. constructor load;
  539. destructor destroy;override;
  540. procedure write;override;
  541. procedure deref;override;
  542. function gettypename:string;override;
  543. function is_publishable : boolean;override;
  544. procedure calcsavesize;
  545. procedure setmax(_max:longint);
  546. procedure setmin(_min:longint);
  547. function min:longint;
  548. function max:longint;
  549. function getrangecheckstring:string;
  550. procedure genrangecheck;
  551. { debug }
  552. {$ifdef GDB}
  553. function stabstring : pchar;override;
  554. {$endif GDB}
  555. { rtti }
  556. procedure write_child_rtti_data;override;
  557. procedure write_rtti_data;override;
  558. private
  559. procedure correct_owner_symtable;
  560. end;
  561. tsetdef = class(tstoreddef)
  562. elementtype : ttype;
  563. settype : tsettype;
  564. constructor create(const t:ttype;high : longint);
  565. constructor load;
  566. destructor destroy;override;
  567. procedure write;override;
  568. procedure deref;override;
  569. function gettypename:string;override;
  570. function is_publishable : boolean;override;
  571. { debug }
  572. {$ifdef GDB}
  573. function stabstring : pchar;override;
  574. procedure concatstabto(asmlist : taasmoutput);override;
  575. {$endif GDB}
  576. { rtti }
  577. procedure write_rtti_data;override;
  578. procedure write_child_rtti_data;override;
  579. end;
  580. var
  581. aktobjectdef : tobjectdef; { used for private functions check !! }
  582. firstglobaldef, { linked list of all globals defs }
  583. lastglobaldef : tstoreddef; { used to reset stabs/ranges }
  584. {$ifdef GDB}
  585. { for STAB debugging }
  586. globaltypecount : word;
  587. pglobaltypecount : pword;
  588. {$endif GDB}
  589. { default types }
  590. generrortype, { error in definition }
  591. voidpointertype, { pointer for Void-Pointerdef }
  592. charpointertype, { pointer for Char-Pointerdef }
  593. voidfarpointertype,
  594. cformaltype, { unique formal definition }
  595. voidtype, { Pointer to Void (procedure) }
  596. cchartype, { Pointer to Char }
  597. cwidechartype, { Pointer to WideChar }
  598. booltype, { pointer to boolean type }
  599. u8bittype, { Pointer to 8-Bit unsigned }
  600. u16bittype, { Pointer to 16-Bit unsigned }
  601. u32bittype, { Pointer to 32-Bit unsigned }
  602. s32bittype, { Pointer to 32-Bit signed }
  603. cu64bittype, { pointer to 64 bit unsigned def }
  604. cs64bittype, { pointer to 64 bit signed def, }
  605. s32floattype, { pointer for realconstn }
  606. s64floattype, { pointer for realconstn }
  607. s80floattype, { pointer to type of temp. floats }
  608. s32fixedtype, { pointer to type of temp. fixed }
  609. cshortstringtype, { pointer to type of short string const }
  610. clongstringtype, { pointer to type of long string const }
  611. cansistringtype, { pointer to type of ansi string const }
  612. cwidestringtype, { pointer to type of wide string const }
  613. openshortstringtype, { pointer to type of an open shortstring,
  614. needed for readln() }
  615. openchararraytype, { pointer to type of an open array of char,
  616. needed for readln() }
  617. cfiletype, { get the same definition for all file }
  618. { used for stabs }
  619. cvarianttype, { we use only one variant def }
  620. pvmttype : ttype; { type of classrefs, used for stabs }
  621. class_tobject : tobjectdef; { pointer to the anchestor of all classes }
  622. interface_iunknown : tobjectdef; { KAZ: pointer to the ancestor }
  623. rec_tguid : trecorddef; { KAZ: pointer to the TGUID type }
  624. { of all interfaces }
  625. const
  626. {$ifdef i386}
  627. pbestrealtype : ^ttype = @s80floattype;
  628. {$endif}
  629. {$ifdef m68k}
  630. pbestrealtype : ^ttype = @s64floattype;
  631. {$endif}
  632. {$ifdef alpha}
  633. pbestrealtype : ^ttype = @s64floattype;
  634. {$endif}
  635. {$ifdef powerpc}
  636. pbestrealtype : ^ttype = @s64floattype;
  637. {$endif}
  638. {$ifdef ia64}
  639. pbestrealtype : ^ttype = @s64floattype;
  640. {$endif}
  641. {$ifdef GDB}
  642. { GDB Helpers }
  643. function typeglobalnumber(const s : string) : string;
  644. {$endif GDB}
  645. { should be in the types unit, but the types unit uses the node stuff :( }
  646. function is_interfacecom(def: tdef): boolean;
  647. function is_interfacecorba(def: tdef): boolean;
  648. function is_interface(def: tdef): boolean;
  649. function is_object(def: tdef): boolean;
  650. function is_class(def: tdef): boolean;
  651. function is_cppclass(def: tdef): boolean;
  652. function is_class_or_interface(def: tdef): boolean;
  653. procedure reset_global_defs;
  654. implementation
  655. uses
  656. {$ifdef Delphi}
  657. sysutils,
  658. {$else Delphi}
  659. strings,
  660. {$endif Delphi}
  661. { global }
  662. verbose,
  663. { target }
  664. systems,cpuinfo,
  665. { symtable }
  666. symsym,symtable,
  667. types,
  668. { ppu }
  669. ppu,symppu,
  670. { module }
  671. {$ifdef GDB}
  672. gdb,
  673. {$endif GDB}
  674. fmodule,
  675. { other }
  676. gendef
  677. ;
  678. {****************************************************************************
  679. Helpers
  680. ****************************************************************************}
  681. {$ifdef GDB}
  682. procedure forcestabto(asmlist : taasmoutput; pd : tdef);
  683. begin
  684. if tstoreddef(pd).is_def_stab_written = not_written then
  685. begin
  686. if assigned(pd.typesym) then
  687. ttypesym(pd.typesym).isusedinstab := true;
  688. tstoreddef(pd).concatstabto(asmlist);
  689. end;
  690. end;
  691. {$endif GDB}
  692. {****************************************************************************
  693. TDEF (base class for definitions)
  694. ****************************************************************************}
  695. constructor tstoreddef.create;
  696. begin
  697. inherited create;
  698. savesize := 0;
  699. has_rtti:=false;
  700. has_inittable:=false;
  701. {$ifdef EXTDEBUG}
  702. fileinfo := aktfilepos;
  703. {$endif}
  704. if registerdef then
  705. symtablestack.registerdef(self);
  706. {$ifdef GDB}
  707. is_def_stab_written := not_written;
  708. globalnb := 0;
  709. {$endif GDB}
  710. if assigned(lastglobaldef) then
  711. begin
  712. lastglobaldef.nextglobal := self;
  713. previousglobal:=lastglobaldef;
  714. end
  715. else
  716. begin
  717. firstglobaldef := self;
  718. previousglobal := nil;
  719. end;
  720. lastglobaldef := self;
  721. nextglobal := nil;
  722. end;
  723. {$ifdef MEMDEBUG}
  724. var
  725. manglenamesize : longint;
  726. {$endif}
  727. constructor tstoreddef.loaddef;
  728. begin
  729. inherited create;
  730. has_rtti:=false;
  731. has_inittable:=false;
  732. {$ifdef EXTDEBUG}
  733. fillchar(fileinfo,sizeof(fileinfo),0);
  734. {$endif}
  735. {$ifdef GDB}
  736. is_def_stab_written := not_written;
  737. globalnb := 0;
  738. {$endif GDB}
  739. if assigned(lastglobaldef) then
  740. begin
  741. lastglobaldef.nextglobal := self;
  742. previousglobal:=lastglobaldef;
  743. end
  744. else
  745. begin
  746. firstglobaldef := self;
  747. previousglobal:=nil;
  748. end;
  749. lastglobaldef := self;
  750. nextglobal := nil;
  751. { load }
  752. indexnr:=readword;
  753. typesym:=ttypesym(readderef);
  754. end;
  755. destructor tstoreddef.destroy;
  756. begin
  757. { first element ? }
  758. if not(assigned(previousglobal)) then
  759. begin
  760. firstglobaldef := nextglobal;
  761. if assigned(firstglobaldef) then
  762. firstglobaldef.previousglobal:=nil;
  763. end
  764. else
  765. begin
  766. { remove reference in the element before }
  767. previousglobal.nextglobal:=nextglobal;
  768. end;
  769. { last element ? }
  770. if not(assigned(nextglobal)) then
  771. begin
  772. lastglobaldef := previousglobal;
  773. if assigned(lastglobaldef) then
  774. lastglobaldef.nextglobal:=nil;
  775. end
  776. else
  777. nextglobal.previousglobal:=previousglobal;
  778. previousglobal:=nil;
  779. nextglobal:=nil;
  780. end;
  781. function tstoreddef.is_in_current : boolean;
  782. var
  783. p : tsymtable;
  784. begin
  785. p:=owner;
  786. is_in_current:=false;
  787. while assigned(p) do
  788. begin
  789. if (p=tsymtable(current_module.globalsymtable)) or (p=tsymtable(current_module.localsymtable))
  790. or (p.symtabletype in [globalsymtable,staticsymtable]) then
  791. begin
  792. is_in_current:=true;
  793. exit;
  794. end
  795. else if p.symtabletype in [localsymtable,parasymtable,objectsymtable] then
  796. begin
  797. if assigned(p.defowner) then
  798. p:=tobjectdef(p.defowner).owner
  799. else
  800. exit;
  801. end
  802. else
  803. exit;
  804. end;
  805. end;
  806. procedure tstoreddef.writedef;
  807. begin
  808. writeword(indexnr);
  809. writederef(typesym);
  810. {$ifdef GDB}
  811. if globalnb = 0 then
  812. begin
  813. if assigned(owner) then
  814. globalnb := owner.getnewtypecount
  815. else
  816. begin
  817. globalnb := PGlobalTypeCount^;
  818. Inc(PGlobalTypeCount^);
  819. end;
  820. end;
  821. {$endif GDB}
  822. end;
  823. function tstoreddef.size : longint;
  824. begin
  825. size:=savesize;
  826. end;
  827. function tstoreddef.alignment : longint;
  828. begin
  829. { normal alignment by default }
  830. alignment:=0;
  831. end;
  832. {$ifdef GDB}
  833. procedure tstoreddef.set_globalnb;
  834. begin
  835. globalnb :=PGlobalTypeCount^;
  836. inc(PglobalTypeCount^);
  837. end;
  838. function tstoreddef.stabstring : pchar;
  839. begin
  840. stabstring := strpnew('t'+numberstring+';');
  841. end;
  842. function tstoreddef.numberstring : string;
  843. var table : tsymtable;
  844. begin
  845. {formal def have no type !}
  846. if deftype = formaldef then
  847. begin
  848. numberstring := tstoreddef(voidtype.def).numberstring;
  849. exit;
  850. end;
  851. if (not assigned(typesym)) or (not ttypesym(typesym).isusedinstab) then
  852. begin
  853. {set even if debuglist is not defined}
  854. if assigned(typesym) then
  855. ttypesym(typesym).isusedinstab := true;
  856. if assigned(debuglist) and (is_def_stab_written = not_written) then
  857. concatstabto(debuglist);
  858. end;
  859. if not (cs_gdb_dbx in aktglobalswitches) then
  860. begin
  861. if globalnb = 0 then
  862. set_globalnb;
  863. numberstring := tostr(globalnb);
  864. end
  865. else
  866. begin
  867. if globalnb = 0 then
  868. begin
  869. if assigned(owner) then
  870. globalnb := owner.getnewtypecount
  871. else
  872. begin
  873. globalnb := PGlobalTypeCount^;
  874. Inc(PGlobalTypeCount^);
  875. end;
  876. end;
  877. if assigned(typesym) then
  878. begin
  879. table := ttypesym(typesym).owner;
  880. if table.unitid > 0 then
  881. numberstring := '('+tostr(table.unitid)+','+tostr(tstoreddef(ttypesym(typesym).restype.def).globalnb)+')'
  882. else
  883. numberstring := tostr(globalnb);
  884. exit;
  885. end;
  886. numberstring := tostr(globalnb);
  887. end;
  888. end;
  889. function tstoreddef.allstabstring : pchar;
  890. var stabchar : string[2];
  891. ss,st : pchar;
  892. sname : string;
  893. sym_line_no : longint;
  894. begin
  895. ss := stabstring;
  896. getmem(st,strlen(ss)+512);
  897. stabchar := 't';
  898. if deftype in tagtypes then
  899. stabchar := 'Tt';
  900. if assigned(typesym) then
  901. begin
  902. sname := ttypesym(typesym).name;
  903. sym_line_no:=ttypesym(typesym).fileinfo.line;
  904. end
  905. else
  906. begin
  907. sname := ' ';
  908. sym_line_no:=0;
  909. end;
  910. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  911. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  912. allstabstring := strnew(st);
  913. freemem(st,strlen(ss)+512);
  914. strdispose(ss);
  915. end;
  916. procedure tstoreddef.concatstabto(asmlist : taasmoutput);
  917. var stab_str : pchar;
  918. begin
  919. if ((typesym = nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  920. and (is_def_stab_written = not_written) then
  921. begin
  922. If cs_gdb_dbx in aktglobalswitches then
  923. begin
  924. { otherwise you get two of each def }
  925. If assigned(typesym) then
  926. begin
  927. if ttypesym(typesym).typ=symconst.typesym then
  928. ttypesym(typesym).isusedinstab:=true;
  929. if (ttypesym(typesym).owner = nil) or
  930. ((ttypesym(typesym).owner.symtabletype = globalsymtable) and
  931. tglobalsymtable(ttypesym(typesym).owner).dbx_count_ok) then
  932. begin
  933. {with DBX we get the definition from the other objects }
  934. is_def_stab_written := written;
  935. exit;
  936. end;
  937. end;
  938. end;
  939. { to avoid infinite loops }
  940. is_def_stab_written := being_written;
  941. stab_str := allstabstring;
  942. asmList.concat(Tai_stabs.Create(stab_str));
  943. is_def_stab_written := written;
  944. end;
  945. end;
  946. {$endif GDB}
  947. { rtti generation }
  948. procedure tstoreddef.generate_rtti;
  949. begin
  950. if not has_rtti then
  951. begin
  952. has_rtti:=true;
  953. getdatalabel(rtti_label);
  954. write_child_rtti_data;
  955. rttiList.concat(Tai_symbol.Create(rtti_label,0));
  956. write_rtti_data;
  957. rttiList.concat(Tai_symbol_end.Create(rtti_label));
  958. end;
  959. end;
  960. function tstoreddef.get_rtti_label : string;
  961. begin
  962. generate_rtti;
  963. get_rtti_label:=rtti_label.name;
  964. end;
  965. { init table handling }
  966. function tstoreddef.needs_inittable : boolean;
  967. begin
  968. needs_inittable:=false;
  969. end;
  970. procedure tstoreddef.generate_inittable;
  971. begin
  972. has_inittable:=true;
  973. getdatalabel(inittable_label);
  974. write_child_init_data;
  975. rttiList.concat(Tai_label.Create(inittable_label));
  976. write_init_data;
  977. end;
  978. procedure tstoreddef.write_init_data;
  979. begin
  980. write_rtti_data;
  981. end;
  982. procedure tstoreddef.write_child_init_data;
  983. begin
  984. write_child_rtti_data;
  985. end;
  986. function tstoreddef.get_inittable_label : tasmlabel;
  987. begin
  988. if not(has_inittable) then
  989. generate_inittable;
  990. get_inittable_label:=inittable_label;
  991. end;
  992. procedure tstoreddef.write_rtti_name;
  993. var
  994. str : string;
  995. begin
  996. { name }
  997. if assigned(typesym) then
  998. begin
  999. str:=ttypesym(typesym).realname;
  1000. rttiList.concat(Tai_string.Create(chr(length(str))+str));
  1001. end
  1002. else
  1003. rttiList.concat(Tai_string.Create(#0))
  1004. end;
  1005. { returns true, if the definition can be published }
  1006. function tstoreddef.is_publishable : boolean;
  1007. begin
  1008. is_publishable:=false;
  1009. end;
  1010. procedure tstoreddef.write_rtti_data;
  1011. begin
  1012. end;
  1013. procedure tstoreddef.write_child_rtti_data;
  1014. begin
  1015. end;
  1016. function tstoreddef.is_intregable : boolean;
  1017. begin
  1018. is_intregable:=false;
  1019. case deftype of
  1020. pointerdef,
  1021. enumdef,
  1022. procvardef :
  1023. is_intregable:=true;
  1024. orddef :
  1025. case torddef(self).typ of
  1026. bool8bit,bool16bit,bool32bit,
  1027. u8bit,u16bit,u32bit,
  1028. s8bit,s16bit,s32bit:
  1029. is_intregable:=true;
  1030. end;
  1031. setdef:
  1032. is_intregable:=(tsetdef(self).settype=smallset);
  1033. end;
  1034. end;
  1035. function tstoreddef.is_fpuregable : boolean;
  1036. begin
  1037. is_fpuregable:=(deftype=floatdef);
  1038. end;
  1039. {****************************************************************************
  1040. TPARALINKEDLIST
  1041. ****************************************************************************}
  1042. function tparalinkedlist.count:longint;
  1043. begin
  1044. { You must use tabstractprocdef.minparacount and .maxparacount instead }
  1045. internalerror(432432978);
  1046. count:=0;
  1047. end;
  1048. {****************************************************************************
  1049. Tstringdef
  1050. ****************************************************************************}
  1051. constructor tstringdef.createshort(l : byte);
  1052. begin
  1053. inherited create;
  1054. string_typ:=st_shortstring;
  1055. deftype:=stringdef;
  1056. len:=l;
  1057. savesize:=len+1;
  1058. end;
  1059. constructor tstringdef.loadshort;
  1060. begin
  1061. inherited loaddef;
  1062. string_typ:=st_shortstring;
  1063. deftype:=stringdef;
  1064. len:=readbyte;
  1065. savesize:=len+1;
  1066. end;
  1067. constructor tstringdef.createlong(l : longint);
  1068. begin
  1069. inherited create;
  1070. string_typ:=st_longstring;
  1071. deftype:=stringdef;
  1072. len:=l;
  1073. savesize:=target_info.size_of_pointer;
  1074. end;
  1075. constructor tstringdef.loadlong;
  1076. begin
  1077. inherited loaddef;
  1078. deftype:=stringdef;
  1079. string_typ:=st_longstring;
  1080. len:=readlong;
  1081. savesize:=target_info.size_of_pointer;
  1082. end;
  1083. constructor tstringdef.createansi(l : longint);
  1084. begin
  1085. inherited create;
  1086. string_typ:=st_ansistring;
  1087. deftype:=stringdef;
  1088. len:=l;
  1089. savesize:=target_info.size_of_pointer;
  1090. end;
  1091. constructor tstringdef.loadansi;
  1092. begin
  1093. inherited loaddef;
  1094. deftype:=stringdef;
  1095. string_typ:=st_ansistring;
  1096. len:=readlong;
  1097. savesize:=target_info.size_of_pointer;
  1098. end;
  1099. constructor tstringdef.createwide(l : longint);
  1100. begin
  1101. inherited create;
  1102. string_typ:=st_widestring;
  1103. deftype:=stringdef;
  1104. len:=l;
  1105. savesize:=target_info.size_of_pointer;
  1106. end;
  1107. constructor tstringdef.loadwide;
  1108. begin
  1109. inherited loaddef;
  1110. deftype:=stringdef;
  1111. string_typ:=st_widestring;
  1112. len:=readlong;
  1113. savesize:=target_info.size_of_pointer;
  1114. end;
  1115. function tstringdef.stringtypname:string;
  1116. const
  1117. typname:array[tstringtype] of string[8]=('',
  1118. 'SHORTSTR','LONGSTR','ANSISTR','WIDESTR'
  1119. );
  1120. begin
  1121. stringtypname:=typname[string_typ];
  1122. end;
  1123. function tstringdef.size : longint;
  1124. begin
  1125. size:=savesize;
  1126. end;
  1127. procedure tstringdef.write;
  1128. begin
  1129. inherited writedef;
  1130. if string_typ=st_shortstring then
  1131. writebyte(len)
  1132. else
  1133. writelong(len);
  1134. case string_typ of
  1135. st_shortstring : current_ppu^.writeentry(ibshortstringdef);
  1136. st_longstring : current_ppu^.writeentry(iblongstringdef);
  1137. st_ansistring : current_ppu^.writeentry(ibansistringdef);
  1138. st_widestring : current_ppu^.writeentry(ibwidestringdef);
  1139. end;
  1140. end;
  1141. {$ifdef GDB}
  1142. function tstringdef.stabstring : pchar;
  1143. var
  1144. bytest,charst,longst : string;
  1145. begin
  1146. case string_typ of
  1147. st_shortstring:
  1148. begin
  1149. charst := typeglobalnumber('char');
  1150. { this is what I found in stabs.texinfo but
  1151. gdb 4.12 for go32 doesn't understand that !! }
  1152. {$IfDef GDBknowsstrings}
  1153. stabstring := strpnew('n'+charst+';'+tostr(len));
  1154. {$else}
  1155. bytest := typeglobalnumber('byte');
  1156. stabstring := strpnew('s'+tostr(len+1)+'length:'+bytest
  1157. +',0,8;st:ar'+bytest
  1158. +';1;'+tostr(len)+';'+charst+',8,'+tostr(len*8)+';;');
  1159. {$EndIf}
  1160. end;
  1161. st_longstring:
  1162. begin
  1163. charst := typeglobalnumber('char');
  1164. { this is what I found in stabs.texinfo but
  1165. gdb 4.12 for go32 doesn't understand that !! }
  1166. {$IfDef GDBknowsstrings}
  1167. stabstring := strpnew('n'+charst+';'+tostr(len));
  1168. {$else}
  1169. bytest := typeglobalnumber('byte');
  1170. longst := typeglobalnumber('longint');
  1171. stabstring := strpnew('s'+tostr(len+5)+'length:'+longst
  1172. +',0,32;dummy:'+bytest+',32,8;st:ar'+bytest
  1173. +';1;'+tostr(len)+';'+charst+',40,'+tostr(len*8)+';;');
  1174. {$EndIf}
  1175. end;
  1176. st_ansistring:
  1177. begin
  1178. { an ansi string looks like a pchar easy !! }
  1179. stabstring:=strpnew('*'+typeglobalnumber('char'));
  1180. end;
  1181. st_widestring:
  1182. begin
  1183. { an ansi string looks like a pchar easy !! }
  1184. stabstring:=strpnew('*'+typeglobalnumber('char'));
  1185. end;
  1186. end;
  1187. end;
  1188. procedure tstringdef.concatstabto(asmlist : taasmoutput);
  1189. begin
  1190. inherited concatstabto(asmlist);
  1191. end;
  1192. {$endif GDB}
  1193. function tstringdef.needs_inittable : boolean;
  1194. begin
  1195. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  1196. end;
  1197. function tstringdef.gettypename : string;
  1198. const
  1199. names : array[tstringtype] of string[20] = ('',
  1200. 'ShortString','LongString','AnsiString','WideString');
  1201. begin
  1202. gettypename:=names[string_typ];
  1203. end;
  1204. procedure tstringdef.write_rtti_data;
  1205. begin
  1206. case string_typ of
  1207. st_ansistring:
  1208. begin
  1209. rttiList.concat(Tai_const.Create_8bit(tkAString));
  1210. write_rtti_name;
  1211. end;
  1212. st_widestring:
  1213. begin
  1214. rttiList.concat(Tai_const.Create_8bit(tkWString));
  1215. write_rtti_name;
  1216. end;
  1217. st_longstring:
  1218. begin
  1219. rttiList.concat(Tai_const.Create_8bit(tkLString));
  1220. write_rtti_name;
  1221. end;
  1222. st_shortstring:
  1223. begin
  1224. rttiList.concat(Tai_const.Create_8bit(tkSString));
  1225. write_rtti_name;
  1226. rttiList.concat(Tai_const.Create_8bit(len));
  1227. end;
  1228. end;
  1229. end;
  1230. function tstringdef.is_publishable : boolean;
  1231. begin
  1232. is_publishable:=true;
  1233. end;
  1234. {****************************************************************************
  1235. TENUMDEF
  1236. ****************************************************************************}
  1237. constructor tenumdef.create;
  1238. begin
  1239. inherited create;
  1240. deftype:=enumdef;
  1241. minval:=0;
  1242. maxval:=0;
  1243. calcsavesize;
  1244. has_jumps:=false;
  1245. basedef:=nil;
  1246. rangenr:=0;
  1247. firstenum:=nil;
  1248. correct_owner_symtable;
  1249. end;
  1250. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:longint);
  1251. begin
  1252. inherited create;
  1253. deftype:=enumdef;
  1254. minval:=_min;
  1255. maxval:=_max;
  1256. basedef:=_basedef;
  1257. calcsavesize;
  1258. has_jumps:=false;
  1259. rangenr:=0;
  1260. firstenum:=basedef.firstenum;
  1261. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1262. firstenum:=tenumsym(firstenum).nextenum;
  1263. correct_owner_symtable;
  1264. end;
  1265. constructor tenumdef.load;
  1266. begin
  1267. inherited loaddef;
  1268. deftype:=enumdef;
  1269. basedef:=tenumdef(readderef);
  1270. minval:=readlong;
  1271. maxval:=readlong;
  1272. savesize:=readlong;
  1273. has_jumps:=false;
  1274. firstenum:=Nil;
  1275. end;
  1276. procedure tenumdef.calcsavesize;
  1277. begin
  1278. if (aktpackenum=4) or (min<0) or (max>65535) then
  1279. savesize:=4
  1280. else
  1281. if (aktpackenum=2) or (min<0) or (max>255) then
  1282. savesize:=2
  1283. else
  1284. savesize:=1;
  1285. end;
  1286. procedure tenumdef.setmax(_max:longint);
  1287. begin
  1288. maxval:=_max;
  1289. calcsavesize;
  1290. end;
  1291. procedure tenumdef.setmin(_min:longint);
  1292. begin
  1293. minval:=_min;
  1294. calcsavesize;
  1295. end;
  1296. function tenumdef.min:longint;
  1297. begin
  1298. min:=minval;
  1299. end;
  1300. function tenumdef.max:longint;
  1301. begin
  1302. max:=maxval;
  1303. end;
  1304. procedure tenumdef.deref;
  1305. begin
  1306. inherited deref;
  1307. resolvedef(tdef(basedef));
  1308. end;
  1309. destructor tenumdef.destroy;
  1310. begin
  1311. inherited destroy;
  1312. end;
  1313. procedure tenumdef.write;
  1314. begin
  1315. inherited writedef;
  1316. writederef(basedef);
  1317. writelong(min);
  1318. writelong(max);
  1319. writelong(savesize);
  1320. current_ppu^.writeentry(ibenumdef);
  1321. end;
  1322. function tenumdef.getrangecheckstring : string;
  1323. begin
  1324. if (cs_create_smart in aktmoduleswitches) then
  1325. getrangecheckstring:='R_'+current_module.modulename^+tostr(rangenr)
  1326. else
  1327. getrangecheckstring:='R_'+tostr(rangenr);
  1328. end;
  1329. procedure tenumdef.genrangecheck;
  1330. begin
  1331. if rangenr=0 then
  1332. begin
  1333. { generate two constant for bounds }
  1334. getlabelnr(rangenr);
  1335. if (cs_create_smart in aktmoduleswitches) then
  1336. dataSegment.concat(Tai_symbol.Createname_global(getrangecheckstring,8))
  1337. else
  1338. dataSegment.concat(Tai_symbol.Createname(getrangecheckstring,8));
  1339. dataSegment.concat(Tai_const.Create_32bit(min));
  1340. dataSegment.concat(Tai_const.Create_32bit(max));
  1341. end;
  1342. end;
  1343. { used for enumdef because the symbols are
  1344. inserted in the owner symtable }
  1345. procedure tenumdef.correct_owner_symtable;
  1346. var
  1347. st : tsymtable;
  1348. begin
  1349. if assigned(owner) and
  1350. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  1351. begin
  1352. owner.defindex.deleteindex(self);
  1353. st:=owner;
  1354. while (st.symtabletype in [recordsymtable,objectsymtable]) do
  1355. st:=st.next;
  1356. st.registerdef(self);
  1357. end;
  1358. end;
  1359. {$ifdef GDB}
  1360. function tenumdef.stabstring : pchar;
  1361. var st,st2 : pchar;
  1362. p : tenumsym;
  1363. s : string;
  1364. memsize : word;
  1365. begin
  1366. memsize := memsizeinc;
  1367. getmem(st,memsize);
  1368. { we can specify the size with @s<size>; prefix PM }
  1369. if savesize <> target_info.size_of_longint then
  1370. strpcopy(st,'@s'+tostr(savesize*8)+';e')
  1371. else
  1372. strpcopy(st,'e');
  1373. p := tenumsym(firstenum);
  1374. while assigned(p) do
  1375. begin
  1376. s :=p.name+':'+tostr(p.value)+',';
  1377. { place for the ending ';' also }
  1378. if (strlen(st)+length(s)+1<memsize) then
  1379. strpcopy(strend(st),s)
  1380. else
  1381. begin
  1382. getmem(st2,memsize+memsizeinc);
  1383. strcopy(st2,st);
  1384. freemem(st,memsize);
  1385. st := st2;
  1386. memsize := memsize+memsizeinc;
  1387. strpcopy(strend(st),s);
  1388. end;
  1389. p := p.nextenum;
  1390. end;
  1391. strpcopy(strend(st),';');
  1392. stabstring := strnew(st);
  1393. freemem(st,memsize);
  1394. end;
  1395. {$endif GDB}
  1396. procedure tenumdef.write_child_rtti_data;
  1397. begin
  1398. if assigned(basedef) then
  1399. basedef.get_rtti_label;
  1400. end;
  1401. procedure tenumdef.write_rtti_data;
  1402. var
  1403. hp : tenumsym;
  1404. begin
  1405. rttiList.concat(Tai_const.Create_8bit(tkEnumeration));
  1406. write_rtti_name;
  1407. case savesize of
  1408. 1:
  1409. rttiList.concat(Tai_const.Create_8bit(otUByte));
  1410. 2:
  1411. rttiList.concat(Tai_const.Create_8bit(otUWord));
  1412. 4:
  1413. rttiList.concat(Tai_const.Create_8bit(otULong));
  1414. end;
  1415. rttiList.concat(Tai_const.Create_32bit(min));
  1416. rttiList.concat(Tai_const.Create_32bit(max));
  1417. if assigned(basedef) then
  1418. rttiList.concat(Tai_const_symbol.Createname(basedef.get_rtti_label))
  1419. else
  1420. rttiList.concat(Tai_const.Create_32bit(0));
  1421. hp:=tenumsym(firstenum);
  1422. while assigned(hp) do
  1423. begin
  1424. rttiList.concat(Tai_const.Create_8bit(length(hp.name)));
  1425. rttiList.concat(Tai_string.Create(lower(hp.name)));
  1426. hp:=hp.nextenum;
  1427. end;
  1428. rttiList.concat(Tai_const.Create_8bit(0));
  1429. end;
  1430. function tenumdef.is_publishable : boolean;
  1431. begin
  1432. is_publishable:=true;
  1433. end;
  1434. function tenumdef.gettypename : string;
  1435. begin
  1436. gettypename:='<enumeration type>';
  1437. end;
  1438. {****************************************************************************
  1439. TORDDEF
  1440. ****************************************************************************}
  1441. constructor torddef.create(t : tbasetype;v,b : longint);
  1442. begin
  1443. inherited create;
  1444. deftype:=orddef;
  1445. low:=v;
  1446. high:=b;
  1447. typ:=t;
  1448. rangenr:=0;
  1449. setsize;
  1450. end;
  1451. constructor torddef.load;
  1452. begin
  1453. inherited loaddef;
  1454. deftype:=orddef;
  1455. typ:=tbasetype(readbyte);
  1456. low:=readlong;
  1457. high:=readlong;
  1458. rangenr:=0;
  1459. setsize;
  1460. end;
  1461. procedure torddef.setsize;
  1462. begin
  1463. if typ=uauto then
  1464. begin
  1465. { generate a unsigned range if high<0 and low>=0 }
  1466. if (low>=0) and (high<0) then
  1467. begin
  1468. savesize:=4;
  1469. typ:=u32bit;
  1470. end
  1471. else if (low>=0) and (high<=255) then
  1472. begin
  1473. savesize:=1;
  1474. typ:=u8bit;
  1475. end
  1476. else if (low>=-128) and (high<=127) then
  1477. begin
  1478. savesize:=1;
  1479. typ:=s8bit;
  1480. end
  1481. else if (low>=0) and (high<=65536) then
  1482. begin
  1483. savesize:=2;
  1484. typ:=u16bit;
  1485. end
  1486. else if (low>=-32768) and (high<=32767) then
  1487. begin
  1488. savesize:=2;
  1489. typ:=s16bit;
  1490. end
  1491. else
  1492. begin
  1493. savesize:=4;
  1494. typ:=s32bit;
  1495. end;
  1496. end
  1497. else
  1498. begin
  1499. case typ of
  1500. u8bit,s8bit,
  1501. uchar,bool8bit:
  1502. savesize:=1;
  1503. u16bit,s16bit,
  1504. bool16bit,uwidechar:
  1505. savesize:=2;
  1506. s32bit,u32bit,
  1507. bool32bit:
  1508. savesize:=4;
  1509. u64bit,s64bit:
  1510. savesize:=8;
  1511. else
  1512. savesize:=0;
  1513. end;
  1514. end;
  1515. { there are no entrys for range checking }
  1516. rangenr:=0;
  1517. end;
  1518. function torddef.getrangecheckstring : string;
  1519. begin
  1520. if (cs_create_smart in aktmoduleswitches) then
  1521. getrangecheckstring:='R_'+current_module.modulename^+tostr(rangenr)
  1522. else
  1523. getrangecheckstring:='R_'+tostr(rangenr);
  1524. end;
  1525. procedure torddef.genrangecheck;
  1526. var
  1527. rangechecksize : longint;
  1528. begin
  1529. if rangenr=0 then
  1530. begin
  1531. if low<=high then
  1532. rangechecksize:=8
  1533. else
  1534. rangechecksize:=16;
  1535. { generate two constant for bounds }
  1536. getlabelnr(rangenr);
  1537. if (cs_create_smart in aktmoduleswitches) then
  1538. dataSegment.concat(Tai_symbol.Createname_global(getrangecheckstring,rangechecksize))
  1539. else
  1540. dataSegment.concat(Tai_symbol.Createname(getrangecheckstring,rangechecksize));
  1541. if low<=high then
  1542. begin
  1543. dataSegment.concat(Tai_const.Create_32bit(low));
  1544. dataSegment.concat(Tai_const.Create_32bit(high));
  1545. end
  1546. { for u32bit we need two bounds }
  1547. else
  1548. begin
  1549. dataSegment.concat(Tai_const.Create_32bit(low));
  1550. dataSegment.concat(Tai_const.Create_32bit($7fffffff));
  1551. dataSegment.concat(Tai_const.Create_32bit(longint($80000000)));
  1552. dataSegment.concat(Tai_const.Create_32bit(high));
  1553. end;
  1554. end;
  1555. end;
  1556. procedure torddef.write;
  1557. begin
  1558. inherited writedef;
  1559. writebyte(byte(typ));
  1560. writelong(low);
  1561. writelong(high);
  1562. current_ppu^.writeentry(iborddef);
  1563. end;
  1564. {$ifdef GDB}
  1565. function torddef.stabstring : pchar;
  1566. begin
  1567. case typ of
  1568. uvoid : stabstring := strpnew(numberstring+';');
  1569. {GDB 4.12 for go32 doesn't like boolean as range for 0 to 1 !!!}
  1570. {$ifdef Use_integer_types_for_boolean}
  1571. bool8bit,
  1572. bool16bit,
  1573. bool32bit : stabstring := strpnew('r'+numberstring+';0;255;');
  1574. {$else : not Use_integer_types_for_boolean}
  1575. bool8bit : stabstring := strpnew('-21;');
  1576. bool16bit : stabstring := strpnew('-22;');
  1577. bool32bit : stabstring := strpnew('-23;');
  1578. u64bit : stabstring := strpnew('-32;');
  1579. s64bit : stabstring := strpnew('-31;');
  1580. {$endif not Use_integer_types_for_boolean}
  1581. { u32bit : stabstring := strpnew('r'+
  1582. s32bittype^.numberstring+';0;-1;'); }
  1583. else
  1584. stabstring := strpnew('r'+tstoreddef(s32bittype.def).numberstring+';'+tostr(low)+';'+tostr(high)+';');
  1585. end;
  1586. end;
  1587. {$endif GDB}
  1588. procedure torddef.write_rtti_data;
  1589. procedure dointeger;
  1590. const
  1591. trans : array[uchar..bool8bit] of byte =
  1592. (otUByte,otUByte,otUWord,otULong,otSByte,otSWord,otSLong,otUByte);
  1593. begin
  1594. write_rtti_name;
  1595. rttiList.concat(Tai_const.Create_8bit(byte(trans[typ])));
  1596. rttiList.concat(Tai_const.Create_32bit(low));
  1597. rttiList.concat(Tai_const.Create_32bit(high));
  1598. end;
  1599. begin
  1600. case typ of
  1601. s64bit :
  1602. begin
  1603. rttiList.concat(Tai_const.Create_8bit(tkInt64));
  1604. write_rtti_name;
  1605. { low }
  1606. rttiList.concat(Tai_const.Create_32bit($0));
  1607. rttiList.concat(Tai_const.Create_32bit($8000));
  1608. { high }
  1609. rttiList.concat(Tai_const.Create_32bit($ffff));
  1610. rttiList.concat(Tai_const.Create_32bit($7fff));
  1611. end;
  1612. u64bit :
  1613. begin
  1614. rttiList.concat(Tai_const.Create_8bit(tkQWord));
  1615. write_rtti_name;
  1616. { low }
  1617. rttiList.concat(Tai_const.Create_32bit($0));
  1618. rttiList.concat(Tai_const.Create_32bit($0));
  1619. { high }
  1620. rttiList.concat(Tai_const.Create_32bit($0));
  1621. rttiList.concat(Tai_const.Create_32bit($8000));
  1622. end;
  1623. bool8bit:
  1624. begin
  1625. rttiList.concat(Tai_const.Create_8bit(tkBool));
  1626. dointeger;
  1627. end;
  1628. uchar:
  1629. begin
  1630. rttiList.concat(Tai_const.Create_8bit(tkChar));
  1631. dointeger;
  1632. end;
  1633. uwidechar:
  1634. begin
  1635. rttiList.concat(Tai_const.Create_8bit(tkWChar));
  1636. dointeger;
  1637. end;
  1638. else
  1639. begin
  1640. rttiList.concat(Tai_const.Create_8bit(tkInteger));
  1641. dointeger;
  1642. end;
  1643. end;
  1644. end;
  1645. function torddef.is_publishable : boolean;
  1646. begin
  1647. is_publishable:=typ in [uchar..bool8bit];
  1648. end;
  1649. function torddef.gettypename : string;
  1650. const
  1651. names : array[tbasetype] of string[20] = ('<unknown type>',
  1652. 'untyped','Char','Byte','Word','DWord','ShortInt',
  1653. 'SmallInt','LongInt','Boolean','WordBool',
  1654. 'LongBool','QWord','Int64','WideChar');
  1655. begin
  1656. gettypename:=names[typ];
  1657. end;
  1658. {****************************************************************************
  1659. TFLOATDEF
  1660. ****************************************************************************}
  1661. constructor tfloatdef.create(t : tfloattype);
  1662. begin
  1663. inherited create;
  1664. deftype:=floatdef;
  1665. typ:=t;
  1666. setsize;
  1667. end;
  1668. constructor tfloatdef.load;
  1669. begin
  1670. inherited loaddef;
  1671. deftype:=floatdef;
  1672. typ:=tfloattype(readbyte);
  1673. setsize;
  1674. end;
  1675. procedure tfloatdef.setsize;
  1676. begin
  1677. case typ of
  1678. s32real : savesize:=4;
  1679. s64real : savesize:=8;
  1680. s80real : savesize:=extended_size;
  1681. s64comp : savesize:=8;
  1682. else
  1683. savesize:=0;
  1684. end;
  1685. end;
  1686. procedure tfloatdef.write;
  1687. begin
  1688. inherited writedef;
  1689. writebyte(byte(typ));
  1690. current_ppu^.writeentry(ibfloatdef);
  1691. end;
  1692. {$ifdef GDB}
  1693. function tfloatdef.stabstring : pchar;
  1694. begin
  1695. case typ of
  1696. s32real,
  1697. s64real : stabstring := strpnew('r'+
  1698. tstoreddef(s32bittype.def).numberstring+';'+tostr(savesize)+';0;');
  1699. { found this solution in stabsread.c from GDB v4.16 }
  1700. s64comp : stabstring := strpnew('r'+
  1701. tstoreddef(s32bittype.def).numberstring+';-'+tostr(savesize)+';0;');
  1702. {$ifdef i386}
  1703. { under dos at least you must give a size of twelve instead of 10 !! }
  1704. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  1705. s80real : stabstring := strpnew('r'+tstoreddef(s32bittype.def).numberstring+';12;0;');
  1706. {$endif i386}
  1707. else
  1708. internalerror(10005);
  1709. end;
  1710. end;
  1711. {$endif GDB}
  1712. procedure tfloatdef.write_rtti_data;
  1713. const
  1714. {tfloattype = (s32real,s64real,s80real,s64bit);}
  1715. translate : array[tfloattype] of byte =
  1716. (ftSingle,ftDouble,ftExtended,ftComp);
  1717. begin
  1718. rttiList.concat(Tai_const.Create_8bit(tkFloat));
  1719. write_rtti_name;
  1720. rttiList.concat(Tai_const.Create_8bit(translate[typ]));
  1721. end;
  1722. function tfloatdef.is_publishable : boolean;
  1723. begin
  1724. is_publishable:=true;
  1725. end;
  1726. function tfloatdef.gettypename : string;
  1727. const
  1728. names : array[tfloattype] of string[20] = (
  1729. 'Single','Double','Extended','Comp');
  1730. begin
  1731. gettypename:=names[typ];
  1732. end;
  1733. {****************************************************************************
  1734. TFILEDEF
  1735. ****************************************************************************}
  1736. constructor tfiledef.createtext;
  1737. begin
  1738. inherited create;
  1739. deftype:=filedef;
  1740. filetyp:=ft_text;
  1741. typedfiletype.reset;
  1742. setsize;
  1743. end;
  1744. constructor tfiledef.createuntyped;
  1745. begin
  1746. inherited create;
  1747. deftype:=filedef;
  1748. filetyp:=ft_untyped;
  1749. typedfiletype.reset;
  1750. setsize;
  1751. end;
  1752. constructor tfiledef.createtyped(const tt : ttype);
  1753. begin
  1754. inherited create;
  1755. deftype:=filedef;
  1756. filetyp:=ft_typed;
  1757. typedfiletype:=tt;
  1758. setsize;
  1759. end;
  1760. constructor tfiledef.load;
  1761. begin
  1762. inherited loaddef;
  1763. deftype:=filedef;
  1764. filetyp:=tfiletyp(readbyte);
  1765. if filetyp=ft_typed then
  1766. typedfiletype.load
  1767. else
  1768. typedfiletype.reset;
  1769. setsize;
  1770. end;
  1771. procedure tfiledef.deref;
  1772. begin
  1773. inherited deref;
  1774. if filetyp=ft_typed then
  1775. typedfiletype.resolve;
  1776. end;
  1777. procedure tfiledef.setsize;
  1778. begin
  1779. case filetyp of
  1780. ft_text :
  1781. savesize:=572;
  1782. ft_typed,
  1783. ft_untyped :
  1784. savesize:=316;
  1785. end;
  1786. end;
  1787. procedure tfiledef.write;
  1788. begin
  1789. inherited writedef;
  1790. writebyte(byte(filetyp));
  1791. if filetyp=ft_typed then
  1792. typedfiletype.write;
  1793. current_ppu^.writeentry(ibfiledef);
  1794. end;
  1795. {$ifdef GDB}
  1796. function tfiledef.stabstring : pchar;
  1797. begin
  1798. {$IfDef GDBknowsfiles}
  1799. case filetyp of
  1800. ft_typed :
  1801. stabstring := strpnew('d'+typedfiletype.def.numberstring{+';'});
  1802. ft_untyped :
  1803. stabstring := strpnew('d'+voiddef.numberstring{+';'});
  1804. ft_text :
  1805. stabstring := strpnew('d'+cchartype^.numberstring{+';'});
  1806. end;
  1807. {$Else}
  1808. {based on
  1809. FileRec = Packed Record
  1810. Handle,
  1811. Mode,
  1812. RecSize : longint;
  1813. _private : array[1..32] of byte;
  1814. UserData : array[1..16] of byte;
  1815. name : array[0..255] of char;
  1816. End; }
  1817. { the buffer part is still missing !! (PM) }
  1818. { but the string could become too long !! }
  1819. stabstring := strpnew('s'+tostr(savesize)+
  1820. 'HANDLE:'+typeglobalnumber('longint')+',0,32;'+
  1821. 'MODE:'+typeglobalnumber('longint')+',32,32;'+
  1822. 'RECSIZE:'+typeglobalnumber('longint')+',64,32;'+
  1823. '_PRIVATE:ar'+typeglobalnumber('word')+';1;32;'+typeglobalnumber('byte')
  1824. +',96,256;'+
  1825. 'USERDATA:ar'+typeglobalnumber('word')+';1;16;'+typeglobalnumber('byte')
  1826. +',352,128;'+
  1827. 'NAME:ar'+typeglobalnumber('word')+';0;255;'+typeglobalnumber('char')
  1828. +',480,2048;;');
  1829. {$EndIf}
  1830. end;
  1831. procedure tfiledef.concatstabto(asmlist : taasmoutput);
  1832. begin
  1833. { most file defs are unnamed !!! }
  1834. if ((typesym = nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1835. (is_def_stab_written = not_written) then
  1836. begin
  1837. if assigned(typedfiletype.def) then
  1838. forcestabto(asmlist,typedfiletype.def);
  1839. inherited concatstabto(asmlist);
  1840. end;
  1841. end;
  1842. {$endif GDB}
  1843. function tfiledef.gettypename : string;
  1844. begin
  1845. case filetyp of
  1846. ft_untyped:
  1847. gettypename:='File';
  1848. ft_typed:
  1849. gettypename:='File Of '+typedfiletype.def.typename;
  1850. ft_text:
  1851. gettypename:='Text'
  1852. end;
  1853. end;
  1854. {****************************************************************************
  1855. TVARIANTDEF
  1856. ****************************************************************************}
  1857. constructor tvariantdef.create;
  1858. begin
  1859. inherited create;
  1860. deftype:=variantdef;
  1861. setsize;
  1862. end;
  1863. constructor tvariantdef.load;
  1864. begin
  1865. inherited loaddef;
  1866. deftype:=variantdef;
  1867. setsize;
  1868. end;
  1869. procedure tvariantdef.write;
  1870. begin
  1871. inherited writedef;
  1872. current_ppu^.writeentry(ibvariantdef);
  1873. end;
  1874. procedure tvariantdef.setsize;
  1875. begin
  1876. savesize:=16;
  1877. end;
  1878. procedure tvariantdef.write_rtti_data;
  1879. begin
  1880. rttiList.concat(Tai_const.Create_8bit(tkVariant));
  1881. end;
  1882. function tvariantdef.needs_inittable : boolean;
  1883. begin
  1884. needs_inittable:=true;
  1885. end;
  1886. {****************************************************************************
  1887. TPOINTERDEF
  1888. ****************************************************************************}
  1889. constructor tpointerdef.create(const tt : ttype);
  1890. begin
  1891. inherited create;
  1892. deftype:=pointerdef;
  1893. pointertype:=tt;
  1894. is_far:=false;
  1895. savesize:=target_info.size_of_pointer;
  1896. end;
  1897. constructor tpointerdef.createfar(const tt : ttype);
  1898. begin
  1899. inherited create;
  1900. deftype:=pointerdef;
  1901. pointertype:=tt;
  1902. is_far:=true;
  1903. savesize:=target_info.size_of_pointer;
  1904. end;
  1905. constructor tpointerdef.load;
  1906. begin
  1907. inherited loaddef;
  1908. deftype:=pointerdef;
  1909. pointertype.load;
  1910. is_far:=(readbyte<>0);
  1911. savesize:=target_info.size_of_pointer;
  1912. end;
  1913. procedure tpointerdef.deref;
  1914. begin
  1915. inherited deref;
  1916. pointertype.resolve;
  1917. end;
  1918. procedure tpointerdef.write;
  1919. begin
  1920. inherited writedef;
  1921. pointertype.write;
  1922. writebyte(byte(is_far));
  1923. current_ppu^.writeentry(ibpointerdef);
  1924. end;
  1925. {$ifdef GDB}
  1926. function tpointerdef.stabstring : pchar;
  1927. begin
  1928. stabstring := strpnew('*'+tstoreddef(pointertype.def).numberstring);
  1929. end;
  1930. procedure tpointerdef.concatstabto(asmlist : taasmoutput);
  1931. var st,nb : string;
  1932. sym_line_no : longint;
  1933. begin
  1934. if assigned(pointertype.def) and
  1935. (pointertype.def.deftype=forwarddef) then
  1936. exit;
  1937. if ( (typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1938. (is_def_stab_written = not_written) then
  1939. begin
  1940. is_def_stab_written := being_written;
  1941. if assigned(pointertype.def) and
  1942. (pointertype.def.deftype in [recorddef,objectdef]) then
  1943. begin
  1944. nb:=tstoreddef(pointertype.def).numberstring;
  1945. {to avoid infinite recursion in record with next-like fields }
  1946. if tstoreddef(pointertype.def).is_def_stab_written = being_written then
  1947. begin
  1948. if assigned(pointertype.def.typesym) then
  1949. begin
  1950. if assigned(typesym) then
  1951. begin
  1952. st := ttypesym(typesym).name;
  1953. sym_line_no:=ttypesym(typesym).fileinfo.line;
  1954. end
  1955. else
  1956. begin
  1957. st := ' ';
  1958. sym_line_no:=0;
  1959. end;
  1960. st := '"'+st+':t'+numberstring+'=*'+nb
  1961. +'=xs'+pointertype.def.typesym.name+':",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0';
  1962. asmList.concat(Tai_stabs.Create(strpnew(st)));
  1963. end;
  1964. end
  1965. else
  1966. begin
  1967. is_def_stab_written := not_written;
  1968. inherited concatstabto(asmlist);
  1969. end;
  1970. is_def_stab_written := written;
  1971. end
  1972. else
  1973. begin
  1974. if assigned(pointertype.def) then
  1975. forcestabto(asmlist,pointertype.def);
  1976. is_def_stab_written := not_written;
  1977. inherited concatstabto(asmlist);
  1978. end;
  1979. end;
  1980. end;
  1981. {$endif GDB}
  1982. function tpointerdef.gettypename : string;
  1983. begin
  1984. if is_far then
  1985. gettypename:='^'+pointertype.def.typename+';far'
  1986. else
  1987. gettypename:='^'+pointertype.def.typename;
  1988. end;
  1989. {****************************************************************************
  1990. TCLASSREFDEF
  1991. ****************************************************************************}
  1992. constructor tclassrefdef.create(const t:ttype);
  1993. begin
  1994. inherited create(t);
  1995. deftype:=classrefdef;
  1996. end;
  1997. constructor tclassrefdef.load;
  1998. begin
  1999. { be careful, tclassdefref inherits from tpointerdef }
  2000. inherited loaddef;
  2001. deftype:=classrefdef;
  2002. pointertype.load;
  2003. is_far:=false;
  2004. savesize:=target_info.size_of_pointer;
  2005. end;
  2006. procedure tclassrefdef.write;
  2007. begin
  2008. { be careful, tclassdefref inherits from tpointerdef }
  2009. inherited writedef;
  2010. pointertype.write;
  2011. current_ppu^.writeentry(ibclassrefdef);
  2012. end;
  2013. {$ifdef GDB}
  2014. function tclassrefdef.stabstring : pchar;
  2015. begin
  2016. stabstring:=strpnew(tstoreddef(pvmttype.def).numberstring+';');
  2017. end;
  2018. procedure tclassrefdef.concatstabto(asmlist : taasmoutput);
  2019. begin
  2020. inherited concatstabto(asmlist);
  2021. end;
  2022. {$endif GDB}
  2023. function tclassrefdef.gettypename : string;
  2024. begin
  2025. gettypename:='Class Of '+pointertype.def.typename;
  2026. end;
  2027. {***************************************************************************
  2028. TSETDEF
  2029. ***************************************************************************}
  2030. { For i386 smallsets work,
  2031. for m68k there are problems
  2032. can be test by compiling with -dusesmallset PM }
  2033. {$ifdef i386}
  2034. {$define usesmallset}
  2035. {$endif i386}
  2036. constructor tsetdef.create(const t:ttype;high : longint);
  2037. begin
  2038. inherited create;
  2039. deftype:=setdef;
  2040. elementtype:=t;
  2041. {$ifdef usesmallset}
  2042. { small sets only working for i386 PM }
  2043. if high<32 then
  2044. begin
  2045. settype:=smallset;
  2046. {$ifdef testvarsets}
  2047. if aktsetalloc=0 THEN { $PACKSET Fixed?}
  2048. {$endif}
  2049. savesize:=Sizeof(longint)
  2050. {$ifdef testvarsets}
  2051. else {No, use $PACKSET VALUE for rounding}
  2052. savesize:=aktsetalloc*((high+aktsetalloc*8-1) DIV (aktsetalloc*8))
  2053. {$endif}
  2054. ;
  2055. end
  2056. else
  2057. {$endif usesmallset}
  2058. if high<256 then
  2059. begin
  2060. settype:=normset;
  2061. savesize:=32;
  2062. end
  2063. else
  2064. {$ifdef testvarsets}
  2065. if high<$10000 then
  2066. begin
  2067. settype:=varset;
  2068. savesize:=4*((high+31) div 32);
  2069. end
  2070. else
  2071. {$endif testvarsets}
  2072. Message(sym_e_ill_type_decl_set);
  2073. end;
  2074. constructor tsetdef.load;
  2075. begin
  2076. inherited loaddef;
  2077. deftype:=setdef;
  2078. elementtype.load;
  2079. settype:=tsettype(readbyte);
  2080. case settype of
  2081. normset : savesize:=32;
  2082. varset : savesize:=readlong;
  2083. smallset : savesize:=Sizeof(longint);
  2084. end;
  2085. end;
  2086. destructor tsetdef.destroy;
  2087. begin
  2088. inherited destroy;
  2089. end;
  2090. procedure tsetdef.write;
  2091. begin
  2092. inherited writedef;
  2093. elementtype.write;
  2094. writebyte(byte(settype));
  2095. if settype=varset then
  2096. writelong(savesize);
  2097. current_ppu^.writeentry(ibsetdef);
  2098. end;
  2099. {$ifdef GDB}
  2100. function tsetdef.stabstring : pchar;
  2101. begin
  2102. { For small sets write a longint, which can at least be seen
  2103. in the current GDB's (PFV)
  2104. this is obsolete with GDBPAS !!
  2105. and anyhow creates problems with version 4.18!! PM
  2106. if settype=smallset then
  2107. stabstring := strpnew('r'+s32bittype^.numberstring+';0;0xffffffff;')
  2108. else }
  2109. stabstring := strpnew('S'+tstoreddef(elementtype.def).numberstring);
  2110. end;
  2111. procedure tsetdef.concatstabto(asmlist : taasmoutput);
  2112. begin
  2113. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  2114. (is_def_stab_written = not_written) then
  2115. begin
  2116. if assigned(elementtype.def) then
  2117. forcestabto(asmlist,elementtype.def);
  2118. inherited concatstabto(asmlist);
  2119. end;
  2120. end;
  2121. {$endif GDB}
  2122. procedure tsetdef.deref;
  2123. begin
  2124. inherited deref;
  2125. elementtype.resolve;
  2126. end;
  2127. procedure tsetdef.write_rtti_data;
  2128. begin
  2129. rttiList.concat(Tai_const.Create_8bit(tkSet));
  2130. write_rtti_name;
  2131. rttiList.concat(Tai_const.Create_8bit(otULong));
  2132. rttiList.concat(Tai_const_symbol.Createname(elementtype.def.get_rtti_label));
  2133. end;
  2134. procedure tsetdef.write_child_rtti_data;
  2135. begin
  2136. elementtype.def.get_rtti_label;
  2137. end;
  2138. function tsetdef.is_publishable : boolean;
  2139. begin
  2140. is_publishable:=settype=smallset;
  2141. end;
  2142. function tsetdef.gettypename : string;
  2143. begin
  2144. if assigned(elementtype.def) then
  2145. gettypename:='Set Of '+elementtype.def.typename
  2146. else
  2147. gettypename:='Empty Set';
  2148. end;
  2149. {***************************************************************************
  2150. TFORMALDEF
  2151. ***************************************************************************}
  2152. constructor tformaldef.create;
  2153. var
  2154. stregdef : boolean;
  2155. begin
  2156. stregdef:=registerdef;
  2157. registerdef:=false;
  2158. inherited create;
  2159. deftype:=formaldef;
  2160. registerdef:=stregdef;
  2161. { formaldef must be registered at unit level !! }
  2162. if registerdef and assigned(current_module) then
  2163. if assigned(current_module.localsymtable) then
  2164. tsymtable(current_module.localsymtable).registerdef(self)
  2165. else if assigned(current_module.globalsymtable) then
  2166. tsymtable(current_module.globalsymtable).registerdef(self);
  2167. savesize:=target_info.size_of_pointer;
  2168. end;
  2169. constructor tformaldef.load;
  2170. begin
  2171. inherited loaddef;
  2172. deftype:=formaldef;
  2173. savesize:=target_info.size_of_pointer;
  2174. end;
  2175. procedure tformaldef.write;
  2176. begin
  2177. inherited writedef;
  2178. current_ppu^.writeentry(ibformaldef);
  2179. end;
  2180. {$ifdef GDB}
  2181. function tformaldef.stabstring : pchar;
  2182. begin
  2183. stabstring := strpnew('formal'+numberstring+';');
  2184. end;
  2185. procedure tformaldef.concatstabto(asmlist : taasmoutput);
  2186. begin
  2187. { formaldef can't be stab'ed !}
  2188. end;
  2189. {$endif GDB}
  2190. function tformaldef.gettypename : string;
  2191. begin
  2192. gettypename:='Var';
  2193. end;
  2194. {***************************************************************************
  2195. TARRAYDEF
  2196. ***************************************************************************}
  2197. constructor tarraydef.create(l,h : longint;const t : ttype);
  2198. begin
  2199. inherited create;
  2200. deftype:=arraydef;
  2201. lowrange:=l;
  2202. highrange:=h;
  2203. rangetype:=t;
  2204. elementtype.reset;
  2205. IsVariant:=false;
  2206. IsConstructor:=false;
  2207. IsArrayOfConst:=false;
  2208. IsDynamicArray:=false;
  2209. rangenr:=0;
  2210. end;
  2211. constructor tarraydef.load;
  2212. begin
  2213. inherited loaddef;
  2214. deftype:=arraydef;
  2215. { the addresses are calculated later }
  2216. elementtype.load;
  2217. rangetype.load;
  2218. lowrange:=readlong;
  2219. highrange:=readlong;
  2220. IsArrayOfConst:=boolean(readbyte);
  2221. IsVariant:=false;
  2222. IsConstructor:=false;
  2223. IsDynamicArray:=false;
  2224. rangenr:=0;
  2225. end;
  2226. function tarraydef.getrangecheckstring : string;
  2227. begin
  2228. if (cs_create_smart in aktmoduleswitches) then
  2229. getrangecheckstring:='R_'+current_module.modulename^+tostr(rangenr)
  2230. else
  2231. getrangecheckstring:='R_'+tostr(rangenr);
  2232. end;
  2233. procedure tarraydef.genrangecheck;
  2234. begin
  2235. if rangenr=0 then
  2236. begin
  2237. { generates the data for range checking }
  2238. getlabelnr(rangenr);
  2239. if (cs_create_smart in aktmoduleswitches) then
  2240. dataSegment.concat(Tai_symbol.Createname_global(getrangecheckstring,8))
  2241. else
  2242. dataSegment.concat(Tai_symbol.Createname(getrangecheckstring,8));
  2243. if lowrange<=highrange then
  2244. begin
  2245. dataSegment.concat(Tai_const.Create_32bit(lowrange));
  2246. dataSegment.concat(Tai_const.Create_32bit(highrange));
  2247. end
  2248. { for big arrays we need two bounds }
  2249. else
  2250. begin
  2251. dataSegment.concat(Tai_const.Create_32bit(lowrange));
  2252. dataSegment.concat(Tai_const.Create_32bit($7fffffff));
  2253. dataSegment.concat(Tai_const.Create_32bit(longint($80000000)));
  2254. dataSegment.concat(Tai_const.Create_32bit(highrange));
  2255. end;
  2256. end;
  2257. end;
  2258. procedure tarraydef.deref;
  2259. begin
  2260. inherited deref;
  2261. elementtype.resolve;
  2262. rangetype.resolve;
  2263. end;
  2264. procedure tarraydef.write;
  2265. begin
  2266. inherited writedef;
  2267. elementtype.write;
  2268. rangetype.write;
  2269. writelong(lowrange);
  2270. writelong(highrange);
  2271. writebyte(byte(IsArrayOfConst));
  2272. current_ppu^.writeentry(ibarraydef);
  2273. end;
  2274. {$ifdef GDB}
  2275. function tarraydef.stabstring : pchar;
  2276. begin
  2277. stabstring := strpnew('ar'+tstoreddef(rangetype.def).numberstring+';'
  2278. +tostr(lowrange)+';'+tostr(highrange)+';'+tstoreddef(elementtype.def).numberstring);
  2279. end;
  2280. procedure tarraydef.concatstabto(asmlist : taasmoutput);
  2281. begin
  2282. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2283. and (is_def_stab_written = not_written) then
  2284. begin
  2285. {when array are inserted they have no definition yet !!}
  2286. if assigned(elementtype.def) then
  2287. inherited concatstabto(asmlist);
  2288. end;
  2289. end;
  2290. {$endif GDB}
  2291. function tarraydef.elesize : longint;
  2292. begin
  2293. if ((lowrange=0) and
  2294. (highrange=-1) and
  2295. (not IsArrayOfConst) and
  2296. (not IsVariant) and
  2297. (not IsDynamicArray)) or
  2298. IsConstructor then
  2299. begin
  2300. { strings are stored by address only }
  2301. case elementtype.def.deftype of
  2302. stringdef :
  2303. elesize:=4;
  2304. else
  2305. elesize:=elementtype.def.size;
  2306. end;
  2307. end
  2308. else
  2309. elesize:=elementtype.def.size;
  2310. end;
  2311. function tarraydef.size : longint;
  2312. begin
  2313. if IsDynamicArray then
  2314. begin
  2315. size:=4;
  2316. exit;
  2317. end;
  2318. {Tarraydef.size may never be called for an open array!}
  2319. if highrange<lowrange then
  2320. internalerror(99080501);
  2321. If (elesize>0) and
  2322. (
  2323. (highrange-lowrange = $7fffffff) or
  2324. { () are needed around elesize-1 to avoid a possible
  2325. integer overflow for elesize=1 !! PM }
  2326. (($7fffffff div elesize + (elesize -1)) < (highrange - lowrange))
  2327. ) Then
  2328. Begin
  2329. Message(sym_e_segment_too_large);
  2330. size := 4
  2331. End
  2332. Else size:=(highrange-lowrange+1)*elesize;
  2333. end;
  2334. function tarraydef.alignment : longint;
  2335. begin
  2336. { alignment is the size of the elements }
  2337. if elementtype.def.deftype=recorddef then
  2338. alignment:=elementtype.def.alignment
  2339. else
  2340. alignment:=elesize;
  2341. end;
  2342. function tarraydef.needs_inittable : boolean;
  2343. begin
  2344. needs_inittable:=IsDynamicArray or elementtype.def.needs_inittable;
  2345. end;
  2346. procedure tarraydef.write_child_rtti_data;
  2347. begin
  2348. elementtype.def.get_rtti_label;
  2349. end;
  2350. procedure tarraydef.write_rtti_data;
  2351. begin
  2352. if IsDynamicArray then
  2353. rttiList.concat(Tai_const.Create_8bit(tkdynarray))
  2354. else
  2355. rttiList.concat(Tai_const.Create_8bit(tkarray));
  2356. write_rtti_name;
  2357. { size of elements }
  2358. rttiList.concat(Tai_const.Create_32bit(elesize));
  2359. { count of elements }
  2360. if not(IsDynamicArray) then
  2361. rttiList.concat(Tai_const.Create_32bit(highrange-lowrange+1));
  2362. { element type }
  2363. rttiList.concat(Tai_const_symbol.Createname(elementtype.def.get_rtti_label));
  2364. { variant type }
  2365. // !!!!!!!!!!!!!!!!
  2366. end;
  2367. function tarraydef.gettypename : string;
  2368. begin
  2369. if isarrayofconst or isConstructor then
  2370. begin
  2371. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2372. gettypename:='Array Of Const'
  2373. else
  2374. gettypename:='Array Of '+elementtype.def.typename;
  2375. end
  2376. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2377. gettypename:='Array Of '+elementtype.def.typename
  2378. else
  2379. begin
  2380. if rangetype.def.deftype=enumdef then
  2381. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2382. else
  2383. gettypename:='Array['+tostr(lowrange)+'..'+
  2384. tostr(highrange)+'] Of '+elementtype.def.typename
  2385. end;
  2386. end;
  2387. {***************************************************************************
  2388. tabstractrecorddef
  2389. ***************************************************************************}
  2390. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2391. begin
  2392. if t=gs_record then
  2393. getsymtable:=symtable
  2394. else
  2395. getsymtable:=nil;
  2396. end;
  2397. {$ifdef GDB}
  2398. procedure tabstractrecorddef.addname(p : tnamedindexitem);
  2399. var
  2400. news, newrec : pchar;
  2401. spec : string[3];
  2402. varsize : longint;
  2403. begin
  2404. { static variables from objects are like global objects }
  2405. if (sp_static in tsym(p).symoptions) then
  2406. exit;
  2407. If tsym(p).typ = varsym then
  2408. begin
  2409. if (sp_protected in tsym(p).symoptions) then
  2410. spec:='/1'
  2411. else if (sp_private in tsym(p).symoptions) then
  2412. spec:='/0'
  2413. else
  2414. spec:='';
  2415. if not assigned(tvarsym(p).vartype.def) then
  2416. writeln(tvarsym(p).name);
  2417. { class fields are pointers PM, obsolete now PM }
  2418. {if (tvarsym(p).vartype.def.deftype=objectdef) and
  2419. tobjectdef(tvarsym(p).vartype.def).is_class then
  2420. spec:=spec+'*'; }
  2421. varsize:=tvarsym(p).vartype.def.size;
  2422. { open arrays made overflows !! }
  2423. if varsize>$fffffff then
  2424. varsize:=$fffffff;
  2425. newrec := strpnew(p.name+':'+spec+tstoreddef(tvarsym(p).vartype.def).numberstring
  2426. +','+tostr(tvarsym(p).address*8)+','
  2427. +tostr(varsize*8)+';');
  2428. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2429. begin
  2430. getmem(news,stabrecsize+memsizeinc);
  2431. strcopy(news,stabrecstring);
  2432. freemem(stabrecstring,stabrecsize);
  2433. stabrecsize:=stabrecsize+memsizeinc;
  2434. stabrecstring:=news;
  2435. end;
  2436. strcat(StabRecstring,newrec);
  2437. strdispose(newrec);
  2438. {This should be used for case !!}
  2439. inc(RecOffset,tvarsym(p).vartype.def.size);
  2440. end;
  2441. end;
  2442. {$endif GDB}
  2443. procedure tabstractrecorddef.count_inittable_fields(sym : tnamedindexitem);
  2444. begin
  2445. if ((tsym(sym).typ=varsym) and
  2446. tvarsym(sym).vartype.def.needs_inittable) then
  2447. inc(count);
  2448. end;
  2449. procedure tabstractrecorddef.count_fields(sym : tnamedindexitem);
  2450. begin
  2451. inc(count);
  2452. end;
  2453. procedure tabstractrecorddef.write_field_inittable(sym : tnamedindexitem);
  2454. begin
  2455. if ((tsym(sym).typ=varsym) and
  2456. tvarsym(sym).vartype.def.needs_inittable) then
  2457. begin
  2458. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tvarsym(sym).vartype.def).get_inittable_label));
  2459. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).address));
  2460. end;
  2461. end;
  2462. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem);
  2463. begin
  2464. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym).vartype.def.get_rtti_label));
  2465. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).address));
  2466. end;
  2467. procedure tabstractrecorddef.generate_child_inittable(sym:tnamedindexitem);
  2468. begin
  2469. if (tsym(sym).typ=varsym) and
  2470. tvarsym(sym).vartype.def.needs_inittable then
  2471. { force inittable generation }
  2472. tstoreddef(tvarsym(sym).vartype.def).get_inittable_label;
  2473. end;
  2474. procedure tabstractrecorddef.generate_child_rtti(sym : tnamedindexitem);
  2475. begin
  2476. tvarsym(sym).vartype.def.get_rtti_label;
  2477. end;
  2478. {***************************************************************************
  2479. trecorddef
  2480. ***************************************************************************}
  2481. constructor trecorddef.create(p : tsymtable);
  2482. begin
  2483. inherited create;
  2484. deftype:=recorddef;
  2485. symtable:=p;
  2486. symtable.defowner := self;
  2487. symtable.dataalignment:=packrecordalignment[aktpackrecords];
  2488. end;
  2489. constructor trecorddef.load;
  2490. var
  2491. oldread_member : boolean;
  2492. begin
  2493. inherited loaddef;
  2494. deftype:=recorddef;
  2495. savesize:=readlong;
  2496. oldread_member:=read_member;
  2497. read_member:=true;
  2498. symtable:=trecordsymtable.create;
  2499. trecordsymtable(symtable).load;
  2500. read_member:=oldread_member;
  2501. symtable.defowner:=self;
  2502. end;
  2503. destructor trecorddef.destroy;
  2504. begin
  2505. if assigned(symtable) then
  2506. symtable.free;
  2507. inherited destroy;
  2508. end;
  2509. function trecorddef.needs_inittable : boolean;
  2510. begin
  2511. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2512. end;
  2513. procedure trecorddef.deref;
  2514. var
  2515. oldrecsyms : tsymtable;
  2516. begin
  2517. inherited deref;
  2518. oldrecsyms:=aktrecordsymtable;
  2519. aktrecordsymtable:=symtable;
  2520. { now dereference the definitions }
  2521. tstoredsymtable(symtable).deref;
  2522. aktrecordsymtable:=oldrecsyms;
  2523. { assign TGUID? load only from system unit (unitid=1) }
  2524. if not(assigned(rec_tguid)) and
  2525. (upper(typename)='TGUID') and
  2526. assigned(owner) and
  2527. assigned(owner.name) and
  2528. (owner.name^='SYSTEM') then
  2529. rec_tguid:=self;
  2530. end;
  2531. procedure trecorddef.write;
  2532. var
  2533. oldread_member : boolean;
  2534. begin
  2535. oldread_member:=read_member;
  2536. read_member:=true;
  2537. inherited writedef;
  2538. writelong(savesize);
  2539. current_ppu^.writeentry(ibrecorddef);
  2540. trecordsymtable(symtable).write;
  2541. read_member:=oldread_member;
  2542. end;
  2543. function trecorddef.size:longint;
  2544. begin
  2545. size:=symtable.datasize;
  2546. end;
  2547. function trecorddef.alignment:longint;
  2548. var
  2549. l : longint;
  2550. hp : tvarsym;
  2551. begin
  2552. { also check the first symbol for it's size, because a
  2553. packed record has dataalignment of 1, but the first
  2554. sym could be a longint which should be aligned on 4 bytes,
  2555. this is compatible with C record packing (PFV) }
  2556. hp:=tvarsym(symtable.symindex.first);
  2557. if assigned(hp) then
  2558. begin
  2559. if hp.vartype.def.deftype in [recorddef,arraydef] then
  2560. l:=hp.vartype.def.alignment
  2561. else
  2562. l:=hp.vartype.def.size;
  2563. if l>symtable.dataalignment then
  2564. begin
  2565. if l>=4 then
  2566. alignment:=4
  2567. else
  2568. if l>=2 then
  2569. alignment:=2
  2570. else
  2571. alignment:=1;
  2572. end
  2573. else
  2574. alignment:=symtable.dataalignment;
  2575. end
  2576. else
  2577. alignment:=symtable.dataalignment;
  2578. end;
  2579. {$ifdef GDB}
  2580. function trecorddef.stabstring : pchar;
  2581. begin
  2582. GetMem(stabrecstring,memsizeinc);
  2583. stabrecsize:=memsizeinc;
  2584. strpcopy(stabRecString,'s'+tostr(size));
  2585. RecOffset := 0;
  2586. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname);
  2587. strpcopy(strend(StabRecString),';');
  2588. stabstring := strnew(StabRecString);
  2589. Freemem(stabrecstring,stabrecsize);
  2590. end;
  2591. procedure trecorddef.concatstabto(asmlist : taasmoutput);
  2592. begin
  2593. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  2594. (is_def_stab_written = not_written) then
  2595. inherited concatstabto(asmlist);
  2596. end;
  2597. {$endif GDB}
  2598. procedure trecorddef.write_child_rtti_data;
  2599. begin
  2600. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_child_rtti);
  2601. end;
  2602. procedure trecorddef.write_child_init_data;
  2603. begin
  2604. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_child_inittable);
  2605. end;
  2606. procedure trecorddef.write_rtti_data;
  2607. begin
  2608. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2609. write_rtti_name;
  2610. rttiList.concat(Tai_const.Create_32bit(size));
  2611. count:=0;
  2612. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_fields);
  2613. rttiList.concat(Tai_const.Create_32bit(count));
  2614. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti);
  2615. end;
  2616. procedure trecorddef.write_init_data;
  2617. begin
  2618. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2619. write_rtti_name;
  2620. rttiList.concat(Tai_const.Create_32bit(size));
  2621. count:=0;
  2622. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_inittable_fields);
  2623. rttiList.concat(Tai_const.Create_32bit(count));
  2624. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_inittable);
  2625. end;
  2626. function trecorddef.gettypename : string;
  2627. begin
  2628. gettypename:='<record type>'
  2629. end;
  2630. {***************************************************************************
  2631. TABSTRACTPROCDEF
  2632. ***************************************************************************}
  2633. constructor tabstractprocdef.create;
  2634. begin
  2635. inherited create;
  2636. para:=TParaLinkedList.Create;
  2637. minparacount:=0;
  2638. maxparacount:=0;
  2639. fpu_used:=0;
  2640. proctypeoption:=potype_none;
  2641. proccalloptions:=[];
  2642. procoptions:=[];
  2643. rettype:=voidtype;
  2644. symtablelevel:=0;
  2645. savesize:=target_info.size_of_pointer;
  2646. end;
  2647. destructor tabstractprocdef.destroy;
  2648. begin
  2649. Para.Free;
  2650. inherited destroy;
  2651. end;
  2652. procedure tabstractprocdef.concatpara(const tt:ttype;vsp : tvarspez;defval:tsym);
  2653. var
  2654. hp : TParaItem;
  2655. begin
  2656. hp:=TParaItem.Create;
  2657. hp.paratyp:=vsp;
  2658. hp.paratype:=tt;
  2659. hp.register:=R_NO;
  2660. hp.defaultvalue:=defval;
  2661. Para.insert(hp);
  2662. if not assigned(defval) then
  2663. inc(minparacount);
  2664. inc(maxparacount);
  2665. end;
  2666. { all functions returning in FPU are
  2667. assume to use 2 FPU registers
  2668. until the function implementation
  2669. is processed PM }
  2670. procedure tabstractprocdef.test_if_fpu_result;
  2671. begin
  2672. if assigned(rettype.def) and
  2673. (rettype.def.deftype=floatdef) then
  2674. fpu_used:=2;
  2675. end;
  2676. procedure tabstractprocdef.deref;
  2677. var
  2678. hp : TParaItem;
  2679. begin
  2680. inherited deref;
  2681. rettype.resolve;
  2682. hp:=TParaItem(Para.first);
  2683. while assigned(hp) do
  2684. begin
  2685. hp.paratype.resolve;
  2686. resolvesym(tsym(hp.defaultvalue));
  2687. hp:=TParaItem(hp.next);
  2688. end;
  2689. end;
  2690. constructor tabstractprocdef.load;
  2691. var
  2692. hp : TParaItem;
  2693. count,i : word;
  2694. begin
  2695. inherited loaddef;
  2696. Para:=TParaLinkedList.Create;
  2697. minparacount:=0;
  2698. maxparacount:=0;
  2699. rettype.load;
  2700. fpu_used:=readbyte;
  2701. proctypeoption:=tproctypeoption(readlong);
  2702. readsmallset(proccalloptions);
  2703. readsmallset(procoptions);
  2704. count:=readword;
  2705. savesize:=target_info.size_of_pointer;
  2706. for i:=1 to count do
  2707. begin
  2708. hp:=TParaItem.Create;
  2709. hp.paratyp:=tvarspez(readbyte);
  2710. { hp.register:=tregister(readbyte); }
  2711. hp.register:=R_NO;
  2712. hp.paratype.load;
  2713. hp.defaultvalue:=tsym(readderef);
  2714. if not assigned(hp.defaultvalue) then
  2715. inc(minparacount);
  2716. inc(maxparacount);
  2717. Para.concat(hp);
  2718. end;
  2719. end;
  2720. procedure tabstractprocdef.write;
  2721. var
  2722. hp : TParaItem;
  2723. oldintfcrc : boolean;
  2724. begin
  2725. inherited writedef;
  2726. rettype.write;
  2727. oldintfcrc:=current_ppu^.do_interface_crc;
  2728. current_ppu^.do_interface_crc:=false;
  2729. writebyte(fpu_used);
  2730. writelong(ord(proctypeoption));
  2731. writesmallset(proccalloptions);
  2732. writesmallset(procoptions);
  2733. current_ppu^.do_interface_crc:=oldintfcrc;
  2734. writeword(maxparacount);
  2735. hp:=TParaItem(Para.first);
  2736. while assigned(hp) do
  2737. begin
  2738. writebyte(byte(hp.paratyp));
  2739. { writebyte(byte(hp.register)); }
  2740. hp.paratype.write;
  2741. writederef(hp.defaultvalue);
  2742. hp:=TParaItem(hp.next);
  2743. end;
  2744. end;
  2745. function tabstractprocdef.para_size(alignsize:longint) : longint;
  2746. var
  2747. pdc : TParaItem;
  2748. l : longint;
  2749. begin
  2750. l:=0;
  2751. pdc:=TParaItem(Para.first);
  2752. while assigned(pdc) do
  2753. begin
  2754. case pdc.paratyp of
  2755. vs_out,
  2756. vs_var : inc(l,target_info.size_of_pointer);
  2757. vs_value,
  2758. vs_const : if push_addr_param(pdc.paratype.def) then
  2759. inc(l,target_info.size_of_pointer)
  2760. else
  2761. inc(l,pdc.paratype.def.size);
  2762. end;
  2763. l:=align(l,alignsize);
  2764. pdc:=TParaItem(pdc.next);
  2765. end;
  2766. para_size:=l;
  2767. end;
  2768. function tabstractprocdef.demangled_paras : string;
  2769. var
  2770. hs,s : string;
  2771. hp : TParaItem;
  2772. hpc : tconstsym;
  2773. begin
  2774. hp:=TParaItem(Para.last);
  2775. if not(assigned(hp)) then
  2776. begin
  2777. demangled_paras:='';
  2778. exit;
  2779. end;
  2780. s:='(';
  2781. while assigned(hp) do
  2782. begin
  2783. if assigned(hp.paratype.def.typesym) then
  2784. s:=s+hp.paratype.def.typesym.realname
  2785. else if hp.paratyp=vs_var then
  2786. s:=s+'var'
  2787. else if hp.paratyp=vs_const then
  2788. s:=s+'const'
  2789. else if hp.paratyp=vs_out then
  2790. s:=s+'out';
  2791. { default value }
  2792. if assigned(hp.defaultvalue) then
  2793. begin
  2794. hpc:=tconstsym(hp.defaultvalue);
  2795. hs:='';
  2796. case hpc.consttyp of
  2797. conststring,
  2798. constresourcestring :
  2799. hs:=strpas(pchar(tpointerord(hpc.value)));
  2800. constreal :
  2801. str(pbestreal(tpointerord(hpc.value))^,hs);
  2802. constord,
  2803. constpointer :
  2804. hs:=tostr(hpc.value);
  2805. constbool :
  2806. begin
  2807. if hpc.value<>0 then
  2808. hs:='TRUE'
  2809. else
  2810. hs:='FALSE';
  2811. end;
  2812. constnil :
  2813. hs:='nil';
  2814. constchar :
  2815. hs:=chr(hpc.value);
  2816. constset :
  2817. hs:='<set>';
  2818. end;
  2819. if hs<>'' then
  2820. s:=s+'="'+hs+'"';
  2821. end;
  2822. hp:=TParaItem(hp.previous);
  2823. if assigned(hp) then
  2824. s:=s+',';
  2825. end;
  2826. s:=s+')';
  2827. demangled_paras:=s;
  2828. end;
  2829. function tabstractprocdef.proccalloption2str : string;
  2830. type
  2831. tproccallopt=record
  2832. mask : tproccalloption;
  2833. str : string[30];
  2834. end;
  2835. const
  2836. proccallopts=13;
  2837. proccallopt : array[1..proccallopts] of tproccallopt=(
  2838. (mask:pocall_none; str:''),
  2839. (mask:pocall_clearstack; str:'ClearStack'),
  2840. (mask:pocall_leftright; str:'LeftRight'),
  2841. (mask:pocall_cdecl; str:'CDecl'),
  2842. (mask:pocall_register; str:'Register'),
  2843. (mask:pocall_stdcall; str:'StdCall'),
  2844. (mask:pocall_safecall; str:'SafeCall'),
  2845. (mask:pocall_palmossyscall;str:'PalmOSSysCall'),
  2846. (mask:pocall_system; str:'System'),
  2847. (mask:pocall_inline; str:'Inline'),
  2848. (mask:pocall_internproc; str:'InternProc'),
  2849. (mask:pocall_internconst; str:'InternConst'),
  2850. (mask:pocall_cdecl; str:'CPPDecl')
  2851. );
  2852. var
  2853. s : string;
  2854. i : longint;
  2855. first : boolean;
  2856. begin
  2857. s:='';
  2858. first:=true;
  2859. for i:=1to proccallopts do
  2860. if (proccallopt[i].mask in proccalloptions) then
  2861. begin
  2862. if first then
  2863. first:=false
  2864. else
  2865. s:=s+';';
  2866. s:=s+proccallopt[i].str;
  2867. end;
  2868. proccalloption2str:=s;
  2869. end;
  2870. {$ifdef GDB}
  2871. function tabstractprocdef.stabstring : pchar;
  2872. begin
  2873. stabstring := strpnew('abstractproc'+numberstring+';');
  2874. end;
  2875. procedure tabstractprocdef.concatstabto(asmlist : taasmoutput);
  2876. begin
  2877. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2878. and (is_def_stab_written = not_written) then
  2879. begin
  2880. if assigned(rettype.def) then forcestabto(asmlist,rettype.def);
  2881. inherited concatstabto(asmlist);
  2882. end;
  2883. end;
  2884. {$endif GDB}
  2885. {***************************************************************************
  2886. TPROCDEF
  2887. ***************************************************************************}
  2888. constructor tprocdef.create;
  2889. begin
  2890. inherited create;
  2891. deftype:=procdef;
  2892. _mangledname:=nil;
  2893. nextoverloaded:=nil;
  2894. fileinfo:=aktfilepos;
  2895. extnumber:=-1;
  2896. aliasnames:=tstringlist.create;
  2897. localst:=tlocalsymtable.create;
  2898. parast:=tparasymtable.create;
  2899. localst.defowner:=self;
  2900. parast.defowner:=self;
  2901. { this is used by insert
  2902. to check same names in parast and localst }
  2903. localst.next:=parast;
  2904. defref:=nil;
  2905. crossref:=nil;
  2906. lastwritten:=nil;
  2907. refcount:=0;
  2908. if (cs_browser in aktmoduleswitches) and make_ref then
  2909. begin
  2910. defref:=tref.create(defref,@akttokenpos);
  2911. inc(refcount);
  2912. end;
  2913. lastref:=defref;
  2914. { first, we assume that all registers are used }
  2915. {$ifdef newcg}
  2916. usedregisters:=[firstreg..lastreg];
  2917. {$else newcg}
  2918. {$ifdef i386}
  2919. usedregisters:=$ff;
  2920. {$else}
  2921. usedregisters:=ALL_REGISTERS;
  2922. {$endif i386}
  2923. {$endif newcg}
  2924. forwarddef:=true;
  2925. interfacedef:=false;
  2926. hasforward:=false;
  2927. _class := nil;
  2928. code:=nil;
  2929. regvarinfo := nil;
  2930. count:=false;
  2931. is_used:=false;
  2932. end;
  2933. constructor tprocdef.load;
  2934. begin
  2935. inherited load;
  2936. deftype:=procdef;
  2937. {$ifdef newcg}
  2938. readnormalset(usedregisters);
  2939. {$else newcg}
  2940. {$ifdef i386}
  2941. usedregisters:=readbyte;
  2942. {$else}
  2943. readnormalset(usedregisters);
  2944. {$endif}
  2945. {$endif newcg}
  2946. _mangledname:=stringdup(readstring);
  2947. extnumber:=readlong;
  2948. nextoverloaded:=tprocdef(readderef);
  2949. _class := tobjectdef(readderef);
  2950. readposinfo(fileinfo);
  2951. if (cs_link_deffile in aktglobalswitches) and
  2952. (tf_need_export in target_info.flags) and
  2953. (po_exports in procoptions) then
  2954. deffile.AddExport(mangledname);
  2955. aliasnames:=tstringlist.create;
  2956. parast:=tparasymtable.create;
  2957. tparasymtable(parast).load;
  2958. parast.defowner:=self;
  2959. localst:=nil;
  2960. {new(localst,loadas(localsymtable));
  2961. localst.defowner:=self;
  2962. parast.next:=localst;
  2963. localst.next:=owner;}
  2964. forwarddef:=false;
  2965. interfacedef:=false;
  2966. hasforward:=false;
  2967. code := nil;
  2968. regvarinfo := nil;
  2969. lastref:=nil;
  2970. lastwritten:=nil;
  2971. defref:=nil;
  2972. refcount:=0;
  2973. count:=true;
  2974. is_used:=false;
  2975. end;
  2976. destructor tprocdef.destroy;
  2977. begin
  2978. if assigned(defref) then
  2979. begin
  2980. defref.freechain;
  2981. defref.free;
  2982. end;
  2983. aliasnames.free;
  2984. if assigned(parast) then
  2985. parast.free;
  2986. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  2987. localst.free;
  2988. if (pocall_inline in proccalloptions) and assigned(code) then
  2989. tnode(code).free;
  2990. if assigned(regvarinfo) then
  2991. dispose(pregvarinfo(regvarinfo));
  2992. if (po_msgstr in procoptions) then
  2993. strdispose(messageinf.str);
  2994. if assigned(_mangledname) then
  2995. stringdispose(_mangledname);
  2996. inherited destroy;
  2997. end;
  2998. procedure tprocdef.write;
  2999. var
  3000. oldintfcrc : boolean;
  3001. begin
  3002. inherited write;
  3003. oldintfcrc:=current_ppu^.do_interface_crc;
  3004. current_ppu^.do_interface_crc:=false;
  3005. { set all registers to used for simplified compilation PM }
  3006. if simplify_ppu then
  3007. begin
  3008. {$ifdef newcg}
  3009. usedregisters:=[firstreg..lastreg];
  3010. {$else newcg}
  3011. {$ifdef i386}
  3012. usedregisters:=$ff;
  3013. {$else}
  3014. usedregisters:=[firstreg..lastreg];
  3015. {$endif i386}
  3016. {$endif newcg}
  3017. end;
  3018. {$ifdef newcg}
  3019. writenormalset(usedregisters);
  3020. {$else newcg}
  3021. {$ifdef i386}
  3022. writebyte(usedregisters);
  3023. {$else}
  3024. writenormalset(usedregisters);
  3025. {$endif i386}
  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_info.size_of_pointer
  3421. else
  3422. size:=target_info.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_info.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_info.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_info.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_info.size_of_pointer;
  3826. odt_interfacecom,odt_interfacecorba:
  3827. vmtmethodoffset:=index*target_info.size_of_pointer;
  3828. else
  3829. {$ifdef WITHDMT}
  3830. vmtmethodoffset:=(index+4)*target_info.size_of_pointer;
  3831. {$else WITHDMT}
  3832. vmtmethodoffset:=(index+3)*target_info.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.29 2001-04-21 12:03:12 peter
  4831. * m68k updates merged from fixes branch
  4832. Revision 1.28 2001/04/18 22:01:58 peter
  4833. * registration of targets and assemblers
  4834. Revision 1.27 2001/04/13 01:22:15 peter
  4835. * symtable change to classes
  4836. * range check generation and errors fixed, make cycle DEBUG=1 works
  4837. * memory leaks fixed
  4838. Revision 1.26 2001/04/05 21:32:22 peter
  4839. * enum stabs fix (merged)
  4840. Revision 1.25 2001/04/04 21:30:45 florian
  4841. * applied several fixes to get the DD8 Delphi Unit compiled
  4842. e.g. "forward"-interfaces are working now
  4843. Revision 1.24 2001/04/02 21:20:34 peter
  4844. * resulttype rewrite
  4845. Revision 1.23 2001/03/22 23:28:39 florian
  4846. * correct initialisation of rec_tguid when loading the system unit
  4847. Revision 1.22 2001/03/22 00:10:58 florian
  4848. + basic variant type support in the compiler
  4849. Revision 1.21 2001/03/11 22:58:50 peter
  4850. * getsym redesign, removed the globals srsym,srsymtable
  4851. Revision 1.20 2001/01/06 20:11:29 peter
  4852. * merged c packrecords fix
  4853. Revision 1.19 2000/12/25 00:07:29 peter
  4854. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  4855. tlinkedlist objects)
  4856. Revision 1.18 2000/12/24 12:20:45 peter
  4857. * classes, enum stabs fixes merged from 1.0.x
  4858. Revision 1.17 2000/12/07 17:19:43 jonas
  4859. * new constant handling: from now on, hex constants >$7fffffff are
  4860. parsed as unsigned constants (otherwise, $80000000 got sign extended
  4861. and became $ffffffff80000000), all constants in the longint range
  4862. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  4863. are cardinals and the rest are int64's.
  4864. * added lots of longint typecast to prevent range check errors in the
  4865. compiler and rtl
  4866. * type casts of symbolic ordinal constants are now preserved
  4867. * fixed bug where the original resulttype.def wasn't restored correctly
  4868. after doing a 64bit rangecheck
  4869. Revision 1.16 2000/11/30 23:12:57 florian
  4870. * if raw interfaces inherit from IUnknown they are ref. counted too
  4871. Revision 1.15 2000/11/29 00:30:40 florian
  4872. * unused units removed from uses clause
  4873. * some changes for widestrings
  4874. Revision 1.14 2000/11/28 00:28:06 pierre
  4875. * stabs fixing
  4876. Revision 1.13 2000/11/26 18:09:40 florian
  4877. * fixed rtti for chars
  4878. Revision 1.12 2000/11/19 16:23:35 florian
  4879. *** empty log message ***
  4880. Revision 1.11 2000/11/12 23:24:12 florian
  4881. * interfaces are basically running
  4882. Revision 1.10 2000/11/11 16:12:38 peter
  4883. * add far; to typename for far pointer
  4884. Revision 1.9 2000/11/07 20:01:57 peter
  4885. * fix vmt index for classes
  4886. Revision 1.8 2000/11/06 23:13:53 peter
  4887. * uppercase manglednames
  4888. Revision 1.7 2000/11/06 23:11:38 florian
  4889. * writeln debugger uninstalled ;)
  4890. Revision 1.6 2000/11/06 23:05:52 florian
  4891. * more fixes
  4892. Revision 1.5 2000/11/06 20:30:55 peter
  4893. * more fixes to get make cycle working
  4894. Revision 1.4 2000/11/04 14:25:22 florian
  4895. + merged Attila's changes for interfaces, not tested yet
  4896. Revision 1.3 2000/11/02 12:04:10 pierre
  4897. * remove RecOffset code, that created problems
  4898. Revision 1.2 2000/11/01 23:04:38 peter
  4899. * tprocdef.fullprocname added for better casesensitve writing of
  4900. procedures
  4901. Revision 1.1 2000/10/31 22:02:52 peter
  4902. * symtable splitted, no real code changes
  4903. }