symdef.pas 254 KB

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