symdef.pas 174 KB

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