symdef.pas 254 KB

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