symdef.pas 171 KB

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