symdef.pas 316 KB

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