symdef.pas 277 KB

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