symdef.pas 189 KB

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