symdef.pas 296 KB

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