symdef.pas 208 KB

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