symdef.pas 253 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693
  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(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(def: tdef);
  3657. var
  3658. sym: tfieldvarsym;
  3659. begin
  3660. sym:=cfieldvarsym.create('$f'+tostr(trecordsymtable(symtable).symlist.count),vs_value,def,[]);
  3661. symtable.insert(sym);
  3662. trecordsymtable(symtable).addfield(sym,vis_hidden);
  3663. end;
  3664. procedure trecorddef.add_fields_from_deflist(fieldtypes: tfplist);
  3665. var
  3666. i: longint;
  3667. begin
  3668. for i:=0 to fieldtypes.count-1 do
  3669. add_field_by_def(tdef(fieldtypes[i]));
  3670. end;
  3671. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  3672. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  3673. var
  3674. i,j : longint;
  3675. begin
  3676. if ppufile.getbyte=1 then
  3677. begin
  3678. new(variantrecdesc);
  3679. ppufile.getderef(variantrecdesc^.variantselectorderef);
  3680. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  3681. for i:=0 to high(variantrecdesc^.branches) do
  3682. begin
  3683. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  3684. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3685. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  3686. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3687. end;
  3688. end
  3689. else
  3690. variantrecdesc:=nil;
  3691. end;
  3692. begin
  3693. inherited ppuload(recorddef,ppufile);
  3694. if df_copied_def in defoptions then
  3695. begin
  3696. ppufile.getderef(cloneddefderef);
  3697. ppuload_platform(ppufile);
  3698. end
  3699. else
  3700. begin
  3701. ppuload_platform(ppufile);
  3702. symtable:=trecordsymtable.create(objrealname^,0,0,0);
  3703. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  3704. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  3705. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  3706. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  3707. trecordsymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  3708. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  3709. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  3710. trecordsymtable(symtable).ppuload(ppufile);
  3711. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3712. but because iso mode supports no units, there is no need to store the variantrecdesc
  3713. in the ppu
  3714. }
  3715. // readvariantrecdesc(variantrecdesc);
  3716. { requires usefieldalignment to be set }
  3717. symtable.defowner:=self;
  3718. end;
  3719. isunion:=false;
  3720. end;
  3721. destructor trecorddef.destroy;
  3722. begin
  3723. if assigned(symtable) then
  3724. begin
  3725. symtable.free;
  3726. symtable:=nil;
  3727. end;
  3728. inherited destroy;
  3729. end;
  3730. function trecorddef.getcopy : tstoreddef;
  3731. begin
  3732. result:=crecorddef.create(objrealname^,symtable.getcopy);
  3733. trecorddef(result).isunion:=isunion;
  3734. include(trecorddef(result).defoptions,df_copied_def);
  3735. if assigned(tcinitcode) then
  3736. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  3737. if assigned(import_lib) then
  3738. trecorddef(result).import_lib:=stringdup(import_lib^);
  3739. end;
  3740. function trecorddef.needs_inittable : boolean;
  3741. begin
  3742. needs_inittable:=trecordsymtable(symtable).needs_init_final
  3743. end;
  3744. function trecorddef.needs_separate_initrtti : boolean;
  3745. begin
  3746. result:=true;
  3747. end;
  3748. procedure trecorddef.buildderef;
  3749. begin
  3750. inherited buildderef;
  3751. if df_copied_def in defoptions then
  3752. cloneddefderef.build(symtable.defowner)
  3753. else
  3754. tstoredsymtable(symtable).buildderef;
  3755. end;
  3756. procedure trecorddef.deref;
  3757. begin
  3758. inherited deref;
  3759. { now dereference the definitions }
  3760. if df_copied_def in defoptions then
  3761. begin
  3762. cloneddef:=trecorddef(cloneddefderef.resolve);
  3763. symtable:=cloneddef.symtable.getcopy;
  3764. end
  3765. else
  3766. tstoredsymtable(symtable).deref;
  3767. { internal types, only load from the system unit }
  3768. if assigned(owner) and
  3769. assigned(owner.name) and
  3770. (owner.name^='SYSTEM') then
  3771. begin
  3772. { TGUID }
  3773. if not assigned(rec_tguid) and
  3774. (upper(typename)='TGUID') then
  3775. rec_tguid:=self
  3776. { JMP_BUF }
  3777. else if not assigned(rec_jmp_buf) and
  3778. (upper(typename)='JMP_BUF') then
  3779. rec_jmp_buf:=self
  3780. else if not assigned(rec_exceptaddr) and
  3781. (upper(typename)='TEXCEPTADDR') then
  3782. rec_exceptaddr:=self;
  3783. end;
  3784. end;
  3785. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  3786. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  3787. var
  3788. i,j : longint;
  3789. begin
  3790. if assigned(variantrecdesc) then
  3791. begin
  3792. ppufile.putbyte(1);
  3793. ppufile.putderef(variantrecdesc^.variantselectorderef);
  3794. ppufile.putasizeint(length(variantrecdesc^.branches));
  3795. for i:=0 to high(variantrecdesc^.branches) do
  3796. begin
  3797. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  3798. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3799. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  3800. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3801. end;
  3802. end
  3803. else
  3804. ppufile.putbyte(0);
  3805. end;
  3806. begin
  3807. inherited ppuwrite(ppufile);
  3808. if df_copied_def in defoptions then
  3809. ppufile.putderef(cloneddefderef)
  3810. else
  3811. begin
  3812. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  3813. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  3814. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  3815. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  3816. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignmin));
  3817. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  3818. ppufile.putword(trecordsymtable(symtable).paddingsize);
  3819. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3820. but because iso mode supports no units, there is no need to store the variantrecdesc
  3821. in the ppu
  3822. }
  3823. // writevariantrecdesc(variantrecdesc);
  3824. end;
  3825. writeentry(ppufile,ibrecorddef);
  3826. if not(df_copied_def in defoptions) then
  3827. trecordsymtable(symtable).ppuwrite(ppufile);
  3828. end;
  3829. function trecorddef.size:asizeint;
  3830. begin
  3831. result:=trecordsymtable(symtable).datasize;
  3832. end;
  3833. function trecorddef.alignment:shortint;
  3834. begin
  3835. alignment:=trecordsymtable(symtable).recordalignment;
  3836. end;
  3837. function trecorddef.padalignment:shortint;
  3838. begin
  3839. padalignment := trecordsymtable(symtable).padalignment;
  3840. end;
  3841. function trecorddef.GetTypeName : string;
  3842. begin
  3843. GetTypeName:='<record type>'
  3844. end;
  3845. {***************************************************************************
  3846. TABSTRACTPROCDEF
  3847. ***************************************************************************}
  3848. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  3849. begin
  3850. inherited create(dt);
  3851. parast:=tparasymtable.create(self,level);
  3852. paras:=nil;
  3853. minparacount:=0;
  3854. maxparacount:=0;
  3855. proctypeoption:=potype_none;
  3856. proccalloption:=pocall_none;
  3857. procoptions:=[];
  3858. returndef:=voidtype;
  3859. savesize:=sizeof(pint);
  3860. callerargareasize:=0;
  3861. calleeargareasize:=0;
  3862. has_paraloc_info:=callnoside;
  3863. funcretloc[callerside].init;
  3864. funcretloc[calleeside].init;
  3865. check_mark_as_nested;
  3866. end;
  3867. destructor tabstractprocdef.destroy;
  3868. begin
  3869. if assigned(paras) then
  3870. begin
  3871. {$ifdef MEMDEBUG}
  3872. memprocpara.start;
  3873. {$endif MEMDEBUG}
  3874. paras.free;
  3875. paras:=nil;
  3876. {$ifdef MEMDEBUG}
  3877. memprocpara.stop;
  3878. {$endif MEMDEBUG}
  3879. end;
  3880. if assigned(parast) then
  3881. begin
  3882. {$ifdef MEMDEBUG}
  3883. memprocparast.start;
  3884. {$endif MEMDEBUG}
  3885. parast.free;
  3886. parast:=nil;
  3887. {$ifdef MEMDEBUG}
  3888. memprocparast.stop;
  3889. {$endif MEMDEBUG}
  3890. end;
  3891. funcretloc[callerside].done;
  3892. funcretloc[calleeside].done;
  3893. inherited destroy;
  3894. end;
  3895. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  3896. begin
  3897. if (tsym(p).typ<>paravarsym) then
  3898. exit;
  3899. inc(plongint(arg)^);
  3900. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  3901. begin
  3902. if not assigned(tparavarsym(p).defaultconstsym) then
  3903. inc(minparacount);
  3904. inc(maxparacount);
  3905. end;
  3906. end;
  3907. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  3908. begin
  3909. if (tsym(p).typ<>paravarsym) then
  3910. exit;
  3911. paras.add(p);
  3912. end;
  3913. procedure tabstractprocdef.calcparas;
  3914. var
  3915. paracount : longint;
  3916. begin
  3917. { This can already be assigned when
  3918. we need to reresolve this unit (PFV) }
  3919. if assigned(paras) then
  3920. paras.free;
  3921. paras:=tparalist.create(false);
  3922. paracount:=0;
  3923. minparacount:=0;
  3924. maxparacount:=0;
  3925. parast.SymList.ForEachCall(@count_para,@paracount);
  3926. paras.capacity:=paracount;
  3927. { Insert parameters in table }
  3928. parast.SymList.ForEachCall(@insert_para,nil);
  3929. { Order parameters }
  3930. paras.sortparas;
  3931. end;
  3932. function tabstractprocdef.mangledprocparanames(oldlen : longint) : string;
  3933. var
  3934. crc : dword;
  3935. hp : TParavarsym;
  3936. hs : TSymStr;
  3937. newlen,
  3938. i : integer;
  3939. begin
  3940. result:='';
  3941. hp:=nil;
  3942. { add parameter types }
  3943. for i:=0 to paras.count-1 do
  3944. begin
  3945. hp:=tparavarsym(paras[i]);
  3946. if not(vo_is_hidden_para in hp.varoptions) then
  3947. result:=result+'$'+hp.vardef.mangledparaname;
  3948. end;
  3949. { add resultdef, add $$ as separator to make it unique from a
  3950. parameter separator }
  3951. if not is_void(returndef) then
  3952. result:=result+'$$'+returndef.mangledparaname;
  3953. newlen:=length(result)+oldlen;
  3954. { Replace with CRC if the parameter line is very long }
  3955. if (newlen-oldlen>12) and
  3956. ((newlen>100) or (newlen-oldlen>64)) then
  3957. begin
  3958. crc:=0;
  3959. for i:=0 to paras.count-1 do
  3960. begin
  3961. hp:=tparavarsym(paras[i]);
  3962. if not(vo_is_hidden_para in hp.varoptions) then
  3963. begin
  3964. hs:=hp.vardef.mangledparaname;
  3965. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3966. end;
  3967. end;
  3968. if not is_void(returndef) then
  3969. begin
  3970. { add a little prefix so that x(integer; integer) is different from x(integer):integer }
  3971. hs:='$$'+returndef.mangledparaname;
  3972. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3973. end;
  3974. result:='$crc'+hexstr(crc,8);
  3975. end;
  3976. end;
  3977. procedure tabstractprocdef.buildderef;
  3978. begin
  3979. { released procdef? }
  3980. if not assigned(parast) then
  3981. exit;
  3982. inherited buildderef;
  3983. returndefderef.build(returndef);
  3984. if po_explicitparaloc in procoptions then
  3985. funcretloc[callerside].buildderef;
  3986. { parast }
  3987. tparasymtable(parast).buildderef;
  3988. end;
  3989. procedure tabstractprocdef.deref;
  3990. begin
  3991. inherited deref;
  3992. returndef:=tdef(returndefderef.resolve);
  3993. if po_explicitparaloc in procoptions then
  3994. begin
  3995. funcretloc[callerside].deref;
  3996. has_paraloc_info:=callerside;
  3997. end
  3998. else
  3999. begin
  4000. { deref is called after loading from a ppu, but also after another
  4001. unit has been reloaded/recompiled and all references must be
  4002. re-resolved. Since the funcretloc contains a reference to a tdef,
  4003. reset it so that we won't try to access the stale def }
  4004. funcretloc[callerside].init;
  4005. has_paraloc_info:=callnoside;
  4006. end;
  4007. { parast }
  4008. tparasymtable(parast).deref;
  4009. { recalculated parameters }
  4010. calcparas;
  4011. end;
  4012. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  4013. begin
  4014. inherited ppuload(dt,ppufile);
  4015. parast:=nil;
  4016. Paras:=nil;
  4017. minparacount:=0;
  4018. maxparacount:=0;
  4019. ppufile.getderef(returndefderef);
  4020. proctypeoption:=tproctypeoption(ppufile.getbyte);
  4021. proccalloption:=tproccalloption(ppufile.getbyte);
  4022. ppufile.getnormalset(procoptions);
  4023. funcretloc[callerside].init;
  4024. if po_explicitparaloc in procoptions then
  4025. funcretloc[callerside].ppuload(ppufile);
  4026. savesize:=sizeof(pint);
  4027. if (po_explicitparaloc in procoptions) then
  4028. has_paraloc_info:=callerside;
  4029. end;
  4030. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  4031. var
  4032. oldintfcrc : boolean;
  4033. begin
  4034. { released procdef? }
  4035. if not assigned(parast) then
  4036. exit;
  4037. inherited ppuwrite(ppufile);
  4038. ppufile.putderef(returndefderef);
  4039. oldintfcrc:=ppufile.do_interface_crc;
  4040. ppufile.do_interface_crc:=false;
  4041. ppufile.putbyte(ord(proctypeoption));
  4042. ppufile.putbyte(ord(proccalloption));
  4043. ppufile.putnormalset(procoptions);
  4044. ppufile.do_interface_crc:=oldintfcrc;
  4045. if (po_explicitparaloc in procoptions) then
  4046. funcretloc[callerside].ppuwrite(ppufile);
  4047. end;
  4048. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  4049. var
  4050. hs,s : ansistring;
  4051. hp : TParavarsym;
  4052. hpc : tconstsym;
  4053. first : boolean;
  4054. i : integer;
  4055. begin
  4056. s:='';
  4057. first:=true;
  4058. for i:=0 to paras.count-1 do
  4059. begin
  4060. hp:=tparavarsym(paras[i]);
  4061. if not(vo_is_hidden_para in hp.varoptions) or
  4062. (pno_showhidden in pno) then
  4063. begin
  4064. if first then
  4065. begin
  4066. s:=s+'(';
  4067. first:=false;
  4068. end
  4069. else
  4070. s:=s+';';
  4071. if vo_is_hidden_para in hp.varoptions then
  4072. s:=s+'<';
  4073. case hp.varspez of
  4074. vs_var :
  4075. s:=s+'var ';
  4076. vs_const :
  4077. s:=s+'const ';
  4078. vs_out :
  4079. s:=s+'out ';
  4080. vs_constref :
  4081. s:=s+'constref ';
  4082. end;
  4083. if (pno_paranames in pno) then
  4084. s:=s+hp.realname+':';
  4085. if hp.univpara then
  4086. s:=s+'univ ';
  4087. if assigned(hp.vardef.typesym) then
  4088. begin
  4089. hs:=hp.vardef.typesym.realname;
  4090. if hs[1]<>'$' then
  4091. s:=s+hp.vardef.OwnerHierarchyName+hs
  4092. else
  4093. s:=s+hp.vardef.GetTypeName;
  4094. end
  4095. else
  4096. s:=s+hp.vardef.GetTypeName;
  4097. { default value }
  4098. if assigned(hp.defaultconstsym) then
  4099. begin
  4100. hpc:=tconstsym(hp.defaultconstsym);
  4101. hs:='';
  4102. case hpc.consttyp of
  4103. conststring,
  4104. constresourcestring :
  4105. begin
  4106. If hpc.value.len>0 then
  4107. begin
  4108. setLength(hs,hpc.value.len);
  4109. { don't write past the end of hs if the constant
  4110. is > 255 chars }
  4111. move(hpc.value.valueptr^,hs[1],length(hs));
  4112. { make sure that constant strings with newline chars
  4113. don't create a linebreak in the assembler code,
  4114. since comments are line-based. Also remove nulls
  4115. because the comments are written as a pchar. }
  4116. ReplaceCase(hs,#0,'.');
  4117. ReplaceCase(hs,#10,'.');
  4118. ReplaceCase(hs,#13,'.');
  4119. end;
  4120. end;
  4121. constreal :
  4122. str(pbestreal(hpc.value.valueptr)^,hs);
  4123. constpointer :
  4124. hs:=tostr(hpc.value.valueordptr);
  4125. constord :
  4126. begin
  4127. if is_boolean(hpc.constdef) then
  4128. begin
  4129. if hpc.value.valueord<>0 then
  4130. hs:='TRUE'
  4131. else
  4132. hs:='FALSE';
  4133. end
  4134. else
  4135. hs:=tostr(hpc.value.valueord);
  4136. end;
  4137. constnil :
  4138. hs:='nil';
  4139. constset :
  4140. hs:='<set>';
  4141. end;
  4142. if hs<>'' then
  4143. s:=s+'="'+hs+'"';
  4144. end;
  4145. if vo_is_hidden_para in hp.varoptions then
  4146. s:=s+'>';
  4147. end;
  4148. end;
  4149. if not first then
  4150. s:=s+')';
  4151. if (po_varargs in procoptions) then
  4152. s:=s+';VarArgs';
  4153. typename_paras:=s;
  4154. end;
  4155. function tabstractprocdef.is_methodpointer:boolean;
  4156. begin
  4157. result:=false;
  4158. end;
  4159. function tabstractprocdef.is_addressonly:boolean;
  4160. begin
  4161. result:=true;
  4162. end;
  4163. function tabstractprocdef.no_self_node: boolean;
  4164. begin
  4165. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  4166. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  4167. end;
  4168. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef;
  4169. var
  4170. j, nestinglevel: longint;
  4171. pvs, npvs: tparavarsym;
  4172. begin
  4173. nestinglevel:=parast.symtablelevel;
  4174. if newtyp=procdef then
  4175. begin
  4176. if (copytyp<>pc_bareproc) then
  4177. result:=cprocdef.create(nestinglevel)
  4178. else
  4179. result:=cprocdef.create(normal_function_level);
  4180. tprocdef(result).visibility:=vis_public;
  4181. end
  4182. else
  4183. begin
  4184. result:=cprocvardef.create(nestinglevel);
  4185. end;
  4186. tabstractprocdef(result).returndef:=returndef;
  4187. tabstractprocdef(result).returndefderef:=returndefderef;
  4188. pvs:=nil;
  4189. npvs:=nil;
  4190. for j:=0 to parast.symlist.count-1 do
  4191. begin
  4192. case tsym(parast.symlist[j]).typ of
  4193. paravarsym:
  4194. begin
  4195. pvs:=tparavarsym(parast.symlist[j]);
  4196. { in case of bare proc, don't copy self, vmt or framepointer
  4197. parameters }
  4198. if (copytyp=pc_bareproc) and
  4199. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result,vo_is_funcret]*pvs.varoptions)<>[]) then
  4200. continue;
  4201. npvs:=cparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  4202. pvs.vardef,pvs.varoptions);
  4203. npvs.defaultconstsym:=pvs.defaultconstsym;
  4204. tabstractprocdef(result).parast.insert(npvs);
  4205. end;
  4206. constsym:
  4207. begin
  4208. // ignore, reuse original constym. Should also be duplicated
  4209. // be safe though
  4210. end;
  4211. symconst.typesym:
  4212. begin
  4213. // reuse original, part of generic declaration
  4214. end
  4215. else
  4216. internalerror(201160604);
  4217. end;
  4218. end;
  4219. tabstractprocdef(result).savesize:=savesize;
  4220. if (typ<>procvardef) and
  4221. (newtyp=procvardef) then
  4222. begin
  4223. { procvars can't be (class)constructures/destructors etc }
  4224. if proctypeoption=potype_constructor then
  4225. begin
  4226. tabstractprocdef(result).returndef:=tdef(owner.defowner);
  4227. if not(is_implicit_pointer_object_type(returndef) or
  4228. (returndef.typ<>objectdef)) then
  4229. tabstractprocdef(result).returndef:=cpointerdef.getreusable(tabstractprocdef(result).returndef);
  4230. tabstractprocdef(result).proctypeoption:=potype_function;
  4231. end
  4232. else if is_void(returndef) then
  4233. tabstractprocdef(result).proctypeoption:=potype_procedure
  4234. else
  4235. tabstractprocdef(result).proctypeoption:=potype_function;
  4236. end
  4237. else
  4238. tabstractprocdef(result).proctypeoption:=proctypeoption;
  4239. tabstractprocdef(result).proccalloption:=proccalloption;
  4240. tabstractprocdef(result).procoptions:=procoptions;
  4241. if (copytyp=pc_bareproc) then
  4242. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  4243. if newtyp=procvardef then
  4244. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  4245. if copytyp=pc_address_only then
  4246. include(tabstractprocdef(result).procoptions,po_addressonly);
  4247. tabstractprocdef(result).callerargareasize:=callerargareasize;
  4248. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  4249. tabstractprocdef(result).maxparacount:=maxparacount;
  4250. tabstractprocdef(result).minparacount:=minparacount;
  4251. if po_explicitparaloc in procoptions then
  4252. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  4253. { recalculate parameter info }
  4254. tabstractprocdef(result).has_paraloc_info:=callnoside;
  4255. {$ifdef m68k}
  4256. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  4257. {$endif}
  4258. if (typ=procdef) and
  4259. (newtyp=procvardef) and
  4260. (owner.symtabletype=ObjectSymtable) then
  4261. include(tprocvardef(result).procoptions,po_methodpointer);
  4262. end;
  4263. procedure tabstractprocdef.check_mark_as_nested;
  4264. begin
  4265. { nested procvars require that nested functions use the Delphi-style
  4266. nested procedure calling convention }
  4267. if (parast.symtablelevel>normal_function_level) and
  4268. (m_nested_procvars in current_settings.modeswitches) then
  4269. include(procoptions,po_delphi_nested_cc);
  4270. end;
  4271. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  4272. begin
  4273. if (side in [callerside,callbothsides]) and
  4274. not(has_paraloc_info in [callerside,callbothsides]) then
  4275. begin
  4276. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  4277. if has_paraloc_info in [calleeside,callbothsides] then
  4278. has_paraloc_info:=callbothsides
  4279. else
  4280. has_paraloc_info:=callerside;
  4281. end;
  4282. if (side in [calleeside,callbothsides]) and
  4283. not(has_paraloc_info in [calleeside,callbothsides]) then
  4284. begin
  4285. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  4286. if has_paraloc_info in [callerside,callbothsides] then
  4287. has_paraloc_info:=callbothsides
  4288. else
  4289. has_paraloc_info:=calleeside;
  4290. end;
  4291. end;
  4292. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  4293. var
  4294. p: tparavarsym;
  4295. ploc: PCGParalocation;
  4296. i: longint;
  4297. begin
  4298. result:=false;
  4299. init_paraloc_info(side);
  4300. for i:=0 to parast.SymList.Count-1 do
  4301. if tsym(parast.SymList[i]).typ=paravarsym then
  4302. begin
  4303. p:=tparavarsym(parast.SymList[i]);
  4304. { check if no parameter is located on the stack }
  4305. if is_open_array(p.vardef) or
  4306. is_array_of_const(p.vardef) then
  4307. begin
  4308. result:=true;
  4309. exit;
  4310. end;
  4311. ploc:=p.paraloc[side].location;
  4312. while assigned(ploc) do
  4313. begin
  4314. if (ploc^.loc=LOC_REFERENCE) then
  4315. begin
  4316. result:=true;
  4317. exit
  4318. end;
  4319. ploc:=ploc^.next;
  4320. end;
  4321. end;
  4322. end;
  4323. function tabstractprocdef.is_pushleftright: boolean;
  4324. begin
  4325. result:=false;
  4326. end;
  4327. function tabstractprocdef.address_type: tdef;
  4328. begin
  4329. result:=voidcodepointertype;
  4330. end;
  4331. procedure tabstractprocdef.declared_far;
  4332. begin
  4333. Message1(parser_w_proc_directive_ignored,'FAR');
  4334. end;
  4335. procedure tabstractprocdef.declared_near;
  4336. begin
  4337. Message1(parser_w_proc_directive_ignored,'NEAR');
  4338. end;
  4339. {***************************************************************************
  4340. TPROCDEF
  4341. ***************************************************************************}
  4342. function tprocdef.GetResultName: PShortString;
  4343. begin
  4344. if not assigned(implprocdefinfo) then
  4345. internalerror(2014010301);
  4346. result:=implprocdefinfo^.resultname;
  4347. end;
  4348. procedure tprocdef.SetResultName(AValue: PShortString);
  4349. begin
  4350. if not assigned(implprocdefinfo) then
  4351. internalerror(2014010302);
  4352. implprocdefinfo^.resultname:=AValue;
  4353. end;
  4354. function tprocdef.GetParentFPInitBlock: tnode;
  4355. begin
  4356. if not assigned(implprocdefinfo) then
  4357. internalerror(2014010303);
  4358. result:=implprocdefinfo^.parentfpinitblock;
  4359. end;
  4360. function tprocdef.GetParentFPStruct: tsym;
  4361. begin
  4362. if not assigned(implprocdefinfo) then
  4363. internalerror(2014010304);
  4364. result:=implprocdefinfo^.parentfpstruct;
  4365. end;
  4366. function tprocdef.GetParentFPStructPtrType: tdef;
  4367. begin
  4368. if not assigned(implprocdefinfo) then
  4369. internalerror(2014010305);
  4370. result:=implprocdefinfo^.parentfpstructptrtype;
  4371. end;
  4372. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  4373. begin
  4374. if not assigned(implprocdefinfo) then
  4375. internalerror(2014010306);
  4376. implprocdefinfo^.parentfpinitblock:=AValue;
  4377. end;
  4378. function tprocdef.Getprocendtai: tai;
  4379. begin
  4380. if not assigned(implprocdefinfo) then
  4381. internalerror(2014010307);
  4382. result:=implprocdefinfo^.procendtai;
  4383. end;
  4384. function tprocdef.Getprocstarttai: tai;
  4385. begin
  4386. if not assigned(implprocdefinfo) then
  4387. internalerror(2014010308);
  4388. result:=implprocdefinfo^.procstarttai;
  4389. end;
  4390. procedure tprocdef.Setprocendtai(AValue: tai);
  4391. begin
  4392. if not assigned(implprocdefinfo) then
  4393. internalerror(2014010309);
  4394. implprocdefinfo^.procendtai:=AValue;
  4395. end;
  4396. function tprocdef.Getskpara: pointer;
  4397. begin
  4398. if not assigned(implprocdefinfo) then
  4399. internalerror(2014010310);
  4400. result:=implprocdefinfo^.skpara;
  4401. end;
  4402. procedure tprocdef.Setskpara(AValue: pointer);
  4403. begin
  4404. if not assigned(implprocdefinfo) then
  4405. internalerror(2014010311);
  4406. implprocdefinfo^.skpara:=AValue;
  4407. end;
  4408. function tprocdef.Getforwarddef: boolean;
  4409. begin
  4410. if not assigned(implprocdefinfo) then
  4411. internalerror(2014010312);
  4412. result:=implprocdefinfo^.forwarddef;
  4413. end;
  4414. function tprocdef.Gethasforward: boolean;
  4415. begin
  4416. if not assigned(implprocdefinfo) then
  4417. internalerror(2014010313);
  4418. result:=implprocdefinfo^.hasforward;
  4419. end;
  4420. function tprocdef.Getinterfacedef: boolean;
  4421. begin
  4422. if not assigned(implprocdefinfo) then
  4423. internalerror(2014010314);
  4424. result:=implprocdefinfo^.interfacedef;
  4425. end;
  4426. procedure tprocdef.Setforwarddef(AValue: boolean);
  4427. begin
  4428. if not assigned(implprocdefinfo) then
  4429. internalerror(2014010315);
  4430. implprocdefinfo^.forwarddef:=AValue;
  4431. end;
  4432. procedure tprocdef.Sethasforward(AValue: boolean);
  4433. begin
  4434. if not assigned(implprocdefinfo) then
  4435. internalerror(2014010316);
  4436. implprocdefinfo^.hasforward:=AValue;
  4437. end;
  4438. function tprocdef.GetIsEmpty: boolean;
  4439. begin
  4440. result:=pio_empty in implprocoptions;
  4441. end;
  4442. procedure tprocdef.SetIsEmpty(AValue: boolean);
  4443. begin
  4444. if AValue then
  4445. include(implprocoptions,pio_empty)
  4446. else
  4447. include(implprocoptions,pio_empty);
  4448. end;
  4449. function tprocdef.GetHasInliningInfo: boolean;
  4450. begin
  4451. result:=pio_has_inlininginfo in implprocoptions;
  4452. end;
  4453. procedure tprocdef.SetHasInliningInfo(AValue: boolean);
  4454. begin
  4455. if AValue then
  4456. include(implprocoptions,pio_has_inlininginfo)
  4457. else
  4458. exclude(implprocoptions,pio_has_inlininginfo);
  4459. end;
  4460. procedure tprocdef.Setinterfacedef(AValue: boolean);
  4461. begin
  4462. if not assigned(implprocdefinfo) then
  4463. internalerror(2014010317);
  4464. implprocdefinfo^.interfacedef:=AValue;
  4465. end;
  4466. procedure tprocdef.Setprocstarttai(AValue: tai);
  4467. begin
  4468. if not assigned(implprocdefinfo) then
  4469. internalerror(2014010318);
  4470. implprocdefinfo^.procstarttai:=AValue;
  4471. end;
  4472. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  4473. begin
  4474. if not assigned(implprocdefinfo) then
  4475. internalerror(2014010319);
  4476. implprocdefinfo^.parentfpstruct:=AValue;
  4477. end;
  4478. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  4479. begin
  4480. if not assigned(implprocdefinfo) then
  4481. internalerror(2014010320);
  4482. implprocdefinfo^.parentfpstructptrtype:=AValue;
  4483. end;
  4484. constructor tprocdef.create(level:byte);
  4485. begin
  4486. inherited create(procdef,level);
  4487. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  4488. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  4489. {$ifdef symansistr}
  4490. _mangledname:='';
  4491. {$else symansistr}
  4492. _mangledname:=nil;
  4493. {$endif symansistr}
  4494. fileinfo:=current_filepos;
  4495. extnumber:=$ffff;
  4496. aliasnames:=TCmdStrList.create;
  4497. funcretsym:=nil;
  4498. forwarddef:=true;
  4499. interfacedef:=false;
  4500. hasforward:=false;
  4501. struct := nil;
  4502. import_dll:=nil;
  4503. import_name:=nil;
  4504. import_nr:=0;
  4505. inlininginfo:=nil;
  4506. deprecatedmsg:=nil;
  4507. end;
  4508. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  4509. var
  4510. i,aliasnamescount : longint;
  4511. level : byte;
  4512. begin
  4513. inherited ppuload(procdef,ppufile);
  4514. {$ifdef symansistr}
  4515. if po_has_mangledname in procoptions then
  4516. _mangledname:=ppufile.getansistring
  4517. else
  4518. _mangledname:='';
  4519. {$else symansistr}
  4520. if po_has_mangledname in procoptions then
  4521. _mangledname:=stringdup(ppufile.getstring)
  4522. else
  4523. _mangledname:=nil;
  4524. {$endif symansistr}
  4525. extnumber:=ppufile.getword;
  4526. level:=ppufile.getbyte;
  4527. ppufile.getderef(structderef);
  4528. ppufile.getderef(procsymderef);
  4529. ppufile.getposinfo(fileinfo);
  4530. visibility:=tvisibility(ppufile.getbyte);
  4531. ppufile.getsmallset(symoptions);
  4532. if sp_has_deprecated_msg in symoptions then
  4533. deprecatedmsg:=stringdup(ppufile.getstring)
  4534. else
  4535. deprecatedmsg:=nil;
  4536. synthetickind:=tsynthetickind(ppufile.getbyte);
  4537. { import stuff }
  4538. if po_has_importdll in procoptions then
  4539. import_dll:=stringdup(ppufile.getstring)
  4540. else
  4541. import_dll:=nil;
  4542. if po_has_importname in procoptions then
  4543. import_name:=stringdup(ppufile.getstring)
  4544. else
  4545. import_name:=nil;
  4546. import_nr:=ppufile.getword;
  4547. if (po_msgint in procoptions) then
  4548. messageinf.i:=ppufile.getlongint;
  4549. if (po_msgstr in procoptions) then
  4550. messageinf.str:=stringdup(ppufile.getstring);
  4551. if (po_dispid in procoptions) then
  4552. dispid:=ppufile.getlongint;
  4553. { inline stuff }
  4554. ppufile.getsmallset(implprocoptions);
  4555. if has_inlininginfo then
  4556. begin
  4557. ppufile.getderef(funcretsymderef);
  4558. new(inlininginfo);
  4559. ppufile.getsmallset(inlininginfo^.flags);
  4560. end
  4561. else
  4562. begin
  4563. inlininginfo:=nil;
  4564. funcretsym:=nil;
  4565. end;
  4566. aliasnames:=TCmdStrList.create;
  4567. { count alias names }
  4568. aliasnamescount:=ppufile.getbyte;
  4569. for i:=1 to aliasnamescount do
  4570. aliasnames.insert(ppufile.getstring);
  4571. ppuload_platform(ppufile);
  4572. { load para symtable }
  4573. parast:=tparasymtable.create(self,level);
  4574. tparasymtable(parast).ppuload(ppufile);
  4575. { load local symtable }
  4576. if has_inlininginfo then
  4577. begin
  4578. localst:=tlocalsymtable.create(self,level);
  4579. tlocalsymtable(localst).ppuload(ppufile);
  4580. end
  4581. else
  4582. localst:=nil;
  4583. { inline stuff }
  4584. if has_inlininginfo then
  4585. inlininginfo^.code:=ppuloadnodetree(ppufile);
  4586. { default values for no persistent data }
  4587. if (cs_link_deffile in current_settings.globalswitches) and
  4588. (tf_need_export in target_info.flags) and
  4589. (po_exports in procoptions) then
  4590. deffile.AddExport(mangledname);
  4591. { Disable po_has_inlining until the derefimpl is done }
  4592. has_inlininginfo:=false;
  4593. end;
  4594. destructor tprocdef.destroy;
  4595. begin
  4596. aliasnames.free;
  4597. aliasnames:=nil;
  4598. if assigned(localst) and
  4599. (localst.symtabletype<>staticsymtable) then
  4600. begin
  4601. {$ifdef MEMDEBUG}
  4602. memproclocalst.start;
  4603. {$endif MEMDEBUG}
  4604. localst.free;
  4605. localst:=nil;
  4606. {$ifdef MEMDEBUG}
  4607. memproclocalst.start;
  4608. {$endif MEMDEBUG}
  4609. end;
  4610. if assigned(inlininginfo) then
  4611. begin
  4612. {$ifdef MEMDEBUG}
  4613. memprocnodetree.start;
  4614. {$endif MEMDEBUG}
  4615. tnode(inlininginfo^.code).free;
  4616. {$ifdef MEMDEBUG}
  4617. memprocnodetree.start;
  4618. {$endif MEMDEBUG}
  4619. dispose(inlininginfo);
  4620. inlininginfo:=nil;
  4621. end;
  4622. if assigned(implprocdefinfo) then
  4623. begin
  4624. stringdispose(implprocdefinfo^.resultname);
  4625. freemem(implprocdefinfo);
  4626. implprocdefinfo:=nil;
  4627. end;
  4628. stringdispose(import_dll);
  4629. stringdispose(import_name);
  4630. stringdispose(deprecatedmsg);
  4631. if (po_msgstr in procoptions) then
  4632. stringdispose(messageinf.str);
  4633. {$ifndef symansistr}
  4634. if assigned(_mangledname) then
  4635. begin
  4636. {$ifdef MEMDEBUG}
  4637. memmanglednames.start;
  4638. {$endif MEMDEBUG}
  4639. stringdispose(_mangledname);
  4640. {$ifdef MEMDEBUG}
  4641. memmanglednames.stop;
  4642. {$endif MEMDEBUG}
  4643. end;
  4644. {$endif symansistr}
  4645. inherited destroy;
  4646. end;
  4647. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  4648. var
  4649. oldintfcrc : boolean;
  4650. aliasnamescount : longint;
  4651. item : TCmdStrListItem;
  4652. begin
  4653. { released procdef? }
  4654. if not assigned(parast) then
  4655. exit;
  4656. inherited ppuwrite(ppufile);
  4657. {$ifdef symansistr}
  4658. if po_has_mangledname in procoptions then
  4659. ppufile.putansistring(_mangledname);
  4660. {$else symansistr}
  4661. if po_has_mangledname in procoptions then
  4662. ppufile.putstring(_mangledname^);
  4663. {$endif symansistr}
  4664. ppufile.putword(extnumber);
  4665. ppufile.putbyte(parast.symtablelevel);
  4666. ppufile.putderef(structderef);
  4667. ppufile.putderef(procsymderef);
  4668. ppufile.putposinfo(fileinfo);
  4669. ppufile.putbyte(byte(visibility));
  4670. ppufile.putsmallset(symoptions);
  4671. if sp_has_deprecated_msg in symoptions then
  4672. ppufile.putstring(deprecatedmsg^);
  4673. ppufile.putbyte(byte(synthetickind));
  4674. { import }
  4675. if po_has_importdll in procoptions then
  4676. ppufile.putstring(import_dll^);
  4677. if po_has_importname in procoptions then
  4678. ppufile.putstring(import_name^);
  4679. ppufile.putword(import_nr);
  4680. if (po_msgint in procoptions) then
  4681. ppufile.putlongint(messageinf.i);
  4682. if (po_msgstr in procoptions) then
  4683. ppufile.putstring(messageinf.str^);
  4684. if (po_dispid in procoptions) then
  4685. ppufile.putlongint(dispid);
  4686. { inline stuff }
  4687. oldintfcrc:=ppufile.do_crc;
  4688. ppufile.do_crc:=false;
  4689. ppufile.putsmallset(implprocoptions);
  4690. if has_inlininginfo then
  4691. begin
  4692. ppufile.putderef(funcretsymderef);
  4693. ppufile.putsmallset(inlininginfo^.flags);
  4694. end;
  4695. { count alias names }
  4696. aliasnamescount:=0;
  4697. item:=TCmdStrListItem(aliasnames.first);
  4698. while assigned(item) do
  4699. begin
  4700. inc(aliasnamescount);
  4701. item:=TCmdStrListItem(item.next);
  4702. end;
  4703. if aliasnamescount>255 then
  4704. internalerror(200711021);
  4705. ppufile.putbyte(aliasnamescount);
  4706. item:=TCmdStrListItem(aliasnames.first);
  4707. while assigned(item) do
  4708. begin
  4709. ppufile.putstring(item.str);
  4710. item:=TCmdStrListItem(item.next);
  4711. end;
  4712. ppufile.do_crc:=oldintfcrc;
  4713. { write this entry }
  4714. writeentry(ppufile,ibprocdef);
  4715. { Save the para symtable, this is taken from the interface }
  4716. tparasymtable(parast).ppuwrite(ppufile);
  4717. { save localsymtable for inline procedures or when local
  4718. browser info is requested, this has no influence on the crc }
  4719. if has_inlininginfo then
  4720. begin
  4721. oldintfcrc:=ppufile.do_crc;
  4722. ppufile.do_crc:=false;
  4723. tlocalsymtable(localst).ppuwrite(ppufile);
  4724. ppufile.do_crc:=oldintfcrc;
  4725. end;
  4726. { node tree for inlining }
  4727. oldintfcrc:=ppufile.do_crc;
  4728. ppufile.do_crc:=false;
  4729. if has_inlininginfo then
  4730. ppuwritenodetree(ppufile,inlininginfo^.code);
  4731. ppufile.do_crc:=oldintfcrc;
  4732. end;
  4733. function tprocdef.fullprocname(showhidden:boolean):string;
  4734. var
  4735. pno: tprocnameoptions;
  4736. begin
  4737. pno:=[];
  4738. if showhidden then
  4739. include(pno,pno_showhidden);
  4740. result:=customprocname(pno);
  4741. end;
  4742. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  4743. var
  4744. s, rn : ansistring;
  4745. t : ttoken;
  4746. begin
  4747. {$ifdef EXTDEBUG}
  4748. include(pno,pno_showhidden);
  4749. {$endif EXTDEBUG}
  4750. s:='';
  4751. if proctypeoption=potype_operator then
  4752. begin
  4753. for t:=NOTOKEN to last_overloaded do
  4754. if procsym.realname='$'+overloaded_names[t] then
  4755. begin
  4756. s:='operator ';
  4757. if (pno_ownername in pno) and
  4758. assigned(struct) then
  4759. s:=s+struct.RttiName+'.';
  4760. s:=s+arraytokeninfo[t].str+typename_paras(pno);
  4761. break;
  4762. end;
  4763. end
  4764. else
  4765. begin
  4766. if (po_classmethod in procoptions) and
  4767. not(pno_noclassmarker in pno) then
  4768. s:='class ';
  4769. case proctypeoption of
  4770. potype_constructor,
  4771. potype_class_constructor:
  4772. s:=s+'constructor ';
  4773. potype_class_destructor,
  4774. potype_destructor:
  4775. s:=s+'destructor ';
  4776. else
  4777. if (pno_proctypeoption in pno) then
  4778. begin
  4779. if assigned(returndef) and
  4780. not(is_void(returndef)) then
  4781. s:=s+'function '
  4782. else
  4783. s:=s+'procedure ';
  4784. end;
  4785. end;
  4786. if (pno_ownername in pno) and
  4787. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  4788. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  4789. rn:=procsym.realname;
  4790. if (pno_noleadingdollar in pno) and
  4791. (rn[1]='$') then
  4792. delete(rn,1,1);
  4793. s:=s+rn+typename_paras(pno);
  4794. end;
  4795. if not(proctypeoption in [potype_constructor,potype_destructor,
  4796. potype_class_constructor,potype_class_destructor]) and
  4797. assigned(returndef) and
  4798. not(is_void(returndef)) then
  4799. s:=s+':'+returndef.GetTypeName;
  4800. if owner.symtabletype=localsymtable then
  4801. s:=s+' is nested'
  4802. else if po_is_block in procoptions then
  4803. s:=s+' is block';
  4804. s:=s+';';
  4805. { forced calling convention? }
  4806. if (po_hascallingconvention in procoptions) then
  4807. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  4808. if (po_staticmethod in procoptions) and
  4809. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  4810. s:=s+' Static;';
  4811. if pno_mangledname in pno then
  4812. s:=s+' -- mangled name: '+mangledname;
  4813. customprocname:=s;
  4814. end;
  4815. function tprocdef.is_methodpointer:boolean;
  4816. begin
  4817. { don't check assigned(_class), that's also the case for nested
  4818. procedures inside methods }
  4819. result:=(owner.symtabletype=ObjectSymtable)and not no_self_node;
  4820. end;
  4821. function tprocdef.is_addressonly:boolean;
  4822. begin
  4823. result:=assigned(owner) and
  4824. not is_methodpointer and
  4825. (not(m_nested_procvars in current_settings.modeswitches) or
  4826. not is_nested_pd(self));
  4827. end;
  4828. procedure tprocdef.make_external;
  4829. begin
  4830. include(procoptions,po_external);
  4831. forwarddef:=false;
  4832. end;
  4833. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  4834. begin
  4835. case t of
  4836. gs_local :
  4837. GetSymtable:=localst;
  4838. gs_para :
  4839. GetSymtable:=parast;
  4840. else
  4841. GetSymtable:=nil;
  4842. end;
  4843. end;
  4844. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp): tstoreddef;
  4845. var
  4846. j : longint;
  4847. begin
  4848. result:=inherited getcopyas(newtyp,copytyp);
  4849. if newtyp=procvardef then
  4850. begin
  4851. { create new paralist }
  4852. tprocvardef(result).calcparas;
  4853. exit;
  4854. end;
  4855. { don't copy mangled name, can be different }
  4856. tprocdef(result).messageinf:=messageinf;
  4857. tprocdef(result).dispid:=dispid;
  4858. if po_msgstr in procoptions then
  4859. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  4860. tprocdef(result).symoptions:=symoptions;
  4861. if assigned(deprecatedmsg) then
  4862. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  4863. { will have to be associated with appropriate procsym }
  4864. tprocdef(result).procsym:=nil;
  4865. { don't create aliases for bare copies, nor copy the funcretsym as
  4866. the function result parameter will be inserted again if necessary
  4867. (e.g. if the calling convention is changed) }
  4868. if copytyp<>pc_bareproc then
  4869. begin
  4870. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  4871. if assigned(funcretsym) then
  4872. begin
  4873. if funcretsym.owner=parast then
  4874. begin
  4875. j:=parast.symlist.indexof(funcretsym);
  4876. if j<0 then
  4877. internalerror(2011040606);
  4878. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  4879. end
  4880. else if funcretsym.owner=localst then
  4881. begin
  4882. { nothing to do, will be inserted for the new procdef while
  4883. parsing its body (by pdecsub.insert_funcret_local) }
  4884. end
  4885. else
  4886. internalerror(2011040605);
  4887. end;
  4888. end;
  4889. { will have to be associated with a new struct }
  4890. tprocdef(result).struct:=nil;
  4891. if assigned(implprocdefinfo) then
  4892. begin
  4893. if assigned(resultname) then
  4894. tprocdef(result).resultname:=stringdup(resultname^);
  4895. end;
  4896. if assigned(import_dll) then
  4897. tprocdef(result).import_dll:=stringdup(import_dll^);
  4898. if assigned(import_name) then
  4899. tprocdef(result).import_name:=stringdup(import_name^);
  4900. tprocdef(result).import_nr:=import_nr;
  4901. tprocdef(result).extnumber:=$ffff;
  4902. tprocdef(result).visibility:=visibility;
  4903. tprocdef(result).synthetickind:=synthetickind;
  4904. { we need a separate implementation for the copied def }
  4905. tprocdef(result).forwarddef:=true;
  4906. tprocdef(result).interfacedef:=true;
  4907. { create new paralist }
  4908. tprocdef(result).calcparas;
  4909. end;
  4910. function tprocdef.getcopy: tstoreddef;
  4911. begin
  4912. result:=getcopyas(procdef,pc_normal);
  4913. end;
  4914. procedure tprocdef.buildderef;
  4915. begin
  4916. inherited buildderef;
  4917. structderef.build(struct);
  4918. { procsym that originaly defined this definition, should be in the
  4919. same symtable }
  4920. procsymderef.build(procsym);
  4921. end;
  4922. procedure tprocdef.buildderefimpl;
  4923. begin
  4924. inherited buildderefimpl;
  4925. { inline tree }
  4926. if has_inlininginfo then
  4927. begin
  4928. { Localst is not available for main/unit init }
  4929. if assigned(localst) then
  4930. begin
  4931. tlocalsymtable(localst).buildderef;
  4932. tlocalsymtable(localst).buildderefimpl;
  4933. end;
  4934. funcretsymderef.build(funcretsym);
  4935. inlininginfo^.code.buildderefimpl;
  4936. end;
  4937. end;
  4938. procedure tprocdef.deref;
  4939. begin
  4940. inherited deref;
  4941. struct:=tabstractrecorddef(structderef.resolve);
  4942. { procsym that originaly defined this definition, should be in the
  4943. same symtable }
  4944. procsym:=tprocsym(procsymderef.resolve);
  4945. end;
  4946. procedure tprocdef.derefimpl;
  4947. begin
  4948. { Enable has_inlininginfo when the inlininginfo
  4949. structure is available. The has_inlininginfo was disabled
  4950. after the load, since the data was invalid }
  4951. if assigned(inlininginfo) then
  4952. has_inlininginfo:=true;
  4953. { Inline }
  4954. if has_inlininginfo then
  4955. begin
  4956. { Locals }
  4957. if assigned(localst) then
  4958. begin
  4959. tlocalsymtable(localst).deref;
  4960. tlocalsymtable(localst).derefimpl;
  4961. end;
  4962. inlininginfo^.code.derefimpl;
  4963. { funcretsym, this is always located in the localst }
  4964. funcretsym:=tsym(funcretsymderef.resolve);
  4965. end
  4966. else
  4967. begin
  4968. { safety }
  4969. { Not safe! A unit may be reresolved after its interface has been
  4970. parsed but before its implementation has been parsed, and in that
  4971. case the funcretsym is still required!
  4972. funcretsym:=nil; }
  4973. end;
  4974. end;
  4975. function tprocdef.GetTypeName : string;
  4976. begin
  4977. GetTypeName := FullProcName(false);
  4978. end;
  4979. function tprocdef.mangledname : TSymStr;
  4980. begin
  4981. {$ifdef symansistr}
  4982. if _mangledname='' then
  4983. begin
  4984. result:=defaultmangledname;
  4985. _mangledname:=result;
  4986. end
  4987. else
  4988. result:=_mangledname;
  4989. {$else symansistr}
  4990. if not assigned(_mangledname) then
  4991. begin
  4992. result:=defaultmangledname;
  4993. _mangledname:=stringdup(mangledname);
  4994. end
  4995. else
  4996. result:=_mangledname^;
  4997. {$endif symansistr}
  4998. end;
  4999. function tprocdef.defaultmangledname: TSymStr;
  5000. begin
  5001. { we need to use the symtable where the procsym is inserted,
  5002. because that is visible to the world }
  5003. defaultmangledname:=make_mangledname('',procsym.owner,procsym.name);
  5004. defaultmangledname:=defaultmangledname+mangledprocparanames(Length(defaultmangledname))
  5005. end;
  5006. function tprocdef.cplusplusmangledname : TSymStr;
  5007. function getcppparaname(p : tdef) : TSymStr;
  5008. const
  5009. {$ifdef NAMEMANGLING_GCC2}
  5010. ordtype2str : array[tordtype] of string[2] = (
  5011. '',
  5012. 'Uc','Us','Ui','Us',
  5013. 'Sc','s','i','x',
  5014. 'b','b','b','b','b',
  5015. 'c','w','x');
  5016. {$else NAMEMANGLING_GCC2}
  5017. ordtype2str : array[tordtype] of string[1] = (
  5018. 'v',
  5019. 'h','t','j','y',
  5020. 'a','s','i','x',
  5021. 'b','b','b','b',
  5022. 'b','b','b','b',
  5023. 'c','w','x');
  5024. floattype2str : array[tfloattype] of string[1] = (
  5025. 'f','d','e','e',
  5026. 'd','d','g');
  5027. {$endif NAMEMANGLING_GCC2}
  5028. var
  5029. s : TSymStr;
  5030. begin
  5031. case p.typ of
  5032. orddef:
  5033. s:=ordtype2str[torddef(p).ordtype];
  5034. pointerdef:
  5035. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  5036. {$ifndef NAMEMANGLING_GCC2}
  5037. floatdef:
  5038. s:=floattype2str[tfloatdef(p).floattype];
  5039. {$endif NAMEMANGLING_GCC2}
  5040. else
  5041. internalerror(2103001);
  5042. end;
  5043. getcppparaname:=s;
  5044. end;
  5045. var
  5046. s,s2 : TSymStr;
  5047. hp : TParavarsym;
  5048. i : integer;
  5049. begin
  5050. {$ifdef NAMEMANGLING_GCC2}
  5051. { outdated gcc 2.x name mangling scheme }
  5052. s := procsym.realname;
  5053. if procsym.owner.symtabletype=ObjectSymtable then
  5054. begin
  5055. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  5056. case proctypeoption of
  5057. potype_destructor:
  5058. s:='_$_'+tostr(length(s2))+s2;
  5059. potype_constructor:
  5060. s:='___'+tostr(length(s2))+s2;
  5061. else
  5062. s:='_'+s+'__'+tostr(length(s2))+s2;
  5063. end;
  5064. end
  5065. else s:=s+'__';
  5066. s:=s+'F';
  5067. { concat modifiers }
  5068. { !!!!! }
  5069. { now we handle the parameters }
  5070. if maxparacount>0 then
  5071. begin
  5072. for i:=0 to paras.count-1 do
  5073. begin
  5074. hp:=tparavarsym(paras[i]);
  5075. { no hidden parameters form part of a C++ mangled name:
  5076. a) self is not included
  5077. b) there are no "high" or other hidden parameters
  5078. }
  5079. if vo_is_hidden_para in hp.varoptions then
  5080. continue;
  5081. s2:=getcppparaname(hp.vardef);
  5082. if hp.varspez in [vs_var,vs_out] then
  5083. s2:='R'+s2;
  5084. s:=s+s2;
  5085. end;
  5086. end
  5087. else
  5088. s:=s+'v';
  5089. cplusplusmangledname:=s;
  5090. {$else NAMEMANGLING_GCC2}
  5091. { gcc 3.x and 4.x name mangling scheme }
  5092. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  5093. if procsym.owner.symtabletype=ObjectSymtable then
  5094. begin
  5095. s:='_ZN';
  5096. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  5097. s:=s+tostr(length(s2))+s2;
  5098. case proctypeoption of
  5099. potype_constructor:
  5100. s:=s+'C1';
  5101. potype_destructor:
  5102. s:=s+'D1';
  5103. else
  5104. s:=s+tostr(length(procsym.realname))+procsym.realname;
  5105. end;
  5106. s:=s+'E';
  5107. end
  5108. else
  5109. s:=procsym.realname;
  5110. { now we handle the parameters }
  5111. if maxparacount>0 then
  5112. begin
  5113. for i:=0 to paras.count-1 do
  5114. begin
  5115. hp:=tparavarsym(paras[i]);
  5116. { no hidden parameters form part of a C++ mangled name:
  5117. a) self is not included
  5118. b) there are no "high" or other hidden parameters
  5119. }
  5120. if vo_is_hidden_para in hp.varoptions then
  5121. continue;
  5122. s2:=getcppparaname(hp.vardef);
  5123. if hp.varspez in [vs_var,vs_out] then
  5124. s2:='R'+s2;
  5125. s:=s+s2;
  5126. end;
  5127. end
  5128. else
  5129. s:=s+'v';
  5130. cplusplusmangledname:=s;
  5131. {$endif NAMEMANGLING_GCC2}
  5132. end;
  5133. function tprocdef.objcmangledname : TSymStr;
  5134. var
  5135. manglednamelen: longint;
  5136. iscatmethod : boolean;
  5137. begin
  5138. if not (po_msgstr in procoptions) then
  5139. internalerror(2009030901);
  5140. { we may very well need longer strings to handle these... }
  5141. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  5142. length('+"[ ]"')+length(messageinf.str^);
  5143. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  5144. if (iscatmethod) then
  5145. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  5146. if manglednamelen>255 then
  5147. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  5148. if not(po_classmethod in procoptions) then
  5149. result:='"-['
  5150. else
  5151. result:='"+[';
  5152. { quotes are necessary because the +/- otherwise confuse the assembler
  5153. into expecting a number
  5154. }
  5155. if iscatmethod then
  5156. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  5157. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  5158. if iscatmethod then
  5159. result:=result+')';
  5160. result:=result+' '+messageinf.str^+']"';
  5161. end;
  5162. procedure tprocdef.setmangledname(const s : TSymStr);
  5163. begin
  5164. { This is not allowed anymore, the forward declaration
  5165. already needs to create the correct mangledname, no changes
  5166. afterwards are allowed (PFV) }
  5167. { Exception: interface definitions in mode macpas, since in that }
  5168. { case no reference to the old name can exist yet (JM) }
  5169. {$ifdef symansistr}
  5170. if _mangledname<>'' then
  5171. if ((m_mac in current_settings.modeswitches) and
  5172. (interfacedef)) then
  5173. _mangledname:=''
  5174. else
  5175. internalerror(200411171);
  5176. {$else symansistr}
  5177. if assigned(_mangledname) then
  5178. if ((m_mac in current_settings.modeswitches) and
  5179. (interfacedef)) then
  5180. stringdispose(_mangledname)
  5181. else
  5182. internalerror(200411171);
  5183. {$endif symansistr}
  5184. {$ifdef jvm}
  5185. { this routine can be called for compilerproces. can't set mangled
  5186. name since it must be calculated, but it uses import_name when set
  5187. -> set that one }
  5188. import_name:=stringdup(s);
  5189. include(procoptions,po_has_importname);
  5190. include(procoptions,po_has_mangledname);
  5191. {$else}
  5192. {$ifdef symansistr}
  5193. _mangledname:=s;
  5194. {$else symansistr}
  5195. _mangledname:=stringdup(s);
  5196. {$endif symansistr}
  5197. {$endif jvm}
  5198. include(procoptions,po_has_mangledname);
  5199. end;
  5200. {***************************************************************************
  5201. TPROCVARDEF
  5202. ***************************************************************************}
  5203. constructor tprocvardef.create(level:byte);
  5204. begin
  5205. inherited create(procvardef,level);
  5206. end;
  5207. class function tprocvardef.getreusableprocaddr(def: tabstractprocdef): tprocvardef;
  5208. var
  5209. res: PHashSetItem;
  5210. oldsymtablestack: tsymtablestack;
  5211. begin
  5212. if not assigned(current_module) then
  5213. internalerror(2011081301);
  5214. res:=current_module.procaddrdefs.FindOrAdd(@def,sizeof(def));
  5215. if not assigned(res^.Data) then
  5216. begin
  5217. { since these pointerdefs can be reused anywhere in the current
  5218. unit, add them to the global/staticsymtable (or local symtable
  5219. if they're a local def, because otherwise they'll be saved
  5220. to the ppu referencing a local symtable entry that doesn't
  5221. exist in the ppu) }
  5222. oldsymtablestack:=symtablestack;
  5223. { do not simply push/pop current_module.localsymtable, because
  5224. that can have side-effects (e.g., it removes helpers) }
  5225. symtablestack:=nil;
  5226. res^.Data:=def.getcopyas(procvardef,pc_address_only);
  5227. def.getreusablesymtab.insertdef(tdef(res^.Data));
  5228. symtablestack:=oldsymtablestack;
  5229. end;
  5230. result:=tprocvardef(res^.Data);
  5231. end;
  5232. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  5233. begin
  5234. inherited ppuload(procvardef,ppufile);
  5235. { load para symtable }
  5236. parast:=tparasymtable.create(self,ppufile.getbyte);
  5237. ppuload_platform(ppufile);
  5238. tparasymtable(parast).ppuload(ppufile);
  5239. end;
  5240. function tprocvardef.getcopy : tstoreddef;
  5241. var
  5242. i : tcallercallee;
  5243. j : longint;
  5244. begin
  5245. result:=cprocvardef.create(parast.symtablelevel);
  5246. tprocvardef(result).returndef:=returndef;
  5247. tprocvardef(result).returndefderef:=returndefderef;
  5248. tprocvardef(result).parast:=parast.getcopy;
  5249. tprocvardef(result).savesize:=savesize;
  5250. { create paralist copy }
  5251. calcparas;
  5252. tprocvardef(result).paras:=tparalist.create(false);
  5253. tprocvardef(result).paras.count:=paras.count;
  5254. for j:=0 to paras.count-1 do
  5255. tprocvardef(result).paras[j]:=paras[j];
  5256. tprocvardef(result).proctypeoption:=proctypeoption;
  5257. tprocvardef(result).proccalloption:=proccalloption;
  5258. tprocvardef(result).procoptions:=procoptions;
  5259. tprocvardef(result).callerargareasize:=callerargareasize;
  5260. tprocvardef(result).calleeargareasize:=calleeargareasize;
  5261. tprocvardef(result).maxparacount:=maxparacount;
  5262. tprocvardef(result).minparacount:=minparacount;
  5263. for i:=low(tcallercallee) to high(tcallercallee) do
  5264. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  5265. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  5266. {$ifdef m68k}
  5267. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  5268. {$endif}
  5269. end;
  5270. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  5271. begin
  5272. inherited ppuwrite(ppufile);
  5273. { Save the para symtable level (necessary to distinguish nested
  5274. procvars) }
  5275. ppufile.putbyte(parast.symtablelevel);
  5276. { Write this entry }
  5277. writeentry(ppufile,ibprocvardef);
  5278. { Save the para symtable, this is taken from the interface }
  5279. tparasymtable(parast).ppuwrite(ppufile);
  5280. end;
  5281. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  5282. begin
  5283. case t of
  5284. gs_para :
  5285. GetSymtable:=parast;
  5286. else
  5287. GetSymtable:=nil;
  5288. end;
  5289. end;
  5290. function tprocvardef.size : asizeint;
  5291. begin
  5292. if ((po_methodpointer in procoptions) or
  5293. is_nested_pd(self)) and
  5294. not(po_addressonly in procoptions) then
  5295. begin
  5296. if is_nested_pd(self) then
  5297. size:=voidcodepointertype.size+parentfpvoidpointertype.size
  5298. else
  5299. size:=voidcodepointertype.size+voidpointertype.size;
  5300. end
  5301. else
  5302. size:=voidcodepointertype.size;
  5303. end;
  5304. function tprocvardef.is_methodpointer:boolean;
  5305. begin
  5306. result:=(po_methodpointer in procoptions);
  5307. end;
  5308. function tprocvardef.is_addressonly:boolean;
  5309. begin
  5310. result:=(not(po_methodpointer in procoptions) and
  5311. not is_nested_pd(self)) or
  5312. (po_addressonly in procoptions);
  5313. end;
  5314. function tprocvardef.getmangledparaname:TSymStr;
  5315. begin
  5316. if not(po_methodpointer in procoptions) then
  5317. if not is_nested_pd(self) then
  5318. result:='procvar'
  5319. else
  5320. { we need the manglednames here, because nestedprocvars can be anonymous, e.g.
  5321. having not a type name or not an unique one, see webtbs/tw27515.pp
  5322. Further, use $_ ... _$ delimiters to avoid ambiguous names, see webtbs/tw27515.pp }
  5323. result:='$_nestedprovar'+mangledprocparanames(0)+'_$'
  5324. else
  5325. result:='procvarofobj'
  5326. end;
  5327. function tprocvardef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp): tstoreddef;
  5328. begin
  5329. result:=inherited;
  5330. tabstractprocdef(result).calcparas;
  5331. end;
  5332. function tprocvardef.is_publishable : boolean;
  5333. begin
  5334. is_publishable:=(po_methodpointer in procoptions);
  5335. end;
  5336. function tprocvardef.GetTypeName : string;
  5337. var
  5338. s: string;
  5339. pno : tprocnameoptions;
  5340. begin
  5341. {$ifdef EXTDEBUG}
  5342. pno:=[pno_showhidden];
  5343. {$else EXTDEBUG}
  5344. pno:=[];
  5345. {$endif EXTDEBUG}
  5346. s:='<';
  5347. if po_classmethod in procoptions then
  5348. s := s+'class method type of'
  5349. else
  5350. if po_addressonly in procoptions then
  5351. s := s+'address of'
  5352. else
  5353. s := s+'procedure variable type of';
  5354. if assigned(returndef) and
  5355. (returndef<>voidtype) then
  5356. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  5357. else
  5358. s:=s+' procedure'+typename_paras(pno);
  5359. if po_methodpointer in procoptions then
  5360. s := s+' of object';
  5361. if is_nested_pd(self) then
  5362. s := s+' is nested';
  5363. { calling convention doesn't matter for blocks }
  5364. if po_is_block in procoptions then
  5365. GetTypeName := s+' is block;'
  5366. else
  5367. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  5368. end;
  5369. {***************************************************************************
  5370. TOBJECTDEF
  5371. ***************************************************************************}
  5372. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  5373. begin
  5374. inherited create(n,objectdef);
  5375. fcurrent_dispid:=0;
  5376. objecttype:=ot;
  5377. childof:=nil;
  5378. if objecttype=odt_helper then
  5379. owner.includeoption(sto_has_helper);
  5380. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords,
  5381. current_settings.alignment.recordalignmin,current_settings.alignment.maxCrecordalign);
  5382. { create space for vmt !! }
  5383. vmtentries:=TFPList.Create;
  5384. set_parent(c);
  5385. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  5386. prepareguid;
  5387. { setup implemented interfaces }
  5388. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5389. ImplementedInterfaces:=TFPObjectList.Create(true)
  5390. else
  5391. ImplementedInterfaces:=nil;
  5392. writing_class_record_dbginfo:=false;
  5393. end;
  5394. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  5395. var
  5396. i,
  5397. implintfcount : longint;
  5398. d, getterd : tderef;
  5399. ImplIntf : TImplementedInterface;
  5400. vmtentry : pvmtentry;
  5401. begin
  5402. inherited ppuload(objectdef,ppufile);
  5403. objecttype:=tobjecttyp(ppufile.getbyte);
  5404. objextname:=stringdup(ppufile.getstring);
  5405. { only used for external Objective-C classes/protocols }
  5406. if (objextname^='') then
  5407. stringdispose(objextname);
  5408. symtable:=tObjectSymtable.create(self,objrealname^,0,0,0);
  5409. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  5410. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  5411. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  5412. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  5413. tObjectSymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  5414. ppufile.getderef(vmt_fieldderef);
  5415. ppufile.getderef(childofderef);
  5416. { load guid }
  5417. iidstr:=nil;
  5418. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5419. begin
  5420. new(iidguid);
  5421. ppufile.getguid(iidguid^);
  5422. iidstr:=stringdup(ppufile.getstring);
  5423. end;
  5424. abstractcnt:=ppufile.getlongint;
  5425. if objecttype=odt_helper then
  5426. ppufile.getderef(extendeddefderef);
  5427. vmtentries:=TFPList.Create;
  5428. vmtentries.count:=ppufile.getlongint;
  5429. for i:=0 to vmtentries.count-1 do
  5430. begin
  5431. ppufile.getderef(d);
  5432. new(vmtentry);
  5433. vmtentry^.procdef:=nil;
  5434. vmtentry^.procdefderef:=d;
  5435. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  5436. vmtentries[i]:=vmtentry;
  5437. end;
  5438. { load implemented interfaces }
  5439. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5440. begin
  5441. ImplementedInterfaces:=TFPObjectList.Create(true);
  5442. implintfcount:=ppufile.getlongint;
  5443. for i:=0 to implintfcount-1 do
  5444. begin
  5445. ppufile.getderef(d);
  5446. ppufile.getderef(getterd);
  5447. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  5448. ImplIntf.IOffset:=ppufile.getlongint;
  5449. byte(ImplIntf.IType):=ppufile.getbyte;
  5450. ImplementedInterfaces.Add(ImplIntf);
  5451. end;
  5452. end
  5453. else
  5454. ImplementedInterfaces:=nil;
  5455. if df_copied_def in defoptions then
  5456. begin
  5457. ppufile.getderef(cloneddefderef);
  5458. ppuload_platform(ppufile);
  5459. end
  5460. else
  5461. begin
  5462. ppuload_platform(ppufile);
  5463. tObjectSymtable(symtable).ppuload(ppufile);
  5464. end;
  5465. { handles the predefined class tobject }
  5466. { the last TOBJECT which is loaded gets }
  5467. { it ! }
  5468. if (childof=nil) and
  5469. (objecttype in [odt_class,odt_javaclass]) and
  5470. (objname^='TOBJECT') then
  5471. class_tobject:=self;
  5472. if (childof=nil) and
  5473. (objecttype=odt_interfacecom) then
  5474. if (objname^='IUNKNOWN') then
  5475. interface_iunknown:=self
  5476. else
  5477. if (objname^='IDISPATCH') then
  5478. interface_idispatch:=self;
  5479. if (childof=nil) and
  5480. (objecttype=odt_objcclass) and
  5481. (objname^='PROTOCOL') then
  5482. objc_protocoltype:=self;
  5483. if (objecttype=odt_javaclass) and
  5484. not(oo_is_formal in objectoptions) then
  5485. begin
  5486. if (objname^='JLOBJECT') then
  5487. java_jlobject:=self
  5488. else if (objname^='JLTHROWABLE') then
  5489. java_jlthrowable:=self
  5490. else if (objname^='FPCBASERECORDTYPE') then
  5491. java_fpcbaserecordtype:=self
  5492. else if (objname^='JLSTRING') then
  5493. java_jlstring:=self
  5494. else if (objname^='ANSISTRINGCLASS') then
  5495. java_ansistring:=self
  5496. else if (objname^='SHORTSTRINGCLASS') then
  5497. java_shortstring:=self
  5498. else if (objname^='JLENUM') then
  5499. java_jlenum:=self
  5500. else if (objname^='JUENUMSET') then
  5501. java_juenumset:=self
  5502. else if (objname^='FPCBITSET') then
  5503. java_jubitset:=self
  5504. else if (objname^='FPCBASEPROCVARTYPE') then
  5505. java_procvarbase:=self;
  5506. end;
  5507. writing_class_record_dbginfo:=false;
  5508. end;
  5509. destructor tobjectdef.destroy;
  5510. begin
  5511. if assigned(symtable) then
  5512. begin
  5513. symtable.free;
  5514. symtable:=nil;
  5515. end;
  5516. stringdispose(objextname);
  5517. stringdispose(iidstr);
  5518. if assigned(ImplementedInterfaces) then
  5519. begin
  5520. ImplementedInterfaces.free;
  5521. ImplementedInterfaces:=nil;
  5522. end;
  5523. if assigned(iidguid) then
  5524. begin
  5525. dispose(iidguid);
  5526. iidguid:=nil;
  5527. end;
  5528. if assigned(vmtentries) then
  5529. begin
  5530. resetvmtentries;
  5531. vmtentries.free;
  5532. vmtentries:=nil;
  5533. end;
  5534. if assigned(vmcallstaticinfo) then
  5535. begin
  5536. freemem(vmcallstaticinfo);
  5537. vmcallstaticinfo:=nil;
  5538. end;
  5539. inherited destroy;
  5540. end;
  5541. function tobjectdef.getcopy : tstoreddef;
  5542. var
  5543. i : longint;
  5544. begin
  5545. result:=cobjectdef.create(objecttype,objrealname^,childof);
  5546. { the constructor allocates a symtable which we release to avoid memory leaks }
  5547. tobjectdef(result).symtable.free;
  5548. tobjectdef(result).symtable:=symtable.getcopy;
  5549. if assigned(objextname) then
  5550. tobjectdef(result).objextname:=stringdup(objextname^);
  5551. if assigned(import_lib) then
  5552. tobjectdef(result).import_lib:=stringdup(import_lib^);
  5553. tobjectdef(result).objectoptions:=objectoptions;
  5554. include(tobjectdef(result).defoptions,df_copied_def);
  5555. tobjectdef(result).extendeddef:=extendeddef;
  5556. if assigned(tcinitcode) then
  5557. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  5558. tobjectdef(result).vmt_field:=vmt_field;
  5559. if assigned(iidguid) then
  5560. begin
  5561. new(tobjectdef(result).iidguid);
  5562. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  5563. end;
  5564. if assigned(iidstr) then
  5565. tobjectdef(result).iidstr:=stringdup(iidstr^);
  5566. tobjectdef(result).abstractcnt:=abstractcnt;
  5567. if assigned(ImplementedInterfaces) then
  5568. begin
  5569. for i:=0 to ImplementedInterfaces.count-1 do
  5570. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  5571. end;
  5572. if assigned(vmtentries) then
  5573. begin
  5574. tobjectdef(result).vmtentries:=TFPList.Create;
  5575. tobjectdef(result).copyvmtentries(self);
  5576. end;
  5577. end;
  5578. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  5579. var
  5580. i : longint;
  5581. vmtentry : pvmtentry;
  5582. ImplIntf : TImplementedInterface;
  5583. old_do_indirect_crc: boolean;
  5584. begin
  5585. { if class1 in unit A changes, and class2 in unit B inherits from it
  5586. (so unit B uses unit A), then unit B with class2 will be recompiled.
  5587. However, if there is also a class3 in unit C that only depends on
  5588. unit B, then unit C will not be recompiled because nothing changed
  5589. to the interface of unit B. Nevertheless, unit C can indirectly
  5590. depend on unit A via derefs, and these must be updated -> the
  5591. indirect crc keeps track of such changes. }
  5592. old_do_indirect_crc:=ppufile.do_indirect_crc;
  5593. ppufile.do_indirect_crc:=true;
  5594. inherited ppuwrite(ppufile);
  5595. ppufile.putbyte(byte(objecttype));
  5596. if assigned(objextname) then
  5597. ppufile.putstring(objextname^)
  5598. else
  5599. ppufile.putstring('');
  5600. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  5601. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  5602. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  5603. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  5604. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignmin));
  5605. ppufile.putderef(vmt_fieldderef);
  5606. ppufile.putderef(childofderef);
  5607. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5608. begin
  5609. ppufile.putguid(iidguid^);
  5610. ppufile.putstring(iidstr^);
  5611. end;
  5612. ppufile.putlongint(abstractcnt);
  5613. if objecttype=odt_helper then
  5614. ppufile.putderef(extendeddefderef);
  5615. ppufile.putlongint(vmtentries.count);
  5616. for i:=0 to vmtentries.count-1 do
  5617. begin
  5618. vmtentry:=pvmtentry(vmtentries[i]);
  5619. ppufile.putderef(vmtentry^.procdefderef);
  5620. ppufile.putbyte(byte(vmtentry^.visibility));
  5621. end;
  5622. if assigned(ImplementedInterfaces) then
  5623. begin
  5624. ppufile.putlongint(ImplementedInterfaces.Count);
  5625. for i:=0 to ImplementedInterfaces.Count-1 do
  5626. begin
  5627. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  5628. ppufile.putderef(ImplIntf.intfdefderef);
  5629. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  5630. ppufile.putlongint(ImplIntf.Ioffset);
  5631. ppufile.putbyte(byte(ImplIntf.IType));
  5632. end;
  5633. end;
  5634. if df_copied_def in defoptions then
  5635. ppufile.putderef(cloneddefderef);
  5636. writeentry(ppufile,ibobjectdef);
  5637. if not(df_copied_def in defoptions) then
  5638. tObjectSymtable(symtable).ppuwrite(ppufile);
  5639. ppufile.do_indirect_crc:=old_do_indirect_crc;
  5640. end;
  5641. function tobjectdef.GetTypeName:string;
  5642. begin
  5643. { in this case we will go in endless recursion, because then }
  5644. { there is no tsym associated yet with the def. It can occur }
  5645. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  5646. { instead of the actual type name }
  5647. if not assigned(typesym) then
  5648. result:='<Currently Parsed Class>'
  5649. else
  5650. result:=typesymbolprettyname;
  5651. end;
  5652. procedure tobjectdef.buildderef;
  5653. var
  5654. i : longint;
  5655. vmtentry : pvmtentry;
  5656. begin
  5657. inherited buildderef;
  5658. vmt_fieldderef.build(vmt_field);
  5659. childofderef.build(childof);
  5660. if df_copied_def in defoptions then
  5661. cloneddefderef.build(symtable.defowner)
  5662. else
  5663. tstoredsymtable(symtable).buildderef;
  5664. if objecttype=odt_helper then
  5665. extendeddefderef.build(extendeddef);
  5666. for i:=0 to vmtentries.count-1 do
  5667. begin
  5668. vmtentry:=pvmtentry(vmtentries[i]);
  5669. vmtentry^.procdefderef.build(vmtentry^.procdef);
  5670. end;
  5671. if assigned(ImplementedInterfaces) then
  5672. begin
  5673. for i:=0 to ImplementedInterfaces.count-1 do
  5674. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  5675. end;
  5676. end;
  5677. procedure tobjectdef.deref;
  5678. var
  5679. i : longint;
  5680. vmtentry : pvmtentry;
  5681. begin
  5682. inherited deref;
  5683. vmt_field:=tsym(vmt_fieldderef.resolve);
  5684. childof:=tobjectdef(childofderef.resolve);
  5685. if df_copied_def in defoptions then
  5686. begin
  5687. cloneddef:=tobjectdef(cloneddefderef.resolve);
  5688. symtable:=cloneddef.symtable.getcopy;
  5689. end
  5690. else
  5691. tstoredsymtable(symtable).deref;
  5692. if objecttype=odt_helper then
  5693. extendeddef:=tdef(extendeddefderef.resolve);
  5694. for i:=0 to vmtentries.count-1 do
  5695. begin
  5696. vmtentry:=pvmtentry(vmtentries[i]);
  5697. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  5698. end;
  5699. if assigned(ImplementedInterfaces) then
  5700. begin
  5701. for i:=0 to ImplementedInterfaces.count-1 do
  5702. TImplementedInterface(ImplementedInterfaces[i]).deref;
  5703. end;
  5704. end;
  5705. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  5706. var
  5707. pd: tprocdef absolute def;
  5708. st: tsymtable;
  5709. psym: tsym;
  5710. nname: TIDString;
  5711. begin
  5712. if (tdef(def).typ<>procdef) then
  5713. exit;
  5714. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  5715. owner = symtable in which objcclassdef is defined
  5716. }
  5717. st:=pd.owner.defowner.owner;
  5718. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  5719. { check for an existing procsym with our special name }
  5720. psym:=tsym(st.find(nname));
  5721. if not assigned(psym) then
  5722. begin
  5723. psym:=cprocsym.create(nname);
  5724. { avoid warning about this symbol being unused }
  5725. psym.IncRefCount;
  5726. { don't check for duplicates:
  5727. a) we checked above
  5728. b) in case we are in the implementation section of a unit, this
  5729. will also check for this symbol in the interface section
  5730. (since you normally cannot have symbols with the same name
  5731. both interface and implementation), and it's possible to
  5732. have class helpers for the same class in the interface and
  5733. in the implementation, and they cannot be merged since only
  5734. the once in the interface must be saved to the ppu/visible
  5735. from other units }
  5736. st.insert(psym,false);
  5737. end
  5738. else if (psym.typ<>procsym) then
  5739. internalerror(2009111501);
  5740. { add ourselves to this special procsym }
  5741. tprocsym(psym).procdeflist.add(def);
  5742. end;
  5743. procedure tobjectdef.derefimpl;
  5744. begin
  5745. inherited derefimpl;
  5746. { the procdefs are not owned by the class helper procsyms, so they
  5747. are not stored/restored either -> re-add them here }
  5748. if (objecttype in [odt_objcclass,odt_objcprotocol]) or
  5749. (oo_is_classhelper in objectoptions) then
  5750. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  5751. end;
  5752. procedure tobjectdef.resetvmtentries;
  5753. var
  5754. i : longint;
  5755. begin
  5756. for i:=0 to vmtentries.Count-1 do
  5757. Dispose(pvmtentry(vmtentries[i]));
  5758. vmtentries.clear;
  5759. end;
  5760. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  5761. var
  5762. i : longint;
  5763. vmtentry : pvmtentry;
  5764. begin
  5765. resetvmtentries;
  5766. vmtentries.count:=objdef.vmtentries.count;
  5767. for i:=0 to objdef.vmtentries.count-1 do
  5768. begin
  5769. new(vmtentry);
  5770. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  5771. vmtentries[i]:=vmtentry;
  5772. end;
  5773. end;
  5774. function tobjectdef.getparentdef:tdef;
  5775. begin
  5776. { TODO: Remove getparentdef hack}
  5777. { With 2 forward declared classes with the child class before the
  5778. parent class the child class is written earlier to the ppu. Leaving it
  5779. possible to have a reference to the parent class for property overriding,
  5780. but the parent class still has the childof not resolved yet (PFV) }
  5781. if childof=nil then
  5782. childof:=tobjectdef(childofderef.resolve);
  5783. result:=childof;
  5784. end;
  5785. procedure tobjectdef.prepareguid;
  5786. begin
  5787. { set up guid }
  5788. if not assigned(iidguid) then
  5789. begin
  5790. new(iidguid);
  5791. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  5792. end;
  5793. { setup iidstring }
  5794. if not assigned(iidstr) then
  5795. iidstr:=stringdup(''); { default is empty string }
  5796. end;
  5797. procedure tobjectdef.set_parent( c : tobjectdef);
  5798. begin
  5799. if assigned(childof) then
  5800. exit;
  5801. childof:=c;
  5802. if not assigned(c) then
  5803. exit;
  5804. { inherit options and status }
  5805. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  5806. { initially has the same number of abstract methods as the parent }
  5807. abstractcnt:=c.abstractcnt;
  5808. { add the data of the anchestor class/object }
  5809. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  5810. begin
  5811. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  5812. { inherit recordalignment }
  5813. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  5814. { if both the parent and this record use C-alignment, also inherit
  5815. the current field alignment }
  5816. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  5817. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  5818. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  5819. { the padding is not inherited for Objective-C classes (maybe not
  5820. for cppclass either?) }
  5821. if objecttype=odt_objcclass then
  5822. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  5823. if (oo_has_vmt in objectoptions) and
  5824. (oo_has_vmt in c.objectoptions) then
  5825. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  5826. { if parent has a vmt field then the offset is the same for the child PM }
  5827. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  5828. begin
  5829. vmt_field:=c.vmt_field;
  5830. include(objectoptions,oo_has_vmt);
  5831. end;
  5832. end;
  5833. end;
  5834. procedure tobjectdef.insertvmt;
  5835. begin
  5836. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5837. exit;
  5838. if (oo_has_vmt in objectoptions) then
  5839. internalerror(12345)
  5840. else
  5841. begin
  5842. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  5843. tObjectSymtable(symtable).fieldalignment);
  5844. if (tf_requires_proper_alignment in target_info.flags) then
  5845. begin
  5846. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  5847. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  5848. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  5849. end;
  5850. vmt_field:=cfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  5851. hidesym(vmt_field);
  5852. tObjectSymtable(symtable).insert(vmt_field);
  5853. tObjectSymtable(symtable).addfield(tfieldvarsym(vmt_field),vis_hidden);
  5854. include(objectoptions,oo_has_vmt);
  5855. end;
  5856. end;
  5857. function tobjectdef.vmt_offset: asizeint;
  5858. begin
  5859. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5860. result:=0
  5861. else if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  5862. result:=tfieldvarsym(vmt_field).fieldoffset
  5863. else
  5864. result:=tfieldvarsym(vmt_field).fieldoffset div 8;
  5865. end;
  5866. procedure tobjectdef.check_forwards;
  5867. begin
  5868. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  5869. inherited;
  5870. if (oo_is_forward in objectoptions) then
  5871. begin
  5872. { ok, in future, the forward can be resolved }
  5873. Message1(sym_e_class_forward_not_resolved,objrealname^);
  5874. exclude(objectoptions,oo_is_forward);
  5875. end;
  5876. end;
  5877. function tobjectdef.find_destructor: tprocdef;
  5878. var
  5879. objdef: tobjectdef;
  5880. begin
  5881. objdef:=self;
  5882. while assigned(objdef) do
  5883. begin
  5884. result:=objdef.find_procdef_bytype(potype_destructor);
  5885. if assigned(result) then
  5886. exit;
  5887. objdef:=objdef.childof;
  5888. end;
  5889. result:=nil;
  5890. end;
  5891. function tobjectdef.implements_any_interfaces: boolean;
  5892. begin
  5893. result := (ImplementedInterfaces.Count > 0) or
  5894. (assigned(childof) and childof.implements_any_interfaces);
  5895. end;
  5896. function tobjectdef.size : asizeint;
  5897. begin
  5898. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5899. result:=voidpointertype.size
  5900. else
  5901. result:=tObjectSymtable(symtable).datasize;
  5902. end;
  5903. function tobjectdef.alignment:shortint;
  5904. begin
  5905. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5906. alignment:=voidpointertype.alignment
  5907. else
  5908. alignment:=tObjectSymtable(symtable).recordalignment;
  5909. end;
  5910. function tobjectdef.vmtmethodoffset(index:longint):longint;
  5911. begin
  5912. { for offset of methods for classes, see rtl/inc/objpash.inc }
  5913. case objecttype of
  5914. odt_class:
  5915. { the +2*sizeof(pint) is size and -size }
  5916. vmtmethodoffset:=index*voidcodepointertype.size+10*voidpointertype.size+2*sizeof(pint);
  5917. odt_helper,
  5918. odt_objcclass,
  5919. odt_objcprotocol:
  5920. vmtmethodoffset:=0;
  5921. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  5922. vmtmethodoffset:=index*voidcodepointertype.size;
  5923. odt_javaclass,
  5924. odt_interfacejava:
  5925. { invalid }
  5926. vmtmethodoffset:=-1;
  5927. else
  5928. { the +2*sizeof(pint) is size and -size }
  5929. {$ifdef WITHDMT}
  5930. vmtmethodoffset:=index*voidcodepointertype.size+2*voidpointertype.size+2*sizeof(pint);
  5931. {$else WITHDMT}
  5932. vmtmethodoffset:=index*voidcodepointertype.size+1*voidpointertype.size+2*sizeof(pint);
  5933. {$endif WITHDMT}
  5934. end;
  5935. end;
  5936. function tobjectdef.vmt_mangledname : TSymStr;
  5937. begin
  5938. if not(oo_has_vmt in objectoptions) then
  5939. Message1(parser_n_object_has_no_vmt,objrealname^);
  5940. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  5941. end;
  5942. function tobjectdef.vmt_def: trecorddef;
  5943. var
  5944. vmttypesym: tsym;
  5945. begin
  5946. vmttypesym:=tsym(get_top_level_symtable.Find('vmtdef$'+mangledparaname));
  5947. if not assigned(vmttypesym) or
  5948. (vmttypesym.typ<>symconst.typesym) or
  5949. (ttypesym(vmttypesym).typedef.typ<>recorddef) then
  5950. internalerror(2015052501);
  5951. result:=trecorddef(ttypesym(vmttypesym).typedef);
  5952. end;
  5953. function tobjectdef.needs_inittable : boolean;
  5954. var
  5955. hp : tobjectdef;
  5956. begin
  5957. case objecttype of
  5958. odt_helper,
  5959. odt_class :
  5960. needs_inittable:=false;
  5961. odt_dispinterface,
  5962. odt_interfacecom:
  5963. needs_inittable:=true;
  5964. odt_interfacecorba:
  5965. begin
  5966. hp:=childof;
  5967. while assigned(hp) do
  5968. begin
  5969. if hp=interface_iunknown then
  5970. begin
  5971. needs_inittable:=true;
  5972. exit;
  5973. end;
  5974. hp:=hp.childof;
  5975. end;
  5976. needs_inittable:=false;
  5977. end;
  5978. odt_object:
  5979. needs_inittable:=
  5980. tObjectSymtable(symtable).needs_init_final or
  5981. (assigned(childof) and
  5982. childof.needs_inittable);
  5983. odt_cppclass,
  5984. odt_objcclass,
  5985. odt_objcprotocol,
  5986. odt_javaclass,
  5987. odt_interfacejava:
  5988. needs_inittable:=false;
  5989. else
  5990. internalerror(200108267);
  5991. end;
  5992. end;
  5993. function tobjectdef.needs_separate_initrtti : boolean;
  5994. begin
  5995. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5996. end;
  5997. function tobjectdef.rtti_mangledname(rt: trttitype): TSymStr;
  5998. begin
  5999. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  6000. result:=inherited rtti_mangledname(rt)
  6001. else
  6002. begin
  6003. { necessary in case of a dynamic array of nsobject, or
  6004. if an nsobject field appears in a record that needs
  6005. init/finalisation }
  6006. if rt=initrtti then
  6007. begin
  6008. result:=voidpointertype.rtti_mangledname(rt);
  6009. exit;
  6010. end;
  6011. if not(target_info.system in systems_objc_nfabi) then
  6012. begin
  6013. result:=target_asm.labelprefix;
  6014. case objecttype of
  6015. odt_objcclass:
  6016. begin
  6017. case rt of
  6018. objcclassrtti:
  6019. if not(oo_is_classhelper in objectoptions) then
  6020. result:=result+'_OBJC_CLASS_'
  6021. else
  6022. result:=result+'_OBJC_CATEGORY_';
  6023. objcmetartti:
  6024. if not(oo_is_classhelper in objectoptions) then
  6025. result:=result+'_OBJC_METACLASS_'
  6026. else
  6027. internalerror(2009111511);
  6028. else
  6029. internalerror(2009092302);
  6030. end;
  6031. end;
  6032. odt_objcprotocol:
  6033. result:=result+'_OBJC_PROTOCOL_';
  6034. end;
  6035. end
  6036. else
  6037. begin
  6038. case objecttype of
  6039. odt_objcclass:
  6040. begin
  6041. if (oo_is_classhelper in objectoptions) and
  6042. (rt<>objcclassrtti) then
  6043. internalerror(2009111512);
  6044. case rt of
  6045. objcclassrtti:
  6046. if not(oo_is_classhelper in objectoptions) then
  6047. result:='_OBJC_CLASS_$_'
  6048. else
  6049. result:='_OBJC_$_CATEGORY_';
  6050. objcmetartti:
  6051. result:='_OBJC_METACLASS_$_';
  6052. objcclassrortti:
  6053. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  6054. objcmetarortti:
  6055. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  6056. else
  6057. internalerror(2009092303);
  6058. end;
  6059. end;
  6060. odt_objcprotocol:
  6061. begin
  6062. result:=lower(target_asm.labelprefix);
  6063. case rt of
  6064. objcclassrtti:
  6065. result:=result+'_OBJC_PROTOCOL_$_';
  6066. objcmetartti:
  6067. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  6068. else
  6069. internalerror(2009092501);
  6070. end;
  6071. end;
  6072. else
  6073. internalerror(2013113005);
  6074. end;
  6075. end;
  6076. result:=result+objextname^;
  6077. end;
  6078. end;
  6079. function tobjectdef.members_need_inittable : boolean;
  6080. begin
  6081. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  6082. end;
  6083. function tobjectdef.is_publishable : boolean;
  6084. begin
  6085. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  6086. end;
  6087. function tobjectdef.get_next_dispid: longint;
  6088. begin
  6089. inc(fcurrent_dispid);
  6090. result:=fcurrent_dispid;
  6091. end;
  6092. function tobjectdef.search_enumerator_get: tprocdef;
  6093. begin
  6094. result:=inherited;
  6095. if not assigned(result) and assigned(childof) then
  6096. result:=childof.search_enumerator_get;
  6097. end;
  6098. function tobjectdef.search_enumerator_move: tprocdef;
  6099. begin
  6100. result:=inherited;
  6101. if not assigned(result) and assigned(childof) then
  6102. result:=childof.search_enumerator_move;
  6103. end;
  6104. function tobjectdef.search_enumerator_current: tsym;
  6105. begin
  6106. result:=inherited;
  6107. if not assigned(result) and assigned(childof) then
  6108. result:=childof.search_enumerator_current;
  6109. end;
  6110. procedure tobjectdef.register_created_classref_type;
  6111. begin
  6112. if not classref_created_in_current_module then
  6113. begin
  6114. classref_created_in_current_module:=true;
  6115. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  6116. end;
  6117. end;
  6118. procedure tobjectdef.register_created_object_type;
  6119. begin
  6120. if not created_in_current_module then
  6121. begin
  6122. created_in_current_module:=true;
  6123. current_module.wpoinfo.addcreatedobjtype(self);
  6124. end;
  6125. end;
  6126. procedure tobjectdef.register_maybe_created_object_type;
  6127. begin
  6128. { if we know it has been created for sure, no need
  6129. to also record that it maybe can be created in
  6130. this module
  6131. }
  6132. if not (created_in_current_module) and
  6133. not (maybe_created_in_current_module) then
  6134. begin
  6135. maybe_created_in_current_module:=true;
  6136. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  6137. end;
  6138. end;
  6139. procedure tobjectdef.register_vmt_call(index: longint);
  6140. begin
  6141. if (is_object(self) or is_class(self)) then
  6142. current_module.wpoinfo.addcalledvmtentry(self,index);
  6143. end;
  6144. procedure check_and_finish_msg(data: tobject; arg: pointer);
  6145. var
  6146. def: tdef absolute data;
  6147. pd: tprocdef absolute data;
  6148. i,
  6149. paracount: longint;
  6150. begin
  6151. if (def.typ=procdef) then
  6152. begin
  6153. { add all messages also under a dummy name to the symtable in
  6154. which the objcclass/protocol/category is declared, so they can
  6155. be called via id.<name>
  6156. }
  6157. create_class_helper_for_procdef(pd,nil);
  6158. { we have to wait until now to set the mangled name because it
  6159. depends on the (possibly external) class name, which is defined
  6160. at the very end. }
  6161. if not(po_msgstr in pd.procoptions) then
  6162. begin
  6163. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  6164. { recover to avoid internalerror later on }
  6165. include(pd.procoptions,po_msgstr);
  6166. pd.messageinf.str:=stringdup('MissingDeclaration');
  6167. end;
  6168. { Mangled name is already set in case this is a copy of
  6169. another type. }
  6170. if not(po_has_mangledname in pd.procoptions) then
  6171. begin
  6172. { check whether the number of formal parameters is correct,
  6173. and whether they have valid Objective-C types }
  6174. paracount:=0;
  6175. for i:=1 to length(pd.messageinf.str^) do
  6176. if pd.messageinf.str^[i]=':' then
  6177. inc(paracount);
  6178. for i:=0 to pd.paras.count-1 do
  6179. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  6180. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  6181. dec(paracount);
  6182. if (paracount<>0) then
  6183. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  6184. pd.setmangledname(pd.objcmangledname);
  6185. end
  6186. else
  6187. { all checks already done }
  6188. exit;
  6189. if not(oo_is_external in pd.struct.objectoptions) then
  6190. begin
  6191. if (po_varargs in pd.procoptions) then
  6192. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  6193. else
  6194. begin
  6195. { check for "array of const" parameters }
  6196. for i:=0 to pd.parast.symlist.count-1 do
  6197. begin
  6198. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  6199. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  6200. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  6201. end;
  6202. end;
  6203. end;
  6204. end;
  6205. end;
  6206. procedure mark_private_fields_used(data: tobject; arg: pointer);
  6207. var
  6208. sym: tsym absolute data;
  6209. begin
  6210. if (sym.typ=fieldvarsym) and
  6211. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  6212. sym.IncRefCount;
  6213. end;
  6214. procedure tobjectdef.finish_objc_data;
  6215. begin
  6216. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  6217. if (oo_is_external in objectoptions) then
  6218. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  6219. end;
  6220. procedure verify_objc_vardef(data: tobject; arg: pointer);
  6221. var
  6222. sym: tabstractvarsym absolute data;
  6223. res: pboolean absolute arg;
  6224. founderrordef: tdef;
  6225. begin
  6226. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  6227. exit;
  6228. if (sym.typ=paravarsym) and
  6229. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  6230. is_array_of_const(tparavarsym(sym).vardef)) then
  6231. exit;
  6232. if not objcchecktype(sym.vardef,founderrordef) then
  6233. begin
  6234. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6235. res^:=false;
  6236. end;
  6237. end;
  6238. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  6239. var
  6240. def: tdef absolute data;
  6241. res: pboolean absolute arg;
  6242. founderrordef: tdef;
  6243. begin
  6244. if (def.typ<>procdef) then
  6245. exit;
  6246. { check parameter types for validity }
  6247. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  6248. { check the result type for validity }
  6249. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  6250. begin
  6251. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6252. res^:=false;
  6253. end;
  6254. end;
  6255. function tobjectdef.check_objc_types: boolean;
  6256. begin
  6257. { done in separate step from finish_objc_data, because when
  6258. finish_objc_data is called, not all forwarddefs have been resolved
  6259. yet and we need to know all types here }
  6260. result:=true;
  6261. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  6262. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  6263. end;
  6264. procedure do_cpp_import_info(data: tobject; arg: pointer);
  6265. var
  6266. def: tdef absolute data;
  6267. pd: tprocdef absolute data;
  6268. begin
  6269. if (def.typ=procdef) then
  6270. begin
  6271. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  6272. if (oo_is_external in pd.struct.objectoptions) then
  6273. begin
  6274. { copied from psub.read_proc }
  6275. if assigned(tobjectdef(pd.struct).import_lib) then
  6276. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  6277. else
  6278. begin
  6279. { add import name to external list for DLL scanning }
  6280. if tf_has_dllscanner in target_info.flags then
  6281. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  6282. end;
  6283. end;
  6284. end;
  6285. end;
  6286. procedure tobjectdef.finish_cpp_data;
  6287. begin
  6288. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  6289. end;
  6290. {****************************************************************************
  6291. TImplementedInterface
  6292. ****************************************************************************}
  6293. function TImplementedInterface.GetIOffset: longint;
  6294. begin
  6295. if (fIOffset=-1) and
  6296. (IType in [etFieldValue,etFieldValueClass]) then
  6297. result:=tfieldvarsym(ImplementsField).fieldoffset
  6298. else
  6299. result:=fIOffset;
  6300. end;
  6301. constructor TImplementedInterface.create(aintf: tobjectdef);
  6302. begin
  6303. inherited create;
  6304. intfdef:=aintf;
  6305. IOffset:=-1;
  6306. IType:=etStandard;
  6307. NameMappings:=nil;
  6308. procdefs:=nil;
  6309. end;
  6310. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  6311. begin
  6312. inherited create;
  6313. intfdef:=nil;
  6314. intfdefderef:=intfd;
  6315. ImplementsGetterDeref:=getterd;
  6316. IOffset:=-1;
  6317. IType:=etStandard;
  6318. NameMappings:=nil;
  6319. procdefs:=nil;
  6320. end;
  6321. destructor TImplementedInterface.destroy;
  6322. var
  6323. i : longint;
  6324. mappedname : pshortstring;
  6325. begin
  6326. if assigned(NameMappings) then
  6327. begin
  6328. for i:=0 to NameMappings.Count-1 do
  6329. begin
  6330. mappedname:=pshortstring(NameMappings[i]);
  6331. stringdispose(mappedname);
  6332. end;
  6333. NameMappings.free;
  6334. NameMappings:=nil;
  6335. end;
  6336. if assigned(procdefs) then
  6337. begin
  6338. procdefs.free;
  6339. procdefs:=nil;
  6340. end;
  6341. inherited destroy;
  6342. end;
  6343. procedure TImplementedInterface.buildderef;
  6344. begin
  6345. intfdefderef.build(intfdef);
  6346. ImplementsGetterDeref.build(ImplementsGetter);
  6347. end;
  6348. procedure TImplementedInterface.deref;
  6349. begin
  6350. intfdef:=tobjectdef(intfdefderef.resolve);
  6351. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  6352. end;
  6353. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  6354. begin
  6355. if not assigned(NameMappings) then
  6356. NameMappings:=TFPHashList.Create;
  6357. NameMappings.Add(origname,stringdup(newname));
  6358. end;
  6359. function TImplementedInterface.GetMapping(const origname: string):string;
  6360. var
  6361. mappedname : pshortstring;
  6362. begin
  6363. result:='';
  6364. if not assigned(NameMappings) then
  6365. exit;
  6366. mappedname:=PShortstring(NameMappings.Find(origname));
  6367. if assigned(mappedname) then
  6368. result:=mappedname^;
  6369. end;
  6370. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  6371. begin
  6372. if not assigned(procdefs) then
  6373. procdefs:=TFPObjectList.Create(false);
  6374. { duplicate entries must be stored, because multiple }
  6375. { interfaces can declare methods with the same name }
  6376. { and all of these get their own VMT entry }
  6377. procdefs.Add(pd);
  6378. end;
  6379. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  6380. var
  6381. i : longint;
  6382. begin
  6383. result:=false;
  6384. { interfaces being implemented through delegation are not mergable (FK) }
  6385. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  6386. exit;
  6387. weight:=0;
  6388. { empty interface is mergeable }
  6389. if ProcDefs.Count=0 then
  6390. begin
  6391. result:=true;
  6392. exit;
  6393. end;
  6394. { The interface to merge must at least the number of
  6395. procedures of this interface }
  6396. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  6397. exit;
  6398. for i:=0 to ProcDefs.Count-1 do
  6399. begin
  6400. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  6401. exit;
  6402. end;
  6403. weight:=ProcDefs.Count;
  6404. result:=true;
  6405. end;
  6406. function TImplementedInterface.getcopy:TImplementedInterface;
  6407. begin
  6408. Result:=TImplementedInterface.Create(nil);
  6409. { 1) the procdefs list will be freed once for each copy
  6410. 2) since the procdefs list owns its elements, those will also be freed for each copy
  6411. 3) idem for the name mappings
  6412. }
  6413. { warning: this is completely wrong on so many levels...
  6414. Move(pointer(self)^,pointer(result)^,InstanceSize);
  6415. We need to make clean copies of the different fields
  6416. this is not implemented yet, and thus we generate an internal
  6417. error instead PM 2011-06-14 }
  6418. internalerror(2011061401);
  6419. end;
  6420. {****************************************************************************
  6421. TFORWARDDEF
  6422. ****************************************************************************}
  6423. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  6424. begin
  6425. inherited create(forwarddef);
  6426. tosymname:=stringdup(s);
  6427. forwardpos:=pos;
  6428. end;
  6429. function tforwarddef.GetTypeName:string;
  6430. begin
  6431. GetTypeName:='unresolved forward to '+tosymname^;
  6432. end;
  6433. destructor tforwarddef.destroy;
  6434. begin
  6435. stringdispose(tosymname);
  6436. inherited destroy;
  6437. end;
  6438. function tforwarddef.getcopy:tstoreddef;
  6439. begin
  6440. result:=cforwarddef.create(tosymname^, forwardpos);
  6441. end;
  6442. {****************************************************************************
  6443. TUNDEFINEDDEF
  6444. ****************************************************************************}
  6445. constructor tundefineddef.create;
  6446. begin
  6447. inherited create(undefineddef);
  6448. end;
  6449. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  6450. begin
  6451. inherited ppuload(undefineddef,ppufile);
  6452. ppuload_platform(ppufile);
  6453. end;
  6454. function tundefineddef.GetTypeName:string;
  6455. begin
  6456. GetTypeName:='<undefined type>';
  6457. end;
  6458. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  6459. begin
  6460. inherited ppuwrite(ppufile);
  6461. writeentry(ppufile,ibundefineddef);
  6462. end;
  6463. {****************************************************************************
  6464. TERRORDEF
  6465. ****************************************************************************}
  6466. constructor terrordef.create;
  6467. begin
  6468. inherited create(errordef);
  6469. { prevent consecutive faults }
  6470. savesize:=1;
  6471. end;
  6472. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  6473. begin
  6474. { Can't write errordefs to ppu }
  6475. internalerror(200411063);
  6476. end;
  6477. function terrordef.GetTypeName:string;
  6478. begin
  6479. GetTypeName:='<erroneous type>';
  6480. end;
  6481. function terrordef.getmangledparaname:TSymStr;
  6482. begin
  6483. getmangledparaname:='error';
  6484. end;
  6485. {****************************************************************************
  6486. Definition Helpers
  6487. ****************************************************************************}
  6488. function is_interfacecom(def: tdef): boolean;
  6489. begin
  6490. is_interfacecom:=
  6491. assigned(def) and
  6492. (def.typ=objectdef) and
  6493. (tobjectdef(def).objecttype=odt_interfacecom);
  6494. end;
  6495. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  6496. begin
  6497. is_interfacecom_or_dispinterface:=
  6498. assigned(def) and
  6499. (def.typ=objectdef) and
  6500. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  6501. end;
  6502. function is_any_interface_kind(def: tdef): boolean;
  6503. begin
  6504. result:=
  6505. assigned(def) and
  6506. (def.typ=objectdef) and
  6507. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  6508. is_objccategory(def));
  6509. end;
  6510. function is_interfacecorba(def: tdef): boolean;
  6511. begin
  6512. is_interfacecorba:=
  6513. assigned(def) and
  6514. (def.typ=objectdef) and
  6515. (tobjectdef(def).objecttype=odt_interfacecorba);
  6516. end;
  6517. function is_interface(def: tdef): boolean;
  6518. begin
  6519. is_interface:=
  6520. assigned(def) and
  6521. (def.typ=objectdef) and
  6522. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  6523. end;
  6524. function is_dispinterface(def: tdef): boolean;
  6525. begin
  6526. result:=
  6527. assigned(def) and
  6528. (def.typ=objectdef) and
  6529. (tobjectdef(def).objecttype=odt_dispinterface);
  6530. end;
  6531. function is_class(def: tdef): boolean;
  6532. begin
  6533. is_class:=
  6534. assigned(def) and
  6535. (def.typ=objectdef) and
  6536. (tobjectdef(def).objecttype=odt_class);
  6537. end;
  6538. function is_object(def: tdef): boolean;
  6539. begin
  6540. is_object:=
  6541. assigned(def) and
  6542. (def.typ=objectdef) and
  6543. (tobjectdef(def).objecttype=odt_object);
  6544. end;
  6545. function is_cppclass(def: tdef): boolean;
  6546. begin
  6547. is_cppclass:=
  6548. assigned(def) and
  6549. (def.typ=objectdef) and
  6550. (tobjectdef(def).objecttype=odt_cppclass);
  6551. end;
  6552. function is_objcclass(def: tdef): boolean;
  6553. begin
  6554. is_objcclass:=
  6555. assigned(def) and
  6556. (def.typ=objectdef) and
  6557. (tobjectdef(def).objecttype=odt_objcclass);
  6558. end;
  6559. function is_objectpascal_helper(def: tdef): boolean;
  6560. begin
  6561. result:=
  6562. assigned(def) and
  6563. (def.typ=objectdef) and
  6564. (tobjectdef(def).objecttype=odt_helper);
  6565. end;
  6566. function is_objcclassref(def: tdef): boolean;
  6567. begin
  6568. is_objcclassref:=
  6569. assigned(def) and
  6570. (def.typ=classrefdef) and
  6571. is_objcclass(tclassrefdef(def).pointeddef);
  6572. end;
  6573. function is_objcprotocol(def: tdef): boolean;
  6574. begin
  6575. result:=
  6576. assigned(def) and
  6577. (def.typ=objectdef) and
  6578. (tobjectdef(def).objecttype=odt_objcprotocol);
  6579. end;
  6580. function is_objccategory(def: tdef): boolean;
  6581. begin
  6582. result:=
  6583. assigned(def) and
  6584. (def.typ=objectdef) and
  6585. { if used as a forward type }
  6586. ((tobjectdef(def).objecttype=odt_objccategory) or
  6587. { if used as after it has been resolved }
  6588. ((tobjectdef(def).objecttype=odt_objcclass) and
  6589. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6590. end;
  6591. function is_objc_class_or_protocol(def: tdef): boolean;
  6592. begin
  6593. result:=
  6594. assigned(def) and
  6595. (def.typ=objectdef) and
  6596. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  6597. end;
  6598. function is_objc_protocol_or_category(def: tdef): boolean;
  6599. begin
  6600. result:=
  6601. assigned(def) and
  6602. (def.typ=objectdef) and
  6603. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  6604. ((tobjectdef(def).objecttype = odt_objcclass) and
  6605. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6606. end;
  6607. function is_classhelper(def: tdef): boolean;
  6608. begin
  6609. result:=
  6610. is_objectpascal_helper(def) or
  6611. is_objccategory(def);
  6612. end;
  6613. function is_class_or_interface(def: tdef): boolean;
  6614. begin
  6615. result:=
  6616. assigned(def) and
  6617. (def.typ=objectdef) and
  6618. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  6619. end;
  6620. function is_class_or_interface_or_objc(def: tdef): boolean;
  6621. begin
  6622. result:=
  6623. assigned(def) and
  6624. (def.typ=objectdef) and
  6625. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  6626. end;
  6627. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  6628. begin
  6629. result:=
  6630. assigned(def) and
  6631. (def.typ=objectdef) and
  6632. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6633. end;
  6634. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  6635. begin
  6636. result:=
  6637. assigned(def) and
  6638. (def.typ=objectdef) and
  6639. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6640. end;
  6641. function is_class_or_interface_or_object(def: tdef): boolean;
  6642. begin
  6643. result:=
  6644. assigned(def) and
  6645. (def.typ=objectdef) and
  6646. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  6647. end;
  6648. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  6649. begin
  6650. result:=
  6651. assigned(def) and
  6652. (def.typ=objectdef) and
  6653. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  6654. end;
  6655. function is_implicit_pointer_object_type(def: tdef): boolean;
  6656. begin
  6657. result:=
  6658. assigned(def) and
  6659. (((def.typ=objectdef) and
  6660. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  6661. ((target_info.system in systems_jvm) and
  6662. (def.typ=recorddef)));
  6663. end;
  6664. function is_implicit_array_pointer(def: tdef): boolean;
  6665. begin
  6666. result:=is_dynamic_array(def) or is_dynamicstring(def);
  6667. end;
  6668. function is_class_or_object(def: tdef): boolean;
  6669. begin
  6670. result:=
  6671. assigned(def) and
  6672. (def.typ=objectdef) and
  6673. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  6674. end;
  6675. function is_record(def: tdef): boolean;
  6676. begin
  6677. result:=
  6678. assigned(def) and
  6679. (def.typ=recorddef);
  6680. end;
  6681. function is_javaclass(def: tdef): boolean;
  6682. begin
  6683. result:=
  6684. assigned(def) and
  6685. (def.typ=objectdef) and
  6686. (tobjectdef(def).objecttype=odt_javaclass);
  6687. end;
  6688. function is_javaclassref(def: tdef): boolean;
  6689. begin
  6690. is_javaclassref:=
  6691. assigned(def) and
  6692. (def.typ=classrefdef) and
  6693. is_javaclass(tclassrefdef(def).pointeddef);
  6694. end;
  6695. function is_javainterface(def: tdef): boolean;
  6696. begin
  6697. result:=
  6698. assigned(def) and
  6699. (def.typ=objectdef) and
  6700. (tobjectdef(def).objecttype=odt_interfacejava);
  6701. end;
  6702. function is_java_class_or_interface(def: tdef): boolean;
  6703. begin
  6704. result:=
  6705. assigned(def) and
  6706. (def.typ=objectdef) and
  6707. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  6708. end;
  6709. procedure loadobjctypes;
  6710. begin
  6711. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  6712. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  6713. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  6714. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  6715. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  6716. end;
  6717. procedure maybeloadcocoatypes;
  6718. var
  6719. tsym: ttypesym;
  6720. cocoaunit: string[15];
  6721. begin
  6722. if assigned(objc_fastenumeration) then
  6723. exit;
  6724. if not(target_info.system in [system_arm_darwin,system_i386_iphonesim,system_aarch64_darwin,system_x86_64_iphonesim]) then
  6725. cocoaunit:='COCOAALL'
  6726. else
  6727. cocoaunit:='IPHONEALL';
  6728. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  6729. if assigned(tsym) then
  6730. objc_fastenumeration:=tobjectdef(tsym.typedef)
  6731. else
  6732. objc_fastenumeration:=nil;
  6733. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  6734. if assigned(tsym) then
  6735. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  6736. else
  6737. objc_fastenumerationstate:=nil;
  6738. end;
  6739. function use_vectorfpu(def : tdef) : boolean;
  6740. begin
  6741. {$ifdef x86}
  6742. {$define use_vectorfpuimplemented}
  6743. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  6744. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  6745. {$endif x86}
  6746. {$ifdef arm}
  6747. {$define use_vectorfpuimplemented}
  6748. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  6749. {$endif arm}
  6750. {$ifdef aarch64}
  6751. {$define use_vectorfpuimplemented}
  6752. use_vectorfpu:=true;
  6753. {$endif aarch64}
  6754. {$ifndef use_vectorfpuimplemented}
  6755. use_vectorfpu:=false;
  6756. {$endif}
  6757. end;
  6758. end.