symdef.pas 292 KB

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