symdef.pas 234 KB

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