symdef.pas 250 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612
  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_iphonesim,
  2550. system_x86_64_linux,system_x86_64_freebsd,
  2551. system_x86_64_openbsd,system_x86_64_netbsd,
  2552. system_x86_64_solaris,system_x86_64_embedded,
  2553. system_x86_64_dragonfly] then
  2554. savesize:=16
  2555. else
  2556. savesize:=12;
  2557. s64real,
  2558. s64currency,
  2559. s64comp : savesize:=8;
  2560. else
  2561. savesize:=0;
  2562. end;
  2563. end;
  2564. function tfloatdef.getvardef : longint;
  2565. const
  2566. floattype2vardef : array[tfloattype] of longint = (
  2567. varSingle,varDouble,varUndefined,varUndefined,
  2568. varUndefined,varCurrency,varUndefined);
  2569. begin
  2570. if (upper(typename)='TDATETIME') and
  2571. assigned(owner) and
  2572. assigned(owner.name) and
  2573. (owner.name^='SYSTEM') then
  2574. result:=varDate
  2575. else
  2576. result:=floattype2vardef[floattype];
  2577. end;
  2578. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  2579. begin
  2580. inherited ppuwrite(ppufile);
  2581. ppufile.putbyte(byte(floattype));
  2582. writeentry(ppufile,ibfloatdef);
  2583. end;
  2584. function tfloatdef.is_publishable : boolean;
  2585. begin
  2586. is_publishable:=true;
  2587. end;
  2588. function tfloatdef.GetTypeName : string;
  2589. const
  2590. names : array[tfloattype] of string[20] = (
  2591. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  2592. begin
  2593. GetTypeName:=names[floattype];
  2594. end;
  2595. {****************************************************************************
  2596. TFILEDEF
  2597. ****************************************************************************}
  2598. constructor tfiledef.createtext;
  2599. begin
  2600. inherited create(filedef);
  2601. filetyp:=ft_text;
  2602. typedfiledef:=nil;
  2603. end;
  2604. constructor tfiledef.createuntyped;
  2605. begin
  2606. inherited create(filedef);
  2607. filetyp:=ft_untyped;
  2608. typedfiledef:=nil;
  2609. end;
  2610. constructor tfiledef.createtyped(def:tdef);
  2611. begin
  2612. inherited create(filedef);
  2613. filetyp:=ft_typed;
  2614. typedfiledef:=def;
  2615. end;
  2616. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  2617. begin
  2618. inherited ppuload(filedef,ppufile);
  2619. filetyp:=tfiletyp(ppufile.getbyte);
  2620. if filetyp=ft_typed then
  2621. ppufile.getderef(typedfiledefderef)
  2622. else
  2623. typedfiledef:=nil;
  2624. ppuload_platform(ppufile);
  2625. end;
  2626. function tfiledef.getcopy : tstoreddef;
  2627. begin
  2628. case filetyp of
  2629. ft_typed:
  2630. result:=cfiledef.createtyped(typedfiledef);
  2631. ft_untyped:
  2632. result:=cfiledef.createuntyped;
  2633. ft_text:
  2634. result:=cfiledef.createtext;
  2635. else
  2636. internalerror(2004121201);
  2637. end;
  2638. end;
  2639. procedure tfiledef.buildderef;
  2640. begin
  2641. inherited buildderef;
  2642. if filetyp=ft_typed then
  2643. typedfiledefderef.build(typedfiledef);
  2644. end;
  2645. procedure tfiledef.deref;
  2646. begin
  2647. inherited deref;
  2648. if filetyp=ft_typed then
  2649. typedfiledef:=tdef(typedfiledefderef.resolve);
  2650. end;
  2651. function tfiledef.size:asizeint;
  2652. begin
  2653. if savesize=0 then
  2654. setsize;
  2655. size:=savesize;
  2656. end;
  2657. procedure tfiledef.setsize;
  2658. begin
  2659. case filetyp of
  2660. ft_text:
  2661. savesize:=search_system_type('TEXTREC').typedef.size;
  2662. ft_typed:
  2663. begin
  2664. savesize:=search_system_type('FILEREC').typedef.size;
  2665. { allocate put/get buffer in iso mode }
  2666. if m_iso in current_settings.modeswitches then
  2667. inc(savesize,typedfiledef.size);
  2668. end;
  2669. ft_untyped:
  2670. savesize:=search_system_type('FILEREC').typedef.size;
  2671. else
  2672. internalerror(2013113001);
  2673. end;
  2674. end;
  2675. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  2676. begin
  2677. inherited ppuwrite(ppufile);
  2678. ppufile.putbyte(byte(filetyp));
  2679. if filetyp=ft_typed then
  2680. ppufile.putderef(typedfiledefderef);
  2681. writeentry(ppufile,ibfiledef);
  2682. end;
  2683. function tfiledef.GetTypeName : string;
  2684. begin
  2685. case filetyp of
  2686. ft_untyped:
  2687. GetTypeName:='File';
  2688. ft_typed:
  2689. GetTypeName:='File Of '+typedfiledef.typename;
  2690. ft_text:
  2691. GetTypeName:='Text'
  2692. else
  2693. internalerror(2013113002);
  2694. end;
  2695. end;
  2696. function tfiledef.getmangledparaname : TSymStr;
  2697. begin
  2698. case filetyp of
  2699. ft_untyped:
  2700. getmangledparaname:='FILE';
  2701. ft_typed:
  2702. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  2703. ft_text:
  2704. getmangledparaname:='TEXT'
  2705. else
  2706. internalerror(2013113003);
  2707. end;
  2708. end;
  2709. {****************************************************************************
  2710. TVARIANTDEF
  2711. ****************************************************************************}
  2712. constructor tvariantdef.create(v : tvarianttype);
  2713. begin
  2714. inherited create(variantdef);
  2715. varianttype:=v;
  2716. setsize;
  2717. end;
  2718. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2719. begin
  2720. inherited ppuload(variantdef,ppufile);
  2721. varianttype:=tvarianttype(ppufile.getbyte);
  2722. setsize;
  2723. ppuload_platform(ppufile);
  2724. end;
  2725. function tvariantdef.getcopy : tstoreddef;
  2726. begin
  2727. result:=cvariantdef.create(varianttype);
  2728. end;
  2729. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2730. begin
  2731. inherited ppuwrite(ppufile);
  2732. ppufile.putbyte(byte(varianttype));
  2733. writeentry(ppufile,ibvariantdef);
  2734. end;
  2735. function tvariantdef.getvardef : longint;
  2736. begin
  2737. Result:=varVariant;
  2738. end;
  2739. procedure tvariantdef.setsize;
  2740. begin
  2741. {$ifdef cpu64bitaddr}
  2742. savesize:=24;
  2743. {$else cpu64bitaddr}
  2744. savesize:=16;
  2745. {$endif cpu64bitaddr}
  2746. end;
  2747. function tvariantdef.GetTypeName : string;
  2748. begin
  2749. case varianttype of
  2750. vt_normalvariant:
  2751. GetTypeName:='Variant';
  2752. vt_olevariant:
  2753. GetTypeName:='OleVariant';
  2754. else
  2755. internalerror(2013113004);
  2756. end;
  2757. end;
  2758. function tvariantdef.needs_inittable : boolean;
  2759. begin
  2760. needs_inittable:=true;
  2761. end;
  2762. function tvariantdef.is_publishable : boolean;
  2763. begin
  2764. is_publishable:=true;
  2765. end;
  2766. {****************************************************************************
  2767. TABSTRACtpointerdef
  2768. ****************************************************************************}
  2769. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  2770. begin
  2771. inherited create(dt);
  2772. pointeddef:=def;
  2773. end;
  2774. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2775. begin
  2776. inherited ppuload(dt,ppufile);
  2777. ppufile.getderef(pointeddefderef);
  2778. end;
  2779. procedure tabstractpointerdef.buildderef;
  2780. begin
  2781. inherited buildderef;
  2782. pointeddefderef.build(pointeddef);
  2783. end;
  2784. procedure tabstractpointerdef.deref;
  2785. begin
  2786. inherited deref;
  2787. pointeddef:=tdef(pointeddefderef.resolve);
  2788. end;
  2789. function tabstractpointerdef.size: asizeint;
  2790. begin
  2791. Result:=voidpointertype.size;
  2792. end;
  2793. function tabstractpointerdef.alignment: shortint;
  2794. begin
  2795. alignment:=size_2_align(voidpointertype.size);
  2796. end;
  2797. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2798. begin
  2799. inherited ppuwrite(ppufile);
  2800. ppufile.putderef(pointeddefderef);
  2801. end;
  2802. {****************************************************************************
  2803. tpointerdef
  2804. ****************************************************************************}
  2805. constructor tpointerdef.create(def:tdef);
  2806. begin
  2807. inherited create(pointerdef,def);
  2808. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  2809. // Dump_Stack(Output,get_frame);
  2810. end;
  2811. function tpointerdef.size: asizeint;
  2812. begin
  2813. result:=sizeof(pint);
  2814. end;
  2815. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2816. begin
  2817. inherited ppuload(pointerdef,ppufile);
  2818. has_pointer_math:=(ppufile.getbyte<>0);
  2819. ppuload_platform(ppufile);
  2820. end;
  2821. function tpointerdef.getcopy : tstoreddef;
  2822. begin
  2823. { don't use direct pointeddef if it is a forwarddef because in other case
  2824. one of them will be destroyed on forward type resolve and the second will
  2825. point to garbage }
  2826. if pointeddef.typ=forwarddef then
  2827. result:=cpointerdef.create(tforwarddef(pointeddef).getcopy)
  2828. else
  2829. result:=cpointerdef.create(pointeddef);
  2830. tpointerdef(result).has_pointer_math:=has_pointer_math;
  2831. tpointerdef(result).savesize:=savesize;
  2832. end;
  2833. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2834. begin
  2835. inherited ppuwrite(ppufile);
  2836. ppufile.putbyte(byte(has_pointer_math));
  2837. writeentry(ppufile,ibpointerdef);
  2838. end;
  2839. function tpointerdef.GetTypeName : string;
  2840. begin
  2841. { parameter types and the resultdef of a procvardef can contain a
  2842. pointer to this procvardef itself, resulting in endless recursion ->
  2843. use the typesym's name instead if it exists (if it doesn't, such as
  2844. for anynonymous procedure types in macpas/iso mode, then there cannot
  2845. be any recursive references to it either) }
  2846. if (pointeddef.typ<>procvardef) or
  2847. not assigned(pointeddef.typesym) then
  2848. GetTypeName:='^'+pointeddef.typename
  2849. else
  2850. GetTypeName:='^'+pointeddef.typesym.realname;
  2851. end;
  2852. function tpointerdef.pointer_arithmetic_int_type:tdef;
  2853. begin
  2854. result:=ptrsinttype;
  2855. end;
  2856. function tpointerdef.pointer_subtraction_result_type:tdef;
  2857. begin
  2858. result:=ptrsinttype;
  2859. end;
  2860. {****************************************************************************
  2861. TCLASSREFDEF
  2862. ****************************************************************************}
  2863. constructor tclassrefdef.create(def:tdef);
  2864. begin
  2865. inherited create(classrefdef,def);
  2866. end;
  2867. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2868. begin
  2869. inherited ppuload(classrefdef,ppufile);
  2870. ppuload_platform(ppufile);
  2871. end;
  2872. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2873. begin
  2874. inherited ppuwrite(ppufile);
  2875. writeentry(ppufile,ibclassrefdef);
  2876. end;
  2877. function tclassrefdef.getcopy:tstoreddef;
  2878. begin
  2879. if pointeddef.typ=forwarddef then
  2880. result:=cclassrefdef.create(tforwarddef(pointeddef).getcopy)
  2881. else
  2882. result:=cclassrefdef.create(pointeddef);
  2883. end;
  2884. function tclassrefdef.GetTypeName : string;
  2885. begin
  2886. GetTypeName:='Class Of '+pointeddef.typename;
  2887. end;
  2888. function tclassrefdef.is_publishable : boolean;
  2889. begin
  2890. result:=true;
  2891. end;
  2892. function tclassrefdef.rtti_mangledname(rt: trttitype): TSymStr;
  2893. begin
  2894. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  2895. result:=inherited rtti_mangledname(rt)
  2896. else
  2897. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  2898. end;
  2899. procedure tclassrefdef.register_created_object_type;
  2900. begin
  2901. tobjectdef(pointeddef).register_created_classref_type;
  2902. end;
  2903. {***************************************************************************
  2904. TSETDEF
  2905. ***************************************************************************}
  2906. constructor tsetdef.create(def:tdef;low, high : asizeint);
  2907. var
  2908. setallocbits: aint;
  2909. packedsavesize: aint;
  2910. actual_setalloc: ShortInt;
  2911. begin
  2912. inherited create(setdef);
  2913. elementdef:=def;
  2914. setmax:=high;
  2915. actual_setalloc:=current_settings.setalloc;
  2916. {$if defined(cpu8bitalu) or defined(cpu16bitalu)}
  2917. if actual_setalloc=0 then
  2918. actual_setalloc:=1;
  2919. {$endif}
  2920. if (actual_setalloc=0) then
  2921. begin
  2922. setbase:=0;
  2923. if (high<32) then
  2924. savesize:=Sizeof(longint)
  2925. else if (high<256) then
  2926. savesize:=32
  2927. else
  2928. savesize:=(high+7) div 8
  2929. end
  2930. else
  2931. begin
  2932. setallocbits:=actual_setalloc*8;
  2933. setbase:=low and not(setallocbits-1);
  2934. packedsavesize:=actual_setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  2935. savesize:=packedsavesize;
  2936. {$if not defined(cpu8bitalu) and not defined(cpu16bitalu)}
  2937. if savesize=3 then
  2938. savesize:=4;
  2939. {$endif}
  2940. end;
  2941. end;
  2942. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2943. begin
  2944. inherited ppuload(setdef,ppufile);
  2945. ppufile.getderef(elementdefderef);
  2946. savesize:=ppufile.getaint;
  2947. setbase:=ppufile.getaint;
  2948. setmax:=ppufile.getaint;
  2949. ppuload_platform(ppufile);
  2950. end;
  2951. function tsetdef.getcopy : tstoreddef;
  2952. begin
  2953. result:=csetdef.create(elementdef,setbase,setmax);
  2954. { the copy might have been created with a different setalloc setting }
  2955. tsetdef(result).savesize:=savesize;
  2956. end;
  2957. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2958. begin
  2959. inherited ppuwrite(ppufile);
  2960. ppufile.putderef(elementdefderef);
  2961. ppufile.putaint(savesize);
  2962. ppufile.putaint(setbase);
  2963. ppufile.putaint(setmax);
  2964. writeentry(ppufile,ibsetdef);
  2965. end;
  2966. procedure tsetdef.buildderef;
  2967. begin
  2968. inherited buildderef;
  2969. elementdefderef.build(elementdef);
  2970. end;
  2971. procedure tsetdef.deref;
  2972. begin
  2973. inherited deref;
  2974. elementdef:=tdef(elementdefderef.resolve);
  2975. end;
  2976. function tsetdef.is_publishable : boolean;
  2977. begin
  2978. is_publishable:=savesize in [1,2,4];
  2979. end;
  2980. function tsetdef.GetTypeName : string;
  2981. begin
  2982. if assigned(elementdef) then
  2983. GetTypeName:='Set Of '+elementdef.typename
  2984. else
  2985. GetTypeName:='Empty Set';
  2986. end;
  2987. {***************************************************************************
  2988. TFORMALDEF
  2989. ***************************************************************************}
  2990. constructor tformaldef.create(Atyped:boolean);
  2991. begin
  2992. inherited create(formaldef);
  2993. typed:=Atyped;
  2994. savesize:=0;
  2995. end;
  2996. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2997. begin
  2998. inherited ppuload(formaldef,ppufile);
  2999. typed:=boolean(ppufile.getbyte);
  3000. savesize:=0;
  3001. ppuload_platform(ppufile);
  3002. end;
  3003. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  3004. begin
  3005. inherited ppuwrite(ppufile);
  3006. ppufile.putbyte(byte(typed));
  3007. writeentry(ppufile,ibformaldef);
  3008. end;
  3009. function tformaldef.GetTypeName : string;
  3010. begin
  3011. if typed then
  3012. GetTypeName:='<Typed formal type>'
  3013. else
  3014. GetTypeName:='<Formal type>';
  3015. end;
  3016. {***************************************************************************
  3017. TARRAYDEF
  3018. ***************************************************************************}
  3019. constructor tarraydef.create(l,h:asizeint;def:tdef);
  3020. begin
  3021. inherited create(arraydef);
  3022. lowrange:=l;
  3023. highrange:=h;
  3024. rangedef:=def;
  3025. _elementdef:=nil;
  3026. arrayoptions:=[];
  3027. symtable:=tarraysymtable.create(self);
  3028. end;
  3029. destructor tarraydef.destroy;
  3030. begin
  3031. symtable.free;
  3032. symtable:=nil;
  3033. inherited;
  3034. end;
  3035. constructor tarraydef.create_from_pointer(def:tpointerdef);
  3036. begin
  3037. { divide by the element size and do -1 so the array will have a valid size,
  3038. further, the element size might be 0 e.g. for empty records, so use max(...,1)
  3039. to avoid a division by zero }
  3040. self.create(0,(high(asizeint) div max(def.pointeddef.size,1))-1,ptrsinttype);
  3041. arrayoptions:=[ado_IsConvertedPointer];
  3042. setelementdef(def.pointeddef);
  3043. end;
  3044. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  3045. begin
  3046. inherited ppuload(arraydef,ppufile);
  3047. { the addresses are calculated later }
  3048. ppufile.getderef(_elementdefderef);
  3049. ppufile.getderef(rangedefderef);
  3050. lowrange:=ppufile.getasizeint;
  3051. highrange:=ppufile.getasizeint;
  3052. ppufile.getsmallset(arrayoptions);
  3053. ppuload_platform(ppufile);
  3054. symtable:=tarraysymtable.create(self);
  3055. tarraysymtable(symtable).ppuload(ppufile)
  3056. end;
  3057. function tarraydef.getcopy : tstoreddef;
  3058. begin
  3059. result:=carraydef.create(lowrange,highrange,rangedef);
  3060. tarraydef(result).arrayoptions:=arrayoptions;
  3061. tarraydef(result)._elementdef:=_elementdef;
  3062. end;
  3063. procedure tarraydef.buildderef;
  3064. begin
  3065. inherited buildderef;
  3066. tarraysymtable(symtable).buildderef;
  3067. _elementdefderef.build(_elementdef);
  3068. rangedefderef.build(rangedef);
  3069. end;
  3070. procedure tarraydef.deref;
  3071. begin
  3072. inherited deref;
  3073. tarraysymtable(symtable).deref;
  3074. _elementdef:=tdef(_elementdefderef.resolve);
  3075. rangedef:=tdef(rangedefderef.resolve);
  3076. end;
  3077. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  3078. begin
  3079. inherited ppuwrite(ppufile);
  3080. ppufile.putderef(_elementdefderef);
  3081. ppufile.putderef(rangedefderef);
  3082. ppufile.putasizeint(lowrange);
  3083. ppufile.putasizeint(highrange);
  3084. ppufile.putsmallset(arrayoptions);
  3085. writeentry(ppufile,ibarraydef);
  3086. tarraysymtable(symtable).ppuwrite(ppufile);
  3087. end;
  3088. function tarraydef.elesize : asizeint;
  3089. begin
  3090. if (ado_IsBitPacked in arrayoptions) then
  3091. internalerror(2006080101);
  3092. if assigned(_elementdef) then
  3093. result:=_elementdef.size
  3094. else
  3095. result:=0;
  3096. end;
  3097. function tarraydef.elepackedbitsize : asizeint;
  3098. begin
  3099. if not(ado_IsBitPacked in arrayoptions) then
  3100. internalerror(2006080102);
  3101. if assigned(_elementdef) then
  3102. result:=_elementdef.packedbitsize
  3103. else
  3104. result:=0;
  3105. end;
  3106. function tarraydef.elecount : asizeuint;
  3107. var
  3108. qhigh,qlow : qword;
  3109. begin
  3110. if ado_IsDynamicArray in arrayoptions then
  3111. begin
  3112. result:=0;
  3113. exit;
  3114. end;
  3115. if (highrange>0) and (lowrange<0) then
  3116. begin
  3117. qhigh:=highrange;
  3118. qlow:=qword(-lowrange);
  3119. { prevent overflow, return 0 to indicate overflow }
  3120. if qhigh+qlow>qword(high(asizeint)-1) then
  3121. result:=0
  3122. else
  3123. result:=qhigh+qlow+1;
  3124. end
  3125. else
  3126. result:=int64(highrange)-lowrange+1;
  3127. end;
  3128. function tarraydef.size : asizeint;
  3129. var
  3130. cachedelecount : asizeuint;
  3131. cachedelesize : asizeint;
  3132. begin
  3133. if ado_IsDynamicArray in arrayoptions then
  3134. begin
  3135. size:=voidpointertype.size;
  3136. exit;
  3137. end;
  3138. { Tarraydef.size may never be called for an open array! }
  3139. if highrange<lowrange then
  3140. internalerror(99080501);
  3141. if not (ado_IsBitPacked in arrayoptions) then
  3142. cachedelesize:=elesize
  3143. else
  3144. cachedelesize := elepackedbitsize;
  3145. cachedelecount:=elecount;
  3146. if (cachedelesize = 0) then
  3147. begin
  3148. size := 0;
  3149. exit;
  3150. end;
  3151. if (cachedelecount = 0) then
  3152. begin
  3153. size := -1;
  3154. exit;
  3155. end;
  3156. { prevent overflow, return -1 to indicate overflow }
  3157. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  3158. if (cachedelecount > asizeuint(high(asizeint))) or
  3159. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  3160. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  3161. accessing the array, see ncgmem (PFV) }
  3162. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  3163. begin
  3164. result:=-1;
  3165. exit;
  3166. end;
  3167. result:=cachedelesize*asizeint(cachedelecount);
  3168. if (ado_IsBitPacked in arrayoptions) then
  3169. { can't just add 7 and divide by 8, because that may overflow }
  3170. result:=result div 8 + ord((result mod 8)<>0);
  3171. end;
  3172. procedure tarraydef.setelementdef(def:tdef);
  3173. begin
  3174. _elementdef:=def;
  3175. if not(
  3176. (ado_IsDynamicArray in arrayoptions) or
  3177. (ado_IsConvertedPointer in arrayoptions) or
  3178. (highrange<lowrange)
  3179. ) and
  3180. (size=-1) then
  3181. Message(sym_e_segment_too_large);
  3182. end;
  3183. function tarraydef.alignment : shortint;
  3184. begin
  3185. { alignment of dyn. arrays doesn't depend on the element size }
  3186. if (ado_IsDynamicArray in arrayoptions) then
  3187. alignment:=size_2_align(voidpointertype.size)
  3188. { alignment is the target alignment for the used load size }
  3189. else if (ado_IsBitPacked in arrayoptions) and
  3190. (elementdef.typ in [enumdef,orddef]) then
  3191. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  3192. { alignment is the alignment of the elements }
  3193. else
  3194. alignment:=elementdef.alignment
  3195. end;
  3196. function tarraydef.needs_inittable : boolean;
  3197. begin
  3198. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  3199. end;
  3200. function tarraydef.needs_separate_initrtti : boolean;
  3201. begin
  3202. if ado_IsBitPacked in arrayoptions then
  3203. result:=false
  3204. else
  3205. result:=elementdef.needs_separate_initrtti;
  3206. end;
  3207. function tarraydef.GetTypeName : string;
  3208. begin
  3209. if (ado_IsConstString in arrayoptions) then
  3210. result:='Constant String'
  3211. else if (ado_isarrayofconst in arrayoptions) or
  3212. (ado_isConstructor in arrayoptions) then
  3213. begin
  3214. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  3215. GetTypeName:='Array Of Const'
  3216. else
  3217. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  3218. end
  3219. else if (ado_IsDynamicArray in arrayoptions) then
  3220. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  3221. else if ((highrange=-1) and (lowrange=0)) then
  3222. GetTypeName:='{Open} Array Of '+elementdef.typename
  3223. else
  3224. begin
  3225. result := '';
  3226. if (ado_IsBitPacked in arrayoptions) then
  3227. result:='BitPacked ';
  3228. if rangedef.typ=enumdef then
  3229. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  3230. else
  3231. result:=result+'Array['+tostr(lowrange)+'..'+
  3232. tostr(highrange)+'] Of '+elementdef.typename
  3233. end;
  3234. end;
  3235. function tarraydef.getmangledparaname : TSymStr;
  3236. begin
  3237. if ado_isarrayofconst in arrayoptions then
  3238. getmangledparaname:='array_of_const'
  3239. else
  3240. if ((highrange=-1) and (lowrange=0)) then
  3241. getmangledparaname:='array_of_'+elementdef.mangledparaname
  3242. else
  3243. internalerror(200204176);
  3244. end;
  3245. function tarraydef.is_publishable : boolean;
  3246. begin
  3247. Result:=ado_IsDynamicArray in arrayoptions;
  3248. end;
  3249. {***************************************************************************
  3250. tabstractrecorddef
  3251. ***************************************************************************}
  3252. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp);
  3253. begin
  3254. inherited create(dt);
  3255. objname:=stringdup(upper(n));
  3256. objrealname:=stringdup(n);
  3257. objectoptions:=[];
  3258. if assigned(current_module.namespace) then
  3259. begin
  3260. import_lib:=stringdup(current_module.namespace^);
  3261. replace(import_lib^,'.','/');
  3262. end;
  3263. end;
  3264. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3265. begin
  3266. inherited ppuload(dt,ppufile);
  3267. objrealname:=stringdup(ppufile.getstring);
  3268. objname:=stringdup(upper(objrealname^));
  3269. import_lib:=stringdup(ppufile.getstring);
  3270. { only used for external C++ classes and Java classes/records }
  3271. if (import_lib^='') then
  3272. stringdispose(import_lib);
  3273. ppufile.getsmallset(objectoptions);
  3274. end;
  3275. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  3276. begin
  3277. inherited ppuwrite(ppufile);
  3278. ppufile.putstring(objrealname^);
  3279. if assigned(import_lib) then
  3280. ppufile.putstring(import_lib^)
  3281. else
  3282. ppufile.putstring('');
  3283. ppufile.putsmallset(objectoptions);
  3284. end;
  3285. destructor tabstractrecorddef.destroy;
  3286. begin
  3287. stringdispose(objname);
  3288. stringdispose(objrealname);
  3289. stringdispose(import_lib);
  3290. tcinitcode.free;
  3291. inherited destroy;
  3292. end;
  3293. procedure tabstractrecorddef.buildderefimpl;
  3294. begin
  3295. inherited buildderefimpl;
  3296. if not (df_copied_def in defoptions) then
  3297. tstoredsymtable(symtable).buildderefimpl;
  3298. end;
  3299. procedure tabstractrecorddef.derefimpl;
  3300. begin
  3301. inherited derefimpl;
  3302. if not (df_copied_def in defoptions) then
  3303. tstoredsymtable(symtable).derefimpl;
  3304. end;
  3305. procedure tabstractrecorddef.check_forwards;
  3306. begin
  3307. { the defs of a copied def are defined for the original type only }
  3308. if not(df_copied_def in defoptions) then
  3309. tstoredsymtable(symtable).check_forwards;
  3310. end;
  3311. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  3312. var
  3313. i: longint;
  3314. sym: tsym;
  3315. begin
  3316. for i:=0 to symtable.SymList.Count-1 do
  3317. begin
  3318. sym:=tsym(symtable.SymList[i]);
  3319. if sym.typ=procsym then
  3320. begin
  3321. result:=tprocsym(sym).find_procdef_bytype(pt);
  3322. if assigned(result) then
  3323. exit;
  3324. end;
  3325. end;
  3326. result:=nil;
  3327. end;
  3328. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  3329. begin
  3330. if t=gs_record then
  3331. GetSymtable:=symtable
  3332. else
  3333. GetSymtable:=nil;
  3334. end;
  3335. function tabstractrecorddef.is_packed:boolean;
  3336. begin
  3337. result:=tabstractrecordsymtable(symtable).is_packed;
  3338. end;
  3339. function tabstractrecorddef.RttiName: string;
  3340. function generate_full_paramname(maxlength:longint):string;
  3341. const
  3342. commacount : array[boolean] of longint = (0,1);
  3343. var
  3344. fullparas,
  3345. paramname : ansistring;
  3346. module : tmodule;
  3347. sym : ttypesym;
  3348. i : longint;
  3349. begin
  3350. { we want at least enough space for an ellipsis }
  3351. if maxlength<3 then
  3352. internalerror(2014121203);
  3353. fullparas:='';
  3354. for i:=0 to genericparas.count-1 do
  3355. begin
  3356. sym:=ttypesym(genericparas[i]);
  3357. module:=find_module_from_symtable(sym.owner);
  3358. if not assigned(module) then
  3359. internalerror(2014121202);
  3360. paramname:=module.realmodulename^;
  3361. if sym.typedef.typ in [objectdef,recorddef] then
  3362. paramname:=paramname+'.'+tabstractrecorddef(sym.typedef).rttiname
  3363. else
  3364. paramname:=paramname+'.'+sym.typedef.typename;
  3365. if length(fullparas)+commacount[i>0]+length(paramname)>maxlength then
  3366. begin
  3367. if i>0 then
  3368. fullparas:=fullparas+',...'
  3369. else
  3370. fullparas:=fullparas+'...';
  3371. break;
  3372. end;
  3373. { could we fit an ellipsis after this parameter if it should be too long? }
  3374. if (maxlength-(length(fullparas)+commacount[i>0]+length(paramname))<4) and (i<genericparas.count-1) then
  3375. begin
  3376. { then omit already this parameter }
  3377. if i>0 then
  3378. fullparas:=fullparas+',...'
  3379. else
  3380. fullparas:=fullparas+'...';
  3381. break;
  3382. end;
  3383. if i>0 then
  3384. fullparas:=fullparas+',';
  3385. fullparas:=fullparas+paramname;
  3386. end;
  3387. result:=fullparas;
  3388. end;
  3389. var
  3390. nongeneric,
  3391. basename : string;
  3392. i,
  3393. remlength,
  3394. paramcount,
  3395. crcidx : longint;
  3396. begin
  3397. if rttistring='' then
  3398. begin
  3399. if is_specialization then
  3400. begin
  3401. rttistring:=OwnerHierarchyName;
  3402. { there should be two $ characters, one before the CRC and one before the count }
  3403. crcidx:=-1;
  3404. for i:=length(objrealname^) downto 1 do
  3405. if objrealname^[i]='$' then
  3406. begin
  3407. crcidx:=i;
  3408. break;
  3409. end;
  3410. if crcidx<0 then
  3411. internalerror(2014121201);
  3412. basename:=copy(objrealname^,1,crcidx-1);
  3413. split_generic_name(basename,nongeneric,paramcount);
  3414. rttistring:=rttistring+nongeneric+'<';
  3415. remlength:=255-length(rttistring)-1;
  3416. if remlength<4 then
  3417. rttistring:=rttistring+'>'
  3418. else
  3419. rttistring:=rttistring+generate_full_paramname(remlength)+'>';
  3420. end
  3421. else
  3422. if is_generic then
  3423. begin
  3424. rttistring:=OwnerHierarchyName;
  3425. split_generic_name(objrealname^,nongeneric,paramcount);
  3426. rttistring:=rttistring+nongeneric+'<';
  3427. { we don't want any ',' if there is only one parameter }
  3428. for i:=0 to paramcount-0 do
  3429. rttistring:=rttistring+',';
  3430. rttistring:=rttistring+'>';
  3431. end
  3432. else
  3433. rttistring:=OwnerHierarchyName+objrealname^;
  3434. end;
  3435. result:=rttistring;
  3436. end;
  3437. function tabstractrecorddef.search_enumerator_get: tprocdef;
  3438. var
  3439. sym : tsym;
  3440. i : integer;
  3441. pd : tprocdef;
  3442. hashedid : THashedIDString;
  3443. begin
  3444. result:=nil;
  3445. hashedid.id:='GETENUMERATOR';
  3446. sym:=tsym(symtable.FindWithHash(hashedid));
  3447. if assigned(sym) and (sym.typ=procsym) then
  3448. begin
  3449. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  3450. begin
  3451. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3452. if (pd.proctypeoption = potype_function) and
  3453. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  3454. (pd.visibility >= vis_public) then
  3455. begin
  3456. result:=pd;
  3457. exit;
  3458. end;
  3459. end;
  3460. end;
  3461. end;
  3462. function tabstractrecorddef.search_enumerator_move: tprocdef;
  3463. var
  3464. sym : tsym;
  3465. i : integer;
  3466. pd : tprocdef;
  3467. hashedid : THashedIDString;
  3468. begin
  3469. result:=nil;
  3470. // first search for po_enumerator_movenext method modifier
  3471. // then search for public function MoveNext: Boolean
  3472. for i:=0 to symtable.SymList.Count-1 do
  3473. begin
  3474. sym:=TSym(symtable.SymList[i]);
  3475. if (sym.typ=procsym) then
  3476. begin
  3477. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  3478. if assigned(pd) then
  3479. begin
  3480. result:=pd;
  3481. exit;
  3482. end;
  3483. end;
  3484. end;
  3485. hashedid.id:='MOVENEXT';
  3486. sym:=tsym(symtable.FindWithHash(hashedid));
  3487. if assigned(sym) and (sym.typ=procsym) then
  3488. begin
  3489. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  3490. begin
  3491. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3492. if (pd.proctypeoption = potype_function) and
  3493. is_boolean(pd.returndef) and
  3494. (pd.minparacount = 0) and
  3495. (pd.visibility >= vis_public) then
  3496. begin
  3497. result:=pd;
  3498. exit;
  3499. end;
  3500. end;
  3501. end;
  3502. end;
  3503. function tabstractrecorddef.search_enumerator_current: tsym;
  3504. var
  3505. sym: tsym;
  3506. i: integer;
  3507. hashedid : THashedIDString;
  3508. begin
  3509. result:=nil;
  3510. // first search for ppo_enumerator_current property modifier
  3511. // then search for public property Current
  3512. for i:=0 to symtable.SymList.Count-1 do
  3513. begin
  3514. sym:=TSym(symtable.SymList[i]);
  3515. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  3516. begin
  3517. result:=sym;
  3518. exit;
  3519. end;
  3520. end;
  3521. hashedid.id:='CURRENT';
  3522. sym:=tsym(symtable.FindWithHash(hashedid));
  3523. if assigned(sym) and (sym.typ=propertysym) and
  3524. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  3525. begin
  3526. result:=sym;
  3527. exit;
  3528. end;
  3529. end;
  3530. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  3531. var
  3532. st: tsymtable;
  3533. enclosingdef: tdef;
  3534. begin
  3535. if typ=objectdef then
  3536. result:=tobjectdef(self).objextname^
  3537. else if assigned(typesym) then
  3538. result:=typesym.realname
  3539. { have to generate anonymous nested type in current unit/class/record }
  3540. else
  3541. internalerror(2011032601);
  3542. { in case of specializations, add some extras to prevent name conflicts
  3543. with nested classes }
  3544. if df_specialization in defoptions then
  3545. result:='$'+result+'$specialization$';
  3546. st:=owner;
  3547. while assigned(st) and
  3548. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  3549. begin
  3550. { nested classes are named as "OuterClass$InnerClass" }
  3551. enclosingdef:=tdef(st.defowner);
  3552. if enclosingdef.typ=procdef then
  3553. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  3554. else if enclosingdef.typ=objectdef then
  3555. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  3556. else if assigned(enclosingdef.typesym) then
  3557. result:=enclosingdef.typesym.realname+'$'+result
  3558. else
  3559. internalerror(2011060305);
  3560. st:=enclosingdef.owner;
  3561. end;
  3562. if with_package_name and
  3563. assigned(import_lib) then
  3564. result:=import_lib^+'/'+result;
  3565. end;
  3566. function tabstractrecorddef.contains_float_field: boolean;
  3567. var
  3568. i : longint;
  3569. begin
  3570. result:=true;
  3571. for i:=0 to symtable.symlist.count-1 do
  3572. begin
  3573. if tsym(symtable.symlist[i]).typ<>fieldvarsym then
  3574. continue;
  3575. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  3576. begin
  3577. if tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  3578. exit;
  3579. { search recursively }
  3580. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  3581. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_float_field) then
  3582. exit;
  3583. end;
  3584. end;
  3585. result:=false;
  3586. end;
  3587. function tabstractrecorddef.contains_cross_aword_field: boolean;
  3588. var
  3589. i : longint;
  3590. foffset, fsize: aword;
  3591. begin
  3592. result:=true;
  3593. for i:=0 to symtable.symlist.count-1 do
  3594. begin
  3595. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  3596. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  3597. continue;
  3598. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  3599. begin
  3600. if is_packed then
  3601. begin
  3602. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset;
  3603. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.packedbitsize;
  3604. end
  3605. else
  3606. begin
  3607. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset*8;
  3608. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.size*8;
  3609. end;
  3610. if (foffset div (sizeof(aword)*8)) <> ((foffset+fsize-1) div (sizeof(aword)*8)) then
  3611. exit;
  3612. { search recursively }
  3613. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  3614. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_cross_aword_field) then
  3615. exit;
  3616. end;
  3617. end;
  3618. result:=false;
  3619. end;
  3620. {***************************************************************************
  3621. trecorddef
  3622. ***************************************************************************}
  3623. constructor trecorddef.create(const n:string; p:TSymtable);
  3624. begin
  3625. inherited create(n,recorddef);
  3626. symtable:=p;
  3627. { we can own the symtable only if nobody else owns a copy so far }
  3628. if symtable.refcount=1 then
  3629. symtable.defowner:=self;
  3630. isunion:=false;
  3631. end;
  3632. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  3633. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  3634. var
  3635. i,j : longint;
  3636. begin
  3637. if ppufile.getbyte=1 then
  3638. begin
  3639. new(variantrecdesc);
  3640. ppufile.getderef(variantrecdesc^.variantselectorderef);
  3641. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  3642. for i:=0 to high(variantrecdesc^.branches) do
  3643. begin
  3644. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  3645. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3646. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  3647. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3648. end;
  3649. end
  3650. else
  3651. variantrecdesc:=nil;
  3652. end;
  3653. begin
  3654. inherited ppuload(recorddef,ppufile);
  3655. if df_copied_def in defoptions then
  3656. begin
  3657. ppufile.getderef(cloneddefderef);
  3658. ppuload_platform(ppufile);
  3659. end
  3660. else
  3661. begin
  3662. ppuload_platform(ppufile);
  3663. symtable:=trecordsymtable.create(objrealname^,0);
  3664. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  3665. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  3666. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  3667. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  3668. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  3669. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  3670. trecordsymtable(symtable).ppuload(ppufile);
  3671. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3672. but because iso mode supports no units, there is no need to store the variantrecdesc
  3673. in the ppu
  3674. }
  3675. // readvariantrecdesc(variantrecdesc);
  3676. { requires usefieldalignment to be set }
  3677. symtable.defowner:=self;
  3678. end;
  3679. isunion:=false;
  3680. end;
  3681. destructor trecorddef.destroy;
  3682. begin
  3683. if assigned(symtable) then
  3684. begin
  3685. symtable.free;
  3686. symtable:=nil;
  3687. end;
  3688. inherited destroy;
  3689. end;
  3690. function trecorddef.getcopy : tstoreddef;
  3691. begin
  3692. result:=crecorddef.create(objrealname^,symtable.getcopy);
  3693. trecorddef(result).isunion:=isunion;
  3694. include(trecorddef(result).defoptions,df_copied_def);
  3695. if assigned(tcinitcode) then
  3696. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  3697. if assigned(import_lib) then
  3698. trecorddef(result).import_lib:=stringdup(import_lib^);
  3699. end;
  3700. function trecorddef.needs_inittable : boolean;
  3701. begin
  3702. needs_inittable:=trecordsymtable(symtable).needs_init_final
  3703. end;
  3704. function trecorddef.needs_separate_initrtti : boolean;
  3705. begin
  3706. result:=true;
  3707. end;
  3708. procedure trecorddef.buildderef;
  3709. begin
  3710. inherited buildderef;
  3711. if df_copied_def in defoptions then
  3712. cloneddefderef.build(symtable.defowner)
  3713. else
  3714. tstoredsymtable(symtable).buildderef;
  3715. end;
  3716. procedure trecorddef.deref;
  3717. begin
  3718. inherited deref;
  3719. { now dereference the definitions }
  3720. if df_copied_def in defoptions then
  3721. begin
  3722. cloneddef:=trecorddef(cloneddefderef.resolve);
  3723. symtable:=cloneddef.symtable.getcopy;
  3724. end
  3725. else
  3726. tstoredsymtable(symtable).deref;
  3727. { assign TGUID? load only from system unit }
  3728. if not(assigned(rec_tguid)) and
  3729. (upper(typename)='TGUID') and
  3730. assigned(owner) and
  3731. assigned(owner.name) and
  3732. (owner.name^='SYSTEM') then
  3733. rec_tguid:=self;
  3734. { assign JMP_BUF? load only from system unit }
  3735. if not(assigned(rec_jmp_buf)) and
  3736. (upper(typename)='JMP_BUF') and
  3737. assigned(owner) and
  3738. assigned(owner.name) and
  3739. (owner.name^='SYSTEM') then
  3740. rec_jmp_buf:=self;
  3741. end;
  3742. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  3743. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  3744. var
  3745. i,j : longint;
  3746. begin
  3747. if assigned(variantrecdesc) then
  3748. begin
  3749. ppufile.putbyte(1);
  3750. ppufile.putderef(variantrecdesc^.variantselectorderef);
  3751. ppufile.putasizeint(length(variantrecdesc^.branches));
  3752. for i:=0 to high(variantrecdesc^.branches) do
  3753. begin
  3754. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  3755. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3756. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  3757. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3758. end;
  3759. end
  3760. else
  3761. ppufile.putbyte(0);
  3762. end;
  3763. begin
  3764. inherited ppuwrite(ppufile);
  3765. if df_copied_def in defoptions then
  3766. ppufile.putderef(cloneddefderef)
  3767. else
  3768. begin
  3769. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  3770. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  3771. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  3772. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  3773. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  3774. ppufile.putword(trecordsymtable(symtable).paddingsize);
  3775. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3776. but because iso mode supports no units, there is no need to store the variantrecdesc
  3777. in the ppu
  3778. }
  3779. // writevariantrecdesc(variantrecdesc);
  3780. end;
  3781. writeentry(ppufile,ibrecorddef);
  3782. if not(df_copied_def in defoptions) then
  3783. trecordsymtable(symtable).ppuwrite(ppufile);
  3784. end;
  3785. function trecorddef.size:asizeint;
  3786. begin
  3787. result:=trecordsymtable(symtable).datasize;
  3788. end;
  3789. function trecorddef.alignment:shortint;
  3790. begin
  3791. alignment:=trecordsymtable(symtable).recordalignment;
  3792. end;
  3793. function trecorddef.padalignment:shortint;
  3794. begin
  3795. padalignment := trecordsymtable(symtable).padalignment;
  3796. end;
  3797. function trecorddef.GetTypeName : string;
  3798. begin
  3799. GetTypeName:='<record type>'
  3800. end;
  3801. {***************************************************************************
  3802. TABSTRACTPROCDEF
  3803. ***************************************************************************}
  3804. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  3805. begin
  3806. inherited create(dt);
  3807. parast:=tparasymtable.create(self,level);
  3808. paras:=nil;
  3809. minparacount:=0;
  3810. maxparacount:=0;
  3811. proctypeoption:=potype_none;
  3812. proccalloption:=pocall_none;
  3813. procoptions:=[];
  3814. returndef:=voidtype;
  3815. savesize:=sizeof(pint);
  3816. callerargareasize:=0;
  3817. calleeargareasize:=0;
  3818. has_paraloc_info:=callnoside;
  3819. funcretloc[callerside].init;
  3820. funcretloc[calleeside].init;
  3821. check_mark_as_nested;
  3822. end;
  3823. destructor tabstractprocdef.destroy;
  3824. begin
  3825. if assigned(paras) then
  3826. begin
  3827. {$ifdef MEMDEBUG}
  3828. memprocpara.start;
  3829. {$endif MEMDEBUG}
  3830. paras.free;
  3831. paras:=nil;
  3832. {$ifdef MEMDEBUG}
  3833. memprocpara.stop;
  3834. {$endif MEMDEBUG}
  3835. end;
  3836. if assigned(parast) then
  3837. begin
  3838. {$ifdef MEMDEBUG}
  3839. memprocparast.start;
  3840. {$endif MEMDEBUG}
  3841. parast.free;
  3842. parast:=nil;
  3843. {$ifdef MEMDEBUG}
  3844. memprocparast.stop;
  3845. {$endif MEMDEBUG}
  3846. end;
  3847. funcretloc[callerside].done;
  3848. funcretloc[calleeside].done;
  3849. inherited destroy;
  3850. end;
  3851. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  3852. begin
  3853. if (tsym(p).typ<>paravarsym) then
  3854. exit;
  3855. inc(plongint(arg)^);
  3856. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  3857. begin
  3858. if not assigned(tparavarsym(p).defaultconstsym) then
  3859. inc(minparacount);
  3860. inc(maxparacount);
  3861. end;
  3862. end;
  3863. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  3864. begin
  3865. if (tsym(p).typ<>paravarsym) then
  3866. exit;
  3867. paras.add(p);
  3868. end;
  3869. procedure tabstractprocdef.calcparas;
  3870. var
  3871. paracount : longint;
  3872. begin
  3873. { This can already be assigned when
  3874. we need to reresolve this unit (PFV) }
  3875. if assigned(paras) then
  3876. paras.free;
  3877. paras:=tparalist.create(false);
  3878. paracount:=0;
  3879. minparacount:=0;
  3880. maxparacount:=0;
  3881. parast.SymList.ForEachCall(@count_para,@paracount);
  3882. paras.capacity:=paracount;
  3883. { Insert parameters in table }
  3884. parast.SymList.ForEachCall(@insert_para,nil);
  3885. { Order parameters }
  3886. paras.sortparas;
  3887. end;
  3888. procedure tabstractprocdef.buildderef;
  3889. begin
  3890. { released procdef? }
  3891. if not assigned(parast) then
  3892. exit;
  3893. inherited buildderef;
  3894. returndefderef.build(returndef);
  3895. if po_explicitparaloc in procoptions then
  3896. funcretloc[callerside].buildderef;
  3897. { parast }
  3898. tparasymtable(parast).buildderef;
  3899. end;
  3900. procedure tabstractprocdef.deref;
  3901. begin
  3902. inherited deref;
  3903. returndef:=tdef(returndefderef.resolve);
  3904. if po_explicitparaloc in procoptions then
  3905. begin
  3906. funcretloc[callerside].deref;
  3907. has_paraloc_info:=callerside;
  3908. end
  3909. else
  3910. begin
  3911. { deref is called after loading from a ppu, but also after another
  3912. unit has been reloaded/recompiled and all references must be
  3913. re-resolved. Since the funcretloc contains a reference to a tdef,
  3914. reset it so that we won't try to access the stale def }
  3915. funcretloc[callerside].init;
  3916. has_paraloc_info:=callnoside;
  3917. end;
  3918. { parast }
  3919. tparasymtable(parast).deref;
  3920. { recalculated parameters }
  3921. calcparas;
  3922. end;
  3923. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3924. begin
  3925. inherited ppuload(dt,ppufile);
  3926. parast:=nil;
  3927. Paras:=nil;
  3928. minparacount:=0;
  3929. maxparacount:=0;
  3930. ppufile.getderef(returndefderef);
  3931. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3932. proccalloption:=tproccalloption(ppufile.getbyte);
  3933. ppufile.getnormalset(procoptions);
  3934. funcretloc[callerside].init;
  3935. if po_explicitparaloc in procoptions then
  3936. funcretloc[callerside].ppuload(ppufile);
  3937. savesize:=sizeof(pint);
  3938. if (po_explicitparaloc in procoptions) then
  3939. has_paraloc_info:=callerside;
  3940. end;
  3941. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3942. var
  3943. oldintfcrc : boolean;
  3944. begin
  3945. { released procdef? }
  3946. if not assigned(parast) then
  3947. exit;
  3948. inherited ppuwrite(ppufile);
  3949. ppufile.putderef(returndefderef);
  3950. oldintfcrc:=ppufile.do_interface_crc;
  3951. ppufile.do_interface_crc:=false;
  3952. ppufile.putbyte(ord(proctypeoption));
  3953. ppufile.putbyte(ord(proccalloption));
  3954. ppufile.putnormalset(procoptions);
  3955. ppufile.do_interface_crc:=oldintfcrc;
  3956. if (po_explicitparaloc in procoptions) then
  3957. funcretloc[callerside].ppuwrite(ppufile);
  3958. end;
  3959. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  3960. var
  3961. hs,s : ansistring;
  3962. hp : TParavarsym;
  3963. hpc : tconstsym;
  3964. first : boolean;
  3965. i : integer;
  3966. begin
  3967. s:='';
  3968. first:=true;
  3969. for i:=0 to paras.count-1 do
  3970. begin
  3971. hp:=tparavarsym(paras[i]);
  3972. if not(vo_is_hidden_para in hp.varoptions) or
  3973. (pno_showhidden in pno) then
  3974. begin
  3975. if first then
  3976. begin
  3977. s:=s+'(';
  3978. first:=false;
  3979. end
  3980. else
  3981. s:=s+';';
  3982. if vo_is_hidden_para in hp.varoptions then
  3983. s:=s+'<';
  3984. case hp.varspez of
  3985. vs_var :
  3986. s:=s+'var ';
  3987. vs_const :
  3988. s:=s+'const ';
  3989. vs_out :
  3990. s:=s+'out ';
  3991. vs_constref :
  3992. s:=s+'constref ';
  3993. end;
  3994. if (pno_paranames in pno) then
  3995. s:=s+hp.realname+':';
  3996. if hp.univpara then
  3997. s:=s+'univ ';
  3998. if assigned(hp.vardef.typesym) then
  3999. begin
  4000. hs:=hp.vardef.typesym.realname;
  4001. if hs[1]<>'$' then
  4002. s:=s+hp.vardef.OwnerHierarchyName+hs
  4003. else
  4004. s:=s+hp.vardef.GetTypeName;
  4005. end
  4006. else
  4007. s:=s+hp.vardef.GetTypeName;
  4008. { default value }
  4009. if assigned(hp.defaultconstsym) then
  4010. begin
  4011. hpc:=tconstsym(hp.defaultconstsym);
  4012. hs:='';
  4013. case hpc.consttyp of
  4014. conststring,
  4015. constresourcestring :
  4016. begin
  4017. If hpc.value.len>0 then
  4018. begin
  4019. setLength(hs,hpc.value.len);
  4020. { don't write past the end of hs if the constant
  4021. is > 255 chars }
  4022. move(hpc.value.valueptr^,hs[1],length(hs));
  4023. { make sure that constant strings with newline chars
  4024. don't create a linebreak in the assembler code,
  4025. since comments are line-based. Also remove nulls
  4026. because the comments are written as a pchar. }
  4027. ReplaceCase(hs,#0,'.');
  4028. ReplaceCase(hs,#10,'.');
  4029. ReplaceCase(hs,#13,'.');
  4030. end;
  4031. end;
  4032. constreal :
  4033. str(pbestreal(hpc.value.valueptr)^,hs);
  4034. constpointer :
  4035. hs:=tostr(hpc.value.valueordptr);
  4036. constord :
  4037. begin
  4038. if is_boolean(hpc.constdef) then
  4039. begin
  4040. if hpc.value.valueord<>0 then
  4041. hs:='TRUE'
  4042. else
  4043. hs:='FALSE';
  4044. end
  4045. else
  4046. hs:=tostr(hpc.value.valueord);
  4047. end;
  4048. constnil :
  4049. hs:='nil';
  4050. constset :
  4051. hs:='<set>';
  4052. end;
  4053. if hs<>'' then
  4054. s:=s+'="'+hs+'"';
  4055. end;
  4056. if vo_is_hidden_para in hp.varoptions then
  4057. s:=s+'>';
  4058. end;
  4059. end;
  4060. if not first then
  4061. s:=s+')';
  4062. if (po_varargs in procoptions) then
  4063. s:=s+';VarArgs';
  4064. typename_paras:=s;
  4065. end;
  4066. function tabstractprocdef.is_methodpointer:boolean;
  4067. begin
  4068. result:=false;
  4069. end;
  4070. function tabstractprocdef.is_addressonly:boolean;
  4071. begin
  4072. result:=true;
  4073. end;
  4074. function tabstractprocdef.no_self_node: boolean;
  4075. begin
  4076. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  4077. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  4078. end;
  4079. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef;
  4080. var
  4081. j, nestinglevel: longint;
  4082. pvs, npvs: tparavarsym;
  4083. begin
  4084. nestinglevel:=parast.symtablelevel;
  4085. if newtyp=procdef then
  4086. begin
  4087. if (copytyp<>pc_bareproc) then
  4088. result:=cprocdef.create(nestinglevel)
  4089. else
  4090. result:=cprocdef.create(normal_function_level);
  4091. tprocdef(result).visibility:=vis_public;
  4092. end
  4093. else
  4094. begin
  4095. result:=cprocvardef.create(nestinglevel);
  4096. end;
  4097. tabstractprocdef(result).returndef:=returndef;
  4098. tabstractprocdef(result).returndefderef:=returndefderef;
  4099. pvs:=nil;
  4100. npvs:=nil;
  4101. for j:=0 to parast.symlist.count-1 do
  4102. begin
  4103. case tsym(parast.symlist[j]).typ of
  4104. paravarsym:
  4105. begin
  4106. pvs:=tparavarsym(parast.symlist[j]);
  4107. { in case of bare proc, don't copy self, vmt or framepointer
  4108. parameters }
  4109. if (copytyp=pc_bareproc) and
  4110. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result,vo_is_funcret]*pvs.varoptions)<>[]) then
  4111. continue;
  4112. npvs:=cparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  4113. pvs.vardef,pvs.varoptions);
  4114. npvs.defaultconstsym:=pvs.defaultconstsym;
  4115. tabstractprocdef(result).parast.insert(npvs);
  4116. end;
  4117. constsym:
  4118. begin
  4119. // ignore, reuse original constym. Should also be duplicated
  4120. // be safe though
  4121. end;
  4122. symconst.typesym:
  4123. begin
  4124. // reuse original, part of generic declaration
  4125. end
  4126. else
  4127. internalerror(201160604);
  4128. end;
  4129. end;
  4130. tabstractprocdef(result).savesize:=savesize;
  4131. tabstractprocdef(result).proctypeoption:=proctypeoption;
  4132. tabstractprocdef(result).proccalloption:=proccalloption;
  4133. tabstractprocdef(result).procoptions:=procoptions;
  4134. if (copytyp=pc_bareproc) then
  4135. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  4136. if newtyp=procvardef then
  4137. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  4138. tabstractprocdef(result).callerargareasize:=callerargareasize;
  4139. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  4140. tabstractprocdef(result).maxparacount:=maxparacount;
  4141. tabstractprocdef(result).minparacount:=minparacount;
  4142. if po_explicitparaloc in procoptions then
  4143. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  4144. { recalculate parameter info }
  4145. tabstractprocdef(result).has_paraloc_info:=callnoside;
  4146. {$ifdef m68k}
  4147. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  4148. {$endif}
  4149. if (typ=procdef) and
  4150. (newtyp=procvardef) and
  4151. (owner.symtabletype=ObjectSymtable) then
  4152. include(tprocvardef(result).procoptions,po_methodpointer);
  4153. end;
  4154. procedure tabstractprocdef.check_mark_as_nested;
  4155. begin
  4156. { nested procvars require that nested functions use the Delphi-style
  4157. nested procedure calling convention }
  4158. if (parast.symtablelevel>normal_function_level) and
  4159. (m_nested_procvars in current_settings.modeswitches) then
  4160. include(procoptions,po_delphi_nested_cc);
  4161. end;
  4162. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  4163. begin
  4164. if (side in [callerside,callbothsides]) and
  4165. not(has_paraloc_info in [callerside,callbothsides]) then
  4166. begin
  4167. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  4168. if has_paraloc_info in [calleeside,callbothsides] then
  4169. has_paraloc_info:=callbothsides
  4170. else
  4171. has_paraloc_info:=callerside;
  4172. end;
  4173. if (side in [calleeside,callbothsides]) and
  4174. not(has_paraloc_info in [calleeside,callbothsides]) then
  4175. begin
  4176. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  4177. if has_paraloc_info in [callerside,callbothsides] then
  4178. has_paraloc_info:=callbothsides
  4179. else
  4180. has_paraloc_info:=calleeside;
  4181. end;
  4182. end;
  4183. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  4184. var
  4185. p: tparavarsym;
  4186. ploc: PCGParalocation;
  4187. i: longint;
  4188. begin
  4189. result:=false;
  4190. init_paraloc_info(side);
  4191. for i:=0 to parast.SymList.Count-1 do
  4192. if tsym(parast.SymList[i]).typ=paravarsym then
  4193. begin
  4194. p:=tparavarsym(parast.SymList[i]);
  4195. { check if no parameter is located on the stack }
  4196. if is_open_array(p.vardef) or
  4197. is_array_of_const(p.vardef) then
  4198. begin
  4199. result:=true;
  4200. exit;
  4201. end;
  4202. ploc:=p.paraloc[side].location;
  4203. while assigned(ploc) do
  4204. begin
  4205. if (ploc^.loc=LOC_REFERENCE) then
  4206. begin
  4207. result:=true;
  4208. exit
  4209. end;
  4210. ploc:=ploc^.next;
  4211. end;
  4212. end;
  4213. end;
  4214. function tabstractprocdef.is_pushleftright: boolean;
  4215. begin
  4216. result:=false;
  4217. end;
  4218. function tabstractprocdef.address_type: tdef;
  4219. begin
  4220. result:=voidcodepointertype;
  4221. end;
  4222. procedure tabstractprocdef.declared_far;
  4223. begin
  4224. Message1(parser_w_proc_directive_ignored,'FAR');
  4225. end;
  4226. procedure tabstractprocdef.declared_near;
  4227. begin
  4228. Message1(parser_w_proc_directive_ignored,'NEAR');
  4229. end;
  4230. {***************************************************************************
  4231. TPROCDEF
  4232. ***************************************************************************}
  4233. function tprocdef.GetResultName: PShortString;
  4234. begin
  4235. if not assigned(implprocdefinfo) then
  4236. internalerror(2014010301);
  4237. result:=implprocdefinfo^.resultname;
  4238. end;
  4239. procedure tprocdef.SetResultName(AValue: PShortString);
  4240. begin
  4241. if not assigned(implprocdefinfo) then
  4242. internalerror(2014010302);
  4243. implprocdefinfo^.resultname:=AValue;
  4244. end;
  4245. function tprocdef.GetParentFPInitBlock: tnode;
  4246. begin
  4247. if not assigned(implprocdefinfo) then
  4248. internalerror(2014010303);
  4249. result:=implprocdefinfo^.parentfpinitblock;
  4250. end;
  4251. function tprocdef.GetParentFPStruct: tsym;
  4252. begin
  4253. if not assigned(implprocdefinfo) then
  4254. internalerror(2014010304);
  4255. result:=implprocdefinfo^.parentfpstruct;
  4256. end;
  4257. function tprocdef.GetParentFPStructPtrType: tdef;
  4258. begin
  4259. if not assigned(implprocdefinfo) then
  4260. internalerror(2014010305);
  4261. result:=implprocdefinfo^.parentfpstructptrtype;
  4262. end;
  4263. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  4264. begin
  4265. if not assigned(implprocdefinfo) then
  4266. internalerror(2014010306);
  4267. implprocdefinfo^.parentfpinitblock:=AValue;
  4268. end;
  4269. function tprocdef.Getprocendtai: tai;
  4270. begin
  4271. if not assigned(implprocdefinfo) then
  4272. internalerror(2014010307);
  4273. result:=implprocdefinfo^.procendtai;
  4274. end;
  4275. function tprocdef.Getprocstarttai: tai;
  4276. begin
  4277. if not assigned(implprocdefinfo) then
  4278. internalerror(2014010308);
  4279. result:=implprocdefinfo^.procstarttai;
  4280. end;
  4281. procedure tprocdef.Setprocendtai(AValue: tai);
  4282. begin
  4283. if not assigned(implprocdefinfo) then
  4284. internalerror(2014010309);
  4285. implprocdefinfo^.procendtai:=AValue;
  4286. end;
  4287. function tprocdef.Getskpara: pointer;
  4288. begin
  4289. if not assigned(implprocdefinfo) then
  4290. internalerror(2014010310);
  4291. result:=implprocdefinfo^.skpara;
  4292. end;
  4293. procedure tprocdef.Setskpara(AValue: pointer);
  4294. begin
  4295. if not assigned(implprocdefinfo) then
  4296. internalerror(2014010311);
  4297. implprocdefinfo^.skpara:=AValue;
  4298. end;
  4299. function tprocdef.Getforwarddef: boolean;
  4300. begin
  4301. if not assigned(implprocdefinfo) then
  4302. internalerror(2014010312);
  4303. result:=implprocdefinfo^.forwarddef;
  4304. end;
  4305. function tprocdef.Gethasforward: boolean;
  4306. begin
  4307. if not assigned(implprocdefinfo) then
  4308. internalerror(2014010313);
  4309. result:=implprocdefinfo^.hasforward;
  4310. end;
  4311. function tprocdef.Getinterfacedef: boolean;
  4312. begin
  4313. if not assigned(implprocdefinfo) then
  4314. internalerror(2014010314);
  4315. result:=implprocdefinfo^.interfacedef;
  4316. end;
  4317. procedure tprocdef.Setforwarddef(AValue: boolean);
  4318. begin
  4319. if not assigned(implprocdefinfo) then
  4320. internalerror(2014010315);
  4321. implprocdefinfo^.forwarddef:=AValue;
  4322. end;
  4323. procedure tprocdef.Sethasforward(AValue: boolean);
  4324. begin
  4325. if not assigned(implprocdefinfo) then
  4326. internalerror(2014010316);
  4327. implprocdefinfo^.hasforward:=AValue;
  4328. end;
  4329. function tprocdef.GetIsEmpty: boolean;
  4330. begin
  4331. result:=pio_empty in implprocoptions;
  4332. end;
  4333. procedure tprocdef.SetIsEmpty(AValue: boolean);
  4334. begin
  4335. if AValue then
  4336. include(implprocoptions,pio_empty)
  4337. else
  4338. include(implprocoptions,pio_empty);
  4339. end;
  4340. function tprocdef.GetHasInliningInfo: boolean;
  4341. begin
  4342. result:=pio_has_inlininginfo in implprocoptions;
  4343. end;
  4344. procedure tprocdef.SetHasInliningInfo(AValue: boolean);
  4345. begin
  4346. if AValue then
  4347. include(implprocoptions,pio_has_inlininginfo)
  4348. else
  4349. exclude(implprocoptions,pio_has_inlininginfo);
  4350. end;
  4351. procedure tprocdef.Setinterfacedef(AValue: boolean);
  4352. begin
  4353. if not assigned(implprocdefinfo) then
  4354. internalerror(2014010317);
  4355. implprocdefinfo^.interfacedef:=AValue;
  4356. end;
  4357. procedure tprocdef.Setprocstarttai(AValue: tai);
  4358. begin
  4359. if not assigned(implprocdefinfo) then
  4360. internalerror(2014010318);
  4361. implprocdefinfo^.procstarttai:=AValue;
  4362. end;
  4363. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  4364. begin
  4365. if not assigned(implprocdefinfo) then
  4366. internalerror(2014010319);
  4367. implprocdefinfo^.parentfpstruct:=AValue;
  4368. end;
  4369. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  4370. begin
  4371. if not assigned(implprocdefinfo) then
  4372. internalerror(2014010320);
  4373. implprocdefinfo^.parentfpstructptrtype:=AValue;
  4374. end;
  4375. constructor tprocdef.create(level:byte);
  4376. begin
  4377. inherited create(procdef,level);
  4378. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  4379. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  4380. {$ifdef symansistr}
  4381. _mangledname:='';
  4382. {$else symansistr}
  4383. _mangledname:=nil;
  4384. {$endif symansistr}
  4385. fileinfo:=current_filepos;
  4386. extnumber:=$ffff;
  4387. aliasnames:=TCmdStrList.create;
  4388. funcretsym:=nil;
  4389. forwarddef:=true;
  4390. interfacedef:=false;
  4391. hasforward:=false;
  4392. struct := nil;
  4393. import_dll:=nil;
  4394. import_name:=nil;
  4395. import_nr:=0;
  4396. inlininginfo:=nil;
  4397. deprecatedmsg:=nil;
  4398. end;
  4399. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  4400. var
  4401. i,aliasnamescount : longint;
  4402. level : byte;
  4403. begin
  4404. inherited ppuload(procdef,ppufile);
  4405. {$ifdef symansistr}
  4406. if po_has_mangledname in procoptions then
  4407. _mangledname:=ppufile.getansistring
  4408. else
  4409. _mangledname:='';
  4410. {$else symansistr}
  4411. if po_has_mangledname in procoptions then
  4412. _mangledname:=stringdup(ppufile.getstring)
  4413. else
  4414. _mangledname:=nil;
  4415. {$endif symansistr}
  4416. extnumber:=ppufile.getword;
  4417. level:=ppufile.getbyte;
  4418. ppufile.getderef(structderef);
  4419. ppufile.getderef(procsymderef);
  4420. ppufile.getposinfo(fileinfo);
  4421. visibility:=tvisibility(ppufile.getbyte);
  4422. ppufile.getsmallset(symoptions);
  4423. if sp_has_deprecated_msg in symoptions then
  4424. deprecatedmsg:=stringdup(ppufile.getstring)
  4425. else
  4426. deprecatedmsg:=nil;
  4427. synthetickind:=tsynthetickind(ppufile.getbyte);
  4428. { import stuff }
  4429. if po_has_importdll in procoptions then
  4430. import_dll:=stringdup(ppufile.getstring)
  4431. else
  4432. import_dll:=nil;
  4433. if po_has_importname in procoptions then
  4434. import_name:=stringdup(ppufile.getstring)
  4435. else
  4436. import_name:=nil;
  4437. import_nr:=ppufile.getword;
  4438. if (po_msgint in procoptions) then
  4439. messageinf.i:=ppufile.getlongint;
  4440. if (po_msgstr in procoptions) then
  4441. messageinf.str:=stringdup(ppufile.getstring);
  4442. if (po_dispid in procoptions) then
  4443. dispid:=ppufile.getlongint;
  4444. { inline stuff }
  4445. ppufile.getsmallset(implprocoptions);
  4446. if has_inlininginfo then
  4447. begin
  4448. ppufile.getderef(funcretsymderef);
  4449. new(inlininginfo);
  4450. ppufile.getsmallset(inlininginfo^.flags);
  4451. end
  4452. else
  4453. begin
  4454. inlininginfo:=nil;
  4455. funcretsym:=nil;
  4456. end;
  4457. aliasnames:=TCmdStrList.create;
  4458. { count alias names }
  4459. aliasnamescount:=ppufile.getbyte;
  4460. for i:=1 to aliasnamescount do
  4461. aliasnames.insert(ppufile.getstring);
  4462. ppuload_platform(ppufile);
  4463. { load para symtable }
  4464. parast:=tparasymtable.create(self,level);
  4465. tparasymtable(parast).ppuload(ppufile);
  4466. { load local symtable }
  4467. if has_inlininginfo then
  4468. begin
  4469. localst:=tlocalsymtable.create(self,level);
  4470. tlocalsymtable(localst).ppuload(ppufile);
  4471. end
  4472. else
  4473. localst:=nil;
  4474. { inline stuff }
  4475. if has_inlininginfo then
  4476. inlininginfo^.code:=ppuloadnodetree(ppufile);
  4477. { default values for no persistent data }
  4478. if (cs_link_deffile in current_settings.globalswitches) and
  4479. (tf_need_export in target_info.flags) and
  4480. (po_exports in procoptions) then
  4481. deffile.AddExport(mangledname);
  4482. { Disable po_has_inlining until the derefimpl is done }
  4483. has_inlininginfo:=false;
  4484. end;
  4485. destructor tprocdef.destroy;
  4486. begin
  4487. aliasnames.free;
  4488. aliasnames:=nil;
  4489. if assigned(localst) and
  4490. (localst.symtabletype<>staticsymtable) then
  4491. begin
  4492. {$ifdef MEMDEBUG}
  4493. memproclocalst.start;
  4494. {$endif MEMDEBUG}
  4495. localst.free;
  4496. localst:=nil;
  4497. {$ifdef MEMDEBUG}
  4498. memproclocalst.start;
  4499. {$endif MEMDEBUG}
  4500. end;
  4501. if assigned(inlininginfo) then
  4502. begin
  4503. {$ifdef MEMDEBUG}
  4504. memprocnodetree.start;
  4505. {$endif MEMDEBUG}
  4506. tnode(inlininginfo^.code).free;
  4507. {$ifdef MEMDEBUG}
  4508. memprocnodetree.start;
  4509. {$endif MEMDEBUG}
  4510. dispose(inlininginfo);
  4511. inlininginfo:=nil;
  4512. end;
  4513. if assigned(implprocdefinfo) then
  4514. begin
  4515. stringdispose(implprocdefinfo^.resultname);
  4516. freemem(implprocdefinfo);
  4517. implprocdefinfo:=nil;
  4518. end;
  4519. stringdispose(import_dll);
  4520. stringdispose(import_name);
  4521. stringdispose(deprecatedmsg);
  4522. if (po_msgstr in procoptions) then
  4523. stringdispose(messageinf.str);
  4524. {$ifndef symansistr}
  4525. if assigned(_mangledname) then
  4526. begin
  4527. {$ifdef MEMDEBUG}
  4528. memmanglednames.start;
  4529. {$endif MEMDEBUG}
  4530. stringdispose(_mangledname);
  4531. {$ifdef MEMDEBUG}
  4532. memmanglednames.stop;
  4533. {$endif MEMDEBUG}
  4534. end;
  4535. {$endif symansistr}
  4536. inherited destroy;
  4537. end;
  4538. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  4539. var
  4540. oldintfcrc : boolean;
  4541. aliasnamescount : longint;
  4542. item : TCmdStrListItem;
  4543. begin
  4544. { released procdef? }
  4545. if not assigned(parast) then
  4546. exit;
  4547. inherited ppuwrite(ppufile);
  4548. {$ifdef symansistr}
  4549. if po_has_mangledname in procoptions then
  4550. ppufile.putansistring(_mangledname);
  4551. {$else symansistr}
  4552. if po_has_mangledname in procoptions then
  4553. ppufile.putstring(_mangledname^);
  4554. {$endif symansistr}
  4555. ppufile.putword(extnumber);
  4556. ppufile.putbyte(parast.symtablelevel);
  4557. ppufile.putderef(structderef);
  4558. ppufile.putderef(procsymderef);
  4559. ppufile.putposinfo(fileinfo);
  4560. ppufile.putbyte(byte(visibility));
  4561. ppufile.putsmallset(symoptions);
  4562. if sp_has_deprecated_msg in symoptions then
  4563. ppufile.putstring(deprecatedmsg^);
  4564. ppufile.putbyte(byte(synthetickind));
  4565. { import }
  4566. if po_has_importdll in procoptions then
  4567. ppufile.putstring(import_dll^);
  4568. if po_has_importname in procoptions then
  4569. ppufile.putstring(import_name^);
  4570. ppufile.putword(import_nr);
  4571. if (po_msgint in procoptions) then
  4572. ppufile.putlongint(messageinf.i);
  4573. if (po_msgstr in procoptions) then
  4574. ppufile.putstring(messageinf.str^);
  4575. if (po_dispid in procoptions) then
  4576. ppufile.putlongint(dispid);
  4577. { inline stuff }
  4578. oldintfcrc:=ppufile.do_crc;
  4579. ppufile.do_crc:=false;
  4580. ppufile.putsmallset(implprocoptions);
  4581. if has_inlininginfo then
  4582. begin
  4583. ppufile.putderef(funcretsymderef);
  4584. ppufile.putsmallset(inlininginfo^.flags);
  4585. end;
  4586. { count alias names }
  4587. aliasnamescount:=0;
  4588. item:=TCmdStrListItem(aliasnames.first);
  4589. while assigned(item) do
  4590. begin
  4591. inc(aliasnamescount);
  4592. item:=TCmdStrListItem(item.next);
  4593. end;
  4594. if aliasnamescount>255 then
  4595. internalerror(200711021);
  4596. ppufile.putbyte(aliasnamescount);
  4597. item:=TCmdStrListItem(aliasnames.first);
  4598. while assigned(item) do
  4599. begin
  4600. ppufile.putstring(item.str);
  4601. item:=TCmdStrListItem(item.next);
  4602. end;
  4603. ppufile.do_crc:=oldintfcrc;
  4604. { write this entry }
  4605. writeentry(ppufile,ibprocdef);
  4606. { Save the para symtable, this is taken from the interface }
  4607. tparasymtable(parast).ppuwrite(ppufile);
  4608. { save localsymtable for inline procedures or when local
  4609. browser info is requested, this has no influence on the crc }
  4610. if has_inlininginfo then
  4611. begin
  4612. oldintfcrc:=ppufile.do_crc;
  4613. ppufile.do_crc:=false;
  4614. tlocalsymtable(localst).ppuwrite(ppufile);
  4615. ppufile.do_crc:=oldintfcrc;
  4616. end;
  4617. { node tree for inlining }
  4618. oldintfcrc:=ppufile.do_crc;
  4619. ppufile.do_crc:=false;
  4620. if has_inlininginfo then
  4621. ppuwritenodetree(ppufile,inlininginfo^.code);
  4622. ppufile.do_crc:=oldintfcrc;
  4623. end;
  4624. function tprocdef.fullprocname(showhidden:boolean):string;
  4625. var
  4626. pno: tprocnameoptions;
  4627. begin
  4628. pno:=[];
  4629. if showhidden then
  4630. include(pno,pno_showhidden);
  4631. result:=customprocname(pno);
  4632. end;
  4633. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  4634. var
  4635. s, rn : ansistring;
  4636. t : ttoken;
  4637. begin
  4638. {$ifdef EXTDEBUG}
  4639. include(pno,pno_showhidden);
  4640. {$endif EXTDEBUG}
  4641. s:='';
  4642. if proctypeoption=potype_operator then
  4643. begin
  4644. for t:=NOTOKEN to last_overloaded do
  4645. if procsym.realname='$'+overloaded_names[t] then
  4646. begin
  4647. s:='operator ';
  4648. if (pno_ownername in pno) and
  4649. assigned(struct) then
  4650. s:=s+struct.RttiName+'.';
  4651. s:=s+arraytokeninfo[t].str+typename_paras(pno);
  4652. break;
  4653. end;
  4654. end
  4655. else
  4656. begin
  4657. if (po_classmethod in procoptions) and
  4658. not(pno_noclassmarker in pno) then
  4659. s:='class ';
  4660. case proctypeoption of
  4661. potype_constructor,
  4662. potype_class_constructor:
  4663. s:=s+'constructor ';
  4664. potype_class_destructor,
  4665. potype_destructor:
  4666. s:=s+'destructor ';
  4667. else
  4668. if (pno_proctypeoption in pno) then
  4669. begin
  4670. if assigned(returndef) and
  4671. not(is_void(returndef)) then
  4672. s:=s+'function '
  4673. else
  4674. s:=s+'procedure ';
  4675. end;
  4676. end;
  4677. if (pno_ownername in pno) and
  4678. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  4679. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  4680. rn:=procsym.realname;
  4681. if (pno_noleadingdollar in pno) and
  4682. (rn[1]='$') then
  4683. delete(rn,1,1);
  4684. s:=s+rn+typename_paras(pno);
  4685. end;
  4686. if not(proctypeoption in [potype_constructor,potype_destructor,
  4687. potype_class_constructor,potype_class_destructor]) and
  4688. assigned(returndef) and
  4689. not(is_void(returndef)) then
  4690. s:=s+':'+returndef.GetTypeName;
  4691. if owner.symtabletype=localsymtable then
  4692. s:=s+' is nested';
  4693. s:=s+';';
  4694. { forced calling convention? }
  4695. if (po_hascallingconvention in procoptions) then
  4696. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  4697. if (po_staticmethod in procoptions) and
  4698. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  4699. s:=s+' Static;';
  4700. if pno_mangledname in pno then
  4701. s:=s+' -- mangled name: '+mangledname;
  4702. customprocname:=s;
  4703. end;
  4704. function tprocdef.is_methodpointer:boolean;
  4705. begin
  4706. { don't check assigned(_class), that's also the case for nested
  4707. procedures inside methods }
  4708. result:=(owner.symtabletype=ObjectSymtable)and not no_self_node;
  4709. end;
  4710. function tprocdef.is_addressonly:boolean;
  4711. begin
  4712. result:=assigned(owner) and
  4713. not is_methodpointer and
  4714. (not(m_nested_procvars in current_settings.modeswitches) or
  4715. not is_nested_pd(self));
  4716. end;
  4717. procedure tprocdef.make_external;
  4718. begin
  4719. include(procoptions,po_external);
  4720. forwarddef:=false;
  4721. end;
  4722. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  4723. begin
  4724. case t of
  4725. gs_local :
  4726. GetSymtable:=localst;
  4727. gs_para :
  4728. GetSymtable:=parast;
  4729. else
  4730. GetSymtable:=nil;
  4731. end;
  4732. end;
  4733. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp): tstoreddef;
  4734. var
  4735. j : longint;
  4736. begin
  4737. result:=inherited getcopyas(newtyp,copytyp);
  4738. if newtyp=procvardef then
  4739. exit;
  4740. { don't copy mangled name, can be different }
  4741. tprocdef(result).messageinf:=messageinf;
  4742. tprocdef(result).dispid:=dispid;
  4743. if po_msgstr in procoptions then
  4744. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  4745. tprocdef(result).symoptions:=symoptions;
  4746. if assigned(deprecatedmsg) then
  4747. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  4748. { will have to be associated with appropriate procsym }
  4749. tprocdef(result).procsym:=nil;
  4750. { don't create aliases for bare copies, nor copy the funcretsym as
  4751. the function result parameter will be inserted again if necessary
  4752. (e.g. if the calling convention is changed) }
  4753. if copytyp<>pc_bareproc then
  4754. begin
  4755. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  4756. if assigned(funcretsym) then
  4757. begin
  4758. if funcretsym.owner=parast then
  4759. begin
  4760. j:=parast.symlist.indexof(funcretsym);
  4761. if j<0 then
  4762. internalerror(2011040606);
  4763. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  4764. end
  4765. else if funcretsym.owner=localst then
  4766. begin
  4767. { nothing to do, will be inserted for the new procdef while
  4768. parsing its body (by pdecsub.insert_funcret_local) }
  4769. end
  4770. else
  4771. internalerror(2011040605);
  4772. end;
  4773. end;
  4774. { will have to be associated with a new struct }
  4775. tprocdef(result).struct:=nil;
  4776. if assigned(implprocdefinfo) then
  4777. begin
  4778. if assigned(resultname) then
  4779. tprocdef(result).resultname:=stringdup(resultname^);
  4780. end;
  4781. if assigned(import_dll) then
  4782. tprocdef(result).import_dll:=stringdup(import_dll^);
  4783. if assigned(import_name) then
  4784. tprocdef(result).import_name:=stringdup(import_name^);
  4785. tprocdef(result).import_nr:=import_nr;
  4786. tprocdef(result).extnumber:=$ffff;
  4787. tprocdef(result).visibility:=visibility;
  4788. tprocdef(result).synthetickind:=synthetickind;
  4789. { we need a separate implementation for the copied def }
  4790. tprocdef(result).forwarddef:=true;
  4791. tprocdef(result).interfacedef:=true;
  4792. { create new paralist }
  4793. tprocdef(result).calcparas;
  4794. end;
  4795. function tprocdef.getcopy: tstoreddef;
  4796. begin
  4797. result:=getcopyas(procdef,pc_normal);
  4798. end;
  4799. procedure tprocdef.buildderef;
  4800. begin
  4801. inherited buildderef;
  4802. structderef.build(struct);
  4803. { procsym that originaly defined this definition, should be in the
  4804. same symtable }
  4805. procsymderef.build(procsym);
  4806. end;
  4807. procedure tprocdef.buildderefimpl;
  4808. begin
  4809. inherited buildderefimpl;
  4810. { inline tree }
  4811. if has_inlininginfo then
  4812. begin
  4813. { Localst is not available for main/unit init }
  4814. if assigned(localst) then
  4815. begin
  4816. tlocalsymtable(localst).buildderef;
  4817. tlocalsymtable(localst).buildderefimpl;
  4818. end;
  4819. funcretsymderef.build(funcretsym);
  4820. inlininginfo^.code.buildderefimpl;
  4821. end;
  4822. end;
  4823. procedure tprocdef.deref;
  4824. begin
  4825. inherited deref;
  4826. struct:=tabstractrecorddef(structderef.resolve);
  4827. { procsym that originaly defined this definition, should be in the
  4828. same symtable }
  4829. procsym:=tprocsym(procsymderef.resolve);
  4830. end;
  4831. procedure tprocdef.derefimpl;
  4832. begin
  4833. { Enable has_inlininginfo when the inlininginfo
  4834. structure is available. The has_inlininginfo was disabled
  4835. after the load, since the data was invalid }
  4836. if assigned(inlininginfo) then
  4837. has_inlininginfo:=true;
  4838. { Inline }
  4839. if has_inlininginfo then
  4840. begin
  4841. { Locals }
  4842. if assigned(localst) then
  4843. begin
  4844. tlocalsymtable(localst).deref;
  4845. tlocalsymtable(localst).derefimpl;
  4846. end;
  4847. inlininginfo^.code.derefimpl;
  4848. { funcretsym, this is always located in the localst }
  4849. funcretsym:=tsym(funcretsymderef.resolve);
  4850. end
  4851. else
  4852. begin
  4853. { safety }
  4854. { Not safe! A unit may be reresolved after its interface has been
  4855. parsed but before its implementation has been parsed, and in that
  4856. case the funcretsym is still required!
  4857. funcretsym:=nil; }
  4858. end;
  4859. end;
  4860. function tprocdef.GetTypeName : string;
  4861. begin
  4862. GetTypeName := FullProcName(false);
  4863. end;
  4864. function tprocdef.mangledname : TSymStr;
  4865. begin
  4866. {$ifdef symansistr}
  4867. if _mangledname='' then
  4868. begin
  4869. result:=defaultmangledname;
  4870. _mangledname:=result;
  4871. end
  4872. else
  4873. result:=_mangledname;
  4874. {$else symansistr}
  4875. if not assigned(_mangledname) then
  4876. begin
  4877. result:=defaultmangledname;
  4878. _mangledname:=stringdup(mangledname);
  4879. end
  4880. else
  4881. result:=_mangledname^;
  4882. {$endif symansistr}
  4883. end;
  4884. function tprocdef.defaultmangledname: TSymStr;
  4885. var
  4886. hp : TParavarsym;
  4887. hs : TSymStr;
  4888. crc : dword;
  4889. newlen,
  4890. oldlen,
  4891. i : integer;
  4892. begin
  4893. hp:=nil;
  4894. { we need to use the symtable where the procsym is inserted,
  4895. because that is visible to the world }
  4896. defaultmangledname:=make_mangledname('',procsym.owner,procsym.name);
  4897. oldlen:=length(defaultmangledname);
  4898. { add parameter types }
  4899. for i:=0 to paras.count-1 do
  4900. begin
  4901. hp:=tparavarsym(paras[i]);
  4902. if not(vo_is_hidden_para in hp.varoptions) then
  4903. defaultmangledname:=defaultmangledname+'$'+hp.vardef.mangledparaname;
  4904. end;
  4905. { add resultdef, add $$ as separator to make it unique from a
  4906. parameter separator }
  4907. if not is_void(returndef) then
  4908. defaultmangledname:=defaultmangledname+'$$'+returndef.mangledparaname;
  4909. newlen:=length(defaultmangledname);
  4910. { Replace with CRC if the parameter line is very long }
  4911. if (newlen-oldlen>12) and
  4912. ((newlen>100) or (newlen-oldlen>64)) then
  4913. begin
  4914. crc:=0;
  4915. for i:=0 to paras.count-1 do
  4916. begin
  4917. hp:=tparavarsym(paras[i]);
  4918. if not(vo_is_hidden_para in hp.varoptions) then
  4919. begin
  4920. hs:=hp.vardef.mangledparaname;
  4921. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4922. end;
  4923. end;
  4924. if not is_void(returndef) then
  4925. begin
  4926. { add a little prefix so that x(integer; integer) is different from x(integer):integer }
  4927. hs:='$$'+returndef.mangledparaname;
  4928. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4929. end;
  4930. defaultmangledname:=Copy(defaultmangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  4931. end;
  4932. end;
  4933. function tprocdef.cplusplusmangledname : TSymStr;
  4934. function getcppparaname(p : tdef) : TSymStr;
  4935. const
  4936. {$ifdef NAMEMANGLING_GCC2}
  4937. ordtype2str : array[tordtype] of string[2] = (
  4938. '',
  4939. 'Uc','Us','Ui','Us',
  4940. 'Sc','s','i','x',
  4941. 'b','b','b','b','b',
  4942. 'c','w','x');
  4943. {$else NAMEMANGLING_GCC2}
  4944. ordtype2str : array[tordtype] of string[1] = (
  4945. 'v',
  4946. 'h','t','j','y',
  4947. 'a','s','i','x',
  4948. 'b','b','b','b',
  4949. 'b','b','b','b',
  4950. 'c','w','x');
  4951. floattype2str : array[tfloattype] of string[1] = (
  4952. 'f','d','e','e',
  4953. 'd','d','g');
  4954. {$endif NAMEMANGLING_GCC2}
  4955. var
  4956. s : TSymStr;
  4957. begin
  4958. case p.typ of
  4959. orddef:
  4960. s:=ordtype2str[torddef(p).ordtype];
  4961. pointerdef:
  4962. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  4963. {$ifndef NAMEMANGLING_GCC2}
  4964. floatdef:
  4965. s:=floattype2str[tfloatdef(p).floattype];
  4966. {$endif NAMEMANGLING_GCC2}
  4967. else
  4968. internalerror(2103001);
  4969. end;
  4970. getcppparaname:=s;
  4971. end;
  4972. var
  4973. s,s2 : TSymStr;
  4974. hp : TParavarsym;
  4975. i : integer;
  4976. begin
  4977. {$ifdef NAMEMANGLING_GCC2}
  4978. { outdated gcc 2.x name mangling scheme }
  4979. s := procsym.realname;
  4980. if procsym.owner.symtabletype=ObjectSymtable then
  4981. begin
  4982. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  4983. case proctypeoption of
  4984. potype_destructor:
  4985. s:='_$_'+tostr(length(s2))+s2;
  4986. potype_constructor:
  4987. s:='___'+tostr(length(s2))+s2;
  4988. else
  4989. s:='_'+s+'__'+tostr(length(s2))+s2;
  4990. end;
  4991. end
  4992. else s:=s+'__';
  4993. s:=s+'F';
  4994. { concat modifiers }
  4995. { !!!!! }
  4996. { now we handle the parameters }
  4997. if maxparacount>0 then
  4998. begin
  4999. for i:=0 to paras.count-1 do
  5000. begin
  5001. hp:=tparavarsym(paras[i]);
  5002. { no hidden parameters form part of a C++ mangled name:
  5003. a) self is not included
  5004. b) there are no "high" or other hidden parameters
  5005. }
  5006. if vo_is_hidden_para in hp.varoptions then
  5007. continue;
  5008. s2:=getcppparaname(hp.vardef);
  5009. if hp.varspez in [vs_var,vs_out] then
  5010. s2:='R'+s2;
  5011. s:=s+s2;
  5012. end;
  5013. end
  5014. else
  5015. s:=s+'v';
  5016. cplusplusmangledname:=s;
  5017. {$else NAMEMANGLING_GCC2}
  5018. { gcc 3.x and 4.x name mangling scheme }
  5019. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  5020. if procsym.owner.symtabletype=ObjectSymtable then
  5021. begin
  5022. s:='_ZN';
  5023. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  5024. s:=s+tostr(length(s2))+s2;
  5025. case proctypeoption of
  5026. potype_constructor:
  5027. s:=s+'C1';
  5028. potype_destructor:
  5029. s:=s+'D1';
  5030. else
  5031. s:=s+tostr(length(procsym.realname))+procsym.realname;
  5032. end;
  5033. s:=s+'E';
  5034. end
  5035. else
  5036. s:=procsym.realname;
  5037. { now we handle the parameters }
  5038. if maxparacount>0 then
  5039. begin
  5040. for i:=0 to paras.count-1 do
  5041. begin
  5042. hp:=tparavarsym(paras[i]);
  5043. { no hidden parameters form part of a C++ mangled name:
  5044. a) self is not included
  5045. b) there are no "high" or other hidden parameters
  5046. }
  5047. if vo_is_hidden_para in hp.varoptions then
  5048. continue;
  5049. s2:=getcppparaname(hp.vardef);
  5050. if hp.varspez in [vs_var,vs_out] then
  5051. s2:='R'+s2;
  5052. s:=s+s2;
  5053. end;
  5054. end
  5055. else
  5056. s:=s+'v';
  5057. cplusplusmangledname:=s;
  5058. {$endif NAMEMANGLING_GCC2}
  5059. end;
  5060. function tprocdef.objcmangledname : TSymStr;
  5061. var
  5062. manglednamelen: longint;
  5063. iscatmethod : boolean;
  5064. begin
  5065. if not (po_msgstr in procoptions) then
  5066. internalerror(2009030901);
  5067. { we may very well need longer strings to handle these... }
  5068. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  5069. length('+"[ ]"')+length(messageinf.str^);
  5070. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  5071. if (iscatmethod) then
  5072. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  5073. if manglednamelen>255 then
  5074. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  5075. if not(po_classmethod in procoptions) then
  5076. result:='"-['
  5077. else
  5078. result:='"+[';
  5079. { quotes are necessary because the +/- otherwise confuse the assembler
  5080. into expecting a number
  5081. }
  5082. if iscatmethod then
  5083. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  5084. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  5085. if iscatmethod then
  5086. result:=result+')';
  5087. result:=result+' '+messageinf.str^+']"';
  5088. end;
  5089. procedure tprocdef.setmangledname(const s : TSymStr);
  5090. begin
  5091. { This is not allowed anymore, the forward declaration
  5092. already needs to create the correct mangledname, no changes
  5093. afterwards are allowed (PFV) }
  5094. { Exception: interface definitions in mode macpas, since in that }
  5095. { case no reference to the old name can exist yet (JM) }
  5096. {$ifdef symansistr}
  5097. if _mangledname<>'' then
  5098. if ((m_mac in current_settings.modeswitches) and
  5099. (interfacedef)) then
  5100. _mangledname:=''
  5101. else
  5102. internalerror(200411171);
  5103. {$else symansistr}
  5104. if assigned(_mangledname) then
  5105. if ((m_mac in current_settings.modeswitches) and
  5106. (interfacedef)) then
  5107. stringdispose(_mangledname)
  5108. else
  5109. internalerror(200411171);
  5110. {$endif symansistr}
  5111. {$ifdef jvm}
  5112. { this routine can be called for compilerproces. can't set mangled
  5113. name since it must be calculated, but it uses import_name when set
  5114. -> set that one }
  5115. import_name:=stringdup(s);
  5116. include(procoptions,po_has_importname);
  5117. include(procoptions,po_has_mangledname);
  5118. {$else}
  5119. {$ifdef symansistr}
  5120. _mangledname:=s;
  5121. {$else symansistr}
  5122. _mangledname:=stringdup(s);
  5123. {$endif symansistr}
  5124. {$endif jvm}
  5125. include(procoptions,po_has_mangledname);
  5126. end;
  5127. {***************************************************************************
  5128. TPROCVARDEF
  5129. ***************************************************************************}
  5130. constructor tprocvardef.create(level:byte);
  5131. begin
  5132. inherited create(procvardef,level);
  5133. end;
  5134. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  5135. begin
  5136. inherited ppuload(procvardef,ppufile);
  5137. { load para symtable }
  5138. parast:=tparasymtable.create(self,ppufile.getbyte);
  5139. ppuload_platform(ppufile);
  5140. tparasymtable(parast).ppuload(ppufile);
  5141. end;
  5142. function tprocvardef.getcopy : tstoreddef;
  5143. var
  5144. i : tcallercallee;
  5145. j : longint;
  5146. begin
  5147. result:=cprocvardef.create(parast.symtablelevel);
  5148. tprocvardef(result).returndef:=returndef;
  5149. tprocvardef(result).returndefderef:=returndefderef;
  5150. tprocvardef(result).parast:=parast.getcopy;
  5151. tprocvardef(result).savesize:=savesize;
  5152. { create paralist copy }
  5153. calcparas;
  5154. tprocvardef(result).paras:=tparalist.create(false);
  5155. tprocvardef(result).paras.count:=paras.count;
  5156. for j:=0 to paras.count-1 do
  5157. tprocvardef(result).paras[j]:=paras[j];
  5158. tprocvardef(result).proctypeoption:=proctypeoption;
  5159. tprocvardef(result).proccalloption:=proccalloption;
  5160. tprocvardef(result).procoptions:=procoptions;
  5161. tprocvardef(result).callerargareasize:=callerargareasize;
  5162. tprocvardef(result).calleeargareasize:=calleeargareasize;
  5163. tprocvardef(result).maxparacount:=maxparacount;
  5164. tprocvardef(result).minparacount:=minparacount;
  5165. for i:=low(tcallercallee) to high(tcallercallee) do
  5166. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  5167. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  5168. {$ifdef m68k}
  5169. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  5170. {$endif}
  5171. end;
  5172. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  5173. begin
  5174. inherited ppuwrite(ppufile);
  5175. { Save the para symtable level (necessary to distinguish nested
  5176. procvars) }
  5177. ppufile.putbyte(parast.symtablelevel);
  5178. { Write this entry }
  5179. writeentry(ppufile,ibprocvardef);
  5180. { Save the para symtable, this is taken from the interface }
  5181. tparasymtable(parast).ppuwrite(ppufile);
  5182. end;
  5183. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  5184. begin
  5185. case t of
  5186. gs_para :
  5187. GetSymtable:=parast;
  5188. else
  5189. GetSymtable:=nil;
  5190. end;
  5191. end;
  5192. function tprocvardef.size : asizeint;
  5193. begin
  5194. if ((po_methodpointer in procoptions) or
  5195. is_nested_pd(self)) and
  5196. not(po_addressonly in procoptions) then
  5197. begin
  5198. if is_nested_pd(self) then
  5199. size:=voidcodepointertype.size+parentfpvoidpointertype.size
  5200. else
  5201. size:=voidcodepointertype.size+voidpointertype.size;
  5202. end
  5203. else
  5204. size:=voidcodepointertype.size;
  5205. end;
  5206. function tprocvardef.is_methodpointer:boolean;
  5207. begin
  5208. result:=(po_methodpointer in procoptions);
  5209. end;
  5210. function tprocvardef.is_addressonly:boolean;
  5211. begin
  5212. result:=(not(po_methodpointer in procoptions) and
  5213. not is_nested_pd(self)) or
  5214. (po_addressonly in procoptions);
  5215. end;
  5216. function tprocvardef.getmangledparaname:TSymStr;
  5217. begin
  5218. if not(po_methodpointer in procoptions) then
  5219. if not is_nested_pd(self) then
  5220. result:='procvar'
  5221. else
  5222. result:='nestedprovar'
  5223. else
  5224. result:='procvarofobj'
  5225. end;
  5226. function tprocvardef.is_publishable : boolean;
  5227. begin
  5228. is_publishable:=(po_methodpointer in procoptions);
  5229. end;
  5230. function tprocvardef.GetTypeName : string;
  5231. var
  5232. s: string;
  5233. pno : tprocnameoptions;
  5234. begin
  5235. {$ifdef EXTDEBUG}
  5236. pno:=[pno_showhidden];
  5237. {$else EXTDEBUG}
  5238. pno:=[];
  5239. {$endif EXTDEBUG}
  5240. s:='<';
  5241. if po_classmethod in procoptions then
  5242. s := s+'class method type of'
  5243. else
  5244. if po_addressonly in procoptions then
  5245. s := s+'address of'
  5246. else
  5247. s := s+'procedure variable type of';
  5248. if assigned(returndef) and
  5249. (returndef<>voidtype) then
  5250. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  5251. else
  5252. s:=s+' procedure'+typename_paras(pno);
  5253. if po_methodpointer in procoptions then
  5254. s := s+' of object';
  5255. if is_nested_pd(self) then
  5256. s := s+' is nested';
  5257. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  5258. end;
  5259. {***************************************************************************
  5260. TOBJECTDEF
  5261. ***************************************************************************}
  5262. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  5263. begin
  5264. inherited create(n,objectdef);
  5265. fcurrent_dispid:=0;
  5266. objecttype:=ot;
  5267. childof:=nil;
  5268. if objecttype=odt_helper then
  5269. owner.includeoption(sto_has_helper);
  5270. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  5271. { create space for vmt !! }
  5272. vmtentries:=TFPList.Create;
  5273. vmt_offset:=0;
  5274. set_parent(c);
  5275. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  5276. prepareguid;
  5277. { setup implemented interfaces }
  5278. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5279. ImplementedInterfaces:=TFPObjectList.Create(true)
  5280. else
  5281. ImplementedInterfaces:=nil;
  5282. writing_class_record_dbginfo:=false;
  5283. end;
  5284. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  5285. var
  5286. i,
  5287. implintfcount : longint;
  5288. d, getterd : tderef;
  5289. ImplIntf : TImplementedInterface;
  5290. vmtentry : pvmtentry;
  5291. begin
  5292. inherited ppuload(objectdef,ppufile);
  5293. objecttype:=tobjecttyp(ppufile.getbyte);
  5294. objextname:=stringdup(ppufile.getstring);
  5295. { only used for external Objective-C classes/protocols }
  5296. if (objextname^='') then
  5297. stringdispose(objextname);
  5298. symtable:=tObjectSymtable.create(self,objrealname^,0);
  5299. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  5300. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  5301. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  5302. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  5303. vmt_offset:=ppufile.getlongint;
  5304. ppufile.getderef(childofderef);
  5305. { load guid }
  5306. iidstr:=nil;
  5307. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5308. begin
  5309. new(iidguid);
  5310. ppufile.getguid(iidguid^);
  5311. iidstr:=stringdup(ppufile.getstring);
  5312. end;
  5313. abstractcnt:=ppufile.getlongint;
  5314. if objecttype=odt_helper then
  5315. ppufile.getderef(extendeddefderef);
  5316. vmtentries:=TFPList.Create;
  5317. vmtentries.count:=ppufile.getlongint;
  5318. for i:=0 to vmtentries.count-1 do
  5319. begin
  5320. ppufile.getderef(d);
  5321. new(vmtentry);
  5322. vmtentry^.procdef:=nil;
  5323. vmtentry^.procdefderef:=d;
  5324. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  5325. vmtentries[i]:=vmtentry;
  5326. end;
  5327. { load implemented interfaces }
  5328. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5329. begin
  5330. ImplementedInterfaces:=TFPObjectList.Create(true);
  5331. implintfcount:=ppufile.getlongint;
  5332. for i:=0 to implintfcount-1 do
  5333. begin
  5334. ppufile.getderef(d);
  5335. ppufile.getderef(getterd);
  5336. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  5337. ImplIntf.IOffset:=ppufile.getlongint;
  5338. byte(ImplIntf.IType):=ppufile.getbyte;
  5339. ImplementedInterfaces.Add(ImplIntf);
  5340. end;
  5341. end
  5342. else
  5343. ImplementedInterfaces:=nil;
  5344. if df_copied_def in defoptions then
  5345. begin
  5346. ppufile.getderef(cloneddefderef);
  5347. ppuload_platform(ppufile);
  5348. end
  5349. else
  5350. begin
  5351. ppuload_platform(ppufile);
  5352. tObjectSymtable(symtable).ppuload(ppufile);
  5353. end;
  5354. { handles the predefined class tobject }
  5355. { the last TOBJECT which is loaded gets }
  5356. { it ! }
  5357. if (childof=nil) and
  5358. (objecttype in [odt_class,odt_javaclass]) and
  5359. (objname^='TOBJECT') then
  5360. class_tobject:=self;
  5361. if (childof=nil) and
  5362. (objecttype=odt_interfacecom) then
  5363. if (objname^='IUNKNOWN') then
  5364. interface_iunknown:=self
  5365. else
  5366. if (objname^='IDISPATCH') then
  5367. interface_idispatch:=self;
  5368. if (childof=nil) and
  5369. (objecttype=odt_objcclass) and
  5370. (objname^='PROTOCOL') then
  5371. objc_protocoltype:=self;
  5372. if (objecttype=odt_javaclass) and
  5373. not(oo_is_formal in objectoptions) then
  5374. begin
  5375. if (objname^='JLOBJECT') then
  5376. java_jlobject:=self
  5377. else if (objname^='JLTHROWABLE') then
  5378. java_jlthrowable:=self
  5379. else if (objname^='FPCBASERECORDTYPE') then
  5380. java_fpcbaserecordtype:=self
  5381. else if (objname^='JLSTRING') then
  5382. java_jlstring:=self
  5383. else if (objname^='ANSISTRINGCLASS') then
  5384. java_ansistring:=self
  5385. else if (objname^='SHORTSTRINGCLASS') then
  5386. java_shortstring:=self
  5387. else if (objname^='JLENUM') then
  5388. java_jlenum:=self
  5389. else if (objname^='JUENUMSET') then
  5390. java_juenumset:=self
  5391. else if (objname^='FPCBITSET') then
  5392. java_jubitset:=self
  5393. else if (objname^='FPCBASEPROCVARTYPE') then
  5394. java_procvarbase:=self;
  5395. end;
  5396. writing_class_record_dbginfo:=false;
  5397. end;
  5398. destructor tobjectdef.destroy;
  5399. begin
  5400. if assigned(symtable) then
  5401. begin
  5402. symtable.free;
  5403. symtable:=nil;
  5404. end;
  5405. stringdispose(objextname);
  5406. stringdispose(iidstr);
  5407. if assigned(ImplementedInterfaces) then
  5408. begin
  5409. ImplementedInterfaces.free;
  5410. ImplementedInterfaces:=nil;
  5411. end;
  5412. if assigned(iidguid) then
  5413. begin
  5414. dispose(iidguid);
  5415. iidguid:=nil;
  5416. end;
  5417. if assigned(vmtentries) then
  5418. begin
  5419. resetvmtentries;
  5420. vmtentries.free;
  5421. vmtentries:=nil;
  5422. end;
  5423. if assigned(vmcallstaticinfo) then
  5424. begin
  5425. freemem(vmcallstaticinfo);
  5426. vmcallstaticinfo:=nil;
  5427. end;
  5428. inherited destroy;
  5429. end;
  5430. function tobjectdef.getcopy : tstoreddef;
  5431. var
  5432. i : longint;
  5433. begin
  5434. result:=cobjectdef.create(objecttype,objrealname^,childof);
  5435. { the constructor allocates a symtable which we release to avoid memory leaks }
  5436. tobjectdef(result).symtable.free;
  5437. tobjectdef(result).symtable:=symtable.getcopy;
  5438. if assigned(objextname) then
  5439. tobjectdef(result).objextname:=stringdup(objextname^);
  5440. if assigned(import_lib) then
  5441. tobjectdef(result).import_lib:=stringdup(import_lib^);
  5442. tobjectdef(result).objectoptions:=objectoptions;
  5443. include(tobjectdef(result).defoptions,df_copied_def);
  5444. tobjectdef(result).extendeddef:=extendeddef;
  5445. if assigned(tcinitcode) then
  5446. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  5447. tobjectdef(result).vmt_offset:=vmt_offset;
  5448. if assigned(iidguid) then
  5449. begin
  5450. new(tobjectdef(result).iidguid);
  5451. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  5452. end;
  5453. if assigned(iidstr) then
  5454. tobjectdef(result).iidstr:=stringdup(iidstr^);
  5455. tobjectdef(result).abstractcnt:=abstractcnt;
  5456. if assigned(ImplementedInterfaces) then
  5457. begin
  5458. for i:=0 to ImplementedInterfaces.count-1 do
  5459. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  5460. end;
  5461. if assigned(vmtentries) then
  5462. begin
  5463. tobjectdef(result).vmtentries:=TFPList.Create;
  5464. tobjectdef(result).copyvmtentries(self);
  5465. end;
  5466. end;
  5467. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  5468. var
  5469. i : longint;
  5470. vmtentry : pvmtentry;
  5471. ImplIntf : TImplementedInterface;
  5472. old_do_indirect_crc: boolean;
  5473. begin
  5474. { if class1 in unit A changes, and class2 in unit B inherits from it
  5475. (so unit B uses unit A), then unit B with class2 will be recompiled.
  5476. However, if there is also a class3 in unit C that only depends on
  5477. unit B, then unit C will not be recompiled because nothing changed
  5478. to the interface of unit B. Nevertheless, unit C can indirectly
  5479. depend on unit A via derefs, and these must be updated -> the
  5480. indirect crc keeps track of such changes. }
  5481. old_do_indirect_crc:=ppufile.do_indirect_crc;
  5482. ppufile.do_indirect_crc:=true;
  5483. inherited ppuwrite(ppufile);
  5484. ppufile.putbyte(byte(objecttype));
  5485. if assigned(objextname) then
  5486. ppufile.putstring(objextname^)
  5487. else
  5488. ppufile.putstring('');
  5489. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  5490. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  5491. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  5492. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  5493. ppufile.putlongint(vmt_offset);
  5494. ppufile.putderef(childofderef);
  5495. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5496. begin
  5497. ppufile.putguid(iidguid^);
  5498. ppufile.putstring(iidstr^);
  5499. end;
  5500. ppufile.putlongint(abstractcnt);
  5501. if objecttype=odt_helper then
  5502. ppufile.putderef(extendeddefderef);
  5503. ppufile.putlongint(vmtentries.count);
  5504. for i:=0 to vmtentries.count-1 do
  5505. begin
  5506. vmtentry:=pvmtentry(vmtentries[i]);
  5507. ppufile.putderef(vmtentry^.procdefderef);
  5508. ppufile.putbyte(byte(vmtentry^.visibility));
  5509. end;
  5510. if assigned(ImplementedInterfaces) then
  5511. begin
  5512. ppufile.putlongint(ImplementedInterfaces.Count);
  5513. for i:=0 to ImplementedInterfaces.Count-1 do
  5514. begin
  5515. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  5516. ppufile.putderef(ImplIntf.intfdefderef);
  5517. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  5518. ppufile.putlongint(ImplIntf.Ioffset);
  5519. ppufile.putbyte(byte(ImplIntf.IType));
  5520. end;
  5521. end;
  5522. if df_copied_def in defoptions then
  5523. ppufile.putderef(cloneddefderef);
  5524. writeentry(ppufile,ibobjectdef);
  5525. if not(df_copied_def in defoptions) then
  5526. tObjectSymtable(symtable).ppuwrite(ppufile);
  5527. ppufile.do_indirect_crc:=old_do_indirect_crc;
  5528. end;
  5529. function tobjectdef.GetTypeName:string;
  5530. begin
  5531. { in this case we will go in endless recursion, because then }
  5532. { there is no tsym associated yet with the def. It can occur }
  5533. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  5534. { instead of the actual type name }
  5535. if not assigned(typesym) then
  5536. result:='<Currently Parsed Class>'
  5537. else
  5538. result:=typesymbolprettyname;
  5539. end;
  5540. procedure tobjectdef.buildderef;
  5541. var
  5542. i : longint;
  5543. vmtentry : pvmtentry;
  5544. begin
  5545. inherited buildderef;
  5546. childofderef.build(childof);
  5547. if df_copied_def in defoptions then
  5548. cloneddefderef.build(symtable.defowner)
  5549. else
  5550. tstoredsymtable(symtable).buildderef;
  5551. if objecttype=odt_helper then
  5552. extendeddefderef.build(extendeddef);
  5553. for i:=0 to vmtentries.count-1 do
  5554. begin
  5555. vmtentry:=pvmtentry(vmtentries[i]);
  5556. vmtentry^.procdefderef.build(vmtentry^.procdef);
  5557. end;
  5558. if assigned(ImplementedInterfaces) then
  5559. begin
  5560. for i:=0 to ImplementedInterfaces.count-1 do
  5561. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  5562. end;
  5563. end;
  5564. procedure tobjectdef.deref;
  5565. var
  5566. i : longint;
  5567. vmtentry : pvmtentry;
  5568. begin
  5569. inherited deref;
  5570. childof:=tobjectdef(childofderef.resolve);
  5571. if df_copied_def in defoptions then
  5572. begin
  5573. cloneddef:=tobjectdef(cloneddefderef.resolve);
  5574. symtable:=cloneddef.symtable.getcopy;
  5575. end
  5576. else
  5577. tstoredsymtable(symtable).deref;
  5578. if objecttype=odt_helper then
  5579. extendeddef:=tdef(extendeddefderef.resolve);
  5580. for i:=0 to vmtentries.count-1 do
  5581. begin
  5582. vmtentry:=pvmtentry(vmtentries[i]);
  5583. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  5584. end;
  5585. if assigned(ImplementedInterfaces) then
  5586. begin
  5587. for i:=0 to ImplementedInterfaces.count-1 do
  5588. TImplementedInterface(ImplementedInterfaces[i]).deref;
  5589. end;
  5590. end;
  5591. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  5592. var
  5593. pd: tprocdef absolute def;
  5594. st: tsymtable;
  5595. psym: tsym;
  5596. nname: TIDString;
  5597. begin
  5598. if (tdef(def).typ<>procdef) then
  5599. exit;
  5600. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  5601. owner = symtable in which objcclassdef is defined
  5602. }
  5603. st:=pd.owner.defowner.owner;
  5604. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  5605. { check for an existing procsym with our special name }
  5606. psym:=tsym(st.find(nname));
  5607. if not assigned(psym) then
  5608. begin
  5609. psym:=cprocsym.create(nname);
  5610. { avoid warning about this symbol being unused }
  5611. psym.IncRefCount;
  5612. { don't check for duplicates:
  5613. a) we checked above
  5614. b) in case we are in the implementation section of a unit, this
  5615. will also check for this symbol in the interface section
  5616. (since you normally cannot have symbols with the same name
  5617. both interface and implementation), and it's possible to
  5618. have class helpers for the same class in the interface and
  5619. in the implementation, and they cannot be merged since only
  5620. the once in the interface must be saved to the ppu/visible
  5621. from other units }
  5622. st.insert(psym,false);
  5623. end
  5624. else if (psym.typ<>procsym) then
  5625. internalerror(2009111501);
  5626. { add ourselves to this special procsym }
  5627. tprocsym(psym).procdeflist.add(def);
  5628. end;
  5629. procedure tobjectdef.derefimpl;
  5630. begin
  5631. inherited derefimpl;
  5632. { the procdefs are not owned by the class helper procsyms, so they
  5633. are not stored/restored either -> re-add them here }
  5634. if (objecttype in [odt_objcclass,odt_objcprotocol]) or
  5635. (oo_is_classhelper in objectoptions) then
  5636. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  5637. end;
  5638. procedure tobjectdef.resetvmtentries;
  5639. var
  5640. i : longint;
  5641. begin
  5642. for i:=0 to vmtentries.Count-1 do
  5643. Dispose(pvmtentry(vmtentries[i]));
  5644. vmtentries.clear;
  5645. end;
  5646. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  5647. var
  5648. i : longint;
  5649. vmtentry : pvmtentry;
  5650. begin
  5651. resetvmtentries;
  5652. vmtentries.count:=objdef.vmtentries.count;
  5653. for i:=0 to objdef.vmtentries.count-1 do
  5654. begin
  5655. new(vmtentry);
  5656. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  5657. vmtentries[i]:=vmtentry;
  5658. end;
  5659. end;
  5660. function tobjectdef.getparentdef:tdef;
  5661. begin
  5662. { TODO: Remove getparentdef hack}
  5663. { With 2 forward declared classes with the child class before the
  5664. parent class the child class is written earlier to the ppu. Leaving it
  5665. possible to have a reference to the parent class for property overriding,
  5666. but the parent class still has the childof not resolved yet (PFV) }
  5667. if childof=nil then
  5668. childof:=tobjectdef(childofderef.resolve);
  5669. result:=childof;
  5670. end;
  5671. procedure tobjectdef.prepareguid;
  5672. begin
  5673. { set up guid }
  5674. if not assigned(iidguid) then
  5675. begin
  5676. new(iidguid);
  5677. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  5678. end;
  5679. { setup iidstring }
  5680. if not assigned(iidstr) then
  5681. iidstr:=stringdup(''); { default is empty string }
  5682. end;
  5683. procedure tobjectdef.set_parent( c : tobjectdef);
  5684. begin
  5685. if assigned(childof) then
  5686. exit;
  5687. childof:=c;
  5688. if not assigned(c) then
  5689. exit;
  5690. { inherit options and status }
  5691. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  5692. { initially has the same number of abstract methods as the parent }
  5693. abstractcnt:=c.abstractcnt;
  5694. { add the data of the anchestor class/object }
  5695. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  5696. begin
  5697. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  5698. { inherit recordalignment }
  5699. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  5700. { if both the parent and this record use C-alignment, also inherit
  5701. the current field alignment }
  5702. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  5703. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  5704. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  5705. { the padding is not inherited for Objective-C classes (maybe not
  5706. for cppclass either?) }
  5707. if objecttype=odt_objcclass then
  5708. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  5709. if (oo_has_vmt in objectoptions) and
  5710. (oo_has_vmt in c.objectoptions) then
  5711. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  5712. { if parent has a vmt field then the offset is the same for the child PM }
  5713. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  5714. begin
  5715. vmt_offset:=c.vmt_offset;
  5716. include(objectoptions,oo_has_vmt);
  5717. end;
  5718. end;
  5719. end;
  5720. procedure tobjectdef.insertvmt;
  5721. var
  5722. vs: tfieldvarsym;
  5723. begin
  5724. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5725. exit;
  5726. if (oo_has_vmt in objectoptions) then
  5727. internalerror(12345)
  5728. else
  5729. begin
  5730. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  5731. tObjectSymtable(symtable).fieldalignment);
  5732. if (tf_requires_proper_alignment in target_info.flags) then
  5733. begin
  5734. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  5735. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  5736. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  5737. end;
  5738. vs:=cfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  5739. hidesym(vs);
  5740. tObjectSymtable(symtable).insert(vs);
  5741. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  5742. if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  5743. vmt_offset:=vs.fieldoffset
  5744. else
  5745. vmt_offset:=vs.fieldoffset div 8;
  5746. include(objectoptions,oo_has_vmt);
  5747. end;
  5748. end;
  5749. procedure tobjectdef.check_forwards;
  5750. begin
  5751. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  5752. inherited;
  5753. if (oo_is_forward in objectoptions) then
  5754. begin
  5755. { ok, in future, the forward can be resolved }
  5756. Message1(sym_e_class_forward_not_resolved,objrealname^);
  5757. exclude(objectoptions,oo_is_forward);
  5758. end;
  5759. end;
  5760. function tobjectdef.find_destructor: tprocdef;
  5761. var
  5762. objdef: tobjectdef;
  5763. begin
  5764. objdef:=self;
  5765. while assigned(objdef) do
  5766. begin
  5767. result:=objdef.find_procdef_bytype(potype_destructor);
  5768. if assigned(result) then
  5769. exit;
  5770. objdef:=objdef.childof;
  5771. end;
  5772. result:=nil;
  5773. end;
  5774. function tobjectdef.implements_any_interfaces: boolean;
  5775. begin
  5776. result := (ImplementedInterfaces.Count > 0) or
  5777. (assigned(childof) and childof.implements_any_interfaces);
  5778. end;
  5779. function tobjectdef.size : asizeint;
  5780. begin
  5781. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5782. result:=voidpointertype.size
  5783. else
  5784. result:=tObjectSymtable(symtable).datasize;
  5785. end;
  5786. function tobjectdef.alignment:shortint;
  5787. begin
  5788. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5789. alignment:=voidpointertype.size
  5790. else
  5791. alignment:=tObjectSymtable(symtable).recordalignment;
  5792. end;
  5793. function tobjectdef.vmtmethodoffset(index:longint):longint;
  5794. begin
  5795. { for offset of methods for classes, see rtl/inc/objpash.inc }
  5796. case objecttype of
  5797. odt_class:
  5798. { the +2*sizeof(pint) is size and -size }
  5799. vmtmethodoffset:=index*voidcodepointertype.size+10*voidpointertype.size+2*sizeof(pint);
  5800. odt_helper,
  5801. odt_objcclass,
  5802. odt_objcprotocol:
  5803. vmtmethodoffset:=0;
  5804. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  5805. vmtmethodoffset:=index*voidcodepointertype.size;
  5806. odt_javaclass,
  5807. odt_interfacejava:
  5808. { invalid }
  5809. vmtmethodoffset:=-1;
  5810. else
  5811. { the +2*sizeof(pint) is size and -size }
  5812. {$ifdef WITHDMT}
  5813. vmtmethodoffset:=index*voidcodepointertype.size+2*voidpointertype.size+2*sizeof(pint);
  5814. {$else WITHDMT}
  5815. vmtmethodoffset:=index*voidcodepointertype.size+1*voidpointertype.size+2*sizeof(pint);
  5816. {$endif WITHDMT}
  5817. end;
  5818. end;
  5819. function tobjectdef.vmt_mangledname : TSymStr;
  5820. begin
  5821. if not(oo_has_vmt in objectoptions) then
  5822. Message1(parser_n_object_has_no_vmt,objrealname^);
  5823. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  5824. end;
  5825. function tobjectdef.needs_inittable : boolean;
  5826. var
  5827. hp : tobjectdef;
  5828. begin
  5829. case objecttype of
  5830. odt_helper,
  5831. odt_class :
  5832. needs_inittable:=false;
  5833. odt_dispinterface,
  5834. odt_interfacecom:
  5835. needs_inittable:=true;
  5836. odt_interfacecorba:
  5837. begin
  5838. hp:=childof;
  5839. while assigned(hp) do
  5840. begin
  5841. if hp=interface_iunknown then
  5842. begin
  5843. needs_inittable:=true;
  5844. exit;
  5845. end;
  5846. hp:=hp.childof;
  5847. end;
  5848. needs_inittable:=false;
  5849. end;
  5850. odt_object:
  5851. needs_inittable:=
  5852. tObjectSymtable(symtable).needs_init_final or
  5853. (assigned(childof) and
  5854. childof.needs_inittable);
  5855. odt_cppclass,
  5856. odt_objcclass,
  5857. odt_objcprotocol,
  5858. odt_javaclass,
  5859. odt_interfacejava:
  5860. needs_inittable:=false;
  5861. else
  5862. internalerror(200108267);
  5863. end;
  5864. end;
  5865. function tobjectdef.needs_separate_initrtti : boolean;
  5866. begin
  5867. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5868. end;
  5869. function tobjectdef.rtti_mangledname(rt: trttitype): TSymStr;
  5870. begin
  5871. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  5872. result:=inherited rtti_mangledname(rt)
  5873. else
  5874. begin
  5875. { necessary in case of a dynamic array of nsobject, or
  5876. if an nsobject field appears in a record that needs
  5877. init/finalisation }
  5878. if rt=initrtti then
  5879. begin
  5880. result:=voidpointertype.rtti_mangledname(rt);
  5881. exit;
  5882. end;
  5883. if not(target_info.system in systems_objc_nfabi) then
  5884. begin
  5885. result:=target_asm.labelprefix;
  5886. case objecttype of
  5887. odt_objcclass:
  5888. begin
  5889. case rt of
  5890. objcclassrtti:
  5891. if not(oo_is_classhelper in objectoptions) then
  5892. result:=result+'_OBJC_CLASS_'
  5893. else
  5894. result:=result+'_OBJC_CATEGORY_';
  5895. objcmetartti:
  5896. if not(oo_is_classhelper in objectoptions) then
  5897. result:=result+'_OBJC_METACLASS_'
  5898. else
  5899. internalerror(2009111511);
  5900. else
  5901. internalerror(2009092302);
  5902. end;
  5903. end;
  5904. odt_objcprotocol:
  5905. result:=result+'_OBJC_PROTOCOL_';
  5906. end;
  5907. end
  5908. else
  5909. begin
  5910. case objecttype of
  5911. odt_objcclass:
  5912. begin
  5913. if (oo_is_classhelper in objectoptions) and
  5914. (rt<>objcclassrtti) then
  5915. internalerror(2009111512);
  5916. case rt of
  5917. objcclassrtti:
  5918. if not(oo_is_classhelper in objectoptions) then
  5919. result:='_OBJC_CLASS_$_'
  5920. else
  5921. result:='_OBJC_$_CATEGORY_';
  5922. objcmetartti:
  5923. result:='_OBJC_METACLASS_$_';
  5924. objcclassrortti:
  5925. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  5926. objcmetarortti:
  5927. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  5928. else
  5929. internalerror(2009092303);
  5930. end;
  5931. end;
  5932. odt_objcprotocol:
  5933. begin
  5934. result:=lower(target_asm.labelprefix);
  5935. case rt of
  5936. objcclassrtti:
  5937. result:=result+'_OBJC_PROTOCOL_$_';
  5938. objcmetartti:
  5939. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  5940. else
  5941. internalerror(2009092501);
  5942. end;
  5943. end;
  5944. else
  5945. internalerror(2013113005);
  5946. end;
  5947. end;
  5948. result:=result+objextname^;
  5949. end;
  5950. end;
  5951. function tobjectdef.members_need_inittable : boolean;
  5952. begin
  5953. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  5954. end;
  5955. function tobjectdef.is_publishable : boolean;
  5956. begin
  5957. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  5958. end;
  5959. function tobjectdef.get_next_dispid: longint;
  5960. begin
  5961. inc(fcurrent_dispid);
  5962. result:=fcurrent_dispid;
  5963. end;
  5964. function tobjectdef.search_enumerator_get: tprocdef;
  5965. begin
  5966. result:=inherited;
  5967. if not assigned(result) and assigned(childof) then
  5968. result:=childof.search_enumerator_get;
  5969. end;
  5970. function tobjectdef.search_enumerator_move: tprocdef;
  5971. begin
  5972. result:=inherited;
  5973. if not assigned(result) and assigned(childof) then
  5974. result:=childof.search_enumerator_move;
  5975. end;
  5976. function tobjectdef.search_enumerator_current: tsym;
  5977. begin
  5978. result:=inherited;
  5979. if not assigned(result) and assigned(childof) then
  5980. result:=childof.search_enumerator_current;
  5981. end;
  5982. procedure tobjectdef.register_created_classref_type;
  5983. begin
  5984. if not classref_created_in_current_module then
  5985. begin
  5986. classref_created_in_current_module:=true;
  5987. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  5988. end;
  5989. end;
  5990. procedure tobjectdef.register_created_object_type;
  5991. begin
  5992. if not created_in_current_module then
  5993. begin
  5994. created_in_current_module:=true;
  5995. current_module.wpoinfo.addcreatedobjtype(self);
  5996. end;
  5997. end;
  5998. procedure tobjectdef.register_maybe_created_object_type;
  5999. begin
  6000. { if we know it has been created for sure, no need
  6001. to also record that it maybe can be created in
  6002. this module
  6003. }
  6004. if not (created_in_current_module) and
  6005. not (maybe_created_in_current_module) then
  6006. begin
  6007. maybe_created_in_current_module:=true;
  6008. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  6009. end;
  6010. end;
  6011. procedure tobjectdef.register_vmt_call(index: longint);
  6012. begin
  6013. if (is_object(self) or is_class(self)) then
  6014. current_module.wpoinfo.addcalledvmtentry(self,index);
  6015. end;
  6016. procedure check_and_finish_msg(data: tobject; arg: pointer);
  6017. var
  6018. def: tdef absolute data;
  6019. pd: tprocdef absolute data;
  6020. i,
  6021. paracount: longint;
  6022. begin
  6023. if (def.typ=procdef) then
  6024. begin
  6025. { add all messages also under a dummy name to the symtable in
  6026. which the objcclass/protocol/category is declared, so they can
  6027. be called via id.<name>
  6028. }
  6029. create_class_helper_for_procdef(pd,nil);
  6030. { we have to wait until now to set the mangled name because it
  6031. depends on the (possibly external) class name, which is defined
  6032. at the very end. }
  6033. if not(po_msgstr in pd.procoptions) then
  6034. begin
  6035. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  6036. { recover to avoid internalerror later on }
  6037. include(pd.procoptions,po_msgstr);
  6038. pd.messageinf.str:=stringdup('MissingDeclaration');
  6039. end;
  6040. { Mangled name is already set in case this is a copy of
  6041. another type. }
  6042. if not(po_has_mangledname in pd.procoptions) then
  6043. begin
  6044. { check whether the number of formal parameters is correct,
  6045. and whether they have valid Objective-C types }
  6046. paracount:=0;
  6047. for i:=1 to length(pd.messageinf.str^) do
  6048. if pd.messageinf.str^[i]=':' then
  6049. inc(paracount);
  6050. for i:=0 to pd.paras.count-1 do
  6051. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  6052. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  6053. dec(paracount);
  6054. if (paracount<>0) then
  6055. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  6056. pd.setmangledname(pd.objcmangledname);
  6057. end
  6058. else
  6059. { all checks already done }
  6060. exit;
  6061. if not(oo_is_external in pd.struct.objectoptions) then
  6062. begin
  6063. if (po_varargs in pd.procoptions) then
  6064. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  6065. else
  6066. begin
  6067. { check for "array of const" parameters }
  6068. for i:=0 to pd.parast.symlist.count-1 do
  6069. begin
  6070. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  6071. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  6072. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  6073. end;
  6074. end;
  6075. end;
  6076. end;
  6077. end;
  6078. procedure mark_private_fields_used(data: tobject; arg: pointer);
  6079. var
  6080. sym: tsym absolute data;
  6081. begin
  6082. if (sym.typ=fieldvarsym) and
  6083. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  6084. sym.IncRefCount;
  6085. end;
  6086. procedure tobjectdef.finish_objc_data;
  6087. begin
  6088. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  6089. if (oo_is_external in objectoptions) then
  6090. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  6091. end;
  6092. procedure verify_objc_vardef(data: tobject; arg: pointer);
  6093. var
  6094. sym: tabstractvarsym absolute data;
  6095. res: pboolean absolute arg;
  6096. founderrordef: tdef;
  6097. begin
  6098. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  6099. exit;
  6100. if (sym.typ=paravarsym) and
  6101. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  6102. is_array_of_const(tparavarsym(sym).vardef)) then
  6103. exit;
  6104. if not objcchecktype(sym.vardef,founderrordef) then
  6105. begin
  6106. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6107. res^:=false;
  6108. end;
  6109. end;
  6110. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  6111. var
  6112. def: tdef absolute data;
  6113. res: pboolean absolute arg;
  6114. founderrordef: tdef;
  6115. begin
  6116. if (def.typ<>procdef) then
  6117. exit;
  6118. { check parameter types for validity }
  6119. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  6120. { check the result type for validity }
  6121. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  6122. begin
  6123. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6124. res^:=false;
  6125. end;
  6126. end;
  6127. function tobjectdef.check_objc_types: boolean;
  6128. begin
  6129. { done in separate step from finish_objc_data, because when
  6130. finish_objc_data is called, not all forwarddefs have been resolved
  6131. yet and we need to know all types here }
  6132. result:=true;
  6133. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  6134. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  6135. end;
  6136. procedure do_cpp_import_info(data: tobject; arg: pointer);
  6137. var
  6138. def: tdef absolute data;
  6139. pd: tprocdef absolute data;
  6140. begin
  6141. if (def.typ=procdef) then
  6142. begin
  6143. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  6144. if (oo_is_external in pd.struct.objectoptions) then
  6145. begin
  6146. { copied from psub.read_proc }
  6147. if assigned(tobjectdef(pd.struct).import_lib) then
  6148. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  6149. else
  6150. begin
  6151. { add import name to external list for DLL scanning }
  6152. if tf_has_dllscanner in target_info.flags then
  6153. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  6154. end;
  6155. end;
  6156. end;
  6157. end;
  6158. procedure tobjectdef.finish_cpp_data;
  6159. begin
  6160. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  6161. end;
  6162. {****************************************************************************
  6163. TImplementedInterface
  6164. ****************************************************************************}
  6165. function TImplementedInterface.GetIOffset: longint;
  6166. begin
  6167. if (fIOffset=-1) and
  6168. (IType in [etFieldValue,etFieldValueClass]) then
  6169. result:=tfieldvarsym(ImplementsField).fieldoffset
  6170. else
  6171. result:=fIOffset;
  6172. end;
  6173. constructor TImplementedInterface.create(aintf: tobjectdef);
  6174. begin
  6175. inherited create;
  6176. intfdef:=aintf;
  6177. IOffset:=-1;
  6178. IType:=etStandard;
  6179. NameMappings:=nil;
  6180. procdefs:=nil;
  6181. end;
  6182. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  6183. begin
  6184. inherited create;
  6185. intfdef:=nil;
  6186. intfdefderef:=intfd;
  6187. ImplementsGetterDeref:=getterd;
  6188. IOffset:=-1;
  6189. IType:=etStandard;
  6190. NameMappings:=nil;
  6191. procdefs:=nil;
  6192. end;
  6193. destructor TImplementedInterface.destroy;
  6194. var
  6195. i : longint;
  6196. mappedname : pshortstring;
  6197. begin
  6198. if assigned(NameMappings) then
  6199. begin
  6200. for i:=0 to NameMappings.Count-1 do
  6201. begin
  6202. mappedname:=pshortstring(NameMappings[i]);
  6203. stringdispose(mappedname);
  6204. end;
  6205. NameMappings.free;
  6206. NameMappings:=nil;
  6207. end;
  6208. if assigned(procdefs) then
  6209. begin
  6210. procdefs.free;
  6211. procdefs:=nil;
  6212. end;
  6213. inherited destroy;
  6214. end;
  6215. procedure TImplementedInterface.buildderef;
  6216. begin
  6217. intfdefderef.build(intfdef);
  6218. ImplementsGetterDeref.build(ImplementsGetter);
  6219. end;
  6220. procedure TImplementedInterface.deref;
  6221. begin
  6222. intfdef:=tobjectdef(intfdefderef.resolve);
  6223. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  6224. end;
  6225. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  6226. begin
  6227. if not assigned(NameMappings) then
  6228. NameMappings:=TFPHashList.Create;
  6229. NameMappings.Add(origname,stringdup(newname));
  6230. end;
  6231. function TImplementedInterface.GetMapping(const origname: string):string;
  6232. var
  6233. mappedname : pshortstring;
  6234. begin
  6235. result:='';
  6236. if not assigned(NameMappings) then
  6237. exit;
  6238. mappedname:=PShortstring(NameMappings.Find(origname));
  6239. if assigned(mappedname) then
  6240. result:=mappedname^;
  6241. end;
  6242. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  6243. begin
  6244. if not assigned(procdefs) then
  6245. procdefs:=TFPObjectList.Create(false);
  6246. { duplicate entries must be stored, because multiple }
  6247. { interfaces can declare methods with the same name }
  6248. { and all of these get their own VMT entry }
  6249. procdefs.Add(pd);
  6250. end;
  6251. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  6252. var
  6253. i : longint;
  6254. begin
  6255. result:=false;
  6256. { interfaces being implemented through delegation are not mergable (FK) }
  6257. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  6258. exit;
  6259. weight:=0;
  6260. { empty interface is mergeable }
  6261. if ProcDefs.Count=0 then
  6262. begin
  6263. result:=true;
  6264. exit;
  6265. end;
  6266. { The interface to merge must at least the number of
  6267. procedures of this interface }
  6268. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  6269. exit;
  6270. for i:=0 to ProcDefs.Count-1 do
  6271. begin
  6272. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  6273. exit;
  6274. end;
  6275. weight:=ProcDefs.Count;
  6276. result:=true;
  6277. end;
  6278. function TImplementedInterface.getcopy:TImplementedInterface;
  6279. begin
  6280. Result:=TImplementedInterface.Create(nil);
  6281. { 1) the procdefs list will be freed once for each copy
  6282. 2) since the procdefs list owns its elements, those will also be freed for each copy
  6283. 3) idem for the name mappings
  6284. }
  6285. { warning: this is completely wrong on so many levels...
  6286. Move(pointer(self)^,pointer(result)^,InstanceSize);
  6287. We need to make clean copies of the different fields
  6288. this is not implemented yet, and thus we generate an internal
  6289. error instead PM 2011-06-14 }
  6290. internalerror(2011061401);
  6291. end;
  6292. {****************************************************************************
  6293. TFORWARDDEF
  6294. ****************************************************************************}
  6295. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  6296. begin
  6297. inherited create(forwarddef);
  6298. tosymname:=stringdup(s);
  6299. forwardpos:=pos;
  6300. end;
  6301. function tforwarddef.GetTypeName:string;
  6302. begin
  6303. GetTypeName:='unresolved forward to '+tosymname^;
  6304. end;
  6305. destructor tforwarddef.destroy;
  6306. begin
  6307. stringdispose(tosymname);
  6308. inherited destroy;
  6309. end;
  6310. function tforwarddef.getcopy:tstoreddef;
  6311. begin
  6312. result:=cforwarddef.create(tosymname^, forwardpos);
  6313. end;
  6314. {****************************************************************************
  6315. TUNDEFINEDDEF
  6316. ****************************************************************************}
  6317. constructor tundefineddef.create;
  6318. begin
  6319. inherited create(undefineddef);
  6320. end;
  6321. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  6322. begin
  6323. inherited ppuload(undefineddef,ppufile);
  6324. ppuload_platform(ppufile);
  6325. end;
  6326. function tundefineddef.GetTypeName:string;
  6327. begin
  6328. GetTypeName:='<undefined type>';
  6329. end;
  6330. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  6331. begin
  6332. inherited ppuwrite(ppufile);
  6333. writeentry(ppufile,ibundefineddef);
  6334. end;
  6335. {****************************************************************************
  6336. TERRORDEF
  6337. ****************************************************************************}
  6338. constructor terrordef.create;
  6339. begin
  6340. inherited create(errordef);
  6341. { prevent consecutive faults }
  6342. savesize:=1;
  6343. end;
  6344. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  6345. begin
  6346. { Can't write errordefs to ppu }
  6347. internalerror(200411063);
  6348. end;
  6349. function terrordef.GetTypeName:string;
  6350. begin
  6351. GetTypeName:='<erroneous type>';
  6352. end;
  6353. function terrordef.getmangledparaname:TSymStr;
  6354. begin
  6355. getmangledparaname:='error';
  6356. end;
  6357. {****************************************************************************
  6358. Definition Helpers
  6359. ****************************************************************************}
  6360. function is_interfacecom(def: tdef): boolean;
  6361. begin
  6362. is_interfacecom:=
  6363. assigned(def) and
  6364. (def.typ=objectdef) and
  6365. (tobjectdef(def).objecttype=odt_interfacecom);
  6366. end;
  6367. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  6368. begin
  6369. is_interfacecom_or_dispinterface:=
  6370. assigned(def) and
  6371. (def.typ=objectdef) and
  6372. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  6373. end;
  6374. function is_any_interface_kind(def: tdef): boolean;
  6375. begin
  6376. result:=
  6377. assigned(def) and
  6378. (def.typ=objectdef) and
  6379. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  6380. is_objccategory(def));
  6381. end;
  6382. function is_interfacecorba(def: tdef): boolean;
  6383. begin
  6384. is_interfacecorba:=
  6385. assigned(def) and
  6386. (def.typ=objectdef) and
  6387. (tobjectdef(def).objecttype=odt_interfacecorba);
  6388. end;
  6389. function is_interface(def: tdef): boolean;
  6390. begin
  6391. is_interface:=
  6392. assigned(def) and
  6393. (def.typ=objectdef) and
  6394. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  6395. end;
  6396. function is_dispinterface(def: tdef): boolean;
  6397. begin
  6398. result:=
  6399. assigned(def) and
  6400. (def.typ=objectdef) and
  6401. (tobjectdef(def).objecttype=odt_dispinterface);
  6402. end;
  6403. function is_class(def: tdef): boolean;
  6404. begin
  6405. is_class:=
  6406. assigned(def) and
  6407. (def.typ=objectdef) and
  6408. (tobjectdef(def).objecttype=odt_class);
  6409. end;
  6410. function is_object(def: tdef): boolean;
  6411. begin
  6412. is_object:=
  6413. assigned(def) and
  6414. (def.typ=objectdef) and
  6415. (tobjectdef(def).objecttype=odt_object);
  6416. end;
  6417. function is_cppclass(def: tdef): boolean;
  6418. begin
  6419. is_cppclass:=
  6420. assigned(def) and
  6421. (def.typ=objectdef) and
  6422. (tobjectdef(def).objecttype=odt_cppclass);
  6423. end;
  6424. function is_objcclass(def: tdef): boolean;
  6425. begin
  6426. is_objcclass:=
  6427. assigned(def) and
  6428. (def.typ=objectdef) and
  6429. (tobjectdef(def).objecttype=odt_objcclass);
  6430. end;
  6431. function is_objectpascal_helper(def: tdef): boolean;
  6432. begin
  6433. result:=
  6434. assigned(def) and
  6435. (def.typ=objectdef) and
  6436. (tobjectdef(def).objecttype=odt_helper);
  6437. end;
  6438. function is_objcclassref(def: tdef): boolean;
  6439. begin
  6440. is_objcclassref:=
  6441. assigned(def) and
  6442. (def.typ=classrefdef) and
  6443. is_objcclass(tclassrefdef(def).pointeddef);
  6444. end;
  6445. function is_objcprotocol(def: tdef): boolean;
  6446. begin
  6447. result:=
  6448. assigned(def) and
  6449. (def.typ=objectdef) and
  6450. (tobjectdef(def).objecttype=odt_objcprotocol);
  6451. end;
  6452. function is_objccategory(def: tdef): boolean;
  6453. begin
  6454. result:=
  6455. assigned(def) and
  6456. (def.typ=objectdef) and
  6457. { if used as a forward type }
  6458. ((tobjectdef(def).objecttype=odt_objccategory) or
  6459. { if used as after it has been resolved }
  6460. ((tobjectdef(def).objecttype=odt_objcclass) and
  6461. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6462. end;
  6463. function is_objc_class_or_protocol(def: tdef): boolean;
  6464. begin
  6465. result:=
  6466. assigned(def) and
  6467. (def.typ=objectdef) and
  6468. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  6469. end;
  6470. function is_objc_protocol_or_category(def: tdef): boolean;
  6471. begin
  6472. result:=
  6473. assigned(def) and
  6474. (def.typ=objectdef) and
  6475. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  6476. ((tobjectdef(def).objecttype = odt_objcclass) and
  6477. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6478. end;
  6479. function is_classhelper(def: tdef): boolean;
  6480. begin
  6481. result:=
  6482. is_objectpascal_helper(def) or
  6483. is_objccategory(def);
  6484. end;
  6485. function is_class_or_interface(def: tdef): boolean;
  6486. begin
  6487. result:=
  6488. assigned(def) and
  6489. (def.typ=objectdef) and
  6490. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  6491. end;
  6492. function is_class_or_interface_or_objc(def: tdef): boolean;
  6493. begin
  6494. result:=
  6495. assigned(def) and
  6496. (def.typ=objectdef) and
  6497. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  6498. end;
  6499. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  6500. begin
  6501. result:=
  6502. assigned(def) and
  6503. (def.typ=objectdef) and
  6504. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6505. end;
  6506. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  6507. begin
  6508. result:=
  6509. assigned(def) and
  6510. (def.typ=objectdef) and
  6511. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6512. end;
  6513. function is_class_or_interface_or_object(def: tdef): boolean;
  6514. begin
  6515. result:=
  6516. assigned(def) and
  6517. (def.typ=objectdef) and
  6518. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  6519. end;
  6520. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  6521. begin
  6522. result:=
  6523. assigned(def) and
  6524. (def.typ=objectdef) and
  6525. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  6526. end;
  6527. function is_implicit_pointer_object_type(def: tdef): boolean;
  6528. begin
  6529. result:=
  6530. assigned(def) and
  6531. (((def.typ=objectdef) and
  6532. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  6533. ((target_info.system in systems_jvm) and
  6534. (def.typ=recorddef)));
  6535. end;
  6536. function is_implicit_array_pointer(def: tdef): boolean;
  6537. begin
  6538. result:=is_dynamic_array(def) or is_dynamicstring(def);
  6539. end;
  6540. function is_class_or_object(def: tdef): boolean;
  6541. begin
  6542. result:=
  6543. assigned(def) and
  6544. (def.typ=objectdef) and
  6545. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  6546. end;
  6547. function is_record(def: tdef): boolean;
  6548. begin
  6549. result:=
  6550. assigned(def) and
  6551. (def.typ=recorddef);
  6552. end;
  6553. function is_javaclass(def: tdef): boolean;
  6554. begin
  6555. result:=
  6556. assigned(def) and
  6557. (def.typ=objectdef) and
  6558. (tobjectdef(def).objecttype=odt_javaclass);
  6559. end;
  6560. function is_javaclassref(def: tdef): boolean;
  6561. begin
  6562. is_javaclassref:=
  6563. assigned(def) and
  6564. (def.typ=classrefdef) and
  6565. is_javaclass(tclassrefdef(def).pointeddef);
  6566. end;
  6567. function is_javainterface(def: tdef): boolean;
  6568. begin
  6569. result:=
  6570. assigned(def) and
  6571. (def.typ=objectdef) and
  6572. (tobjectdef(def).objecttype=odt_interfacejava);
  6573. end;
  6574. function is_java_class_or_interface(def: tdef): boolean;
  6575. begin
  6576. result:=
  6577. assigned(def) and
  6578. (def.typ=objectdef) and
  6579. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  6580. end;
  6581. procedure loadobjctypes;
  6582. begin
  6583. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  6584. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  6585. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  6586. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  6587. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  6588. end;
  6589. procedure maybeloadcocoatypes;
  6590. var
  6591. tsym: ttypesym;
  6592. cocoaunit: string[15];
  6593. begin
  6594. if assigned(objc_fastenumeration) then
  6595. exit;
  6596. if not(target_info.system in [system_arm_darwin,system_i386_iphonesim,system_aarch64_darwin,system_x86_64_iphonesim]) then
  6597. cocoaunit:='COCOAALL'
  6598. else
  6599. cocoaunit:='IPHONEALL';
  6600. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  6601. if assigned(tsym) then
  6602. objc_fastenumeration:=tobjectdef(tsym.typedef)
  6603. else
  6604. objc_fastenumeration:=nil;
  6605. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  6606. if assigned(tsym) then
  6607. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  6608. else
  6609. objc_fastenumerationstate:=nil;
  6610. end;
  6611. function use_vectorfpu(def : tdef) : boolean;
  6612. begin
  6613. {$ifdef x86}
  6614. {$define use_vectorfpuimplemented}
  6615. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  6616. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  6617. {$endif x86}
  6618. {$ifdef arm}
  6619. {$define use_vectorfpuimplemented}
  6620. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  6621. {$endif arm}
  6622. {$ifdef aarch64}
  6623. {$define use_vectorfpuimplemented}
  6624. use_vectorfpu:=true;
  6625. {$endif aarch64}
  6626. {$ifndef use_vectorfpuimplemented}
  6627. use_vectorfpu:=false;
  6628. {$endif}
  6629. end;
  6630. function getpointerdef(def: tdef): tpointerdef;
  6631. var
  6632. res: PHashSetItem;
  6633. oldsymtablestack: tsymtablestack;
  6634. begin
  6635. if not assigned(current_module) then
  6636. internalerror(2011071101);
  6637. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  6638. if not assigned(res^.Data) then
  6639. begin
  6640. { since these pointerdefs can be reused anywhere in the current
  6641. unit, add them to the global/staticsymtable }
  6642. oldsymtablestack:=symtablestack;
  6643. { do not simply push/pop current_module.localsymtable, because
  6644. that can have side-effects (e.g., it removes helpers) }
  6645. symtablestack:=nil;
  6646. res^.Data:=cpointerdef.create(def);
  6647. if assigned(current_module.localsymtable) then
  6648. current_module.localsymtable.insertdef(tdef(res^.Data))
  6649. else
  6650. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6651. symtablestack:=oldsymtablestack;
  6652. end;
  6653. result:=tpointerdef(res^.Data);
  6654. end;
  6655. function getsingletonarraydef(def: tdef): tarraydef;
  6656. begin
  6657. result:=getarraydef(def,1);
  6658. end;
  6659. function getarraydef(def: tdef; elecount: asizeint): tarraydef;
  6660. var
  6661. res: PHashSetItem;
  6662. oldsymtablestack: tsymtablestack;
  6663. arrdesc: packed record
  6664. def: tdef;
  6665. elecount: asizeint;
  6666. end;
  6667. begin
  6668. if not assigned(current_module) then
  6669. internalerror(2011081301);
  6670. arrdesc.def:=def;
  6671. arrdesc.elecount:=elecount;
  6672. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  6673. if not assigned(res^.Data) then
  6674. begin
  6675. { since these arraydef can be reused anywhere in the current
  6676. unit, add them to the global/staticsymtable }
  6677. oldsymtablestack:=symtablestack;
  6678. symtablestack:=nil;
  6679. res^.Data:=carraydef.create(0,elecount-1,ptrsinttype);
  6680. tarraydef(res^.Data).elementdef:=def;
  6681. if assigned(current_module.localsymtable) then
  6682. current_module.localsymtable.insertdef(tdef(res^.Data))
  6683. else
  6684. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6685. symtablestack:=oldsymtablestack;
  6686. end;
  6687. result:=tarraydef(res^.Data);
  6688. end;
  6689. end.