symdef.pas 235 KB

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