symdef.pas 175 KB

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