symdef.pas 334 KB

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