symdef.pas 244 KB

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