symdef.pas 334 KB

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