symdef.pas 253 KB

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