symdef.pas 170 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566
  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. fpu_used:=2;
  2595. end;
  2596. procedure tabstractprocdef.deref;
  2597. var
  2598. hp : TParaItem;
  2599. begin
  2600. inherited deref;
  2601. rettype.resolve;
  2602. hp:=TParaItem(Para.first);
  2603. while assigned(hp) do
  2604. begin
  2605. hp.paratype.resolve;
  2606. resolvesym(tsym(hp.defaultvalue));
  2607. hp:=TParaItem(hp.next);
  2608. end;
  2609. end;
  2610. constructor tabstractprocdef.load(ppufile:tcompilerppufile);
  2611. var
  2612. hp : TParaItem;
  2613. count,i : word;
  2614. begin
  2615. inherited loaddef(ppufile);
  2616. Para:=TParaLinkedList.Create;
  2617. minparacount:=0;
  2618. maxparacount:=0;
  2619. ppufile.gettype(rettype);
  2620. fpu_used:=ppufile.getbyte;
  2621. proctypeoption:=tproctypeoption(ppufile.getlongint);
  2622. ppufile.getsmallset(proccalloptions);
  2623. ppufile.getsmallset(procoptions);
  2624. count:=ppufile.getword;
  2625. savesize:=target_info.size_of_pointer;
  2626. for i:=1 to count do
  2627. begin
  2628. hp:=TParaItem.Create;
  2629. hp.paratyp:=tvarspez(ppufile.getbyte);
  2630. { hp.register:=tregister(ppufile.getbyte); }
  2631. hp.register:=R_NO;
  2632. ppufile.gettype(hp.paratype);
  2633. hp.defaultvalue:=tsym(ppufile.getderef);
  2634. if not assigned(hp.defaultvalue) then
  2635. inc(minparacount);
  2636. inc(maxparacount);
  2637. Para.concat(hp);
  2638. end;
  2639. end;
  2640. procedure tabstractprocdef.write(ppufile:tcompilerppufile);
  2641. var
  2642. hp : TParaItem;
  2643. oldintfcrc : boolean;
  2644. begin
  2645. inherited writedef(ppufile);
  2646. ppufile.puttype(rettype);
  2647. oldintfcrc:=ppufile.do_interface_crc;
  2648. ppufile.do_interface_crc:=false;
  2649. if simplify_ppu then
  2650. fpu_used:=0;
  2651. ppufile.putbyte(fpu_used);
  2652. ppufile.putlongint(ord(proctypeoption));
  2653. ppufile.putsmallset(proccalloptions);
  2654. ppufile.putsmallset(procoptions);
  2655. ppufile.do_interface_crc:=oldintfcrc;
  2656. ppufile.putword(maxparacount);
  2657. hp:=TParaItem(Para.first);
  2658. while assigned(hp) do
  2659. begin
  2660. ppufile.putbyte(byte(hp.paratyp));
  2661. { ppufile.putbyte(byte(hp.register)); }
  2662. ppufile.puttype(hp.paratype);
  2663. ppufile.putderef(hp.defaultvalue);
  2664. hp:=TParaItem(hp.next);
  2665. end;
  2666. end;
  2667. function tabstractprocdef.para_size(alignsize:longint) : longint;
  2668. var
  2669. pdc : TParaItem;
  2670. l : longint;
  2671. begin
  2672. l:=0;
  2673. pdc:=TParaItem(Para.first);
  2674. while assigned(pdc) do
  2675. begin
  2676. case pdc.paratyp of
  2677. vs_out,
  2678. vs_var : inc(l,target_info.size_of_pointer);
  2679. vs_value,
  2680. vs_const : if push_addr_param(pdc.paratype.def) then
  2681. inc(l,target_info.size_of_pointer)
  2682. else
  2683. inc(l,pdc.paratype.def.size);
  2684. end;
  2685. l:=align(l,alignsize);
  2686. pdc:=TParaItem(pdc.next);
  2687. end;
  2688. para_size:=l;
  2689. end;
  2690. function tabstractprocdef.demangled_paras : string;
  2691. var
  2692. hs,s : string;
  2693. hp : TParaItem;
  2694. hpc : tconstsym;
  2695. begin
  2696. hp:=TParaItem(Para.last);
  2697. if not(assigned(hp)) then
  2698. begin
  2699. demangled_paras:='';
  2700. exit;
  2701. end;
  2702. s:='(';
  2703. while assigned(hp) do
  2704. begin
  2705. if assigned(hp.paratype.def.typesym) then
  2706. s:=s+hp.paratype.def.typesym.realname
  2707. else if hp.paratyp=vs_var then
  2708. s:=s+'var'
  2709. else if hp.paratyp=vs_const then
  2710. s:=s+'const'
  2711. else if hp.paratyp=vs_out then
  2712. s:=s+'out';
  2713. { default value }
  2714. if assigned(hp.defaultvalue) then
  2715. begin
  2716. hpc:=tconstsym(hp.defaultvalue);
  2717. hs:='';
  2718. case hpc.consttyp of
  2719. conststring,
  2720. constresourcestring :
  2721. hs:=strpas(pchar(hpc.valueptr));
  2722. constreal :
  2723. str(pbestreal(hpc.valueptr)^,hs);
  2724. constord :
  2725. hs:=tostr(hpc.valueord);
  2726. constpointer :
  2727. hs:=tostr(hpc.valueordptr);
  2728. constbool :
  2729. begin
  2730. if hpc.valueord<>0 then
  2731. hs:='TRUE'
  2732. else
  2733. hs:='FALSE';
  2734. end;
  2735. constnil :
  2736. hs:='nil';
  2737. constchar :
  2738. hs:=chr(hpc.valueord);
  2739. constset :
  2740. hs:='<set>';
  2741. end;
  2742. if hs<>'' then
  2743. s:=s+'="'+hs+'"';
  2744. end;
  2745. hp:=TParaItem(hp.previous);
  2746. if assigned(hp) then
  2747. s:=s+',';
  2748. end;
  2749. s:=s+')';
  2750. if (po_varargs in procoptions) then
  2751. s:=s+';VarArgs';
  2752. demangled_paras:=s;
  2753. end;
  2754. function tabstractprocdef.proccalloption2str : string;
  2755. type
  2756. tproccallopt=record
  2757. mask : tproccalloption;
  2758. str : string[30];
  2759. end;
  2760. const
  2761. proccallopts=13;
  2762. proccallopt : array[1..proccallopts] of tproccallopt=(
  2763. (mask:pocall_none; str:''),
  2764. (mask:pocall_clearstack; str:'ClearStack'),
  2765. (mask:pocall_leftright; str:'LeftRight'),
  2766. (mask:pocall_cdecl; str:'CDecl'),
  2767. (mask:pocall_register; str:'Register'),
  2768. (mask:pocall_stdcall; str:'StdCall'),
  2769. (mask:pocall_safecall; str:'SafeCall'),
  2770. (mask:pocall_palmossyscall;str:'PalmOSSysCall'),
  2771. (mask:pocall_system; str:'System'),
  2772. (mask:pocall_inline; str:'Inline'),
  2773. (mask:pocall_internproc; str:'InternProc'),
  2774. (mask:pocall_internconst; str:'InternConst'),
  2775. (mask:pocall_cppdecl; str:'CPPDecl')
  2776. );
  2777. var
  2778. s : string;
  2779. i : longint;
  2780. first : boolean;
  2781. begin
  2782. s:='';
  2783. first:=true;
  2784. for i:=1 to proccallopts do
  2785. if (proccallopt[i].mask in proccalloptions) then
  2786. begin
  2787. if first then
  2788. first:=false
  2789. else
  2790. s:=s+';';
  2791. s:=s+proccallopt[i].str;
  2792. end;
  2793. proccalloption2str:=s;
  2794. end;
  2795. {$ifdef GDB}
  2796. function tabstractprocdef.stabstring : pchar;
  2797. begin
  2798. stabstring := strpnew('abstractproc'+numberstring+';');
  2799. end;
  2800. procedure tabstractprocdef.concatstabto(asmlist : taasmoutput);
  2801. begin
  2802. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2803. and (is_def_stab_written = not_written) then
  2804. begin
  2805. if assigned(rettype.def) then forcestabto(asmlist,rettype.def);
  2806. inherited concatstabto(asmlist);
  2807. end;
  2808. end;
  2809. {$endif GDB}
  2810. {***************************************************************************
  2811. TPROCDEF
  2812. ***************************************************************************}
  2813. constructor tprocdef.create;
  2814. begin
  2815. inherited create;
  2816. deftype:=procdef;
  2817. _mangledname:=nil;
  2818. nextoverloaded:=nil;
  2819. fileinfo:=aktfilepos;
  2820. extnumber:=-1;
  2821. aliasnames:=tstringlist.create;
  2822. localst:=tlocalsymtable.create;
  2823. parast:=tparasymtable.create;
  2824. funcretsym:=nil;
  2825. localst.defowner:=self;
  2826. parast.defowner:=self;
  2827. { this is used by insert
  2828. to check same names in parast and localst }
  2829. localst.next:=parast;
  2830. defref:=nil;
  2831. crossref:=nil;
  2832. lastwritten:=nil;
  2833. refcount:=0;
  2834. if (cs_browser in aktmoduleswitches) and make_ref then
  2835. begin
  2836. defref:=tref.create(defref,@akttokenpos);
  2837. inc(refcount);
  2838. end;
  2839. lastref:=defref;
  2840. { first, we assume that all registers are used }
  2841. {$ifdef newcg}
  2842. usedregisters:=[firstreg..lastreg];
  2843. {$else newcg}
  2844. {$ifdef i386}
  2845. usedregisters:=$ff;
  2846. {$endif i386}
  2847. {$ifdef POWERPC}
  2848. { on the PPC, we use the OS specific standard calling conventions }
  2849. { so the information about the used register isn't necessary yet }
  2850. usedregisters:=0;
  2851. {$endif POWERPC}
  2852. {$endif newcg}
  2853. forwarddef:=true;
  2854. interfacedef:=false;
  2855. hasforward:=false;
  2856. _class := nil;
  2857. code:=nil;
  2858. regvarinfo := nil;
  2859. count:=false;
  2860. is_used:=false;
  2861. end;
  2862. constructor tprocdef.load(ppufile:tcompilerppufile);
  2863. begin
  2864. inherited load(ppufile);
  2865. deftype:=procdef;
  2866. {$ifdef newcg}
  2867. readnormalset(usedregisters);
  2868. {$else newcg}
  2869. {$ifdef i386}
  2870. usedregisters:=ppufile.getbyte;
  2871. {$else}
  2872. {$ifdef POWERPC}
  2873. { on the PPC, we use the OS specific standard calling conventions }
  2874. { so the information about the used register isn't necessary yet }
  2875. usedregisters:=0;
  2876. {$else POWERPC}
  2877. readnormalset(usedregisters);
  2878. {$endif POWERPC}
  2879. {$endif}
  2880. {$endif newcg}
  2881. _mangledname:=stringdup(ppufile.getstring);
  2882. extnumber:=ppufile.getlongint;
  2883. nextoverloaded:=tprocdef(ppufile.getderef);
  2884. _class := tobjectdef(ppufile.getderef);
  2885. ppufile.getposinfo(fileinfo);
  2886. { inline stuff }
  2887. if (pocall_inline in proccalloptions) then
  2888. funcretsym:=tsym(ppufile.getderef)
  2889. else
  2890. funcretsym:=nil;
  2891. { load para and local symtables }
  2892. parast:=tparasymtable.create;
  2893. tparasymtable(parast).load(ppufile);
  2894. parast.defowner:=self;
  2895. if (pocall_inline in proccalloptions) or
  2896. ((current_module.flags and uf_local_browser)<>0) then
  2897. begin
  2898. localst:=tlocalsymtable.create;
  2899. tlocalsymtable(localst).load(ppufile);
  2900. localst.defowner:=self;
  2901. end
  2902. else
  2903. localst:=nil;
  2904. { default values for no persistent data }
  2905. if (cs_link_deffile in aktglobalswitches) and
  2906. (tf_need_export in target_info.flags) and
  2907. (po_exports in procoptions) then
  2908. deffile.AddExport(mangledname);
  2909. aliasnames:=tstringlist.create;
  2910. forwarddef:=false;
  2911. interfacedef:=false;
  2912. hasforward:=false;
  2913. code := nil;
  2914. regvarinfo := nil;
  2915. lastref:=nil;
  2916. lastwritten:=nil;
  2917. defref:=nil;
  2918. refcount:=0;
  2919. count:=true;
  2920. is_used:=false;
  2921. end;
  2922. destructor tprocdef.destroy;
  2923. begin
  2924. if assigned(defref) then
  2925. begin
  2926. defref.freechain;
  2927. defref.free;
  2928. end;
  2929. aliasnames.free;
  2930. if assigned(parast) then
  2931. parast.free;
  2932. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  2933. localst.free;
  2934. if (pocall_inline in proccalloptions) and assigned(code) then
  2935. tnode(code).free;
  2936. if assigned(regvarinfo) then
  2937. dispose(pregvarinfo(regvarinfo));
  2938. if (po_msgstr in procoptions) then
  2939. strdispose(messageinf.str);
  2940. if assigned(_mangledname) then
  2941. stringdispose(_mangledname);
  2942. inherited destroy;
  2943. end;
  2944. procedure tprocdef.write(ppufile:tcompilerppufile);
  2945. var
  2946. oldintfcrc : boolean;
  2947. begin
  2948. inherited write(ppufile);
  2949. oldintfcrc:=ppufile.do_interface_crc;
  2950. ppufile.do_interface_crc:=false;
  2951. { set all registers to used for simplified compilation PM }
  2952. if simplify_ppu then
  2953. begin
  2954. {$ifdef newcg}
  2955. usedregisters:=[firstreg..lastreg];
  2956. {$else newcg}
  2957. {$ifdef i386}
  2958. usedregisters:=$ff;
  2959. {$else}
  2960. {$ifdef POWERPC}
  2961. { on the PPC, we use the OS specific standard calling conventions }
  2962. { so the information about the used register isn't necessary yet }
  2963. usedregisters:=0;
  2964. {$else POWERPC}
  2965. usedregisters:=[firstreg..lastreg];
  2966. {$endif POWERPC}
  2967. {$endif i386}
  2968. {$endif newcg}
  2969. end;
  2970. {$ifdef newcg}
  2971. writenormalset(usedregisters);
  2972. {$else newcg}
  2973. {$ifdef i386}
  2974. ppufile.putbyte(usedregisters);
  2975. {$else}
  2976. {$ifdef POWERPC}
  2977. { on the PPC, we use the OS specific standard calling conventions }
  2978. { so the information about the used register isn't necessary yet }
  2979. {$else POWERPC}
  2980. writenormalset(usedregisters);
  2981. {$endif POWERPC}
  2982. {$endif i386}
  2983. {$endif newcg}
  2984. ppufile.do_interface_crc:=oldintfcrc;
  2985. ppufile.putstring(mangledname);
  2986. ppufile.putlongint(extnumber);
  2987. if (proctypeoption<>potype_operator) then
  2988. ppufile.putderef(nextoverloaded)
  2989. else
  2990. begin
  2991. { only write the overloads from the same unit }
  2992. if assigned(nextoverloaded) and
  2993. (nextoverloaded.owner=owner) then
  2994. ppufile.putderef(nextoverloaded)
  2995. else
  2996. ppufile.putderef(nil);
  2997. end;
  2998. ppufile.putderef(_class);
  2999. ppufile.putposinfo(fileinfo);
  3000. { inline stuff references to localsymtable, no influence
  3001. on the crc }
  3002. oldintfcrc:=ppufile.do_crc;
  3003. ppufile.do_crc:=false;
  3004. if (pocall_inline in proccalloptions) then
  3005. ppufile.putderef(funcretsym);
  3006. ppufile.do_crc:=oldintfcrc;
  3007. { write this entry }
  3008. ppufile.writeentry(ibprocdef);
  3009. { Save the para symtable, this is taken from the interface }
  3010. if not assigned(parast) then
  3011. begin
  3012. parast:=tparasymtable.create;
  3013. parast.defowner:=self;
  3014. end;
  3015. tparasymtable(parast).write(ppufile);
  3016. { save localsymtable for inline procedures or when local
  3017. browser info is requested, this has no influence on the crc }
  3018. if (pocall_inline in proccalloptions) or
  3019. ((current_module.flags and uf_local_browser)<>0) then
  3020. begin
  3021. oldintfcrc:=ppufile.do_crc;
  3022. ppufile.do_crc:=false;
  3023. if not assigned(localst) then
  3024. begin
  3025. localst:=tlocalsymtable.create;
  3026. localst.defowner:=self;
  3027. end;
  3028. tlocalsymtable(localst).write(ppufile);
  3029. ppufile.do_crc:=oldintfcrc;
  3030. end;
  3031. end;
  3032. function tprocdef.fullprocname:string;
  3033. var
  3034. s : string;
  3035. begin
  3036. s:='';
  3037. if assigned(_class) then
  3038. s:=_class.objname^+'.';
  3039. s:=s+procsym.realname+demangled_paras;
  3040. fullprocname:=s;
  3041. end;
  3042. function tprocdef.fullprocnamewithret:string;
  3043. var
  3044. s : string;
  3045. begin
  3046. s:=fullprocname;
  3047. if assigned(rettype.def) and
  3048. not(is_equal(rettype.def,voidtype.def)) then
  3049. s:=s+' : '+rettype.def.gettypename;
  3050. fullprocnamewithret:=s;
  3051. end;
  3052. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3053. begin
  3054. case t of
  3055. gs_local :
  3056. getsymtable:=localst;
  3057. gs_para :
  3058. getsymtable:=parast;
  3059. else
  3060. getsymtable:=nil;
  3061. end;
  3062. end;
  3063. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3064. var
  3065. pos : tfileposinfo;
  3066. move_last : boolean;
  3067. begin
  3068. move_last:=lastwritten=lastref;
  3069. while (not ppufile.endofentry) do
  3070. begin
  3071. ppufile.getposinfo(pos);
  3072. inc(refcount);
  3073. lastref:=tref.create(lastref,@pos);
  3074. lastref.is_written:=true;
  3075. if refcount=1 then
  3076. defref:=lastref;
  3077. end;
  3078. if move_last then
  3079. lastwritten:=lastref;
  3080. if ((current_module.flags and uf_local_browser)<>0) and
  3081. locals then
  3082. begin
  3083. tparasymtable(parast).load_references(ppufile,locals);
  3084. tlocalsymtable(localst).load_references(ppufile,locals);
  3085. end;
  3086. end;
  3087. Const
  3088. local_symtable_index : longint = $8001;
  3089. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3090. var
  3091. ref : tref;
  3092. pdo : tobjectdef;
  3093. move_last : boolean;
  3094. begin
  3095. move_last:=lastwritten=lastref;
  3096. if move_last and
  3097. (((current_module.flags and uf_local_browser)=0) or
  3098. not locals) then
  3099. exit;
  3100. { write address of this symbol }
  3101. ppufile.putderef(self);
  3102. { write refs }
  3103. if assigned(lastwritten) then
  3104. ref:=lastwritten
  3105. else
  3106. ref:=defref;
  3107. while assigned(ref) do
  3108. begin
  3109. if ref.moduleindex=current_module.unit_index then
  3110. begin
  3111. ppufile.putposinfo(ref.posinfo);
  3112. ref.is_written:=true;
  3113. if move_last then
  3114. lastwritten:=ref;
  3115. end
  3116. else if not ref.is_written then
  3117. move_last:=false
  3118. else if move_last then
  3119. lastwritten:=ref;
  3120. ref:=ref.nextref;
  3121. end;
  3122. ppufile.writeentry(ibdefref);
  3123. write_references:=true;
  3124. if ((current_module.flags and uf_local_browser)<>0) and
  3125. locals then
  3126. begin
  3127. pdo:=_class;
  3128. if (owner.symtabletype<>localsymtable) then
  3129. while assigned(pdo) do
  3130. begin
  3131. if pdo.symtable<>aktrecordsymtable then
  3132. begin
  3133. pdo.symtable.unitid:=local_symtable_index;
  3134. inc(local_symtable_index);
  3135. end;
  3136. pdo:=pdo.childof;
  3137. end;
  3138. parast.unitid:=local_symtable_index;
  3139. inc(local_symtable_index);
  3140. localst.unitid:=local_symtable_index;
  3141. inc(local_symtable_index);
  3142. tstoredsymtable(parast).write_references(ppufile,locals);
  3143. tstoredsymtable(localst).write_references(ppufile,locals);
  3144. { decrement for }
  3145. local_symtable_index:=local_symtable_index-2;
  3146. pdo:=_class;
  3147. if (owner.symtabletype<>localsymtable) then
  3148. while assigned(pdo) do
  3149. begin
  3150. if pdo.symtable<>aktrecordsymtable then
  3151. dec(local_symtable_index);
  3152. pdo:=pdo.childof;
  3153. end;
  3154. end;
  3155. end;
  3156. function tprocdef.haspara:boolean;
  3157. begin
  3158. haspara:=assigned(parast.symindex.first);
  3159. end;
  3160. {$ifdef GDB}
  3161. { procedure addparaname(p : tsym);
  3162. var vs : char;
  3163. begin
  3164. if tvarsym(p).varspez = vs_value then vs := '1'
  3165. else vs := '0';
  3166. strpcopy(strend(StabRecString),p^.name+':'+tstoreddef(tvarsym(p).vartype.def).numberstring+','+vs+';');
  3167. end; }
  3168. function tprocdef.stabstring : pchar;
  3169. var
  3170. i : longint;
  3171. stabrecstring : pchar;
  3172. begin
  3173. getmem(StabRecString,1024);
  3174. strpcopy(StabRecString,'f'+tstoreddef(rettype.def).numberstring);
  3175. i:=maxparacount;
  3176. if i>0 then
  3177. begin
  3178. strpcopy(strend(StabRecString),','+tostr(i)+';');
  3179. (* confuse gdb !! PM
  3180. if assigned(parast) then
  3181. parast.foreach({$ifdef FPCPROCVAR}@{$endif}addparaname)
  3182. else
  3183. begin
  3184. param := para1;
  3185. i := 0;
  3186. while assigned(param) do
  3187. begin
  3188. inc(i);
  3189. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3190. {Here we have lost the parameter names !!}
  3191. {using lower case parameters }
  3192. strpcopy(strend(stabrecstring),'p'+tostr(i)
  3193. +':'+param^.paratype.def.numberstring+','+vartyp+';');
  3194. param := param^.next;
  3195. end;
  3196. end; *)
  3197. {strpcopy(strend(StabRecString),';');}
  3198. end;
  3199. stabstring := strnew(stabrecstring);
  3200. freemem(stabrecstring,1024);
  3201. end;
  3202. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3203. begin
  3204. end;
  3205. {$endif GDB}
  3206. procedure tprocdef.deref;
  3207. var
  3208. oldlocalsymtable : tsymtable;
  3209. begin
  3210. inherited deref;
  3211. resolvedef(tdef(nextoverloaded));
  3212. resolvedef(tdef(_class));
  3213. { parast }
  3214. oldlocalsymtable:=aktlocalsymtable;
  3215. aktlocalsymtable:=parast;
  3216. tparasymtable(parast).deref;
  3217. aktlocalsymtable:=oldlocalsymtable;
  3218. end;
  3219. procedure tprocdef.derefimpl;
  3220. var
  3221. oldlocalsymtable : tsymtable;
  3222. begin
  3223. if assigned(localst) then
  3224. begin
  3225. { localst }
  3226. oldlocalsymtable:=aktlocalsymtable;
  3227. aktlocalsymtable:=localst;
  3228. { we can deref both interface and implementation parts }
  3229. tlocalsymtable(localst).deref;
  3230. tlocalsymtable(localst).derefimpl;
  3231. aktlocalsymtable:=oldlocalsymtable;
  3232. { funcretsym, this is always located in the localst }
  3233. resolvesym(funcretsym);
  3234. end
  3235. else
  3236. begin
  3237. { safety }
  3238. funcretsym:=nil;
  3239. end;
  3240. end;
  3241. function tprocdef.mangledname : string;
  3242. begin
  3243. if assigned(_mangledname) then
  3244. mangledname:=_mangledname^
  3245. else
  3246. mangledname:='';
  3247. if count then
  3248. is_used:=true;
  3249. end;
  3250. function tprocdef.cplusplusmangledname : string;
  3251. function getcppparaname(p : tdef) : string;
  3252. const
  3253. ordtype2str : array[tbasetype] of string[2] = (
  3254. '','','c',
  3255. 'Uc','Us','Ui',
  3256. 'Sc','s','i',
  3257. 'b','b','b',
  3258. 'Us','x','w');
  3259. var
  3260. s : string;
  3261. begin
  3262. case p.deftype of
  3263. orddef:
  3264. s:=ordtype2str[torddef(p).typ];
  3265. pointerdef:
  3266. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3267. else
  3268. internalerror(2103001);
  3269. end;
  3270. getcppparaname:=s;
  3271. end;
  3272. var
  3273. s,s2 : string;
  3274. param : TParaItem;
  3275. begin
  3276. s := procsym.realname;
  3277. if procsym.owner.symtabletype=objectsymtable then
  3278. begin
  3279. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3280. case proctypeoption of
  3281. potype_destructor:
  3282. s:='_$_'+tostr(length(s2))+s2;
  3283. potype_constructor:
  3284. s:='___'+tostr(length(s2))+s2;
  3285. else
  3286. s:='_'+s+'__'+tostr(length(s2))+s2;
  3287. end;
  3288. end
  3289. else s:=s+'__';
  3290. s:=s+'F';
  3291. { concat modifiers }
  3292. { !!!!! }
  3293. { now we handle the parameters }
  3294. param := TParaItem(Para.first);
  3295. if assigned(param) then
  3296. while assigned(param) do
  3297. begin
  3298. s2:=getcppparaname(param.paratype.def);
  3299. if param.paratyp in [vs_var,vs_out] then
  3300. s2:='R'+s2;
  3301. s:=s+s2;
  3302. param:=TParaItem(param.next);
  3303. end
  3304. else
  3305. s:=s+'v';
  3306. cplusplusmangledname:=s;
  3307. end;
  3308. procedure tprocdef.setmangledname(const s : string);
  3309. begin
  3310. if assigned(_mangledname) then
  3311. begin
  3312. {$ifdef MEMDEBUG}
  3313. dec(manglenamesize,length(_mangledname^));
  3314. {$endif}
  3315. stringdispose(_mangledname);
  3316. end;
  3317. _mangledname:=stringdup(s);
  3318. {$ifdef MEMDEBUG}
  3319. inc(manglenamesize,length(s));
  3320. {$endif}
  3321. {$ifdef EXTDEBUG}
  3322. if assigned(parast) then
  3323. begin
  3324. stringdispose(parast.name);
  3325. parast.name:=stringdup('args of '+s);
  3326. end;
  3327. if assigned(localst) then
  3328. begin
  3329. stringdispose(localst.name);
  3330. localst.name:=stringdup('locals of '+s);
  3331. end;
  3332. {$endif}
  3333. end;
  3334. {***************************************************************************
  3335. TPROCVARDEF
  3336. ***************************************************************************}
  3337. constructor tprocvardef.create;
  3338. begin
  3339. inherited create;
  3340. deftype:=procvardef;
  3341. end;
  3342. constructor tprocvardef.load(ppufile:tcompilerppufile);
  3343. begin
  3344. inherited load(ppufile);
  3345. deftype:=procvardef;
  3346. end;
  3347. procedure tprocvardef.write(ppufile:tcompilerppufile);
  3348. begin
  3349. { here we cannot get a real good value so just give something }
  3350. { plausible (PM) }
  3351. { a more secure way would be
  3352. to allways store in a temp }
  3353. if is_fpu(rettype.def) then
  3354. fpu_used:=2
  3355. else
  3356. fpu_used:=0;
  3357. inherited write(ppufile);
  3358. ppufile.writeentry(ibprocvardef);
  3359. end;
  3360. function tprocvardef.size : longint;
  3361. begin
  3362. if (po_methodpointer in procoptions) then
  3363. size:=2*target_info.size_of_pointer
  3364. else
  3365. size:=target_info.size_of_pointer;
  3366. end;
  3367. {$ifdef GDB}
  3368. function tprocvardef.stabstring : pchar;
  3369. var
  3370. nss : pchar;
  3371. { i : longint; }
  3372. begin
  3373. { i := maxparacount; }
  3374. getmem(nss,1024);
  3375. { it is not a function but a function pointer !! (PM) }
  3376. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)}+';');
  3377. { this confuses gdb !!
  3378. we should use 'F' instead of 'f' but
  3379. as we use c++ language mode
  3380. it does not like that either
  3381. Please do not remove this part
  3382. might be used once
  3383. gdb for pascal is ready PM }
  3384. (*
  3385. param := para1;
  3386. i := 0;
  3387. while assigned(param) do
  3388. begin
  3389. inc(i);
  3390. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3391. {Here we have lost the parameter names !!}
  3392. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3393. strcat(nss,pst);
  3394. strdispose(pst);
  3395. param := param^.next;
  3396. end; *)
  3397. {strpcopy(strend(nss),';');}
  3398. stabstring := strnew(nss);
  3399. freemem(nss,1024);
  3400. end;
  3401. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3402. begin
  3403. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  3404. and (is_def_stab_written = not_written) then
  3405. inherited concatstabto(asmlist);
  3406. is_def_stab_written:=written;
  3407. end;
  3408. {$endif GDB}
  3409. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3410. var
  3411. pdc : TParaItem;
  3412. methodkind, paraspec : byte;
  3413. begin
  3414. if po_methodpointer in procoptions then
  3415. begin
  3416. { write method id and name }
  3417. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  3418. write_rtti_name;
  3419. { write kind of method (can only be function or procedure)}
  3420. if rettype.def = voidtype.def then
  3421. methodkind := mkProcedure
  3422. else
  3423. methodkind := mkFunction;
  3424. rttiList.concat(Tai_const.Create_8bit(methodkind));
  3425. { get # of parameters }
  3426. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  3427. { write parameter info. The parameters must be written in reverse order
  3428. if this method uses right to left parameter pushing! }
  3429. if (pocall_leftright in proccalloptions) then
  3430. pdc:=TParaItem(Para.last)
  3431. else
  3432. pdc:=TParaItem(Para.first);
  3433. while assigned(pdc) do
  3434. begin
  3435. case pdc.paratyp of
  3436. vs_value: paraspec := 0;
  3437. vs_const: paraspec := pfConst;
  3438. vs_var : paraspec := pfVar;
  3439. vs_out : paraspec := pfOut;
  3440. end;
  3441. { write flags for current parameter }
  3442. rttiList.concat(Tai_const.Create_8bit(paraspec));
  3443. { write name of current parameter ### how can I get this??? (sg)}
  3444. rttiList.concat(Tai_const.Create_8bit(0));
  3445. { write name of type of current parameter }
  3446. tstoreddef(pdc.paratype.def).write_rtti_name;
  3447. if (pocall_leftright in proccalloptions) then
  3448. pdc:=TParaItem(pdc.previous)
  3449. else
  3450. pdc:=TParaItem(pdc.next);
  3451. end;
  3452. { write name of result type }
  3453. tstoreddef(rettype.def).write_rtti_name;
  3454. end;
  3455. end;
  3456. function tprocvardef.is_publishable : boolean;
  3457. begin
  3458. is_publishable:=(po_methodpointer in procoptions);
  3459. end;
  3460. function tprocvardef.gettypename : string;
  3461. begin
  3462. if assigned(rettype.def) and
  3463. (rettype.def<>voidtype.def) then
  3464. gettypename:='<procedure variable type of function'+demangled_paras+
  3465. ':'+rettype.def.gettypename+';'+proccalloption2str+'>'
  3466. else
  3467. gettypename:='<procedure variable type of procedure'+demangled_paras+
  3468. ';'+proccalloption2str+'>';
  3469. end;
  3470. {***************************************************************************
  3471. TOBJECTDEF
  3472. ***************************************************************************}
  3473. {$ifdef GDB}
  3474. const
  3475. vtabletype : word = 0;
  3476. vtableassigned : boolean = false;
  3477. {$endif GDB}
  3478. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  3479. begin
  3480. inherited create;
  3481. objecttype:=ot;
  3482. deftype:=objectdef;
  3483. objectoptions:=[];
  3484. childof:=nil;
  3485. symtable:=tobjectsymtable.create(n);
  3486. { create space for vmt !! }
  3487. vmt_offset:=0;
  3488. symtable.datasize:=0;
  3489. symtable.defowner:=self;
  3490. { recordalign -1 means C record packing, that starts
  3491. with an alignment of 1 }
  3492. if aktalignment.recordalignmax=-1 then
  3493. symtable.dataalignment:=1
  3494. else
  3495. symtable.dataalignment:=aktalignment.recordalignmax;
  3496. lastvtableindex:=0;
  3497. set_parent(c);
  3498. objname:=stringdup(n);
  3499. { set up guid }
  3500. isiidguidvalid:=true; { default null guid }
  3501. fillchar(iidguid,sizeof(iidguid),0); { default null guid }
  3502. iidstr:=stringdup(''); { default is empty string }
  3503. { setup implemented interfaces }
  3504. if objecttype in [odt_class,odt_interfacecorba] then
  3505. implementedinterfaces:=timplementedinterfaces.create
  3506. else
  3507. implementedinterfaces:=nil;
  3508. {$ifdef GDB}
  3509. writing_class_record_stab:=false;
  3510. {$endif GDB}
  3511. end;
  3512. constructor tobjectdef.load(ppufile:tcompilerppufile);
  3513. var
  3514. oldread_member : boolean;
  3515. i,implintfcount: longint;
  3516. begin
  3517. inherited loaddef(ppufile);
  3518. deftype:=objectdef;
  3519. objecttype:=tobjectdeftype(ppufile.getbyte);
  3520. savesize:=ppufile.getlongint;
  3521. vmt_offset:=ppufile.getlongint;
  3522. objname:=stringdup(ppufile.getstring);
  3523. childof:=tobjectdef(ppufile.getderef);
  3524. ppufile.getsmallset(objectoptions);
  3525. { load guid }
  3526. iidstr:=nil;
  3527. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3528. begin
  3529. isiidguidvalid:=boolean(ppufile.getbyte);
  3530. ppufile.putguid(iidguid);
  3531. iidstr:=stringdup(ppufile.getstring);
  3532. lastvtableindex:=ppufile.getlongint;
  3533. end;
  3534. { load implemented interfaces }
  3535. if objecttype in [odt_class,odt_interfacecorba] then
  3536. begin
  3537. implementedinterfaces:=timplementedinterfaces.create;
  3538. implintfcount:=ppufile.getlongint;
  3539. for i:=1 to implintfcount do
  3540. begin
  3541. implementedinterfaces.addintfref(tdef(ppufile.getderef));
  3542. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  3543. end;
  3544. end
  3545. else
  3546. implementedinterfaces:=nil;
  3547. oldread_member:=read_member;
  3548. read_member:=true;
  3549. symtable:=tobjectsymtable.create(objname^);
  3550. tobjectsymtable(symtable).load(ppufile);
  3551. read_member:=oldread_member;
  3552. symtable.defowner:=self;
  3553. { handles the predefined class tobject }
  3554. { the last TOBJECT which is loaded gets }
  3555. { it ! }
  3556. if (childof=nil) and
  3557. (objecttype=odt_class) and
  3558. (upper(objname^)='TOBJECT') then
  3559. class_tobject:=self;
  3560. if (childof=nil) and
  3561. (objecttype=odt_interfacecom) and
  3562. (upper(objname^)='IUNKNOWN') then
  3563. interface_iunknown:=self;
  3564. {$ifdef GDB}
  3565. writing_class_record_stab:=false;
  3566. {$endif GDB}
  3567. end;
  3568. destructor tobjectdef.destroy;
  3569. begin
  3570. if assigned(symtable) then
  3571. symtable.free;
  3572. if (oo_is_forward in objectoptions) then
  3573. Message1(sym_e_class_forward_not_resolved,objname^);
  3574. stringdispose(objname);
  3575. stringdispose(iidstr);
  3576. if assigned(implementedinterfaces) then
  3577. implementedinterfaces.free;
  3578. inherited destroy;
  3579. end;
  3580. procedure tobjectdef.write(ppufile:tcompilerppufile);
  3581. var
  3582. oldread_member : boolean;
  3583. implintfcount : longint;
  3584. i : longint;
  3585. begin
  3586. inherited writedef(ppufile);
  3587. ppufile.putbyte(byte(objecttype));
  3588. ppufile.putlongint(size);
  3589. ppufile.putlongint(vmt_offset);
  3590. ppufile.putstring(objname^);
  3591. ppufile.putderef(childof);
  3592. ppufile.putsmallset(objectoptions);
  3593. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3594. begin
  3595. ppufile.putbyte(byte(isiidguidvalid));
  3596. ppufile.putguid(iidguid);
  3597. ppufile.putstring(iidstr^);
  3598. ppufile.putlongint(lastvtableindex);
  3599. end;
  3600. if objecttype in [odt_class,odt_interfacecorba] then
  3601. begin
  3602. implintfcount:=implementedinterfaces.count;
  3603. ppufile.putlongint(implintfcount);
  3604. for i:=1 to implintfcount do
  3605. begin
  3606. ppufile.putderef(implementedinterfaces.interfaces(i));
  3607. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  3608. end;
  3609. end;
  3610. ppufile.writeentry(ibobjectdef);
  3611. oldread_member:=read_member;
  3612. read_member:=true;
  3613. tobjectsymtable(symtable).write(ppufile);
  3614. read_member:=oldread_member;
  3615. end;
  3616. procedure tobjectdef.deref;
  3617. var
  3618. oldrecsyms : tsymtable;
  3619. begin
  3620. inherited deref;
  3621. resolvedef(tdef(childof));
  3622. oldrecsyms:=aktrecordsymtable;
  3623. aktrecordsymtable:=symtable;
  3624. tstoredsymtable(symtable).deref;
  3625. aktrecordsymtable:=oldrecsyms;
  3626. if objecttype in [odt_class,odt_interfacecorba] then
  3627. implementedinterfaces.deref;
  3628. end;
  3629. procedure tobjectdef.set_parent( c : tobjectdef);
  3630. begin
  3631. { nothing to do if the parent was not forward !}
  3632. if assigned(childof) then
  3633. exit;
  3634. childof:=c;
  3635. { some options are inherited !! }
  3636. if assigned(c) then
  3637. begin
  3638. { only important for classes }
  3639. lastvtableindex:=c.lastvtableindex;
  3640. objectoptions:=objectoptions+(c.objectoptions*
  3641. [oo_has_virtual,oo_has_private,oo_has_protected,
  3642. oo_has_constructor,oo_has_destructor]);
  3643. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3644. begin
  3645. { add the data of the anchestor class }
  3646. inc(symtable.datasize,c.symtable.datasize);
  3647. if (oo_has_vmt in objectoptions) and
  3648. (oo_has_vmt in c.objectoptions) then
  3649. dec(symtable.datasize,target_info.size_of_pointer);
  3650. { if parent has a vmt field then
  3651. the offset is the same for the child PM }
  3652. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3653. begin
  3654. vmt_offset:=c.vmt_offset;
  3655. include(objectoptions,oo_has_vmt);
  3656. end;
  3657. end;
  3658. end;
  3659. savesize := symtable.datasize;
  3660. end;
  3661. procedure tobjectdef.insertvmt;
  3662. begin
  3663. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3664. exit;
  3665. if (oo_has_vmt in objectoptions) then
  3666. internalerror(12345)
  3667. else
  3668. begin
  3669. symtable.datasize:=align(symtable.datasize,symtable.dataalignment);
  3670. vmt_offset:=symtable.datasize;
  3671. inc(symtable.datasize,target_info.size_of_pointer);
  3672. include(objectoptions,oo_has_vmt);
  3673. end;
  3674. end;
  3675. procedure tobjectdef.check_forwards;
  3676. begin
  3677. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3678. tstoredsymtable(symtable).check_forwards;
  3679. if (oo_is_forward in objectoptions) then
  3680. begin
  3681. { ok, in future, the forward can be resolved }
  3682. Message1(sym_e_class_forward_not_resolved,objname^);
  3683. exclude(objectoptions,oo_is_forward);
  3684. end;
  3685. end;
  3686. { true, if self inherits from d (or if they are equal) }
  3687. function tobjectdef.is_related(d : tobjectdef) : boolean;
  3688. var
  3689. hp : tobjectdef;
  3690. begin
  3691. hp:=self;
  3692. while assigned(hp) do
  3693. begin
  3694. if hp=d then
  3695. begin
  3696. is_related:=true;
  3697. exit;
  3698. end;
  3699. hp:=hp.childof;
  3700. end;
  3701. is_related:=false;
  3702. end;
  3703. procedure tobjectdef._searchdestructor(sym : tnamedindexitem);
  3704. var
  3705. p : tprocdef;
  3706. begin
  3707. { if we found already a destructor, then we exit }
  3708. if assigned(sd) then
  3709. exit;
  3710. if tsym(sym).typ=procsym then
  3711. begin
  3712. p:=tprocsym(sym).definition;
  3713. while assigned(p) do
  3714. begin
  3715. if p.proctypeoption=potype_destructor then
  3716. begin
  3717. sd:=p;
  3718. exit;
  3719. end;
  3720. p:=p.nextoverloaded;
  3721. end;
  3722. end;
  3723. end;
  3724. function tobjectdef.searchdestructor : tprocdef;
  3725. var
  3726. o : tobjectdef;
  3727. begin
  3728. searchdestructor:=nil;
  3729. o:=self;
  3730. sd:=nil;
  3731. while assigned(o) do
  3732. begin
  3733. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}_searchdestructor);
  3734. if assigned(sd) then
  3735. begin
  3736. searchdestructor:=sd;
  3737. exit;
  3738. end;
  3739. o:=o.childof;
  3740. end;
  3741. end;
  3742. function tobjectdef.size : longint;
  3743. begin
  3744. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  3745. size:=target_info.size_of_pointer
  3746. else
  3747. size:=symtable.datasize;
  3748. end;
  3749. function tobjectdef.alignment:longint;
  3750. begin
  3751. alignment:=symtable.dataalignment;
  3752. end;
  3753. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3754. begin
  3755. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3756. case objecttype of
  3757. odt_class:
  3758. vmtmethodoffset:=(index+12)*target_info.size_of_pointer;
  3759. odt_interfacecom,odt_interfacecorba:
  3760. vmtmethodoffset:=index*target_info.size_of_pointer;
  3761. else
  3762. {$ifdef WITHDMT}
  3763. vmtmethodoffset:=(index+4)*target_info.size_of_pointer;
  3764. {$else WITHDMT}
  3765. vmtmethodoffset:=(index+3)*target_info.size_of_pointer;
  3766. {$endif WITHDMT}
  3767. end;
  3768. end;
  3769. function tobjectdef.vmt_mangledname : string;
  3770. {DM: I get a nil pointer on the owner name. I don't know if this
  3771. may happen, and I have therefore fixed the problem by doing nil pointer
  3772. checks.}
  3773. var
  3774. s1,s2:string;
  3775. begin
  3776. if not(oo_has_vmt in objectoptions) then
  3777. Message1(parser_object_has_no_vmt,objname^);
  3778. if owner.name=nil then
  3779. s1:=''
  3780. else
  3781. s1:=upper(owner.name^);
  3782. if objname=nil then
  3783. s2:=''
  3784. else
  3785. s2:=Upper(objname^);
  3786. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  3787. end;
  3788. function tobjectdef.rtti_name : string;
  3789. var
  3790. s1,s2:string;
  3791. begin
  3792. if owner.name=nil then
  3793. s1:=''
  3794. else
  3795. s1:=upper(owner.name^);
  3796. if objname=nil then
  3797. s2:=''
  3798. else
  3799. s2:=Upper(objname^);
  3800. rtti_name:='RTTI_'+s1+'$_'+s2;
  3801. end;
  3802. {$ifdef GDB}
  3803. procedure tobjectdef.addprocname(p :tnamedindexitem);
  3804. var virtualind,argnames : string;
  3805. news, newrec : pchar;
  3806. pd,ipd : tprocdef;
  3807. lindex : longint;
  3808. para : TParaItem;
  3809. arglength : byte;
  3810. sp : char;
  3811. begin
  3812. If tsym(p).typ = procsym then
  3813. begin
  3814. pd := tprocsym(p).definition;
  3815. { this will be used for full implementation of object stabs
  3816. not yet done }
  3817. ipd := pd;
  3818. while assigned(ipd.nextoverloaded) do ipd := ipd.nextoverloaded;
  3819. if (po_virtualmethod in pd.procoptions) then
  3820. begin
  3821. lindex := pd.extnumber;
  3822. {doesnt seem to be necessary
  3823. lindex := lindex or $80000000;}
  3824. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  3825. end
  3826. else
  3827. virtualind := '.';
  3828. { used by gdbpas to recognize constructor and destructors }
  3829. if (pd.proctypeoption=potype_constructor) then
  3830. argnames:='__ct__'
  3831. else if (pd.proctypeoption=potype_destructor) then
  3832. argnames:='__dt__'
  3833. else
  3834. argnames := '';
  3835. { arguments are not listed here }
  3836. {we don't need another definition}
  3837. para := TParaItem(pd.Para.first);
  3838. while assigned(para) do
  3839. begin
  3840. if Para.paratype.def.deftype = formaldef then
  3841. begin
  3842. if Para.paratyp=vs_var then
  3843. argnames := argnames+'3var'
  3844. else if Para.paratyp=vs_const then
  3845. argnames:=argnames+'5const'
  3846. else if Para.paratyp=vs_out then
  3847. argnames:=argnames+'3out';
  3848. end
  3849. else
  3850. begin
  3851. { if the arg definition is like (v: ^byte;..
  3852. there is no sym attached to data !!! }
  3853. if assigned(Para.paratype.def.typesym) then
  3854. begin
  3855. arglength := length(Para.paratype.def.typesym.name);
  3856. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  3857. end
  3858. else
  3859. begin
  3860. argnames:=argnames+'11unnamedtype';
  3861. end;
  3862. end;
  3863. para := TParaItem(Para.next);
  3864. end;
  3865. ipd.is_def_stab_written := written;
  3866. { here 2A must be changed for private and protected }
  3867. { 0 is private 1 protected and 2 public }
  3868. if (sp_private in tsym(p).symoptions) then sp:='0'
  3869. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  3870. else sp:='2';
  3871. newrec := strpnew(p.name+'::'+ipd.numberstring
  3872. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  3873. +virtualind+';');
  3874. { get spare place for a string at the end }
  3875. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  3876. begin
  3877. getmem(news,stabrecsize+memsizeinc);
  3878. strcopy(news,stabrecstring);
  3879. freemem(stabrecstring,stabrecsize);
  3880. stabrecsize:=stabrecsize+memsizeinc;
  3881. stabrecstring:=news;
  3882. end;
  3883. strcat(StabRecstring,newrec);
  3884. {freemem(newrec,memsizeinc); }
  3885. strdispose(newrec);
  3886. {This should be used for case !!
  3887. RecOffset := RecOffset + pd.size;}
  3888. end;
  3889. end;
  3890. function tobjectdef.stabstring : pchar;
  3891. var anc : tobjectdef;
  3892. oldrec : pchar;
  3893. oldrecsize,oldrecoffset : longint;
  3894. str_end : string;
  3895. begin
  3896. if not (objecttype=odt_class) or writing_class_record_stab then
  3897. begin
  3898. oldrec := stabrecstring;
  3899. oldrecsize:=stabrecsize;
  3900. stabrecsize:=memsizeinc;
  3901. GetMem(stabrecstring,stabrecsize);
  3902. strpcopy(stabRecString,'s'+tostr(symtable.datasize));
  3903. if assigned(childof) then
  3904. begin
  3905. {only one ancestor not virtual, public, at base offset 0 }
  3906. { !1 , 0 2 0 , }
  3907. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  3908. end;
  3909. {virtual table to implement yet}
  3910. OldRecOffset:=RecOffset;
  3911. RecOffset := 0;
  3912. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname);
  3913. RecOffset:=OldRecOffset;
  3914. if (oo_has_vmt in objectoptions) then
  3915. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  3916. begin
  3917. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  3918. +','+tostr(vmt_offset*8)+';');
  3919. end;
  3920. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname);
  3921. if (oo_has_vmt in objectoptions) then
  3922. begin
  3923. anc := self;
  3924. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  3925. anc := anc.childof;
  3926. { just in case anc = self }
  3927. str_end:=';~%'+anc.classnumberstring+';';
  3928. end
  3929. else
  3930. str_end:=';';
  3931. strpcopy(strend(stabrecstring),str_end);
  3932. stabstring := strnew(StabRecString);
  3933. freemem(stabrecstring,stabrecsize);
  3934. stabrecstring := oldrec;
  3935. stabrecsize:=oldrecsize;
  3936. end
  3937. else
  3938. begin
  3939. stabstring:=strpnew('*'+classnumberstring);
  3940. end;
  3941. end;
  3942. procedure tobjectdef.set_globalnb;
  3943. begin
  3944. globalnb:=PglobalTypeCount^;
  3945. inc(PglobalTypeCount^);
  3946. { classes need two type numbers, the globalnb is set to the ptr }
  3947. if objecttype=odt_class then
  3948. begin
  3949. globalnb:=PGlobalTypeCount^;
  3950. inc(PglobalTypeCount^);
  3951. end;
  3952. end;
  3953. function tobjectdef.classnumberstring : string;
  3954. begin
  3955. { write stabs again if needed }
  3956. numberstring;
  3957. if objecttype=odt_class then
  3958. begin
  3959. dec(globalnb);
  3960. classnumberstring:=numberstring;
  3961. inc(globalnb);
  3962. end
  3963. else
  3964. classnumberstring:=numberstring;
  3965. end;
  3966. function tobjectdef.allstabstring : pchar;
  3967. var stabchar : string[2];
  3968. ss,st : pchar;
  3969. sname : string;
  3970. sym_line_no : longint;
  3971. begin
  3972. ss := stabstring;
  3973. getmem(st,strlen(ss)+512);
  3974. stabchar := 't';
  3975. if deftype in tagtypes then
  3976. stabchar := 'Tt';
  3977. if assigned(typesym) then
  3978. begin
  3979. sname := typesym.name;
  3980. sym_line_no:=typesym.fileinfo.line;
  3981. end
  3982. else
  3983. begin
  3984. sname := ' ';
  3985. sym_line_no:=0;
  3986. end;
  3987. if writing_class_record_stab then
  3988. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  3989. else
  3990. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  3991. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  3992. allstabstring := strnew(st);
  3993. freemem(st,strlen(ss)+512);
  3994. strdispose(ss);
  3995. end;
  3996. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  3997. var st : pstring;
  3998. begin
  3999. if objecttype<>odt_class then
  4000. begin
  4001. inherited concatstabto(asmlist);
  4002. exit;
  4003. end;
  4004. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4005. (is_def_stab_written = not_written) then
  4006. begin
  4007. if globalnb=0 then
  4008. set_globalnb;
  4009. { Write the record class itself }
  4010. writing_class_record_stab:=true;
  4011. inherited concatstabto(asmlist);
  4012. writing_class_record_stab:=false;
  4013. { Write the invisible pointer class }
  4014. is_def_stab_written:=not_written;
  4015. if assigned(typesym) then
  4016. begin
  4017. st:=typesym.FName;
  4018. typesym.FName:=stringdup(' ');
  4019. end;
  4020. inherited concatstabto(asmlist);
  4021. if assigned(typesym) then
  4022. begin
  4023. stringdispose(typesym.FName);
  4024. typesym.FName:=st;
  4025. end;
  4026. end;
  4027. end;
  4028. {$endif GDB}
  4029. function tobjectdef.needs_inittable : boolean;
  4030. begin
  4031. case objecttype of
  4032. odt_class :
  4033. needs_inittable:=false;
  4034. odt_interfacecom:
  4035. needs_inittable:=true;
  4036. odt_interfacecorba:
  4037. needs_inittable:=is_related(interface_iunknown);
  4038. odt_object:
  4039. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4040. else
  4041. internalerror(200108267);
  4042. end;
  4043. end;
  4044. procedure tobjectdef.count_published_properties(sym:tnamedindexitem);
  4045. begin
  4046. if needs_prop_entry(tsym(sym)) and
  4047. (tsym(sym).typ<>varsym) then
  4048. inc(count);
  4049. end;
  4050. procedure tobjectdef.write_property_info(sym : tnamedindexitem);
  4051. var
  4052. proctypesinfo : byte;
  4053. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4054. var
  4055. typvalue : byte;
  4056. hp : psymlistitem;
  4057. address : longint;
  4058. begin
  4059. if not(assigned(proc) and assigned(proc.firstsym)) then
  4060. begin
  4061. rttiList.concat(Tai_const.Create_32bit(1));
  4062. typvalue:=3;
  4063. end
  4064. else if proc.firstsym^.sym.typ=varsym then
  4065. begin
  4066. address:=0;
  4067. hp:=proc.firstsym;
  4068. while assigned(hp) do
  4069. begin
  4070. inc(address,tvarsym(hp^.sym).address);
  4071. hp:=hp^.next;
  4072. end;
  4073. rttiList.concat(Tai_const.Create_32bit(address));
  4074. typvalue:=0;
  4075. end
  4076. else
  4077. begin
  4078. if not(po_virtualmethod in tprocdef(proc.def).procoptions) then
  4079. begin
  4080. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.def).mangledname));
  4081. typvalue:=1;
  4082. end
  4083. else
  4084. begin
  4085. { virtual method, write vmt offset }
  4086. rttiList.concat(Tai_const.Create_32bit(
  4087. tprocdef(proc.def)._class.vmtmethodoffset(tprocdef(proc.def).extnumber)));
  4088. typvalue:=2;
  4089. end;
  4090. end;
  4091. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4092. end;
  4093. begin
  4094. if needs_prop_entry(tsym(sym)) then
  4095. case tsym(sym).typ of
  4096. varsym:
  4097. begin
  4098. {$ifdef dummy}
  4099. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4100. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4101. internalerror(1509992);
  4102. { access to implicit class property as field }
  4103. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4104. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4105. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4106. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4107. { per default stored }
  4108. rttiList.concat(Tai_const.Create_32bit(1));
  4109. { index as well as ... }
  4110. rttiList.concat(Tai_const.Create_32bit(0));
  4111. { default value are zero }
  4112. rttiList.concat(Tai_const.Create_32bit(0));
  4113. rttiList.concat(Tai_const.Create_16bit(count));
  4114. inc(count);
  4115. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4116. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4117. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4118. {$endif dummy}
  4119. end;
  4120. propertysym:
  4121. begin
  4122. if ppo_indexed in tpropertysym(sym).propoptions then
  4123. proctypesinfo:=$40
  4124. else
  4125. proctypesinfo:=0;
  4126. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4127. writeproc(tpropertysym(sym).readaccess,0);
  4128. writeproc(tpropertysym(sym).writeaccess,2);
  4129. { isn't it stored ? }
  4130. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4131. begin
  4132. rttiList.concat(Tai_const.Create_32bit(0));
  4133. proctypesinfo:=proctypesinfo or (3 shl 4);
  4134. end
  4135. else
  4136. writeproc(tpropertysym(sym).storedaccess,4);
  4137. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4138. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4139. rttiList.concat(Tai_const.Create_16bit(count));
  4140. inc(count);
  4141. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4142. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4143. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4144. end;
  4145. else internalerror(1509992);
  4146. end;
  4147. end;
  4148. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem);
  4149. begin
  4150. if needs_prop_entry(tsym(sym)) then
  4151. begin
  4152. case tsym(sym).typ of
  4153. propertysym:
  4154. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4155. else
  4156. internalerror(1509991);
  4157. end;
  4158. end;
  4159. end;
  4160. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4161. begin
  4162. FRTTIType:=rt;
  4163. case rt of
  4164. initrtti :
  4165. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti);
  4166. fullrtti :
  4167. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti);
  4168. else
  4169. internalerror(200108301);
  4170. end;
  4171. end;
  4172. type
  4173. tclasslistitem = class(tlinkedlistitem)
  4174. index : longint;
  4175. p : tobjectdef;
  4176. end;
  4177. var
  4178. classtablelist : tlinkedlist;
  4179. tablecount : longint;
  4180. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4181. var
  4182. hp : tclasslistitem;
  4183. begin
  4184. hp:=tclasslistitem(classtablelist.first);
  4185. while assigned(hp) do
  4186. if hp.p=p then
  4187. begin
  4188. searchclasstablelist:=hp;
  4189. exit;
  4190. end
  4191. else
  4192. hp:=tclasslistitem(hp.next);
  4193. searchclasstablelist:=nil;
  4194. end;
  4195. procedure tobjectdef.count_published_fields(sym:tnamedindexitem);
  4196. var
  4197. hp : tclasslistitem;
  4198. begin
  4199. if needs_prop_entry(tsym(sym)) and
  4200. (tsym(sym).typ=varsym) then
  4201. begin
  4202. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4203. internalerror(0206001);
  4204. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4205. if not(assigned(hp)) then
  4206. begin
  4207. hp:=tclasslistitem.create;
  4208. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4209. hp.index:=tablecount;
  4210. classtablelist.concat(hp);
  4211. inc(tablecount);
  4212. end;
  4213. inc(count);
  4214. end;
  4215. end;
  4216. procedure tobjectdef.writefields(sym:tnamedindexitem);
  4217. var
  4218. hp : tclasslistitem;
  4219. begin
  4220. if needs_prop_entry(tsym(sym)) and
  4221. (tsym(sym).typ=varsym) then
  4222. begin
  4223. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).address));
  4224. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4225. if not(assigned(hp)) then
  4226. internalerror(0206002);
  4227. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4228. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4229. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4230. end;
  4231. end;
  4232. function tobjectdef.generate_field_table : tasmlabel;
  4233. var
  4234. fieldtable,
  4235. classtable : tasmlabel;
  4236. hp : tclasslistitem;
  4237. begin
  4238. classtablelist:=TLinkedList.Create;
  4239. getdatalabel(fieldtable);
  4240. getdatalabel(classtable);
  4241. count:=0;
  4242. tablecount:=0;
  4243. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields);
  4244. rttiList.concat(Tai_label.Create(fieldtable));
  4245. rttiList.concat(Tai_const.Create_16bit(count));
  4246. rttiList.concat(Tai_const_symbol.Create(classtable));
  4247. symtable.foreach({$ifdef FPC}@{$endif}writefields);
  4248. { generate the class table }
  4249. rttiList.concat(Tai_label.Create(classtable));
  4250. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4251. hp:=tclasslistitem(classtablelist.first);
  4252. while assigned(hp) do
  4253. begin
  4254. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4255. hp:=tclasslistitem(hp.next);
  4256. end;
  4257. generate_field_table:=fieldtable;
  4258. classtablelist.free;
  4259. end;
  4260. function tobjectdef.next_free_name_index : longint;
  4261. var
  4262. i : longint;
  4263. begin
  4264. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4265. i:=childof.next_free_name_index
  4266. else
  4267. i:=0;
  4268. count:=0;
  4269. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties);
  4270. next_free_name_index:=i+count;
  4271. end;
  4272. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4273. begin
  4274. case objecttype of
  4275. odt_class:
  4276. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4277. odt_object:
  4278. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4279. odt_interfacecom:
  4280. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4281. odt_interfacecorba:
  4282. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4283. else
  4284. exit;
  4285. end;
  4286. { generate the name }
  4287. rttiList.concat(Tai_const.Create_8bit(length(objname^)));
  4288. rttiList.concat(Tai_string.Create(objname^));
  4289. case rt of
  4290. initrtti :
  4291. begin
  4292. rttiList.concat(Tai_const.Create_32bit(size));
  4293. if objecttype in [odt_class,odt_object] then
  4294. begin
  4295. count:=0;
  4296. FRTTIType:=rt;
  4297. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti);
  4298. rttiList.concat(Tai_const.Create_32bit(count));
  4299. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti);
  4300. end;
  4301. end;
  4302. fullrtti :
  4303. begin
  4304. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4305. rttiList.concat(Tai_const.Create_32bit(0))
  4306. else
  4307. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname));
  4308. { write owner typeinfo }
  4309. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4310. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4311. else
  4312. rttiList.concat(Tai_const.Create_32bit(0));
  4313. { count total number of properties }
  4314. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4315. count:=childof.next_free_name_index
  4316. else
  4317. count:=0;
  4318. { write it }
  4319. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties);
  4320. rttiList.concat(Tai_const.Create_16bit(count));
  4321. { write unit name }
  4322. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4323. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4324. { write published properties count }
  4325. count:=0;
  4326. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties);
  4327. rttiList.concat(Tai_const.Create_16bit(count));
  4328. { count is used to write nameindex }
  4329. { but we need an offset of the owner }
  4330. { to give each property an own slot }
  4331. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4332. count:=childof.next_free_name_index
  4333. else
  4334. count:=0;
  4335. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info);
  4336. end;
  4337. end;
  4338. end;
  4339. function tobjectdef.is_publishable : boolean;
  4340. begin
  4341. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4342. end;
  4343. {****************************************************************************
  4344. TIMPLEMENTEDINTERFACES
  4345. ****************************************************************************}
  4346. type
  4347. tnamemap = class(TNamedIndexItem)
  4348. newname: pstring;
  4349. constructor create(const aname, anewname: string);
  4350. destructor destroy; override;
  4351. end;
  4352. constructor tnamemap.create(const aname, anewname: string);
  4353. begin
  4354. inherited createname(name);
  4355. newname:=stringdup(anewname);
  4356. end;
  4357. destructor tnamemap.destroy;
  4358. begin
  4359. stringdispose(newname);
  4360. inherited destroy;
  4361. end;
  4362. type
  4363. tprocdefstore = class(TNamedIndexItem)
  4364. procdef: tprocdef;
  4365. constructor create(aprocdef: tprocdef);
  4366. end;
  4367. constructor tprocdefstore.create(aprocdef: tprocdef);
  4368. begin
  4369. inherited create;
  4370. procdef:=aprocdef;
  4371. end;
  4372. type
  4373. timplintfentry = class(TNamedIndexItem)
  4374. intf: tobjectdef;
  4375. ioffs: longint;
  4376. namemappings: tdictionary;
  4377. procdefs: TIndexArray;
  4378. constructor create(aintf: tobjectdef);
  4379. destructor destroy; override;
  4380. end;
  4381. constructor timplintfentry.create(aintf: tobjectdef);
  4382. begin
  4383. inherited create;
  4384. intf:=aintf;
  4385. ioffs:=-1;
  4386. namemappings:=nil;
  4387. procdefs:=nil;
  4388. end;
  4389. destructor timplintfentry.destroy;
  4390. begin
  4391. if assigned(namemappings) then
  4392. namemappings.free;
  4393. if assigned(procdefs) then
  4394. procdefs.free;
  4395. inherited destroy;
  4396. end;
  4397. constructor timplementedinterfaces.create;
  4398. begin
  4399. finterfaces:=tindexarray.create(1);
  4400. end;
  4401. destructor timplementedinterfaces.destroy;
  4402. begin
  4403. finterfaces.destroy;
  4404. end;
  4405. function timplementedinterfaces.count: longint;
  4406. begin
  4407. count:=finterfaces.count;
  4408. end;
  4409. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4410. begin
  4411. if (intfindex<1) or (intfindex>count) then
  4412. InternalError(200006123);
  4413. end;
  4414. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4415. begin
  4416. checkindex(intfindex);
  4417. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4418. end;
  4419. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  4420. begin
  4421. checkindex(intfindex);
  4422. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  4423. end;
  4424. function timplementedinterfaces.searchintf(def: tdef): longint;
  4425. var
  4426. i: longint;
  4427. begin
  4428. i:=1;
  4429. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4430. if i<=count then
  4431. searchintf:=i
  4432. else
  4433. searchintf:=-1;
  4434. end;
  4435. procedure timplementedinterfaces.deref;
  4436. var
  4437. i: longint;
  4438. begin
  4439. for i:=1 to count do
  4440. with timplintfentry(finterfaces.search(i)) do
  4441. resolvedef(tdef(intf));
  4442. end;
  4443. procedure timplementedinterfaces.addintfref(def: tdef);
  4444. begin
  4445. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4446. end;
  4447. procedure timplementedinterfaces.addintf(def: tdef);
  4448. begin
  4449. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4450. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4451. internalerror(200006124);
  4452. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4453. end;
  4454. procedure timplementedinterfaces.clearmappings;
  4455. var
  4456. i: longint;
  4457. begin
  4458. for i:=1 to count do
  4459. with timplintfentry(finterfaces.search(i)) do
  4460. begin
  4461. if assigned(namemappings) then
  4462. namemappings.free;
  4463. namemappings:=nil;
  4464. end;
  4465. end;
  4466. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  4467. begin
  4468. checkindex(intfindex);
  4469. with timplintfentry(finterfaces.search(intfindex)) do
  4470. begin
  4471. if not assigned(namemappings) then
  4472. namemappings:=tdictionary.create;
  4473. namemappings.insert(tnamemap.create(name,newname));
  4474. end;
  4475. end;
  4476. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  4477. begin
  4478. checkindex(intfindex);
  4479. if not assigned(nextexist) then
  4480. with timplintfentry(finterfaces.search(intfindex)) do
  4481. begin
  4482. if assigned(namemappings) then
  4483. nextexist:=namemappings.search(name)
  4484. else
  4485. nextexist:=nil;
  4486. end;
  4487. if assigned(nextexist) then
  4488. begin
  4489. getmappings:=tnamemap(nextexist).newname^;
  4490. nextexist:=tnamemap(nextexist).listnext;
  4491. end
  4492. else
  4493. getmappings:='';
  4494. end;
  4495. procedure timplementedinterfaces.clearimplprocs;
  4496. var
  4497. i: longint;
  4498. begin
  4499. for i:=1 to count do
  4500. with timplintfentry(finterfaces.search(i)) do
  4501. begin
  4502. if assigned(procdefs) then
  4503. procdefs.free;
  4504. procdefs:=nil;
  4505. end;
  4506. end;
  4507. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4508. begin
  4509. checkindex(intfindex);
  4510. with timplintfentry(finterfaces.search(intfindex)) do
  4511. begin
  4512. if not assigned(procdefs) then
  4513. procdefs:=tindexarray.create(4);
  4514. procdefs.insert(tprocdefstore.create(procdef));
  4515. end;
  4516. end;
  4517. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4518. begin
  4519. checkindex(intfindex);
  4520. with timplintfentry(finterfaces.search(intfindex)) do
  4521. if assigned(procdefs) then
  4522. implproccount:=procdefs.count
  4523. else
  4524. implproccount:=0;
  4525. end;
  4526. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4527. begin
  4528. checkindex(intfindex);
  4529. with timplintfentry(finterfaces.search(intfindex)) do
  4530. if assigned(procdefs) then
  4531. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4532. else
  4533. internalerror(200006131);
  4534. end;
  4535. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4536. var
  4537. possible: boolean;
  4538. i: longint;
  4539. iiep1: TIndexArray;
  4540. iiep2: TIndexArray;
  4541. begin
  4542. checkindex(intfindex);
  4543. checkindex(remainindex);
  4544. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4545. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4546. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4547. begin
  4548. possible:=true;
  4549. weight:=0;
  4550. end
  4551. else
  4552. begin
  4553. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4554. i:=1;
  4555. while (possible) and (i<=iiep1.count) do
  4556. begin
  4557. possible:=
  4558. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  4559. inc(i);
  4560. end;
  4561. if possible then
  4562. weight:=iiep1.count;
  4563. end;
  4564. isimplmergepossible:=possible;
  4565. end;
  4566. {****************************************************************************
  4567. TFORWARDDEF
  4568. ****************************************************************************}
  4569. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4570. var
  4571. oldregisterdef : boolean;
  4572. begin
  4573. { never register the forwarddefs, they are disposed at the
  4574. end of the type declaration block }
  4575. oldregisterdef:=registerdef;
  4576. registerdef:=false;
  4577. inherited create;
  4578. registerdef:=oldregisterdef;
  4579. deftype:=forwarddef;
  4580. tosymname:=s;
  4581. forwardpos:=pos;
  4582. end;
  4583. function tforwarddef.gettypename:string;
  4584. begin
  4585. gettypename:='unresolved forward to '+tosymname;
  4586. end;
  4587. {****************************************************************************
  4588. TERRORDEF
  4589. ****************************************************************************}
  4590. constructor terrordef.create;
  4591. begin
  4592. inherited create;
  4593. deftype:=errordef;
  4594. end;
  4595. {$ifdef GDB}
  4596. function terrordef.stabstring : pchar;
  4597. begin
  4598. stabstring:=strpnew('error'+numberstring);
  4599. end;
  4600. {$endif GDB}
  4601. function terrordef.gettypename:string;
  4602. begin
  4603. gettypename:='<erroneous type>';
  4604. end;
  4605. {****************************************************************************
  4606. GDB Helpers
  4607. ****************************************************************************}
  4608. {$ifdef GDB}
  4609. function typeglobalnumber(const s : string) : string;
  4610. var st : string;
  4611. symt : tsymtable;
  4612. srsym : tsym;
  4613. srsymtable : tsymtable;
  4614. old_make_ref : boolean;
  4615. begin
  4616. old_make_ref:=make_ref;
  4617. make_ref:=false;
  4618. typeglobalnumber := '0';
  4619. srsym := nil;
  4620. if pos('.',s) > 0 then
  4621. begin
  4622. st := copy(s,1,pos('.',s)-1);
  4623. searchsym(st,srsym,srsymtable);
  4624. st := copy(s,pos('.',s)+1,255);
  4625. if assigned(srsym) then
  4626. begin
  4627. if srsym.typ = unitsym then
  4628. begin
  4629. symt := tunitsym(srsym).unitsymtable;
  4630. srsym := tsym(symt.search(st));
  4631. end else srsym := nil;
  4632. end;
  4633. end else st := s;
  4634. if srsym = nil then
  4635. searchsym(st,srsym,srsymtable);
  4636. if (srsym=nil) or
  4637. (srsym.typ<>typesym) then
  4638. begin
  4639. Message(type_e_type_id_expected);
  4640. exit;
  4641. end;
  4642. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  4643. make_ref:=old_make_ref;
  4644. end;
  4645. {$endif GDB}
  4646. {****************************************************************************
  4647. Definition Helpers
  4648. ****************************************************************************}
  4649. procedure reset_global_defs;
  4650. var
  4651. def : tstoreddef;
  4652. {$ifdef debug}
  4653. prevdef : tstoreddef;
  4654. {$endif debug}
  4655. begin
  4656. {$ifdef debug}
  4657. prevdef:=nil;
  4658. {$endif debug}
  4659. {$ifdef GDB}
  4660. pglobaltypecount:=@globaltypecount;
  4661. {$endif GDB}
  4662. def:=firstglobaldef;
  4663. while assigned(def) do
  4664. begin
  4665. {$ifdef GDB}
  4666. if assigned(def.typesym) then
  4667. ttypesym(def.typesym).isusedinstab:=false;
  4668. def.is_def_stab_written:=not_written;
  4669. {$endif GDB}
  4670. { reset rangenr's }
  4671. case def.deftype of
  4672. orddef : torddef(def).rangenr:=0;
  4673. enumdef : tenumdef(def).rangenr:=0;
  4674. arraydef : tarraydef(def).rangenr:=0;
  4675. end;
  4676. def.localrttilab[initrtti]:=nil;
  4677. def.localrttilab[fullrtti]:=nil;
  4678. {$ifdef debug}
  4679. prevdef:=def;
  4680. {$endif debug}
  4681. def:=def.nextglobal;
  4682. end;
  4683. end;
  4684. function is_interfacecom(def: tdef): boolean;
  4685. begin
  4686. is_interfacecom:=
  4687. assigned(def) and
  4688. (def.deftype=objectdef) and
  4689. (tobjectdef(def).objecttype=odt_interfacecom);
  4690. end;
  4691. function is_interfacecorba(def: tdef): boolean;
  4692. begin
  4693. is_interfacecorba:=
  4694. assigned(def) and
  4695. (def.deftype=objectdef) and
  4696. (tobjectdef(def).objecttype=odt_interfacecorba);
  4697. end;
  4698. function is_interface(def: tdef): boolean;
  4699. begin
  4700. is_interface:=
  4701. assigned(def) and
  4702. (def.deftype=objectdef) and
  4703. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  4704. end;
  4705. function is_class(def: tdef): boolean;
  4706. begin
  4707. is_class:=
  4708. assigned(def) and
  4709. (def.deftype=objectdef) and
  4710. (tobjectdef(def).objecttype=odt_class);
  4711. end;
  4712. function is_object(def: tdef): boolean;
  4713. begin
  4714. is_object:=
  4715. assigned(def) and
  4716. (def.deftype=objectdef) and
  4717. (tobjectdef(def).objecttype=odt_object);
  4718. end;
  4719. function is_cppclass(def: tdef): boolean;
  4720. begin
  4721. is_cppclass:=
  4722. assigned(def) and
  4723. (def.deftype=objectdef) and
  4724. (tobjectdef(def).objecttype=odt_cppclass);
  4725. end;
  4726. function is_class_or_interface(def: tdef): boolean;
  4727. begin
  4728. is_class_or_interface:=
  4729. assigned(def) and
  4730. (def.deftype=objectdef) and
  4731. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  4732. end;
  4733. end.
  4734. {
  4735. $Log$
  4736. Revision 1.47 2001-09-02 21:18:28 peter
  4737. * split constsym.value in valueord,valueordptr,valueptr. The valueordptr
  4738. is used for holding target platform pointer values. As those can be
  4739. bigger than the source platform.
  4740. Revision 1.46 2001/08/30 20:13:54 peter
  4741. * rtti/init table updates
  4742. * rttisym for reusable global rtti/init info
  4743. * support published for interfaces
  4744. Revision 1.45 2001/08/26 13:36:49 florian
  4745. * some cg reorganisation
  4746. * some PPC updates
  4747. Revision 1.44 2001/08/22 21:16:22 florian
  4748. * some interfaces related problems regarding
  4749. mapping of interface implementions fixed
  4750. Revision 1.43 2001/08/19 09:39:27 peter
  4751. * local browser support fixed
  4752. Revision 1.41 2001/08/12 20:04:33 peter
  4753. * fpu_used=0 when simplify_ppu is used
  4754. * small crc updating fixes for tprocdef
  4755. Revision 1.40 2001/08/06 21:40:48 peter
  4756. * funcret moved from tprocinfo to tprocdef
  4757. Revision 1.39 2001/08/01 21:47:48 peter
  4758. * fixed passing of array of record or shortstring to open array
  4759. Revision 1.38 2001/07/30 20:59:27 peter
  4760. * m68k updates from v10 merged
  4761. Revision 1.37 2001/07/30 11:52:57 jonas
  4762. * fixed web bugs 1563/1564: procvars of object can't be regvars (merged)
  4763. Revision 1.36 2001/07/01 20:16:16 peter
  4764. * alignmentinfo record added
  4765. * -Oa argument supports more alignment settings that can be specified
  4766. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  4767. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  4768. required alignment and the maximum usefull alignment. The final
  4769. alignment will be choosen per variable size dependent on these
  4770. settings
  4771. Revision 1.35 2001/06/27 21:37:36 peter
  4772. * v10 merges
  4773. Revision 1.34 2001/06/04 18:05:39 peter
  4774. * procdef demangling fixed
  4775. Revision 1.33 2001/06/04 11:53:13 peter
  4776. + varargs directive
  4777. Revision 1.32 2001/05/09 19:58:45 peter
  4778. * m68k doesn't support double (merged)
  4779. Revision 1.31 2001/05/06 14:49:17 peter
  4780. * ppu object to class rewrite
  4781. * move ppu read and write stuff to fppu
  4782. Revision 1.30 2001/04/22 22:46:49 florian
  4783. * more variant support
  4784. Revision 1.29 2001/04/21 12:03:12 peter
  4785. * m68k updates merged from fixes branch
  4786. Revision 1.28 2001/04/18 22:01:58 peter
  4787. * registration of targets and assemblers
  4788. Revision 1.27 2001/04/13 01:22:15 peter
  4789. * symtable change to classes
  4790. * range check generation and errors fixed, make cycle DEBUG=1 works
  4791. * memory leaks fixed
  4792. Revision 1.26 2001/04/05 21:32:22 peter
  4793. * enum stabs fix (merged)
  4794. Revision 1.25 2001/04/04 21:30:45 florian
  4795. * applied several fixes to get the DD8 Delphi Unit compiled
  4796. e.g. "forward"-interfaces are working now
  4797. Revision 1.24 2001/04/02 21:20:34 peter
  4798. * resulttype rewrite
  4799. Revision 1.23 2001/03/22 23:28:39 florian
  4800. * correct initialisation of rec_tguid when loading the system unit
  4801. Revision 1.22 2001/03/22 00:10:58 florian
  4802. + basic variant type support in the compiler
  4803. Revision 1.21 2001/03/11 22:58:50 peter
  4804. * getsym redesign, removed the globals srsym,srsymtable
  4805. Revision 1.20 2001/01/06 20:11:29 peter
  4806. * merged c packrecords fix
  4807. Revision 1.19 2000/12/25 00:07:29 peter
  4808. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  4809. tlinkedlist objects)
  4810. Revision 1.18 2000/12/24 12:20:45 peter
  4811. * classes, enum stabs fixes merged from 1.0.x
  4812. Revision 1.17 2000/12/07 17:19:43 jonas
  4813. * new constant handling: from now on, hex constants >$7fffffff are
  4814. parsed as unsigned constants (otherwise, $80000000 got sign extended
  4815. and became $ffffffff80000000), all constants in the longint range
  4816. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  4817. are cardinals and the rest are int64's.
  4818. * added lots of longint typecast to prevent range check errors in the
  4819. compiler and rtl
  4820. * type casts of symbolic ordinal constants are now preserved
  4821. * fixed bug where the original resulttype.def wasn't restored correctly
  4822. after doing a 64bit rangecheck
  4823. Revision 1.16 2000/11/30 23:12:57 florian
  4824. * if raw interfaces inherit from IUnknown they are ref. counted too
  4825. Revision 1.15 2000/11/29 00:30:40 florian
  4826. * unused units removed from uses clause
  4827. * some changes for widestrings
  4828. Revision 1.14 2000/11/28 00:28:06 pierre
  4829. * stabs fixing
  4830. Revision 1.13 2000/11/26 18:09:40 florian
  4831. * fixed rtti for chars
  4832. Revision 1.12 2000/11/19 16:23:35 florian
  4833. *** empty log message ***
  4834. Revision 1.11 2000/11/12 23:24:12 florian
  4835. * interfaces are basically running
  4836. Revision 1.10 2000/11/11 16:12:38 peter
  4837. * add far; to typename for far pointer
  4838. Revision 1.9 2000/11/07 20:01:57 peter
  4839. * fix vmt index for classes
  4840. Revision 1.8 2000/11/06 23:13:53 peter
  4841. * uppercase manglednames
  4842. Revision 1.7 2000/11/06 23:11:38 florian
  4843. * writeln debugger uninstalled ;)
  4844. Revision 1.6 2000/11/06 23:05:52 florian
  4845. * more fixes
  4846. Revision 1.5 2000/11/06 20:30:55 peter
  4847. * more fixes to get make cycle working
  4848. Revision 1.4 2000/11/04 14:25:22 florian
  4849. + merged Attila's changes for interfaces, not tested yet
  4850. Revision 1.3 2000/11/02 12:04:10 pierre
  4851. * remove RecOffset code, that created problems
  4852. Revision 1.2 2000/11/01 23:04:38 peter
  4853. * tprocdef.fullprocname added for better casesensitve writing of
  4854. procedures
  4855. Revision 1.1 2000/10/31 22:02:52 peter
  4856. * symtable splitted, no real code changes
  4857. }