symdef.pas 335 KB

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