symdef.pas 317 KB

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