symdef.pas 249 KB

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