symdef.pas 334 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811
  1. {
  2. Symbol table implementation for the definitions
  3. Copyright (c) 1998-2005 by Florian Klaempfl, Pierre Muller
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symdef;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,widestr,
  23. { global }
  24. globtype,globals,tokens,constexp,
  25. { symtable }
  26. symconst,symbase,symtype,
  27. { node }
  28. node,
  29. { aasm }
  30. aasmtai,
  31. cpuinfo,
  32. cgbase,
  33. parabase
  34. ;
  35. type
  36. {************************************************
  37. TDef
  38. ************************************************}
  39. tgenericconstraintdata=class
  40. interfaces : tfpobjectlist;
  41. interfacesderef : tfplist;
  42. flags : tgenericconstraintflags;
  43. { only required while parsing }
  44. fileinfo : tfileposinfo;
  45. constructor create;
  46. destructor destroy;override;
  47. procedure ppuload(ppufile:tcompilerppufile);
  48. procedure ppuwrite(ppufile:tcompilerppufile);
  49. procedure buildderef;
  50. procedure deref;
  51. end;
  52. { trtti_attribute_list }
  53. trtti_attribute = class
  54. typesym : tsym;
  55. typesymderef : tderef;
  56. typeconstr : tdef;
  57. typeconstrderef : tderef;
  58. { these two are not stored in PPU }
  59. constructorcall : tnode;
  60. constructorpd : tdef;
  61. paras : array of tnode;
  62. constructor ppuload(ppufile:tcompilerppufile);
  63. procedure ppuwrite(ppufile:tcompilerppufile);
  64. procedure ppuload_subentries(ppufile:tcompilerppufile);
  65. procedure ppuwrite_subentries(ppufile:tcompilerppufile);
  66. destructor destroy;override;
  67. procedure buildderef;
  68. procedure deref;
  69. end;
  70. trtti_attribute_list = class
  71. rtti_attributes : TFPObjectList;
  72. { if the attribute list is bound to a def or symbol }
  73. is_bound : Boolean;
  74. class procedure bind(var dangling,owned:trtti_attribute_list);
  75. class procedure copyandbind(alist :trtti_attribute_list; var owned : trtti_attribute_list);
  76. procedure addattribute(atypesym:tsym;typeconstr:tdef;constructorcall:tnode;constref paras:array of tnode);
  77. procedure addattribute(attr:trtti_attribute);
  78. destructor destroy; override;
  79. function get_attribute_count:longint;
  80. procedure buildderef;
  81. procedure deref;
  82. class function ppuload(ppufile:tcompilerppufile):trtti_attribute_list;
  83. class procedure ppuwrite(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  84. class procedure ppuload_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  85. class procedure ppuwrite_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  86. end;
  87. { tstoreddef }
  88. tstoreddef = class(tdef)
  89. private
  90. {$ifdef symansistr}
  91. _fullownerhierarchyname : ansistring;
  92. {$else symansistr}
  93. _fullownerhierarchyname : pshortstring;
  94. {$endif symansistr}
  95. procedure writeentry(ppufile: tcompilerppufile; ibnr: byte);
  96. protected
  97. typesymderef : tderef;
  98. procedure ppuwrite_platform(ppufile:tcompilerppufile);virtual;
  99. procedure ppuload_platform(ppufile:tcompilerppufile);virtual;
  100. { a (possibly) reusable def is always created on the basis of another
  101. def, and contains a reference to this other def. If this other
  102. def is in a non-persistent symboltable, the new def cannot actually
  103. be safely reused everywhere in the current module. This routine
  104. abtracts that checking, and also restores the symtable stack
  105. (which had to be reset before creating the new def, so that the new
  106. def did not automatically get added to its top) }
  107. class procedure setup_reusable_def(origdef, newdef: tdef; res: PHashSetItem; oldsymtablestack: tsymtablestack);
  108. public
  109. {$ifdef EXTDEBUG}
  110. fileinfo : tfileposinfo;
  111. {$endif}
  112. { generic support }
  113. genericdef : tstoreddef;
  114. genericdefderef : tderef;
  115. generictokenbuf : tdynamicarray;
  116. { this list contains references to the symbols that make up the
  117. generic parameters; the symbols are not owned by this list
  118. Note: this list is allocated on demand! }
  119. genericparas : tfphashobjectlist;
  120. genericparaderefs : tfplist;
  121. { contains additional data if this def is a generic constraint
  122. Note: this class is allocated on demand! }
  123. genconstraintdata : tgenericconstraintdata;
  124. { this is Nil if the def has no RTTI attributes }
  125. rtti_attribute_list : trtti_attribute_list;
  126. { original def for "type <name>" declarations }
  127. orgdef : tstoreddef;
  128. orgdefderef : tderef;
  129. constructor create(dt:tdeftyp;doregister:boolean);
  130. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  131. destructor destroy;override;
  132. function getcopy : tstoreddef;virtual;
  133. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  134. { this is called directly after ppuload }
  135. procedure ppuload_subentries(ppufile:tcompilerppufile);virtual;
  136. { this is called directly after ppuwrite }
  137. procedure ppuwrite_subentries(ppufile:tcompilerppufile);virtual;
  138. procedure buildderef;override;
  139. procedure buildderefimpl;override;
  140. procedure deref;override;
  141. procedure derefimpl;override;
  142. function size:asizeint;override;
  143. function getvardef:longint;override;
  144. function alignment:shortint;override;
  145. function is_publishable : tpublishproperty;override;
  146. function needs_inittable : boolean;override;
  147. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  148. function rtti_mangledname(rt:trttitype):TSymStr;override;
  149. function OwnerHierarchyName: string; override;
  150. function OwnerHierarchyPrettyName: string; override;
  151. function fullownerhierarchyname(skipprocparams:boolean):TSymStr;override;
  152. function needs_separate_initrtti:boolean;override;
  153. function in_currentunit: boolean;
  154. { regvars }
  155. function is_intregable : boolean;
  156. function is_fpuregable : boolean;
  157. { def can be put into a register if it is const/immutable }
  158. function is_const_intregable : boolean;
  159. { generics }
  160. procedure initgeneric;
  161. { this function can be used to determine whether a def is really a
  162. generic declaration or just a normal type declared inside another
  163. generic }
  164. function is_generic:boolean;
  165. { same as above for specializations }
  166. function is_specialization:boolean;
  167. { generic utilities }
  168. function is_generic_param_const(index:integer):boolean;inline;
  169. function get_generic_param_def(index:integer):tdef;inline;
  170. { registers this def in the unit's deflist; no-op if already registered }
  171. procedure register_def; override;
  172. { add the def to the top of the symtable stack if it's not yet owned
  173. by another symtable }
  174. procedure maybe_put_in_symtable_stack;
  175. private
  176. savesize : asizeuint;
  177. end;
  178. tfiletyp = (ft_text,ft_typed,ft_untyped);
  179. tfiledef = class(tstoreddef)
  180. filetyp : tfiletyp;
  181. typedfiledef : tdef;
  182. typedfiledefderef : tderef;
  183. constructor createtext;virtual;
  184. constructor createuntyped;virtual;
  185. constructor createtyped(def : tdef);virtual;
  186. constructor ppuload(ppufile:tcompilerppufile);
  187. function getcopy : tstoreddef;override;
  188. { do not override this routine in platform-specific subclasses,
  189. override ppuwrite_platform instead }
  190. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  191. procedure buildderef;override;
  192. procedure deref;override;
  193. function GetTypeName:string;override;
  194. function getmangledparaname:TSymStr;override;
  195. function size:asizeint;override;
  196. procedure setsize;
  197. function alignment: shortint; override;
  198. end;
  199. tfiledefclass = class of tfiledef;
  200. tvariantdef = class(tstoreddef)
  201. varianttype : tvarianttype;
  202. constructor create(v : tvarianttype);virtual;
  203. constructor ppuload(ppufile:tcompilerppufile);
  204. function getcopy : tstoreddef;override;
  205. function GetTypeName:string;override;
  206. function alignment : shortint;override;
  207. { do not override this routine in platform-specific subclasses,
  208. override ppuwrite_platform instead }
  209. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  210. function getvardef:longint;override;
  211. procedure setsize;
  212. function is_publishable : tpublishproperty;override;
  213. function needs_inittable : boolean;override;
  214. end;
  215. tvariantdefclass = class of tvariantdef;
  216. tformaldef = class(tstoreddef)
  217. typed:boolean;
  218. constructor create(Atyped:boolean);virtual;
  219. constructor ppuload(ppufile:tcompilerppufile);
  220. { do not override this routine in platform-specific subclasses,
  221. override ppuwrite_platform instead }
  222. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  223. function GetTypeName:string;override;
  224. end;
  225. tformaldefclass = class of tformaldef;
  226. tforwarddef = class(tstoreddef)
  227. tosymname : pshortstring;
  228. forwardpos : tfileposinfo;
  229. constructor create(const s:string;const pos:tfileposinfo);virtual;
  230. destructor destroy;override;
  231. function getcopy:tstoreddef;override;
  232. function GetTypeName:string;override;
  233. end;
  234. tforwarddefclass = class of tforwarddef;
  235. tundefineddef = class(tstoreddef)
  236. constructor create(doregister:boolean);virtual;
  237. constructor ppuload(ppufile:tcompilerppufile);
  238. { do not override this routine in platform-specific subclasses,
  239. override ppuwrite_platform instead }
  240. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  241. function GetTypeName:string;override;
  242. end;
  243. tundefineddefclass = class of tundefineddef;
  244. terrordef = class(tstoreddef)
  245. constructor create;virtual;
  246. { do not override this routine in platform-specific subclasses,
  247. override ppuwrite_platform instead }
  248. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  249. function GetTypeName:string;override;
  250. function getmangledparaname : TSymStr;override;
  251. end;
  252. terrordefclass = class of terrordef;
  253. tabstractpointerdef = class(tstoreddef)
  254. pointeddef : tdef;
  255. pointeddefderef : tderef;
  256. constructor create(dt:tdeftyp;def:tdef);
  257. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  258. procedure ppuwrite(ppufile:tcompilerppufile);override;
  259. procedure buildderef;override;
  260. procedure deref;override;
  261. function size:asizeint;override;
  262. function alignment:shortint;override;
  263. end;
  264. tpointerdef = class(tabstractpointerdef)
  265. has_pointer_math : boolean;
  266. constructor create(def:tdef);virtual;
  267. { returns a pointerdef for def, reusing an existing one in case it
  268. exists in the current module }
  269. class function getreusable(def: tdef): tpointerdef; virtual;
  270. { same as above, but in case the def must never be freed after the
  271. current module has been compiled -- even if the def was not written
  272. to the ppu file (for defs in para locations, as we don't reset them
  273. so we don't have to recalculate them all the time) }
  274. class function getreusable_no_free(def: tdef): tpointerdef;
  275. function size:asizeint;override;
  276. function getcopy:tstoreddef;override;
  277. constructor ppuload(ppufile:tcompilerppufile);
  278. { do not override this routine in platform-specific subclasses,
  279. override ppuwrite_platform instead }
  280. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  281. function GetTypeName:string;override;
  282. {# returns the appropriate int type for pointer arithmetic with the given pointer type.
  283. When adding or subtracting a number to/from a pointer, this function returns the
  284. int type to which that number has to be converted, before the operation can be performed.
  285. Normally, this is sinttype, except on i8086, where it takes into account the
  286. special i8086 pointer types (near, far, huge). }
  287. function pointer_arithmetic_int_type:tdef;virtual;
  288. {# the unsigned version of pointer_arithmetic_int_type. Used with inc/dec. }
  289. function pointer_arithmetic_uint_type:tdef;virtual;
  290. {# returns the int type produced when subtracting two pointers of the given type.
  291. Normally, this is sinttype, except on i8086, where it takes into account the
  292. special i8086 pointer types (near, far, huge). }
  293. function pointer_subtraction_result_type:tdef;virtual;
  294. function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual;
  295. {# the integer index type used to convert the pointer to array (i.e. denotes int_type in: ptr[int_type]) }
  296. function converted_pointer_to_array_range_type:tdef;virtual;
  297. end;
  298. tpointerdefclass = class of tpointerdef;
  299. tprocdef = class;
  300. tabstractrecorddef= class(tstoreddef)
  301. private
  302. rttistring : string;
  303. {$ifdef DEBUG_NODE_XML}
  304. protected
  305. procedure XMLPrintDefData(var T: Text; Sym: TSym); override;
  306. {$endif DEBUG_NODE_XML}
  307. public
  308. objname,
  309. objrealname : PShortString;
  310. { for C++ classes: name of the library this class is imported from }
  311. { for Java classes/records: package name }
  312. import_lib : PShortString;
  313. symtable : TSymtable;
  314. cloneddef : tabstractrecorddef;
  315. cloneddefderef : tderef;
  316. objectoptions : tobjectoptions;
  317. rtti : trtti_directive;
  318. { for targets that initialise typed constants via explicit assignments
  319. instead of by generating an initialised data sectino }
  320. tcinitcode : tnode;
  321. constructor create(const n:string; dt:tdeftyp;doregister:boolean);
  322. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  323. procedure ppuwrite(ppufile:tcompilerppufile);override;
  324. destructor destroy; override;
  325. procedure buildderefimpl;override;
  326. procedure derefimpl;override;
  327. procedure check_forwards; virtual;
  328. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  329. function GetSymtable(t:tGetSymtable):TSymtable;override;
  330. function is_packed:boolean;
  331. function RttiName: string;
  332. { enumerator support }
  333. function search_enumerator_get: tprocdef; virtual;
  334. function search_enumerator_move: tprocdef; virtual;
  335. function search_enumerator_current: tsym; virtual;
  336. { JVM }
  337. function jvm_full_typename(with_package_name: boolean): string;
  338. { check if the symtable contains a float field }
  339. function contains_float_field : boolean;
  340. { check if the symtable contains a field that spans an aword boundary }
  341. function contains_cross_aword_field: boolean;
  342. { extended RTTI }
  343. procedure apply_rtti_directive(dir: trtti_directive); virtual;
  344. function is_visible_for_rtti(option: trtti_option; vis: tvisibility): boolean; inline;
  345. function rtti_visibilities_for_option(option: trtti_option): tvisibilities; inline;
  346. function has_extended_rtti: boolean; inline;
  347. end;
  348. pvariantrecdesc = ^tvariantrecdesc;
  349. tvariantrecbranch = record
  350. { we store only single values here and no ranges because tvariantrecdesc is only needed in iso mode
  351. which does not support range expressions in variant record definitions }
  352. values : array of Tconstexprint;
  353. nestedvariant : pvariantrecdesc;
  354. end;
  355. ppvariantrecdesc = ^pvariantrecdesc;
  356. tvariantrecdesc = record
  357. variantselector : tsym;
  358. variantselectorderef : tderef;
  359. branches : array of tvariantrecbranch;
  360. end;
  361. trecorddef = class(tabstractrecorddef)
  362. {$ifdef DEBUG_NODE_XML}
  363. protected
  364. function XMLPrintType: ansistring; override;
  365. {$endif DEBUG_NODE_XML}
  366. public
  367. variantrecdesc : pvariantrecdesc;
  368. isunion : boolean;
  369. constructor create(const n:string; p:TSymtable);virtual;
  370. constructor create_global_internal(const n: string; packrecords, recordalignmin: shortint); virtual;
  371. constructor create_internal(const n: string; packrecords, recordalignmin: shortint; where: tsymtable); virtual;
  372. function add_field_by_def(const optionalname: TIDString; def: tdef): tsym;
  373. procedure add_fields_from_deflist(fieldtypes: tfplist);
  374. constructor ppuload(ppufile:tcompilerppufile);
  375. destructor destroy;override;
  376. function getcopy : tstoreddef;override;
  377. { do not override this routine in platform-specific subclasses,
  378. override ppuwrite_platform instead }
  379. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  380. procedure buildderef;override;
  381. procedure deref;override;
  382. function size:asizeint;override;
  383. function alignment : shortint;override;
  384. function padalignment: shortint;
  385. function GetTypeName:string;override;
  386. { debug }
  387. function needs_inittable : boolean;override;
  388. function needs_separate_initrtti:boolean;override;
  389. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  390. end;
  391. trecorddefclass = class of trecorddef;
  392. tobjectdef = class;
  393. { TImplementedInterface }
  394. TImplementedInterface = class
  395. private
  396. fIOffset : longint;
  397. function GetIOffset: longint;
  398. public
  399. IntfDef : tobjectdef;
  400. IntfDefDeref : tderef;
  401. IType : tinterfaceentrytype;
  402. VtblImplIntf : TImplementedInterface;
  403. NameMappings : TFPHashList;
  404. ProcDefs : TFPObjectList;
  405. ImplementsGetter : tsym;
  406. ImplementsGetterDeref : tderef;
  407. ImplementsField : tsym;
  408. constructor create(aintf: tobjectdef);virtual;
  409. constructor create_deref(intfd,getterd:tderef);virtual;
  410. destructor destroy; override;
  411. function getcopy:TImplementedInterface;
  412. procedure buildderef;
  413. procedure deref;
  414. procedure AddMapping(const origname, newname: string);
  415. function GetMapping(const origname: string):string;
  416. procedure AddImplProc(pd:tprocdef);
  417. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  418. property IOffset: longint read GetIOffset write fIOffset;
  419. end;
  420. timplementedinterfaceclass = class of timplementedinterface;
  421. { tvmtentry }
  422. tvmtentry = record
  423. procdef : tprocdef;
  424. procdefderef : tderef;
  425. visibility : tvisibility;
  426. end;
  427. pvmtentry = ^tvmtentry;
  428. { tobjectdef }
  429. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  430. pmvcallstaticinfo = ^tmvcallstaticinfo;
  431. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  432. tobjectdef = class(tabstractrecorddef)
  433. private
  434. fcurrent_dispid: longint;
  435. {$ifdef DEBUG_NODE_XML}
  436. protected
  437. function XMLPrintType: ansistring; override;
  438. procedure XMLPrintDefInfo(var T: Text; Sym: TSym); override;
  439. procedure XMLPrintDefData(var T: Text; Sym: TSym); override;
  440. {$endif DEBUG_NODE_XML}
  441. public
  442. childof : tobjectdef;
  443. childofderef : tderef;
  444. { for Object Pascal helpers }
  445. extendeddef : tdef;
  446. extendeddefderef: tderef;
  447. helpertype : thelpertype;
  448. { for Objective-C: protocols and classes can have the same name there }
  449. objextname : pshortstring;
  450. { to be able to have a variable vmt position }
  451. { and no vmt field for objects without virtuals }
  452. vmtentries : TFPList;
  453. vmcallstaticinfo : pmvcallstaticinfo;
  454. vmt_field : tsym;
  455. vmt_fieldderef : tderef;
  456. iidguid : pguid;
  457. iidstr : pshortstring;
  458. { store implemented interfaces defs and name mappings }
  459. ImplementedInterfaces : TFPObjectList;
  460. { number of abstract methods (used by JVM target to determine whether
  461. or not the class should be marked as abstract: must be done if 1 or
  462. more abstract methods) }
  463. abstractcnt : longint;
  464. writing_class_record_dbginfo,
  465. { a class of this type has been created in this module }
  466. created_in_current_module,
  467. { a loadvmtnode for this class has been created in this
  468. module, so if a classrefdef variable of this or a parent
  469. class is used somewhere to instantiate a class, then this
  470. class may be instantiated
  471. }
  472. maybe_created_in_current_module,
  473. { a "class of" this particular class has been created in
  474. this module
  475. }
  476. classref_created_in_current_module : boolean;
  477. objecttype : tobjecttyp;
  478. { for interfaces that can be invoked using Invoke(),
  479. this is the definition of the hidden class that is generated by the compiler.
  480. we need this definition to reference it in the RTTI.
  481. Since interfaces can inherit, so can these hidden classes,
  482. so we need to write this to the ppu to be able to reference the parents.
  483. }
  484. hiddenclassdef : tobjectdef;
  485. hiddenclassdefref : tderef;
  486. constructor create(ot:tobjecttyp;const n:string;c:tobjectdef;doregister:boolean);virtual;
  487. constructor ppuload(ppufile:tcompilerppufile);
  488. destructor destroy;override;
  489. function getcopy : tstoreddef;override;
  490. { do not override this routine in platform-specific subclasses,
  491. override ppuwrite_platform instead }
  492. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  493. function GetTypeName:string;override;
  494. procedure buildderef;override;
  495. procedure deref;override;
  496. procedure derefimpl;override;
  497. procedure copyvmtentries(objdef:tobjectdef);
  498. function getparentdef:tdef;override;
  499. function size : asizeint;override;
  500. function alignment:shortint;override;
  501. function vmtmethodoffset(index:longint):longint;
  502. function members_need_inittable : boolean;
  503. { this should be called when this class implements an interface }
  504. procedure prepareguid;
  505. function is_publishable : tpublishproperty;override;
  506. function needs_inittable : boolean;override;
  507. function needs_separate_initrtti : boolean;override;
  508. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  509. function rtti_mangledname(rt:trttitype):TSymStr;override;
  510. function is_unique_objpasdef: boolean;
  511. function vmt_mangledname : TSymStr;
  512. function vmt_def: trecorddef;
  513. procedure check_forwards; override;
  514. procedure insertvmt;
  515. function vmt_offset: asizeint;
  516. procedure set_parent(c : tobjectdef);
  517. function find_destructor: tprocdef;
  518. function implements_any_interfaces: boolean;
  519. function register_implemented_interface(intfdef:tobjectdef;useguid:boolean):timplementedinterface;
  520. { dispinterface support }
  521. function get_next_dispid: longint;
  522. { enumerator support }
  523. function search_enumerator_get: tprocdef; override;
  524. function search_enumerator_move: tprocdef; override;
  525. function search_enumerator_current: tsym; override;
  526. { WPO }
  527. procedure register_created_object_type;override;
  528. procedure register_maybe_created_object_type;
  529. procedure register_created_classref_type;
  530. procedure register_vmt_call(index:longint);
  531. { ObjC }
  532. procedure finish_objc_data;
  533. function check_objc_types: boolean;
  534. { C++ }
  535. procedure finish_cpp_data;
  536. procedure apply_rtti_directive(dir: trtti_directive); override;
  537. end;
  538. tobjectdefclass = class of tobjectdef;
  539. tclassrefdef = class(tabstractpointerdef)
  540. constructor create(def:tdef);virtual;
  541. constructor ppuload(ppufile:tcompilerppufile);
  542. { do not override this routine in platform-specific subclasses,
  543. override ppuwrite_platform instead }
  544. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  545. function getcopy:tstoreddef;override;
  546. function GetTypeName:string;override;
  547. function is_publishable : tpublishproperty;override;
  548. function rtti_mangledname(rt:trttitype):TSymStr;override;
  549. procedure register_created_object_type;override;
  550. end;
  551. tclassrefdefclass = class of tclassrefdef;
  552. tarraydef = class(tstoreddef)
  553. lowrange,
  554. highrange : asizeint;
  555. rangedef : tdef;
  556. rangedefderef : tderef;
  557. arrayoptions : tarraydefoptions;
  558. symtable : TSymtable;
  559. protected
  560. _elementdef : tdef;
  561. _elementdefderef : tderef;
  562. procedure setelementdef(def:tdef);
  563. class function getreusable_intern(def: tdef; elems: asizeint; const options: tarraydefoptions): tarraydef;
  564. public
  565. function elesize : asizeint;
  566. function elepackedbitsize : asizeint;
  567. function elecount : asizeuint;
  568. constructor create_from_pointer(def: tpointerdef);virtual;
  569. constructor create(l, h: asizeint; def: tdef);virtual;
  570. constructor create_vector(l,h:asizeint; def:tdef);
  571. constructor create_openarray;virtual;
  572. class function getreusable(def: tdef; elems: asizeint): tarraydef;
  573. class function getreusable_vector(def: tdef; elems: asizeint): tarraydef;
  574. { same as above, but in case the def must never be freed after the
  575. current module has been compiled -- even if the def was not written
  576. to the ppu file (for defs in para locations, as we don't reset them
  577. so we don't have to recalculate them all the time) }
  578. class function getreusable_no_free(def: tdef; elems: asizeint): tarraydef;
  579. class function getreusable_no_free_vector(def: tdef; elems: asizeint): tarraydef;
  580. constructor ppuload(ppufile:tcompilerppufile);
  581. destructor destroy; override;
  582. function getcopy : tstoreddef;override;
  583. { do not override this routine in platform-specific subclasses,
  584. override ppuwrite_platform instead }
  585. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  586. function GetTypeName:string;override;
  587. function getmangledparaname : TSymStr;override;
  588. procedure buildderef;override;
  589. procedure deref;override;
  590. function size : asizeint;override;
  591. function alignment : shortint;override;
  592. { returns the label of the range check string }
  593. function needs_inittable : boolean;override;
  594. function needs_separate_initrtti : boolean;override;
  595. property elementdef : tdef read _elementdef write setelementdef;
  596. function is_publishable : tpublishproperty;override;
  597. function is_hwvector: boolean;
  598. end;
  599. tarraydefclass = class of tarraydef;
  600. torddef = class(tstoreddef)
  601. low,high : TConstExprInt;
  602. ordtype : tordtype;
  603. constructor create(t : tordtype;v,b : TConstExprInt; doregister: boolean);virtual;
  604. constructor ppuload(ppufile:tcompilerppufile);
  605. function getcopy : tstoreddef;override;
  606. { do not override this routine in platform-specific subclasses,
  607. override ppuwrite_platform instead }
  608. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  609. function is_publishable : tpublishproperty;override;
  610. function GetTypeName:string;override;
  611. function alignment:shortint;override;
  612. procedure setsize;
  613. function packedbitsize: asizeint; override;
  614. function getvardef : longint;override;
  615. end;
  616. torddefclass = class of torddef;
  617. tfloatdef = class(tstoreddef)
  618. floattype : tfloattype;
  619. constructor create(t: tfloattype; doregister: boolean);virtual;
  620. constructor ppuload(ppufile:tcompilerppufile);
  621. function getcopy : tstoreddef;override;
  622. { do not override this routine in platform-specific subclasses,
  623. override ppuwrite_platform instead }
  624. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  625. function GetTypeName:string;override;
  626. function is_publishable : tpublishproperty;override;
  627. function alignment:shortint;override;
  628. function structalignment: shortint;override;
  629. procedure setsize;
  630. function getvardef:longint;override;
  631. end;
  632. tfloatdefclass = class of tfloatdef;
  633. { tabstractprocdef }
  634. tprocnameoption = (pno_showhidden, pno_proctypeoption, pno_paranames,
  635. pno_ownername, pno_noclassmarker, pno_noleadingdollar,
  636. pno_mangledname, pno_noparams, pno_prettynames);
  637. tprocnameoptions = set of tprocnameoption;
  638. tproccopytyp = (pc_normal,
  639. {$ifdef i8086}
  640. { the address in a far format }
  641. pc_far_address,
  642. { the offset part of the far address }
  643. pc_offset,
  644. {$endif i8086}
  645. { creates a procvardef describing only the code pointer
  646. of a method/netsted function/... }
  647. pc_address_only,
  648. { everything except for hidden parameters }
  649. pc_normal_no_hidden,
  650. { everything except for the parameters (because they
  651. might be moved over to the copy) }
  652. pc_normal_no_paras,
  653. { always creates a top-level function, removes all
  654. special parameters (self, vmt, parentfp, ...) }
  655. pc_bareproc
  656. );
  657. tcacheableproccopytyp = pc_normal..pc_address_only;
  658. tabstractprocdef = class(tstoreddef)
  659. { saves a definition to the return type }
  660. returndef : tdef;
  661. returndefderef : tderef;
  662. parast : TSymtable;
  663. paras : tparalist;
  664. proctypeoption : tproctypeoption;
  665. proccalloption : tproccalloption;
  666. procoptions : tprocoptions;
  667. callerargareasize,
  668. calleeargareasize: pint;
  669. {$ifdef m68k}
  670. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  671. {$endif}
  672. funcretloc : array[callerside..calleeside] of TCGPara;
  673. has_paraloc_info : tcallercallee; { paraloc info is available }
  674. { number of user visible parameters }
  675. maxparacount,
  676. minparacount : byte;
  677. constructor create(dt:tdeftyp;level:byte;doregister:boolean);
  678. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  679. destructor destroy;override;
  680. procedure ppuwrite(ppufile:tcompilerppufile);override;
  681. procedure buildderef;override;
  682. procedure deref;override;
  683. procedure calcparas;
  684. function mangledprocparanames(oldlen : longint) : string;
  685. function typename_paras(pno: tprocnameoptions): ansistring;
  686. function is_methodpointer:boolean;virtual;
  687. function is_addressonly:boolean;virtual;
  688. function no_self_node:boolean;
  689. { get either a copy as a procdef or procvardef }
  690. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef; virtual;
  691. function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual;
  692. procedure check_mark_as_nested;
  693. procedure init_paraloc_info(side: tcallercallee);
  694. procedure done_paraloc_info(side: tcallercallee);
  695. function stack_tainting_parameter(side: tcallercallee): boolean;
  696. function is_pushleftright: boolean;virtual;
  697. function address_type:tdef;virtual;
  698. { address type, generated for ofs() }
  699. function ofs_address_type:tdef;virtual;
  700. procedure declared_far;virtual;
  701. procedure declared_near;virtual;
  702. function generate_safecall_wrapper: boolean; virtual;
  703. { returns true if the def is a generic param of the procdef }
  704. function is_generic_param(def:tdef): boolean;
  705. function wpo_may_create_instance(optionalmethodpointer: tnode): boolean;
  706. private
  707. procedure count_para(p:TObject;arg:pointer);
  708. procedure insert_para(p:TObject;arg:pointer);
  709. end;
  710. tprocvardef = class(tabstractprocdef)
  711. constructor create(level:byte;doregister:boolean);virtual;
  712. { returns a procvardef that represents the address of a proc(var)def }
  713. class function getreusableprocaddr(def: tabstractprocdef; copytyp: tcacheableproccopytyp): tprocvardef; virtual;
  714. { same as above, but in case the def must never be freed after the
  715. current module has been compiled -- even if the def was not written
  716. to the ppu file (for defs in para locations, as we don't reset them
  717. so we don't have to recalculate them all the time) }
  718. class function getreusableprocaddr_no_free(def: tabstractprocdef): tprocvardef;
  719. constructor ppuload(ppufile:tcompilerppufile);
  720. function getcopy : tstoreddef;override;
  721. { do not override this routine in platform-specific subclasses,
  722. override ppuwrite_platform instead }
  723. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  724. function GetSymtable(t:tGetSymtable):TSymtable;override;
  725. function size : asizeint;override;
  726. function GetTypeName:string;override;
  727. function is_publishable : tpublishproperty;override;
  728. function is_methodpointer:boolean;override;
  729. function is_addressonly:boolean;override;
  730. function getmangledparaname:TSymStr;override;
  731. function getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef; override;
  732. end;
  733. tprocvardefclass = class of tprocvardef;
  734. tmessageinf = record
  735. case integer of
  736. 0 : (str : pshortstring);
  737. 1 : (i : longint);
  738. end;
  739. tinlininginfo = record
  740. { node tree }
  741. code : tnode;
  742. flags : tprocinfoflags;
  743. end;
  744. pinlininginfo = ^tinlininginfo;
  745. tcapturedsyminfo = record
  746. sym : tsym;
  747. def : tdef;
  748. { the location where the symbol was first encountered }
  749. fileinfo : tfileposinfo;
  750. end;
  751. pcapturedsyminfo = ^tcapturedsyminfo;
  752. timplprocdefinfo = record
  753. resultname : pshortstring;
  754. parentfpstruct: tsym;
  755. parentfpstructptrtype: tdef;
  756. parentfpinitblock: tnode;
  757. procstarttai,
  758. procendtai : tai;
  759. skpara: pointer;
  760. personality: tprocdef;
  761. was_anonymous,
  762. has_capturer,
  763. forwarddef,
  764. interfacedef : boolean;
  765. hasforward : boolean;
  766. is_implemented : boolean;
  767. capturedsyms : tfplist;
  768. end;
  769. pimplprocdefinfo = ^timplprocdefinfo;
  770. { tprocdef }
  771. tprocdef = class(tabstractprocdef)
  772. protected
  773. {$ifdef symansistr}
  774. _mangledname : ansistring;
  775. {$else symansistr}
  776. _mangledname : pshortstring;
  777. {$endif}
  778. _parentfpsym : tsym;
  779. { information that is only required until the implementation of the
  780. procdef has been handled }
  781. implprocdefinfo : pimplprocdefinfo;
  782. function store_localst:boolean;
  783. function GetResultName: PShortString;
  784. procedure SetResultName(AValue: PShortString);
  785. function GetParentFPStruct: tsym;
  786. procedure SetParentFPStruct(AValue: tsym);
  787. function GetParentFPStructPtrType: tdef;
  788. procedure SetParentFPStructPtrType(AValue: tdef);
  789. function GetParentFPInitBlock: tnode;
  790. procedure SetParentFPInitBlock(AValue: tnode);
  791. function Getprocstarttai: tai;
  792. procedure Setprocstarttai(AValue: tai);
  793. function Getprocendtai: tai;
  794. procedure Setprocendtai(AValue: tai);
  795. function Getskpara: pointer;
  796. procedure Setskpara(AValue: pointer);
  797. function Getpersonality: tprocdef;
  798. procedure Setpersonality(AValue: tprocdef);
  799. function Getforwarddef: boolean;
  800. procedure Setforwarddef(AValue: boolean);
  801. function Getinterfacedef: boolean;
  802. procedure Setinterfacedef(AValue: boolean);virtual;
  803. function Gethasforward: boolean;
  804. procedure Sethasforward(AValue: boolean);
  805. function GetIsEmpty: boolean;
  806. procedure SetIsEmpty(AValue: boolean);
  807. function GetHasInliningInfo: boolean;
  808. procedure SetHasInliningInfo(AValue: boolean);
  809. function Getis_implemented: boolean;
  810. procedure Setis_implemented(AValue: boolean);
  811. function getwas_anonymous:boolean;
  812. procedure setwas_anonymous(avalue:boolean);
  813. function gethas_capturer:boolean;
  814. procedure sethas_capturer(avalue:boolean);
  815. function Getcapturedsyms:tfplist;
  816. function getparentfpsym: tsym;
  817. public
  818. messageinf : tmessageinf;
  819. dispid : longint;
  820. {$ifndef EXTDEBUG}
  821. { where is this function defined and what were the symbol
  822. flags, needed here because there
  823. is only one symbol for all overloaded functions
  824. EXTDEBUG has fileinfo in tdef (PFV) }
  825. fileinfo : tfileposinfo;
  826. {$endif}
  827. symoptions : tsymoptions;
  828. deprecatedmsg : pshortstring;
  829. { generic support }
  830. genericdecltokenbuf : tdynamicarray;
  831. { symbol owning this definition }
  832. procsym : tsym;
  833. procsymderef : tderef;
  834. { alias names }
  835. aliasnames : TCmdStrList;
  836. { symtables }
  837. localst : TSymtable;
  838. funcretsym : tsym;
  839. funcretsymderef : tderef;
  840. struct : tabstractrecorddef;
  841. structderef : tderef;
  842. implprocoptions: timplprocoptions;
  843. { import info }
  844. import_dll,
  845. import_name : pshortstring;
  846. { info for inlining the subroutine, if this pointer is nil,
  847. the procedure can't be inlined }
  848. inlininginfo : pinlininginfo;
  849. import_nr : word;
  850. extnumber : word;
  851. { set to a value different from tsk_none in case this procdef is for
  852. a routine that has to be internally generated by the compiler }
  853. synthetickind: tsynthetickind;
  854. visibility : tvisibility;
  855. {$ifndef DISABLE_FAST_OVERLOAD_PATCH}
  856. seenmarker : pointer; // used for filtering in tcandidate
  857. {$endif}
  858. {$ifdef symansistr}
  859. section: ansistring;
  860. {$else symansistr}
  861. section: pshortstring;
  862. {$endif}
  863. { only needed when actually compiling a unit, no need to save/load from ppu }
  864. invoke_helper : tprocdef;
  865. copied_from : tprocdef;
  866. constructor create(level:byte;doregister:boolean);virtual;
  867. constructor ppuload(ppufile:tcompilerppufile);
  868. destructor destroy;override;
  869. procedure freeimplprocdefinfo;
  870. { do not override this routine in platform-specific subclasses,
  871. override ppuwrite_platform instead }
  872. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  873. procedure buildderef;override;
  874. procedure buildderefimpl;override;
  875. procedure deref;override;
  876. procedure derefimpl;override;
  877. function GetSymtable(t:tGetSymtable):TSymtable;override;
  878. { warnings:
  879. * the symtablestack top has to be the symtable to which the copy
  880. should be added
  881. * getcopy does not create a finished/ready-to-use procdef; it
  882. needs to be finalised afterwards by calling
  883. symcreat.finish_copied_procdef() afterwards
  884. }
  885. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef; override;
  886. function getcopy: tstoreddef; override;
  887. function GetTypeName : string;override;
  888. function mangledname : TSymStr; virtual;
  889. procedure setmangledname(const s : TSymStr);
  890. function needsglobalasmsym: boolean;
  891. procedure setcompilerprocname;
  892. function fullprocname(showhidden:boolean):string;
  893. function customprocname(pno: tprocnameoptions):ansistring;
  894. function defaultmangledname: TSymStr;
  895. function cplusplusmangledname : TSymStr;
  896. function objcmangledname : TSymStr;
  897. function is_methodpointer:boolean;override;
  898. function is_addressonly:boolean;override;
  899. procedure make_external;
  900. procedure init_genericdecl;
  901. procedure reset_after_conv;
  902. function get_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean; virtual;
  903. function get_safecall_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean; virtual;
  904. procedure add_captured_sym(sym:tsym;def:tdef;const filepos:tfileposinfo);
  905. { returns whether the mangled name or any of its aliases is equal to
  906. s }
  907. function has_alias_name(const s: TSymStr):boolean;
  908. { aliases to fields only required when a function is implemented in
  909. the current unit }
  910. property resultname: PShortString read GetResultName write SetResultName;
  911. { temporary reference to structure containing copies of all local
  912. variables and parameters accessed by nested routines; reference to
  913. this structure is passed as "parent frame pointer" on targets that
  914. lack this concept (at least JVM and LLVM); no need to save to/
  915. restore from ppu, since nested routines are always in the same
  916. unit }
  917. property parentfpstruct: tsym read GetParentFPStruct write SetParentFPStruct;
  918. { pointer to parentfpstruct's type (not yet valid during parsing, so
  919. cannot be used for $parentfp parameter) (no need to save to ppu) }
  920. property parentfpstructptrtype: tdef read GetParentFPStructPtrType write SetParentFPStructPtrType;
  921. { code to copy the parameters accessed from nested routines into the
  922. parentfpstruct (no need to save to ppu) }
  923. property parentfpinitblock: tnode read GetParentFPInitBlock write SetParentFPInitBlock;
  924. { First/last assembler symbol/instruction in aasmoutput list.
  925. Note: initialised after compiling the code for the procdef, but
  926. not saved to/restored from ppu. Used when inserting debug info }
  927. property procstarttai: tai read Getprocstarttai write Setprocstarttai;
  928. property procendtai: tai read Getprocendtai write Setprocendtai;
  929. { optional parameter for the synthetic routine generation logic }
  930. property skpara: pointer read Getskpara write Setskpara;
  931. { ABI-conformant exception handling personality function }
  932. property personality: tprocdef read Getpersonality write Setpersonality;
  933. { true, if the procedure is only declared
  934. (forward procedure) }
  935. property forwarddef: boolean read Getforwarddef write Setforwarddef;
  936. { true if the procedure is declared in the interface }
  937. property interfacedef: boolean read Getinterfacedef write Setinterfacedef;
  938. { true if the procedure has a forward declaration }
  939. property hasforward: boolean read Gethasforward write Sethasforward;
  940. { true if the routine's body is empty }
  941. property isempty: boolean read GetIsEmpty write SetIsEmpty;
  942. { true if all information required to inline this routine is available }
  943. property has_inlininginfo: boolean read GetHasInliningInfo write SetHasInliningInfo;
  944. { returns the $parentfp parameter for nested routines }
  945. property parentfpsym: tsym read getparentfpsym;
  946. { true if the implementation part for this procdef has been handled }
  947. property is_implemented: boolean read Getis_implemented write Setis_implemented;
  948. { valid if the procdef captures any symbols from outer scopes }
  949. property capturedsyms:tfplist read Getcapturedsyms;
  950. { true if this procdef was originally an anonymous function }
  951. property was_anonymous:boolean read getwas_anonymous write setwas_anonymous;
  952. { true if the procdef has a capturer for anonymous functions }
  953. property has_capturer:boolean read gethas_capturer write sethas_capturer;
  954. end;
  955. tprocdefclass = class of tprocdef;
  956. { single linked list of overloaded procs }
  957. pprocdeflist = ^tprocdeflist;
  958. tprocdeflist = record
  959. def : tprocdef;
  960. defderef : tderef;
  961. next : pprocdeflist;
  962. end;
  963. tstringdef = class(tstoreddef)
  964. encoding : tstringencoding;
  965. stringtype : tstringtype;
  966. len : asizeint;
  967. constructor createshort(l: byte; doregister: boolean);virtual;
  968. constructor loadshort(ppufile:tcompilerppufile);
  969. constructor createlong(l: asizeint; doregister: boolean);virtual;
  970. constructor loadlong(ppufile:tcompilerppufile);
  971. constructor createansi(aencoding: tstringencoding; doregister: boolean);virtual;
  972. constructor loadansi(ppufile:tcompilerppufile);
  973. constructor createwide(doregister: boolean);virtual;
  974. constructor loadwide(ppufile:tcompilerppufile);
  975. constructor createunicode(doregister: boolean);virtual;
  976. constructor loadunicode(ppufile:tcompilerppufile);virtual;
  977. function getcopy : tstoreddef;override;
  978. function stringtypname:string;
  979. { do not override this routine in platform-specific subclasses,
  980. override ppuwrite_platform instead }
  981. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  982. function GetTypeName:string;override;
  983. function getmangledparaname:TSymStr;override;
  984. function is_publishable : tpublishproperty;override;
  985. function size:asizeint;override;
  986. function alignment : shortint;override;
  987. function needs_inittable : boolean;override;
  988. function getvardef:longint;override;
  989. { returns the default char type def for the string }
  990. function get_default_char_type: tdef;
  991. { returns the default string type }
  992. function get_default_string_type: tdef;
  993. end;
  994. tstringdefclass = class of tstringdef;
  995. tenumdef = class(tstoreddef)
  996. minval,
  997. maxval : asizeint;
  998. basedef : tenumdef;
  999. basedefderef : tderef;
  1000. symtable : TSymtable;
  1001. has_jumps : boolean;
  1002. constructor create;virtual;
  1003. constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);virtual;
  1004. constructor ppuload(ppufile:tcompilerppufile);
  1005. destructor destroy;override;
  1006. function getcopy : tstoreddef;override;
  1007. { do not override this routine in platform-specific subclasses,
  1008. override ppuwrite_platform instead }
  1009. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  1010. procedure buildderef;override;
  1011. procedure deref;override;
  1012. function GetTypeName:string;override;
  1013. function is_publishable : tpublishproperty;override;
  1014. procedure calcsavesize(packenum: shortint);
  1015. function packedbitsize: asizeint; override;
  1016. procedure setmax(_max:asizeint);
  1017. procedure setmin(_min:asizeint);
  1018. function min:asizeint;
  1019. function max:asizeint;
  1020. function getfirstsym:tsym;
  1021. function int2enumsym(l: asizeint): tsym;
  1022. { returns basedef if assigned, otherwise self }
  1023. function getbasedef: tenumdef;
  1024. end;
  1025. tenumdefclass = class of tenumdef;
  1026. tsetdef = class(tstoreddef)
  1027. elementdef : tdef;
  1028. elementdefderef : tderef;
  1029. { setbase is the value of the lowest value being representable by the set, this could
  1030. be lower then the lowest value being a valid value from the declaration: a set [3..4] might
  1031. have a setbase of 0 for code generation/alignment reasons }
  1032. setbase,
  1033. { setlow is the lowest value valid according to the declaration of a set, i.e. for a set [3..4] it is really 3 }
  1034. setlow,
  1035. setmax : asizeint;
  1036. constructor create(def: tdef; low, high: asizeint; doregister: boolean);virtual;
  1037. constructor ppuload(ppufile:tcompilerppufile);
  1038. function getcopy : tstoreddef;override;
  1039. { do not override this routine in platform-specific subclasses,
  1040. override ppuwrite_platform instead }
  1041. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  1042. procedure buildderef;override;
  1043. procedure deref;override;
  1044. function GetTypeName:string;override;
  1045. function is_publishable : tpublishproperty;override;
  1046. function alignment: shortint; override;
  1047. end;
  1048. tsetdefclass = class of tsetdef;
  1049. tgenericdummyentry = class
  1050. dummysym : tsym;
  1051. resolvedsym : tsym;
  1052. end;
  1053. tdefawaresymtablestack = class(TSymtablestack)
  1054. private
  1055. procedure add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  1056. procedure remove_helpers_and_generics(st:tsymtable);inline;
  1057. procedure remove_helpers(st:tsymtable);
  1058. procedure remove_generics(st:tsymtable);
  1059. procedure pushcommon(st:tsymtable);inline;
  1060. public
  1061. procedure push(st: TSymtable); override;
  1062. procedure pushafter(st,afterst:TSymtable); override;
  1063. procedure pop(st: TSymtable); override;
  1064. end;
  1065. var
  1066. current_structdef: tabstractrecorddef; { used for private functions check !! }
  1067. current_genericdef: tstoreddef; { used to reject declaration of generic class inside generic class }
  1068. current_specializedef: tstoreddef; { used to implement usage of generic class in itself }
  1069. cfiledef: tfiledefclass;
  1070. cvariantdef: tvariantdefclass;
  1071. cformaldef: tformaldefclass;
  1072. cforwarddef: tforwarddefclass;
  1073. cundefineddef: tundefineddefclass;
  1074. cerrordef: terrordefclass;
  1075. cpointerdef: tpointerdefclass;
  1076. crecorddef: trecorddefclass;
  1077. cimplementedinterface: timplementedinterfaceclass;
  1078. cobjectdef: tobjectdefclass;
  1079. cclassrefdef: tclassrefdefclass;
  1080. carraydef: tarraydefclass;
  1081. corddef: torddefclass;
  1082. cfloatdef: tfloatdefclass;
  1083. cprocvardef: tprocvardefclass;
  1084. cprocdef: tprocdefclass;
  1085. cstringdef: tstringdefclass;
  1086. cenumdef: tenumdefclass;
  1087. csetdef: tsetdefclass;
  1088. { default types }
  1089. generrordef, { error in definition }
  1090. voidpointertype, { pointer for Void-pointeddef }
  1091. charpointertype, { pointer for Char-pointeddef }
  1092. widecharpointertype, { pointer for WideChar-pointeddef }
  1093. voidcodepointertype, { pointer to code; corresponds to System.CodePointer }
  1094. voidstackpointertype, { the pointer type used for accessing parameters and local vars on the stack }
  1095. parentfpvoidpointertype, { void pointer with the size of the hidden parentfp parameter, passed to nested functions }
  1096. {$ifdef x86}
  1097. voidnearpointertype,
  1098. voidnearcspointertype,
  1099. voidneardspointertype,
  1100. voidnearsspointertype,
  1101. voidnearespointertype,
  1102. voidnearfspointertype,
  1103. voidneargspointertype,
  1104. {$ifdef i8086}
  1105. voidfarpointertype,
  1106. voidhugepointertype,
  1107. charnearpointertype,
  1108. charfarpointertype,
  1109. charhugepointertype,
  1110. bytefarpointertype, { used for Mem[] }
  1111. wordfarpointertype, { used for MemW[] }
  1112. longintfarpointertype, { used for MemL[] }
  1113. {$endif i8086}
  1114. {$endif x86}
  1115. {$ifdef wasm}
  1116. wasmvoidexternreftype,
  1117. {$endif wasm}
  1118. cundefinedtype,
  1119. cformaltype, { unique formal definition }
  1120. ctypedformaltype, { unique typed formal definition }
  1121. voidtype, { Void (procedure) }
  1122. cansichartype, { Char }
  1123. cwidechartype, { WideChar }
  1124. cchartype, { either cansichartype or cwidechartype. Do not free }
  1125. pasbool1type, { boolean type }
  1126. pasbool8type,
  1127. pasbool16type,
  1128. pasbool32type,
  1129. pasbool64type,
  1130. bool8type,
  1131. bool16type,
  1132. bool32type,
  1133. bool64type, { implement me }
  1134. {$ifdef llvm}
  1135. llvmbool1type, { LLVM i1 type }
  1136. {$endif llvm}
  1137. u8inttype, { 8-Bit unsigned integer }
  1138. s8inttype, { 8-Bit signed integer }
  1139. u16inttype, { 16-Bit unsigned integer }
  1140. s16inttype, { 16-Bit signed integer }
  1141. u24inttype, { 24-Bit unsigned integer }
  1142. s24inttype, { 24-Bit signed integer }
  1143. u32inttype, { 32-Bit unsigned integer }
  1144. s32inttype, { 32-Bit signed integer }
  1145. u40inttype, { 40-Bit unsigned integer }
  1146. s40inttype, { 40-Bit signed integer }
  1147. u48inttype, { 48-Bit unsigned integer }
  1148. s48inttype, { 48-Bit signed integer }
  1149. u56inttype, { 56-Bit unsigned integer }
  1150. s56inttype, { 56-Bit signed integer }
  1151. u64inttype, { 64-bit unsigned integer }
  1152. s64inttype, { 64-bit signed integer }
  1153. u128inttype, { 128-bit unsigned integer }
  1154. s128inttype, { 128-bit signed integer }
  1155. s32floattype, { 32 bit floating point number }
  1156. s64floattype, { 64 bit floating point number }
  1157. s80floattype, { 80 bit floating point number }
  1158. sc80floattype, { 80 bit floating point number but stored like in C }
  1159. s64currencytype, { pointer to a currency type }
  1160. cshortstringtype, { pointer to type of short string const }
  1161. clongstringtype, { pointer to type of long string const }
  1162. cansistringtype, { pointer to type of ansi string const }
  1163. cwidestringtype, { pointer to type of wide string const }
  1164. cunicodestringtype,
  1165. openshortstringtype, { pointer to type of an open shortstring,
  1166. needed for readln() }
  1167. openchararraytype, { pointer to type of an open array of char,
  1168. needed for readln() }
  1169. cfiletype, { get the same definition for all file }
  1170. { used for stabs }
  1171. methodpointertype, { typecasting of methodpointers to extract self }
  1172. nestedprocpointertype, { typecasting of nestedprocpointers to extract parentfp }
  1173. hresultdef,
  1174. typekindtype, { def of TTypeKind for correct handling of GetTypeKind parameters }
  1175. { we use only one variant def for every variant class }
  1176. cvarianttype,
  1177. colevarianttype,
  1178. { default integer type, normally s32inttype on 32 bit systems and s64bittype on 64 bit systems }
  1179. sinttype,
  1180. uinttype,
  1181. { integer types corresponding to OS_SINT/OS_INT }
  1182. ossinttype,
  1183. osuinttype,
  1184. { integer types corresponding to the ALU size, sizeof(aint) and the ALUSInt/ALUUInt types in the system unit }
  1185. alusinttype,
  1186. aluuinttype,
  1187. { integer types corresponding to SizeInt and SizeUInt for the target platform }
  1188. sizeuinttype,
  1189. sizesinttype,
  1190. { unsigned and signed ord type with the same size as a pointer }
  1191. ptruinttype,
  1192. ptrsinttype,
  1193. { unsigned and signed ord type with the same size as a codepointer }
  1194. codeptruinttype,
  1195. codeptrsinttype,
  1196. { several types to simulate more or less C++ objects for GDB }
  1197. vmttype,
  1198. vmtarraytype,
  1199. { type of classrefs, used for stabs }
  1200. pvmttype,
  1201. { return type of the setjmp function }
  1202. exceptionreasontype : tdef;
  1203. { pointer to the anchestor of all classes }
  1204. class_tobject : tobjectdef;
  1205. { pointer to the base type for custom attributes }
  1206. class_tcustomattribute : tobjectdef;
  1207. { pointer to the ancestor of all COM interfaces }
  1208. interface_iunknown : tobjectdef;
  1209. { pointer to the ancestor of all dispinterfaces }
  1210. interface_idispatch : tobjectdef;
  1211. { pointer to the TGUID type
  1212. of all interfaces }
  1213. rec_tguid : trecorddef;
  1214. { jump buffer type, used by setjmp }
  1215. rec_jmp_buf : trecorddef;
  1216. { system.texceptaddr type, used by fpc_pushexceptaddr }
  1217. rec_exceptaddr: trecorddef;
  1218. { Objective-C base types }
  1219. objc_metaclasstype,
  1220. objc_superclasstype,
  1221. objc_idtype,
  1222. objc_seltype : tpointerdef;
  1223. objc_objecttype : trecorddef;
  1224. { base type of @protocol(protocolname) Objective-C statements }
  1225. objc_protocoltype : tobjectdef;
  1226. { helper types for for-in "fast enumeration" support in Objective-C 2.0 }
  1227. objc_fastenumeration : tobjectdef;
  1228. objc_fastenumerationstate : trecorddef;
  1229. {$ifdef llvm}
  1230. { llvm types }
  1231. { a unique def to identify any kind of metadata }
  1232. llvm_metadatatype : tdef;
  1233. {$endif llvm}
  1234. { Java base types }
  1235. { java.lang.Object }
  1236. java_jlobject : tobjectdef;
  1237. { java.lang.Throwable }
  1238. java_jlthrowable : tobjectdef;
  1239. { FPC base type for records }
  1240. java_fpcbaserecordtype : tobjectdef;
  1241. { java.lang.String }
  1242. java_jlstring : tobjectdef;
  1243. { java.lang.Enum }
  1244. java_jlenum : tobjectdef;
  1245. { java.util.EnumSet }
  1246. java_juenumset : tobjectdef;
  1247. { java.util.BitSet }
  1248. java_jubitset : tobjectdef;
  1249. { FPC java implementation of ansistrings }
  1250. java_ansistring : tobjectdef;
  1251. { FPC java implementation of shortstrings }
  1252. java_shortstring : tobjectdef;
  1253. { FPC java procvar base class }
  1254. java_procvarbase : tobjectdef;
  1255. { x86 vector types }
  1256. x86_m64type,
  1257. x86_m128type,
  1258. x86_m128dtype,
  1259. x86_m128itype,
  1260. x86_m256type,
  1261. x86_m256dtype,
  1262. x86_m256itype : tdef;
  1263. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1264. function make_dllmangledname(const dllname,importname:TSymStr;
  1265. import_nr : word; pco : tproccalloption):TSymStr;
  1266. { should be in the types unit, but the types unit uses the node stuff :( }
  1267. function is_interfacecom(def: tdef): boolean;
  1268. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  1269. function is_any_interface_kind(def: tdef): boolean;
  1270. function is_interfacecorba(def: tdef): boolean;
  1271. function is_interface(def: tdef): boolean;
  1272. function is_dispinterface(def: tdef): boolean;
  1273. function is_object(def: tdef): boolean;
  1274. function is_class(def: tdef): boolean;
  1275. function is_cppclass(def: tdef): boolean;
  1276. function is_objectpascal_helper(def: tdef): boolean;
  1277. function is_objcclass(def: tdef): boolean;
  1278. function is_objcclassref(def: tdef): boolean;
  1279. function is_objcprotocol(def: tdef): boolean;
  1280. function is_objccategory(def: tdef): boolean;
  1281. function is_objc_class_or_protocol(def: tdef): boolean;
  1282. function is_objc_protocol_or_category(def: tdef): boolean;
  1283. function is_classhelper(def: tdef): boolean;
  1284. function is_class_or_interface(def: tdef): boolean;
  1285. function is_class_or_interface_or_objc(def: tdef): boolean;
  1286. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  1287. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  1288. function is_class_or_interface_or_object(def: tdef): boolean;
  1289. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  1290. function is_implicit_pointer_object_type(def: tdef): boolean;
  1291. { returns true, if def is a type which is an implicit pointer to an array (dyn. array or dyn. string) }
  1292. function is_implicit_array_pointer(def: tdef): boolean;
  1293. function is_class_or_object(def: tdef): boolean;
  1294. function is_record(def: tdef): boolean;
  1295. function is_javaclass(def: tdef): boolean;
  1296. function is_javaclassref(def: tdef): boolean;
  1297. function is_javainterface(def: tdef): boolean;
  1298. function is_java_class_or_interface(def: tdef): boolean;
  1299. procedure loadobjctypes;
  1300. procedure maybeloadcocoatypes;
  1301. function use_vectorfpu(def : tdef) : boolean;
  1302. function getansistringcodepage:tstringencoding; inline;
  1303. function getansistringdef:tstringdef;
  1304. function getparaencoding(def:tdef):tstringencoding; inline;
  1305. function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
  1306. function get_recorddef(prefix:tinternaltypeprefix;const fields:array of tdef; packrecords:shortint): trecorddef;
  1307. { get a table def of the form
  1308. record
  1309. count: countdef;
  1310. elements: array[0..count-1] of elementdef
  1311. end;
  1312. Returns both the outer record and the inner arraydef
  1313. }
  1314. procedure get_tabledef(prefix:tinternaltypeprefix;countdef,elementdef:tdef;count:longint;packrecords:shortint;out recdef:trecorddef;out arrdef:tarraydef);
  1315. function fileinfo_of_typesym_in_def(def:tdef;sym:tsym;out filepos:tfileposinfo):boolean;
  1316. procedure reset_all_default_types; {housekeeping for Textmode IDE sanity}
  1317. implementation
  1318. uses
  1319. SysUtils,
  1320. cutils,
  1321. { global }
  1322. verbose,
  1323. { target }
  1324. systems,paramgr,
  1325. { symtable }
  1326. symsym,symtable,defutil,objcdef,
  1327. { parser }
  1328. pgenutil,
  1329. { module }
  1330. fmodule,ppu,
  1331. { other }
  1332. aasmbase,
  1333. gendef,
  1334. fpchash,
  1335. entfile
  1336. ;
  1337. {****************************************************************************
  1338. Helpers
  1339. ****************************************************************************}
  1340. function fileinfo_of_typesym_in_def(def:tdef;sym:tsym;out filepos:tfileposinfo):boolean;
  1341. var
  1342. gst : tgetsymtable;
  1343. st : tsymtable;
  1344. i : longint;
  1345. srsym : tsym;
  1346. begin
  1347. result:=false;
  1348. if sym.typ<>typesym then
  1349. exit;
  1350. for gst:=low(tgetsymtable) to high(tgetsymtable) do
  1351. begin
  1352. st:=def.getsymtable(gst);
  1353. if not assigned(st) then
  1354. continue;
  1355. for i:=0 to st.symlist.count-1 do
  1356. begin
  1357. srsym:=tsym(st.symlist[i]);
  1358. case srsym.typ of
  1359. fieldvarsym,
  1360. paravarsym:
  1361. if tabstractvarsym(srsym).vardef.typesym=sym then
  1362. begin
  1363. filepos:=srsym.fileinfo;
  1364. result:=true;
  1365. break;
  1366. end;
  1367. typesym:
  1368. begin
  1369. result:=fileinfo_of_typesym_in_def(ttypesym(srsym).typedef,sym,filepos);
  1370. if result then
  1371. break;
  1372. end
  1373. else
  1374. ;
  1375. end;
  1376. end;
  1377. if result then
  1378. break;
  1379. end;
  1380. { for this we would need the position of the result declaration :/ }
  1381. {if not result and
  1382. (def.typ in [procdef,procvardef]) and
  1383. assigned(tabstractprocdef(def).returndef) and
  1384. (tabstractprocdef(def).returndef.typesym=sym) then
  1385. begin
  1386. result:=true;
  1387. end;}
  1388. end;
  1389. function getansistringcodepage:tstringencoding; inline;
  1390. begin
  1391. if ([cs_explicit_codepage,cs_system_codepage]*current_settings.moduleswitches)<>[] then
  1392. result:=current_settings.sourcecodepage
  1393. else
  1394. result:=0;
  1395. end;
  1396. function getansistringdef:tstringdef;
  1397. var
  1398. symtable:tsymtable;
  1399. oldstack : tsymtablestack;
  1400. begin
  1401. { if a codepage is explicitly defined in this mudule we need to return
  1402. a replacement for ansistring def }
  1403. if ([cs_explicit_codepage,cs_system_codepage]*current_settings.moduleswitches)<>[] then
  1404. begin
  1405. if not assigned(current_module) then
  1406. internalerror(2011101301);
  1407. { codepage can be redeclared only once per unit so we don't need a list of
  1408. redefined ansistring but only one pointer }
  1409. if not assigned(current_module.ansistrdef) then
  1410. begin
  1411. { if we did not create it yet we need to do this now }
  1412. if current_module.in_interface then
  1413. symtable:=current_module.globalsymtable
  1414. else
  1415. symtable:=current_module.localsymtable;
  1416. { create a temporary stack as it's not good (TM) to mess around
  1417. with the order if the unit contains generics or helpers; don't
  1418. use a def aware symtablestack though }
  1419. oldstack:=symtablestack;
  1420. symtablestack:=tsymtablestack.create;
  1421. symtablestack.push(symtable);
  1422. current_module.ansistrdef:=cstringdef.createansi(current_settings.sourcecodepage,true);
  1423. symtablestack.pop(symtable);
  1424. symtablestack.free;
  1425. symtablestack:=oldstack;
  1426. end;
  1427. result:=tstringdef(current_module.ansistrdef);
  1428. end
  1429. else
  1430. result:=tstringdef(cansistringtype);
  1431. end;
  1432. function getparaencoding(def:tdef):tstringencoding; inline;
  1433. begin
  1434. { don't pass CP_NONE encoding to internal functions
  1435. they expect 0 encoding instead
  1436. exception: result of string concatenation, because if you pass the
  1437. result of a string concatenation to a rawbytestring, the result of
  1438. that concatenation shouldn't be converted to defaultsystemcodepage
  1439. if all strings have the same type }
  1440. result:=tstringdef(def).encoding;
  1441. if result=globals.CP_NONE then
  1442. result:=0
  1443. end;
  1444. function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
  1445. var
  1446. typ: ttypesym;
  1447. name: string;
  1448. begin
  1449. name:=internaltypeprefixName[itp_threadvar_record]+def.unique_id_str;
  1450. typ:=try_search_current_module_type(name);
  1451. if assigned(typ) then
  1452. begin
  1453. result:=trecorddef(ttypesym(typ).typedef);
  1454. index_field:=tsym(result.symtable.symlist[0]);
  1455. non_mt_data_field:=tsym(result.symtable.symlist[1]);
  1456. exit;
  1457. end;
  1458. { set recordalinmin to sizeof(pint), so the second field gets put at
  1459. offset = sizeof(pint) as expected }
  1460. result:=crecorddef.create_global_internal(
  1461. name,sizeof(pint),sizeof(pint));
  1462. {$ifdef cpu16bitaddr}
  1463. index_field:=result.add_field_by_def('',u16inttype);
  1464. {$else cpu16bitaddr}
  1465. index_field:=result.add_field_by_def('',u32inttype);
  1466. {$endif cpu16bitaddr}
  1467. non_mt_data_field:=result.add_field_by_def('',def);
  1468. { no need to add alignment padding, we won't create arrays of these }
  1469. end;
  1470. function get_recorddef(prefix:tinternaltypeprefix; const fields:array of tdef; packrecords:shortint): trecorddef;
  1471. var
  1472. fieldlist: tfplist;
  1473. srsym: tsym;
  1474. srsymtable: tsymtable;
  1475. i: longint;
  1476. name : TIDString;
  1477. begin
  1478. name:=copy(internaltypeprefixName[prefix],2,length(internaltypeprefixName[prefix]));
  1479. if searchsym_type(name,srsym,srsymtable) then
  1480. begin
  1481. result:=trecorddef(ttypesym(srsym).typedef);
  1482. exit
  1483. end;
  1484. { also always search in the current module (symtables are popped for
  1485. RTTI related code already) }
  1486. if searchsym_in_module(pointer(current_module),name,srsym,srsymtable) then
  1487. begin
  1488. result:=trecorddef(ttypesym(srsym).typedef);
  1489. exit;
  1490. end;
  1491. fieldlist:=tfplist.create;
  1492. for i:=low(fields) to high(fields) do
  1493. fieldlist.add(fields[i]);
  1494. result:=crecorddef.create_global_internal(internaltypeprefixName[prefix],packrecords,
  1495. targetinfos[target_info.system]^.alignment.recordalignmin);
  1496. result.add_fields_from_deflist(fieldlist);
  1497. fieldlist.free;
  1498. end;
  1499. procedure get_tabledef(prefix:tinternaltypeprefix;countdef,elementdef:tdef;count:longint;packrecords:shortint;out recdef:trecorddef;out arrdef:tarraydef);
  1500. var
  1501. fields: tfplist;
  1502. name: TIDString;
  1503. srsym: tsym;
  1504. fieldvarsym: tfieldvarsym;
  1505. srsymtable: tsymtable;
  1506. begin
  1507. { already created a message string table with this number of elements
  1508. in this unit -> reuse the def }
  1509. name:=internaltypeprefixName[prefix]+tostr(count);
  1510. if searchsym_type(copy(name,2,length(name)),srsym,srsymtable) then
  1511. begin
  1512. recdef:=trecorddef(ttypesym(srsym).typedef);
  1513. fieldvarsym:=trecordsymtable(recdef.symtable).findfieldbyoffset(countdef.size);
  1514. if fieldvarsym<>nil then
  1515. arrdef:=tarraydef(fieldvarsym.vardef)
  1516. else
  1517. arrdef:=nil;
  1518. exit
  1519. end;
  1520. { also always search in the current module (symtables are popped for
  1521. RTTI related code already) }
  1522. if searchsym_in_module(pointer(current_module),copy(name,2,length(name)),srsym,srsymtable) then
  1523. begin
  1524. recdef:=trecorddef(ttypesym(srsym).typedef);
  1525. fieldvarsym:=trecordsymtable(recdef.symtable).findfieldbyoffset(countdef.size);
  1526. if fieldvarsym<>nil then
  1527. arrdef:=tarraydef(fieldvarsym.vardef)
  1528. else
  1529. arrdef:=nil;
  1530. exit;
  1531. end;
  1532. recdef:=crecorddef.create_global_internal(name,packrecords,
  1533. targetinfos[target_info.system]^.alignment.recordalignmin);
  1534. fields:=tfplist.create;
  1535. fields.add(countdef);
  1536. if count>0 then
  1537. begin
  1538. arrdef:=carraydef.create(0,count-1,sizeuinttype);
  1539. arrdef.elementdef:=elementdef;
  1540. fields.add(arrdef);
  1541. end
  1542. else
  1543. arrdef:=nil;
  1544. recdef.add_fields_from_deflist(fields);
  1545. fields.free;
  1546. end;
  1547. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1548. var
  1549. s,t,
  1550. prefix : TSymStr;
  1551. hash : qword;
  1552. begin
  1553. prefix:='';
  1554. if not assigned(st) then
  1555. internalerror(200204212);
  1556. repeat
  1557. { sub procedures }
  1558. while (st.symtabletype in [localsymtable,parasymtable]) do
  1559. begin
  1560. if st.defowner.typ<>procdef then
  1561. internalerror(200204173);
  1562. { Add the full mangledname of the routine to prevent
  1563. conflicts with two overloads both having a local entity
  1564. -- routine (tb0314), class, interface -- with the same name }
  1565. s:=tprocdef(st.defowner).procsym.name;
  1566. s:=s+tprocdef(st.defowner).mangledprocparanames(Length(s));
  1567. if prefix<>'' then
  1568. begin
  1569. if length(prefix)>(maxidlen-length(s)-1) then
  1570. begin
  1571. hash:=InitFnv64;
  1572. hash:=UpdateFnv64(hash,prefix[1],length(prefix));
  1573. prefix:='$H'+Base64Mangle(hash);
  1574. end;
  1575. prefix:=s+'_'+prefix
  1576. end
  1577. else
  1578. prefix:=s;
  1579. st:=st.defowner.owner;
  1580. end;
  1581. { object/classes symtable, nested type definitions in classes require the while loop }
  1582. while st.symtabletype in [ObjectSymtable,recordsymtable] do
  1583. begin
  1584. if not (st.defowner.typ in [objectdef,recorddef]) then
  1585. internalerror(200204174);
  1586. if length(prefix)>(maxidlen-length(tabstractrecorddef(st.defowner).objname^)-3) then
  1587. begin
  1588. hash:=InitFnv64;
  1589. hash:=UpdateFnv64(hash,prefix[1],length(prefix));
  1590. prefix:='$H'+Base64Mangle(hash);
  1591. end;
  1592. prefix:=tabstractrecorddef(st.defowner).objname^+'_$_'+prefix;
  1593. st:=st.defowner.owner;
  1594. end;
  1595. { local classes & interfaces are possible (because of closures)
  1596. or parasymtable for this case:
  1597. class function Trace<TResult>(const Func: TFunc<TLogToken, TResult>): TResult;
  1598. }
  1599. if not (st.symtabletype in [localsymtable,parasymtable]) then
  1600. break;
  1601. prefix:='$'+prefix;
  1602. until false;
  1603. { symtable must now be static or global }
  1604. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  1605. internalerror(200204175);
  1606. { The mangled name is made out of at most 4 parts:
  1607. 1) Optional typeprefix given as first parameter
  1608. with '_$' appended if not empty
  1609. 2) Unit name or 'P$'+program name (never empty)
  1610. 3) optional prefix variable that contains a unique
  1611. name for the local symbol table (prepended with '$_$'
  1612. if not empty)
  1613. 4) suffix as given as third parameter,
  1614. also optional (i.e. can be empty)
  1615. prepended by '_$$_' if not empty }
  1616. result:='';
  1617. if typeprefix<>'' then
  1618. result:=result+typeprefix+'_$';
  1619. { Add P$ for program, which can have the same name as
  1620. a unit }
  1621. if (TSymtable(main_module.localsymtable)=st) and
  1622. (not main_module.is_unit) then
  1623. result:=result+'P$'+st.name^
  1624. else
  1625. result:=result+st.name^;
  1626. if prefix<>'' then
  1627. result:=result+'$_$'+prefix;
  1628. if suffix<>'' then
  1629. result:=result+'_$$_'+suffix;
  1630. if length(result)>(maxidlen-1) then
  1631. begin
  1632. hash:=InitFnv64;
  1633. hash:=UpdateFnv64(hash,result[1],length(result));
  1634. result:=copy(result,1,maxidlen-(high(Base64OfUint64String)-low(Base64OfUint64String)+1)-2)+'$H'+Base64Mangle(hash);
  1635. end;
  1636. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  1637. { Further, the Mac OS X 10.5 linker does not consider symbols which do not }
  1638. { start with '_' as regular symbols (it does not generate N_GSYM entries }
  1639. { those in the debug map, leading to troubles with dsymutil). So always }
  1640. { add an underscore on darwin. }
  1641. if (target_info.system in systems_darwin) then
  1642. result := '_' + result;
  1643. end;
  1644. function make_dllmangledname(const dllname,importname:TSymStr;import_nr : word; pco : tproccalloption):TSymStr;
  1645. var
  1646. crc : cardinal;
  1647. i : longint;
  1648. use_crc : boolean;
  1649. dllprefix : TSymStr;
  1650. begin
  1651. if (target_info.system in (systems_all_windows + systems_nativent +
  1652. [system_i386_emx, system_i386_os2]))
  1653. and (dllname <> '') then
  1654. begin
  1655. dllprefix:=lower(ExtractFileName(dllname));
  1656. { Remove .dll suffix if present }
  1657. if copy(dllprefix,length(dllprefix)-3,length(dllprefix))='.dll' then
  1658. dllprefix:=copy(dllprefix,1,length(dllprefix)-4);
  1659. use_crc:=false;
  1660. for i:=1 to length(dllprefix) do
  1661. if not (dllprefix[i] in ['a'..'z','A'..'Z','_','0'..'9']) then
  1662. begin
  1663. use_crc:=true;
  1664. break;
  1665. end;
  1666. if use_crc then
  1667. begin
  1668. crc:=0;
  1669. crc:=UpdateCrc32(crc,dllprefix[1],length(dllprefix));
  1670. dllprefix:='_$dll$crc$'+hexstr(crc,8)+'$';
  1671. end
  1672. else
  1673. dllprefix:='_$dll$'+dllprefix+'$';
  1674. if importname<>'' then
  1675. result:=dllprefix+importname
  1676. else
  1677. result:=dllprefix+'_index_'+tostr(import_nr);
  1678. { Replace ? and @ in import name, since GNU AS does not allow these characters in symbol names. }
  1679. { This allows to import VC++ mangled names from DLLs. }
  1680. { Do not perform replacement, if external symbol is not imported from DLL. }
  1681. if (dllname<>'') then
  1682. begin
  1683. Replace(result,'?','__q$$');
  1684. {$ifdef arm}
  1685. { @ symbol is not allowed in ARM assembler only }
  1686. Replace(result,'@','__a$$');
  1687. {$endif arm}
  1688. end;
  1689. end
  1690. else
  1691. begin
  1692. if importname<>'' then
  1693. begin
  1694. if not(pco in [pocall_cdecl,pocall_cppdecl]) then
  1695. result:=importname
  1696. else
  1697. result:=target_info.Cprefix+importname;
  1698. end
  1699. else
  1700. result:='_index_'+tostr(import_nr);
  1701. end;
  1702. end;
  1703. {****************************************************************************
  1704. TDEFAWARESYMTABLESTACK
  1705. (symtablestack descendant that does some special actions on
  1706. the pushed/popped symtables)
  1707. ****************************************************************************}
  1708. procedure tdefawaresymtablestack.add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  1709. var
  1710. s: TSymStr;
  1711. list: TFPObjectList;
  1712. def: tdef;
  1713. sym : tsym;
  1714. i: integer;
  1715. begin
  1716. { search the symtable from first to last; the helper to use will be the
  1717. last one in the list }
  1718. for i:=0 to st.symlist.count-1 do
  1719. begin
  1720. sym:=tsym(st.symlist[i]);
  1721. if not (sym.typ in [typesym,procsym]) then
  1722. continue;
  1723. if sym.typ=typesym then
  1724. def:=ttypesym(st.SymList[i]).typedef
  1725. else
  1726. def:=nil;
  1727. if is_objectpascal_helper(def) then
  1728. begin
  1729. s:=generate_objectpascal_helper_key(tobjectdef(def).extendeddef);
  1730. Message1(sym_d_adding_helper_for,s);
  1731. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  1732. if not assigned(list) then
  1733. begin
  1734. list:=TFPObjectList.Create(false);
  1735. current_module.extendeddefs.Add(s,list);
  1736. end;
  1737. list.Add(def);
  1738. end
  1739. else
  1740. begin
  1741. if addgenerics then
  1742. add_generic_dummysym(sym,'');
  1743. { add nested helpers as well }
  1744. if assigned(def) and
  1745. (def.typ in [recorddef,objectdef]) and
  1746. (sto_has_helper in tabstractrecorddef(def).symtable.tableoptions) and
  1747. not is_owned_by(def,tdef(st.defowner)) then
  1748. add_helpers_and_generics(tabstractrecorddef(def).symtable,false);
  1749. end;
  1750. end;
  1751. end;
  1752. procedure tdefawaresymtablestack.remove_helpers_and_generics(st:tsymtable);
  1753. begin
  1754. if sto_has_helper in st.tableoptions then
  1755. remove_helpers(st);
  1756. if sto_has_generic in st.tableoptions then
  1757. remove_generics(st);
  1758. end;
  1759. procedure tdefawaresymtablestack.remove_helpers(st:TSymtable);
  1760. var
  1761. i, j: integer;
  1762. tmpst: TSymtable;
  1763. list: TFPObjectList;
  1764. begin
  1765. for i:=current_module.extendeddefs.count-1 downto 0 do
  1766. begin
  1767. list:=TFPObjectList(current_module.extendeddefs[i]);
  1768. for j:=list.count-1 downto 0 do
  1769. begin
  1770. if not (list[j] is tobjectdef) then
  1771. Internalerror(2011031501);
  1772. tmpst:=tobjectdef(list[j]).owner;
  1773. repeat
  1774. if tmpst=st then
  1775. begin
  1776. list.delete(j);
  1777. break;
  1778. end
  1779. else
  1780. begin
  1781. if assigned(tmpst.defowner) then
  1782. tmpst:=tmpst.defowner.owner
  1783. else
  1784. tmpst:=nil;
  1785. end;
  1786. until not assigned(tmpst) or (tmpst.symtabletype in [globalsymtable,staticsymtable]);
  1787. end;
  1788. if list.count=0 then
  1789. current_module.extendeddefs.delete(i);
  1790. end;
  1791. end;
  1792. procedure tdefawaresymtablestack.remove_generics(st:tsymtable);
  1793. var
  1794. i,j : longint;
  1795. entry : tgenericdummyentry;
  1796. list : tfpobjectlist;
  1797. begin
  1798. for i:=current_module.genericdummysyms.count-1 downto 0 do
  1799. begin
  1800. list:=tfpobjectlist(current_module.genericdummysyms[i]);
  1801. if not assigned(list) then
  1802. continue;
  1803. for j:=list.count-1 downto 0 do
  1804. begin
  1805. entry:=tgenericdummyentry(list[j]);
  1806. if entry.dummysym.owner=st then
  1807. list.delete(j);
  1808. end;
  1809. if list.count=0 then
  1810. current_module.genericdummysyms.delete(i);
  1811. end;
  1812. end;
  1813. procedure tdefawaresymtablestack.pushcommon(st:tsymtable);
  1814. begin
  1815. if (sto_has_generic in st.tableoptions) or
  1816. (
  1817. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1818. (sto_has_helper in st.tableoptions)
  1819. ) then
  1820. { nested helpers will be added as well }
  1821. add_helpers_and_generics(st,true);
  1822. end;
  1823. procedure tdefawaresymtablestack.push(st: TSymtable);
  1824. begin
  1825. pushcommon(st);
  1826. inherited push(st);
  1827. end;
  1828. procedure tdefawaresymtablestack.pushafter(st,afterst:TSymtable);
  1829. begin
  1830. pushcommon(st);
  1831. inherited pushafter(st,afterst);
  1832. end;
  1833. procedure tdefawaresymtablestack.pop(st: TSymtable);
  1834. begin
  1835. inherited pop(st);
  1836. if (sto_has_generic in st.tableoptions) or
  1837. (
  1838. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1839. (sto_has_helper in st.tableoptions)
  1840. ) then
  1841. { nested helpers will be removed as well }
  1842. remove_helpers_and_generics(st);
  1843. end;
  1844. {****************************************************************************
  1845. TDEF (base class for definitions)
  1846. ****************************************************************************}
  1847. constructor tgenericconstraintdata.create;
  1848. begin
  1849. interfaces:=tfpobjectlist.create(false);
  1850. interfacesderef:=tfplist.create;
  1851. end;
  1852. destructor tgenericconstraintdata.destroy;
  1853. begin
  1854. TFPList.FreeAndNilDisposing(interfacesderef,typeinfo(tderef));
  1855. interfaces.free;
  1856. inherited destroy;
  1857. end;
  1858. procedure tgenericconstraintdata.ppuload(ppufile: tcompilerppufile);
  1859. var
  1860. cnt,i : longint;
  1861. intfderef : pderef;
  1862. begin
  1863. ppufile.getset(tppuset1(flags));
  1864. cnt:=ppufile.getlongint;
  1865. for i:=0 to cnt-1 do
  1866. begin
  1867. new(intfderef);
  1868. ppufile.getderef(intfderef^);
  1869. interfacesderef.add(intfderef);
  1870. end;
  1871. end;
  1872. procedure tgenericconstraintdata.ppuwrite(ppufile: tcompilerppufile);
  1873. var
  1874. i : longint;
  1875. begin
  1876. ppufile.putset(tppuset1(flags));
  1877. ppufile.putlongint(interfacesderef.count);
  1878. for i:=0 to interfacesderef.count-1 do
  1879. ppufile.putderef(pderef(interfacesderef[i])^);
  1880. end;
  1881. procedure tgenericconstraintdata.buildderef;
  1882. var
  1883. intfderef : pderef;
  1884. i : longint;
  1885. begin
  1886. interfacesderef.capacity:=interfacesderef.count+interfaces.count;
  1887. for i:=0 to interfaces.count-1 do
  1888. begin
  1889. new(intfderef);
  1890. intfderef^.build(tobjectdef(interfaces[i]));
  1891. interfacesderef.add(intfderef);
  1892. end;
  1893. end;
  1894. procedure tgenericconstraintdata.deref;
  1895. var
  1896. i : longint;
  1897. begin
  1898. interfaces.capacity:=interfaces.count+interfacesderef.count;
  1899. for i:=0 to interfacesderef.count-1 do
  1900. interfaces.add(pderef(interfacesderef[i])^.resolve);
  1901. end;
  1902. procedure tstoreddef.writeentry(ppufile: tcompilerppufile; ibnr: byte);
  1903. begin
  1904. ppuwrite_platform(ppufile);
  1905. ppufile.writeentry(ibnr);
  1906. end;
  1907. procedure tstoreddef.ppuwrite_platform(ppufile: tcompilerppufile);
  1908. begin
  1909. { by default: do nothing }
  1910. end;
  1911. procedure tstoreddef.ppuload_platform(ppufile: tcompilerppufile);
  1912. begin
  1913. { by default: do nothing }
  1914. end;
  1915. class procedure tstoreddef.setup_reusable_def(origdef, newdef: tdef; res: PHashSetItem; oldsymtablestack: tsymtablestack);
  1916. var
  1917. reusablesymtab: tsymtable;
  1918. begin
  1919. { must not yet belong to a symtable }
  1920. if assigned(newdef.owner) then
  1921. internalerror(2015111503);
  1922. reusablesymtab:=origdef.getreusablesymtab;
  1923. res^.Data:=newdef;
  1924. reusablesymtab.insertdef(newdef);
  1925. symtablestack:=oldsymtablestack;
  1926. end;
  1927. constructor tstoreddef.create(dt:tdeftyp;doregister:boolean);
  1928. begin
  1929. inherited create(dt);
  1930. savesize := 0;
  1931. {$ifdef EXTDEBUG}
  1932. fileinfo := current_filepos;
  1933. {$endif}
  1934. generictokenbuf:=nil;
  1935. genericdef:=nil;
  1936. typesymderef.reset;
  1937. genericdefderef.reset;
  1938. { Don't register forwarddefs, they are disposed at the
  1939. end of an type block }
  1940. if (dt=forwarddef) then
  1941. exit;
  1942. { Register in symtable stack }
  1943. if doregister then
  1944. begin
  1945. { immediately register interface defs, as they will always be
  1946. written to the ppu, their defid influences the interface crc and
  1947. if we wait, depending on e.g. compiler defines they may get a
  1948. different defid (e.g. when a function is called, its procdef is
  1949. registered, so depending on whether or not, or when, an interface
  1950. procedure is called in the implementation, that may change its
  1951. defid otherwise) }
  1952. if assigned(current_module) and
  1953. current_module.in_interface then
  1954. register_def
  1955. else
  1956. maybe_put_in_symtable_stack;
  1957. end;
  1958. end;
  1959. destructor tstoreddef.destroy;
  1960. begin
  1961. { Direct calls are not allowed, use symtable.deletedef() }
  1962. if assigned(owner) then
  1963. internalerror(200612311);
  1964. if assigned(generictokenbuf) then
  1965. begin
  1966. generictokenbuf.free;
  1967. generictokenbuf:=nil;
  1968. end;
  1969. rtti_attribute_list.free;
  1970. genericparas.free;
  1971. TFPList.FreeAndNilDisposing(genericparaderefs,typeinfo(tderef));
  1972. genconstraintdata.free;
  1973. {$ifndef symansistr}
  1974. stringdispose(_fullownerhierarchyname);
  1975. {$endif not symansistr}
  1976. inherited destroy;
  1977. end;
  1978. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1979. var
  1980. sizeleft,i,cnt : longint;
  1981. buf : array[0..255] of byte;
  1982. symderef : pderef;
  1983. begin
  1984. inherited create(dt);
  1985. DefId:=ppufile.getlongint;
  1986. current_module.deflist[DefId]:=self;
  1987. {$ifdef EXTDEBUG}
  1988. fillchar(fileinfo,sizeof(fileinfo),0);
  1989. {$endif}
  1990. { load }
  1991. ppufile.getderef(typesymderef);
  1992. ppufile.getset(tppuset2(defoptions));
  1993. ppufile.getset(tppuset1(defstates));
  1994. if df_unique in defoptions then
  1995. ppufile.getderef(orgdefderef);
  1996. if df_genconstraint in defoptions then
  1997. begin
  1998. genconstraintdata:=tgenericconstraintdata.create;
  1999. genconstraintdata.ppuload(ppufile);
  2000. end;
  2001. if [df_generic,df_specialization]*defoptions<>[] then
  2002. begin
  2003. cnt:=ppufile.getlongint;
  2004. if cnt>0 then
  2005. begin
  2006. genericparas:=tfphashobjectlist.create(false);
  2007. genericparaderefs:=tfplist.create;
  2008. for i:=0 to cnt-1 do
  2009. begin
  2010. genericparas.add(ppufile.getstring,nil);
  2011. New(symderef);
  2012. ppufile.getderef(symderef^);
  2013. genericparaderefs.add(symderef);
  2014. end;
  2015. end;
  2016. end;
  2017. if df_generic in defoptions then
  2018. begin
  2019. sizeleft:=ppufile.getlongint;
  2020. initgeneric;
  2021. while sizeleft>0 do
  2022. begin
  2023. if sizeleft>sizeof(buf) then
  2024. i:=sizeof(buf)
  2025. else
  2026. i:=sizeleft;
  2027. ppufile.getdata(buf,i);
  2028. generictokenbuf.write(buf,i);
  2029. dec(sizeleft,i);
  2030. end;
  2031. end;
  2032. if df_specialization in defoptions then
  2033. ppufile.getderef(genericdefderef);
  2034. rtti_attribute_list:=trtti_attribute_list.ppuload(ppufile);
  2035. end;
  2036. function tstoreddef.needs_separate_initrtti:boolean;
  2037. begin
  2038. result:=false;
  2039. end;
  2040. function tstoreddef.rtti_mangledname(rt : trttitype) : TSymStr;
  2041. var
  2042. prefix : string[4];
  2043. begin
  2044. if (rt=fullrtti) or (not needs_separate_initrtti) then
  2045. begin
  2046. prefix:='RTTI';
  2047. include(defstates,ds_rtti_table_used);
  2048. end
  2049. else
  2050. begin
  2051. prefix:='INIT';
  2052. include(defstates,ds_init_table_used);
  2053. end;
  2054. if assigned(typesym) and
  2055. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  2056. result:=make_mangledname(prefix,typesym.owner,typesym.name)
  2057. else
  2058. result:=make_mangledname(prefix,findunitsymtable(owner),'def'+unique_id_str)
  2059. end;
  2060. function tstoreddef.OwnerHierarchyName: string;
  2061. var
  2062. tmp: tdef;
  2063. begin
  2064. tmp:=self;
  2065. result:='';
  2066. repeat
  2067. { can be not assigned in case of a forwarddef }
  2068. if assigned(tmp.owner) and
  2069. (tmp.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2070. tmp:=tdef(tmp.owner.defowner)
  2071. else
  2072. break;
  2073. result:=tabstractrecorddef(tmp).objrealname^+'.'+result;
  2074. until tmp=nil;
  2075. end;
  2076. function tstoreddef.OwnerHierarchyPrettyName: string;
  2077. var
  2078. tmp: tdef;
  2079. begin
  2080. tmp:=self;
  2081. result:='';
  2082. repeat
  2083. { can be not assigned in case of a forwarddef }
  2084. if assigned(tmp.owner) and
  2085. (tmp.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2086. tmp:=tdef(tmp.owner.defowner)
  2087. else
  2088. break;
  2089. result:=tabstractrecorddef(tmp).typesymbolprettyname+'.'+result;
  2090. until tmp=nil;
  2091. end;
  2092. function tstoreddef.fullownerhierarchyname(skipprocparams:boolean): TSymStr;
  2093. var
  2094. lastowner: tsymtable;
  2095. tmp: tdef;
  2096. pno: tprocnameoptions;
  2097. begin
  2098. {$ifdef symansistr}
  2099. if not skipprocparams and (_fullownerhierarchyname<>'') then
  2100. exit(_fullownerhierarchyname);
  2101. {$else symansistr}
  2102. if not skipprocparams and assigned(_fullownerhierarchyname) then
  2103. exit(_fullownerhierarchyname^);
  2104. {$endif symansistr}
  2105. { the def can only reside inside structured types or
  2106. procedures/functions/methods }
  2107. tmp:=self;
  2108. result:='';
  2109. repeat
  2110. lastowner:=tmp.owner;
  2111. { can be not assigned in case of a forwarddef }
  2112. if not assigned(lastowner) then
  2113. break
  2114. else
  2115. tmp:=tdef(lastowner.defowner);
  2116. if not assigned(tmp) then
  2117. break;
  2118. if tmp.typ in [recorddef,objectdef] then
  2119. result:=tabstractrecorddef(tmp).objrealname^+'.'+result
  2120. else
  2121. if tmp.typ=procdef then
  2122. begin
  2123. pno:=[pno_paranames,pno_proctypeoption];
  2124. if skipprocparams then
  2125. include(pno,pno_noparams);
  2126. result:=tprocdef(tmp).customprocname(pno)+'.'+result;
  2127. end;
  2128. until tmp=nil;
  2129. { add the unit name }
  2130. if assigned(lastowner) and
  2131. assigned(lastowner.realname) then
  2132. result:=lastowner.realname^+'.'+result;
  2133. if not skipprocparams then
  2134. { don't store the name in this case }
  2135. {$ifdef symansistr}
  2136. _fullownerhierarchyname:=result;
  2137. {$else symansistr}
  2138. _fullownerhierarchyname:=stringdup(result);
  2139. {$endif symansistr}
  2140. end;
  2141. function tstoreddef.in_currentunit: boolean;
  2142. var
  2143. st: tsymtable;
  2144. begin
  2145. st:=owner;
  2146. while not(st.symtabletype in [globalsymtable,staticsymtable]) do
  2147. st:=st.defowner.owner;
  2148. result:=st.iscurrentunit;
  2149. end;
  2150. function tstoreddef.getcopy : tstoreddef;
  2151. begin
  2152. Message(sym_e_cant_create_unique_type);
  2153. getcopy:=cerrordef.create;
  2154. end;
  2155. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  2156. var
  2157. sizeleft,i : longint;
  2158. buf : array[0..255] of byte;
  2159. oldintfcrc : boolean;
  2160. begin
  2161. if defid<0 then
  2162. internalerror(2015101401);
  2163. ppufile.putlongint(DefId);
  2164. ppufile.putderef(typesymderef);
  2165. ppufile.putset(tppuset2(defoptions));
  2166. oldintfcrc:=ppufile.do_crc;
  2167. ppufile.do_crc:=false;
  2168. ppufile.putset(tppuset1(defstates));
  2169. if df_unique in defoptions then
  2170. ppufile.putderef(orgdefderef);
  2171. if df_genconstraint in defoptions then
  2172. genconstraintdata.ppuwrite(ppufile);
  2173. if [df_generic,df_specialization]*defoptions<>[] then
  2174. begin
  2175. if not assigned(genericparas) then
  2176. ppufile.putlongint(0)
  2177. else
  2178. begin
  2179. if not assigned(genericparaderefs) then
  2180. internalerror(2014052305);
  2181. ppufile.putlongint(genericparas.count);
  2182. for i:=0 to genericparas.count-1 do
  2183. begin
  2184. ppufile.putstring(genericparas.nameofindex(i));
  2185. ppufile.putderef(pderef(genericparaderefs[i])^);
  2186. end;
  2187. end;
  2188. end;
  2189. if df_generic in defoptions then
  2190. begin
  2191. if assigned(generictokenbuf) then
  2192. begin
  2193. sizeleft:=generictokenbuf.size;
  2194. generictokenbuf.seek(0);
  2195. end
  2196. else
  2197. sizeleft:=0;
  2198. ppufile.putlongint(sizeleft);
  2199. while sizeleft>0 do
  2200. begin
  2201. if sizeleft>sizeof(buf) then
  2202. i:=sizeof(buf)
  2203. else
  2204. i:=sizeleft;
  2205. generictokenbuf.read(buf,i);
  2206. ppufile.putdata(buf,i);
  2207. dec(sizeleft,i);
  2208. end;
  2209. end;
  2210. ppufile.do_crc:=oldintfcrc;
  2211. if df_specialization in defoptions then
  2212. ppufile.putderef(genericdefderef);
  2213. trtti_attribute_list.ppuwrite(rtti_attribute_list,ppufile);
  2214. end;
  2215. procedure tstoreddef.ppuload_subentries(ppufile: tcompilerppufile);
  2216. begin
  2217. trtti_attribute_list.ppuload_subentries(rtti_attribute_list,ppufile);
  2218. end;
  2219. procedure tstoreddef.ppuwrite_subentries(ppufile: tcompilerppufile);
  2220. begin
  2221. trtti_attribute_list.ppuwrite_subentries(rtti_attribute_list,ppufile);
  2222. end;
  2223. procedure tstoreddef.buildderef;
  2224. var
  2225. i : longint;
  2226. sym : tsym;
  2227. symderef : pderef;
  2228. begin
  2229. if not registered then
  2230. register_def;
  2231. typesymderef.build(typesym);
  2232. orgdefderef.build(orgdef);
  2233. genericdefderef.build(genericdef);
  2234. if assigned(rtti_attribute_list) then
  2235. rtti_attribute_list.buildderef;
  2236. if assigned(genconstraintdata) then
  2237. genconstraintdata.buildderef;
  2238. if assigned(genericparas) then
  2239. begin
  2240. if not assigned(genericparaderefs) then
  2241. genericparaderefs:=tfplist.create;
  2242. genericparaderefs.capacity:=genericparaderefs.count+genericparas.count;
  2243. for i:=0 to genericparas.count-1 do
  2244. begin
  2245. sym:=tsym(genericparas.items[i]);
  2246. new(symderef);
  2247. symderef^.build(sym);
  2248. genericparaderefs.add(symderef);
  2249. end;
  2250. end;
  2251. end;
  2252. procedure tstoreddef.buildderefimpl;
  2253. begin
  2254. end;
  2255. procedure tstoreddef.deref;
  2256. var
  2257. symderef : pderef;
  2258. i : longint;
  2259. begin
  2260. typesym:=ttypesym(typesymderef.resolve);
  2261. if df_unique in defoptions then
  2262. orgdef:=tstoreddef(orgdefderef.resolve);
  2263. if df_specialization in defoptions then
  2264. genericdef:=tstoreddef(genericdefderef.resolve);
  2265. if assigned(rtti_attribute_list) then
  2266. rtti_attribute_list.deref;
  2267. if assigned(genconstraintdata) then
  2268. genconstraintdata.deref;
  2269. if assigned(genericparas) then
  2270. begin
  2271. if not assigned(genericparaderefs) then
  2272. internalerror(2014052302);
  2273. if genericparas.count<>genericparaderefs.count then
  2274. internalerror(2014052303);
  2275. for i:=0 to genericparaderefs.count-1 do
  2276. begin
  2277. symderef:=pderef(genericparaderefs[i]);
  2278. genericparas.items[i]:=symderef^.resolve;
  2279. end;
  2280. end;
  2281. end;
  2282. procedure tstoreddef.derefimpl;
  2283. begin
  2284. end;
  2285. function tstoreddef.size : asizeint;
  2286. begin
  2287. size:=savesize;
  2288. end;
  2289. function tstoreddef.getvardef:longint;
  2290. begin
  2291. result:=varUndefined;
  2292. end;
  2293. function tstoreddef.alignment : shortint;
  2294. begin
  2295. { natural alignment by default }
  2296. alignment:=size_2_align(savesize);
  2297. { can happen if savesize = 0, e.g. for voiddef or
  2298. an empty record
  2299. }
  2300. if (alignment=0) then
  2301. alignment:=1;
  2302. end;
  2303. { returns true, if the definition can be published }
  2304. function tstoreddef.is_publishable : tpublishproperty;
  2305. begin
  2306. is_publishable:=pp_error;
  2307. end;
  2308. { needs an init table }
  2309. function tstoreddef.needs_inittable : boolean;
  2310. begin
  2311. needs_inittable:=false;
  2312. end;
  2313. function tstoreddef.has_non_trivial_init_child(check_parent:boolean):boolean;
  2314. begin
  2315. result:=false;
  2316. end;
  2317. function tstoreddef.is_intregable : boolean;
  2318. {$ifndef cpuhighleveltarget}
  2319. var
  2320. recsize,temp: longint;
  2321. {$endif cpuhighleveltarget}
  2322. begin
  2323. case typ of
  2324. orddef,
  2325. pointerdef,
  2326. enumdef,
  2327. classrefdef:
  2328. is_intregable:=true;
  2329. procvardef :
  2330. is_intregable:=tprocvardef(self).is_addressonly or (po_methodpointer in tprocvardef(self).procoptions);
  2331. objectdef:
  2332. is_intregable:=(is_implicit_pointer_object_type(self)) and not needs_inittable;
  2333. setdef:
  2334. is_intregable:=is_smallset(self);
  2335. arraydef:
  2336. {$ifdef cpuhighleveltarget}
  2337. is_intregable:=false
  2338. {$else cpuhighleveltarget}
  2339. is_intregable:=not(is_special_array(self)) and
  2340. (tarraydef(self).size<=8) and (tarraydef(self).size in [1,2,4,8]) and
  2341. tstoreddef(tarraydef(self).elementdef).is_intregable
  2342. {$ifdef SUPPORT_MMX}
  2343. and not((cs_mmx in current_settings.localswitches) and
  2344. is_mmx_able_array(self))
  2345. {$endif SUPPORT_MMX}
  2346. {$endif cpuhighleveltarget}
  2347. ;
  2348. recorddef:
  2349. begin
  2350. {$ifdef cpuhighleveltarget}
  2351. is_intregable:=false;
  2352. {$else cpuhighleveltarget}
  2353. recsize:=size;
  2354. is_intregable:=
  2355. ispowerof2(recsize,temp) and
  2356. ((recsize<=sizeof(aint)*2) and
  2357. not trecorddef(self).contains_cross_aword_field and
  2358. { records cannot go into registers on 16 bit targets for now }
  2359. (sizeof(aint)>2) and
  2360. not trecorddef(self).contains_float_field
  2361. ) and
  2362. not needs_inittable;
  2363. {$endif cpuhighleveltarget}
  2364. end;
  2365. else
  2366. is_intregable:=false;
  2367. end;
  2368. end;
  2369. function tstoreddef.is_fpuregable : boolean;
  2370. begin
  2371. {$ifdef x86}
  2372. result:=use_vectorfpu(self);
  2373. {$else x86}
  2374. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches)
  2375. {$ifdef xtensa}
  2376. and (FPUXTENSA_SINGLE in fpu_capabilities[current_settings.fputype]) and (tfloatdef(self).floattype=s32real)
  2377. {$endif xtensa}
  2378. {$ifdef riscv}
  2379. and (((CPURV_HAS_F in cpu_capabilities[current_settings.cputype]) and (tfloatdef(self).floattype=s32real)) or
  2380. ((CPURV_HAS_D in cpu_capabilities[current_settings.cputype]) and (tfloatdef(self).floattype=s64real)) or
  2381. ((CPURV_HAS_Q in cpu_capabilities[current_settings.cputype]) and (tfloatdef(self).floattype=s128real)))
  2382. {$endif riscv}
  2383. {$ifdef arm}
  2384. and (((FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[current_settings.fputype]) and (tfloatdef(self).floattype=s32real)) or
  2385. (FPUARM_HAS_VFP_DOUBLE in fpu_capabilities[current_settings.fputype]))
  2386. {$endif arm}
  2387. ;
  2388. {$endif x86}
  2389. end;
  2390. function tstoreddef.is_const_intregable : boolean;
  2391. begin
  2392. case typ of
  2393. stringdef:
  2394. result:=tstringdef(self).stringtype in [st_ansistring,st_unicodestring,st_widestring];
  2395. arraydef:
  2396. result:=is_dynamic_array(self);
  2397. objectdef:
  2398. result:=is_interface(self);
  2399. else
  2400. result:=false;
  2401. end;
  2402. end;
  2403. procedure tstoreddef.initgeneric;
  2404. begin
  2405. if assigned(generictokenbuf) then
  2406. internalerror(200512131);
  2407. generictokenbuf:=tdynamicarray.create(256);
  2408. end;
  2409. function tstoreddef.is_generic: boolean;
  2410. var
  2411. sym: tsym;
  2412. i: longint;
  2413. begin
  2414. result:=assigned(genericparas) and
  2415. (genericparas.count>0) and
  2416. (df_generic in defoptions);
  2417. if result then
  2418. { if any of the type parameters does *not* belong to us (meaning it was passed
  2419. in from outside) then we aren't a generic, but a specialization }
  2420. for i:=0 to genericparas.count-1 do
  2421. begin
  2422. sym:=tsym(genericparas[i]);
  2423. { sym must be either a type or const }
  2424. if not (sym.typ in [symconst.typesym,symconst.constsym]) then
  2425. internalerror(2014050903);
  2426. if (sym.owner.defowner<>self) or (sp_generic_unnamed_type in sym.symoptions) then
  2427. exit(false);
  2428. if (sym.typ=symconst.constsym) and (sp_generic_const in sym.symoptions) then
  2429. exit(false);
  2430. end;
  2431. end;
  2432. function tstoreddef.is_generic_param_const(index:integer):boolean;
  2433. begin
  2434. result:=tsym(genericparas[index]).typ=constsym;
  2435. end;
  2436. function tstoreddef.get_generic_param_def(index:integer):tdef;
  2437. begin
  2438. if tsym(genericparas[index]).typ=constsym then
  2439. result:=tconstsym(genericparas[index]).constdef
  2440. else
  2441. result:=ttypesym(genericparas[index]).typedef;
  2442. end;
  2443. function tstoreddef.is_specialization: boolean;
  2444. var
  2445. i : longint;
  2446. sym : tsym;
  2447. begin
  2448. result:=assigned(genericparas) and
  2449. (genericparas.count>0) and
  2450. (df_specialization in defoptions);
  2451. if result then
  2452. begin
  2453. { if at least one of the generic parameters is not owned by us (meaning it was
  2454. passed in from outside) then we have a specialization, otherwise we have a generic }
  2455. for i:=0 to genericparas.count-1 do
  2456. begin
  2457. sym:=tsym(genericparas[i]);
  2458. { sym must be either a type or const }
  2459. if not (sym.typ in [symconst.typesym,symconst.constsym]) then
  2460. internalerror(2014050904);
  2461. if (sym.owner.defowner<>self) or (sp_generic_unnamed_type in sym.symoptions) then
  2462. exit(true);
  2463. if (sym.typ=symconst.constsym) and (sp_generic_const in sym.symoptions) then
  2464. exit(true);
  2465. end;
  2466. result:=false;
  2467. end;
  2468. end;
  2469. procedure tstoreddef.register_def;
  2470. var
  2471. gst : tgetsymtable;
  2472. st : tsymtable;
  2473. tmod : tmodule;
  2474. begin
  2475. if registered then
  2476. exit;
  2477. if assigned(owner) then
  2478. begin
  2479. tmod:=find_module_from_symtable(owner);
  2480. if assigned(tmod) and assigned(current_module) and (tmod<>current_module) then
  2481. begin
  2482. comment(v_error,'Definition '+fullownerhierarchyname(false)+' from module '+tmod.mainsource+' registered with current module '+current_module.mainsource);
  2483. end;
  2484. if not assigned(tmod) then
  2485. tmod:=current_module;
  2486. end
  2487. else
  2488. tmod:=current_module;
  2489. { Register in current_module }
  2490. if assigned(tmod) then
  2491. begin
  2492. exclude(defoptions,df_not_registered_no_free);
  2493. for gst:=low(tgetsymtable) to high(tgetsymtable) do
  2494. begin
  2495. st:=getsymtable(gst);
  2496. if assigned(st) then
  2497. tstoredsymtable(st).register_children;
  2498. end;
  2499. if defid<defid_not_registered then
  2500. defid:=deflist_index
  2501. else
  2502. begin
  2503. tmod.deflist.Add(self);
  2504. defid:=tmod.deflist.Count-1;
  2505. registered_in_module:=tmod;
  2506. end;
  2507. maybe_put_in_symtable_stack;
  2508. end
  2509. else
  2510. DefId:=defid_registered_nost;
  2511. end;
  2512. procedure tstoreddef.maybe_put_in_symtable_stack;
  2513. var
  2514. insertstack: psymtablestackitem;
  2515. begin
  2516. if assigned(symtablestack) and
  2517. not assigned(self.owner) then
  2518. begin
  2519. insertstack:=symtablestack.stack;
  2520. { don't insert defs in exception symtables, as they are freed before
  2521. the module is compiled, so we can get crashes on high level targets
  2522. if they still need it while e.g. writing assembler code }
  2523. while assigned(insertstack) and
  2524. (insertstack^.symtable.symtabletype in [exceptsymtable,withsymtable]) do
  2525. insertstack:=insertstack^.next;
  2526. if not assigned(insertstack) then
  2527. internalerror(200602044);
  2528. if insertstack^.symtable.sealed then
  2529. internalerror(2015022301);
  2530. insertstack^.symtable.insertdef(self);
  2531. end;
  2532. end;
  2533. {****************************************************************************
  2534. Tstringdef
  2535. ****************************************************************************}
  2536. constructor tstringdef.createshort(l: byte; doregister: boolean);
  2537. begin
  2538. inherited create(stringdef,doregister);
  2539. stringtype:=st_shortstring;
  2540. encoding:=0;
  2541. len:=l;
  2542. end;
  2543. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  2544. begin
  2545. inherited ppuload(stringdef,ppufile);
  2546. stringtype:=st_shortstring;
  2547. encoding:=0;
  2548. len:=ppufile.getbyte;
  2549. ppuload_platform(ppufile);
  2550. end;
  2551. constructor tstringdef.createlong(l: asizeint; doregister: boolean);
  2552. begin
  2553. inherited create(stringdef,doregister);
  2554. stringtype:=st_longstring;
  2555. encoding:=0;
  2556. len:=l;
  2557. end;
  2558. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  2559. begin
  2560. inherited ppuload(stringdef,ppufile);
  2561. stringtype:=st_longstring;
  2562. encoding:=0;
  2563. len:=ppufile.getasizeint;
  2564. ppuload_platform(ppufile);
  2565. end;
  2566. constructor tstringdef.createansi(aencoding: tstringencoding; doregister: boolean);
  2567. begin
  2568. inherited create(stringdef,doregister);
  2569. stringtype:=st_ansistring;
  2570. encoding:=aencoding;
  2571. len:=-1;
  2572. end;
  2573. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  2574. begin
  2575. inherited ppuload(stringdef,ppufile);
  2576. stringtype:=st_ansistring;
  2577. len:=ppufile.getasizeint;
  2578. encoding:=ppufile.getword;
  2579. ppuload_platform(ppufile);
  2580. end;
  2581. constructor tstringdef.createwide(doregister: boolean);
  2582. begin
  2583. inherited create(stringdef,doregister);
  2584. stringtype:=st_widestring;
  2585. if target_info.endian=endian_little then
  2586. encoding:=CP_UTF16LE
  2587. else
  2588. encoding:=CP_UTF16BE;
  2589. len:=-1;
  2590. end;
  2591. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  2592. begin
  2593. inherited ppuload(stringdef,ppufile);
  2594. stringtype:=st_widestring;
  2595. if target_info.endian=endian_little then
  2596. encoding:=CP_UTF16LE
  2597. else
  2598. encoding:=CP_UTF16BE;
  2599. len:=ppufile.getasizeint;
  2600. ppuload_platform(ppufile);
  2601. end;
  2602. constructor tstringdef.createunicode(doregister: boolean);
  2603. begin
  2604. inherited create(stringdef,doregister);
  2605. stringtype:=st_unicodestring;
  2606. if target_info.endian=endian_little then
  2607. encoding:=CP_UTF16LE
  2608. else
  2609. encoding:=CP_UTF16BE;
  2610. len:=-1;
  2611. end;
  2612. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  2613. begin
  2614. inherited ppuload(stringdef,ppufile);
  2615. stringtype:=st_unicodestring;
  2616. len:=ppufile.getasizeint;
  2617. encoding:=ppufile.getword;
  2618. ppuload_platform(ppufile);
  2619. end;
  2620. function tstringdef.getcopy : tstoreddef;
  2621. begin
  2622. result:=cstringdef.create(typ,true);
  2623. result.typ:=stringdef;
  2624. tstringdef(result).stringtype:=stringtype;
  2625. tstringdef(result).encoding:=encoding;
  2626. tstringdef(result).len:=len;
  2627. end;
  2628. function tstringdef.stringtypname:string;
  2629. const
  2630. typname:array[tstringtype] of string[10]=(
  2631. 'shortstr','longstr','ansistr','widestr','unicodestr'
  2632. );
  2633. begin
  2634. stringtypname:=typname[stringtype];
  2635. end;
  2636. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  2637. begin
  2638. inherited ppuwrite(ppufile);
  2639. if stringtype=st_shortstring then
  2640. begin
  2641. {$ifdef extdebug}
  2642. if len > 255 then internalerror(12122002);
  2643. {$endif}
  2644. ppufile.putbyte(byte(len))
  2645. end
  2646. else
  2647. ppufile.putasizeint(len);
  2648. if stringtype in [st_ansistring,st_unicodestring] then
  2649. ppufile.putword(encoding);
  2650. case stringtype of
  2651. st_shortstring : writeentry(ppufile,ibshortstringdef);
  2652. st_longstring : writeentry(ppufile,iblongstringdef);
  2653. st_ansistring : writeentry(ppufile,ibansistringdef);
  2654. st_widestring : writeentry(ppufile,ibwidestringdef);
  2655. st_unicodestring : writeentry(ppufile,ibunicodestringdef);
  2656. end;
  2657. end;
  2658. function tstringdef.needs_inittable : boolean;
  2659. begin
  2660. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  2661. end;
  2662. function tstringdef.GetTypeName : string;
  2663. const
  2664. names : array[tstringtype] of string[15] = (
  2665. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  2666. begin
  2667. GetTypeName:=names[stringtype];
  2668. case stringtype of
  2669. st_ansistring,st_unicodestring:
  2670. GetTypeName:=GetTypeName+'('+tostr(encoding)+')';
  2671. st_shortstring:
  2672. GetTypeName:=GetTypeName+'['+tostr(len)+']';
  2673. else
  2674. ;
  2675. end;
  2676. end;
  2677. function tstringdef.getvardef : longint;
  2678. const
  2679. vardef : array[tstringtype] of longint = (
  2680. varUndefined,varUndefined,varString,varOleStr,varUString);
  2681. begin
  2682. result:=vardef[stringtype];
  2683. end;
  2684. function tstringdef.get_default_char_type: tdef;
  2685. begin
  2686. case stringtype of
  2687. st_shortstring,
  2688. st_longstring,
  2689. st_ansistring:
  2690. result:=cansichartype;
  2691. st_unicodestring,
  2692. st_widestring:
  2693. result:=cwidechartype;
  2694. end;
  2695. end;
  2696. function tstringdef.get_default_string_type: tdef;
  2697. begin
  2698. case stringtype of
  2699. st_shortstring:
  2700. result:=cshortstringtype;
  2701. { st_longstring is currently not supported but
  2702. when it is this case will need to be supplied }
  2703. st_longstring:
  2704. internalerror(2021040801);
  2705. st_ansistring:
  2706. result:=cansistringtype;
  2707. st_widestring:
  2708. result:=cwidestringtype;
  2709. st_unicodestring:
  2710. result:=cunicodestringtype;
  2711. end
  2712. end;
  2713. function tstringdef.alignment : shortint;
  2714. begin
  2715. case stringtype of
  2716. st_unicodestring,
  2717. st_widestring,
  2718. st_ansistring:
  2719. alignment:=voidpointertype.alignment;
  2720. st_longstring,
  2721. st_shortstring:
  2722. { char to string accesses byte 0 and 1 with one word access }
  2723. if (tf_requires_proper_alignment in target_info.flags) or
  2724. { macpas needs an alignment of 2 (MetroWerks compatible) }
  2725. (m_mac in current_settings.modeswitches) then
  2726. alignment:=size_2_align(2)
  2727. else
  2728. alignment:=size_2_align(1);
  2729. end;
  2730. end;
  2731. function tstringdef.getmangledparaname : TSymStr;
  2732. begin
  2733. getmangledparaname:='STRING';
  2734. end;
  2735. function tstringdef.is_publishable : tpublishproperty;
  2736. begin
  2737. is_publishable:=pp_publish;
  2738. end;
  2739. function tstringdef.size: asizeint;
  2740. begin
  2741. case stringtype of
  2742. st_shortstring:
  2743. Result:=len+1;
  2744. st_longstring,
  2745. st_ansistring,
  2746. st_widestring,
  2747. st_unicodestring:
  2748. Result:=voidpointertype.size;
  2749. end;
  2750. end;
  2751. {****************************************************************************
  2752. TENUMDEF
  2753. ****************************************************************************}
  2754. constructor tenumdef.create;
  2755. begin
  2756. inherited create(enumdef,true);
  2757. minval:=0;
  2758. maxval:=0;
  2759. calcsavesize(current_settings.packenum);
  2760. has_jumps:=false;
  2761. basedef:=nil;
  2762. basedefderef.reset;
  2763. symtable:=tenumsymtable.create(self);
  2764. end;
  2765. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  2766. begin
  2767. inherited create(enumdef,true);
  2768. minval:=_min;
  2769. maxval:=_max;
  2770. basedef:=_basedef;
  2771. calcsavesize(current_settings.packenum);
  2772. has_jumps:=false;
  2773. symtable:=basedef.symtable.getcopy;
  2774. include(defoptions, df_copied_def);
  2775. end;
  2776. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  2777. begin
  2778. inherited ppuload(enumdef,ppufile);
  2779. minval:=ppufile.getaint;
  2780. maxval:=ppufile.getaint;
  2781. savesize:=ppufile.getaint;
  2782. has_jumps:=false;
  2783. if df_copied_def in defoptions then
  2784. begin
  2785. symtable:=nil;
  2786. ppufile.getderef(basedefderef);
  2787. ppuload_platform(ppufile);
  2788. end
  2789. else
  2790. begin
  2791. ppuload_platform(ppufile);
  2792. // create with nil defowner first to prevent values changes on insert
  2793. symtable:=tenumsymtable.create(nil);
  2794. tenumsymtable(symtable).ppuload(ppufile);
  2795. symtable.defowner:=self;
  2796. end;
  2797. end;
  2798. destructor tenumdef.destroy;
  2799. begin
  2800. symtable.free;
  2801. symtable:=nil;
  2802. inherited destroy;
  2803. end;
  2804. function tenumdef.getcopy : tstoreddef;
  2805. begin
  2806. if assigned(basedef) then
  2807. result:=cenumdef.create_subrange(basedef,minval,maxval)
  2808. else
  2809. begin
  2810. result:=cenumdef.create;
  2811. tenumdef(result).minval:=minval;
  2812. tenumdef(result).maxval:=maxval;
  2813. tenumdef(result).symtable.free;
  2814. tenumdef(result).symtable:=symtable.getcopy;
  2815. tenumdef(result).basedef:=self;
  2816. end;
  2817. tenumdef(result).has_jumps:=has_jumps;
  2818. tenumdef(result).basedefderef:=basedefderef;
  2819. include(tenumdef(result).defoptions,df_copied_def);
  2820. end;
  2821. procedure tenumdef.calcsavesize(packenum: shortint);
  2822. begin
  2823. {$IFNDEF cpu64bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2824. if (packenum=8) or (int64(min)<low(longint)) or (int64(max)>high(cardinal)) or ((min<0) and (max>high(longint))) then
  2825. savesize:=8
  2826. {$IFNDEF cpu64bitaddr} {$pop} {$ENDIF}
  2827. else
  2828. {$IFDEF cpu16bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2829. if (packenum=4) or (min<low(smallint)) or (max>high(word)) or ((min<0) and (max>high(smallint))) then
  2830. savesize:=4
  2831. {$IFDEF cpu16bitaddr} {$pop} {$ENDIF}
  2832. else
  2833. if (packenum=2) or (min<low(shortint)) or (max>high(byte)) or ((min<0) and (max>high(shortint))) then
  2834. savesize:=2
  2835. else
  2836. savesize:=1;
  2837. end;
  2838. function tenumdef.packedbitsize: asizeint;
  2839. var
  2840. sizeval: tconstexprint;
  2841. power: longint;
  2842. begin
  2843. result := 0;
  2844. if (minval >= 0) and
  2845. (maxval <= 1) then
  2846. result := 1
  2847. else
  2848. begin
  2849. if (minval>=0) then
  2850. sizeval:=maxval
  2851. else
  2852. { don't count 0 twice, but take into account that range goes from -n-1..n }
  2853. sizeval:=(cutils.max(-minval,maxval+1)*2)-1;
  2854. { 256 must become 512 etc. }
  2855. nextpowerof2(sizeval+1,power);
  2856. result := power;
  2857. end;
  2858. end;
  2859. procedure tenumdef.setmax(_max:asizeint);
  2860. begin
  2861. maxval:=_max;
  2862. calcsavesize(current_settings.packenum);
  2863. end;
  2864. procedure tenumdef.setmin(_min:asizeint);
  2865. begin
  2866. minval:=_min;
  2867. calcsavesize(current_settings.packenum);
  2868. end;
  2869. function tenumdef.min:asizeint;
  2870. begin
  2871. min:=minval;
  2872. end;
  2873. function tenumdef.max:asizeint;
  2874. begin
  2875. max:=maxval;
  2876. end;
  2877. function tenumdef.getfirstsym: tsym;
  2878. var
  2879. i:integer;
  2880. begin
  2881. for i := 0 to symtable.SymList.Count - 1 do
  2882. begin
  2883. result:=tsym(symtable.SymList[i]);
  2884. if tenumsym(result).value=minval then
  2885. exit;
  2886. end;
  2887. result:=nil;
  2888. end;
  2889. function tenumdef.int2enumsym(l: asizeint): tsym;
  2890. var
  2891. i: longint;
  2892. sym: tsym;
  2893. bdef: tenumdef;
  2894. begin
  2895. result:=nil;
  2896. if (l<minval) or
  2897. (l>maxval) then
  2898. exit;
  2899. bdef:=getbasedef;
  2900. for i:=0 to bdef.symtable.symlist.count-1 do
  2901. begin
  2902. sym:=tsym(bdef.symtable.symlist[i]);
  2903. if (sym.typ=enumsym) and
  2904. (tenumsym(sym).value=l) then
  2905. begin
  2906. result:=sym;
  2907. exit;
  2908. end;
  2909. end;
  2910. end;
  2911. function tenumdef.getbasedef: tenumdef;
  2912. begin
  2913. if not assigned(basedef) then
  2914. result:=self
  2915. else
  2916. result:=basedef;
  2917. end;
  2918. procedure tenumdef.buildderef;
  2919. begin
  2920. inherited buildderef;
  2921. if df_copied_def in defoptions then
  2922. basedefderef.build(basedef)
  2923. else
  2924. tenumsymtable(symtable).buildderef;
  2925. end;
  2926. procedure tenumdef.deref;
  2927. begin
  2928. inherited deref;
  2929. if df_copied_def in defoptions then
  2930. begin
  2931. basedef:=tenumdef(basedefderef.resolve);
  2932. symtable:=basedef.symtable.getcopy;
  2933. end
  2934. else
  2935. tenumsymtable(symtable).deref(false);
  2936. end;
  2937. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  2938. begin
  2939. inherited ppuwrite(ppufile);
  2940. ppufile.putaint(min);
  2941. ppufile.putaint(max);
  2942. ppufile.putaint(savesize);
  2943. if df_copied_def in defoptions then
  2944. ppufile.putderef(basedefderef);
  2945. writeentry(ppufile,ibenumdef);
  2946. if not (df_copied_def in defoptions) then
  2947. tenumsymtable(symtable).ppuwrite(ppufile);
  2948. end;
  2949. function tenumdef.is_publishable : tpublishproperty;
  2950. begin
  2951. if not has_jumps then
  2952. is_publishable:=pp_publish
  2953. else
  2954. if m_delphi in current_settings.modeswitches then
  2955. is_publishable:=pp_ignore
  2956. else
  2957. is_publishable:=pp_error;
  2958. end;
  2959. function tenumdef.GetTypeName : string;
  2960. begin
  2961. GetTypeName:='<enumeration type>';
  2962. end;
  2963. {****************************************************************************
  2964. TRTTI_ATTRIBUTE_LIST
  2965. ****************************************************************************}
  2966. constructor trtti_attribute.ppuload(ppufile: tcompilerppufile);
  2967. begin
  2968. ppufile.getderef(typesymderef);
  2969. ppufile.getderef(typeconstrderef);
  2970. setlength(paras,ppufile.getlongint);
  2971. end;
  2972. procedure trtti_attribute.ppuwrite(ppufile: tcompilerppufile);
  2973. begin
  2974. ppufile.putderef(typesymderef);
  2975. ppufile.putderef(typeconstrderef);
  2976. ppufile.putlongint(length(paras));
  2977. end;
  2978. procedure trtti_attribute.ppuload_subentries(ppufile: tcompilerppufile);
  2979. var
  2980. i : sizeint;
  2981. begin
  2982. for i:=0 to high(paras) do
  2983. paras[i]:=ppuloadnodetree(ppufile);
  2984. end;
  2985. procedure trtti_attribute.ppuwrite_subentries(ppufile: tcompilerppufile);
  2986. var
  2987. i : sizeint;
  2988. begin
  2989. for i:=0 to high(paras) do
  2990. ppuwritenodetree(ppufile,paras[i]);
  2991. end;
  2992. destructor trtti_attribute.destroy;
  2993. var
  2994. n : tnode;
  2995. begin
  2996. constructorcall.free;
  2997. for n in paras do
  2998. n.free;
  2999. inherited destroy;
  3000. end;
  3001. procedure trtti_attribute.buildderef;
  3002. var
  3003. i : sizeint;
  3004. begin
  3005. typesymderef.build(typesym);
  3006. typeconstrderef.build(typeconstr);
  3007. for i:=0 to high(paras) do
  3008. paras[i].buildderefimpl;
  3009. end;
  3010. procedure trtti_attribute.deref;
  3011. var
  3012. i : sizeint;
  3013. begin
  3014. typesym:=tsym(typesymderef.resolve);
  3015. typeconstr:=tdef(typeconstrderef.resolve);
  3016. for i:=0 to high(paras) do
  3017. paras[i].derefimpl;
  3018. end;
  3019. class procedure trtti_attribute_list.bind(var dangling,owned:trtti_attribute_list);
  3020. begin
  3021. if assigned(owned) then
  3022. internalerror(2019071001);
  3023. if not assigned(dangling) then
  3024. exit;
  3025. if dangling.is_bound then
  3026. internalerror(2019071002);
  3027. current_module.used_rtti_attrs.concatlistcopy(dangling.rtti_attributes);
  3028. dangling.is_bound:=true;
  3029. owned:=dangling;
  3030. dangling:=nil;
  3031. end;
  3032. class procedure trtti_attribute_list.copyandbind(alist : trtti_attribute_list; var owned: trtti_attribute_list);
  3033. var
  3034. i,j : Integer;
  3035. attr,newattribute : trtti_attribute;
  3036. begin
  3037. if owned=Nil then
  3038. owned:=trtti_attribute_list.Create;
  3039. owned.is_bound:=True;
  3040. for i:=0 to aList.rtti_attributes.Count-1 do
  3041. begin
  3042. attr:=trtti_attribute(alist.rtti_attributes[i]);
  3043. newattribute:=trtti_attribute.Create;
  3044. newattribute.typesym:=attr.typesym;
  3045. newattribute.typeconstr:=attr.typeconstr;
  3046. newattribute.constructorcall:=attr.constructorcall.getcopy;
  3047. setlength(newattribute.paras,length(attr.paras));
  3048. for j:=0 to length(attr.paras)-1 do
  3049. newattribute.paras[j]:=attr.paras[j].getcopy;
  3050. owned.AddAttribute(newattribute);
  3051. end;
  3052. current_module.used_rtti_attrs.concatlistcopy(owned.rtti_attributes);
  3053. end;
  3054. procedure trtti_attribute_list.addattribute(atypesym:tsym;typeconstr:tdef;constructorcall:tnode;constref paras:array of tnode);
  3055. var
  3056. newattribute : trtti_attribute;
  3057. i : sizeint;
  3058. begin
  3059. if not assigned(rtti_attributes) then
  3060. rtti_attributes:=TFPObjectList.Create(true);
  3061. newattribute:=trtti_attribute.Create;
  3062. newattribute.typesym:=atypesym;
  3063. newattribute.typeconstr:=typeconstr;
  3064. newattribute.constructorcall:=constructorcall;
  3065. setlength(newattribute.paras,length(paras));
  3066. for i:=0 to high(paras) do
  3067. newattribute.paras[i]:=paras[i];
  3068. rtti_attributes.Add(newattribute);
  3069. end;
  3070. procedure trtti_attribute_list.addattribute(attr:trtti_attribute);
  3071. begin
  3072. if not assigned(rtti_attributes) then
  3073. rtti_attributes:=TFPObjectList.Create(true);
  3074. rtti_attributes.add(attr);
  3075. end;
  3076. destructor trtti_attribute_list.destroy;
  3077. begin
  3078. rtti_attributes.Free;
  3079. inherited destroy;
  3080. end;
  3081. function trtti_attribute_list.get_attribute_count:longint;
  3082. begin
  3083. if assigned(rtti_attributes) then
  3084. result:=rtti_attributes.Count
  3085. else
  3086. result:=0;
  3087. end;
  3088. procedure trtti_attribute_list.buildderef;
  3089. var
  3090. i : sizeint;
  3091. begin
  3092. if not assigned(rtti_attributes) then
  3093. exit;
  3094. for i:=0 to rtti_attributes.count-1 do
  3095. trtti_attribute(rtti_attributes[i]).buildderef;
  3096. end;
  3097. procedure trtti_attribute_list.deref;
  3098. var
  3099. i : sizeint;
  3100. begin
  3101. if not assigned(rtti_attributes) then
  3102. exit;
  3103. for i:=0 to rtti_attributes.count-1 do
  3104. trtti_attribute(rtti_attributes[i]).deref;
  3105. end;
  3106. class procedure trtti_attribute_list.ppuload_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3107. var
  3108. i : sizeint;
  3109. begin
  3110. if assigned(attrlist) then
  3111. begin
  3112. if not assigned(attrlist.rtti_attributes) then
  3113. internalerror(2019071101);
  3114. for i:=0 to attrlist.rtti_attributes.count-1 do
  3115. trtti_attribute(attrlist.rtti_attributes[i]).ppuload_subentries(ppufile);
  3116. end;
  3117. end;
  3118. class procedure trtti_attribute_list.ppuwrite_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3119. var
  3120. i : sizeint;
  3121. begin
  3122. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  3123. begin
  3124. for i:=0 to attrlist.rtti_attributes.count-1 do
  3125. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite_subentries(ppufile);
  3126. end;
  3127. end;
  3128. class function trtti_attribute_list.ppuload(ppufile:tcompilerppufile):trtti_attribute_list;
  3129. var
  3130. cnt,i : longint;
  3131. begin
  3132. cnt:=ppufile.getlongint;
  3133. if cnt>0 then
  3134. begin
  3135. result:=trtti_attribute_list.create;
  3136. for i:=0 to cnt-1 do
  3137. result.addattribute(trtti_attribute.ppuload(ppufile));
  3138. end
  3139. else
  3140. result:=nil;
  3141. end;
  3142. class procedure trtti_attribute_list.ppuwrite(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3143. var
  3144. i : longint;
  3145. begin
  3146. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  3147. begin
  3148. ppufile.putlongint(attrlist.rtti_attributes.count);
  3149. for i:=0 to attrlist.rtti_attributes.count-1 do
  3150. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite(ppufile);
  3151. end
  3152. else
  3153. ppufile.putlongint(0);
  3154. end;
  3155. {****************************************************************************
  3156. TORDDEF
  3157. ****************************************************************************}
  3158. constructor torddef.create(t : tordtype;v,b : TConstExprInt; doregister: boolean);
  3159. begin
  3160. inherited create(orddef,doregister);
  3161. low:=v;
  3162. high:=b;
  3163. ordtype:=t;
  3164. setsize;
  3165. end;
  3166. constructor torddef.ppuload(ppufile:tcompilerppufile);
  3167. begin
  3168. inherited ppuload(orddef,ppufile);
  3169. ordtype:=tordtype(ppufile.getbyte);
  3170. low:=ppufile.getexprint;
  3171. high:=ppufile.getexprint;
  3172. setsize;
  3173. ppuload_platform(ppufile);
  3174. end;
  3175. function torddef.getcopy : tstoreddef;
  3176. begin
  3177. result:=corddef.create(ordtype,low,high,true);
  3178. result.typ:=orddef;
  3179. torddef(result).low:=low;
  3180. torddef(result).high:=high;
  3181. torddef(result).ordtype:=ordtype;
  3182. torddef(result).savesize:=savesize;
  3183. end;
  3184. function torddef.alignment:shortint;
  3185. begin
  3186. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) and
  3187. (ordtype in [s64bit,u64bit]) then
  3188. result := 4
  3189. else
  3190. result := inherited alignment;
  3191. end;
  3192. procedure torddef.setsize;
  3193. const
  3194. sizetbl : array[tordtype] of longint = (
  3195. 0,
  3196. 1,2,4,8,16,
  3197. 1,2,4,8,16,
  3198. 1,1,2,4,8,
  3199. 1,2,4,8,
  3200. 1,2,8,system.high(longint)
  3201. );
  3202. begin
  3203. savesize:=sizetbl[ordtype];
  3204. if savesize=system.high(longint) then
  3205. savesize:=packedbitsize div 8;
  3206. end;
  3207. function torddef.packedbitsize: asizeint;
  3208. var
  3209. sizeval: tconstexprint;
  3210. power: longint;
  3211. begin
  3212. result := 0;
  3213. if ordtype = uvoid then
  3214. exit;
  3215. {$ifndef cpu64bitalu}
  3216. if (ordtype in [s64bit,u64bit]) then
  3217. {$else not cpu64bitalu}
  3218. if ((ordtype = u64bit) and
  3219. (high > system.high(int64))) or
  3220. ((ordtype = s64bit) and
  3221. ((low <= (system.low(int64) div 2)) or
  3222. ((low < 0) and
  3223. (high > (system.high(int64) div 2))))) then
  3224. {$endif cpu64bitalu}
  3225. result := 64
  3226. else if (
  3227. (low >= 0) and
  3228. (high <= 1)
  3229. ) or (
  3230. ordtype in [pasbool1,pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit]
  3231. ) then
  3232. result := 1
  3233. else
  3234. begin
  3235. if (low>=0) then
  3236. sizeval:=high
  3237. else
  3238. { don't count 0 twice, but take into account that range goes from -n-1..n }
  3239. sizeval:=(cutils.max(-low,high+1)*2)-1;
  3240. { 256 must become 512 etc. }
  3241. nextpowerof2(sizeval+1,power);
  3242. result := power;
  3243. end;
  3244. end;
  3245. function torddef.getvardef : longint;
  3246. const
  3247. basetype2vardef : array[tordtype] of longint = (
  3248. varUndefined,
  3249. varbyte,varword,varlongword,varqword,varUndefined,
  3250. varshortint,varsmallint,varinteger,varint64,varUndefined,
  3251. varboolean,varboolean,varboolean,varboolean,varboolean,
  3252. varboolean,varboolean,varUndefined,varUndefined,
  3253. varUndefined,varUndefined,varCurrency,varEmpty);
  3254. begin
  3255. result:=basetype2vardef[ordtype];
  3256. if result=varEmpty then
  3257. result:=basetype2vardef[range_to_basetype(low,high)];
  3258. end;
  3259. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  3260. begin
  3261. inherited ppuwrite(ppufile);
  3262. ppufile.putbyte(byte(ordtype));
  3263. ppufile.putexprint(low);
  3264. ppufile.putexprint(high);
  3265. writeentry(ppufile,iborddef);
  3266. end;
  3267. function torddef.is_publishable : tpublishproperty;
  3268. begin
  3269. if ordtype<>uvoid then
  3270. is_publishable:=pp_publish
  3271. else
  3272. is_publishable:=pp_error;
  3273. end;
  3274. function torddef.GetTypeName : string;
  3275. const
  3276. names : array[tordtype] of string[20] = (
  3277. 'untyped',
  3278. 'Byte','Word','DWord','QWord','UInt128',
  3279. 'ShortInt','SmallInt','LongInt','Int64','Int128',
  3280. 'Boolean','Boolean8','Boolean16','Boolean32','Boolean64',
  3281. 'ByteBool','WordBool','LongBool','QWordBool',
  3282. 'AnsiChar','WideChar','Currency','CustomRange');
  3283. begin
  3284. GetTypeName:=names[ordtype];
  3285. end;
  3286. {****************************************************************************
  3287. TFLOATDEF
  3288. ****************************************************************************}
  3289. constructor tfloatdef.create(t: tfloattype; doregister: boolean);
  3290. begin
  3291. inherited create(floatdef,doregister);
  3292. floattype:=t;
  3293. setsize;
  3294. end;
  3295. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  3296. begin
  3297. inherited ppuload(floatdef,ppufile);
  3298. floattype:=tfloattype(ppufile.getbyte);
  3299. setsize;
  3300. ppuload_platform(ppufile);
  3301. end;
  3302. function tfloatdef.getcopy : tstoreddef;
  3303. begin
  3304. result:=cfloatdef.create(floattype,true);
  3305. result.typ:=floatdef;
  3306. tfloatdef(result).savesize:=savesize;
  3307. end;
  3308. function tfloatdef.alignment:shortint;
  3309. begin
  3310. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) then
  3311. case floattype of
  3312. sc80real,
  3313. s80real: result:=16;
  3314. s64real,
  3315. s64currency,
  3316. s64comp : result:=4;
  3317. else
  3318. result := inherited alignment;
  3319. end
  3320. else
  3321. result := inherited alignment;
  3322. end;
  3323. function tfloatdef.structalignment: shortint;
  3324. begin
  3325. { aix is really annoying: the recommended scalar alignment for both
  3326. int64 and double is 64 bits, but in structs int64 has to be aligned
  3327. to 8 bytes and double to 4 bytes }
  3328. if (target_info.system in systems_aix) and
  3329. (floattype=s64real) then
  3330. result:=4
  3331. else
  3332. result:=alignment;
  3333. end;
  3334. procedure tfloatdef.setsize;
  3335. begin
  3336. case floattype of
  3337. s32real : savesize:=4;
  3338. s80real : savesize:=10;
  3339. sc80real:
  3340. if target_info.system in [system_i386_darwin,
  3341. system_i386_iphonesim,system_x86_64_darwin,
  3342. system_x86_64_iphonesim,
  3343. system_x86_64_linux,system_x86_64_freebsd,
  3344. system_x86_64_openbsd,system_x86_64_netbsd,
  3345. system_x86_64_solaris,system_x86_64_embedded,
  3346. system_x86_64_dragonfly,system_x86_64_haiku] then
  3347. savesize:=16
  3348. else
  3349. savesize:=12;
  3350. s64real,
  3351. s64currency,
  3352. s64comp : savesize:=8;
  3353. else
  3354. savesize:=0;
  3355. end;
  3356. end;
  3357. function tfloatdef.getvardef : longint;
  3358. const
  3359. floattype2vardef : array[tfloattype] of longint = (
  3360. varSingle,varDouble,varUndefined,varUndefined,
  3361. varUndefined,varCurrency,varUndefined);
  3362. begin
  3363. if (upper(typename)='TDATETIME') and
  3364. assigned(owner) and
  3365. assigned(owner.name) and
  3366. (owner.name^='SYSTEM') then
  3367. result:=varDate
  3368. else
  3369. result:=floattype2vardef[floattype];
  3370. end;
  3371. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  3372. begin
  3373. inherited ppuwrite(ppufile);
  3374. ppufile.putbyte(byte(floattype));
  3375. writeentry(ppufile,ibfloatdef);
  3376. end;
  3377. function tfloatdef.is_publishable : tpublishproperty;
  3378. begin
  3379. is_publishable:=pp_publish;
  3380. end;
  3381. function tfloatdef.GetTypeName : string;
  3382. const
  3383. names : array[tfloattype] of string[20] = (
  3384. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  3385. begin
  3386. GetTypeName:=names[floattype];
  3387. end;
  3388. {****************************************************************************
  3389. TFILEDEF
  3390. ****************************************************************************}
  3391. constructor tfiledef.createtext;
  3392. begin
  3393. inherited create(filedef,true);
  3394. filetyp:=ft_text;
  3395. typedfiledef:=nil;
  3396. typedfiledefderef.reset;
  3397. end;
  3398. constructor tfiledef.createuntyped;
  3399. begin
  3400. inherited create(filedef,true);
  3401. filetyp:=ft_untyped;
  3402. typedfiledef:=nil;
  3403. end;
  3404. constructor tfiledef.createtyped(def:tdef);
  3405. begin
  3406. inherited create(filedef,true);
  3407. filetyp:=ft_typed;
  3408. typedfiledef:=def;
  3409. end;
  3410. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  3411. begin
  3412. inherited ppuload(filedef,ppufile);
  3413. filetyp:=tfiletyp(ppufile.getbyte);
  3414. if filetyp=ft_typed then
  3415. ppufile.getderef(typedfiledefderef)
  3416. else
  3417. typedfiledef:=nil;
  3418. ppuload_platform(ppufile);
  3419. end;
  3420. function tfiledef.getcopy : tstoreddef;
  3421. begin
  3422. case filetyp of
  3423. ft_typed:
  3424. result:=cfiledef.createtyped(typedfiledef);
  3425. ft_untyped:
  3426. result:=cfiledef.createuntyped;
  3427. ft_text:
  3428. result:=cfiledef.createtext;
  3429. end;
  3430. end;
  3431. procedure tfiledef.buildderef;
  3432. begin
  3433. inherited buildderef;
  3434. if filetyp=ft_typed then
  3435. typedfiledefderef.build(typedfiledef);
  3436. end;
  3437. procedure tfiledef.deref;
  3438. begin
  3439. inherited deref;
  3440. if filetyp=ft_typed then
  3441. typedfiledef:=tdef(typedfiledefderef.resolve);
  3442. end;
  3443. function tfiledef.size:asizeint;
  3444. begin
  3445. if savesize=0 then
  3446. setsize;
  3447. size:=savesize;
  3448. end;
  3449. procedure tfiledef.setsize;
  3450. begin
  3451. case filetyp of
  3452. ft_text:
  3453. savesize:=search_system_type('TEXTREC').typedef.size;
  3454. ft_typed:
  3455. begin
  3456. savesize:=search_system_type('FILEREC').typedef.size;
  3457. { allocate put/get buffer in iso mode }
  3458. if m_isolike_io in current_settings.modeswitches then
  3459. inc(savesize,typedfiledef.size);
  3460. end;
  3461. ft_untyped:
  3462. savesize:=search_system_type('FILEREC').typedef.size;
  3463. end;
  3464. end;
  3465. function tfiledef.alignment: shortint;
  3466. begin
  3467. case filetyp of
  3468. ft_text:
  3469. result:=search_system_type('TEXTREC').typedef.alignment;
  3470. ft_typed,
  3471. ft_untyped:
  3472. result:=search_system_type('FILEREC').typedef.alignment;
  3473. end;
  3474. end;
  3475. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  3476. begin
  3477. inherited ppuwrite(ppufile);
  3478. ppufile.putbyte(byte(filetyp));
  3479. if filetyp=ft_typed then
  3480. ppufile.putderef(typedfiledefderef);
  3481. writeentry(ppufile,ibfiledef);
  3482. end;
  3483. function tfiledef.GetTypeName : string;
  3484. begin
  3485. case filetyp of
  3486. ft_untyped:
  3487. GetTypeName:='File';
  3488. ft_typed:
  3489. GetTypeName:='File Of '+typedfiledef.typename;
  3490. ft_text:
  3491. GetTypeName:='Text'
  3492. end;
  3493. end;
  3494. function tfiledef.getmangledparaname : TSymStr;
  3495. begin
  3496. case filetyp of
  3497. ft_untyped:
  3498. getmangledparaname:='FILE';
  3499. ft_typed:
  3500. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  3501. ft_text:
  3502. getmangledparaname:='TEXT'
  3503. end;
  3504. end;
  3505. {****************************************************************************
  3506. TVARIANTDEF
  3507. ****************************************************************************}
  3508. constructor tvariantdef.create(v : tvarianttype);
  3509. begin
  3510. inherited create(variantdef,true);
  3511. varianttype:=v;
  3512. setsize;
  3513. end;
  3514. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  3515. begin
  3516. inherited ppuload(variantdef,ppufile);
  3517. varianttype:=tvarianttype(ppufile.getbyte);
  3518. setsize;
  3519. ppuload_platform(ppufile);
  3520. end;
  3521. function tvariantdef.getcopy : tstoreddef;
  3522. begin
  3523. result:=cvariantdef.create(varianttype);
  3524. end;
  3525. function tvariantdef.alignment: shortint;
  3526. begin
  3527. result:=search_system_type('TVARDATA').typedef.alignment;
  3528. end;
  3529. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  3530. begin
  3531. inherited ppuwrite(ppufile);
  3532. ppufile.putbyte(byte(varianttype));
  3533. writeentry(ppufile,ibvariantdef);
  3534. end;
  3535. function tvariantdef.getvardef : longint;
  3536. begin
  3537. Result:=varVariant;
  3538. end;
  3539. procedure tvariantdef.setsize;
  3540. begin
  3541. {$ifdef cpu64bitaddr}
  3542. savesize:=24;
  3543. {$else cpu64bitaddr}
  3544. savesize:=16;
  3545. {$endif cpu64bitaddr}
  3546. end;
  3547. function tvariantdef.GetTypeName : string;
  3548. begin
  3549. case varianttype of
  3550. vt_normalvariant:
  3551. GetTypeName:='Variant';
  3552. vt_olevariant:
  3553. GetTypeName:='OleVariant';
  3554. end;
  3555. end;
  3556. function tvariantdef.needs_inittable : boolean;
  3557. begin
  3558. needs_inittable:=true;
  3559. end;
  3560. function tvariantdef.is_publishable : tpublishproperty;
  3561. begin
  3562. is_publishable:=pp_publish;
  3563. end;
  3564. {****************************************************************************
  3565. TABSTRACtpointerdef
  3566. ****************************************************************************}
  3567. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  3568. begin
  3569. inherited create(dt,true);
  3570. pointeddef:=def;
  3571. pointeddefderef.reset;
  3572. if df_generic in pointeddef.defoptions then
  3573. include(defoptions,df_generic);
  3574. if df_specialization in pointeddef.defoptions then
  3575. include(defoptions,df_specialization);
  3576. end;
  3577. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3578. begin
  3579. inherited ppuload(dt,ppufile);
  3580. ppufile.getderef(pointeddefderef);
  3581. end;
  3582. procedure tabstractpointerdef.buildderef;
  3583. begin
  3584. inherited buildderef;
  3585. pointeddefderef.build(pointeddef);
  3586. end;
  3587. procedure tabstractpointerdef.deref;
  3588. begin
  3589. inherited deref;
  3590. pointeddef:=tdef(pointeddefderef.resolve);
  3591. end;
  3592. function tabstractpointerdef.size: asizeint;
  3593. begin
  3594. Result:=voidpointertype.size;
  3595. end;
  3596. function tabstractpointerdef.alignment: shortint;
  3597. begin
  3598. alignment:=size_2_align(voidpointertype.size);
  3599. end;
  3600. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3601. begin
  3602. inherited ppuwrite(ppufile);
  3603. ppufile.putderef(pointeddefderef);
  3604. end;
  3605. {****************************************************************************
  3606. tpointerdef
  3607. ****************************************************************************}
  3608. constructor tpointerdef.create(def:tdef);
  3609. begin
  3610. inherited create(pointerdef,def);
  3611. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  3612. if (df_specialization in tstoreddef(def).defoptions)
  3613. {$ifndef genericdef_for_nested}
  3614. { currently, nested procdefs of generic routines get df_specialization,
  3615. but no genericdef }
  3616. and assigned(tstoreddef(def).genericdef)
  3617. {$endif}
  3618. then
  3619. genericdef:=cpointerdef.getreusable(tstoreddef(def).genericdef);
  3620. end;
  3621. class function tpointerdef.getreusable(def: tdef): tpointerdef;
  3622. var
  3623. res: PHashSetItem;
  3624. oldsymtablestack: tsymtablestack;
  3625. begin
  3626. if not assigned(current_module) then
  3627. internalerror(2011071101);
  3628. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  3629. if not assigned(res^.Data) then
  3630. begin
  3631. { since these pointerdefs can be reused anywhere in the current
  3632. unit, add them to the global/staticsymtable (or local symtable
  3633. if they're a local def, because otherwise they'll be saved
  3634. to the ppu referencing a local symtable entry that doesn't
  3635. exist in the ppu) }
  3636. oldsymtablestack:=symtablestack;
  3637. { do not simply push/pop current_module.localsymtable, because
  3638. that can have side-effects (e.g., it removes helpers) }
  3639. symtablestack:=nil;
  3640. result:=cpointerdef.create(def);
  3641. setup_reusable_def(def,result,res,oldsymtablestack);
  3642. { res^.Data may still be nil -> don't overwrite result }
  3643. exit;
  3644. end;
  3645. result:=tpointerdef(res^.Data);
  3646. end;
  3647. class function tpointerdef.getreusable_no_free(def: tdef): tpointerdef;
  3648. begin
  3649. result:=getreusable(def);
  3650. if not result.is_registered then
  3651. include(result.defoptions,df_not_registered_no_free);
  3652. end;
  3653. function tpointerdef.size: asizeint;
  3654. begin
  3655. result:=sizeof(pint);
  3656. end;
  3657. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  3658. begin
  3659. inherited ppuload(pointerdef,ppufile);
  3660. has_pointer_math:=(ppufile.getbyte<>0);
  3661. ppuload_platform(ppufile);
  3662. end;
  3663. function tpointerdef.getcopy : tstoreddef;
  3664. begin
  3665. { don't use direct pointeddef if it is a forwarddef because in other case
  3666. one of them will be destroyed on forward type resolve and the second will
  3667. point to garbage }
  3668. if pointeddef.typ=forwarddef then
  3669. result:=cpointerdef.create(tforwarddef(pointeddef).getcopy)
  3670. else
  3671. result:=cpointerdef.create(pointeddef);
  3672. tpointerdef(result).has_pointer_math:=has_pointer_math;
  3673. tpointerdef(result).savesize:=savesize;
  3674. end;
  3675. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3676. begin
  3677. inherited ppuwrite(ppufile);
  3678. ppufile.putbyte(byte(has_pointer_math));
  3679. writeentry(ppufile,ibpointerdef);
  3680. end;
  3681. function tpointerdef.GetTypeName : string;
  3682. begin
  3683. { parameter types and the resultdef of a procvardef can contain a
  3684. pointer to this procvardef itself, resulting in endless recursion ->
  3685. use the typesym's name instead if it exists (if it doesn't, such as
  3686. for anynonymous procedure types in macpas/iso mode, then there cannot
  3687. be any recursive references to it either) }
  3688. if (pointeddef.typ<>procvardef) or
  3689. not assigned(pointeddef.typesym) then
  3690. GetTypeName:='^'+pointeddef.typename
  3691. else
  3692. GetTypeName:='^'+pointeddef.typesym.realname;
  3693. end;
  3694. function tpointerdef.pointer_arithmetic_int_type:tdef;
  3695. begin
  3696. result:=ptrsinttype;
  3697. end;
  3698. function tpointerdef.pointer_arithmetic_uint_type:tdef;
  3699. begin
  3700. result:=ptruinttype;
  3701. end;
  3702. function tpointerdef.pointer_subtraction_result_type:tdef;
  3703. begin
  3704. result:=ptrsinttype;
  3705. end;
  3706. function tpointerdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  3707. begin
  3708. result:=true;
  3709. end;
  3710. function tpointerdef.converted_pointer_to_array_range_type:tdef;
  3711. begin
  3712. result:=ptrsinttype;
  3713. end;
  3714. {****************************************************************************
  3715. TCLASSREFDEF
  3716. ****************************************************************************}
  3717. constructor tclassrefdef.create(def:tdef);
  3718. begin
  3719. while (def.typ=objectdef) and tobjectdef(def).is_unique_objpasdef do
  3720. def:=tobjectdef(def).childof;
  3721. inherited create(classrefdef,def);
  3722. if df_specialization in tstoreddef(def).defoptions then
  3723. genericdef:=cclassrefdef.create(tstoreddef(def).genericdef);
  3724. end;
  3725. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  3726. begin
  3727. inherited ppuload(classrefdef,ppufile);
  3728. ppuload_platform(ppufile);
  3729. end;
  3730. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  3731. begin
  3732. inherited ppuwrite(ppufile);
  3733. writeentry(ppufile,ibclassrefdef);
  3734. end;
  3735. function tclassrefdef.getcopy:tstoreddef;
  3736. begin
  3737. if pointeddef.typ=forwarddef then
  3738. result:=cclassrefdef.create(tforwarddef(pointeddef).getcopy)
  3739. else
  3740. result:=cclassrefdef.create(pointeddef);
  3741. end;
  3742. function tclassrefdef.GetTypeName : string;
  3743. begin
  3744. GetTypeName:='Class Of '+pointeddef.typesymbolprettyname;
  3745. end;
  3746. function tclassrefdef.is_publishable : tpublishproperty;
  3747. begin
  3748. is_publishable:=pp_publish;
  3749. end;
  3750. function tclassrefdef.rtti_mangledname(rt: trttitype): TSymStr;
  3751. begin
  3752. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  3753. result:=inherited rtti_mangledname(rt)
  3754. else
  3755. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  3756. end;
  3757. procedure tclassrefdef.register_created_object_type;
  3758. begin
  3759. tobjectdef(pointeddef).register_created_classref_type;
  3760. end;
  3761. {***************************************************************************
  3762. TSETDEF
  3763. ***************************************************************************}
  3764. constructor tsetdef.create(def: tdef; low, high: asizeint; doregister: boolean);
  3765. var
  3766. setallocbits: aint;
  3767. packedsavesize: aint;
  3768. actual_setalloc: ShortInt;
  3769. begin
  3770. inherited create(setdef,doregister);
  3771. elementdef:=def;
  3772. elementdefderef.reset;
  3773. setmax:=high;
  3774. setlow:=low;
  3775. actual_setalloc:=current_settings.setalloc;
  3776. {$if defined(cpu8bitalu) or defined(cpu16bitalu)}
  3777. if actual_setalloc=0 then
  3778. actual_setalloc:=1;
  3779. {$endif}
  3780. if (actual_setalloc=0) then
  3781. begin
  3782. setbase:=0;
  3783. if (high<32) then
  3784. savesize:=Sizeof(longint)
  3785. else if (high<256) then
  3786. savesize:=32
  3787. else
  3788. savesize:=(high+7) div 8
  3789. end
  3790. else
  3791. begin
  3792. setallocbits:=actual_setalloc*8;
  3793. setbase:=low and not(setallocbits-1);
  3794. packedsavesize:=actual_setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  3795. savesize:=packedsavesize;
  3796. {$if not defined(cpu8bitalu) and not defined(cpu16bitalu)}
  3797. if savesize=3 then
  3798. savesize:=4;
  3799. {$endif}
  3800. end;
  3801. end;
  3802. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  3803. begin
  3804. inherited ppuload(setdef,ppufile);
  3805. ppufile.getderef(elementdefderef);
  3806. savesize:=ppufile.getasizeint;
  3807. setbase:=ppufile.getasizeint;
  3808. setlow:=ppufile.getasizeint;
  3809. setmax:=ppufile.getasizeint;
  3810. ppuload_platform(ppufile);
  3811. end;
  3812. function tsetdef.getcopy : tstoreddef;
  3813. begin
  3814. result:=csetdef.create(elementdef,setbase,setmax,true);
  3815. { the copy might have been created with a different setalloc setting }
  3816. tsetdef(result).savesize:=savesize;
  3817. end;
  3818. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  3819. begin
  3820. inherited ppuwrite(ppufile);
  3821. ppufile.putderef(elementdefderef);
  3822. ppufile.putasizeint(savesize);
  3823. ppufile.putasizeint(setbase);
  3824. ppufile.putasizeint(setlow);
  3825. ppufile.putasizeint(setmax);
  3826. writeentry(ppufile,ibsetdef);
  3827. end;
  3828. procedure tsetdef.buildderef;
  3829. begin
  3830. inherited buildderef;
  3831. elementdefderef.build(elementdef);
  3832. end;
  3833. procedure tsetdef.deref;
  3834. begin
  3835. inherited deref;
  3836. elementdef:=tdef(elementdefderef.resolve);
  3837. end;
  3838. function tsetdef.is_publishable : tpublishproperty;
  3839. begin
  3840. if savesize in [1,2,4] then
  3841. is_publishable:=pp_publish
  3842. else
  3843. is_publishable:=pp_error;
  3844. end;
  3845. function tsetdef.alignment: shortint;
  3846. begin
  3847. Result:=inherited;
  3848. if result>sizeof(aint) then
  3849. result:=sizeof(aint);
  3850. end;
  3851. function tsetdef.GetTypeName : string;
  3852. begin
  3853. if assigned(elementdef) then
  3854. GetTypeName:='Set Of '+elementdef.typename
  3855. else
  3856. GetTypeName:='Empty Set';
  3857. end;
  3858. {***************************************************************************
  3859. TFORMALDEF
  3860. ***************************************************************************}
  3861. constructor tformaldef.create(Atyped:boolean);
  3862. begin
  3863. inherited create(formaldef,true);
  3864. typed:=Atyped;
  3865. savesize:=0;
  3866. end;
  3867. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  3868. begin
  3869. inherited ppuload(formaldef,ppufile);
  3870. typed:=boolean(ppufile.getbyte);
  3871. savesize:=0;
  3872. ppuload_platform(ppufile);
  3873. end;
  3874. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  3875. begin
  3876. inherited ppuwrite(ppufile);
  3877. ppufile.putbyte(byte(typed));
  3878. writeentry(ppufile,ibformaldef);
  3879. end;
  3880. function tformaldef.GetTypeName : string;
  3881. begin
  3882. if typed then
  3883. GetTypeName:='<Typed formal type>'
  3884. else
  3885. GetTypeName:='<Formal type>';
  3886. end;
  3887. {***************************************************************************
  3888. TARRAYDEF
  3889. ***************************************************************************}
  3890. constructor tarraydef.create(l, h: asizeint; def: tdef);
  3891. begin
  3892. inherited create(arraydef,true);
  3893. lowrange:=l;
  3894. highrange:=h;
  3895. rangedef:=def;
  3896. rangedefderef.reset;
  3897. _elementdef:=nil;
  3898. _elementdefderef.reset;
  3899. arrayoptions:=[];
  3900. symtable:=tarraysymtable.create(self);
  3901. end;
  3902. constructor tarraydef.create_vector(l ,h: asizeint; def: tdef);
  3903. begin
  3904. self.create(l,h,def);
  3905. include(arrayoptions,ado_IsVector);
  3906. end;
  3907. constructor tarraydef.create_openarray;
  3908. begin
  3909. self.create(0,-1,sizesinttype);
  3910. include(arrayoptions,ado_OpenArray);
  3911. end;
  3912. class function tarraydef.getreusable_intern(def: tdef; elems: asizeint; const options: tarraydefoptions): tarraydef;
  3913. var
  3914. res: PHashSetItem;
  3915. oldsymtablestack: tsymtablestack;
  3916. arrdesc: packed record
  3917. def: tdef;
  3918. elecount: asizeint;
  3919. options: tarraydefoptions
  3920. end;
  3921. begin
  3922. if not assigned(current_module) then
  3923. internalerror(2011081301);
  3924. arrdesc.def:=def;
  3925. arrdesc.elecount:=elems;
  3926. arrdesc.options:=options;
  3927. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  3928. if not assigned(res^.Data) then
  3929. begin
  3930. { since these pointerdefs can be reused anywhere in the current
  3931. unit, add them to the global/staticsymtable (or local symtable
  3932. if they're a local def, because otherwise they'll be saved
  3933. to the ppu referencing a local symtable entry that doesn't
  3934. exist in the ppu) }
  3935. oldsymtablestack:=symtablestack;
  3936. { do not simply push/pop current_module.localsymtable, because
  3937. that can have side-effects (e.g., it removes helpers) }
  3938. symtablestack:=nil;
  3939. result:=carraydef.create(0,elems-1,sizesinttype);
  3940. result.elementdef:=def;
  3941. result.arrayoptions:=options;
  3942. setup_reusable_def(def,result,res,oldsymtablestack);
  3943. { res^.Data may still be nil -> don't overwrite result }
  3944. exit;
  3945. end;
  3946. result:=tarraydef(res^.Data);
  3947. end;
  3948. class function tarraydef.getreusable(def: tdef; elems: asizeint): tarraydef;
  3949. begin
  3950. result:=getreusable_intern(def,elems,[]);
  3951. end;
  3952. class function tarraydef.getreusable_vector(def: tdef; elems: asizeint): tarraydef;
  3953. begin
  3954. result:=getreusable_intern(def,elems,[ado_IsVector]);
  3955. end;
  3956. class function tarraydef.getreusable_no_free(def: tdef; elems: asizeint): tarraydef;
  3957. begin
  3958. result:=getreusable(def,elems);
  3959. if not result.is_registered then
  3960. include(result.defoptions,df_not_registered_no_free);
  3961. end;
  3962. class function tarraydef.getreusable_no_free_vector(def: tdef; elems: asizeint): tarraydef;
  3963. begin
  3964. result:=getreusable_vector(def,elems);
  3965. if not result.is_registered then
  3966. include(result.defoptions,df_not_registered_no_free);
  3967. end;
  3968. destructor tarraydef.destroy;
  3969. begin
  3970. symtable.free;
  3971. symtable:=nil;
  3972. inherited;
  3973. end;
  3974. constructor tarraydef.create_from_pointer(def:tpointerdef);
  3975. begin
  3976. { divide by the element size and do -1 so the array will have a valid size,
  3977. further, the element size might be 0 e.g. for empty records, so use max(...,1)
  3978. to avoid a division by zero }
  3979. self.create(0,(high(asizeint) div max(def.pointeddef.size,1))-1,
  3980. def.converted_pointer_to_array_range_type);
  3981. arrayoptions:=[ado_IsConvertedPointer];
  3982. setelementdef(def.pointeddef);
  3983. end;
  3984. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  3985. begin
  3986. inherited ppuload(arraydef,ppufile);
  3987. { the addresses are calculated later }
  3988. ppufile.getderef(_elementdefderef);
  3989. ppufile.getderef(rangedefderef);
  3990. lowrange:=ppufile.getasizeint;
  3991. highrange:=ppufile.getasizeint;
  3992. ppufile.getset(tppuset2(arrayoptions));
  3993. ppuload_platform(ppufile);
  3994. symtable:=tarraysymtable.create(self);
  3995. tarraysymtable(symtable).ppuload(ppufile)
  3996. end;
  3997. function tarraydef.getcopy : tstoreddef;
  3998. begin
  3999. result:=carraydef.create(lowrange,highrange,rangedef);
  4000. tarraydef(result).arrayoptions:=arrayoptions;
  4001. tarraydef(result)._elementdef:=_elementdef;
  4002. end;
  4003. procedure tarraydef.buildderef;
  4004. begin
  4005. inherited buildderef;
  4006. tarraysymtable(symtable).buildderef;
  4007. _elementdefderef.build(_elementdef);
  4008. rangedefderef.build(rangedef);
  4009. end;
  4010. procedure tarraydef.deref;
  4011. begin
  4012. inherited deref;
  4013. tarraysymtable(symtable).deref(false);
  4014. _elementdef:=tdef(_elementdefderef.resolve);
  4015. rangedef:=tdef(rangedefderef.resolve);
  4016. end;
  4017. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  4018. begin
  4019. inherited ppuwrite(ppufile);
  4020. ppufile.putderef(_elementdefderef);
  4021. ppufile.putderef(rangedefderef);
  4022. ppufile.putasizeint(lowrange);
  4023. ppufile.putasizeint(highrange);
  4024. ppufile.putset(tppuset2(arrayoptions));
  4025. writeentry(ppufile,ibarraydef);
  4026. tarraysymtable(symtable).ppuwrite(ppufile);
  4027. end;
  4028. function tarraydef.elesize : asizeint;
  4029. begin
  4030. if (ado_IsBitPacked in arrayoptions) then
  4031. internalerror(2006080101);
  4032. if assigned(_elementdef) then
  4033. result:=_elementdef.size
  4034. else
  4035. result:=0;
  4036. end;
  4037. function tarraydef.elepackedbitsize : asizeint;
  4038. begin
  4039. if not(ado_IsBitPacked in arrayoptions) then
  4040. internalerror(2006080102);
  4041. if assigned(_elementdef) then
  4042. result:=_elementdef.packedbitsize
  4043. else
  4044. result:=0;
  4045. end;
  4046. function tarraydef.elecount : asizeuint;
  4047. var
  4048. qhigh,qlow : qword;
  4049. begin
  4050. if ado_IsDynamicArray in arrayoptions then
  4051. begin
  4052. result:=0;
  4053. exit;
  4054. end;
  4055. { check whether the range might be larger than high(asizeint). Has
  4056. to include 0..high(sizeint), since that's high(sizeint)+1 elements }
  4057. if (highrange>=0) and (lowrange<=0) then
  4058. begin
  4059. qhigh:=highrange;
  4060. if lowrange=low(asizeint) then
  4061. qlow:=high(asizeint) + 1
  4062. else
  4063. qlow:=qword(-lowrange);
  4064. { prevent overflow, return 0 to indicate overflow }
  4065. if qhigh+qlow>qword(high(asizeint)-1) then
  4066. result:=0
  4067. else
  4068. result:=qhigh+qlow+1;
  4069. end
  4070. else
  4071. result:=int64(highrange)-lowrange+1;
  4072. end;
  4073. function tarraydef.size : asizeint;
  4074. var
  4075. cachedelecount : asizeuint;
  4076. cachedelesize : asizeint;
  4077. begin
  4078. if ado_IsDynamicArray in arrayoptions then
  4079. begin
  4080. size:=voidpointertype.size;
  4081. exit;
  4082. end;
  4083. { Tarraydef.size may never be called for an open array! }
  4084. if ado_OpenArray in arrayoptions then
  4085. internalerror(99080501);
  4086. if not (ado_IsBitPacked in arrayoptions) then
  4087. cachedelesize:=elesize
  4088. else
  4089. cachedelesize := elepackedbitsize;
  4090. cachedelecount:=elecount;
  4091. if (cachedelesize = 0) then
  4092. begin
  4093. size := 0;
  4094. exit;
  4095. end;
  4096. if (cachedelecount = 0) then
  4097. begin
  4098. if ado_isconststring in arrayoptions then
  4099. size := 0
  4100. else
  4101. size := -1;
  4102. exit;
  4103. end;
  4104. { prevent overflow, return -1 to indicate overflow }
  4105. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  4106. if (cachedelecount > asizeuint(high(asizeint))) or
  4107. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  4108. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  4109. accessing the array, see ncgmem (PFV) }
  4110. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  4111. begin
  4112. result:=-1;
  4113. exit;
  4114. end;
  4115. result:=cachedelesize*asizeint(cachedelecount);
  4116. if (ado_IsBitPacked in arrayoptions) then
  4117. { can't just add 7 and divide by 8, because that may overflow }
  4118. result:=result div 8 + ord((result mod 8)<>0);
  4119. {$ifdef cpu16bitaddr}
  4120. if result>65535 then
  4121. begin
  4122. result:=-1;
  4123. exit;
  4124. end;
  4125. {$endif cpu16bitaddr}
  4126. end;
  4127. procedure tarraydef.setelementdef(def:tdef);
  4128. begin
  4129. _elementdef:=def;
  4130. if not(
  4131. (ado_IsDynamicArray in arrayoptions) or
  4132. (ado_IsConvertedPointer in arrayoptions) or
  4133. (ado_IsConstructor in arrayoptions) or
  4134. (ado_IsGeneric in arrayoptions) or
  4135. (highrange<lowrange)
  4136. ) and
  4137. (size=-1) then
  4138. Message(sym_e_segment_too_large);
  4139. end;
  4140. function tarraydef.alignment : shortint;
  4141. begin
  4142. if ado_IsVector in arrayoptions then
  4143. alignment:=size
  4144. { alignment of dyn. arrays doesn't depend on the element size }
  4145. else if ado_IsDynamicArray in arrayoptions then
  4146. alignment:=voidpointertype.alignment
  4147. { alignment is the target alignment for the used load size }
  4148. else if (ado_IsBitPacked in arrayoptions) and
  4149. (elementdef.typ in [enumdef,orddef]) then
  4150. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  4151. { alignment is the alignment of the elements }
  4152. else
  4153. alignment:=elementdef.alignment
  4154. end;
  4155. function tarraydef.needs_inittable : boolean;
  4156. begin
  4157. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  4158. end;
  4159. function tarraydef.needs_separate_initrtti : boolean;
  4160. begin
  4161. if ado_IsBitPacked in arrayoptions then
  4162. result:=false
  4163. else
  4164. result:=elementdef.needs_separate_initrtti;
  4165. end;
  4166. function tarraydef.GetTypeName : string;
  4167. begin
  4168. if (ado_IsConstString in arrayoptions) then
  4169. result:='Constant String'
  4170. else if (ado_isarrayofconst in arrayoptions) or
  4171. (ado_isConstructor in arrayoptions) then
  4172. begin
  4173. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  4174. GetTypeName:='Array Of Const'
  4175. else
  4176. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  4177. end
  4178. else if (ado_IsDynamicArray in arrayoptions) then
  4179. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  4180. else if (ado_OpenArray in arrayoptions) then
  4181. GetTypeName:='{Open} Array Of '+elementdef.typename
  4182. else
  4183. begin
  4184. result := '';
  4185. if (ado_IsBitPacked in arrayoptions) then
  4186. result:='BitPacked ';
  4187. if rangedef.typ=enumdef then
  4188. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  4189. else
  4190. result:=result+'Array['+tostr(lowrange)+'..'+
  4191. tostr(highrange)+'] Of '+elementdef.typename
  4192. end;
  4193. end;
  4194. function tarraydef.getmangledparaname : TSymStr;
  4195. begin
  4196. if ado_isarrayofconst in arrayoptions then
  4197. getmangledparaname:='array_of_const'
  4198. else
  4199. if ((highrange=-1) and (lowrange=0)) then
  4200. getmangledparaname:='array_of_'+elementdef.mangledparaname
  4201. else
  4202. internalerror(200204176);
  4203. end;
  4204. function tarraydef.is_publishable : tpublishproperty;
  4205. begin
  4206. if ado_IsDynamicArray in arrayoptions then
  4207. is_publishable:=pp_publish
  4208. else
  4209. is_publishable:=pp_error;
  4210. end;
  4211. function tarraydef.is_hwvector: boolean;
  4212. begin
  4213. result:=ado_IsVector in arrayoptions;
  4214. end;
  4215. {***************************************************************************
  4216. tabstractrecorddef
  4217. ***************************************************************************}
  4218. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp;doregister:boolean);
  4219. begin
  4220. inherited create(dt,doregister);
  4221. objname:=stringdup(upper(n));
  4222. objrealname:=stringdup(n);
  4223. objectoptions:=[];
  4224. if assigned(current_module.namespace) then
  4225. begin
  4226. import_lib:=stringdup(current_module.namespace^);
  4227. replace(import_lib^,'.','/');
  4228. end;
  4229. end;
  4230. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  4231. var
  4232. ro: trtti_option;
  4233. begin
  4234. inherited ppuload(dt,ppufile);
  4235. objrealname:=ppufile.getpshortstring;
  4236. objname:=stringdup(upper(objrealname^));
  4237. import_lib:=ppufile.getpshortstring;
  4238. { only used for external C++ classes and Java classes/records }
  4239. if (import_lib^='') then
  4240. stringdispose(import_lib);
  4241. ppufile.getset(tppuset4(objectoptions));
  4242. rtti.clause:=trtti_clause(ppufile.getbyte);
  4243. for ro in trtti_option do
  4244. ppufile.getset(tppuset1(rtti.options[ro]));
  4245. end;
  4246. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  4247. var
  4248. ro: trtti_option;
  4249. begin
  4250. inherited ppuwrite(ppufile);
  4251. ppufile.putstring(objrealname^);
  4252. if assigned(import_lib) then
  4253. ppufile.putstring(import_lib^)
  4254. else
  4255. ppufile.putstring('');
  4256. ppufile.putset(tppuset4(objectoptions));
  4257. ppufile.putbyte(byte(rtti.clause));
  4258. for ro in trtti_option do
  4259. ppufile.putset(tppuset1(rtti.options[ro]));
  4260. end;
  4261. destructor tabstractrecorddef.destroy;
  4262. begin
  4263. stringdispose(objname);
  4264. stringdispose(objrealname);
  4265. stringdispose(import_lib);
  4266. tcinitcode.free;
  4267. inherited destroy;
  4268. end;
  4269. procedure tabstractrecorddef.buildderefimpl;
  4270. begin
  4271. inherited buildderefimpl;
  4272. if not (df_copied_def in defoptions) then
  4273. tstoredsymtable(symtable).buildderefimpl;
  4274. end;
  4275. procedure tabstractrecorddef.derefimpl;
  4276. begin
  4277. inherited derefimpl;
  4278. if not (df_copied_def in defoptions) then
  4279. tstoredsymtable(symtable).derefimpl(false);
  4280. end;
  4281. procedure tabstractrecorddef.check_forwards;
  4282. begin
  4283. { the defs of a copied def are defined for the original type only }
  4284. if not(df_copied_def in defoptions) then
  4285. tstoredsymtable(symtable).check_forwards;
  4286. end;
  4287. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  4288. var
  4289. i: longint;
  4290. sym: tsym;
  4291. begin
  4292. for i:=0 to symtable.SymList.Count-1 do
  4293. begin
  4294. sym:=tsym(symtable.SymList[i]);
  4295. if sym.typ=procsym then
  4296. begin
  4297. result:=tprocsym(sym).find_procdef_bytype(pt);
  4298. if assigned(result) then
  4299. exit;
  4300. end;
  4301. end;
  4302. result:=nil;
  4303. end;
  4304. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  4305. begin
  4306. if t=gs_record then
  4307. GetSymtable:=symtable
  4308. else
  4309. GetSymtable:=nil;
  4310. end;
  4311. function tabstractrecorddef.is_packed:boolean;
  4312. begin
  4313. result:=tabstractrecordsymtable(symtable).is_packed;
  4314. end;
  4315. function tabstractrecorddef.RttiName: string;
  4316. function generate_full_paramname(maxlength:longint):string;
  4317. const
  4318. commacount : array[boolean] of longint = (0,1);
  4319. var
  4320. fullparas,
  4321. paramname : ansistring;
  4322. module : tmodule;
  4323. sym : tsym;
  4324. def : tdef;
  4325. i : longint;
  4326. begin
  4327. { we want at least enough space for an ellipsis }
  4328. if maxlength<3 then
  4329. internalerror(2014121203);
  4330. fullparas:='';
  4331. for i:=0 to genericparas.count-1 do
  4332. begin
  4333. sym:=tsym(genericparas[i]);
  4334. module:=find_module_from_symtable(sym.owner);
  4335. if not assigned(module) then
  4336. internalerror(2014121202);
  4337. if not (sym.typ in [constsym,symconst.typesym]) then
  4338. internalerror(2020042501);
  4339. if sym.typ=constsym then
  4340. def:=tconstsym(sym).constdef
  4341. else
  4342. def:=ttypesym(sym).typedef;
  4343. paramname:=module.realmodulename^;
  4344. if def.typ in [objectdef,recorddef] then
  4345. paramname:=paramname+'.'+tabstractrecorddef(def).rttiname
  4346. else
  4347. paramname:=paramname+'.'+def.typename;
  4348. if length(fullparas)+commacount[i>0]+length(paramname)>maxlength then
  4349. begin
  4350. if i>0 then
  4351. fullparas:=fullparas+',...'
  4352. else
  4353. fullparas:=fullparas+'...';
  4354. break;
  4355. end;
  4356. { could we fit an ellipsis after this parameter if it should be too long? }
  4357. if (maxlength-(length(fullparas)+commacount[i>0]+length(paramname))<4) and (i<genericparas.count-1) then
  4358. begin
  4359. { then omit already this parameter }
  4360. if i>0 then
  4361. fullparas:=fullparas+',...'
  4362. else
  4363. fullparas:=fullparas+'...';
  4364. break;
  4365. end;
  4366. if i>0 then
  4367. fullparas:=fullparas+',';
  4368. fullparas:=fullparas+paramname;
  4369. end;
  4370. result:=fullparas;
  4371. end;
  4372. var
  4373. nongeneric,
  4374. basename : string;
  4375. i,
  4376. remlength,
  4377. paramcount,
  4378. crcidx : longint;
  4379. begin
  4380. if rttistring='' then
  4381. begin
  4382. if is_specialization then
  4383. begin
  4384. rttistring:=OwnerHierarchyName;
  4385. { there should be two $ characters, one before the CRC and one before the count }
  4386. crcidx:=-1;
  4387. for i:=length(objrealname^) downto 1 do
  4388. if objrealname^[i]='$' then
  4389. begin
  4390. crcidx:=i;
  4391. break;
  4392. end;
  4393. if crcidx<0 then
  4394. internalerror(2014121201);
  4395. basename:=copy(objrealname^,1,crcidx-1);
  4396. split_generic_name(basename,nongeneric,paramcount);
  4397. rttistring:=rttistring+nongeneric+'<';
  4398. remlength:=255-length(rttistring)-1;
  4399. if remlength<4 then
  4400. rttistring:=rttistring+'>'
  4401. else
  4402. rttistring:=rttistring+generate_full_paramname(remlength)+'>';
  4403. end
  4404. else
  4405. if is_generic then
  4406. begin
  4407. rttistring:=OwnerHierarchyName;
  4408. split_generic_name(objrealname^,nongeneric,paramcount);
  4409. rttistring:=rttistring+nongeneric+'<';
  4410. { we don't want any ',' if there is only one parameter }
  4411. for i:=0 to paramcount-1 do
  4412. rttistring:=rttistring+',';
  4413. rttistring:=rttistring+'>';
  4414. end
  4415. else
  4416. rttistring:=OwnerHierarchyName+objrealname^;
  4417. end;
  4418. result:=rttistring;
  4419. end;
  4420. function tabstractrecorddef.search_enumerator_get: tprocdef;
  4421. var
  4422. sym : tsym;
  4423. i : integer;
  4424. pd : tprocdef;
  4425. hashedid : THashedIDString;
  4426. begin
  4427. result:=nil;
  4428. hashedid.id:='GETENUMERATOR';
  4429. sym:=tsym(symtable.FindWithHash(hashedid));
  4430. if assigned(sym) and (sym.typ=procsym) then
  4431. begin
  4432. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  4433. begin
  4434. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4435. if (pd.proctypeoption = potype_function) and
  4436. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  4437. (pd.visibility >= vis_public) then
  4438. begin
  4439. result:=pd;
  4440. exit;
  4441. end;
  4442. end;
  4443. end;
  4444. end;
  4445. function tabstractrecorddef.search_enumerator_move: tprocdef;
  4446. var
  4447. sym : tsym;
  4448. i : integer;
  4449. pd : tprocdef;
  4450. hashedid : THashedIDString;
  4451. begin
  4452. result:=nil;
  4453. // first search for po_enumerator_movenext method modifier
  4454. // then search for public function MoveNext: Boolean
  4455. for i:=0 to symtable.SymList.Count-1 do
  4456. begin
  4457. sym:=TSym(symtable.SymList[i]);
  4458. if (sym.typ=procsym) then
  4459. begin
  4460. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  4461. if assigned(pd) then
  4462. begin
  4463. result:=pd;
  4464. exit;
  4465. end;
  4466. end;
  4467. end;
  4468. hashedid.id:='MOVENEXT';
  4469. sym:=tsym(symtable.FindWithHash(hashedid));
  4470. if assigned(sym) and (sym.typ=procsym) then
  4471. begin
  4472. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  4473. begin
  4474. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4475. if (pd.proctypeoption = potype_function) and
  4476. is_boolean(pd.returndef) and
  4477. (pd.minparacount = 0) and
  4478. (pd.visibility >= vis_public) then
  4479. begin
  4480. result:=pd;
  4481. exit;
  4482. end;
  4483. end;
  4484. end;
  4485. end;
  4486. function tabstractrecorddef.search_enumerator_current: tsym;
  4487. var
  4488. sym: tsym;
  4489. i: integer;
  4490. hashedid : THashedIDString;
  4491. begin
  4492. result:=nil;
  4493. // first search for ppo_enumerator_current property modifier
  4494. // then search for public property Current
  4495. for i:=0 to symtable.SymList.Count-1 do
  4496. begin
  4497. sym:=TSym(symtable.SymList[i]);
  4498. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  4499. begin
  4500. result:=sym;
  4501. exit;
  4502. end;
  4503. end;
  4504. hashedid.id:='CURRENT';
  4505. sym:=tsym(symtable.FindWithHash(hashedid));
  4506. if assigned(sym) and (sym.typ=propertysym) and
  4507. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  4508. begin
  4509. result:=sym;
  4510. exit;
  4511. end;
  4512. end;
  4513. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  4514. var
  4515. st: tsymtable;
  4516. enclosingdef: tdef;
  4517. begin
  4518. if typ=objectdef then
  4519. result:=tobjectdef(self).objextname^
  4520. else if assigned(typesym) then
  4521. result:=typesym.realname
  4522. { have to generate anonymous nested type in current unit/class/record }
  4523. else
  4524. internalerror(2011032601);
  4525. { in case of specializations, add some extras to prevent name conflicts
  4526. with nested classes }
  4527. if df_specialization in defoptions then
  4528. result:='$'+result+'$specialization$';
  4529. st:=owner;
  4530. while assigned(st) and
  4531. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  4532. begin
  4533. { nested classes are named as "OuterClass$InnerClass" }
  4534. enclosingdef:=tdef(st.defowner);
  4535. if enclosingdef.typ=procdef then
  4536. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  4537. else if enclosingdef.typ=objectdef then
  4538. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  4539. else if assigned(enclosingdef.typesym) then
  4540. result:=enclosingdef.typesym.realname+'$'+result
  4541. else
  4542. internalerror(2011060305);
  4543. st:=enclosingdef.owner;
  4544. end;
  4545. if with_package_name and
  4546. assigned(import_lib) then
  4547. result:=import_lib^+'/'+result;
  4548. end;
  4549. function tabstractrecorddef.contains_float_field: boolean;
  4550. var
  4551. i : longint;
  4552. begin
  4553. result:=true;
  4554. for i:=0 to symtable.symlist.count-1 do
  4555. begin
  4556. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4557. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4558. continue;
  4559. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4560. begin
  4561. if tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  4562. exit;
  4563. { search recursively }
  4564. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4565. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_float_field) then
  4566. exit;
  4567. end;
  4568. end;
  4569. result:=false;
  4570. end;
  4571. function tabstractrecorddef.contains_cross_aword_field: boolean;
  4572. var
  4573. i : longint;
  4574. foffset, fsize: aword;
  4575. begin
  4576. result:=true;
  4577. for i:=0 to symtable.symlist.count-1 do
  4578. begin
  4579. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4580. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4581. continue;
  4582. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4583. begin
  4584. if is_packed then
  4585. begin
  4586. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset;
  4587. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.packedbitsize;
  4588. end
  4589. else
  4590. begin
  4591. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset*8;
  4592. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.size*8;
  4593. end;
  4594. if (fsize>0) and ((foffset div (sizeof(aword)*8)) <> ((foffset+fsize-1) div (sizeof(aword)*8))) then
  4595. exit;
  4596. { search recursively }
  4597. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4598. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_cross_aword_field) then
  4599. exit;
  4600. end;
  4601. end;
  4602. result:=false;
  4603. end;
  4604. procedure tabstractrecorddef.apply_rtti_directive(dir: trtti_directive);
  4605. begin
  4606. { records don't support the inherit clause but shouldn't
  4607. give an error either if used (for Delphi compatibility),
  4608. so we silently enforce the clause as explicit. }
  4609. rtti.clause:=rtc_explicit;
  4610. rtti.options:=dir.options;
  4611. end;
  4612. function tabstractrecorddef.is_visible_for_rtti(option: trtti_option; vis: tvisibility): boolean;
  4613. begin
  4614. case vis of
  4615. vis_private,
  4616. vis_strictprivate: result:=rv_private in rtti.options[option];
  4617. vis_protected,
  4618. vis_strictprotected: result:=rv_protected in rtti.options[option];
  4619. vis_public: result:=rv_public in rtti.options[option];
  4620. vis_published: result:=rv_published in rtti.options[option];
  4621. otherwise
  4622. result:=false;
  4623. end;
  4624. end;
  4625. function tabstractrecorddef.rtti_visibilities_for_option(option: trtti_option): tvisibilities;
  4626. begin
  4627. result:=[];
  4628. if rv_private in rtti.options[option] then
  4629. begin
  4630. include(result,vis_private);
  4631. include(result,vis_strictprivate);
  4632. end;
  4633. if rv_protected in rtti.options[option] then
  4634. begin
  4635. include(result,vis_protected);
  4636. include(result,vis_strictprotected);
  4637. end;
  4638. if rv_public in rtti.options[option] then
  4639. include(result,vis_public);
  4640. if rv_published in rtti.options[option] then
  4641. include(result,vis_published);
  4642. end;
  4643. function tabstractrecorddef.has_extended_rtti: boolean;
  4644. begin
  4645. result := (rtti.options[ro_fields]<>[]) or
  4646. (rtti.options[ro_methods]<>[]) or
  4647. (rtti.options[ro_properties]<>[]);
  4648. end;
  4649. {$ifdef DEBUG_NODE_XML}
  4650. procedure tabstractrecorddef.XMLPrintDefData(var T: Text; Sym: TSym);
  4651. procedure WriteSymOptions(SourceSym: TSym);
  4652. var
  4653. i: TSymOption;
  4654. first: Boolean;
  4655. begin
  4656. First := True;
  4657. for i := Low(TSymOption) to High(TSymOption) do
  4658. if i in SourceSym.symoptions then
  4659. begin
  4660. if First then
  4661. begin
  4662. Write(T, '" symoptions="', i);
  4663. First := False;
  4664. end
  4665. else
  4666. Write(T, ',', i)
  4667. end;
  4668. end;
  4669. var
  4670. List: TFPHashObjectList;
  4671. i: Integer;
  4672. begin
  4673. WriteLn(T, PrintNodeIndention, '<size>', size, '</size>');
  4674. if (alignment = structalignment) and (alignment = aggregatealignment) then
  4675. begin
  4676. { Straightforward and simple }
  4677. WriteLn(T, PrintNodeIndention, '<alignment>', alignment, '</alignment>');
  4678. end
  4679. else
  4680. begin
  4681. WriteLn(T, PrintNodeIndention, '<alignment>');
  4682. printnodeindent;
  4683. WriteLn(T, PrintNodeIndention, '<basic>', alignment, '</basic>');
  4684. if (structalignment <> alignment) then
  4685. WriteLn(T, PrintNodeIndention, '<struct>', structalignment, '</struct>');
  4686. if (aggregatealignment <> alignment) and (aggregatealignment <> structalignment) then
  4687. WriteLn(T, PrintNodeIndention, '<aggregate>', aggregatealignment, '</aggregate>');
  4688. printnodeunindent;
  4689. WriteLn(T, PrintNodeIndention, '</alignment>');
  4690. end;
  4691. { List the fields }
  4692. List := Symtable.SymList;
  4693. for i := 0 to List.Count - 1 do
  4694. case TSym(List[i]).typ of
  4695. { staticvarsym,localvarsym,paravarsym,fieldvarsym,
  4696. typesym,procsym,unitsym,}
  4697. constsym:
  4698. with TConstSym(List[i]) do
  4699. begin
  4700. Write(T, PrintNodeIndention, '<const name="', RealName, '" pos="', fileinfo.line, ',', fileinfo.column);
  4701. WriteSymOptions(TSym(List[i]));
  4702. WriteLn(T, '">');
  4703. PrintNodeIndent;
  4704. XMLPrintConstData(T);
  4705. PrintNodeUnindent;
  4706. WriteLn(T, PrintNodeIndention, '</const>');
  4707. end;
  4708. {
  4709. errorsym,syssym,labelsym,absolutevarsym,propertysym,
  4710. macrosym,namespacesym,undefinedsym,programparasym
  4711. }
  4712. fieldvarsym:
  4713. with TFieldVarSym(List[i]) do
  4714. begin
  4715. Write(T, PrintNodeIndention, '<field name="', RealName, '" pos="', fileinfo.line, ',', fileinfo.column);
  4716. WriteSymOptions(TSym(List[i]));
  4717. WriteLn(T, '">');
  4718. PrintNodeIndent;
  4719. XMLPrintFieldData(T);
  4720. PrintNodeUnindent;
  4721. WriteLn(T, PrintNodeIndention, '</field>');
  4722. end;
  4723. else
  4724. ;
  4725. end;
  4726. end;
  4727. {$endif DEBUG_NODE_XML}
  4728. {***************************************************************************
  4729. trecorddef
  4730. ***************************************************************************}
  4731. constructor trecorddef.create(const n:string; p:TSymtable);
  4732. begin
  4733. inherited create(n,recorddef,true);
  4734. symtable:=p;
  4735. { we can own the symtable only if nobody else owns a copy so far }
  4736. if symtable.refcount=1 then
  4737. symtable.defowner:=self;
  4738. isunion:=false;
  4739. cloneddefderef.reset;
  4740. end;
  4741. constructor trecorddef.create_internal(const n: string; packrecords, recordalignmin: shortint; where: tsymtable);
  4742. var
  4743. name : string;
  4744. pname : pshortstring;
  4745. oldsymtablestack: tsymtablestack;
  4746. ts: ttypesym;
  4747. begin
  4748. { construct name }
  4749. if n<>'' then
  4750. pname:=@n
  4751. else
  4752. begin
  4753. init_defid;
  4754. name:='$InternalRec'+unique_id_str;
  4755. pname:=@name;
  4756. end;
  4757. oldsymtablestack:=symtablestack;
  4758. { do not simply push/pop current_module.localsymtable, because
  4759. that can have side-effects (e.g., it removes helpers) }
  4760. symtablestack:=nil;
  4761. symtable:=trecordsymtable.create(pname^,packrecords,recordalignmin);
  4762. symtable.defowner:=self;
  4763. isunion:=false;
  4764. inherited create(pname^,recorddef,true);
  4765. where.insertdef(self);
  4766. { if we specified a name, then we'll probably want to look up the
  4767. type again by name too -> create typesym }
  4768. if n<>'' then
  4769. begin
  4770. ts:=ctypesym.create(n,self);
  4771. include(ts.symoptions,sp_internal);
  4772. { avoid hints about unused types (these may only be used for
  4773. typed constant data) }
  4774. ts.increfcount;
  4775. where.insertsym(ts);
  4776. end;
  4777. symtablestack:=oldsymtablestack;
  4778. { don't create RTTI for internal types, these are not exported }
  4779. defstates:=defstates+[ds_rtti_table_written,ds_init_table_written];
  4780. include(defoptions,df_internal);
  4781. end;
  4782. constructor trecorddef.create_global_internal(const n: string; packrecords, recordalignmin: shortint);
  4783. var
  4784. where : tsymtable;
  4785. begin
  4786. where:=current_module.localsymtable;
  4787. if not assigned(where) then
  4788. where:=current_module.globalsymtable;
  4789. create_internal(n,packrecords,recordalignmin,where);
  4790. end;
  4791. function trecorddef.add_field_by_def(const optionalname: TIDString; def: tdef): tsym;
  4792. var
  4793. sym: tfieldvarsym;
  4794. name: TIDString;
  4795. pname: ^TIDString;
  4796. begin
  4797. if optionalname='' then
  4798. begin
  4799. name:='$f'+tostr(trecordsymtable(symtable).symlist.count);
  4800. pname:=@name
  4801. end
  4802. else
  4803. pname:=@optionalname;
  4804. sym:=cfieldvarsym.create(pname^,vs_value,def,[]);
  4805. symtable.insertsym(sym);
  4806. trecordsymtable(symtable).addfield(sym,vis_hidden);
  4807. result:=sym;
  4808. end;
  4809. procedure trecorddef.add_fields_from_deflist(fieldtypes: tfplist);
  4810. var
  4811. i: longint;
  4812. begin
  4813. for i:=0 to fieldtypes.count-1 do
  4814. add_field_by_def('',tdef(fieldtypes[i]));
  4815. end;
  4816. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  4817. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  4818. var
  4819. i,j : longint;
  4820. begin
  4821. if ppufile.getbyte=1 then
  4822. begin
  4823. new(variantrecdesc);
  4824. ppufile.getderef(variantrecdesc^.variantselectorderef);
  4825. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  4826. for i:=0 to high(variantrecdesc^.branches) do
  4827. begin
  4828. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  4829. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4830. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  4831. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4832. end;
  4833. end
  4834. else
  4835. variantrecdesc:=nil;
  4836. end;
  4837. begin
  4838. inherited ppuload(recorddef,ppufile);
  4839. if df_copied_def in defoptions then
  4840. begin
  4841. ppufile.getderef(cloneddefderef);
  4842. ppuload_platform(ppufile);
  4843. end
  4844. else
  4845. begin
  4846. symtable:=trecordsymtable.create(objrealname^,0,0);
  4847. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  4848. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  4849. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  4850. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  4851. trecordsymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  4852. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  4853. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  4854. ppufile.getset(tppuset1(trecordsymtable(symtable).managementoperators));
  4855. { position of ppuload_platform call must correspond
  4856. to position of writeentry in ppuwrite method }
  4857. ppuload_platform(ppufile);
  4858. trecordsymtable(symtable).ppuload(ppufile);
  4859. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4860. but because iso mode supports no units, there is no need to store the variantrecdesc
  4861. in the ppu
  4862. }
  4863. // readvariantrecdesc(variantrecdesc);
  4864. { requires usefieldalignment to be set }
  4865. symtable.defowner:=self;
  4866. end;
  4867. isunion:=false;
  4868. end;
  4869. destructor trecorddef.destroy;
  4870. procedure free_variantrecdesc(var variantrecdesc : pvariantrecdesc);
  4871. var
  4872. i : longint;
  4873. begin
  4874. while assigned(variantrecdesc) do
  4875. begin
  4876. for i:=0 to high(variantrecdesc^.branches) do
  4877. begin
  4878. free_variantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4879. SetLength(variantrecdesc^.branches[i].values,0);
  4880. end;
  4881. SetLength(variantrecdesc^.branches,0);
  4882. dispose(variantrecdesc);
  4883. variantrecdesc:=nil;
  4884. end;
  4885. end;
  4886. begin
  4887. if assigned(variantrecdesc) then
  4888. free_variantrecdesc(variantrecdesc);
  4889. if assigned(symtable) then
  4890. begin
  4891. symtable.free;
  4892. symtable:=nil;
  4893. end;
  4894. inherited destroy;
  4895. end;
  4896. function trecorddef.getcopy : tstoreddef;
  4897. begin
  4898. result:=crecorddef.create(objrealname^,symtable.getcopy);
  4899. trecorddef(result).isunion:=isunion;
  4900. include(trecorddef(result).defoptions,df_copied_def);
  4901. if assigned(tcinitcode) then
  4902. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  4903. if assigned(import_lib) then
  4904. trecorddef(result).import_lib:=stringdup(import_lib^);
  4905. end;
  4906. function trecorddef.needs_inittable : boolean;
  4907. begin
  4908. { each record with managed field or with any management operator needs
  4909. init table }
  4910. needs_inittable:=(trecordsymtable(symtable).managementoperators<>[]) or
  4911. trecordsymtable(symtable).needs_init_final
  4912. end;
  4913. function trecorddef.needs_separate_initrtti : boolean;
  4914. begin
  4915. result:=true;
  4916. end;
  4917. function trecorddef.has_non_trivial_init_child(check_parent:boolean):boolean;
  4918. begin
  4919. result:=trecordsymtable(symtable).has_non_trivial_init;
  4920. end;
  4921. procedure trecorddef.buildderef;
  4922. begin
  4923. inherited buildderef;
  4924. if df_copied_def in defoptions then
  4925. cloneddefderef.build(symtable.defowner)
  4926. else
  4927. tstoredsymtable(symtable).buildderef;
  4928. end;
  4929. procedure trecorddef.deref;
  4930. begin
  4931. inherited deref;
  4932. { now dereference the definitions }
  4933. if df_copied_def in defoptions then
  4934. begin
  4935. cloneddef:=trecorddef(cloneddefderef.resolve);
  4936. symtable:=cloneddef.symtable.getcopy;
  4937. end
  4938. else
  4939. tstoredsymtable(symtable).deref(false);
  4940. { internal types, only load from the system unit }
  4941. if assigned(owner) and
  4942. assigned(owner.name) and
  4943. (owner.name^='SYSTEM') then
  4944. begin
  4945. { TGUID }
  4946. if not assigned(rec_tguid) and
  4947. (upper(typename)='TGUID') then
  4948. rec_tguid:=self
  4949. { JMP_BUF }
  4950. else if not assigned(rec_jmp_buf) and
  4951. (upper(typename)='JMP_BUF') then
  4952. rec_jmp_buf:=self
  4953. else if not assigned(rec_exceptaddr) and
  4954. (upper(typename)='TEXCEPTADDR') then
  4955. rec_exceptaddr:=self;
  4956. end;
  4957. end;
  4958. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  4959. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  4960. var
  4961. i,j : longint;
  4962. begin
  4963. if assigned(variantrecdesc) then
  4964. begin
  4965. ppufile.putbyte(1);
  4966. ppufile.putderef(variantrecdesc^.variantselectorderef);
  4967. ppufile.putasizeint(length(variantrecdesc^.branches));
  4968. for i:=0 to high(variantrecdesc^.branches) do
  4969. begin
  4970. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  4971. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4972. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  4973. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4974. end;
  4975. end
  4976. else
  4977. ppufile.putbyte(0);
  4978. end;
  4979. begin
  4980. inherited ppuwrite(ppufile);
  4981. if df_copied_def in defoptions then
  4982. ppufile.putderef(cloneddefderef)
  4983. else
  4984. begin
  4985. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  4986. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  4987. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  4988. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  4989. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignmin));
  4990. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  4991. ppufile.putword(trecordsymtable(symtable).paddingsize);
  4992. ppufile.putset(tppuset1(trecordsymtable(symtable).managementoperators));
  4993. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4994. but because iso mode supports no units, there is no need to store the variantrecdesc
  4995. in the ppu
  4996. }
  4997. // writevariantrecdesc(variantrecdesc);
  4998. end;
  4999. writeentry(ppufile,ibrecorddef);
  5000. if not(df_copied_def in defoptions) then
  5001. trecordsymtable(symtable).ppuwrite(ppufile);
  5002. end;
  5003. function trecorddef.size:asizeint;
  5004. begin
  5005. result:=trecordsymtable(symtable).datasize;
  5006. end;
  5007. function trecorddef.alignment:shortint;
  5008. begin
  5009. alignment:=trecordsymtable(symtable).recordalignment;
  5010. end;
  5011. function trecorddef.padalignment:shortint;
  5012. begin
  5013. padalignment := trecordsymtable(symtable).padalignment;
  5014. end;
  5015. function trecorddef.GetTypeName : string;
  5016. begin
  5017. GetTypeName:='<record type>'
  5018. end;
  5019. {$ifdef DEBUG_NODE_XML}
  5020. function TRecordDef.XMLPrintType: ansistring;
  5021. begin
  5022. Result := '&lt;record&gt;';
  5023. end;
  5024. {$endif DEBUG_NODE_XML}
  5025. {***************************************************************************
  5026. TABSTRACTPROCDEF
  5027. ***************************************************************************}
  5028. constructor tabstractprocdef.create(dt:tdeftyp;level:byte;doregister:boolean);
  5029. begin
  5030. inherited create(dt,doregister);
  5031. parast:=tparasymtable.create(self,level);
  5032. paras:=nil;
  5033. minparacount:=0;
  5034. maxparacount:=0;
  5035. proctypeoption:=potype_none;
  5036. proccalloption:=pocall_none;
  5037. procoptions:=[];
  5038. returndef:=voidtype;
  5039. returndefderef.reset;
  5040. savesize:=sizeof(pint);
  5041. callerargareasize:=0;
  5042. calleeargareasize:=0;
  5043. has_paraloc_info:=callnoside;
  5044. funcretloc[callerside].init;
  5045. funcretloc[calleeside].init;
  5046. check_mark_as_nested;
  5047. end;
  5048. destructor tabstractprocdef.destroy;
  5049. begin
  5050. if assigned(paras) then
  5051. begin
  5052. {$ifdef MEMDEBUG}
  5053. memprocpara.start;
  5054. {$endif MEMDEBUG}
  5055. paras.free;
  5056. paras:=nil;
  5057. {$ifdef MEMDEBUG}
  5058. memprocpara.stop;
  5059. {$endif MEMDEBUG}
  5060. end;
  5061. if assigned(parast) then
  5062. begin
  5063. {$ifdef MEMDEBUG}
  5064. memprocparast.start;
  5065. {$endif MEMDEBUG}
  5066. parast.free;
  5067. parast:=nil;
  5068. {$ifdef MEMDEBUG}
  5069. memprocparast.stop;
  5070. {$endif MEMDEBUG}
  5071. end;
  5072. funcretloc[callerside].done;
  5073. funcretloc[calleeside].done;
  5074. inherited destroy;
  5075. end;
  5076. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  5077. begin
  5078. if (tsym(p).typ<>paravarsym) then
  5079. exit;
  5080. inc(plongint(arg)^);
  5081. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  5082. begin
  5083. if not assigned(tparavarsym(p).defaultconstsym) then
  5084. inc(minparacount);
  5085. inc(maxparacount);
  5086. end;
  5087. end;
  5088. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  5089. begin
  5090. if (tsym(p).typ<>paravarsym) then
  5091. exit;
  5092. paras.add(p);
  5093. end;
  5094. procedure tabstractprocdef.calcparas;
  5095. var
  5096. paracount : longint;
  5097. begin
  5098. { This can already be assigned when
  5099. we need to reresolve this unit (PFV) }
  5100. if assigned(paras) then
  5101. paras.free;
  5102. paras:=tparalist.create(false);
  5103. paracount:=0;
  5104. minparacount:=0;
  5105. maxparacount:=0;
  5106. parast.SymList.ForEachCall(@count_para,@paracount);
  5107. paras.capacity:=paracount;
  5108. { Insert parameters in table }
  5109. parast.SymList.ForEachCall(@insert_para,nil);
  5110. { Order parameters }
  5111. paras.sortparas;
  5112. end;
  5113. function tabstractprocdef.mangledprocparanames(oldlen : longint) : string;
  5114. var
  5115. hash : qword;
  5116. hp : TParavarsym;
  5117. hs : TSymStr;
  5118. newlen,
  5119. i : integer;
  5120. begin
  5121. result:='';
  5122. hp:=nil;
  5123. { add parameter types }
  5124. for i:=0 to paras.count-1 do
  5125. begin
  5126. hp:=tparavarsym(paras[i]);
  5127. if not(vo_is_hidden_para in hp.varoptions) then
  5128. result:=result+'$'+hp.vardef.mangledparaname;
  5129. end;
  5130. { add resultdef, add $$ as separator to make it unique from a
  5131. parameter separator }
  5132. if not is_void(returndef) then
  5133. result:=result+'$$'+returndef.mangledparaname;
  5134. newlen:=length(result)+oldlen;
  5135. { Replace with hash if the parameter line is very long }
  5136. if (newlen-oldlen>12) and
  5137. ((newlen>100) or (newlen-oldlen>64)) then
  5138. begin
  5139. hash:=InitFnv64;
  5140. for i:=0 to paras.count-1 do
  5141. begin
  5142. hp:=tparavarsym(paras[i]);
  5143. if not(vo_is_hidden_para in hp.varoptions) then
  5144. begin
  5145. hs:=hp.vardef.mangledparaname;
  5146. hash:=UpdateFnv64(hash,hs[1],length(hs));
  5147. end;
  5148. end;
  5149. if not is_void(returndef) then
  5150. begin
  5151. { add a little prefix so that x(integer; integer) is different from x(integer):integer }
  5152. hs:='$$'+returndef.mangledparaname;
  5153. hash:=UpdateFnv64(hash,hs[1],length(hs));
  5154. end;
  5155. result:='$h'+Base64Mangle(hash);
  5156. end;
  5157. end;
  5158. procedure tabstractprocdef.buildderef;
  5159. begin
  5160. { released procdef? }
  5161. if not assigned(parast) then
  5162. exit;
  5163. inherited buildderef;
  5164. returndefderef.build(returndef);
  5165. if po_explicitparaloc in procoptions then
  5166. funcretloc[callerside].buildderef;
  5167. { parast }
  5168. tparasymtable(parast).buildderef;
  5169. end;
  5170. procedure tabstractprocdef.deref;
  5171. begin
  5172. inherited deref;
  5173. returndef:=tdef(returndefderef.resolve);
  5174. if po_explicitparaloc in procoptions then
  5175. begin
  5176. funcretloc[callerside].deref;
  5177. has_paraloc_info:=callerside;
  5178. end
  5179. else
  5180. begin
  5181. { deref is called after loading from a ppu, but also after another
  5182. unit has been reloaded/recompiled and all references must be
  5183. re-resolved. Since the funcretloc contains a reference to a tdef,
  5184. reset it so that we won't try to access the stale def }
  5185. funcretloc[callerside].init;
  5186. has_paraloc_info:=callnoside;
  5187. end;
  5188. { parast }
  5189. tparasymtable(parast).deref(false);
  5190. { recalculated parameters }
  5191. calcparas;
  5192. end;
  5193. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  5194. begin
  5195. inherited ppuload(dt,ppufile);
  5196. parast:=nil;
  5197. Paras:=nil;
  5198. minparacount:=0;
  5199. maxparacount:=0;
  5200. ppufile.getderef(returndefderef);
  5201. proctypeoption:=tproctypeoption(ppufile.getbyte);
  5202. proccalloption:=tproccalloption(ppufile.getbyte);
  5203. ppufile.getset(tppuset8(procoptions));
  5204. funcretloc[callerside].init;
  5205. if po_explicitparaloc in procoptions then
  5206. funcretloc[callerside].ppuload(ppufile);
  5207. savesize:=sizeof(pint);
  5208. if (po_explicitparaloc in procoptions) then
  5209. has_paraloc_info:=callerside;
  5210. end;
  5211. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  5212. var
  5213. oldintfcrc : boolean;
  5214. begin
  5215. { released procdef? }
  5216. if not assigned(parast) then
  5217. exit;
  5218. inherited ppuwrite(ppufile);
  5219. ppufile.putderef(returndefderef);
  5220. oldintfcrc:=ppufile.do_interface_crc;
  5221. ppufile.do_interface_crc:=false;
  5222. ppufile.putbyte(ord(proctypeoption));
  5223. ppufile.putbyte(ord(proccalloption));
  5224. ppufile.putset(tppuset8(procoptions));
  5225. ppufile.do_interface_crc:=oldintfcrc;
  5226. if (po_explicitparaloc in procoptions) then
  5227. funcretloc[callerside].ppuwrite(ppufile);
  5228. end;
  5229. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  5230. var
  5231. hs,s : ansistring;
  5232. hp : TParavarsym;
  5233. hpc : tconstsym;
  5234. first : boolean;
  5235. i,j : integer;
  5236. begin
  5237. s:='';
  5238. first:=true;
  5239. for i:=0 to paras.count-1 do
  5240. begin
  5241. hp:=tparavarsym(paras[i]);
  5242. if not(vo_is_hidden_para in hp.varoptions) or
  5243. (pno_showhidden in pno) then
  5244. begin
  5245. if first then
  5246. begin
  5247. s:=s+'(';
  5248. first:=false;
  5249. end
  5250. else
  5251. s:=s+';';
  5252. if vo_is_hidden_para in hp.varoptions then
  5253. s:=s+'<';
  5254. case hp.varspez of
  5255. vs_var :
  5256. s:=s+'var ';
  5257. vs_const :
  5258. s:=s+'const ';
  5259. vs_out :
  5260. s:=s+'out ';
  5261. vs_constref :
  5262. s:=s+'constref ';
  5263. else
  5264. ;
  5265. end;
  5266. if (pno_paranames in pno) then
  5267. s:=s+hp.realname+':';
  5268. if hp.univpara then
  5269. s:=s+'univ ';
  5270. if assigned(hp.vardef.typesym) then
  5271. begin
  5272. hs:=hp.vardef.typesym.realname;
  5273. if hs[1]<>'$' then
  5274. s:=s+hp.vardef.OwnerHierarchyName+hs
  5275. else
  5276. s:=s+hp.vardef.GetTypeName;
  5277. end
  5278. else
  5279. s:=s+hp.vardef.GetTypeName;
  5280. { default value }
  5281. if assigned(hp.defaultconstsym) then
  5282. begin
  5283. hpc:=tconstsym(hp.defaultconstsym);
  5284. hs:='';
  5285. case hpc.consttyp of
  5286. constwresourcestring,
  5287. constwstring:
  5288. begin
  5289. if hpc.value.valuews.len>0 then
  5290. begin
  5291. setlength(hs,hpc.value.valuews.len);
  5292. for j:=0 to hpc.value.valuews.len-1 do
  5293. begin
  5294. if (ord(hpc.value.valuews.data[j])<127) and
  5295. not(byte(hpc.value.valuews.data[j]) in [0,10,13]) then
  5296. hs[j+1]:=char(hpc.value.valuews.data[j])
  5297. else
  5298. hs[j+1]:='.';
  5299. end;
  5300. end;
  5301. end;
  5302. conststring,
  5303. constresourcestring :
  5304. begin
  5305. if hpc.value.len>0 then
  5306. begin
  5307. setLength(hs,hpc.value.len);
  5308. { don't write past the end of hs if the constant
  5309. is > 255 chars }
  5310. move(hpc.value.valueptr^,hs[1],length(hs));
  5311. { make sure that constant strings with newline chars
  5312. don't create a linebreak in the assembler code,
  5313. since comments are line-based. Also remove nulls
  5314. because the comments are written as a pchar. }
  5315. ReplaceCase(hs,#0,'.');
  5316. ReplaceCase(hs,#10,'.');
  5317. ReplaceCase(hs,#13,'.');
  5318. end;
  5319. end;
  5320. constreal :
  5321. str(pbestreal(hpc.value.valueptr)^,hs);
  5322. constpointer :
  5323. hs:=tostr(hpc.value.valueordptr);
  5324. constord :
  5325. begin
  5326. if is_boolean(hpc.constdef) then
  5327. begin
  5328. if hpc.value.valueord<>0 then
  5329. hs:='TRUE'
  5330. else
  5331. hs:='FALSE';
  5332. end
  5333. else
  5334. hs:=tostr(hpc.value.valueord);
  5335. end;
  5336. constnil :
  5337. hs:='nil';
  5338. constset :
  5339. hs:='<set>';
  5340. constguid:
  5341. hs:=guid2string(pguid(hpc.value.valueptr)^);
  5342. constnone:
  5343. internalerror(2019050704);
  5344. end;
  5345. if hs<>'' then
  5346. s:=s+'=`'+hs+'`';
  5347. end;
  5348. if vo_is_hidden_para in hp.varoptions then
  5349. s:=s+'>';
  5350. end;
  5351. end;
  5352. if not first then
  5353. s:=s+')';
  5354. if (po_varargs in procoptions) then
  5355. s:=s+';VarArgs';
  5356. typename_paras:=s;
  5357. end;
  5358. function tabstractprocdef.is_methodpointer:boolean;
  5359. begin
  5360. result:=false;
  5361. end;
  5362. function tabstractprocdef.is_addressonly:boolean;
  5363. begin
  5364. result:=true;
  5365. end;
  5366. function tabstractprocdef.no_self_node: boolean;
  5367. begin
  5368. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  5369. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  5370. end;
  5371. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  5372. var
  5373. j, nestinglevel: longint;
  5374. pvs, npvs: tparavarsym;
  5375. begin
  5376. nestinglevel:=parast.symtablelevel;
  5377. if newtyp=procdef then
  5378. begin
  5379. if (copytyp<>pc_bareproc) then
  5380. result:=cprocdef.create(nestinglevel,doregister)
  5381. else
  5382. result:=cprocdef.create(normal_function_level,doregister);
  5383. tprocdef(result).visibility:=vis_public;
  5384. end
  5385. else
  5386. begin
  5387. result:=cprocvardef.create(nestinglevel,true);
  5388. end;
  5389. tabstractprocdef(result).returndef:=returndef;
  5390. tabstractprocdef(result).returndefderef:=returndefderef;
  5391. pvs:=nil;
  5392. npvs:=nil;
  5393. if copytyp<>pc_normal_no_paras then
  5394. begin
  5395. for j:=0 to parast.symlist.count-1 do
  5396. begin
  5397. case tsym(parast.symlist[j]).typ of
  5398. paravarsym:
  5399. begin
  5400. pvs:=tparavarsym(parast.symlist[j]);
  5401. { in case of bare proc, don't copy self, vmt or framepointer
  5402. parameters }
  5403. if (copytyp in [pc_bareproc,pc_normal_no_hidden]) and
  5404. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result,vo_is_funcret,vo_is_high_para]*pvs.varoptions)<>[]) then
  5405. continue;
  5406. if paraprefix='' then
  5407. npvs:=cparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  5408. pvs.vardef,pvs.varoptions)
  5409. else if not(vo_is_high_para in pvs.varoptions) then
  5410. npvs:=cparavarsym.create(paraprefix+pvs.realname,pvs.paranr,pvs.varspez,
  5411. pvs.vardef,pvs.varoptions)
  5412. else
  5413. npvs:=cparavarsym.create('$high'+paraprefix+copy(pvs.name,5,length(pvs.name)),pvs.paranr,pvs.varspez,
  5414. pvs.vardef,pvs.varoptions);
  5415. npvs.defaultconstsym:=pvs.defaultconstsym;
  5416. tabstractprocdef(result).parast.insertsym(npvs);
  5417. end;
  5418. constsym:
  5419. begin
  5420. // ignore, reuse original constym. Should also be duplicated
  5421. // be safe though
  5422. end;
  5423. symconst.typesym:
  5424. begin
  5425. // reuse original, part of generic declaration
  5426. end
  5427. else
  5428. internalerror(201160604);
  5429. end;
  5430. end;
  5431. end;
  5432. tabstractprocdef(result).savesize:=savesize;
  5433. if (typ<>procvardef) and
  5434. (newtyp=procvardef) then
  5435. begin
  5436. { procvars can't be (class)constructures/destructors etc }
  5437. if proctypeoption=potype_constructor then
  5438. begin
  5439. tabstractprocdef(result).returndef:=tdef(owner.defowner);
  5440. if not(is_implicit_pointer_object_type(returndef) or
  5441. (returndef.typ<>objectdef)) then
  5442. tabstractprocdef(result).returndef:=cpointerdef.getreusable(tabstractprocdef(result).returndef);
  5443. tabstractprocdef(result).proctypeoption:=potype_function;
  5444. end
  5445. else if is_void(returndef) then
  5446. tabstractprocdef(result).proctypeoption:=potype_procedure
  5447. else
  5448. tabstractprocdef(result).proctypeoption:=potype_function;
  5449. end
  5450. else
  5451. tabstractprocdef(result).proctypeoption:=proctypeoption;
  5452. tabstractprocdef(result).proccalloption:=proccalloption;
  5453. tabstractprocdef(result).procoptions:=procoptions;
  5454. if (copytyp=pc_bareproc) then
  5455. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  5456. if newtyp=procvardef then
  5457. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  5458. if copytyp=pc_address_only then
  5459. include(tabstractprocdef(result).procoptions,po_addressonly);
  5460. tabstractprocdef(result).callerargareasize:=callerargareasize;
  5461. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  5462. tabstractprocdef(result).maxparacount:=maxparacount;
  5463. tabstractprocdef(result).minparacount:=minparacount;
  5464. if po_explicitparaloc in procoptions then
  5465. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  5466. { recalculate parameter info }
  5467. tabstractprocdef(result).has_paraloc_info:=callnoside;
  5468. {$ifdef m68k}
  5469. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  5470. {$endif}
  5471. if (typ=procdef) and
  5472. (newtyp=procvardef) and
  5473. (owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  5474. include(tprocvardef(result).procoptions,po_methodpointer);
  5475. end;
  5476. function tabstractprocdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  5477. begin
  5478. result:=is_addressonly;
  5479. end;
  5480. procedure tabstractprocdef.check_mark_as_nested;
  5481. begin
  5482. { nested procvars require that nested functions use the Delphi-style
  5483. nested procedure calling convention }
  5484. if (parast.symtablelevel>normal_function_level) and
  5485. (m_nested_procvars in current_settings.modeswitches) then
  5486. include(procoptions,po_delphi_nested_cc);
  5487. end;
  5488. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  5489. begin
  5490. if (side in [callerside,callbothsides]) and
  5491. not(has_paraloc_info in [callerside,callbothsides]) then
  5492. begin
  5493. if not is_c_variadic(self) then
  5494. callerargareasize:=paramanager.create_paraloc_info(self,callerside)
  5495. else
  5496. callerargareasize:=paramanager.create_varargs_paraloc_info(self,callerside,nil);
  5497. if has_paraloc_info in [calleeside,callbothsides] then
  5498. has_paraloc_info:=callbothsides
  5499. else
  5500. has_paraloc_info:=callerside;
  5501. end;
  5502. if (side in [calleeside,callbothsides]) and
  5503. not(has_paraloc_info in [calleeside,callbothsides]) then
  5504. begin
  5505. if not is_c_variadic(self) then
  5506. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside)
  5507. else
  5508. callerargareasize:=paramanager.create_varargs_paraloc_info(self,calleeside,nil);
  5509. if has_paraloc_info in [callerside,callbothsides] then
  5510. has_paraloc_info:=callbothsides
  5511. else
  5512. has_paraloc_info:=calleeside;
  5513. end;
  5514. end;
  5515. procedure tabstractprocdef.done_paraloc_info(side: tcallercallee);
  5516. var
  5517. i: longint;
  5518. begin
  5519. if (side in [callerside,callbothsides]) and
  5520. (has_paraloc_info in [callerside,callbothsides]) then
  5521. begin
  5522. funcretloc[callerside].done;
  5523. for i:=0 to paras.count-1 do
  5524. tparavarsym(paras[i]).paraloc[callerside].done;
  5525. if has_paraloc_info=callerside then
  5526. has_paraloc_info:=callnoside
  5527. else
  5528. has_paraloc_info:=calleeside;
  5529. end;
  5530. if (side in [calleeside,callbothsides]) and
  5531. (has_paraloc_info in [calleeside,callbothsides]) then
  5532. begin
  5533. funcretloc[calleeside].done;
  5534. for i:=0 to paras.count-1 do
  5535. tparavarsym(paras[i]).paraloc[calleeside].done;
  5536. if has_paraloc_info=calleeside then
  5537. has_paraloc_info:=callnoside
  5538. else
  5539. has_paraloc_info:=callerside;
  5540. end;
  5541. end;
  5542. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  5543. var
  5544. p: tparavarsym;
  5545. ploc: PCGParalocation;
  5546. i: longint;
  5547. begin
  5548. result:=false;
  5549. init_paraloc_info(side);
  5550. for i:=0 to parast.SymList.Count-1 do
  5551. if tsym(parast.SymList[i]).typ=paravarsym then
  5552. begin
  5553. p:=tparavarsym(parast.SymList[i]);
  5554. if not p.is_used then
  5555. continue;
  5556. { check if no parameter is located on the stack }
  5557. if (is_open_array(p.vardef) or
  5558. is_array_of_const(p.vardef)) and (p.varspez=vs_value) then
  5559. begin
  5560. result:=true;
  5561. exit;
  5562. end;
  5563. ploc:=p.paraloc[side].location;
  5564. while assigned(ploc) do
  5565. begin
  5566. if (ploc^.loc=LOC_REFERENCE) then
  5567. begin
  5568. result:=true;
  5569. exit
  5570. end;
  5571. ploc:=ploc^.next;
  5572. end;
  5573. end;
  5574. end;
  5575. function tabstractprocdef.is_pushleftright: boolean;
  5576. begin
  5577. result:=false;
  5578. end;
  5579. function tabstractprocdef.address_type: tdef;
  5580. begin
  5581. result:=voidcodepointertype;
  5582. end;
  5583. function tabstractprocdef.ofs_address_type:tdef;
  5584. begin
  5585. result:=address_type;
  5586. end;
  5587. procedure tabstractprocdef.declared_far;
  5588. begin
  5589. Message1(parser_w_proc_directive_ignored,'FAR');
  5590. end;
  5591. procedure tabstractprocdef.declared_near;
  5592. begin
  5593. Message1(parser_w_proc_directive_ignored,'NEAR');
  5594. end;
  5595. function tabstractprocdef.generate_safecall_wrapper: boolean;
  5596. begin
  5597. {$ifdef SUPPORT_SAFECALL}
  5598. result:=
  5599. (proccalloption=pocall_safecall) and
  5600. not(po_assembler in procoptions) and
  5601. (tf_safecall_exceptions in target_info.flags);
  5602. {$else SUPPORT_SAFECALL}
  5603. result:=false;
  5604. {$endif}
  5605. end;
  5606. function tabstractprocdef.is_generic_param(def:tdef): boolean;
  5607. begin
  5608. if def.typ=undefineddef then
  5609. result:=def.owner=self.parast
  5610. else if def.typ=objectdef then
  5611. result:=(def.owner=self.parast) and (tstoreddef(def).genconstraintdata<>nil)
  5612. else
  5613. result:=false;
  5614. end;
  5615. function tabstractprocdef.wpo_may_create_instance(optionalmethodpointer: tnode): boolean;
  5616. begin
  5617. result:=
  5618. (proctypeoption=potype_constructor) or
  5619. ((typ=procdef) and
  5620. ((not assigned(optionalmethodpointer) and
  5621. is_class(tdef(owner.defowner))) or
  5622. (assigned(optionalmethodpointer) and
  5623. ((optionalmethodpointer.resultdef.typ=classrefdef) or
  5624. (optionalmethodpointer.nodetype=typen)))) and
  5625. (tprocdef(self).procsym.Name='NEWINSTANCE'))
  5626. end;
  5627. {***************************************************************************
  5628. TPROCDEF
  5629. ***************************************************************************}
  5630. function tprocdef.getparentfpsym: tsym;
  5631. begin
  5632. if not assigned(_parentfpsym) then
  5633. begin
  5634. _parentfpsym:=tsym(parast.Find('parentfp'));
  5635. if not assigned(_parentfpsym) then
  5636. internalerror(200309281);
  5637. end;
  5638. result:=_parentfpsym;
  5639. end;
  5640. function tprocdef.Getis_implemented: boolean;
  5641. begin
  5642. result:=not assigned(implprocdefinfo) or implprocdefinfo^.is_implemented;
  5643. end;
  5644. procedure tprocdef.Setis_implemented(AValue: boolean);
  5645. begin
  5646. if not assigned(implprocdefinfo) then
  5647. internalerror(2020062101);
  5648. implprocdefinfo^.is_implemented:=AValue;
  5649. end;
  5650. function tprocdef.getwas_anonymous:boolean;
  5651. begin
  5652. result:=assigned(implprocdefinfo) and implprocdefinfo^.was_anonymous;
  5653. end;
  5654. procedure tprocdef.setwas_anonymous(avalue:boolean);
  5655. begin
  5656. if not assigned(implprocdefinfo) then
  5657. internalerror(2022020502);
  5658. implprocdefinfo^.was_anonymous:=avalue;
  5659. end;
  5660. function tprocdef.gethas_capturer:boolean;
  5661. begin
  5662. result:=assigned(implprocdefinfo) and implprocdefinfo^.has_capturer;
  5663. end;
  5664. procedure tprocdef.sethas_capturer(avalue:boolean);
  5665. begin
  5666. if not assigned(implprocdefinfo) then
  5667. internalerror(2022020503);
  5668. implprocdefinfo^.has_capturer:=avalue;
  5669. end;
  5670. function tprocdef.Getcapturedsyms:tfplist;
  5671. begin
  5672. if not assigned(implprocdefinfo) then
  5673. result:=nil
  5674. else
  5675. result:=implprocdefinfo^.capturedsyms;
  5676. end;
  5677. function tprocdef.store_localst: boolean;
  5678. begin
  5679. result:=has_inlininginfo or (df_generic in defoptions);
  5680. end;
  5681. function tprocdef.GetResultName: PShortString;
  5682. begin
  5683. if not assigned(implprocdefinfo) then
  5684. internalerror(2014010301);
  5685. result:=implprocdefinfo^.resultname;
  5686. end;
  5687. procedure tprocdef.SetResultName(AValue: PShortString);
  5688. begin
  5689. if not assigned(implprocdefinfo) then
  5690. internalerror(2014010302);
  5691. implprocdefinfo^.resultname:=AValue;
  5692. end;
  5693. function tprocdef.GetParentFPInitBlock: tnode;
  5694. begin
  5695. if not assigned(implprocdefinfo) then
  5696. internalerror(2014010303);
  5697. result:=implprocdefinfo^.parentfpinitblock;
  5698. end;
  5699. function tprocdef.GetParentFPStruct: tsym;
  5700. begin
  5701. if not assigned(implprocdefinfo) then
  5702. internalerror(2014010304);
  5703. result:=implprocdefinfo^.parentfpstruct;
  5704. end;
  5705. function tprocdef.GetParentFPStructPtrType: tdef;
  5706. begin
  5707. if not assigned(implprocdefinfo) then
  5708. internalerror(2014010305);
  5709. result:=implprocdefinfo^.parentfpstructptrtype;
  5710. end;
  5711. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  5712. begin
  5713. if not assigned(implprocdefinfo) then
  5714. internalerror(2014010306);
  5715. implprocdefinfo^.parentfpinitblock:=AValue;
  5716. end;
  5717. function tprocdef.Getprocendtai: tai;
  5718. begin
  5719. if not assigned(implprocdefinfo) then
  5720. internalerror(2014010307);
  5721. result:=implprocdefinfo^.procendtai;
  5722. end;
  5723. function tprocdef.Getprocstarttai: tai;
  5724. begin
  5725. if not assigned(implprocdefinfo) then
  5726. internalerror(2014010308);
  5727. result:=implprocdefinfo^.procstarttai;
  5728. end;
  5729. procedure tprocdef.Setprocendtai(AValue: tai);
  5730. begin
  5731. if not assigned(implprocdefinfo) then
  5732. internalerror(2014010309);
  5733. implprocdefinfo^.procendtai:=AValue;
  5734. end;
  5735. function tprocdef.Getskpara: pointer;
  5736. begin
  5737. if not assigned(implprocdefinfo) then
  5738. internalerror(2014010310);
  5739. result:=implprocdefinfo^.skpara;
  5740. end;
  5741. procedure tprocdef.Setskpara(AValue: pointer);
  5742. begin
  5743. if not assigned(implprocdefinfo) then
  5744. internalerror(2014010311);
  5745. implprocdefinfo^.skpara:=AValue;
  5746. end;
  5747. function tprocdef.Getpersonality: tprocdef;
  5748. begin
  5749. if not assigned(implprocdefinfo) then
  5750. internalerror(2016121704);
  5751. result:=implprocdefinfo^.personality;
  5752. end;
  5753. procedure tprocdef.Setpersonality(AValue: tprocdef);
  5754. begin
  5755. if not assigned(implprocdefinfo) then
  5756. internalerror(2016121705);
  5757. implprocdefinfo^.personality:=AValue;
  5758. end;
  5759. function tprocdef.Getforwarddef: boolean;
  5760. begin
  5761. if not assigned(implprocdefinfo) then
  5762. internalerror(2014010312);
  5763. result:=implprocdefinfo^.forwarddef;
  5764. end;
  5765. function tprocdef.Gethasforward: boolean;
  5766. begin
  5767. if not assigned(implprocdefinfo) then
  5768. internalerror(2014010313);
  5769. result:=implprocdefinfo^.hasforward;
  5770. end;
  5771. function tprocdef.Getinterfacedef: boolean;
  5772. begin
  5773. if not assigned(implprocdefinfo) then
  5774. internalerror(2014010314);
  5775. result:=implprocdefinfo^.interfacedef;
  5776. end;
  5777. procedure tprocdef.Setforwarddef(AValue: boolean);
  5778. begin
  5779. if not assigned(implprocdefinfo) then
  5780. internalerror(2014010315);
  5781. implprocdefinfo^.forwarddef:=AValue;
  5782. end;
  5783. procedure tprocdef.Sethasforward(AValue: boolean);
  5784. begin
  5785. if not assigned(implprocdefinfo) then
  5786. internalerror(2014010316);
  5787. implprocdefinfo^.hasforward:=AValue;
  5788. end;
  5789. function tprocdef.GetIsEmpty: boolean;
  5790. begin
  5791. result:=pio_empty in implprocoptions;
  5792. end;
  5793. procedure tprocdef.SetIsEmpty(AValue: boolean);
  5794. begin
  5795. if AValue then
  5796. include(implprocoptions,pio_empty)
  5797. else
  5798. exclude(implprocoptions,pio_empty);
  5799. end;
  5800. function tprocdef.GetHasInliningInfo: boolean;
  5801. begin
  5802. result:=pio_has_inlininginfo in implprocoptions;
  5803. end;
  5804. procedure tprocdef.SetHasInliningInfo(AValue: boolean);
  5805. begin
  5806. if AValue then
  5807. include(implprocoptions,pio_has_inlininginfo)
  5808. else
  5809. exclude(implprocoptions,pio_has_inlininginfo);
  5810. end;
  5811. procedure tprocdef.Setinterfacedef(AValue: boolean);
  5812. begin
  5813. if not assigned(implprocdefinfo) then
  5814. internalerror(2014010317);
  5815. implprocdefinfo^.interfacedef:=AValue;
  5816. end;
  5817. procedure tprocdef.Setprocstarttai(AValue: tai);
  5818. begin
  5819. if not assigned(implprocdefinfo) then
  5820. internalerror(2014010318);
  5821. implprocdefinfo^.procstarttai:=AValue;
  5822. end;
  5823. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  5824. begin
  5825. if not assigned(implprocdefinfo) then
  5826. internalerror(2014010319);
  5827. implprocdefinfo^.parentfpstruct:=AValue;
  5828. end;
  5829. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  5830. begin
  5831. if not assigned(implprocdefinfo) then
  5832. internalerror(2014010320);
  5833. implprocdefinfo^.parentfpstructptrtype:=AValue;
  5834. end;
  5835. constructor tprocdef.create(level:byte;doregister:boolean);
  5836. begin
  5837. inherited create(procdef,level,doregister);
  5838. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  5839. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  5840. {$ifdef symansistr}
  5841. _mangledname:='';
  5842. {$else symansistr}
  5843. _mangledname:=nil;
  5844. {$endif symansistr}
  5845. {$ifndef DISABLE_FAST_OVERLOAD_PATCH}
  5846. seenmarker := nil;
  5847. {$endif}
  5848. fileinfo:=current_filepos;
  5849. extnumber:=$ffff;
  5850. aliasnames:=TCmdStrList.create;
  5851. funcretsym:=nil;
  5852. funcretsymderef.reset;
  5853. procsymderef.reset;
  5854. forwarddef:=true;
  5855. interfacedef:=false;
  5856. hasforward:=false;
  5857. struct := nil;
  5858. structderef.reset;
  5859. import_dll:=nil;
  5860. import_name:=nil;
  5861. import_nr:=0;
  5862. inlininginfo:=nil;
  5863. deprecatedmsg:=nil;
  5864. genericdecltokenbuf:=nil;
  5865. if cs_opt_fastmath in current_settings.optimizerswitches then
  5866. include(implprocoptions, pio_fastmath);
  5867. end;
  5868. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  5869. var
  5870. i,aliasnamescount,sizeleft : longint;
  5871. level : byte;
  5872. buf : array[0..255] of byte;
  5873. begin
  5874. inherited ppuload(procdef,ppufile);
  5875. {$ifdef symansistr}
  5876. if po_has_mangledname in procoptions then
  5877. _mangledname:=ppufile.getansistring
  5878. else
  5879. _mangledname:='';
  5880. {$else symansistr}
  5881. if po_has_mangledname in procoptions then
  5882. _mangledname:=ppufile.getpshortstring
  5883. else
  5884. _mangledname:=nil;
  5885. {$endif symansistr}
  5886. extnumber:=ppufile.getword;
  5887. level:=ppufile.getbyte;
  5888. ppufile.getderef(structderef);
  5889. ppufile.getderef(procsymderef);
  5890. ppufile.getposinfo(fileinfo);
  5891. visibility:=tvisibility(ppufile.getbyte);
  5892. ppufile.getset(tppuset2(symoptions));
  5893. if sp_has_deprecated_msg in symoptions then
  5894. deprecatedmsg:=ppufile.getpshortstring
  5895. else
  5896. deprecatedmsg:=nil;
  5897. { import stuff }
  5898. if po_has_importdll in procoptions then
  5899. import_dll:=ppufile.getpshortstring
  5900. else
  5901. import_dll:=nil;
  5902. if po_has_importname in procoptions then
  5903. import_name:=ppufile.getpshortstring
  5904. else
  5905. import_name:=nil;
  5906. import_nr:=ppufile.getword;
  5907. if (po_msgint in procoptions) then
  5908. messageinf.i:=ppufile.getlongint;
  5909. if (po_msgstr in procoptions) then
  5910. messageinf.str:=ppufile.getpshortstring;
  5911. if (po_dispid in procoptions) then
  5912. dispid:=ppufile.getlongint;
  5913. { inline stuff }
  5914. ppufile.getset(tppuset1(implprocoptions));
  5915. if has_inlininginfo then
  5916. begin
  5917. ppufile.getderef(funcretsymderef);
  5918. new(inlininginfo);
  5919. ppufile.getset(tppuset4(inlininginfo^.flags));
  5920. end
  5921. else
  5922. begin
  5923. inlininginfo:=nil;
  5924. funcretsym:=nil;
  5925. end;
  5926. aliasnames:=TCmdStrList.create;
  5927. { count alias names }
  5928. aliasnamescount:=ppufile.getbyte;
  5929. for i:=1 to aliasnamescount do
  5930. aliasnames.insert(ppufile.getstring);
  5931. { load the token stream containing the declaration }
  5932. sizeleft:=ppufile.getlongint;
  5933. if sizeleft>0 then
  5934. begin
  5935. init_genericdecl;
  5936. while sizeleft>0 do
  5937. begin
  5938. if sizeleft>sizeof(buf) then
  5939. i:=sizeof(buf)
  5940. else
  5941. i:=sizeleft;
  5942. ppufile.getdata(buf,i);
  5943. genericdecltokenbuf.write(buf,i);
  5944. dec(sizeleft,i);
  5945. end;
  5946. end;
  5947. ppuload_platform(ppufile);
  5948. { load para symtable }
  5949. parast:=tparasymtable.create(self,level);
  5950. tparasymtable(parast).ppuload(ppufile);
  5951. { load local symtable }
  5952. if store_localst then
  5953. begin
  5954. localst:=tlocalsymtable.create(self,level);
  5955. tlocalsymtable(localst).ppuload(ppufile);
  5956. end
  5957. else
  5958. localst:=nil;
  5959. { inline stuff }
  5960. if has_inlininginfo then
  5961. inlininginfo^.code:=ppuloadnodetree(ppufile);
  5962. { default values for no persistent data }
  5963. if (cs_link_deffile in current_settings.globalswitches) and
  5964. (tf_need_export in target_info.flags) and
  5965. (po_exports in procoptions) then
  5966. deffile.AddExport(mangledname);
  5967. { Disable po_has_inlining until the derefimpl is done }
  5968. has_inlininginfo:=false;
  5969. end;
  5970. destructor tprocdef.destroy;
  5971. begin
  5972. aliasnames.free;
  5973. aliasnames:=nil;
  5974. if assigned(localst) and
  5975. (localst.symtabletype<>staticsymtable) then
  5976. begin
  5977. {$ifdef MEMDEBUG}
  5978. memproclocalst.start;
  5979. {$endif MEMDEBUG}
  5980. localst.free;
  5981. localst:=nil;
  5982. {$ifdef MEMDEBUG}
  5983. memproclocalst.start;
  5984. {$endif MEMDEBUG}
  5985. end;
  5986. if assigned(inlininginfo) then
  5987. begin
  5988. {$ifdef MEMDEBUG}
  5989. memprocnodetree.start;
  5990. {$endif MEMDEBUG}
  5991. tnode(inlininginfo^.code).free;
  5992. {$ifdef MEMDEBUG}
  5993. memprocnodetree.start;
  5994. {$endif MEMDEBUG}
  5995. dispose(inlininginfo);
  5996. inlininginfo:=nil;
  5997. end;
  5998. freeimplprocdefinfo;
  5999. genericdecltokenbuf.free;
  6000. genericdecltokenbuf:=nil;
  6001. stringdispose(import_dll);
  6002. stringdispose(import_name);
  6003. stringdispose(deprecatedmsg);
  6004. if (po_msgstr in procoptions) then
  6005. stringdispose(messageinf.str);
  6006. {$ifndef symansistr}
  6007. if assigned(_mangledname) then
  6008. begin
  6009. {$ifdef MEMDEBUG}
  6010. memmanglednames.start;
  6011. {$endif MEMDEBUG}
  6012. stringdispose(_mangledname);
  6013. {$ifdef MEMDEBUG}
  6014. memmanglednames.stop;
  6015. {$endif MEMDEBUG}
  6016. end;
  6017. {$endif symansistr}
  6018. inherited destroy;
  6019. end;
  6020. procedure tprocdef.freeimplprocdefinfo;
  6021. begin
  6022. if assigned(implprocdefinfo) then
  6023. begin
  6024. stringdispose(implprocdefinfo^.resultname);
  6025. TFPList.FreeAndNilDisposing(implprocdefinfo^.capturedsyms,typeinfo(tcapturedsyminfo));
  6026. freemem(implprocdefinfo);
  6027. implprocdefinfo:=nil;
  6028. end;
  6029. end;
  6030. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  6031. var
  6032. oldintfcrc : boolean;
  6033. aliasnamescount,i,sizeleft : longint;
  6034. item : TCmdStrListItem;
  6035. buf : array[0..255] of byte;
  6036. begin
  6037. { released procdef? }
  6038. if not assigned(parast) then
  6039. exit;
  6040. inherited ppuwrite(ppufile);
  6041. {$ifdef symansistr}
  6042. if po_has_mangledname in procoptions then
  6043. ppufile.putansistring(_mangledname);
  6044. {$else symansistr}
  6045. if po_has_mangledname in procoptions then
  6046. ppufile.putstring(_mangledname^);
  6047. {$endif symansistr}
  6048. ppufile.putword(extnumber);
  6049. ppufile.putbyte(parast.symtablelevel);
  6050. ppufile.putderef(structderef);
  6051. ppufile.putderef(procsymderef);
  6052. ppufile.putposinfo(fileinfo);
  6053. ppufile.putbyte(byte(visibility));
  6054. ppufile.putset(tppuset2(symoptions));
  6055. if sp_has_deprecated_msg in symoptions then
  6056. ppufile.putstring(deprecatedmsg^);
  6057. { import }
  6058. if po_has_importdll in procoptions then
  6059. ppufile.putstring(import_dll^);
  6060. if po_has_importname in procoptions then
  6061. ppufile.putstring(import_name^);
  6062. ppufile.putword(import_nr);
  6063. if (po_msgint in procoptions) then
  6064. ppufile.putlongint(messageinf.i);
  6065. if (po_msgstr in procoptions) then
  6066. ppufile.putstring(messageinf.str^);
  6067. if (po_dispid in procoptions) then
  6068. ppufile.putlongint(dispid);
  6069. { inline stuff }
  6070. oldintfcrc:=ppufile.do_crc;
  6071. ppufile.do_crc:=false;
  6072. ppufile.putset(tppuset1(implprocoptions));
  6073. if has_inlininginfo then
  6074. begin
  6075. ppufile.putderef(funcretsymderef);
  6076. ppufile.putset(tppuset4(inlininginfo^.flags));
  6077. end;
  6078. { count alias names }
  6079. aliasnamescount:=0;
  6080. item:=TCmdStrListItem(aliasnames.first);
  6081. while assigned(item) do
  6082. begin
  6083. inc(aliasnamescount);
  6084. item:=TCmdStrListItem(item.next);
  6085. end;
  6086. if aliasnamescount>255 then
  6087. internalerror(200711021);
  6088. ppufile.putbyte(aliasnamescount);
  6089. item:=TCmdStrListItem(aliasnames.first);
  6090. while assigned(item) do
  6091. begin
  6092. ppufile.putstring(item.str);
  6093. item:=TCmdStrListItem(item.next);
  6094. end;
  6095. ppufile.do_crc:=oldintfcrc;
  6096. { generic tokens for the declaration }
  6097. if assigned(genericdecltokenbuf) and (genericdecltokenbuf.size>0) then
  6098. begin
  6099. sizeleft:=genericdecltokenbuf.size;
  6100. genericdecltokenbuf.seek(0);
  6101. ppufile.putlongint(sizeleft);
  6102. while sizeleft>0 do
  6103. begin
  6104. if sizeleft>sizeof(buf) then
  6105. i:=sizeof(buf)
  6106. else
  6107. i:=sizeleft;
  6108. genericdecltokenbuf.read(buf,i);
  6109. ppufile.putdata(buf,i);
  6110. dec(sizeleft,i);
  6111. end;
  6112. end
  6113. else
  6114. ppufile.putlongint(0);
  6115. { write this entry }
  6116. writeentry(ppufile,ibprocdef);
  6117. { Save the para symtable, this is taken from the interface }
  6118. tparasymtable(parast).ppuwrite(ppufile);
  6119. { save localsymtable for inline procedures or when local
  6120. browser info is requested, this has no influence on the crc }
  6121. if store_localst and not ppufile.crc_only then
  6122. begin
  6123. oldintfcrc:=ppufile.do_crc;
  6124. ppufile.do_crc:=false;
  6125. tlocalsymtable(localst).ppuwrite(ppufile);
  6126. ppufile.do_crc:=oldintfcrc;
  6127. end;
  6128. { node tree for inlining }
  6129. oldintfcrc:=ppufile.do_crc;
  6130. ppufile.do_crc:=false;
  6131. if has_inlininginfo then
  6132. ppuwritenodetree(ppufile,inlininginfo^.code);
  6133. ppufile.do_crc:=oldintfcrc;
  6134. end;
  6135. function tprocdef.fullprocname(showhidden:boolean):string;
  6136. var
  6137. pno: tprocnameoptions;
  6138. begin
  6139. pno:=[];
  6140. if showhidden then
  6141. include(pno,pno_showhidden);
  6142. result:=customprocname(pno);
  6143. end;
  6144. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  6145. var
  6146. s, hs, rn : ansistring;
  6147. t : ttoken;
  6148. module : tmodule;
  6149. syssym : tsyssym;
  6150. begin
  6151. {$ifdef EXTDEBUG}
  6152. include(pno,pno_showhidden);
  6153. {$endif EXTDEBUG}
  6154. s:='';
  6155. rn:='';
  6156. if proctypeoption=potype_operator then
  6157. begin
  6158. for t:=NOTOKEN to last_overloaded do
  6159. if procsym.realname='$'+overloaded_names[t] then
  6160. begin
  6161. s:='operator ';
  6162. if (pno_ownername in pno) and
  6163. assigned(struct) then
  6164. s:=s+struct.RttiName+'.';
  6165. s:=s+arraytokeninfo[t].str;
  6166. if not (pno_noparams in pno) then
  6167. s:=s+typename_paras(pno);
  6168. break;
  6169. end;
  6170. end
  6171. else
  6172. begin
  6173. if (po_classmethod in procoptions) and
  6174. not(pno_noclassmarker in pno) then
  6175. s:='class ';
  6176. case proctypeoption of
  6177. potype_constructor,
  6178. potype_class_constructor:
  6179. s:=s+'constructor ';
  6180. potype_class_destructor,
  6181. potype_destructor:
  6182. s:=s+'destructor ';
  6183. else
  6184. if (pno_proctypeoption in pno) and not (po_anonymous in procoptions) then
  6185. begin
  6186. if assigned(returndef) and
  6187. not(is_void(returndef)) then
  6188. s:=s+'function '
  6189. else
  6190. s:=s+'procedure ';
  6191. end;
  6192. end;
  6193. if (pno_ownername in pno) and
  6194. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  6195. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  6196. if (po_compilerproc in procoptions) and (extnumber<>$ffff) then
  6197. begin
  6198. syssym:=tsyssym.find_by_number(extnumber);
  6199. if not assigned(syssym) then
  6200. internalerror(2016060305);
  6201. rn:=syssym.realname;
  6202. end
  6203. else if po_anonymous in procoptions then
  6204. begin
  6205. s:=s+'anonymous ';
  6206. if assigned(returndef) and
  6207. not(is_void(returndef)) then
  6208. s:=s+'function'
  6209. else
  6210. s:=s+'procedure';
  6211. end
  6212. else if pno_prettynames in pno then
  6213. rn:=procsym.prettyname
  6214. else
  6215. rn:=procsym.RealName;
  6216. if (pno_noleadingdollar in pno) and
  6217. (rn[1]='$') then
  6218. delete(rn,1,1);
  6219. s:=s+rn;
  6220. if not (pno_noparams in pno) then
  6221. s:=s+typename_paras(pno);
  6222. end;
  6223. if not(proctypeoption in [potype_constructor,potype_destructor,
  6224. potype_class_constructor,potype_class_destructor]) and
  6225. assigned(returndef) and
  6226. not(is_void(returndef)) then
  6227. begin
  6228. if assigned(returndef.typesym) then
  6229. begin
  6230. module:=find_module_from_symtable(returndef.typesym.owner);
  6231. if module <> current_module then
  6232. s:=s+':'+module.realmodulename^+'.'
  6233. else
  6234. s:=s+':';
  6235. if pno_prettynames in pno then
  6236. hs:=returndef.typesym.prettyname
  6237. else
  6238. hs:=returndef.typesym.realname;
  6239. if hs[1]<>'$' then
  6240. s:=s+returndef.OwnerHierarchyName+hs
  6241. else
  6242. s:=s+returndef.GetTypeName;
  6243. end
  6244. else
  6245. s:=s+':'+returndef.GetTypeName;
  6246. end;
  6247. if not (po_anonymous in procoptions) then
  6248. if assigned(owner) and (owner.symtabletype=localsymtable) then
  6249. s:=s+' is nested'
  6250. else if po_is_block in procoptions then
  6251. s:=s+' is block';
  6252. s:=s+';';
  6253. if po_far in procoptions then
  6254. s:=s+' far;';
  6255. { forced calling convention? }
  6256. if (po_hascallingconvention in procoptions) then
  6257. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  6258. if (po_staticmethod in procoptions) and
  6259. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  6260. s:=s+' Static;';
  6261. if pno_mangledname in pno then
  6262. s:=s+' -- mangled name: '+mangledname;
  6263. customprocname:=s;
  6264. end;
  6265. function tprocdef.is_methodpointer:boolean;
  6266. begin
  6267. { don't check assigned(_class), that's also the case for nested
  6268. procedures inside methods }
  6269. result:=(owner.symtabletype in [recordsymtable,ObjectSymtable]) and not no_self_node;
  6270. end;
  6271. function tprocdef.is_addressonly:boolean;
  6272. begin
  6273. result:=assigned(owner) and
  6274. not is_methodpointer and
  6275. (not(m_nested_procvars in current_settings.modeswitches) or
  6276. not is_nested_pd(self)) and
  6277. (
  6278. not (po_anonymous in procoptions) or
  6279. not assigned(capturedsyms) or
  6280. (capturedsyms.count=0)
  6281. );
  6282. end;
  6283. procedure tprocdef.make_external;
  6284. begin
  6285. include(procoptions,po_external);
  6286. forwarddef:=false;
  6287. end;
  6288. procedure tprocdef.init_genericdecl;
  6289. begin
  6290. if assigned(genericdecltokenbuf) then
  6291. internalerror(2015061901);
  6292. genericdecltokenbuf:=tdynamicarray.create(256);
  6293. end;
  6294. procedure tprocdef.reset_after_conv;
  6295. begin
  6296. _parentfpsym:=nil;
  6297. end;
  6298. function tprocdef.get_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  6299. begin
  6300. result:=false;
  6301. if proctypeoption=potype_constructor then
  6302. begin
  6303. result:=true;
  6304. ressym:=tsym(parast.Find('self'));
  6305. resdef:=tabstractnormalvarsym(ressym).vardef;
  6306. { and TP-style constructors return a pointer to self }
  6307. if is_object(resdef) then
  6308. resdef:=cpointerdef.getreusable(resdef);
  6309. end
  6310. else if (proccalloption=pocall_safecall) and
  6311. (tf_safecall_exceptions in target_info.flags) then
  6312. begin
  6313. result:=true;
  6314. ressym:=tsym(localst.Find('safecallresult'));
  6315. resdef:=tabstractnormalvarsym(ressym).vardef;
  6316. end
  6317. else if not is_void(returndef) then
  6318. begin
  6319. result:=true;
  6320. ressym:=funcretsym;
  6321. resdef:=tabstractnormalvarsym(ressym).vardef;
  6322. end;
  6323. end;
  6324. function tprocdef.get_safecall_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  6325. begin
  6326. result:=false;
  6327. if (proctypeoption<>potype_constructor) and
  6328. (proccalloption=pocall_safecall) and
  6329. (tf_safecall_exceptions in target_info.flags) then
  6330. begin
  6331. result:=true;
  6332. ressym:=tsym(localst.Find('safecallresult'));
  6333. resdef:=tabstractnormalvarsym(ressym).vardef;
  6334. end
  6335. end;
  6336. procedure tprocdef.add_captured_sym(sym:tsym;def:tdef;const filepos:tfileposinfo);
  6337. var
  6338. i : longint;
  6339. capturedsym : pcapturedsyminfo;
  6340. begin
  6341. if not assigned(implprocdefinfo) then
  6342. internalerror(2021052601);
  6343. if not assigned(implprocdefinfo^.capturedsyms) then
  6344. implprocdefinfo^.capturedsyms:=tfplist.create;
  6345. for i:=0 to implprocdefinfo^.capturedsyms.count-1 do
  6346. begin
  6347. capturedsym:=pcapturedsyminfo(implprocdefinfo^.capturedsyms[i]);
  6348. if (capturedsym^.sym=sym) and (capturedsym^.def=def) then
  6349. exit;
  6350. end;
  6351. new(capturedsym);
  6352. capturedsym^.sym:=sym;
  6353. capturedsym^.def:=def;
  6354. capturedsym^.fileinfo:=filepos;
  6355. implprocdefinfo^.capturedsyms.add(capturedsym);
  6356. end;
  6357. function tprocdef.has_alias_name(const s: TSymStr): boolean;
  6358. var
  6359. item : TCmdStrListItem;
  6360. begin
  6361. result:=true;
  6362. if mangledname=s then
  6363. exit;
  6364. item:=TCmdStrListItem(aliasnames.first);
  6365. while assigned(item) do
  6366. begin
  6367. if item.str=s then
  6368. exit;
  6369. item:=TCmdStrListItem(item.next);
  6370. end;
  6371. result:=false;
  6372. end;
  6373. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  6374. begin
  6375. case t of
  6376. gs_local :
  6377. GetSymtable:=localst;
  6378. gs_para :
  6379. GetSymtable:=parast;
  6380. else
  6381. GetSymtable:=nil;
  6382. end;
  6383. end;
  6384. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  6385. var
  6386. j : longint;
  6387. begin
  6388. result:=inherited;
  6389. if newtyp=procvardef then
  6390. begin
  6391. { create new paralist }
  6392. tprocvardef(result).calcparas;
  6393. exit;
  6394. end;
  6395. { don't copy mangled name, can be different }
  6396. tprocdef(result).messageinf:=messageinf;
  6397. tprocdef(result).dispid:=dispid;
  6398. if po_msgstr in procoptions then
  6399. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  6400. tprocdef(result).symoptions:=symoptions;
  6401. if assigned(deprecatedmsg) then
  6402. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  6403. { will have to be associated with appropriate procsym }
  6404. tprocdef(result).procsym:=nil;
  6405. { don't create aliases for bare copies, nor copy the funcretsym as
  6406. the function result parameter will be inserted again if necessary
  6407. (e.g. if the calling convention is changed) }
  6408. if not(copytyp in [pc_bareproc,pc_normal_no_hidden]) then
  6409. begin
  6410. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  6411. if assigned(funcretsym) then
  6412. begin
  6413. if funcretsym.owner=parast then
  6414. begin
  6415. j:=parast.symlist.indexof(funcretsym);
  6416. if j<0 then
  6417. internalerror(2011040606);
  6418. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  6419. end
  6420. else if funcretsym.owner=localst then
  6421. begin
  6422. { nothing to do, will be inserted for the new procdef while
  6423. parsing its body (by pdecsub.insert_funcret_local) }
  6424. end
  6425. else
  6426. internalerror(2011040605);
  6427. end;
  6428. end;
  6429. { will have to be associated with a new struct }
  6430. tprocdef(result).struct:=nil;
  6431. if assigned(implprocdefinfo) then
  6432. begin
  6433. if assigned(resultname) then
  6434. tprocdef(result).resultname:=stringdup(resultname^);
  6435. tprocdef(result).synthetickind:=synthetickind;
  6436. end;
  6437. if assigned(import_dll) then
  6438. tprocdef(result).import_dll:=stringdup(import_dll^);
  6439. if assigned(import_name) then
  6440. tprocdef(result).import_name:=stringdup(import_name^);
  6441. tprocdef(result).import_nr:=import_nr;
  6442. tprocdef(result).extnumber:=$ffff;
  6443. tprocdef(result).visibility:=visibility;
  6444. { we need a separate implementation for the copied def }
  6445. tprocdef(result).forwarddef:=true;
  6446. tprocdef(result).interfacedef:=true;
  6447. { create new paralist }
  6448. tprocdef(result).calcparas;
  6449. end;
  6450. function tprocdef.getcopy: tstoreddef;
  6451. begin
  6452. result:=getcopyas(procdef,pc_normal,'',true);
  6453. end;
  6454. procedure tprocdef.buildderef;
  6455. begin
  6456. inherited buildderef;
  6457. structderef.build(struct);
  6458. { procsym that originaly defined this definition, should be in the
  6459. same symtable }
  6460. procsymderef.build(procsym);
  6461. end;
  6462. procedure tprocdef.buildderefimpl;
  6463. begin
  6464. inherited buildderefimpl;
  6465. { Localst is not available for main/unit init }
  6466. if store_localst and assigned(localst) then
  6467. begin
  6468. tlocalsymtable(localst).buildderef;
  6469. tlocalsymtable(localst).buildderefimpl;
  6470. end;
  6471. { inline tree }
  6472. if has_inlininginfo then
  6473. begin
  6474. funcretsymderef.build(funcretsym);
  6475. inlininginfo^.code.buildderefimpl;
  6476. end;
  6477. end;
  6478. procedure tprocdef.deref;
  6479. begin
  6480. inherited deref;
  6481. struct:=tabstractrecorddef(structderef.resolve);
  6482. { procsym that originaly defined this definition, should be in the
  6483. same symtable }
  6484. procsym:=tprocsym(procsymderef.resolve);
  6485. end;
  6486. procedure tprocdef.derefimpl;
  6487. begin
  6488. { Enable has_inlininginfo when the inlininginfo
  6489. structure is available. The has_inlininginfo was disabled
  6490. after the load, since the data was invalid }
  6491. if assigned(inlininginfo) then
  6492. has_inlininginfo:=true;
  6493. { Locals }
  6494. if store_localst and assigned(localst) then
  6495. begin
  6496. tlocalsymtable(localst).deref(false);
  6497. tlocalsymtable(localst).derefimpl(false);
  6498. end;
  6499. { Inline }
  6500. if has_inlininginfo then
  6501. begin
  6502. inlininginfo^.code.derefimpl;
  6503. { funcretsym, this is always located in the localst }
  6504. funcretsym:=tsym(funcretsymderef.resolve);
  6505. end
  6506. else
  6507. begin
  6508. { safety }
  6509. { Not safe! A unit may be reresolved after its interface has been
  6510. parsed but before its implementation has been parsed, and in that
  6511. case the funcretsym is still required!
  6512. funcretsym:=nil; }
  6513. end;
  6514. end;
  6515. function tprocdef.GetTypeName : string;
  6516. begin
  6517. GetTypeName := FullProcName(false);
  6518. end;
  6519. function tprocdef.mangledname : TSymStr;
  6520. begin
  6521. {$ifdef symansistr}
  6522. if _mangledname='' then
  6523. begin
  6524. result:=defaultmangledname;
  6525. _mangledname:=result;
  6526. end
  6527. else
  6528. result:=_mangledname;
  6529. {$else symansistr}
  6530. if not assigned(_mangledname) then
  6531. begin
  6532. result:=defaultmangledname;
  6533. _mangledname:=stringdup(mangledname);
  6534. end
  6535. else
  6536. result:=_mangledname^;
  6537. {$endif symansistr}
  6538. end;
  6539. function tprocdef.defaultmangledname: TSymStr;
  6540. var
  6541. n : TSymStr;
  6542. begin
  6543. n:=procsym.name;
  6544. { make sure that the mangled names of these overloadable methods types is
  6545. unique even if it's made lowercase (e.g. for section names) }
  6546. if proctypeoption in [potype_operator,potype_class_constructor,potype_class_destructor] then
  6547. n:='$'+n;
  6548. { we need to use the symtable where the procsym is inserted,
  6549. because that is visible to the world }
  6550. defaultmangledname:=make_mangledname('',procsym.owner,n);
  6551. defaultmangledname:=defaultmangledname+mangledprocparanames(Length(defaultmangledname))
  6552. end;
  6553. function tprocdef.cplusplusmangledname : TSymStr;
  6554. function getcppparaname(p : tdef) : TSymStr;
  6555. const
  6556. {$ifdef NAMEMANGLING_GCC2}
  6557. ordtype2str : array[tordtype] of string[2] = (
  6558. '',
  6559. 'Uc','Us','Ui','Us','',
  6560. 'Sc','s','i','x','',
  6561. 'b','b','b','b','b','b',
  6562. 'c','w','x');
  6563. {$else NAMEMANGLING_GCC2}
  6564. ordtype2str : array[tordtype] of string[1] = (
  6565. 'v',
  6566. 'h','t','j','y','',
  6567. 'a','s','i','x','',
  6568. 'b','b','b','b','b',
  6569. 'b','b','b','b',
  6570. 'c','w','x','C');
  6571. floattype2str : array[tfloattype] of string[1] = (
  6572. 'f','d','e','e',
  6573. 'd','d','g');
  6574. {$endif NAMEMANGLING_GCC2}
  6575. var
  6576. s : TSymStr;
  6577. begin
  6578. case p.typ of
  6579. orddef:
  6580. begin
  6581. s:=ordtype2str[torddef(p).ordtype];
  6582. if s='C' then
  6583. s:=ordtype2str[range_to_basetype(torddef(p).low,torddef(p).high)];
  6584. end;
  6585. pointerdef:
  6586. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  6587. {$ifndef NAMEMANGLING_GCC2}
  6588. floatdef:
  6589. s:=floattype2str[tfloatdef(p).floattype];
  6590. {$endif NAMEMANGLING_GCC2}
  6591. else
  6592. internalerror(2103001);
  6593. end;
  6594. getcppparaname:=s;
  6595. end;
  6596. var
  6597. s,s2 : TSymStr;
  6598. hp : TParavarsym;
  6599. i : integer;
  6600. begin
  6601. {$ifdef NAMEMANGLING_GCC2}
  6602. { outdated gcc 2.x name mangling scheme }
  6603. s := procsym.realname;
  6604. if procsym.owner.symtabletype=ObjectSymtable then
  6605. begin
  6606. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  6607. case proctypeoption of
  6608. potype_destructor:
  6609. s:='_$_'+tostr(length(s2))+s2;
  6610. potype_constructor:
  6611. s:='___'+tostr(length(s2))+s2;
  6612. else
  6613. s:='_'+s+'__'+tostr(length(s2))+s2;
  6614. end;
  6615. end
  6616. else s:=s+'__';
  6617. s:=s+'F';
  6618. { concat modifiers }
  6619. { !!!!! }
  6620. { now we handle the parameters }
  6621. if maxparacount>0 then
  6622. begin
  6623. for i:=0 to paras.count-1 do
  6624. begin
  6625. hp:=tparavarsym(paras[i]);
  6626. { no hidden parameters form part of a C++ mangled name:
  6627. a) self is not included
  6628. b) there are no "high" or other hidden parameters
  6629. }
  6630. if vo_is_hidden_para in hp.varoptions then
  6631. continue;
  6632. s2:=getcppparaname(hp.vardef);
  6633. if hp.varspez in [vs_var,vs_out] then
  6634. s2:='R'+s2;
  6635. s:=s+s2;
  6636. end;
  6637. end
  6638. else
  6639. s:=s+'v';
  6640. cplusplusmangledname:=s;
  6641. {$else NAMEMANGLING_GCC2}
  6642. { gcc 3.x and 4.x name mangling scheme }
  6643. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  6644. if procsym.owner.symtabletype=ObjectSymtable then
  6645. begin
  6646. s:='_ZN';
  6647. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  6648. s:=s+tostr(length(s2))+s2;
  6649. case proctypeoption of
  6650. potype_constructor:
  6651. s:=s+'C1';
  6652. potype_destructor:
  6653. s:=s+'D1';
  6654. else
  6655. s:=s+tostr(length(procsym.realname))+procsym.realname;
  6656. end;
  6657. s:=s+'E';
  6658. end
  6659. else
  6660. s:=procsym.realname;
  6661. { now we handle the parameters }
  6662. if maxparacount>0 then
  6663. begin
  6664. for i:=0 to paras.count-1 do
  6665. begin
  6666. hp:=tparavarsym(paras[i]);
  6667. { no hidden parameters form part of a C++ mangled name:
  6668. a) self is not included
  6669. b) there are no "high" or other hidden parameters
  6670. }
  6671. if vo_is_hidden_para in hp.varoptions then
  6672. continue;
  6673. s2:=getcppparaname(hp.vardef);
  6674. if hp.varspez in [vs_var,vs_out] then
  6675. s2:='R'+s2;
  6676. s:=s+s2;
  6677. end;
  6678. end
  6679. else
  6680. s:=s+'v';
  6681. cplusplusmangledname:=s;
  6682. {$endif NAMEMANGLING_GCC2}
  6683. end;
  6684. function tprocdef.objcmangledname : TSymStr;
  6685. var
  6686. manglednamelen: longint;
  6687. iscatmethod : boolean;
  6688. begin
  6689. if not (po_msgstr in procoptions) then
  6690. internalerror(2009030901);
  6691. { we may very well need longer strings to handle these... }
  6692. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  6693. length('+"[ ]"')+length(messageinf.str^);
  6694. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  6695. if (iscatmethod) then
  6696. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  6697. if manglednamelen>255 then
  6698. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  6699. if not(po_classmethod in procoptions) then
  6700. result:='"-['
  6701. else
  6702. result:='"+[';
  6703. { quotes are necessary because the +/- otherwise confuse the assembler
  6704. into expecting a number
  6705. }
  6706. if iscatmethod then
  6707. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  6708. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  6709. if iscatmethod then
  6710. result:=result+')';
  6711. result:=result+' '+messageinf.str^+']"';
  6712. end;
  6713. procedure tprocdef.setmangledname(const s : TSymStr);
  6714. begin
  6715. { This is not allowed anymore, the forward declaration
  6716. already needs to create the correct mangledname, no changes
  6717. afterwards are allowed (PFV) }
  6718. { Exception: interface definitions in mode macpas, since in that }
  6719. { case no reference to the old name can exist yet (JM) }
  6720. {$ifdef symansistr}
  6721. if _mangledname<>'' then
  6722. if ((m_mac in current_settings.modeswitches) and
  6723. (interfacedef)) then
  6724. _mangledname:=''
  6725. else
  6726. internalerror(200411171);
  6727. {$else symansistr}
  6728. if assigned(_mangledname) then
  6729. if ((m_mac in current_settings.modeswitches) and
  6730. (interfacedef)) then
  6731. stringdispose(_mangledname)
  6732. else
  6733. internalerror(200411171);
  6734. {$endif symansistr}
  6735. {$ifdef jvm}
  6736. { this routine can be called for compilerproces. can't set mangled
  6737. name since it must be calculated, but it uses import_name when set
  6738. -> set that one }
  6739. import_name:=stringdup(s);
  6740. include(procoptions,po_has_importname);
  6741. include(procoptions,po_has_mangledname);
  6742. {$else}
  6743. {$ifdef symansistr}
  6744. _mangledname:=s;
  6745. {$else symansistr}
  6746. _mangledname:=stringdup(s);
  6747. {$endif symansistr}
  6748. {$endif jvm}
  6749. include(procoptions,po_has_mangledname);
  6750. end;
  6751. function tprocdef.needsglobalasmsym: boolean;
  6752. begin
  6753. result:=
  6754. (cs_profile in current_settings.moduleswitches) or
  6755. { smart linking using a library requires to promote
  6756. all non-nested procedures to AB_GLOBAL
  6757. otherwise you get undefined symbol error at linking
  6758. for msdos target with -CX option for instance }
  6759. (create_smartlink_library and not is_nested_pd(self)) or
  6760. (po_global in procoptions);
  6761. end;
  6762. procedure tprocdef.setcompilerprocname;
  6763. begin
  6764. procsym.realname:='$'+lower(procsym.name);
  6765. end;
  6766. {***************************************************************************
  6767. TPROCVARDEF
  6768. ***************************************************************************}
  6769. constructor tprocvardef.create(level:byte;doregister:boolean);
  6770. begin
  6771. inherited create(procvardef,level,doregister);
  6772. end;
  6773. class function tprocvardef.getreusableprocaddr(def: tabstractprocdef; copytyp: tcacheableproccopytyp): tprocvardef;
  6774. var
  6775. res: PHashSetItem;
  6776. oldsymtablestack: tsymtablestack;
  6777. key: packed record
  6778. def: tabstractprocdef;
  6779. copytyp: tcacheableproccopytyp;
  6780. end;
  6781. begin
  6782. if not assigned(current_module) then
  6783. internalerror(2011081302);
  6784. key.def:=def;
  6785. key.copytyp:=copytyp;
  6786. res:=current_module.procaddrdefs.FindOrAdd(@key,sizeof(key));
  6787. if not assigned(res^.Data) then
  6788. begin
  6789. { since these pointerdefs can be reused anywhere in the current
  6790. unit, add them to the global/staticsymtable (or local symtable
  6791. if they're a local def, because otherwise they'll be saved
  6792. to the ppu referencing a local symtable entry that doesn't
  6793. exist in the ppu) }
  6794. oldsymtablestack:=symtablestack;
  6795. { do not simply push/pop current_module.localsymtable, because
  6796. that can have side-effects (e.g., it removes helpers) }
  6797. symtablestack:=nil;
  6798. result:=tprocvardef(def.getcopyas(procvardef,copytyp,'',true));
  6799. setup_reusable_def(def,result,res,oldsymtablestack);
  6800. { res^.Data may still be nil -> don't overwrite result }
  6801. exit;
  6802. end;
  6803. result:=tprocvardef(res^.Data);
  6804. end;
  6805. class function tprocvardef.getreusableprocaddr_no_free(def: tabstractprocdef): tprocvardef;
  6806. begin
  6807. result:=getreusableprocaddr(def,pc_address_only);
  6808. if not result.is_registered then
  6809. include(result.defoptions,df_not_registered_no_free);
  6810. end;
  6811. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  6812. begin
  6813. inherited ppuload(procvardef,ppufile);
  6814. { load para symtable }
  6815. parast:=tparasymtable.create(self,ppufile.getbyte);
  6816. ppuload_platform(ppufile);
  6817. tparasymtable(parast).ppuload(ppufile);
  6818. end;
  6819. function tprocvardef.getcopy : tstoreddef;
  6820. var
  6821. i : tcallercallee;
  6822. j : longint;
  6823. begin
  6824. result:=cprocvardef.create(parast.symtablelevel,true);
  6825. tprocvardef(result).returndef:=returndef;
  6826. tprocvardef(result).returndefderef:=returndefderef;
  6827. tprocvardef(result).parast:=parast.getcopy;
  6828. tprocvardef(result).savesize:=savesize;
  6829. { create paralist copy }
  6830. calcparas;
  6831. tprocvardef(result).paras:=tparalist.create(false);
  6832. tprocvardef(result).paras.count:=paras.count;
  6833. for j:=0 to paras.count-1 do
  6834. tprocvardef(result).paras[j]:=paras[j];
  6835. tprocvardef(result).proctypeoption:=proctypeoption;
  6836. tprocvardef(result).proccalloption:=proccalloption;
  6837. tprocvardef(result).procoptions:=procoptions;
  6838. tprocvardef(result).callerargareasize:=callerargareasize;
  6839. tprocvardef(result).calleeargareasize:=calleeargareasize;
  6840. tprocvardef(result).maxparacount:=maxparacount;
  6841. tprocvardef(result).minparacount:=minparacount;
  6842. for i:=low(funcretloc) to high(funcretloc) do
  6843. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  6844. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  6845. {$ifdef m68k}
  6846. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  6847. {$endif}
  6848. end;
  6849. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  6850. begin
  6851. inherited ppuwrite(ppufile);
  6852. { Save the para symtable level (necessary to distinguish nested
  6853. procvars) }
  6854. ppufile.putbyte(parast.symtablelevel);
  6855. { Write this entry }
  6856. writeentry(ppufile,ibprocvardef);
  6857. { Save the para symtable, this is taken from the interface }
  6858. tparasymtable(parast).ppuwrite(ppufile);
  6859. end;
  6860. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  6861. begin
  6862. case t of
  6863. gs_para :
  6864. GetSymtable:=parast;
  6865. else
  6866. GetSymtable:=nil;
  6867. end;
  6868. end;
  6869. function tprocvardef.size : asizeint;
  6870. begin
  6871. { we return false for is_addressonly for a block (because it's not a
  6872. simple pointer to a function), but they are handled as implicit
  6873. pointers to a datastructure that contains everything ->
  6874. voidpointertype.size instead of voidcodepointertype.size }
  6875. if po_is_block in procoptions then
  6876. size:=voidpointertype.size
  6877. else if not is_addressonly then
  6878. begin
  6879. if is_nested_pd(self) then
  6880. size:=voidcodepointertype.size+parentfpvoidpointertype.size
  6881. else
  6882. size:=voidcodepointertype.size+voidpointertype.size;
  6883. end
  6884. else
  6885. size:=voidcodepointertype.size;
  6886. end;
  6887. function tprocvardef.is_methodpointer:boolean;
  6888. begin
  6889. result:=(po_methodpointer in procoptions);
  6890. end;
  6891. function tprocvardef.is_addressonly:boolean;
  6892. begin
  6893. result:=((not(po_methodpointer in procoptions) or (po_staticmethod in procoptions)) and
  6894. not(po_is_block in procoptions) and
  6895. not is_nested_pd(self)) or
  6896. (po_addressonly in procoptions);
  6897. end;
  6898. function tprocvardef.getmangledparaname:TSymStr;
  6899. begin
  6900. if not(po_methodpointer in procoptions) then
  6901. if not is_nested_pd(self) then
  6902. result:='procvar'
  6903. else
  6904. { we need the manglednames here, because nestedprocvars can be anonymous, e.g.
  6905. having not a type name or not an unique one, see webtbs/tw27515.pp
  6906. Further, use $_ ... _$ delimiters to avoid ambiguous names, see webtbs/tw27515.pp }
  6907. result:='$_nestedprovar'+mangledprocparanames(0)+'_$'
  6908. else
  6909. result:='procvarofobj'
  6910. end;
  6911. function tprocvardef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  6912. begin
  6913. result:=inherited;
  6914. tabstractprocdef(result).calcparas;
  6915. end;
  6916. function tprocvardef.is_publishable : tpublishproperty;
  6917. begin
  6918. if po_methodpointer in procoptions then
  6919. is_publishable:=pp_publish
  6920. else
  6921. is_publishable:=pp_error;
  6922. end;
  6923. function tprocvardef.GetTypeName : string;
  6924. var
  6925. s: string;
  6926. pno : tprocnameoptions;
  6927. begin
  6928. {$ifdef EXTDEBUG}
  6929. pno:=[pno_showhidden];
  6930. {$else EXTDEBUG}
  6931. pno:=[];
  6932. {$endif EXTDEBUG}
  6933. s:='<';
  6934. if po_is_block in procoptions then
  6935. s := s+'reference to'
  6936. else if po_classmethod in procoptions then
  6937. s := s+'class method type of'
  6938. else
  6939. if po_addressonly in procoptions then
  6940. s := s+'address of'
  6941. else
  6942. s := s+'procedure variable type of';
  6943. if assigned(returndef) and
  6944. (returndef<>voidtype) then
  6945. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  6946. else
  6947. s:=s+' procedure'+typename_paras(pno);
  6948. if po_methodpointer in procoptions then
  6949. s := s+' of object';
  6950. if is_nested_pd(self) then
  6951. s := s+' is nested';
  6952. if po_far in procoptions then
  6953. s := s+';far';
  6954. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  6955. end;
  6956. {***************************************************************************
  6957. TOBJECTDEF
  6958. ***************************************************************************}
  6959. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef;doregister:boolean);
  6960. begin
  6961. inherited create(n,objectdef,doregister);
  6962. fcurrent_dispid:=0;
  6963. objecttype:=ot;
  6964. childof:=nil;
  6965. childofderef.reset;
  6966. vmt_fieldderef.reset;
  6967. hiddenclassdefref.reset;
  6968. extendeddefderef.reset;
  6969. cloneddefderef.reset;
  6970. if objecttype=odt_helper then
  6971. owner.includeoption(sto_has_helper);
  6972. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords,
  6973. current_settings.alignment.recordalignmin);
  6974. { create space for vmt !! }
  6975. vmtentries:=TFPList.Create;
  6976. set_parent(c);
  6977. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  6978. prepareguid;
  6979. { setup implemented interfaces }
  6980. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
  6981. ImplementedInterfaces:=TFPObjectList.Create(true)
  6982. else
  6983. ImplementedInterfaces:=nil;
  6984. writing_class_record_dbginfo:=false;
  6985. end;
  6986. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  6987. var
  6988. i,
  6989. implintfcount : longint;
  6990. d, getterd : tderef;
  6991. ImplIntf : TImplementedInterface;
  6992. vmtentry : pvmtentry;
  6993. begin
  6994. inherited ppuload(objectdef,ppufile);
  6995. objecttype:=tobjecttyp(ppufile.getbyte);
  6996. helpertype:=thelpertype(ppufile.getbyte);
  6997. objextname:=ppufile.getpshortstring;
  6998. { only used for external Objective-C classes/protocols }
  6999. if (objextname^='') then
  7000. stringdispose(objextname);
  7001. symtable:=tObjectSymtable.create(self,objrealname^,0,0);
  7002. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  7003. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  7004. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  7005. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  7006. tObjectSymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  7007. ppufile.getderef(vmt_fieldderef);
  7008. ppufile.getderef(childofderef);
  7009. { load guid }
  7010. iidstr:=nil;
  7011. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  7012. begin
  7013. new(iidguid);
  7014. ppufile.getguid(iidguid^);
  7015. iidstr:=ppufile.getpshortstring;
  7016. end;
  7017. abstractcnt:=ppufile.getlongint;
  7018. if objecttype=odt_helper then
  7019. ppufile.getderef(extendeddefderef);
  7020. vmtentries:=TFPList.Create;
  7021. vmtentries.count:=ppufile.getlongint;
  7022. for i:=0 to vmtentries.count-1 do
  7023. begin
  7024. ppufile.getderef(d);
  7025. new(vmtentry);
  7026. vmtentry^.procdef:=nil;
  7027. vmtentry^.procdefderef:=d;
  7028. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  7029. vmtentries[i]:=vmtentry;
  7030. end;
  7031. { load implemented interfaces }
  7032. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
  7033. begin
  7034. ImplementedInterfaces:=TFPObjectList.Create(true);
  7035. implintfcount:=ppufile.getlongint;
  7036. for i:=0 to implintfcount-1 do
  7037. begin
  7038. ppufile.getderef(d);
  7039. ppufile.getderef(getterd);
  7040. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  7041. ImplIntf.IOffset:=ppufile.getlongint;
  7042. byte(ImplIntf.IType):=ppufile.getbyte;
  7043. ImplementedInterfaces.Add(ImplIntf);
  7044. end;
  7045. end
  7046. else
  7047. ImplementedInterfaces:=nil;
  7048. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7049. ppufile.getderef(hiddenclassdefref);
  7050. if df_copied_def in defoptions then
  7051. begin
  7052. ppufile.getderef(cloneddefderef);
  7053. ppuload_platform(ppufile);
  7054. end
  7055. else
  7056. begin
  7057. ppuload_platform(ppufile);
  7058. tObjectSymtable(symtable).ppuload(ppufile);
  7059. end;
  7060. { handles the predefined class tobject }
  7061. { the last TOBJECT which is loaded gets }
  7062. { it ! }
  7063. { but do this only from a unit that's }
  7064. { marked as system unit to avoid some }
  7065. { equally named user's type to override }
  7066. { the internal types! }
  7067. if mf_system_unit in current_module.moduleflags then
  7068. begin
  7069. if (childof=nil) and
  7070. (objecttype in [odt_class,odt_javaclass]) and
  7071. (objname^='TOBJECT') then
  7072. class_tobject:=self;
  7073. if (childof=nil) and
  7074. (objecttype=odt_interfacecom) then
  7075. if (objname^='IUNKNOWN') then
  7076. interface_iunknown:=self
  7077. else
  7078. if (objname^='IDISPATCH') then
  7079. interface_idispatch:=self;
  7080. if (objecttype=odt_javaclass) and
  7081. not(oo_is_formal in objectoptions) then
  7082. begin
  7083. if (objname^='JLOBJECT') then
  7084. java_jlobject:=self
  7085. else if (objname^='JLTHROWABLE') then
  7086. java_jlthrowable:=self
  7087. else if (objname^='FPCBASERECORDTYPE') then
  7088. java_fpcbaserecordtype:=self
  7089. else if (objname^='JLSTRING') then
  7090. java_jlstring:=self
  7091. else if (objname^='ANSISTRINGCLASS') then
  7092. java_ansistring:=self
  7093. else if (objname^='SHORTSTRINGCLASS') then
  7094. java_shortstring:=self
  7095. else if (objname^='JLENUM') then
  7096. java_jlenum:=self
  7097. else if (objname^='JUENUMSET') then
  7098. java_juenumset:=self
  7099. else if (objname^='FPCBITSET') then
  7100. java_jubitset:=self
  7101. else if (objname^='FPCBASEPROCVARTYPE') then
  7102. java_procvarbase:=self;
  7103. end;
  7104. end;
  7105. if (childof=nil) and
  7106. (objecttype=odt_objcclass) and
  7107. (objname^='PROTOCOL') then
  7108. objc_protocoltype:=self;
  7109. writing_class_record_dbginfo:=false;
  7110. end;
  7111. destructor tobjectdef.destroy;
  7112. begin
  7113. if assigned(symtable) then
  7114. begin
  7115. symtable.free;
  7116. symtable:=nil;
  7117. end;
  7118. stringdispose(objextname);
  7119. stringdispose(iidstr);
  7120. if assigned(ImplementedInterfaces) then
  7121. begin
  7122. ImplementedInterfaces.free;
  7123. ImplementedInterfaces:=nil;
  7124. end;
  7125. if assigned(iidguid) then
  7126. begin
  7127. dispose(iidguid);
  7128. iidguid:=nil;
  7129. end;
  7130. TFPList.FreeAndNilDisposing(vmtentries,TypeInfo(tvmtentry));
  7131. if assigned(vmcallstaticinfo) then
  7132. begin
  7133. freemem(vmcallstaticinfo);
  7134. vmcallstaticinfo:=nil;
  7135. end;
  7136. inherited destroy;
  7137. end;
  7138. function tobjectdef.getcopy : tstoreddef;
  7139. var
  7140. i : longint;
  7141. begin
  7142. result:=cobjectdef.create(objecttype,objrealname^,childof,true);
  7143. { the constructor allocates a symtable which we release to avoid memory leaks }
  7144. tobjectdef(result).symtable.free;
  7145. tobjectdef(result).symtable:=symtable.getcopy;
  7146. if assigned(objextname) then
  7147. tobjectdef(result).objextname:=stringdup(objextname^);
  7148. if assigned(import_lib) then
  7149. tobjectdef(result).import_lib:=stringdup(import_lib^);
  7150. tobjectdef(result).objectoptions:=objectoptions;
  7151. include(tobjectdef(result).defoptions,df_copied_def);
  7152. tobjectdef(result).extendeddef:=extendeddef;
  7153. if assigned(tcinitcode) then
  7154. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  7155. tobjectdef(result).vmt_field:=vmt_field;
  7156. if assigned(iidguid) then
  7157. begin
  7158. new(tobjectdef(result).iidguid);
  7159. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  7160. end;
  7161. if assigned(iidstr) then
  7162. tobjectdef(result).iidstr:=stringdup(iidstr^);
  7163. tobjectdef(result).abstractcnt:=abstractcnt;
  7164. if assigned(ImplementedInterfaces) then
  7165. begin
  7166. tobjectdef(result).ImplementedInterfaces.capacity:=tobjectdef(result).ImplementedInterfaces.count+ImplementedInterfaces.count;
  7167. for i:=0 to ImplementedInterfaces.count-1 do
  7168. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  7169. end;
  7170. tobjectdef(result).copyvmtentries(self);
  7171. end;
  7172. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  7173. var
  7174. i : longint;
  7175. vmtentry : pvmtentry;
  7176. ImplIntf : TImplementedInterface;
  7177. old_do_indirect_crc: boolean;
  7178. begin
  7179. { if class1 in unit A changes, and class2 in unit B inherits from it
  7180. (so unit B uses unit A), then unit B with class2 will be recompiled.
  7181. However, if there is also a class3 in unit C that only depends on
  7182. unit B, then unit C will not be recompiled because nothing changed
  7183. to the interface of unit B. Nevertheless, unit C can indirectly
  7184. depend on unit A via derefs, and these must be updated -> the
  7185. indirect crc keeps track of such changes. }
  7186. old_do_indirect_crc:=ppufile.do_indirect_crc;
  7187. ppufile.do_indirect_crc:=true;
  7188. inherited ppuwrite(ppufile);
  7189. ppufile.putbyte(byte(objecttype));
  7190. ppufile.putbyte(byte(helpertype));
  7191. if assigned(objextname) then
  7192. ppufile.putstring(objextname^)
  7193. else
  7194. ppufile.putstring('');
  7195. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  7196. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  7197. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  7198. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  7199. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignmin));
  7200. ppufile.putderef(vmt_fieldderef);
  7201. ppufile.putderef(childofderef);
  7202. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  7203. begin
  7204. ppufile.putguid(iidguid^);
  7205. ppufile.putstring(iidstr^);
  7206. end;
  7207. ppufile.putlongint(abstractcnt);
  7208. if objecttype=odt_helper then
  7209. ppufile.putderef(extendeddefderef);
  7210. ppufile.putlongint(vmtentries.count);
  7211. for i:=0 to vmtentries.count-1 do
  7212. begin
  7213. vmtentry:=pvmtentry(vmtentries[i]);
  7214. ppufile.putderef(vmtentry^.procdefderef);
  7215. ppufile.putbyte(byte(vmtentry^.visibility));
  7216. end;
  7217. if assigned(ImplementedInterfaces) then
  7218. begin
  7219. ppufile.putlongint(ImplementedInterfaces.Count);
  7220. for i:=0 to ImplementedInterfaces.Count-1 do
  7221. begin
  7222. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  7223. ppufile.putderef(ImplIntf.intfdefderef);
  7224. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  7225. ppufile.putlongint(ImplIntf.Ioffset);
  7226. ppufile.putbyte(byte(ImplIntf.IType));
  7227. end;
  7228. end;
  7229. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7230. ppufile.putderef(hiddenclassdefref);
  7231. if df_copied_def in defoptions then
  7232. ppufile.putderef(cloneddefderef);
  7233. writeentry(ppufile,ibobjectdef);
  7234. if not(df_copied_def in defoptions) then
  7235. tObjectSymtable(symtable).ppuwrite(ppufile);
  7236. ppufile.do_indirect_crc:=old_do_indirect_crc;
  7237. end;
  7238. function tobjectdef.GetTypeName:string;
  7239. begin
  7240. { in this case we will go in endless recursion, because then }
  7241. { there is no tsym associated yet with the def. It can occur }
  7242. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  7243. { instead of the actual type name }
  7244. if not assigned(typesym) then
  7245. result:='<Currently Parsed Class>'
  7246. else
  7247. result:=typesymbolprettyname;
  7248. end;
  7249. procedure tobjectdef.buildderef;
  7250. var
  7251. i : longint;
  7252. vmtentry : pvmtentry;
  7253. begin
  7254. inherited buildderef;
  7255. vmt_fieldderef.build(vmt_field);
  7256. childofderef.build(childof);
  7257. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7258. hiddenclassdefref.build(hiddenclassdef);
  7259. if df_copied_def in defoptions then
  7260. cloneddefderef.build(symtable.defowner)
  7261. else
  7262. tstoredsymtable(symtable).buildderef;
  7263. if objecttype=odt_helper then
  7264. extendeddefderef.build(extendeddef);
  7265. for i:=0 to vmtentries.count-1 do
  7266. begin
  7267. vmtentry:=pvmtentry(vmtentries[i]);
  7268. vmtentry^.procdefderef.build(vmtentry^.procdef);
  7269. end;
  7270. if assigned(ImplementedInterfaces) then
  7271. begin
  7272. for i:=0 to ImplementedInterfaces.count-1 do
  7273. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  7274. end;
  7275. end;
  7276. procedure tobjectdef.deref;
  7277. var
  7278. i : longint;
  7279. vmtentry : pvmtentry;
  7280. begin
  7281. inherited deref;
  7282. vmt_field:=tsym(vmt_fieldderef.resolve);
  7283. childof:=tobjectdef(childofderef.resolve);
  7284. if (target_cpu=tsystemcpu.cpu_wasm32) and (objecttype in objecttypes_with_thunk) then
  7285. hiddenclassdef:=tobjectdef(hiddenclassdefref.resolve);
  7286. if df_copied_def in defoptions then
  7287. begin
  7288. cloneddef:=tobjectdef(cloneddefderef.resolve);
  7289. symtable:=cloneddef.symtable.getcopy;
  7290. end
  7291. else
  7292. tstoredsymtable(symtable).deref(false);
  7293. if objecttype=odt_helper then
  7294. extendeddef:=tdef(extendeddefderef.resolve);
  7295. for i:=0 to vmtentries.count-1 do
  7296. begin
  7297. vmtentry:=pvmtentry(vmtentries[i]);
  7298. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  7299. end;
  7300. if assigned(ImplementedInterfaces) then
  7301. begin
  7302. for i:=0 to ImplementedInterfaces.count-1 do
  7303. TImplementedInterface(ImplementedInterfaces[i]).deref;
  7304. end;
  7305. end;
  7306. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  7307. var
  7308. pd: tprocdef absolute def;
  7309. st: tsymtable;
  7310. psym: tsym;
  7311. nname: TIDString;
  7312. begin
  7313. if (tdef(def).typ<>procdef) then
  7314. exit;
  7315. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  7316. owner = symtable in which objcclassdef is defined
  7317. }
  7318. st:=pd.owner.defowner.owner;
  7319. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  7320. { check for an existing procsym with our special name }
  7321. psym:=tsym(st.find(nname));
  7322. if not assigned(psym) then
  7323. begin
  7324. psym:=cprocsym.create(nname);
  7325. { avoid warning about this symbol being unused }
  7326. psym.IncRefCount;
  7327. { don't check for duplicates:
  7328. a) we checked above
  7329. b) in case we are in the implementation section of a unit, this
  7330. will also check for this symbol in the interface section
  7331. (since you normally cannot have symbols with the same name
  7332. both interface and implementation), and it's possible to
  7333. have class helpers for the same class in the interface and
  7334. in the implementation, and they cannot be merged since only
  7335. the once in the interface must be saved to the ppu/visible
  7336. from other units }
  7337. st.insertsym(psym,false);
  7338. end
  7339. else if (psym.typ<>procsym) then
  7340. internalerror(2009111501);
  7341. { add ourselves to this special procsym }
  7342. tprocsym(psym).procdeflist.add(def);
  7343. end;
  7344. procedure tobjectdef.derefimpl;
  7345. begin
  7346. inherited derefimpl;
  7347. { the procdefs are not owned by the class helper procsyms, so they
  7348. are not stored/restored either -> re-add them here }
  7349. if (objecttype in [odt_objcclass,odt_objcprotocol]) or
  7350. (oo_is_classhelper in objectoptions) then
  7351. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  7352. end;
  7353. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  7354. var
  7355. i : longint;
  7356. vmtentry : pvmtentry;
  7357. begin
  7358. if vmtentries.count<>0 then
  7359. internalerror(2019081401);
  7360. vmtentries.count:=objdef.vmtentries.count;
  7361. for i:=0 to objdef.vmtentries.count-1 do
  7362. begin
  7363. new(vmtentry);
  7364. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  7365. vmtentries[i]:=vmtentry;
  7366. end;
  7367. end;
  7368. function tobjectdef.getparentdef:tdef;
  7369. begin
  7370. { TODO: Remove getparentdef hack}
  7371. { With 2 forward declared classes with the child class before the
  7372. parent class the child class is written earlier to the ppu. Leaving it
  7373. possible to have a reference to the parent class for property overriding,
  7374. but the parent class still has the childof not resolved yet (PFV) }
  7375. if childof=nil then
  7376. childof:=tobjectdef(childofderef.resolve);
  7377. result:=childof;
  7378. end;
  7379. procedure tobjectdef.prepareguid;
  7380. begin
  7381. { set up guid }
  7382. if not assigned(iidguid) then
  7383. begin
  7384. new(iidguid);
  7385. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  7386. end;
  7387. { setup iidstring }
  7388. if not assigned(iidstr) then
  7389. iidstr:=stringdup(''); { default is empty string }
  7390. end;
  7391. procedure tobjectdef.set_parent( c : tobjectdef);
  7392. begin
  7393. if assigned(childof) then
  7394. exit;
  7395. childof:=c;
  7396. if not assigned(c) then
  7397. exit;
  7398. { inherit options and status }
  7399. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  7400. { check if parent is a generic parameter }
  7401. if sp_generic_para in c.typesym.symoptions then
  7402. objectoptions:=objectoptions+[oo_inherits_not_specialized];
  7403. { initially has the same number of abstract methods as the parent }
  7404. abstractcnt:=c.abstractcnt;
  7405. { add the data of the anchestor class/object }
  7406. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  7407. begin
  7408. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  7409. { inherit recordalignment }
  7410. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  7411. { if both the parent and this record use C-alignment, also inherit
  7412. the current field alignment }
  7413. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  7414. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  7415. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  7416. { the padding is not inherited for Objective-C classes (maybe not
  7417. for cppclass either?) }
  7418. if objecttype=odt_objcclass then
  7419. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  7420. if (oo_has_vmt in objectoptions) and
  7421. (oo_has_vmt in c.objectoptions) then
  7422. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  7423. { if parent has a vmt field then the offset is the same for the child PM }
  7424. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  7425. begin
  7426. vmt_field:=c.vmt_field;
  7427. include(objectoptions,oo_has_vmt);
  7428. end;
  7429. end;
  7430. end;
  7431. procedure tobjectdef.insertvmt;
  7432. begin
  7433. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  7434. exit;
  7435. if (oo_has_vmt in objectoptions) then
  7436. internalerror(2020100816)
  7437. else
  7438. begin
  7439. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  7440. tObjectSymtable(symtable).fieldalignment);
  7441. if (tf_requires_proper_alignment in target_info.flags) then
  7442. begin
  7443. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  7444. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  7445. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  7446. end;
  7447. vmt_field:=cfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  7448. hidesym(vmt_field);
  7449. tObjectSymtable(symtable).insertsym(vmt_field);
  7450. tObjectSymtable(symtable).addfield(tfieldvarsym(vmt_field),vis_hidden);
  7451. include(objectoptions,oo_has_vmt);
  7452. end;
  7453. end;
  7454. function tobjectdef.vmt_offset: asizeint;
  7455. begin
  7456. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  7457. result:=0
  7458. else if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  7459. result:=tfieldvarsym(vmt_field).fieldoffset
  7460. else
  7461. result:=tfieldvarsym(vmt_field).fieldoffset div 8;
  7462. end;
  7463. procedure tobjectdef.check_forwards;
  7464. begin
  7465. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  7466. inherited;
  7467. if (oo_is_forward in objectoptions) then
  7468. begin
  7469. { ok, in future, the forward can be resolved }
  7470. Message1(sym_e_class_forward_not_resolved,objrealname^);
  7471. exclude(objectoptions,oo_is_forward);
  7472. end;
  7473. end;
  7474. function tobjectdef.find_destructor: tprocdef;
  7475. var
  7476. objdef: tobjectdef;
  7477. begin
  7478. objdef:=self;
  7479. while assigned(objdef) do
  7480. begin
  7481. result:=objdef.find_procdef_bytype(potype_destructor);
  7482. if assigned(result) then
  7483. exit;
  7484. objdef:=objdef.childof;
  7485. end;
  7486. result:=nil;
  7487. end;
  7488. function tobjectdef.implements_any_interfaces: boolean;
  7489. begin
  7490. result := (ImplementedInterfaces.Count > 0) or
  7491. (assigned(childof) and childof.implements_any_interfaces);
  7492. end;
  7493. function tobjectdef.register_implemented_interface(intfdef:tobjectdef;useguid:boolean):timplementedinterface;
  7494. begin
  7495. { allocate the GUID only if the class implements at least one interface }
  7496. if useguid then
  7497. prepareguid;
  7498. result:=timplementedinterface.create(intfdef);
  7499. ImplementedInterfaces.Add(result);
  7500. end;
  7501. function tobjectdef.size : asizeint;
  7502. begin
  7503. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  7504. result:=voidpointertype.size
  7505. else
  7506. result:=tObjectSymtable(symtable).datasize;
  7507. end;
  7508. function tobjectdef.alignment:shortint;
  7509. begin
  7510. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  7511. alignment:=voidpointertype.alignment
  7512. else
  7513. alignment:=tObjectSymtable(symtable).recordalignment;
  7514. end;
  7515. function tobjectdef.vmtmethodoffset(index:longint):longint;
  7516. begin
  7517. { for offset of methods for classes, see rtl/inc/objpash.inc }
  7518. case objecttype of
  7519. odt_class:
  7520. { the +2*sizeof(pint) is size and -size }
  7521. vmtmethodoffset:=index*voidcodepointertype.size+10*voidpointertype.size+2*sizeof(pint);
  7522. odt_helper,
  7523. odt_objcclass,
  7524. odt_objcprotocol:
  7525. vmtmethodoffset:=0;
  7526. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  7527. vmtmethodoffset:=index*voidcodepointertype.size;
  7528. odt_javaclass,
  7529. odt_interfacejava:
  7530. { invalid }
  7531. vmtmethodoffset:=-1;
  7532. else
  7533. { the +2*sizeof(pint) is size and -size }
  7534. {$ifdef WITHDMT}
  7535. vmtmethodoffset:=index*voidcodepointertype.size+2*voidpointertype.size+2*sizeof(pint);
  7536. {$else WITHDMT}
  7537. vmtmethodoffset:=index*voidcodepointertype.size+1*voidpointertype.size+2*sizeof(pint);
  7538. {$endif WITHDMT}
  7539. end;
  7540. end;
  7541. function tobjectdef.vmt_mangledname : TSymStr;
  7542. begin
  7543. if not(oo_has_vmt in objectoptions) then
  7544. Message1(parser_n_object_has_no_vmt,objrealname^);
  7545. if not is_unique_objpasdef then
  7546. vmt_mangledname:=make_mangledname('VMT',owner,objname^)
  7547. else
  7548. vmt_mangledname:=childof.vmt_mangledname;
  7549. end;
  7550. function tobjectdef.vmt_def: trecorddef;
  7551. var
  7552. where: tsymtable;
  7553. vmttypesym: tsymentry;
  7554. begin
  7555. if not is_unique_objpasdef then
  7556. begin
  7557. vmttypesym:=symtable.Find('vmtdef');
  7558. if not assigned(vmttypesym) or
  7559. (vmttypesym.typ<>symconst.typesym) or
  7560. (ttypesym(vmttypesym).typedef.typ<>recorddef) then
  7561. internalerror(2015052501);
  7562. result:=trecorddef(ttypesym(vmttypesym).typedef);
  7563. end
  7564. else
  7565. result:=childof.vmt_def;
  7566. end;
  7567. function tobjectdef.needs_inittable : boolean;
  7568. var
  7569. hp : tobjectdef;
  7570. begin
  7571. case objecttype of
  7572. odt_helper,
  7573. odt_class :
  7574. needs_inittable:=false;
  7575. odt_dispinterface,
  7576. odt_interfacecom:
  7577. needs_inittable:=true;
  7578. odt_interfacecorba:
  7579. begin
  7580. hp:=childof;
  7581. while assigned(hp) do
  7582. begin
  7583. if hp=interface_iunknown then
  7584. begin
  7585. needs_inittable:=true;
  7586. exit;
  7587. end;
  7588. hp:=hp.childof;
  7589. end;
  7590. needs_inittable:=false;
  7591. end;
  7592. odt_object:
  7593. needs_inittable:=
  7594. tObjectSymtable(symtable).needs_init_final or
  7595. (assigned(childof) and
  7596. childof.needs_inittable);
  7597. odt_cppclass,
  7598. odt_objcclass,
  7599. odt_objcprotocol,
  7600. odt_javaclass,
  7601. odt_interfacejava:
  7602. needs_inittable:=false;
  7603. else
  7604. internalerror(200108267);
  7605. end;
  7606. end;
  7607. function tobjectdef.needs_separate_initrtti : boolean;
  7608. begin
  7609. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  7610. end;
  7611. function tobjectdef.has_non_trivial_init_child(check_parent:boolean):boolean;
  7612. begin
  7613. if objecttype in [odt_class,odt_object] then
  7614. begin
  7615. result:=tobjectsymtable(symtable).has_non_trivial_init or
  7616. (check_parent and assigned(childof) and childof.has_non_trivial_init_child(true));
  7617. end
  7618. else
  7619. result:=false;
  7620. end;
  7621. function tobjectdef.rtti_mangledname(rt: trttitype): TSymStr;
  7622. begin
  7623. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  7624. begin
  7625. if not is_unique_objpasdef then
  7626. result:=inherited rtti_mangledname(rt)
  7627. else
  7628. result:=childof.rtti_mangledname(rt)
  7629. end
  7630. else
  7631. begin
  7632. { necessary in case of a dynamic array of nsobject, or
  7633. if an nsobject field appears in a record that needs
  7634. init/finalisation }
  7635. if rt=initrtti then
  7636. begin
  7637. result:=voidpointertype.rtti_mangledname(rt);
  7638. exit;
  7639. end;
  7640. if not(target_info.system in systems_objc_nfabi) then
  7641. begin
  7642. result:=target_asm.labelprefix;
  7643. case objecttype of
  7644. odt_objcclass:
  7645. begin
  7646. case rt of
  7647. objcclassrtti:
  7648. if not(oo_is_classhelper in objectoptions) then
  7649. result:=result+'_OBJC_CLASS_'
  7650. else
  7651. result:=result+'_OBJC_CATEGORY_';
  7652. objcmetartti:
  7653. if not(oo_is_classhelper in objectoptions) then
  7654. result:=result+'_OBJC_METACLASS_'
  7655. else
  7656. internalerror(2009111511);
  7657. else
  7658. internalerror(2009092302);
  7659. end;
  7660. end;
  7661. odt_objcprotocol:
  7662. result:=result+'_OBJC_PROTOCOL_';
  7663. else
  7664. ;
  7665. end;
  7666. end
  7667. else
  7668. begin
  7669. case objecttype of
  7670. odt_objcclass:
  7671. begin
  7672. if (oo_is_classhelper in objectoptions) and
  7673. (rt<>objcclassrtti) then
  7674. internalerror(2009111512);
  7675. case rt of
  7676. objcclassrtti:
  7677. if not(oo_is_classhelper in objectoptions) then
  7678. result:='_OBJC_CLASS_$_'
  7679. else
  7680. result:='_OBJC_$_CATEGORY_';
  7681. objcmetartti:
  7682. result:='_OBJC_METACLASS_$_';
  7683. objcclassrortti:
  7684. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  7685. objcmetarortti:
  7686. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  7687. else
  7688. internalerror(2009092303);
  7689. end;
  7690. end;
  7691. odt_objcprotocol:
  7692. begin
  7693. result:=lower(target_asm.labelprefix);
  7694. case rt of
  7695. objcclassrtti:
  7696. result:=result+'_OBJC_PROTOCOL_$_';
  7697. objcmetartti:
  7698. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  7699. else
  7700. internalerror(2009092501);
  7701. end;
  7702. end;
  7703. else
  7704. internalerror(2013113005);
  7705. end;
  7706. end;
  7707. result:=result+objextname^;
  7708. end;
  7709. end;
  7710. function tobjectdef.is_unique_objpasdef: boolean;
  7711. begin
  7712. result:=
  7713. (df_unique in defoptions) and
  7714. is_class_or_interface_or_dispinterface(self)
  7715. end;
  7716. function tobjectdef.members_need_inittable : boolean;
  7717. begin
  7718. members_need_inittable:=tObjectSymtable(symtable).needs_init_final or
  7719. has_non_trivial_init_child(true);
  7720. end;
  7721. function tobjectdef.is_publishable : tpublishproperty;
  7722. begin
  7723. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  7724. is_publishable:=pp_publish
  7725. else
  7726. is_publishable:=pp_error;
  7727. end;
  7728. function tobjectdef.get_next_dispid: longint;
  7729. begin
  7730. inc(fcurrent_dispid);
  7731. result:=fcurrent_dispid;
  7732. end;
  7733. function tobjectdef.search_enumerator_get: tprocdef;
  7734. begin
  7735. result:=inherited;
  7736. if not assigned(result) and assigned(childof) then
  7737. result:=childof.search_enumerator_get;
  7738. end;
  7739. function tobjectdef.search_enumerator_move: tprocdef;
  7740. begin
  7741. result:=inherited;
  7742. if not assigned(result) and assigned(childof) then
  7743. result:=childof.search_enumerator_move;
  7744. end;
  7745. function tobjectdef.search_enumerator_current: tsym;
  7746. begin
  7747. result:=inherited;
  7748. if not assigned(result) and assigned(childof) then
  7749. result:=childof.search_enumerator_current;
  7750. end;
  7751. procedure tobjectdef.register_created_classref_type;
  7752. begin
  7753. if not classref_created_in_current_module then
  7754. begin
  7755. classref_created_in_current_module:=true;
  7756. if not (owner.symtabletype in [localsymtable]) then
  7757. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  7758. end;
  7759. end;
  7760. procedure tobjectdef.register_created_object_type;
  7761. begin
  7762. if not created_in_current_module then
  7763. begin
  7764. created_in_current_module:=true;
  7765. if not (owner.symtabletype in [localsymtable]) then
  7766. current_module.wpoinfo.addcreatedobjtype(self);
  7767. end;
  7768. end;
  7769. procedure tobjectdef.register_maybe_created_object_type;
  7770. begin
  7771. { if we know it has been created for sure, no need
  7772. to also record that it maybe can be created in
  7773. this module
  7774. }
  7775. if not (created_in_current_module) and
  7776. not (maybe_created_in_current_module) then
  7777. begin
  7778. maybe_created_in_current_module:=true;
  7779. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  7780. end;
  7781. end;
  7782. procedure tobjectdef.register_vmt_call(index: longint);
  7783. begin
  7784. if (is_object(self) or is_class(self)) then
  7785. current_module.wpoinfo.addcalledvmtentry(self,index);
  7786. end;
  7787. procedure check_and_finish_msg(data: tobject; arg: pointer);
  7788. var
  7789. def: tdef absolute data;
  7790. pd: tprocdef absolute data;
  7791. i,
  7792. paracount: longint;
  7793. begin
  7794. if (def.typ=procdef) then
  7795. begin
  7796. { add all messages also under a dummy name to the symtable in
  7797. which the objcclass/protocol/category is declared, so they can
  7798. be called via id.<name>
  7799. }
  7800. create_class_helper_for_procdef(pd,nil);
  7801. { we have to wait until now to set the mangled name because it
  7802. depends on the (possibly external) class name, which is defined
  7803. at the very end. }
  7804. if not(po_msgstr in pd.procoptions) then
  7805. begin
  7806. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  7807. { recover to avoid internalerror later on }
  7808. include(pd.procoptions,po_msgstr);
  7809. pd.messageinf.str:=stringdup('MissingDeclaration');
  7810. end;
  7811. { Mangled name is already set in case this is a copy of
  7812. another type. }
  7813. if not(po_has_mangledname in pd.procoptions) then
  7814. begin
  7815. { check whether the number of formal parameters is correct,
  7816. and whether they have valid Objective-C types }
  7817. paracount:=0;
  7818. for i:=1 to length(pd.messageinf.str^) do
  7819. if pd.messageinf.str^[i]=':' then
  7820. inc(paracount);
  7821. for i:=0 to pd.paras.count-1 do
  7822. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  7823. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  7824. dec(paracount);
  7825. if (paracount<>0) then
  7826. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  7827. pd.setmangledname(pd.objcmangledname);
  7828. end
  7829. else
  7830. { all checks already done }
  7831. exit;
  7832. if not(oo_is_external in pd.struct.objectoptions) then
  7833. begin
  7834. if (po_varargs in pd.procoptions) then
  7835. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  7836. else
  7837. begin
  7838. { check for "array of const" parameters }
  7839. for i:=0 to pd.parast.symlist.count-1 do
  7840. begin
  7841. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  7842. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  7843. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  7844. end;
  7845. end;
  7846. end;
  7847. end;
  7848. end;
  7849. procedure mark_private_fields_used(data: tobject; arg: pointer);
  7850. var
  7851. sym: tsym absolute data;
  7852. begin
  7853. if (sym.typ=fieldvarsym) and
  7854. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  7855. sym.IncRefCount;
  7856. end;
  7857. procedure tobjectdef.finish_objc_data;
  7858. begin
  7859. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  7860. if (oo_is_external in objectoptions) then
  7861. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  7862. end;
  7863. procedure verify_objc_vardef(data: tobject; arg: pointer);
  7864. var
  7865. sym: tabstractvarsym absolute data;
  7866. res: pboolean absolute arg;
  7867. founderrordef: tdef;
  7868. begin
  7869. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  7870. exit;
  7871. if (sym.typ=paravarsym) and
  7872. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  7873. is_array_of_const(tparavarsym(sym).vardef)) then
  7874. exit;
  7875. if not objcchecktype(sym.vardef,founderrordef) then
  7876. begin
  7877. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7878. res^:=false;
  7879. end;
  7880. end;
  7881. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  7882. var
  7883. def: tdef absolute data;
  7884. res: pboolean absolute arg;
  7885. founderrordef: tdef;
  7886. begin
  7887. if (def.typ<>procdef) then
  7888. exit;
  7889. { check parameter types for validity }
  7890. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  7891. { check the result type for validity }
  7892. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  7893. begin
  7894. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7895. res^:=false;
  7896. end;
  7897. end;
  7898. function tobjectdef.check_objc_types: boolean;
  7899. begin
  7900. { done in separate step from finish_objc_data, because when
  7901. finish_objc_data is called, not all forwarddefs have been resolved
  7902. yet and we need to know all types here }
  7903. result:=true;
  7904. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  7905. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  7906. end;
  7907. procedure do_cpp_import_info(data: tobject; arg: pointer);
  7908. var
  7909. def: tdef absolute data;
  7910. pd: tprocdef absolute data;
  7911. begin
  7912. if (def.typ=procdef) then
  7913. begin
  7914. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  7915. if (oo_is_external in pd.struct.objectoptions) then
  7916. begin
  7917. { copied from psub.read_proc }
  7918. if assigned(tobjectdef(pd.struct).import_lib) then
  7919. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  7920. else
  7921. begin
  7922. { add import name to external list for DLL scanning }
  7923. if tf_has_dllscanner in target_info.flags then
  7924. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  7925. end;
  7926. end;
  7927. end;
  7928. end;
  7929. procedure tobjectdef.finish_cpp_data;
  7930. begin
  7931. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  7932. end;
  7933. procedure tobjectdef.apply_rtti_directive(dir: trtti_directive);
  7934. begin
  7935. rtti.clause:=dir.clause;
  7936. rtti.options:=dir.options;
  7937. if (dir.clause=rtc_inherit) and assigned(childof) and (childof.rtti.clause<>rtc_none) then
  7938. begin
  7939. rtti.options[ro_methods]:=rtti.options[ro_methods]+childof.rtti.options[ro_methods];
  7940. rtti.options[ro_fields]:=rtti.options[ro_fields]+childof.rtti.options[ro_fields];
  7941. rtti.options[ro_properties]:=rtti.options[ro_properties]+childof.rtti.options[ro_properties];
  7942. end;
  7943. end;
  7944. {$ifdef DEBUG_NODE_XML}
  7945. function TObjectDef.XMLPrintType: ansistring;
  7946. begin
  7947. if (oo_is_forward in objectoptions) then
  7948. Result := '&lt;class prototype&gt;'
  7949. else
  7950. Result := '&lt;class&gt;';
  7951. end;
  7952. procedure TObjectDef.XMLPrintDefInfo(var T: Text; Sym: TSym);
  7953. var
  7954. i: TObjectOption;
  7955. first: Boolean;
  7956. begin
  7957. inherited XMLPrintDefInfo(T, Sym);
  7958. First := True;
  7959. for i := Low(TObjectOption) to High(TObjectOption) do
  7960. if i in objectoptions then
  7961. begin
  7962. if First then
  7963. begin
  7964. Write(T, ' objectoptions="', i);
  7965. First := False;
  7966. end
  7967. else
  7968. Write(T, ',', i)
  7969. end;
  7970. if not first then
  7971. Write(T, '"');
  7972. end;
  7973. procedure TObjectDef.XMLPrintDefData(var T: Text; Sym: TSym);
  7974. begin
  7975. { There's nothing useful yet if the type is only forward-declared }
  7976. if not (oo_is_forward in objectoptions) then
  7977. begin
  7978. if Assigned(childof) then
  7979. WriteLn(T, printnodeindention, '<ancestor>', SanitiseXMLString(childof.typesym.RealName), '</ancestor>');
  7980. inherited XMLPrintDefData(T, Sym);
  7981. end;
  7982. end;
  7983. {$endif DEBUG_NODE_XML}
  7984. {****************************************************************************
  7985. TImplementedInterface
  7986. ****************************************************************************}
  7987. function TImplementedInterface.GetIOffset: longint;
  7988. begin
  7989. if (fIOffset=-1) and
  7990. (IType in [etFieldValue,etFieldValueClass]) then
  7991. result:=tfieldvarsym(ImplementsField).fieldoffset
  7992. else
  7993. result:=fIOffset;
  7994. end;
  7995. constructor TImplementedInterface.create(aintf: tobjectdef);
  7996. begin
  7997. inherited create;
  7998. intfdef:=aintf;
  7999. intfdefderef.reset;
  8000. IOffset:=-1;
  8001. IType:=etStandard;
  8002. NameMappings:=nil;
  8003. procdefs:=nil;
  8004. end;
  8005. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  8006. begin
  8007. inherited create;
  8008. intfdef:=nil;
  8009. intfdefderef:=intfd;
  8010. ImplementsGetterDeref:=getterd;
  8011. IOffset:=-1;
  8012. IType:=etStandard;
  8013. NameMappings:=nil;
  8014. procdefs:=nil;
  8015. end;
  8016. destructor TImplementedInterface.destroy;
  8017. var
  8018. i : longint;
  8019. mappedname : pshortstring;
  8020. begin
  8021. if assigned(NameMappings) then
  8022. begin
  8023. for i:=0 to NameMappings.Count-1 do
  8024. begin
  8025. mappedname:=pshortstring(NameMappings[i]);
  8026. stringdispose(mappedname);
  8027. end;
  8028. NameMappings.free;
  8029. NameMappings:=nil;
  8030. end;
  8031. if assigned(procdefs) then
  8032. begin
  8033. procdefs.free;
  8034. procdefs:=nil;
  8035. end;
  8036. inherited destroy;
  8037. end;
  8038. procedure TImplementedInterface.buildderef;
  8039. begin
  8040. intfdefderef.build(intfdef);
  8041. ImplementsGetterDeref.build(ImplementsGetter);
  8042. end;
  8043. procedure TImplementedInterface.deref;
  8044. begin
  8045. intfdef:=tobjectdef(intfdefderef.resolve);
  8046. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  8047. end;
  8048. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  8049. begin
  8050. if not assigned(NameMappings) then
  8051. NameMappings:=TFPHashList.Create;
  8052. NameMappings.Add(origname,stringdup(newname));
  8053. end;
  8054. function TImplementedInterface.GetMapping(const origname: string):string;
  8055. var
  8056. mappedname : pshortstring;
  8057. begin
  8058. result:='';
  8059. if not assigned(NameMappings) then
  8060. exit;
  8061. mappedname:=PShortstring(NameMappings.Find(origname));
  8062. if assigned(mappedname) then
  8063. result:=mappedname^;
  8064. end;
  8065. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  8066. begin
  8067. if not assigned(procdefs) then
  8068. procdefs:=TFPObjectList.Create(false);
  8069. { duplicate entries must be stored, because multiple }
  8070. { interfaces can declare methods with the same name }
  8071. { and all of these get their own VMT entry }
  8072. procdefs.Add(pd);
  8073. end;
  8074. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  8075. var
  8076. i : longint;
  8077. begin
  8078. result:=false;
  8079. { interfaces being implemented through delegation are not mergable (FK) }
  8080. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  8081. exit;
  8082. weight:=0;
  8083. { empty interface is mergeable }
  8084. if ProcDefs.Count=0 then
  8085. begin
  8086. result:=true;
  8087. exit;
  8088. end;
  8089. { The interface to merge must at least the number of
  8090. procedures of this interface }
  8091. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  8092. exit;
  8093. for i:=0 to ProcDefs.Count-1 do
  8094. begin
  8095. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  8096. exit;
  8097. end;
  8098. weight:=ProcDefs.Count;
  8099. result:=true;
  8100. end;
  8101. function TImplementedInterface.getcopy:TImplementedInterface;
  8102. var
  8103. i : longint;
  8104. begin
  8105. Result:=TImplementedInterface.Create(nil);
  8106. { 1) the procdefs list will be freed once for each copy
  8107. 2) since the procdefs list owns its elements, those will also be freed for each copy
  8108. Nope: procdefs are owned by their symtable, so no copy necessary
  8109. 3) idem for the name mappings
  8110. }
  8111. result.fIOffset:=fIOffset;
  8112. result.IntfDef:=IntfDef;
  8113. result.IntfDefDeref.reset;
  8114. result.IType:=IType;
  8115. result.VtblImplIntf:=VtblImplIntf;
  8116. if assigned(NameMappings) then
  8117. begin
  8118. result.NameMappings:=TFPHashList.create;
  8119. for i:=0 to NameMappings.Count-1 do
  8120. Result.NameMappings.Add(NameMappings.NameOfIndex(i),
  8121. stringdup(pshortstring(NameMappings.Items[i])^));
  8122. end;
  8123. if assigned(ProcDefs) then
  8124. begin
  8125. result.ProcDefs:=TFPObjectList.create(false);
  8126. { Note: this is probably wrong, because those procdefs are owned by
  8127. the old objectdef from which we copy, what would be the correct way
  8128. of doing this is to lookup the equivalent copy in the new owner
  8129. and reference this instead... But this is complicated so let's try
  8130. it this way until it blows up ok? }
  8131. for i:=0 to ProcDefs.Count-1 do
  8132. Result.ProcDefs.add(tprocdef(procdefs[i]).getcopy);
  8133. end;
  8134. result.ImplementsGetter:=ImplementsGetter;
  8135. result.ImplementsGetterDeref.reset;
  8136. result.ImplementsField:=ImplementsField;
  8137. end;
  8138. {****************************************************************************
  8139. TFORWARDDEF
  8140. ****************************************************************************}
  8141. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  8142. begin
  8143. inherited create(forwarddef,true);
  8144. tosymname:=stringdup(s);
  8145. forwardpos:=pos;
  8146. end;
  8147. function tforwarddef.GetTypeName:string;
  8148. begin
  8149. GetTypeName:='unresolved forward to '+tosymname^;
  8150. end;
  8151. destructor tforwarddef.destroy;
  8152. begin
  8153. stringdispose(tosymname);
  8154. inherited destroy;
  8155. end;
  8156. function tforwarddef.getcopy:tstoreddef;
  8157. begin
  8158. result:=cforwarddef.create(tosymname^, forwardpos);
  8159. end;
  8160. {****************************************************************************
  8161. TUNDEFINEDDEF
  8162. ****************************************************************************}
  8163. constructor tundefineddef.create(doregister:boolean);
  8164. begin
  8165. inherited create(undefineddef,doregister);
  8166. end;
  8167. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  8168. begin
  8169. inherited ppuload(undefineddef,ppufile);
  8170. ppuload_platform(ppufile);
  8171. end;
  8172. function tundefineddef.GetTypeName:string;
  8173. begin
  8174. GetTypeName:='<undefined type>';
  8175. end;
  8176. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  8177. begin
  8178. inherited ppuwrite(ppufile);
  8179. writeentry(ppufile,ibundefineddef);
  8180. end;
  8181. {****************************************************************************
  8182. TERRORDEF
  8183. ****************************************************************************}
  8184. constructor terrordef.create;
  8185. begin
  8186. inherited create(errordef,true);
  8187. { prevent consecutive faults }
  8188. savesize:=1;
  8189. end;
  8190. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  8191. begin
  8192. { Can't write errordefs to ppu }
  8193. internalerror(200411063);
  8194. end;
  8195. function terrordef.GetTypeName:string;
  8196. begin
  8197. GetTypeName:='<erroneous type>';
  8198. end;
  8199. function terrordef.getmangledparaname:TSymStr;
  8200. begin
  8201. getmangledparaname:='error';
  8202. end;
  8203. {****************************************************************************
  8204. Definition Helpers
  8205. ****************************************************************************}
  8206. function is_interfacecom(def: tdef): boolean;
  8207. begin
  8208. is_interfacecom:=
  8209. assigned(def) and
  8210. (def.typ=objectdef) and
  8211. (tobjectdef(def).objecttype=odt_interfacecom);
  8212. end;
  8213. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  8214. begin
  8215. is_interfacecom_or_dispinterface:=
  8216. assigned(def) and
  8217. (def.typ=objectdef) and
  8218. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  8219. end;
  8220. function is_any_interface_kind(def: tdef): boolean;
  8221. begin
  8222. result:=
  8223. assigned(def) and
  8224. (def.typ=objectdef) and
  8225. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  8226. is_objccategory(def));
  8227. end;
  8228. function is_interfacecorba(def: tdef): boolean;
  8229. begin
  8230. is_interfacecorba:=
  8231. assigned(def) and
  8232. (def.typ=objectdef) and
  8233. (tobjectdef(def).objecttype=odt_interfacecorba);
  8234. end;
  8235. function is_interface(def: tdef): boolean;
  8236. begin
  8237. is_interface:=
  8238. assigned(def) and
  8239. (def.typ=objectdef) and
  8240. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  8241. end;
  8242. function is_dispinterface(def: tdef): boolean;
  8243. begin
  8244. result:=
  8245. assigned(def) and
  8246. (def.typ=objectdef) and
  8247. (tobjectdef(def).objecttype=odt_dispinterface);
  8248. end;
  8249. function is_class(def: tdef): boolean;
  8250. begin
  8251. is_class:=
  8252. assigned(def) and
  8253. (def.typ=objectdef) and
  8254. (tobjectdef(def).objecttype=odt_class);
  8255. end;
  8256. function is_object(def: tdef): boolean;
  8257. begin
  8258. is_object:=
  8259. assigned(def) and
  8260. (def.typ=objectdef) and
  8261. (tobjectdef(def).objecttype=odt_object);
  8262. end;
  8263. function is_cppclass(def: tdef): boolean;
  8264. begin
  8265. is_cppclass:=
  8266. assigned(def) and
  8267. (def.typ=objectdef) and
  8268. (tobjectdef(def).objecttype=odt_cppclass);
  8269. end;
  8270. function is_objcclass(def: tdef): boolean;
  8271. begin
  8272. is_objcclass:=
  8273. assigned(def) and
  8274. (def.typ=objectdef) and
  8275. (tobjectdef(def).objecttype=odt_objcclass);
  8276. end;
  8277. function is_objectpascal_helper(def: tdef): boolean;
  8278. begin
  8279. result:=
  8280. assigned(def) and
  8281. (def.typ=objectdef) and
  8282. (tobjectdef(def).objecttype=odt_helper);
  8283. end;
  8284. function is_objcclassref(def: tdef): boolean;
  8285. begin
  8286. is_objcclassref:=
  8287. assigned(def) and
  8288. (def.typ=classrefdef) and
  8289. is_objcclass(tclassrefdef(def).pointeddef);
  8290. end;
  8291. function is_objcprotocol(def: tdef): boolean;
  8292. begin
  8293. result:=
  8294. assigned(def) and
  8295. (def.typ=objectdef) and
  8296. (tobjectdef(def).objecttype=odt_objcprotocol);
  8297. end;
  8298. function is_objccategory(def: tdef): boolean;
  8299. begin
  8300. result:=
  8301. assigned(def) and
  8302. (def.typ=objectdef) and
  8303. { if used as a forward type }
  8304. ((tobjectdef(def).objecttype=odt_objccategory) or
  8305. { if used as after it has been resolved }
  8306. ((tobjectdef(def).objecttype=odt_objcclass) and
  8307. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  8308. end;
  8309. function is_objc_class_or_protocol(def: tdef): boolean;
  8310. begin
  8311. result:=
  8312. assigned(def) and
  8313. (def.typ=objectdef) and
  8314. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  8315. end;
  8316. function is_objc_protocol_or_category(def: tdef): boolean;
  8317. begin
  8318. result:=
  8319. assigned(def) and
  8320. (def.typ=objectdef) and
  8321. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  8322. ((tobjectdef(def).objecttype = odt_objcclass) and
  8323. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  8324. end;
  8325. function is_classhelper(def: tdef): boolean;
  8326. begin
  8327. result:=
  8328. is_objectpascal_helper(def) or
  8329. is_objccategory(def);
  8330. end;
  8331. function is_class_or_interface(def: tdef): boolean;
  8332. begin
  8333. result:=
  8334. assigned(def) and
  8335. (def.typ=objectdef) and
  8336. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  8337. end;
  8338. function is_class_or_interface_or_objc(def: tdef): boolean;
  8339. begin
  8340. result:=
  8341. assigned(def) and
  8342. (def.typ=objectdef) and
  8343. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  8344. end;
  8345. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  8346. begin
  8347. result:=
  8348. assigned(def) and
  8349. (def.typ=objectdef) and
  8350. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  8351. end;
  8352. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  8353. begin
  8354. result:=
  8355. assigned(def) and
  8356. (def.typ=objectdef) and
  8357. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  8358. end;
  8359. function is_class_or_interface_or_object(def: tdef): boolean;
  8360. begin
  8361. result:=
  8362. assigned(def) and
  8363. (def.typ=objectdef) and
  8364. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  8365. end;
  8366. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  8367. begin
  8368. result:=
  8369. assigned(def) and
  8370. (def.typ=objectdef) and
  8371. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  8372. end;
  8373. function is_implicit_pointer_object_type(def: tdef): boolean;
  8374. begin
  8375. result:=
  8376. assigned(def) and
  8377. (((def.typ=objectdef) and
  8378. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  8379. ((target_info.system in systems_jvm) and
  8380. (def.typ=recorddef)));
  8381. end;
  8382. function is_implicit_array_pointer(def: tdef): boolean;
  8383. begin
  8384. result:=is_dynamic_array(def) or is_dynamicstring(def);
  8385. end;
  8386. function is_class_or_object(def: tdef): boolean;
  8387. begin
  8388. result:=
  8389. assigned(def) and
  8390. (def.typ=objectdef) and
  8391. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  8392. end;
  8393. function is_record(def: tdef): boolean;
  8394. begin
  8395. result:=
  8396. assigned(def) and
  8397. (def.typ=recorddef);
  8398. end;
  8399. function is_javaclass(def: tdef): boolean;
  8400. begin
  8401. result:=
  8402. assigned(def) and
  8403. (def.typ=objectdef) and
  8404. (tobjectdef(def).objecttype=odt_javaclass);
  8405. end;
  8406. function is_javaclassref(def: tdef): boolean;
  8407. begin
  8408. is_javaclassref:=
  8409. assigned(def) and
  8410. (def.typ=classrefdef) and
  8411. is_javaclass(tclassrefdef(def).pointeddef);
  8412. end;
  8413. function is_javainterface(def: tdef): boolean;
  8414. begin
  8415. result:=
  8416. assigned(def) and
  8417. (def.typ=objectdef) and
  8418. (tobjectdef(def).objecttype=odt_interfacejava);
  8419. end;
  8420. function is_java_class_or_interface(def: tdef): boolean;
  8421. begin
  8422. result:=
  8423. assigned(def) and
  8424. (def.typ=objectdef) and
  8425. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  8426. end;
  8427. procedure loadobjctypes;
  8428. begin
  8429. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  8430. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  8431. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  8432. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  8433. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  8434. end;
  8435. procedure maybeloadcocoatypes;
  8436. var
  8437. tsym: ttypesym;
  8438. cocoaunit: string[15];
  8439. begin
  8440. if assigned(objc_fastenumeration) then
  8441. exit;
  8442. if not(target_info.system in [system_arm_ios,system_i386_iphonesim,system_aarch64_ios,system_x86_64_iphonesim,system_aarch64_iphonesim]) then
  8443. cocoaunit:='COCOAALL'
  8444. else
  8445. cocoaunit:='IPHONEALL';
  8446. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  8447. if assigned(tsym) then
  8448. objc_fastenumeration:=tobjectdef(tsym.typedef)
  8449. else
  8450. objc_fastenumeration:=nil;
  8451. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  8452. if assigned(tsym) then
  8453. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  8454. else
  8455. objc_fastenumerationstate:=nil;
  8456. end;
  8457. function use_vectorfpu(def : tdef) : boolean;
  8458. begin
  8459. {$ifdef x86}
  8460. {$define use_vectorfpuimplemented}
  8461. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  8462. (is_double(def) and (current_settings.fputype in sse_doublescalar)) or
  8463. { Check vector types }
  8464. (
  8465. is_normal_array(def) and
  8466. (ado_IsVector in tarraydef(def).arrayoptions) and
  8467. (
  8468. (
  8469. is_single(tarraydef(def).elementdef) and
  8470. (
  8471. { SSE or AVX XMM register }
  8472. ((tarraydef(def).elecount = 4) and (current_settings.fputype in sse_singlescalar)) or
  8473. { AVX YMM register }
  8474. ((tarraydef(def).elecount = 8) and (current_settings.fputype in fpu_avx_instructionsets))
  8475. {$ifndef i8086}
  8476. or
  8477. { AVX512 ZMM register }
  8478. ((tarraydef(def).elecount = 16) and (current_settings.fputype in [fpu_avx512f]))
  8479. {$endif not i8086}
  8480. )
  8481. ) or
  8482. (
  8483. is_double(tarraydef(def).elementdef) and
  8484. (
  8485. { SSE or AVX XMM register }
  8486. ((tarraydef(def).elecount = 2) and (current_settings.fputype in sse_doublescalar)) or
  8487. { AVX YMM register }
  8488. ((tarraydef(def).elecount = 4) and (current_settings.fputype in fpu_avx_instructionsets))
  8489. {$ifndef i8086}
  8490. { AVX512 ZMM register }
  8491. or ((tarraydef(def).elecount = 8) and (current_settings.fputype in [fpu_avx512f]))
  8492. {$endif not i8086}
  8493. )
  8494. )
  8495. )
  8496. );
  8497. {$endif x86}
  8498. {$ifdef arm}
  8499. {$define use_vectorfpuimplemented}
  8500. use_vectorfpu:=FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[current_settings.fputype];
  8501. {$endif arm}
  8502. {$ifdef aarch64}
  8503. {$define use_vectorfpuimplemented}
  8504. use_vectorfpu:=true;
  8505. {$endif aarch64}
  8506. {$ifndef use_vectorfpuimplemented}
  8507. use_vectorfpu:=false;
  8508. {$endif}
  8509. end;
  8510. procedure reset_all_default_types;
  8511. { Those class pointers have to be set to nil manually }
  8512. { after memory they point to have been released. }
  8513. { Necessary strictly for Textmode IDE. }
  8514. begin
  8515. voidpointertype:=nil; { pointer for Void-pointeddef }
  8516. charpointertype:=nil; { pointer for Char-pointeddef }
  8517. widecharpointertype:=nil; { pointer for WideChar-pointeddef }
  8518. voidcodepointertype:=nil; { pointer to code; corresponds to System.CodePointer }
  8519. voidstackpointertype:=nil; { the pointer type used for accessing parameters and local vars on the stack }
  8520. parentfpvoidpointertype:=nil; { void pointer with the size of the hidden parentfp parameter, passed to nested functions }
  8521. {$ifdef x86}
  8522. voidnearpointertype:=nil;
  8523. voidnearcspointertype:=nil;
  8524. voidneardspointertype:=nil;
  8525. voidnearsspointertype:=nil;
  8526. voidnearespointertype:=nil;
  8527. voidnearfspointertype:=nil;
  8528. voidneargspointertype:=nil;
  8529. {$ifdef i8086}
  8530. voidfarpointertype:=nil;
  8531. voidhugepointertype:=nil;
  8532. charnearpointertype:=nil;
  8533. charfarpointertype:=nil;
  8534. charhugepointertype:=nil;
  8535. bytefarpointertype:=nil; { used for Mem[] }
  8536. wordfarpointertype:=nil; { used for MemW[] }
  8537. longintfarpointertype:=nil; { used for MemL[] }
  8538. {$endif i8086}
  8539. {$endif x86}
  8540. {$ifdef wasm}
  8541. wasmvoidexternreftype:=nil;
  8542. {$endif wasm}
  8543. cundefinedtype:=nil;
  8544. cformaltype:=nil; { unique formal definition }
  8545. ctypedformaltype:=nil; { unique typed formal definition }
  8546. voidtype:=nil; { Void (procedure) }
  8547. cansichartype:=nil; { Char }
  8548. cwidechartype:=nil; { WideChar }
  8549. cchartype:=nil; { either cansichartype or cwidechartype. Do not free }
  8550. pasbool1type:=nil; { boolean type }
  8551. pasbool8type:=nil;
  8552. pasbool16type:=nil;
  8553. pasbool32type:=nil;
  8554. pasbool64type:=nil;
  8555. bool8type:=nil;
  8556. bool16type:=nil;
  8557. bool32type:=nil;
  8558. bool64type:=nil;
  8559. {$ifdef llvm}
  8560. llvmbool1type:=nil; { LLVM i1 type }
  8561. {$endif llvm}
  8562. u8inttype:=nil; { 8-Bit unsigned integer }
  8563. s8inttype:=nil; { 8-Bit signed integer }
  8564. u16inttype:=nil; { 16-Bit unsigned integer }
  8565. s16inttype:=nil; { 16-Bit signed integer }
  8566. u24inttype:=nil; { 24-Bit unsigned integer }
  8567. s24inttype:=nil; { 24-Bit signed integer }
  8568. u32inttype:=nil; { 32-Bit unsigned integer }
  8569. s32inttype:=nil; { 32-Bit signed integer }
  8570. u40inttype:=nil; { 40-Bit unsigned integer }
  8571. s40inttype:=nil; { 40-Bit signed integer }
  8572. u48inttype:=nil; { 48-Bit unsigned integer }
  8573. s48inttype:=nil; { 48-Bit signed integer }
  8574. u56inttype:=nil; { 56-Bit unsigned integer }
  8575. s56inttype:=nil; { 56-Bit signed integer }
  8576. u64inttype:=nil; { 64-bit unsigned integer }
  8577. s64inttype:=nil; { 64-bit signed integer }
  8578. u128inttype:=nil; { 128-bit unsigned integer }
  8579. s128inttype:=nil; { 128-bit signed integer }
  8580. s32floattype:=nil; { 32 bit floating point number }
  8581. s64floattype:=nil; { 64 bit floating point number }
  8582. s80floattype:=nil; { 80 bit floating point number }
  8583. sc80floattype:=nil; { 80 bit floating point number but stored like in C }
  8584. s64currencytype:=nil; { pointer to a currency type }
  8585. cshortstringtype:=nil; { pointer to type of short string const }
  8586. clongstringtype:=nil; { pointer to type of long string const }
  8587. cansistringtype:=nil; { pointer to type of ansi string const }
  8588. cwidestringtype:=nil; { pointer to type of wide string const }
  8589. cunicodestringtype:=nil;
  8590. openshortstringtype:=nil;
  8591. openchararraytype:=nil;
  8592. cfiletype:=nil;
  8593. methodpointertype:=nil; { typecasting of methodpointers to extract self }
  8594. nestedprocpointertype:=nil; { typecasting of nestedprocpointers to extract parentfp }
  8595. hresultdef:=nil;
  8596. typekindtype:=nil; { def of TTypeKind for correct handling of GetTypeKind parameters }
  8597. { we use only one variant def for every variant class }
  8598. cvarianttype:=nil;
  8599. colevarianttype:=nil;
  8600. { default integer type, normally s32inttype on 32 bit systems and s64bittype on 64 bit systems }
  8601. sinttype:=nil;
  8602. uinttype:=nil;
  8603. { integer types corresponding to OS_SINT/OS_INT }
  8604. ossinttype:=nil;
  8605. osuinttype:=nil;
  8606. { integer types corresponding to the ALU size, sizeof(aint) and the ALUSInt/ALUUInt types in the system unit }
  8607. alusinttype:=nil;
  8608. aluuinttype:=nil;
  8609. { integer types corresponding to SizeInt and SizeUInt for the target platform }
  8610. sizeuinttype:=nil;
  8611. sizesinttype:=nil;
  8612. { unsigned and signed ord type with the same size as a pointer }
  8613. ptruinttype:=nil;
  8614. ptrsinttype:=nil;
  8615. { unsigned and signed ord type with the same size as a codepointer }
  8616. codeptruinttype:=nil;
  8617. codeptrsinttype:=nil;
  8618. { several types to simulate more or less C++ objects for GDB }
  8619. vmttype:=nil;
  8620. vmtarraytype:=nil;
  8621. { type of classrefs, used for stabs }
  8622. pvmttype:=nil;
  8623. { return type of the setjmp function }
  8624. exceptionreasontype:=nil;
  8625. class_tobject:=nil;
  8626. class_tcustomattribute:=nil;
  8627. interface_iunknown:=nil;
  8628. interface_idispatch:=nil;
  8629. rec_tguid:=nil;
  8630. rec_jmp_buf:=nil;
  8631. rec_exceptaddr:=nil;
  8632. objc_metaclasstype:=nil;
  8633. objc_superclasstype:=nil;
  8634. objc_idtype:=nil;
  8635. objc_seltype:=nil;
  8636. objc_objecttype:=nil;
  8637. objc_protocoltype:=nil;
  8638. objc_fastenumeration:=nil;
  8639. objc_fastenumerationstate:=nil;
  8640. {$ifdef llvm}
  8641. { llvm types }
  8642. { a unique def to identify any kind of metadata }
  8643. llvm_metadatatype:=nil;
  8644. {$endif llvm}
  8645. { Java base types }
  8646. java_jlobject:=nil;
  8647. java_jlthrowable:=nil;
  8648. java_fpcbaserecordtype:=nil;
  8649. java_jlstring:=nil;
  8650. java_jlenum:=nil;
  8651. java_juenumset:=nil;
  8652. java_jubitset:=nil;
  8653. java_ansistring:=nil;
  8654. java_shortstring:=nil;
  8655. java_procvarbase:=nil;
  8656. { x86 vector types }
  8657. x86_m64type:=nil;
  8658. x86_m128type:=nil;
  8659. x86_m128dtype:=nil;
  8660. x86_m128itype:=nil;
  8661. x86_m256type:=nil;
  8662. x86_m256dtype:=nil;
  8663. x86_m256itype:=nil;
  8664. end;
  8665. end.