symdef.pas 315 KB

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