symdef.pas 178 KB

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