symdef.pas 241 KB

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