symdef.pas 272 KB

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