symdef.pas 185 KB

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