symdef.pas 175 KB

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