symdef.pas 251 KB

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