symdef.pas 234 KB

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