symdef.pas 233 KB

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