symdef.pas 172 KB

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