symdef.pas 316 KB

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