symdef.pas 250 KB

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